Bug 1479236: Stop loading NetUtil.jsm in the content process. r?Mossop draft
authorKris Maglione <maglione.k@gmail.com>
Sat, 28 Jul 2018 17:47:06 -0700
changeset 823843 53fa64e738903e4eda1f7ade92775d09c9f7a80a
parent 823842 ba40a15f353c4cb54cfe22d75e22dd401454d1be
push id117798
push usermaglione.k@gmail.com
push dateSun, 29 Jul 2018 00:47:24 +0000
reviewersMossop
bugs1479236
milestone63.0a1
Bug 1479236: Stop loading NetUtil.jsm in the content process. r?Mossop MozReview-Commit-ID: CvV25FHerXJ
browser/modules/ContentLinkHandler.jsm
--- a/browser/modules/ContentLinkHandler.jsm
+++ b/browser/modules/ContentLinkHandler.jsm
@@ -8,23 +8,24 @@ const EXPORTED_SYMBOLS = ["ContentLinkHa
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyGlobalGetters(this, ["Blob", "FileReader"]);
 
 ChromeUtils.defineModuleGetter(this, "Feeds",
   "resource:///modules/Feeds.jsm");
-ChromeUtils.defineModuleGetter(this, "NetUtil",
-  "resource://gre/modules/NetUtil.jsm");
 ChromeUtils.defineModuleGetter(this, "DeferredTask",
   "resource://gre/modules/DeferredTask.jsm");
 ChromeUtils.defineModuleGetter(this, "PromiseUtils",
   "resource://gre/modules/PromiseUtils.jsm");
 
+const BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1",
+                                                 "nsIBinaryInputStream", "setInputStream");
+
 const SIZES_TELEMETRY_ENUM = {
   NO_SIZES: 0,
   ANY: 1,
   DIMENSION: 2,
   INVALID: 3,
 };
 
 const FAVICON_PARSING_TIMEOUT = 100;
@@ -64,26 +65,25 @@ function promiseBlobAsOctets(blob) {
   });
 }
 
 class FaviconLoad {
   constructor(iconInfo) {
     this.buffers = [];
     this.icon = iconInfo;
 
-    this.channel = NetUtil.newChannel({
-      uri: iconInfo.iconUri,
-      loadingNode: iconInfo.node,
-      loadingPrincipal: iconInfo.node.nodePrincipal,
-      triggeringPrincipal: iconInfo.node.nodePrincipal,
-      contentPolicyType: Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE_FAVICON,
-      securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS |
-                     Ci.nsILoadInfo.SEC_ALLOW_CHROME |
-                     Ci.nsILoadInfo.SEC_DISALLOW_SCRIPT,
-    });
+    this.channel = Services.io.newChannelFromURI2(
+      iconInfo.iconUri,
+      iconInfo.node,
+      iconInfo.node.nodePrincipal,
+      iconInfo.node.nodePrincipal,
+      (Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS |
+       Ci.nsILoadInfo.SEC_ALLOW_CHROME |
+       Ci.nsILoadInfo.SEC_DISALLOW_SCRIPT),
+      Ci.nsIContentPolicy.TYPE_INTERNAL_IMAGE_FAVICON);
 
     this.channel.loadFlags |= Ci.nsIRequest.LOAD_BACKGROUND;
     // Sometimes node is a document and sometimes it is an element. This is
     // the easiest single way to get to the load group in both those cases.
     this.channel.loadGroup = iconInfo.node.ownerGlobal.document.documentLoadGroup;
     this.channel.notificationCallbacks = this;
 
     if (Services.prefs.getBoolPref("network.http.tailing.enabled", true) &&
@@ -116,18 +116,20 @@ class FaviconLoad {
 
     this.channel.cancel(Cr.NS_BINDING_ABORTED);
   }
 
   onStartRequest(request, context) {
   }
 
   onDataAvailable(request, context, inputStream, offset, count) {
-    let data = NetUtil.readInputStreamToString(inputStream, count);
-    this.buffers.push(Uint8Array.from(data, c => c.charCodeAt(0)));
+    let stream = new BinaryInputStream(inputStream);
+    let buffer = new ArrayBuffer(count);
+    stream.readArrayBuffer(buffer.byteLength, buffer);
+    this.buffers.push(new Uint8Array(buffer));
   }
 
   asyncOnChannelRedirect(oldChannel, newChannel, flags, callback) {
     if (oldChannel == this.channel) {
       this.channel = newChannel;
     }
 
     callback.onRedirectVerifyCallback(Cr.NS_OK);