Bug 835712 - Use more webidl for safer JS traversal. r=bz, r=jesup
authorJan-Ivar Bruaroey <jib@mozilla.com>
Wed, 13 Feb 2013 14:26:30 -0500
changeset 122190 2a21768b10f09722018659cbeef5eb8a577e2f57
parent 122189 f213ceb739aa7d812a30eecf52f42c148de616e4
child 122191 5faf053cccaf361b0cbc2ea1f375cdd612fb194a
push id24322
push userdbaron@mozilla.com
push dateMon, 18 Feb 2013 08:55:11 +0000
treeherdermozilla-central@0acbd06d48a9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, jesup
bugs835712
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 835712 - Use more webidl for safer JS traversal. r=bz, r=jesup
dom/webidl/DummyBinding.webidl
dom/webidl/RTCConfiguration.webidl
dom/webidl/WebIDL.mk
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
media/webrtc/signaling/test/signaling_unittests.cpp
--- a/dom/webidl/DummyBinding.webidl
+++ b/dom/webidl/DummyBinding.webidl
@@ -5,16 +5,16 @@
  */
 
 // Dummy bindings that we need to force generation of things that
 // aren't actually referenced anywhere in IDL yet but are used in C++.
 
 interface DummyInterface {
   readonly attribute OnErrorEventHandlerNonNull onErrorEventHandler;
   FilePropertyBag fileBag();
-  RTCIceServer rtcIceServer();
+  RTCConfiguration rtcConfiguration();
   CFStateChangeEventDict cfstateChangeEvent();
   USSDReceivedEventDict ussdReceivedEvent();
 };
 
 interface DummyInterfaceWorkers {
   BlobPropertyBag blobBag();
 };
new file mode 100644
--- /dev/null
+++ b/dom/webidl/RTCConfiguration.webidl
@@ -0,0 +1,14 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/.
+ */
+
+dictionary RTCIceServer {
+    DOMString  url;
+    DOMString? credential = null;
+};
+
+dictionary RTCConfiguration {
+    sequence<RTCIceServer> iceServers;
+};
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -119,17 +119,17 @@ webidl_files = \
   PaintRequestList.webidl \
   PannerNode.webidl \
   Performance.webidl \
   PerformanceNavigation.webidl \
   PerformanceTiming.webidl \
   ProcessingInstruction.webidl \
   Rect.webidl \
   RGBColor.webidl \
-  RTCIceServer.webidl \
+  RTCConfiguration.webidl \
   Screen.webidl \
   SVGAElement.webidl \
   SVGAltGlyphElement.webidl \
   SVGAngle.webidl \
   SVGAnimatedAngle.webidl \
   SVGAnimatedBoolean.webidl \
   SVGAnimatedLength.webidl \
   SVGAnimatedLengthList.webidl \
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -38,17 +38,17 @@
 #ifdef MOZILLA_INTERNAL_API
 #include "nsContentUtils.h"
 #include "nsDOMJSUtils.h"
 #include "nsIScriptError.h"
 #include "nsPrintfCString.h"
 #include "nsURLHelper.h"
 #include "nsNetUtil.h"
 #include "mozilla/dom/BindingUtils.h"
-#include "mozilla/dom/RTCIceServerBinding.h"
+#include "mozilla/dom/RTCConfigurationBinding.h"
 #include "MediaStreamList.h"
 #include "nsIScriptGlobalObject.h"
 #include "jsapi.h"
 #endif
 
 #ifndef USE_FAKE_MEDIA_STREAMS
 #include "MediaSegment.h"
 #endif
@@ -342,53 +342,40 @@ Warn(JSContext* aCx, const nsCString& aM
 
 /**
  * In JS, an RTCConfiguration looks like this:
  *
  * { "iceServers": [ { url:"stun:23.21.150.121" },
  *                   { url:"turn:user@turn.example.org", credential:"mypass"} ] }
  *
  * This function converts an already-validated jsval that looks like the above
- * into an RTCConfiguration object.
+ * into an IceConfiguration object.
  */
 nsresult
 PeerConnectionImpl::ConvertRTCConfiguration(const JS::Value& aSrc,
-                                            RTCConfiguration *aDst,
+                                            IceConfiguration *aDst,
                                             JSContext* aCx)
 {
 #ifdef MOZILLA_INTERNAL_API
   if (!aSrc.isObject()) {
     return NS_ERROR_FAILURE;
   }
-  JSObject& config = aSrc.toObject();
-  JSAutoCompartment ac(aCx, &config);
-  JS::Value jsServers;
-  if (!(JS_GetProperty(aCx, &config, "iceServers", &jsServers) && jsServers.isObject())) {
-    return NS_ERROR_FAILURE;
-  }
-  JSObject& servers = jsServers.toObject();
-  uint32_t len;
-  if (!(IsArrayLike(aCx, &servers) && JS_GetArrayLength(aCx, &servers, &len))) {
+  JSAutoCompartment ac(aCx, &aSrc.toObject());
+  RTCConfiguration config;
+  if (!(config.Init(aCx, nullptr, aSrc) && config.mIceServers.WasPassed())) {
     return NS_ERROR_FAILURE;
   }
-  for (uint32_t i = 0; i < len; i++) {
-    nsresult rv;
-    // XXXbz once this moves to WebIDL, remove the RTCIceServer hack
-    // in DummyBinding.webidl.
-    RTCIceServer server;
-    {
-      JS::Value v;
-      if (!(JS_GetElement(aCx, &servers, i, &v) && server.Init(aCx, nullptr, v))) {
-        return NS_ERROR_FAILURE;
-      }
-    }
+  for (uint32_t i = 0; i < config.mIceServers.Value().Length(); i++) {
+    // XXXbz once this moves to WebIDL, remove RTCConfiguration in DummyBinding.webidl.
+    RTCIceServer& server = config.mIceServers.Value()[i];
     if (!server.mUrl.WasPassed()) {
       return NS_ERROR_FAILURE;
     }
     nsRefPtr<nsIURI> url;
+    nsresult rv;
     rv = NS_NewURI(getter_AddRefs(url), server.mUrl.Value());
     NS_ENSURE_SUCCESS(rv, rv);
     bool isStun = false, isStuns = false, isTurn = false, isTurns = false;
     url->SchemeIs("stun", &isStun);
     url->SchemeIs("stuns", &isStuns);
     url->SchemeIs("turn", &isTurn);
     url->SchemeIs("turns", &isTurns);
     if (!(isStun || isStuns || isTurn || isTurns)) {
@@ -445,17 +432,17 @@ PeerConnectionImpl::Initialize(IPeerConn
                                JSContext* aCx)
 {
   return Initialize(aObserver, aWindow, nullptr, &aRTCConfiguration, aThread, aCx);
 }
 
 nsresult
 PeerConnectionImpl::Initialize(IPeerConnectionObserver* aObserver,
                                nsIDOMWindow* aWindow,
-                               const RTCConfiguration* aConfiguration,
+                               const IceConfiguration* aConfiguration,
                                const JS::Value* aRTCConfiguration,
                                nsIThread* aThread,
                                JSContext* aCx)
 {
   nsresult res;
 
 #ifdef MOZILLA_INTERNAL_API
   MOZ_ASSERT(NS_IsMainThread());
@@ -495,17 +482,17 @@ PeerConnectionImpl::Initialize(IPeerConn
   }
 
   // Connect ICE slots.
   mMedia->SignalIceGatheringCompleted.connect(this, &PeerConnectionImpl::IceGatheringCompleted);
   mMedia->SignalIceCompleted.connect(this, &PeerConnectionImpl::IceCompleted);
 
   // Initialize the media object.
   if (aRTCConfiguration) {
-    RTCConfiguration ic;
+    IceConfiguration ic;
     res = ConvertRTCConfiguration(*aRTCConfiguration, &ic, aCx);
     NS_ENSURE_SUCCESS(res, res);
     res = mMedia->Init(ic.getServers());
   } else {
     res = mMedia->Init(aConfiguration->getServers());
   }
   if (NS_FAILED(res)) {
     CSFLogError(logTag, "%s: Couldn't initialize media object", __FUNCTION__);
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
@@ -60,17 +60,17 @@ public:
   void setBooleanConstraint(const std::string& constraint, bool enabled, bool mandatory);
 
   void buildArray(cc_media_constraints_t** constraintarray);
 
 private:
   constraints_map  mConstraints;
 };
 
-class RTCConfiguration
+class IceConfiguration
 {
 public:
   bool addServer(const std::string& addr, uint16_t port)
   {
     NrIceStunServer* server(NrIceStunServer::Create(addr, port));
     if (!server) {
       return false;
     }
@@ -136,17 +136,17 @@ public:
     kRoleAnswerer
   };
 
   NS_DECL_ISUPPORTS
   NS_DECL_IPEERCONNECTION
 
   static PeerConnectionImpl* CreatePeerConnection();
   static nsresult ConvertRTCConfiguration(const JS::Value& aSrc,
-    RTCConfiguration *aDst, JSContext* aCx);
+    IceConfiguration *aDst, JSContext* aCx);
   static nsresult ConvertConstraints(
     const JS::Value& aConstraints, MediaConstraints* aObj, JSContext* aCx);
   static nsresult MakeMediaStream(nsIDOMWindow* aWindow,
                                   uint32_t aHint, nsIDOMMediaStream** aStream);
 
   Role GetRole() const {
     PC_AUTO_ENTER_API_CALL_NO_CHECK();
     return mRole;
@@ -204,35 +204,35 @@ public:
   // Create a fake media stream
   nsresult CreateFakeMediaStream(uint32_t hint, nsIDOMMediaStream** retval);
 
   nsPIDOMWindow* GetWindow() const {
     PC_AUTO_ENTER_API_CALL_NO_CHECK();
     return mWindow;
   }
 
-  // Initialize PeerConnection from an RTCConfiguration object.
+  // Initialize PeerConnection from an IceConfiguration object.
   nsresult Initialize(IPeerConnectionObserver* aObserver,
                       nsIDOMWindow* aWindow,
-                      const RTCConfiguration& aConfiguration,
+                      const IceConfiguration& aConfiguration,
                       nsIThread* aThread) {
     return Initialize(aObserver, aWindow, &aConfiguration, nullptr, aThread, nullptr);
   }
 
   // Validate constraints and construct a MediaConstraints object
   // from a JS::Value.
   NS_IMETHODIMP CreateOffer(MediaConstraints& aConstraints);
   NS_IMETHODIMP CreateAnswer(MediaConstraints& aConstraints);
 
 private:
   PeerConnectionImpl(const PeerConnectionImpl&rhs);
   PeerConnectionImpl& operator=(PeerConnectionImpl);
   nsresult Initialize(IPeerConnectionObserver* aObserver,
                       nsIDOMWindow* aWindow,
-                      const RTCConfiguration* aConfiguration,
+                      const IceConfiguration* aConfiguration,
                       const JS::Value* aRTCConfiguration,
                       nsIThread* aThread,
                       JSContext* aCx);
   NS_IMETHODIMP CreateOfferInt(MediaConstraints& constraints);
   NS_IMETHODIMP CreateAnswerInt(MediaConstraints& constraints);
 
   nsresult CloseInt(bool aIsSynchronous);
   void ChangeReadyState(ReadyState aReadyState);
--- a/media/webrtc/signaling/test/signaling_unittests.cpp
+++ b/media/webrtc/signaling/test/signaling_unittests.cpp
@@ -529,17 +529,17 @@ class SignalingAgent {
   void Init_m(nsCOMPtr<nsIThread> thread)
   {
     pc = sipcc::PeerConnectionImpl::CreatePeerConnection();
     ASSERT_TRUE(pc);
 
     pObserver = new TestObserver(pc);
     ASSERT_TRUE(pObserver);
 
-    sipcc::RTCConfiguration cfg;
+    sipcc::IceConfiguration cfg;
     cfg.addServer("23.21.150.121", 3478);
     ASSERT_EQ(pc->Initialize(pObserver, nullptr, cfg, thread), NS_OK);
 
   }
 
   void Init(nsCOMPtr<nsIThread> thread)
   {
     thread->Dispatch(
@@ -557,17 +557,17 @@ class SignalingAgent {
     pc = sipcc::PeerConnectionImpl::CreatePeerConnection();
     if (!pc)
       return false;
 
     pObserver = new TestObserver(pc);
     if (!pObserver)
       return false;
 
-    sipcc::RTCConfiguration cfg;
+    sipcc::IceConfiguration cfg;
     cfg.addServer("23.21.150.121", 3478);
     if (NS_FAILED(pc->Initialize(pObserver, nullptr, cfg, thread)))
       return false;
 
     return true;
   }
 
   bool InitAllowFail(nsCOMPtr<nsIThread> thread)