Bug 1189060 - add CreateOfferRequest.webidl interface for add-ons r=florian,peterv a=sylvestre
authorJan-Ivar Bruaroey <jib@mozilla.com>
Tue, 11 Aug 2015 13:48:55 -0400
changeset 288817 1c9bbc9454dbeff074cd3a542e291fa058f7ab06
parent 288816 00baa70421f03f8e8bb8be9276abed3207cb5a1c
child 288818 ffdc61617a74ff24f5b3a7b5446445d15eece9d9
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian, peterv, sylvestre
bugs1189060
milestone42.0a2
Bug 1189060 - add CreateOfferRequest.webidl interface for add-ons r=florian,peterv a=sylvestre
browser/modules/ContentWebRTC.jsm
browser/modules/webrtcUI.jsm
dom/media/PeerConnection.js
dom/media/PeerConnection.manifest
dom/webidl/CreateOfferRequest.webidl
dom/webidl/moz.build
--- a/browser/modules/ContentWebRTC.jsm
+++ b/browser/modules/ContentWebRTC.jsm
@@ -72,30 +72,28 @@ this.ContentWebRTC = {
       case "webrtc:StopSharing":
         Services.obs.notifyObservers(null, "getUserMedia:revoke", aMessage.data);
         break;
     }
   }
 };
 
 function handlePCRequest(aSubject, aTopic, aData) {
-  // Need to access JS object behind XPCOM wrapper added by observer API (using a
-  // WebIDL interface didn't work here as object comes from JSImplemented code).
-  aSubject = aSubject.wrappedJSObject;
-  let { windowID, callID, isSecure } = aSubject;
+  let { windowID, innerWindowID, callID, isSecure } = aSubject;
   let contentWindow = Services.wm.getOuterWindowWithId(windowID);
 
   if (!contentWindow.pendingPeerConnectionRequests) {
     setupPendingListsInitially(contentWindow);
   }
   contentWindow.pendingPeerConnectionRequests.add(callID);
 
   let request = {
+    windowID: windowID,
+    innerWindowID: innerWindowID,
     callID: callID,
-    windowID: windowID,
     documentURI: contentWindow.document.documentURI,
     secure: isSecure,
   };
 
   let mm = getMessageManagerForWindow(contentWindow);
   mm.sendAsyncMessage("rtcpeer:Request", request);
 }
 
--- a/browser/modules/webrtcUI.jsm
+++ b/browser/modules/webrtcUI.jsm
@@ -151,20 +151,24 @@ this.webrtcUI = {
       //   --------------------------------------------------------------
       //   No IP leaked yet + No gUM granted        Warn user
       //   No IP leaked yet + gUM granted           Avoid extra dialog
       //   No IP leaked yet + gUM request pending.  Delay until gUM grant
       //   IP already leaked                        Too late to warn
 
       case "rtcpeer:Request": {
         // Always allow. This code-point exists for add-ons to override.
-        let request = aMessage.data;
+        let { callID, windowID } = aMessage.data;
+        // Also available: isSecure, innerWindowID. For contentWindow:
+        //
+        //   let contentWindow = Services.wm.getOuterWindowWithId(windowID);
+
         let mm = aMessage.target.messageManager;
-        mm.sendAsyncMessage("rtcpeer:Allow", { callID: request.callID,
-                                               windowID: request.windowID });
+        mm.sendAsyncMessage("rtcpeer:Allow",
+                            { callID: callID, windowID: windowID });
         break;
       }
       case "rtcpeer:CancelRequest":
         // No data to release. This code-point exists for add-ons to override.
         break;
       case "webrtc:Request":
         prompt(aMessage.target, aMessage.data);
         break;
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -20,26 +20,28 @@ const PC_CONTRACT = "@mozilla.org/dom/pe
 const PC_OBS_CONTRACT = "@mozilla.org/dom/peerconnectionobserver;1";
 const PC_ICE_CONTRACT = "@mozilla.org/dom/rtcicecandidate;1";
 const PC_SESSION_CONTRACT = "@mozilla.org/dom/rtcsessiondescription;1";
 const PC_MANAGER_CONTRACT = "@mozilla.org/dom/peerconnectionmanager;1";
 const PC_STATS_CONTRACT = "@mozilla.org/dom/rtcstatsreport;1";
 const PC_STATIC_CONTRACT = "@mozilla.org/dom/peerconnectionstatic;1";
 const PC_SENDER_CONTRACT = "@mozilla.org/dom/rtpsender;1";
 const PC_RECEIVER_CONTRACT = "@mozilla.org/dom/rtpreceiver;1";
+const PC_COREQUEST_CONTRACT = "@mozilla.org/dom/createofferrequest;1";
 
 const PC_CID = Components.ID("{bdc2e533-b308-4708-ac8e-a8bfade6d851}");
 const PC_OBS_CID = Components.ID("{d1748d4c-7f6a-4dc5-add6-d55b7678537e}");
 const PC_ICE_CID = Components.ID("{02b9970c-433d-4cc2-923d-f7028ac66073}");
 const PC_SESSION_CID = Components.ID("{1775081b-b62d-4954-8ffe-a067bbf508a7}");
 const PC_MANAGER_CID = Components.ID("{7293e901-2be3-4c02-b4bd-cbef6fc24f78}");
 const PC_STATS_CID = Components.ID("{7fe6e18b-0da3-4056-bf3b-440ef3809e06}");
 const PC_STATIC_CID = Components.ID("{0fb47c47-a205-4583-a9fc-cbadf8c95880}");
 const PC_SENDER_CID = Components.ID("{4fff5d46-d827-4cd4-a970-8fd53977440e}");
 const PC_RECEIVER_CID = Components.ID("{d974b814-8fde-411c-8c45-b86791b81030}");
+const PC_COREQUEST_CID = Components.ID("{74b2122d-65a8-4824-aa9e-3d664cb75dc2}");
 
 // Global list of PeerConnection objects, so they can be cleaned up when
 // a page is torn down. (Maps inner window ID to an array of PC objects).
 function GlobalPCList() {
   this._list = {};
   this._networkdown = false; // XXX Need to query current state somehow
   this._lifecycleobservers = {};
   this._nextId = 1;
@@ -778,21 +780,20 @@ RTCPeerConnection.prototype = {
     if (AppConstants.MOZ_B2G ||
         Services.prefs.getBoolPref("media.navigator.permission.disabled")) {
       return this._havePermission = Promise.resolve();
     }
     return this._havePermission = new Promise((resolve, reject) => {
       this._settlePermission = { allow: resolve, deny: reject };
       let outerId = this._win.QueryInterface(Ci.nsIInterfaceRequestor).
           getInterface(Ci.nsIDOMWindowUtils).outerWindowID;
-      let request = { windowID: outerId,
-                      innerWindowId: this._winID,
-                      callID: this._globalPCListId,
-                      isSecure: this._https };
-      request.wrappedJSObject = request;
+
+      let chrome = new CreateOfferRequest(outerId, this._winID,
+                                                 this._globalPCListId, false);
+      let request = this._win.CreateOfferRequest._create(this._win, chrome);
       Services.obs.notifyObservers(request, "PeerConnection:request", null);
     });
   },
 
   setLocalDescription: function(desc, onSuccess, onError) {
     return this._legacyCatch(onSuccess, onError, () => {
       this._localType = desc.type;
 
@@ -1484,19 +1485,33 @@ function RTCRtpReceiver(pc, track) {
 }
 RTCRtpReceiver.prototype = {
   classDescription: "RTCRtpReceiver",
   classID: PC_RECEIVER_CID,
   contractID: PC_RECEIVER_CONTRACT,
   QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
 };
 
+function CreateOfferRequest(windowID, innerWindowID, callID, isSecure) {
+  this.windowID = windowID;
+  this.innerWindowID = innerWindowID;
+  this.callID = callID;
+  this.isSecure = isSecure;
+}
+CreateOfferRequest.prototype = {
+  classDescription: "CreateOfferRequest",
+  classID: PC_COREQUEST_CID,
+  contractID: PC_COREQUEST_CONTRACT,
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
+};
+
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory(
   [GlobalPCList,
    RTCIceCandidate,
    RTCSessionDescription,
    RTCPeerConnection,
    RTCPeerConnectionStatic,
    RTCRtpReceiver,
    RTCRtpSender,
    RTCStatsReport,
-   PeerConnectionObserver]
+   PeerConnectionObserver,
+   CreateOfferRequest]
 );
--- a/dom/media/PeerConnection.manifest
+++ b/dom/media/PeerConnection.manifest
@@ -2,18 +2,20 @@ component {bdc2e533-b308-4708-ac8e-a8bfa
 component {d1748d4c-7f6a-4dc5-add6-d55b7678537e} PeerConnection.js
 component {02b9970c-433d-4cc2-923d-f7028ac66073} PeerConnection.js
 component {1775081b-b62d-4954-8ffe-a067bbf508a7} PeerConnection.js
 component {7293e901-2be3-4c02-b4bd-cbef6fc24f78} PeerConnection.js
 component {7fe6e18b-0da3-4056-bf3b-440ef3809e06} PeerConnection.js
 component {0fb47c47-a205-4583-a9fc-cbadf8c95880} PeerConnection.js
 component {4fff5d46-d827-4cd4-a970-8fd53977440e} PeerConnection.js
 component {d974b814-8fde-411c-8c45-b86791b81030} PeerConnection.js
+component {74b2122d-65a8-4824-aa9e-3d664cb75dc2} PeerConnection.js
 
 contract @mozilla.org/dom/peerconnection;1 {bdc2e533-b308-4708-ac8e-a8bfade6d851}
 contract @mozilla.org/dom/peerconnectionobserver;1 {d1748d4c-7f6a-4dc5-add6-d55b7678537e}
 contract @mozilla.org/dom/rtcicecandidate;1 {02b9970c-433d-4cc2-923d-f7028ac66073}
 contract @mozilla.org/dom/rtcsessiondescription;1 {1775081b-b62d-4954-8ffe-a067bbf508a7}
 contract @mozilla.org/dom/peerconnectionmanager;1 {7293e901-2be3-4c02-b4bd-cbef6fc24f78}
 contract @mozilla.org/dom/rtcstatsreport;1 {7fe6e18b-0da3-4056-bf3b-440ef3809e06}
 contract @mozilla.org/dom/peerconnectionstatic;1 {0fb47c47-a205-4583-a9fc-cbadf8c95880}
 contract @mozilla.org/dom/rtpsender;1 {4fff5d46-d827-4cd4-a970-8fd53977440e}
 contract @mozilla.org/dom/rtpreceiver;1 {d974b814-8fde-411c-8c45-b86791b81030}
+contract @mozilla.org/dom/createofferrequest;1 {74b2122d-65a8-4824-aa9e-3d664cb75dc2}
new file mode 100644
--- /dev/null
+++ b/dom/webidl/CreateOfferRequest.webidl
@@ -0,0 +1,16 @@
+/* -*- 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/.
+ *
+ * This is an internal IDL file
+ */
+
+[ChromeOnly,
+ JSImplementation="@mozilla.org/dom/createofferrequest;1"]
+interface CreateOfferRequest {
+  readonly attribute unsigned long long windowID;
+  readonly attribute unsigned long long innerWindowID;
+  readonly attribute DOMString callID;
+  readonly attribute boolean isSecure;
+};
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -83,16 +83,17 @@ WEBIDL_FILES = [
     'Comment.webidl',
     'CompositionEvent.webidl',
     'Console.webidl',
     'Constraints.webidl',
     'Contacts.webidl',
     'ContainerBoxObject.webidl',
     'ConvolverNode.webidl',
     'Coordinates.webidl',
+    'CreateOfferRequest.webidl',
     'Crypto.webidl',
     'CSPDictionaries.webidl',
     'CSPReport.webidl',
     'CSS.webidl',
     'CSSAnimation.webidl',
     'CSSLexer.webidl',
     'CSSPrimitiveValue.webidl',
     'CSSRuleList.webidl',