Bug 1087737: Make JS callers of ios.newChannel call ios.newChannel2 in mobile/ (r=wesj)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Fri, 24 Oct 2014 15:01:55 -0700
changeset 248678 e285881c00c50dd5b3cb2e8e8aff115d616f9c47
parent 248677 70bc10b845afeee83d9fa20464b0f365c9e08094
child 248679 d9306cec6ff8bba45b7584d5580819d3f5043949
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswesj
bugs1087737
milestone37.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 1087737: Make JS callers of ios.newChannel call ios.newChannel2 in mobile/ (r=wesj)
mobile/android/base/tests/testResourceSubstitutions.js
mobile/android/chrome/content/CastingApps.js
mobile/android/components/AboutRedirector.js
mobile/android/components/HelperAppDialog.js
--- a/mobile/android/base/tests/testResourceSubstitutions.js
+++ b/mobile/android/base/tests/testResourceSubstitutions.js
@@ -7,20 +7,27 @@ const { classes: Cc, interfaces: Ci, uti
 
 Cu.import("resource://gre/modules/Promise.jsm"); /*global Promise */
 Cu.import("resource://gre/modules/Services.jsm"); /*global Services */
 Cu.import("resource://gre/modules/NetUtil.jsm"); /*global NetUtil */
 
 function readChannel(url) {
   let deferred = Promise.defer();
 
-  let channel = NetUtil.newChannel(url);
+  let channel = NetUtil.newChannel2(url,
+                                    null,
+                                    null,
+                                    null,      // aLoadingNode
+                                    Services.scriptSecurityManager.getSystemPrincipal(),
+                                    null,      // aTriggeringPrincipal
+                                    Ci.nsILoadInfo.SEC_NORMAL,
+                                    Ci.nsIContentPolicy.TYPE_OTHER);
   channel.contentType = "text/plain";
 
-  NetUtil.asyncFetch(channel, function(inputStream, status) {
+  NetUtil.asyncFetch2(channel, function(inputStream, status) {
     if (!Components.isSuccessCode(status)) {
       deferred.reject();
       return;
     }
 
     let content = NetUtil.readInputStreamToString(inputStream, inputStream.available());
     deferred.resolve(content);
   });
--- a/mobile/android/chrome/content/CastingApps.js
+++ b/mobile/android/chrome/content/CastingApps.js
@@ -325,27 +325,33 @@ var CastingApps = {
           // Once we find a <video> under the overlay, we check it and exit.
           this._getVideo(element, types, extensions, aCallback);
           return;
         }
       }
     } catch(e) {}
   },
 
-  _getContentTypeForURI: function(aURI, aCallback) {
-    let channel = Services.io.newChannelFromURI(aURI);
+  _getContentTypeForURI: function(aURI, aElement, aCallback) {
+    let channel = Services.io.newChannelFromURI2(aURI,
+                                                 aElement,
+                                                 null, // aLoadingPrincipal
+                                                 null, // aTriggeringPrincipal
+                                                 Ci.nsILoadInfo.SEC_NORMAL,
+                                                 Ci.nsIContentPolicy.TYPE_OTHER);
+
     let listener = {
       onStartRequest: function(request, context) {
         switch (channel.responseStatus) {
           case 301:
           case 302:
           case 303:
             request.cancel(0);
             let location = channel.getResponseHeader("Location");
-            CastingApps._getContentTypeForURI(CastingApps.makeURI(location), aCallback);
+            CastingApps._getContentTypeForURI(CastingApps.makeURI(location), aElement, aCallback);
             break;
           default:
             aCallback(channel.contentType);
             request.cancel(0);
             break;
         }
       },
       onStopRequest: function(request, context, statusCode)  {},
@@ -416,17 +422,17 @@ var CastingApps = {
       asyncURIs.push(sourceURI);
     }
 
     // If we didn't find a good URI directly, let's look using async methods
     // As soon as we find a good sourceURL, avoid firing the callback any further
     aCallback.fired = false;
     for (let sourceURI of asyncURIs) {
       // Do an async fetch to figure out the mimetype of the source video
-      this._getContentTypeForURI(sourceURI, (aType) => {
+      this._getContentTypeForURI(sourceURI, aElement, (aType) => {
         if (!aCallback.fired && this.allowableMimeType(aType, aTypes)) {
           aCallback.fired = true;
           aCallback({ element: aElement, source: sourceURI.spec, poster: posterURL, sourceURI: sourceURI, type: aType });
         }
       });
     }
 
     // If we didn't find any castable source, let's send back a signal
--- a/mobile/android/components/AboutRedirector.js
+++ b/mobile/android/components/AboutRedirector.js
@@ -107,23 +107,25 @@ AboutRedirector.prototype = {
     let flags;
     let moduleInfo = this._getModuleInfo(aURI);
     if (moduleInfo.hide)
       flags = Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT;
 
     return flags | Ci.nsIAboutModule.ALLOW_SCRIPT;
   },
 
-  newChannel: function(aURI) {
+  newChannel: function(aURI, aLoadInfo) {
     let moduleInfo = this._getModuleInfo(aURI);
 
     var ios = Cc["@mozilla.org/network/io-service;1"].
               getService(Ci.nsIIOService);
 
-    var channel = ios.newChannel(moduleInfo.uri, null, null);
+    var newURI = ios.newURI(moduleInfo.uri, null, null);
+
+    var channel = ios.newChannelFromURIWithLoadInfo(newURI, aLoadInfo);
 
     if (!moduleInfo.privileged) {
       // Setting the owner to null means that we'll go through the normal
       // path in GetChannelPrincipal and create a codebase principal based
       // on the channel's originalURI
       channel.owner = null;
     }
 
--- a/mobile/android/components/HelperAppDialog.js
+++ b/mobile/android/components/HelperAppDialog.js
@@ -57,17 +57,22 @@ HelperAppLauncherDialog.prototype = {
         url.schemeIs("resource") ||
         url.schemeIs("wyciwyg")) {
       return false;
     }
 
     // For all other URIs, try to resolve them to an inner URI, and check that.
     if (!alreadyResolved) {
       let ioSvc = Cc["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
-      let innerURI = ioSvc.newChannelFromURI(url).URI;
+      let innerURI = ioSvc.newChannelFromURI2(url,
+                                              null,      // aLoadingNode
+                                              Services.scriptSecurityManager.getSystemPrincipal(),
+                                              null,      // aTriggeringPrincipal
+                                              Ci.nsILoadInfo.SEC_NORMAL,
+                                              Ci.nsIContentPolicy.TYPE_OTHER).URI;
       if (!url.equals(innerURI)) {
         return this._canDownload(innerURI, true);
       }
     }
 
     if (url.schemeIs("file")) {
       // If it's in our app directory or profile directory, we never ever
       // want to do anything with it, including saving to disk or passing the