Bug 822674. Give RTCPeerConnection a sane classinfo. r=jst,jesup. r=peterv pending
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 15 Feb 2013 22:41:31 -0500
changeset 131973 0fc77f0a35d883a3c10e0713f2f3dadc1155cdda
parent 131972 9f9eb67458e93aedbb9ad85afda079cec88ccf29
child 131974 7a145f17e37cdd9d13190a29042711cf2c2a7588
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst, jesup, peterv
bugs822674
milestone21.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 822674. Give RTCPeerConnection a sane classinfo. r=jst,jesup. r=peterv pending
content/base/src/nsDOMDataChannel.cpp
dom/base/nsDOMClassInfo.cpp
dom/base/nsDOMClassInfoClasses.h
dom/media/PeerConnection.js
dom/media/tests/mochitest/Makefile.in
dom/media/tests/mochitest/test_peerConnection_bug822674.html
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/src/XPCComponents.cpp
--- a/content/base/src/nsDOMDataChannel.cpp
+++ b/content/base/src/nsDOMDataChannel.cpp
@@ -17,16 +17,17 @@ extern PRLogModuleInfo* GetDataChannelLo
 #undef LOG
 #define LOG(args) PR_LOG(GetDataChannelLog(), PR_LOG_DEBUG, args)
 
 
 #include "nsDOMDataChannel.h"
 #include "nsIDOMFile.h"
 #include "nsIJSNativeInitializer.h"
 #include "nsIDOMDataChannel.h"
+#include "nsIDOMRTCPeerConnection.h"
 #include "nsIDOMMessageEvent.h"
 #include "nsDOMClassInfo.h"
 #include "nsDOMEventTargetHelper.h"
 
 #include "js/Value.h"
 
 #include "nsError.h"
 #include "nsAutoPtr.h"
@@ -104,16 +105,21 @@ private:
   enum
   {
     DC_BINARY_TYPE_ARRAYBUFFER,
     DC_BINARY_TYPE_BLOB,
   } mBinaryType;
 };
 
 DOMCI_DATA(DataChannel, nsDOMDataChannel)
+// A bit of a hack for RTCPeerConnection, since it doesn't have a .cpp file of
+// its own.  Note that it's not castable to anything in particular other than
+// nsIDOMRTCPeerConnection, so we can just use nsIDOMRTCPeerConnection as the
+// "class".
+DOMCI_DATA(RTCPeerConnection, nsIDOMRTCPeerConnection)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMDataChannel,
                                                   nsDOMEventTargetHelper)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMDataChannel,
                                                 nsDOMEventTargetHelper)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -461,16 +461,17 @@ using mozilla::dom::workers::ResolveWork
 #endif
 
 #ifdef MOZ_TIME_MANAGER
 #include "TimeManager.h"
 #endif
 
 #ifdef MOZ_WEBRTC
 #include "nsIDOMDataChannel.h"
+#include "nsIDOMRTCPeerConnection.h"
 #endif
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
 
 static const char kDOMStringBundleURL[] =
@@ -1412,16 +1413,18 @@ static nsDOMClassInfoData sClassInfoData
 #ifdef MOZ_TIME_MANAGER
   NS_DEFINE_CLASSINFO_DATA(MozTimeManager, nsDOMGenericSH,
                            DOM_DEFAULT_SCRIPTABLE_FLAGS)
 #endif
 
 #ifdef MOZ_WEBRTC
   NS_DEFINE_CLASSINFO_DATA(DataChannel, nsEventTargetSH,
                            EVENTTARGET_SCRIPTABLE_FLAGS)
+  NS_DEFINE_CLASSINFO_DATA(RTCPeerConnection, nsDOMGenericSH,
+                           DOM_DEFAULT_SCRIPTABLE_FLAGS)
 #endif
 };
 
 #define NS_DEFINE_CONTRACT_CTOR(_class, _contract_id)                           \
   static nsresult                                                               \
   _class##Ctor(nsISupports** aInstancePtrResult)                                \
   {                                                                             \
     nsresult rv = NS_OK;                                                        \
@@ -3620,16 +3623,20 @@ nsDOMClassInfo::Init()
   DOM_CLASSINFO_MAP_END
 #endif
 
 #ifdef MOZ_WEBRTC
   DOM_CLASSINFO_MAP_BEGIN(DataChannel, nsIDOMDataChannel)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMDataChannel)
     DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
   DOM_CLASSINFO_MAP_END
+
+  DOM_CLASSINFO_MAP_BEGIN(RTCPeerConnection, nsIDOMRTCPeerConnection)
+    DOM_CLASSINFO_MAP_ENTRY(nsIDOMRTCPeerConnection)
+  DOM_CLASSINFO_MAP_END
 #endif
 
 #ifdef DEBUG
   {
     uint32_t i = ArrayLength(sClassInfoData);
 
     if (i != eDOMClassInfoIDCount) {
       MOZ_NOT_REACHED("The number of items in sClassInfoData doesn't match the "
--- a/dom/base/nsDOMClassInfoClasses.h
+++ b/dom/base/nsDOMClassInfoClasses.h
@@ -416,9 +416,10 @@ DOMCI_CLASS(MozActivity)
 #endif
 
 #ifdef MOZ_TIME_MANAGER
 DOMCI_CLASS(MozTimeManager)
 #endif
 
 #ifdef MOZ_WEBRTC
 DOMCI_CLASS(DataChannel)
+DOMCI_CLASS(RTCPeerConnection)
 #endif
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -234,23 +234,17 @@ function PeerConnection() {
   // Data channel.
   this.ondatachannel = null;
   this.onconnection = null;
   this.onclosedconnection = null;
 }
 PeerConnection.prototype = {
   classID: PC_CID,
 
-  classInfo: XPCOMUtils.generateCI({classID: PC_CID,
-                                    contractID: PC_CONTRACT,
-                                    classDescription: "PeerConnection",
-                                    interfaces: [
-                                      Ci.nsIDOMRTCPeerConnection
-                                    ],
-                                    flags: Ci.nsIClassInfo.DOM_OBJECT}),
+  classInfo: Cu.getDOMClassInfo("RTCPeerConnection"),
 
   QueryInterface: XPCOMUtils.generateQI([
     Ci.nsIDOMRTCPeerConnection,
     Ci.nsIDOMGlobalObjectConstructor,
     Ci.nsISupportsWeakReference
   ]),
 
   // Constructor is an explicit function, because of nsIDOMGlobalObjectConstructor.
--- a/dom/media/tests/mochitest/Makefile.in
+++ b/dom/media/tests/mochitest/Makefile.in
@@ -24,16 +24,17 @@ MOCHITEST_FILES = \
   test_getUserMedia_stopVideoStreamWithFollowupVideo.html \
   test_getUserMedia_stopVideoAudioStreamWithFollowupVideoAudio.html \
   test_getUserMedia_stopVideoStream.html \
   test_getUserMedia_stopVideoAudioStream.html \
   test_peerConnection_basicAudio.html \
   test_peerConnection_basicAudioVideo.html \
   test_peerConnection_basicAudioVideoCombined.html \
   test_peerConnection_basicVideo.html \
+  test_peerConnection_bug822674.html \
   test_peerConnection_bug827843.html \
   test_peerConnection_bug825703.html \
   test_peerConnection_bug834153.html \
   test_peerConnection_bug840344.html \
   head.js \
   mediaStreamPlayback.js \
   pc.js \
   $(NULL)
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_bug822674.html
@@ -0,0 +1,33 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=822674
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for Bug 822674</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="head.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript">
+
+  /** Test for Bug 822674 **/
+  runTest(function() {
+    var pc = new mozRTCPeerConnection();
+    pc.thereIsNeverGoingToBeAPropertyWithThisNameOnThisInterface = 1;
+    is(pc.thereIsNeverGoingToBeAPropertyWithThisNameOnThisInterface, 1,
+       "Can set expandos on an RTCPeerConnection")
+    SimpleTest.finish();
+  });
+  </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=822674">Mozilla Bug 822674</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -8,16 +8,17 @@
 #include "xpcjsid.idl"
 #include "nsIComponentManager.idl"
 
 %{C++
 #include "jspubtd.h"
 %}
 
 interface xpcIJSWeakReference;
+interface nsIClassInfo;
 
 /**
 * interface of Components.interfacesByID
 * (interesting stuff only reflected into JavaScript)
 */
 [scriptable, uuid(c99cffac-5aed-4267-ad2f-f4a4c9d4a081)]
 interface nsIXPCComponents_InterfacesByID : nsISupports
 {
@@ -113,17 +114,17 @@ interface nsIXPCComponents_utils_Sandbox
 interface ScheduledGCCallback : nsISupports
 {
     void callback();
 };
 
 /**
 * interface of Components.utils
 */
-[scriptable, uuid(0d0fd2f7-3250-4092-9340-ca9bcb7be470)]
+[scriptable, uuid(5b62c98f-5ff8-41f9-bcb8-a24d1b4255d4)]
 interface nsIXPCComponents_Utils : nsISupports
 {
 
     /* reportError is designed to be called from JavaScript only.
      *
      * It will report a JS Error object to the JS console, and return. It
      * is meant for use in exception handler blocks which want to "eat"
      * an exception, but still want to report it to the console.
@@ -397,17 +398,26 @@ interface nsIXPCComponents_Utils : nsISu
     attribute boolean ion;
 
     [implicit_jscontext]
     void setGCZeal(in long zeal);
 
     [implicit_jscontext]
     void nukeSandbox(in jsval obj);
 
+    /**
+     * Check whether the given object is an XrayWrapper.
+     */
     bool isXrayWrapper(in jsval obj);
+
+    /**
+     * Get a DOM classinfo for the given classname.  Only some class
+     * names are supported.
+     */
+    nsIClassInfo getDOMClassInfo(in AString aClassName);
 };
 
 /**
 * interface of JavaScript's 'Components' object
 */
 [scriptable, uuid(8406dedb-23cc-42db-9f69-1f18785091b5)]
 interface nsIXPCComponents : nsISupports
 {
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -29,16 +29,17 @@
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/Preferences.h"
 #include "nsPrincipal.h"
 #include "mozilla/Attributes.h"
 #include "nsIScriptContext.h"
 #include "nsJSEnvironment.h"
 #include "nsXMLHttpRequest.h"
 #include "mozilla/Telemetry.h"
+#include "nsDOMClassInfoID.h"
 
 using namespace mozilla;
 using namespace js;
 using namespace xpc;
 
 using mozilla::dom::DestroyProtoAndIfaceCache;
 
 /***************************************************************************/
@@ -4523,16 +4524,32 @@ nsXPCComponents_Utils::NukeSandbox(const
 NS_IMETHODIMP
 nsXPCComponents_Utils::IsXrayWrapper(const JS::Value &obj, bool* aRetval)
 {
     *aRetval =
         obj.isObject() && xpc::WrapperFactory::IsXrayWrapper(&obj.toObject());
     return NS_OK;
 }
 
+NS_IMETHODIMP
+nsXPCComponents_Utils::GetDOMClassInfo(const nsAString& aClassName,
+                                       nsIClassInfo** aClassInfo)
+{
+#ifdef MOZ_WEBRTC
+    if (aClassName.EqualsLiteral("RTCPeerConnection")) {
+        NS_ADDREF(*aClassInfo =
+                  NS_GetDOMClassInfoInstance(eDOMClassInfo_RTCPeerConnection_id));
+        return NS_OK;
+    }
+#endif
+
+    *aClassInfo = nullptr;
+    return NS_ERROR_NOT_AVAILABLE;
+}
+
 /***************************************************************************/
 /***************************************************************************/
 /***************************************************************************/
 
 // XXXjband We ought to cache the wrapper in the object's slots rather than
 // re-wrapping on demand
 
 NS_INTERFACE_MAP_BEGIN(nsXPCComponents)