Bug 1087744: Make JS callers of ios.newChannel call ios.newChannel2 in toolkit/ (r=gijs)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Fri, 24 Oct 2014 15:25:34 -0700
changeset 228584 91100de4f2ad561068c9639705633c7e800c8656
parent 228583 35e75bce4db42b46aa307e41737dd983cf9fceea
child 228585 a4786600afa56d4c62a367746cca690502cf27e3
push id28264
push usercbook@mozilla.com
push dateWed, 11 Feb 2015 13:58:35 +0000
treeherdermozilla-central@38058cb42a0e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgijs
bugs1087744
milestone38.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 1087744: Make JS callers of ios.newChannel call ios.newChannel2 in toolkit/ (r=gijs)
toolkit/components/aboutmemory/content/aboutMemory.js
toolkit/components/search/nsSearchService.js
toolkit/components/thumbnails/PageThumbsProtocol.js
toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
toolkit/mozapps/extensions/internal/LightweightThemeImageOptimizer.jsm
toolkit/mozapps/extensions/internal/XPIProvider.jsm
toolkit/mozapps/update/nsUpdateService.js
--- a/toolkit/components/aboutmemory/content/aboutMemory.js
+++ b/toolkit/components/aboutmemory/content/aboutMemory.js
@@ -665,17 +665,22 @@ function loadMemoryReportsFromFile(aFile
           reader.readAsText(new Blob(this.data));
         } catch (ex) {
           handleException(ex);
         }
       }
     }, null);
 
     let file = new nsFile(aFilename);
-    let fileChan = Services.io.newChannelFromURI(Services.io.newFileURI(file));
+    let fileChan = Services.io.newChannelFromURI2(Services.io.newFileURI(file),
+                                                  null,      // aLoadingNode
+                                                  Services.scriptSecurityManager.getSystemPrincipal(),
+                                                  null,      // aTriggeringPrincipal
+                                                  Ci.nsILoadInfo.SEC_NORMAL,
+                                                  Ci.nsIContentPolicy.TYPE_OTHER);
     fileChan.asyncOpen(converter, null);
 
   } catch (ex) {
     handleException(ex);
   }
 }
 
 /**
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -1450,17 +1450,22 @@ Engine.prototype = {
    */
   _initFromURIAndLoad: function SRCH_ENG_initFromURIAndLoad() {
     ENSURE_WARN(this._uri instanceof Ci.nsIURI,
                 "Must have URI when calling _initFromURIAndLoad!",
                 Cr.NS_ERROR_UNEXPECTED);
 
     LOG("_initFromURIAndLoad: Downloading engine from: \"" + this._uri.spec + "\".");
 
-    var chan = NetUtil.ioService.newChannelFromURI(this._uri);
+    var chan = NetUtil.ioService.newChannelFromURI2(this._uri,
+                                                    null,      // aLoadingNode
+                                                    Services.scriptSecurityManager.getSystemPrincipal(),
+                                                    null,      // aTriggeringPrincipal
+                                                    Ci.nsILoadInfo.SEC_NORMAL,
+                                                    Ci.nsIContentPolicy.TYPE_OTHER);
 
     if (this._engineToUpdate && (chan instanceof Ci.nsIHttpChannel)) {
       var lastModified = engineMetadataService.getAttr(this._engineToUpdate,
                                                        "updatelastmodified");
       if (lastModified)
         chan.setRequestHeader("If-Modified-Since", lastModified, false);
     }
     var listener = new loadListener(chan, this, this._onLoad);
@@ -1513,17 +1518,22 @@ Engine.prototype = {
                 "Must have URI when calling _initFromURISync!",
                 Cr.NS_ERROR_UNEXPECTED);
 
     ENSURE_WARN(this._uri.schemeIs("chrome"), "_initFromURISync called for non-chrome URI",
                 Cr.NS_ERROR_FAILURE);
 
     LOG("_initFromURISync: Loading engine from: \"" + this._uri.spec + "\".");
 
-    var chan = NetUtil.ioService.newChannelFromURI(this._uri);
+    var chan = NetUtil.ioService.newChannelFromURI2(this._uri,
+                                                    null,      // aLoadingNode
+                                                    Services.scriptSecurityManager.getSystemPrincipal(),
+                                                    null,      // aTriggeringPrincipal
+                                                    Ci.nsILoadInfo.SEC_NORMAL,
+                                                    Ci.nsIContentPolicy.TYPE_OTHER);
 
     var stream = chan.open();
     var parser = Cc["@mozilla.org/xmlextras/domparser;1"].
                  createInstance(Ci.nsIDOMParser);
     var doc = parser.parseFromStream(stream, "UTF-8", stream.available(), "text/xml");
 
     this._data = doc.documentElement;
 
@@ -1830,17 +1840,22 @@ Engine.prototype = {
       case "http":
       case "https":
       case "ftp":
         // No use downloading the icon if the engine file is read-only
         if (!this._readOnly ||
             getBoolPref(BROWSER_SEARCH_PREF + "cache.enabled", true)) {
           LOG("_setIcon: Downloading icon: \"" + uri.spec +
               "\" for engine: \"" + this.name + "\"");
-          var chan = NetUtil.ioService.newChannelFromURI(uri);
+          var chan = NetUtil.ioService.newChannelFromURI2(uri,
+                                                          null,      // aLoadingNode
+                                                          Services.scriptSecurityManager.getSystemPrincipal(),
+                                                          null,      // aTriggeringPrincipal
+                                                          Ci.nsILoadInfo.SEC_NORMAL,
+                                                          Ci.nsIContentPolicy.TYPE_IMAGE);
 
           let iconLoadCallback = function (aByteArray, aEngine) {
             // This callback may run after we've already set a preferred icon,
             // so check again.
             if (aEngine._hasPreferredIcon && !aIsPreferred)
               return;
 
             if (!aByteArray || aByteArray.length > MAX_ICON_SIZE) {
@@ -3865,17 +3880,22 @@ SearchService.prototype = {
 
       chromeFiles.push(chromeFile);
 
       // Read list.txt from the chrome package to find the engines we need to
       // load
       let listURL = root + "list.txt";
       let names = [];
       try {
-        let chan = NetUtil.ioService.newChannelFromURI(makeURI(listURL));
+        let chan = NetUtil.ioService.newChannelFromURI2(makeURI(listURL),
+                                                        null,      // aLoadingNode
+                                                        Services.scriptSecurityManager.getSystemPrincipal(),
+                                                        null,      // aTriggeringPrincipal
+                                                        Ci.nsILoadInfo.SEC_NORMAL,
+                                                        Ci.nsIContentPolicy.TYPE_OTHER);
         let sis = Cc["@mozilla.org/scriptableinputstream;1"].
                   createInstance(Ci.nsIScriptableInputStream);
         sis.init(chan.open());
         let list = sis.read(sis.available());
         names = list.split("\n").filter(function (n) !!n);
       } catch (ex) {
         LOG("_findJAREngines: failed to retrieve list.txt from " + listURL + ": " + ex);
 
@@ -4926,17 +4946,22 @@ var engineMetadataService = {
     }
     switch (this._initState) {
       case engineMetadataService._InitStates.NOT_STARTED:
         let jsonFile = new FileUtils.File(this._jsonFile);
         // 1. Load json file if it exists
         if (jsonFile.exists()) {
           try {
             let uri = Services.io.newFileURI(jsonFile);
-            let stream = Services.io.newChannelFromURI(uri).open();
+            let stream = Services.io.newChannelFromURI2(uri,
+                                                        null,      // aLoadingNode
+                                                        Services.scriptSecurityManager.getSystemPrincipal(),
+                                                        null,      // aTriggeringPrincipal
+                                                        Ci.nsILoadInfo.SEC_NORMAL,
+                                                        Ci.nsIContentPolicy.TYPE_OTHER).open();
             this._store = parseJsonFromStream(stream);
           } catch (x) {
             LOG("metadata syncInit: could not load JSON file " + x);
             this._store = {};
           }
         } else {
           LOG("metadata syncInit: using an empty store");
           this._store = {};
--- a/toolkit/components/thumbnails/PageThumbsProtocol.js
+++ b/toolkit/components/thumbnails/PageThumbsProtocol.js
@@ -73,17 +73,22 @@ Protocol.prototype = {
    * Constructs a new channel from the given URI for this protocol handler.
    * @param aURI The URI for which to construct a channel.
    * @return The newly created channel.
    */
   newChannel: function Proto_newChannel(aURI) {
     let {url} = parseURI(aURI);
     let file = PageThumbsStorage.getFilePathForURL(url);
     let fileuri = Services.io.newFileURI(new FileUtils.File(file));
-    return Services.io.newChannelFromURI(fileuri);
+    return Services.io.newChannelFromURI2(fileuri,
+                                          null,      // aLoadingNode
+                                          Services.scriptSecurityManager.getSystemPrincipal(),
+                                          null,      // aTriggeringPrincipal
+                                          Ci.nsILoadInfo.SEC_NORMAL,
+                                          Ci.nsIContentPolicy.TYPE_IMAGE);
   },
 
   /**
    * Decides whether to allow a blacklisted port.
    * @return Always false, we'll never allow ports.
    */
   allowPort: function () false,
 
--- a/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
+++ b/toolkit/components/url-classifier/nsUrlClassifierHashCompleter.js
@@ -215,17 +215,22 @@ HashCompleterRequest.prototype = {
   },
 
   // Creates an nsIChannel for the request and fills the body.
   openChannel: function HCR_openChannel() {
     let loadFlags = Ci.nsIChannel.INHIBIT_CACHING |
                     Ci.nsIChannel.LOAD_BYPASS_CACHE;
 
     let uri = Services.io.newURI(this.gethashUrl, null, null);
-    let channel = Services.io.newChannelFromURI(uri);
+    let channel = Services.io.newChannelFromURI2(uri,
+                                                 null,      // aLoadingNode
+                                                 Services.scriptSecurityManager.getSystemPrincipal(),
+                                                 null,      // aTriggeringPrincipal
+                                                 Ci.nsILoadInfo.SEC_NORMAL,
+                                                 Ci.nsIContentPolicy.TYPE_OTHER);
     channel.loadFlags = loadFlags;
 
     // Disable keepalive.
     let httpChannel = channel.QueryInterface(Ci.nsIHttpChannel);
     httpChannel.setRequestHeader("Connection", "close", false);
 
     this._channel = channel;
 
--- a/toolkit/mozapps/extensions/internal/LightweightThemeImageOptimizer.jsm
+++ b/toolkit/mozapps/extensions/internal/LightweightThemeImageOptimizer.jsm
@@ -111,24 +111,31 @@ let ImageCropper = {
 
       resetInProgress();
     });
   }
 };
 
 let ImageFile = {
   read: function ImageFile_read(aURI, aCallback) {
-    this._netUtil.asyncFetch(aURI, function read_asyncFetch(aInputStream, aStatus, aRequest) {
-      if (Components.isSuccessCode(aStatus) && aRequest instanceof Ci.nsIChannel) {
-        let channel = aRequest.QueryInterface(Ci.nsIChannel);
-        aCallback(aInputStream, channel.contentType);
-      } else {
-        aCallback();
-      }
-    });
+    this._netUtil.asyncFetch2(
+      aURI,
+      function read_asyncFetch(aInputStream, aStatus, aRequest) {
+        if (Components.isSuccessCode(aStatus) && aRequest instanceof Ci.nsIChannel) {
+          let channel = aRequest.QueryInterface(Ci.nsIChannel);
+          aCallback(aInputStream, channel.contentType);
+        } else {
+          aCallback();
+        }
+      },
+      null,      // aLoadingNode
+      Services.scriptSecurityManager.getSystemPrincipal(),
+      null,      // aTriggeringPrincipal
+      Ci.nsILoadInfo.SEC_NORMAL,
+      Ci.nsIContentPolicy.TYPE_IMAGE);
   },
 
   write: function ImageFile_write(aFile, aInputStream, aCallback) {
     let fos = FileUtils.openSafeFileOutputStream(aFile);
     this._netUtil.asyncCopy(aInputStream, fos, function write_asyncCopy(aResult) {
       FileUtils.closeSafeFileOutputStream(fos);
 
       // Remove the file if writing was not successful.
--- a/toolkit/mozapps/extensions/internal/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/internal/XPIProvider.jsm
@@ -1924,17 +1924,22 @@ this.XPIProvider = {
       case "about":
         if (aURI.spec == "about:blank") {
           // Do not attempt to map about:blank
           return null;
         }
 
         let chan;
         try {
-          chan = Services.io.newChannelFromURI(aURI);
+          chan = Services.io.newChannelFromURI2(aURI,
+                                                null,      // aLoadingNode
+                                                Services.scriptSecurityManager.getSystemPrincipal(),
+                                                null,      // aTriggeringPrincipal
+                                                Ci.nsILoadInfo.SEC_NORMAL,
+                                                Ci.nsIContentPolicy.TYPE_OTHER);
         }
         catch (ex) {
           return null;
         }
         // Avoid looping
         if (chan.URI.equals(aURI)) {
           return null;
         }
@@ -5395,17 +5400,24 @@ AddonInstall.prototype = {
     let listener = Cc["@mozilla.org/network/stream-listener-tee;1"].
                    createInstance(Ci.nsIStreamListenerTee);
     listener.init(this, this.stream);
     try {
       Components.utils.import("resource://gre/modules/CertUtils.jsm");
       let requireBuiltIn = Preferences.get(PREF_INSTALL_REQUIREBUILTINCERTS, true);
       this.badCertHandler = new BadCertHandler(!requireBuiltIn);
 
-      this.channel = NetUtil.newChannel(this.sourceURI);
+      this.channel = NetUtil.newChannel2(this.sourceURI,
+                                         null,
+                                         null,
+                                         null,      // aLoadingNode
+                                         Services.scriptSecurityManager.getSystemPrincipal(),
+                                         null,      // aTriggeringPrincipal
+                                         Ci.nsILoadInfo.SEC_NORMAL,
+                                         Ci.nsIContentPolicy.TYPE_OTHER);
       this.channel.notificationCallbacks = this;
       if (this.channel instanceof Ci.nsIHttpChannel) {
         this.channel.setRequestHeader("Moz-XPI-Update", "1", true);
         if (this.channel instanceof Ci.nsIHttpChannelInternal)
           this.channel.forceAllowThirdPartyCookie = true;
       }
       this.channel.asyncOpen(listener, null);
 
--- a/toolkit/mozapps/update/nsUpdateService.js
+++ b/toolkit/mozapps/update/nsUpdateService.js
@@ -1357,17 +1357,24 @@ function cleanupActiveUpdate() {
  * directory or the GRE directory with preference given to it being located in
  * the application directory.
  */
 function getLocale() {
   if (gLocale)
     return gLocale;
 
   for (let res of ['app', 'gre']) {
-    var channel = Services.io.newChannel("resource://" + res + "/" + FILE_UPDATE_LOCALE, null, null);
+    var channel = Services.io.newChannel2("resource://" + res + "/" + FILE_UPDATE_LOCALE,
+                                          null,
+                                          null,
+                                          null,      // aLoadingNode
+                                          Services.scriptSecurityManager.getSystemPrincipal(),
+                                          null,      // aTriggeringPrincipal
+                                          Ci.nsILoadInfo.SEC_NORMAL,
+                                          Ci.nsIContentPolicy.TYPE_DATAREQUEST);
     try {
       var inputStream = channel.open();
       gLocale = readStringFromInputStream(inputStream);
     } catch(e) {}
     if (gLocale)
       break;
   }