Bug 843627 part 3. Enable WebIDL bindings for <embed> and <applet>. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Sun, 17 Mar 2013 10:42:05 -0400
changeset 125138 4f79d9d9d818b6639987a190fe10f567d1d63b39
parent 125137 61099fdb7b2398302cf9a695e03169cd3ea00b0f
child 125139 ca91f19a36dbf32b52d3f42a91a194ce442f451f
push id24449
push useremorley@mozilla.com
push dateMon, 18 Mar 2013 20:06:48 +0000
treeherdermozilla-central@e23e43a2c14e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs843627
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 843627 part 3. Enable WebIDL bindings for <embed> and <applet>. r=peterv
browser/base/content/test/test_bug787619.html
content/html/content/src/HTMLSharedObjectElement.cpp
content/html/content/src/HTMLSharedObjectElement.h
dom/bindings/BindingUtils.cpp
dom/plugins/test/mochitest/test_bug751809.html
dom/webidl/WebIDL.mk
--- a/browser/base/content/test/test_bug787619.html
+++ b/browser/base/content/test/test_bug787619.html
@@ -19,17 +19,17 @@
   SimpleTest.waitForExplicitFinish();
 
   const Ci = SpecialPowers.Ci;
   let wrapperClickCount = 0;
 
   function test1() {
     let plugin = document.getElementById('plugin');
     ok(plugin, 'got plugin element');
-    let objLC = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
+    let objLC = SpecialPowers.wrap(plugin);
     ok(!objLC.activated, 'plugin should not be activated');
 
     synthesizeMouseAtCenter(plugin, {});
     waitForCondition(function() objLC.activated, test2, 
                      'waited too long for plugin to activate');
   }
 
   function test2() {
--- a/content/html/content/src/HTMLSharedObjectElement.cpp
+++ b/content/html/content/src/HTMLSharedObjectElement.cpp
@@ -1,15 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 // vim:set et sw=2 sts=2 cin:
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/HTMLSharedObjectElement.h"
+#include "mozilla/dom/HTMLEmbedElementBinding.h"
+#include "mozilla/dom/HTMLAppletElementBinding.h"
 #include "mozilla/Util.h"
 
 #include "nsIDocument.h"
 #include "nsIPluginDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsThreadUtils.h"
 #include "nsIDOMSVGDocument.h"
 #include "nsIScriptError.h"
@@ -29,16 +31,18 @@ HTMLSharedObjectElement::HTMLSharedObjec
   : nsGenericHTMLElement(aNodeInfo),
     mIsDoneAddingChildren(mNodeInfo->Equals(nsGkAtoms::embed) || !aFromParser)
 {
   RegisterFreezableElement();
   SetIsNetworkCreated(aFromParser == FROM_PARSER_NETWORK);
 
   // By default we're in the loading state
   AddStatesSilently(NS_EVENT_STATE_LOADING);
+
+  SetIsDOMBinding();
 }
 
 void
 HTMLSharedObjectElement::GetItemValueText(nsAString& aValue)
 {
   if (mNodeInfo->Equals(nsGkAtoms::applet)) {
     nsGenericHTMLElement::GetItemValueText(aValue);
   } else {
@@ -356,10 +360,37 @@ HTMLSharedObjectElement::CopyInnerTo(Ele
 
   if (aDest->OwnerDoc()->IsStaticDocument()) {
     CreateStaticClone(static_cast<HTMLSharedObjectElement*>(aDest));
   }
 
   return rv;
 }
 
+JSObject*
+HTMLSharedObjectElement::WrapNode(JSContext* aCx, JSObject* aScope)
+{
+  JSObject* obj;
+  if (mNodeInfo->Equals(nsGkAtoms::applet)) {
+    obj = HTMLAppletElementBinding::Wrap(aCx, aScope, this);
+  } else {
+    MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::embed));
+    obj = HTMLEmbedElementBinding::Wrap(aCx, aScope, this);
+  }
+  if (!obj) {
+    return nullptr;
+  }
+  SetupProtoChain(aCx, obj);
+  return obj;
+}
+
+JSObject*
+HTMLSharedObjectElement::GetCanonicalPrototype(JSContext* aCx, JSObject* aGlobal)
+{
+  if (mNodeInfo->Equals(nsGkAtoms::applet)) {
+    return HTMLAppletElementBinding::GetProtoObject(aCx, aGlobal);
+  }
+  MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::embed));
+  return HTMLEmbedElementBinding::GetProtoObject(aCx, aGlobal);
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/content/html/content/src/HTMLSharedObjectElement.h
+++ b/content/html/content/src/HTMLSharedObjectElement.h
@@ -239,14 +239,18 @@ private:
   }
 
   // mIsDoneAddingChildren is only really used for <applet>.  This boolean is
   // always true for <embed>, per the documentation in nsIContent.h.
   bool mIsDoneAddingChildren;
 
   virtual void GetItemValueText(nsAString& text);
   virtual void SetItemValueText(const nsAString& text);
+
+  virtual JSObject* WrapNode(JSContext *aCx, JSObject *aScope) MOZ_OVERRIDE;
+  virtual JSObject* GetCanonicalPrototype(JSContext* aCx,
+                                          JSObject* aGlobal) MOZ_OVERRIDE;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_HTMLSharedObjectElement_h
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -17,16 +17,19 @@
 #include "WrapperFactory.h"
 #include "xpcprivate.h"
 #include "XPCQuickStubs.h"
 #include "XPCWrapper.h"
 #include "XrayWrapper.h"
 
 #include "mozilla/dom/HTMLObjectElement.h"
 #include "mozilla/dom/HTMLObjectElementBinding.h"
+#include "mozilla/dom/HTMLSharedObjectElement.h"
+#include "mozilla/dom/HTMLEmbedElementBinding.h"
+#include "mozilla/dom/HTMLAppletElementBinding.h"
 
 namespace mozilla {
 namespace dom {
 
 JSErrorFormatString ErrorFormatString[] = {
 #define MSG_DEF(_name, _argc, _str) \
   { _str, _argc, JSEXN_TYPEERR },
 #include "mozilla/dom/Errors.msg"
@@ -1528,19 +1531,30 @@ ReparentWrapper(JSContext* aCx, JSObject
   bool preserving = cache->PreservingWrapper();
   cache->SetPreservingWrapper(false);
   cache->SetWrapper(aObj);
   cache->SetPreservingWrapper(preserving);
   if (!JS_CopyPropertiesFrom(aCx, aObj, propertyHolder)) {
     MOZ_CRASH();
   }
 
-  HTMLObjectElement* htmlobject;
+  nsObjectLoadingContent* htmlobject;
   nsresult rv = UnwrapObject<HTMLObjectElement>(aCx, aObj, htmlobject);
-  if (NS_SUCCEEDED(rv)) {
+  if (NS_FAILED(rv)) {
+    rv = UnwrapObject<prototypes::id::HTMLEmbedElement,
+                      HTMLSharedObjectElement>(aCx, aObj, htmlobject);
+    if (NS_FAILED(rv)) {
+      rv = UnwrapObject<prototypes::id::HTMLAppletElement,
+                        HTMLSharedObjectElement>(aCx, aObj, htmlobject);
+      if (NS_FAILED(rv)) {
+        htmlobject = nullptr;
+      }
+    }
+  }
+  if (htmlobject) {
     htmlobject->SetupProtoChain(aCx, aObj);
   }
 
   // Now we can just fix up the parent and return the wrapper
 
   if (newParent && !JS_SetParent(aCx, aObj, newParent)) {
     MOZ_CRASH();
   }
--- a/dom/plugins/test/mochitest/test_bug751809.html
+++ b/dom/plugins/test/mochitest/test_bug751809.html
@@ -34,33 +34,33 @@
       }
       tries++;
     }, 100);
     var moveOn = function() { clearInterval(interval); nextTest(); };
   }
 
   function go() {
     var plugin = document.getElementById('plugin');
-    var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
+    var objLoadingContent = SpecialPowers.wrap(plugin);
     ok(!objLoadingContent.activated, "plugin should not be activated");
     
     SimpleTest.waitForFocus(afterWindowFocus);
   }
 
   function afterWindowFocus() {
     var plugin = document.getElementById('plugin');
 
     synthesizeMouseAtCenter(plugin, {});
     var condition = function() plugin.setColor !== undefined;
     waitForCondition(condition, afterPluginActivation, "Waited too long for plugin to activate");
   }
     
   function afterPluginActivation() {
     var plugin = document.getElementById('plugin');
-    var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
+    var objLoadingContent = SpecialPowers.wrap(plugin);
     ok(objLoadingContent.activated, "plugin should be activated now");
 
     // Triggering a paint and waiting for it to be flushed makes sure
     // that both plugin and platform see the plugin element as visible.
     // See bug 805330 for details.
     plugin.setColor("FF000088");
     waitForAllPaintsFlushed(afterPaintsFlushed);
   }
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -61,29 +61,31 @@ webidl_files = \
   FileHandle.webidl \
   FileList.webidl \
   FileReaderSync.webidl \
   FileRequest.webidl \
   FormData.webidl \
   Function.webidl \
   GainNode.webidl \
   HTMLAnchorElement.webidl \
+  HTMLAppletElement.webidl \
   HTMLAreaElement.webidl \
   HTMLBaseElement.webidl \
   HTMLBodyElement.webidl \
   HTMLBRElement.webidl \
   HTMLButtonElement.webidl \
   HTMLCollection.webidl \
   HTMLDataElement.webidl \
   HTMLDataListElement.webidl \
   HTMLDirectoryElement.webidl \
   HTMLDivElement.webidl \
   HTMLDListElement.webidl \
   HTMLDocument.webidl \
   HTMLElement.webidl \
+  HTMLEmbedElement.webidl \
   HTMLFieldSetElement.webidl \
   HTMLFontElement.webidl \
   HTMLFrameElement.webidl \
   HTMLFrameSetElement.webidl \
   HTMLHeadElement.webidl \
   HTMLHeadingElement.webidl \
   HTMLHRElement.webidl \
   HTMLHtmlElement.webidl \