Bug 1087738: Make JS callers of ios.newChannel call ios.newChannel2 in modules/ (r=mwu)
authorChristoph Kerschbaumer <mozilla@christophkerschbaumer.com>
Fri, 24 Oct 2014 15:06:16 -0700
changeset 222883 d9306cec6ff8bba45b7584d5580819d3f5043949
parent 222882 e285881c00c50dd5b3cb2e8e8aff115d616f9c47
child 222884 afaab9b353b741c1e5e904d5e3a3806fbf0dc2af
push id10731
push usercbook@mozilla.com
push dateFri, 09 Jan 2015 14:51:37 +0000
treeherderfx-team@e6756043d930 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmwu
bugs1087738
milestone37.0a1
Bug 1087738: Make JS callers of ios.newChannel call ios.newChannel2 in modules/ (r=mwu)
modules/libjar/test/unit/test_bug370103.js
modules/libjar/test/unit/test_bug407303.js
modules/libjar/test/unit/test_bug589292.js
modules/libjar/test/unit/test_bug597702.js
modules/libjar/test/unit/test_bug637286.js
modules/libjar/test/unit/test_bug658093.js
modules/libjar/test/unit/test_jarchannel.js
modules/libjar/test/unit/test_not_found.js
modules/libjar/zipwriter/test/unit/test_asyncadd.js
--- a/modules/libjar/test/unit/test_bug370103.js
+++ b/modules/libjar/test/unit/test_bug370103.js
@@ -1,23 +1,32 @@
-var Cc = Components.classes;
-var Ci = Components.interfaces;
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+Cu.import("resource://gre/modules/Services.jsm");
 
 // Regression test for bug 370103 - crash when passing a null listener to
 // nsIChannel.asyncOpen
 function run_test() {
   // Compose the jar: url
   var ioService = Cc["@mozilla.org/network/io-service;1"].
                     getService(Ci.nsIIOService);
   var file = do_get_file("data/test_bug370103.jar");
   var url = ioService.newFileURI(file).spec;
   url = "jar:" + url + "!/test_bug370103";
 
   // Try opening channel with null listener
-  var channel = ioService.newChannel(url, null, null);
+  var channel = ioService.newChannel2(url,
+                                      null,
+                                      null,
+                                      null,      // aLoadingNode
+                                      Services.scriptSecurityManager.getSystemPrincipal(),
+                                      null,      // aTriggeringPrincipal
+                                      Ci.nsILoadInfo.SEC_NORMAL,
+                                      Ci.nsIContentPolicy.TYPE_OTHER);
 
   var exception = false;
   try {
     channel.asyncOpen(null, null);
   }
   catch(e) {
     exception = true;
   }
--- a/modules/libjar/test/unit/test_bug407303.js
+++ b/modules/libjar/test/unit/test_bug407303.js
@@ -1,13 +1,15 @@
 // Regression test for bug 407303 - A failed channel should not be checked
 // for an unsafe content type.
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
+const Cu = Components.utils;
+Cu.import("resource://gre/modules/Services.jsm");
 
 // XXX: NS_ERROR_UNKNOWN_HOST is not in Components.results
 const NS_ERROR_UNKNOWN_HOST = 0x804B001E;
 
 var listener = {
   QueryInterface: function(iid) {
     if (iid.equals(Ci.nsISupports) ||
         iid.equals(Ci.nsIRequestObserver))
@@ -27,13 +29,19 @@ var listener = {
     do_test_finished();
   }
 };
 
 function run_test() {
   var ios = Cc["@mozilla.org/network/io-service;1"].
             getService(Ci.nsIIOService);
 
-  var channel = ios.newChannel("jar:http://test.invalid/test.jar!/index.html",
-                               null, null);
+  var channel = ios.newChannel2("jar:http://test.invalid/test.jar!/index.html",
+                                null,
+                                null,
+                                null,      // aLoadingNode
+                                Services.scriptSecurityManager.getSystemPrincipal(),
+                                null,      // aTriggeringPrincipal
+                                Ci.nsILoadInfo.SEC_NORMAL,
+                                Ci.nsIContentPolicy.TYPE_OTHER);
   channel.asyncOpen(listener, null);
   do_test_pending();
 }
--- a/modules/libjar/test/unit/test_bug589292.js
+++ b/modules/libjar/test/unit/test_bug589292.js
@@ -1,19 +1,29 @@
 // Make sure we behave appropriately when asking for content-disposition
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
+const Cu = Components.utils;
+Cu.import("resource://gre/modules/Services.jsm");
+
 const path = "data/test_bug589292.zip";
 
 function run_test() {
   var ios = Cc["@mozilla.org/network/io-service;1"].
             getService(Ci.nsIIOService);
   var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/foo.txt";
-  var channel = ios.newChannel(spec, null, null);
+  var channel = ios.newChannel2(spec,
+                                null,
+                                null,
+                                null,      // aLoadingNode
+                                Services.scriptSecurityManager.getSystemPrincipal(),
+                                null,      // aTriggeringPrincipal
+                                Ci.nsILoadInfo.SEC_NORMAL,
+                                Ci.nsIContentPolicy.TYPE_OTHER);
   instr = channel.open();
   var val;
   try {
     val = channel.contentDisposition;
     do_check_true(false, "The channel has content disposition?!");
   } catch (e) {
     // This is what we want to happen - there's no underlying channel, so no
     // content-disposition header is available
--- a/modules/libjar/test/unit/test_bug597702.js
+++ b/modules/libjar/test/unit/test_bug597702.js
@@ -1,26 +1,42 @@
 /* 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/. */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
+const Cu = Components.utils;
+Cu.import("resource://gre/modules/Services.jsm");
 
 // Check that reading non existant inner jars results in the right error
 
 function run_test() {
   var file = do_get_file("data/test_bug597702.zip");
   var ios = Cc["@mozilla.org/network/io-service;1"].
             getService(Ci.nsIIOService);
   var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
   var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello";
   var badSpec = "jar:" + outerJarBase + "jar_that_isnt_in_the.jar!/hello";
-  var goodChannel = ios.newChannel(goodSpec, null, null);
-  var badChannel = ios.newChannel(badSpec, null, null);
+  var goodChannel = ios.newChannel2(goodSpec,
+                                    null,
+                                    null,
+                                    null,      // aLoadingNode
+                                    Services.scriptSecurityManager.getSystemPrincipal(),
+                                    null,      // aTriggeringPrincipal
+                                    Ci.nsILoadInfo.SEC_NORMAL,
+                                    Ci.nsIContentPolicy.TYPE_OTHER);
+  var badChannel = ios.newChannel2(badSpec,
+                                   null,
+                                   null,
+                                   null,      // aLoadingNode
+                                   Services.scriptSecurityManager.getSystemPrincipal(),
+                                   null,      // aTriggeringPrincipal
+                                   Ci.nsILoadInfo.SEC_NORMAL,
+                                   Ci.nsIContentPolicy.TYPE_OTHER);
 
   try {
     instr = goodChannel.open();
   } catch (e) {
     do_throw("Failed to open file in inner jar");
   }
 
   try {
--- a/modules/libjar/test/unit/test_bug637286.js
+++ b/modules/libjar/test/unit/test_bug637286.js
@@ -1,22 +1,31 @@
 /* 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/. */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
+const Cu = Components.utils;
+Cu.import("resource://gre/modules/Services.jsm");
 
 // Check that the zip cache can expire entries from nested jars
 var ios = Cc["@mozilla.org/network/io-service;1"].
           getService(Ci.nsIIOService);
 
 function open_inner_zip(base, idx) {
     var spec = "jar:" + base + "inner" + idx + ".zip!/foo";
-    var channel = ios.newChannel(spec, null, null);
+    var channel = ios.newChannel2(spec,
+                                  null,
+                                  null,
+                                  null,      // aLoadingNode
+                                  Services.scriptSecurityManager.getSystemPrincipal(),
+                                  null,      // aTriggeringPrincipal
+                                  Ci.nsILoadInfo.SEC_NORMAL,
+                                  Ci.nsIContentPolicy.TYPE_OTHER);
     var stream = channel.open();
 }
 
 function run_test() {
   var file = do_get_file("data/test_bug637286.zip");
   var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
 
   for (var i = 0; i < 40; i++) {
--- a/modules/libjar/test/unit/test_bug658093.js
+++ b/modules/libjar/test/unit/test_bug658093.js
@@ -1,23 +1,32 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
+const Cu = Components.utils;
+Cu.import("resource://gre/modules/Services.jsm");
 
 // Check that we don't crash on reading a directory entry signature
 var ios = Cc["@mozilla.org/network/io-service;1"].
           getService(Ci.nsIIOService);
 
 function run_test() {
   var file = do_get_file("data/test_bug658093.zip");
   var spec = "jar:" + ios.newFileURI(file).spec + "!/0000";
-  var channel = ios.newChannel(spec, null, null);
+  var channel = ios.newChannel2(spec,
+                                null,
+                                null,
+                                null,      // aLoadingNode
+                                Services.scriptSecurityManager.getSystemPrincipal(),
+                                null,      // aTriggeringPrincipal
+                                Ci.nsILoadInfo.SEC_NORMAL,
+                                Ci.nsIContentPolicy.TYPE_OTHER);
   var failed = false;
   try {
     var stream = channel.open();
   } catch (e) {
     failed = true;
   }
   do_check_true(failed);
 }
--- a/modules/libjar/test/unit/test_jarchannel.js
+++ b/modules/libjar/test/unit/test_jarchannel.js
@@ -5,19 +5,22 @@
 /**
  * Tests some basic jar channel functionality
  */
 
 
 const {classes: Cc,
        interfaces: Ci,
        results: Cr,
+       utils: Cu,
        Constructor: ctor
        } = Components;
 
+Cu.import("resource://gre/modules/Services.jsm");
+
 const ios = Cc["@mozilla.org/network/io-service;1"].
                 getService(Ci.nsIIOService);
 const dirSvc = Cc["@mozilla.org/file/directory_service;1"].
                 getService(Ci.nsIProperties);
 const obs = Cc["@mozilla.org/observer-service;1"].
                 getService(Ci.nsIObserverService);
 
 const nsIBinaryInputStream = ctor("@mozilla.org/binaryinputstream;1",
@@ -67,17 +70,24 @@ Listener.prototype = {
     }
 };
 
 /**
  * Basic reading test for asynchronously opened jar channel
  */
 function testAsync() {
     var uri = jarBase + "/inner40.zip";
-    var chan = ios.newChannel(uri, null, null);
+    var chan = ios.newChannel2(uri,
+                               null,
+                               null,
+                               null,      // aLoadingNode
+                               Services.scriptSecurityManager.getSystemPrincipal(),
+                               null,      // aTriggeringPrincipal
+                               Ci.nsILoadInfo.SEC_NORMAL,
+                               Ci.nsIContentPolicy.TYPE_OTHER);
     do_check_true(chan.contentLength < 0);
     chan.asyncOpen(new Listener(function(l) {
         do_check_true(chan.contentLength > 0);
         do_check_true(l.gotStartRequest);
         do_check_true(l.gotStopRequest);
         do_check_eq(l.available, chan.contentLength);
 
         run_next_test();
@@ -89,17 +99,25 @@ add_test(testAsync);
 add_test(testAsync);
 
 /**
  * Basic test for nsIZipReader.
  * This relies on the jar cache to succeed in child processes.
  */
 function testZipEntry() {
     var uri = jarBase + "/inner40.zip";
-    var chan = ios.newChannel(uri, null, null).QueryInterface(Ci.nsIJARChannel);
+    var chan = ios.newChannel2(uri,
+                               null,
+                               null,
+                               null,      // aLoadingNode
+                               Services.scriptSecurityManager.getSystemPrincipal(),
+                               null,      // aTriggeringPrincipal
+                               Ci.nsILoadInfo.SEC_NORMAL,
+                               Ci.nsIContentPolicy.TYPE_OTHER)
+                  .QueryInterface(Ci.nsIJARChannel);
     var entry = chan.zipEntry;
     do_check_true(entry.CRC32 == 0x8b635486);
     do_check_true(entry.realSize == 184);
     run_next_test();
 }
 
 add_test(testZipEntry);
 
@@ -109,48 +127,69 @@ add_test(testZipEntry);
 // 3) we can't do file lock checks on android, so skip those tests too.
 if (!inChild) {
 
   /**
    * Basic reading test for synchronously opened jar channels
    */
   add_test(function testSync() {
       var uri = jarBase + "/inner40.zip";
-      var chan = ios.newChannel(uri, null, null);
+      var chan = ios.newChannel2(uri,
+                                 null,
+                                 null,
+                                 null,      // aLoadingNode
+                                 Services.scriptSecurityManager.getSystemPrincipal(),
+                                 null,      // aTriggeringPrincipal
+                                 Ci.nsILoadInfo.SEC_NORMAL,
+                                 Ci.nsIContentPolicy.TYPE_OTHER);
       var stream = chan.open();
       do_check_true(chan.contentLength > 0);
       do_check_eq(stream.available(), chan.contentLength);
       stream.close();
       stream.close(); // should still not throw
 
       run_next_test();
   });
 
 
   /**
    * Basic reading test for synchronously opened, nested jar channels
    */
   add_test(function testSyncNested() {
       var uri = "jar:" + jarBase + "/inner40.zip!/foo";
-      var chan = ios.newChannel(uri, null, null);
+      var chan = ios.newChannel2(uri,
+                                 null,
+                                 null,
+                                 null,      // aLoadingNode
+                                 Services.scriptSecurityManager.getSystemPrincipal(),
+                                 null,      // aTriggeringPrincipal
+                                 Ci.nsILoadInfo.SEC_NORMAL,
+                                 Ci.nsIContentPolicy.TYPE_OTHER);
       var stream = chan.open();
       do_check_true(chan.contentLength > 0);
       do_check_eq(stream.available(), chan.contentLength);
       stream.close();
       stream.close(); // should still not throw
 
       run_next_test();
   });
 
   /**
    * Basic reading test for asynchronously opened, nested jar channels
    */
   add_test(function testAsyncNested(next) {
       var uri = "jar:" + jarBase + "/inner40.zip!/foo";
-      var chan = ios.newChannel(uri, null, null);
+      var chan = ios.newChannel2(uri,
+                                 null,
+                                 null,
+                                 null,      // aLoadingNode
+                                 Services.scriptSecurityManager.getSystemPrincipal(),
+                                 null,      // aTriggeringPrincipal
+                                 Ci.nsILoadInfo.SEC_NORMAL,
+                                 Ci.nsIContentPolicy.TYPE_OTHER);
       chan.asyncOpen(new Listener(function(l) {
           do_check_true(chan.contentLength > 0);
           do_check_true(l.gotStartRequest);
           do_check_true(l.gotStopRequest);
           do_check_eq(l.available, chan.contentLength);
 
           run_next_test();
       }), null);
@@ -161,17 +200,24 @@ if (!inChild) {
    * opened jar channel stream
    */
   add_test(function testSyncCloseUnlocks() {
       var copy = tmpDir.clone();
       copy.append(fileBase);
       file.copyTo(copy.parent, copy.leafName);
 
       var uri = "jar:" + ios.newFileURI(copy).spec + "!/inner40.zip";
-      var chan = ios.newChannel(uri, null, null);
+      var chan = ios.newChannel2(uri,
+                                 null,
+                                 null,
+                                 null,      // aLoadingNode
+                                 Services.scriptSecurityManager.getSystemPrincipal(),
+                                 null,      // aTriggeringPrincipal
+                                 Ci.nsILoadInfo.SEC_NORMAL,
+                                 Ci.nsIContentPolicy.TYPE_OTHER);
       var stream = chan.open();
       do_check_true(chan.contentLength > 0);
       stream.close();
 
       // Drop any jar caches
       obs.notifyObservers(null, "chrome-flush-caches", null);
 
       try {
@@ -189,17 +235,24 @@ if (!inChild) {
    * opened jar channel stream
    */
   add_test(function testAsyncCloseUnlocks() {
       var copy = tmpDir.clone();
       copy.append(fileBase);
       file.copyTo(copy.parent, copy.leafName);
 
       var uri = "jar:" + ios.newFileURI(copy).spec + "!/inner40.zip";
-      var chan = ios.newChannel(uri, null, null);
+      var chan = ios.newChannel2(uri,
+                                 null,
+                                 null,
+                                 null,      // aLoadingNode
+                                 Services.scriptSecurityManager.getSystemPrincipal(),
+                                 null,      // aTriggeringPrincipal
+                                 Ci.nsILoadInfo.SEC_NORMAL,
+                                 Ci.nsIContentPolicy.TYPE_OTHER);
       chan.asyncOpen(new Listener(function (l) {
           do_check_true(chan.contentLength > 0);
 
           // Drop any jar caches
           obs.notifyObservers(null, "chrome-flush-caches", null);
 
           try {
               copy.remove(false);
@@ -220,34 +273,55 @@ if (inChild) {
      */
     add_test(function testSimultaneous() {
         var uri = jarBase + "/inner1.zip";
 
         // Drop any JAR caches
         obs.notifyObservers(null, "chrome-flush-caches", null);
 
         // Open the first channel without ensureChildFd()
-        var chan_first = ios.newChannel(uri, null, null)
+        var chan_first = ios.newChannel2(uri,
+                                         null,
+                                         null,
+                                         null,      // aLoadingNode
+                                         Services.scriptSecurityManager.getSystemPrincipal(),
+                                         null,      // aTriggeringPrincipal
+                                         Ci.nsILoadInfo.SEC_NORMAL,
+                                         Ci.nsIContentPolicy.TYPE_OTHER)
                             .QueryInterface(Ci.nsIJARChannel);
         chan_first.asyncOpen(new Listener(function(l) {
         }), null);
 
         // Open multiple channels with ensureChildFd()
         var num = 10;
         var chan = [];
         for (var i = 0; i < num; i++) {
-            chan[i] = ios.newChannel(uri, null, null)
+            chan[i] = ios.newChannel2(uri,
+                                      null,
+                                      null,
+                                      null,      // aLoadingNode
+                                      Services.scriptSecurityManager.getSystemPrincipal(),
+                                      null,      // aTriggeringPrincipal
+                                      Ci.nsILoadInfo.SEC_NORMAL,
+                                      Ci.nsIContentPolicy.TYPE_OTHER)
                          .QueryInterface(Ci.nsIJARChannel);
             chan[i].ensureChildFd();
             chan[i].asyncOpen(new Listener(function(l) {
             }), null);
         }
 
         // Open the last channel with ensureChildFd()
-        var chan_last = ios.newChannel(uri, null, null)
+        var chan_last = ios.newChannel2(uri,
+                                        null,
+                                        null,
+                                        null,      // aLoadingNode
+                                        Services.scriptSecurityManager.getSystemPrincipal(),
+                                        null,      // aTriggeringPrincipal
+                                        Ci.nsILoadInfo.SEC_NORMAL,
+                                        Ci.nsIContentPolicy.TYPE_OTHER)
                            .QueryInterface(Ci.nsIJARChannel);
         chan_last.ensureChildFd();
         chan_last.asyncOpen(new Listener(function(l) {
             run_next_test();
         }), null);
     });
 } // if inChild
 
--- a/modules/libjar/test/unit/test_not_found.js
+++ b/modules/libjar/test/unit/test_not_found.js
@@ -1,18 +1,28 @@
 // Should report file not found on non-existent files
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/Services.jsm");
 const path = "data/test_bug333423.zip";
 
 function run_test() {
   var ios = Cc["@mozilla.org/network/io-service;1"].
             getService(Ci.nsIIOService);
   var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/";
-  var channel = ios.newChannel(spec + "file_that_isnt_in.archive", null, null);
+  var channel = ios.newChannel2(spec + "file_that_isnt_in.archive",
+                                null,
+                                null,
+                                null,      // aLoadingNode
+                                Services.scriptSecurityManager.getSystemPrincipal(),
+                                null,      // aTriggeringPrincipal
+                                Ci.nsILoadInfo.SEC_NORMAL,
+                                Ci.nsIContentPolicy.TYPE_OTHER);
   try {
     instr = channel.open();
     do_throw("Failed to report that file doesn't exist")
   } catch (e) {
       do_check_true(e.name == "NS_ERROR_FILE_NOT_FOUND")
   }
 }
--- a/modules/libjar/zipwriter/test/unit/test_asyncadd.js
+++ b/modules/libjar/zipwriter/test/unit/test_asyncadd.js
@@ -1,13 +1,16 @@
 /* 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/.
  */
 
+const Cu = Components.utils;
+Cu.import("resource://gre/modules/Services.jsm");
+
 // Values taken from using zipinfo to list the test.zip contents
 var TESTS = [
   {
     name: "test.txt",
     size: 232,
     crc: 0x0373ac26
   },
   {
@@ -63,23 +66,33 @@ var methods = {
   {
     zipW.addEntryFile(entry, Ci.nsIZipWriter.COMPRESSION_NONE, source,
                       true);
   },
   channel: function method_channel(entry, source)
   {
     zipW.addEntryChannel(entry, source.lastModifiedTime * PR_MSEC_PER_SEC,
                          Ci.nsIZipWriter.COMPRESSION_NONE,
-                         ioSvc.newChannelFromURI(ioSvc.newFileURI(source)), true);
+                         ioSvc.newChannelFromURI2(ioSvc.newFileURI(source),
+                                                  null,      // aLoadingNode
+                                                  Services.scriptSecurityManager.getSystemPrincipal(),
+                                                  null,      // aTriggeringPrincipal
+                                                  Ci.nsILoadInfo.SEC_NORMAL,
+                                                  Ci.nsIContentPolicy.TYPE_OTHER), true);
   },
   stream: function method_stream(entry, source)
   {
     zipW.addEntryStream(entry, source.lastModifiedTime * PR_MSEC_PER_SEC,
                         Ci.nsIZipWriter.COMPRESSION_NONE,
-                        ioSvc.newChannelFromURI(ioSvc.newFileURI(source)).open(), true);
+                        ioSvc.newChannelFromURI2(ioSvc.newFileURI(source),
+                                                 null,      // aLoadingNode
+                                                 Services.scriptSecurityManager.getSystemPrincipal(),
+                                                 null,      // aTriggeringPrincipal
+                                                 Ci.nsILoadInfo.SEC_NORMAL,
+                                                 Ci.nsIContentPolicy.TYPE_OTHER).open(), true);
   }
 }
 
 function run_test()
 {
   zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
 
   for (var i = 0; i < TESTS.length; i++) {