Bug 1153314 - Assign load group to IdP load channel, r=jib
authorMartin Thomson <martin.thomson@gmail.com>
Wed, 15 Apr 2015 14:19:21 -0700
changeset 258327 f23689de62164560d97bb297a2e5247bc4f251ab
parent 258326 0761dba193080f2f7043dc8d465b5ad65dda57b8
child 258328 bbfa03945585e60ac1bafee72190562b6acba697
push id8007
push userraliiev@mozilla.com
push dateMon, 11 May 2015 19:23:16 +0000
treeherdermozilla-aurora@e2ce1aac996e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs1153314
milestone40.0a1
Bug 1153314 - Assign load group to IdP load channel, r=jib
dom/media/IdpSandbox.jsm
dom/media/PeerConnectionIdp.jsm
--- a/dom/media/IdpSandbox.jsm
+++ b/dom/media/IdpSandbox.jsm
@@ -35,26 +35,29 @@ RedirectHttpsOnly.prototype = {
 /** This class loads a resource into a single string. ResourceLoader.load() is
  * the entry point. */
 function ResourceLoader(res, rej) {
   this.resolve = res;
   this.reject = rej;
   this.data = '';
 }
 
-/** Loads the identified https:// URL.  */
-ResourceLoader.load = function(uri) {
+/** Loads the identified https:// URL. */
+ResourceLoader.load = function(uri, doc) {
   return new Promise((resolve, reject) => {
     let listener = new ResourceLoader(resolve, reject);
     let ioService = Cc['@mozilla.org/network/io-service;1']
       .getService(Ci.nsIIOService);
     let systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
     // the '2' identifies this as a script load
-    let ioChannel = ioService.newChannelFromURI2(uri, null, systemPrincipal,
-                                                 systemPrincipal, 0, 2);
+    let ioChannel = ioService.newChannelFromURI2(uri, doc, doc.nodePrincipal,
+                                                 systemPrincipal, 0,
+                                                 Ci.nsIContentPolicy.TYPE_SCRIPT);
+
+    ioChannel.loadGroup = doc.documentLoadGroup.QueryInterface(Ci.nsILoadGroup);
     ioChannel.notificationCallbacks = new RedirectHttpsOnly();
     ioChannel.asyncOpen(listener, null);
   });
 };
 
 ResourceLoader.prototype = {
   onDataAvailable: function(request, context, input, offset, count) {
     let stream = Cc['@mozilla.org/scriptableinputstream;1']
@@ -105,22 +108,24 @@ function createLocationFromURI(uri) {
   };
 }
 
 /**
  * A javascript sandbox for running an IdP.
  *
  * @param domain (string) the domain of the IdP
  * @param protocol (string?) the protocol of the IdP [default: 'default']
+ * @param doc (obj) the current document
  * @throws if the domain or protocol aren't valid
  */
-function IdpSandbox(domain, protocol) {
+function IdpSandbox(domain, protocol, doc) {
   this.source = IdpSandbox.createIdpUri(domain, protocol || "default");
   this.active = null;
   this.sandbox = null;
+  this.document = doc;
 }
 
 IdpSandbox.checkDomain = function(domain) {
   if (!domain || typeof domain !== 'string') {
     throw new Error('Invalid domain for identity provider: ' +
                     'must be a non-zero length string');
   }
 };
@@ -171,17 +176,17 @@ IdpSandbox.createIdpUri = function(domai
 
 IdpSandbox.prototype = {
   isSame: function(domain, protocol) {
     return this.source.spec === IdpSandbox.createIdpUri(domain, protocol).spec;
   },
 
   start: function() {
     if (!this.active) {
-      this.active = ResourceLoader.load(this.source)
+      this.active = ResourceLoader.load(this.source, this.document)
         .then(result => this._createSandbox(result));
     }
     return this.active;
   },
 
   // Provides the sandbox with some useful facilities.  Initially, this is only
   // a minimal set; it is far easier to add more as the need arises, than to
   // take them back if we discover a mistake.
--- a/dom/media/PeerConnectionIdp.jsm
+++ b/dom/media/PeerConnectionIdp.jsm
@@ -51,17 +51,17 @@ PeerConnectionIdp.prototype = {
     this.protocol = protocol || 'default';
     this.username = username;
     if (this._idp) {
       if (this._idp.isSame(provider, protocol)) {
         return; // noop
       }
       this._idp.stop();
     }
-    this._idp = new IdpSandbox(provider, protocol);
+    this._idp = new IdpSandbox(provider, protocol, this._win.document);
   },
 
   // start the IdP and do some error fixup
   start: function() {
     return this._idp.start()
       .catch(e => {
         throw new this._win.DOMException(e.message, 'IdpError');
       });