Bug 1242730 - Convert callsites to use channel.async0pen2() within browser/extensions/pdfjs. r=ydelendik
authorYury Delendik <ydelendik@mozilla.com>
Thu, 24 Mar 2016 12:52:29 -0500
changeset 341455 6153baa6401d8611015ae3fa0d589204286eadba
parent 341454 94bf6a16d707a3450ad3360a9d02ddf65ab445aa
child 341456 605c72e8e966af0ceab460f32d847280cb0a1e81
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersydelendik
bugs1242730
milestone49.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 1242730 - Convert callsites to use channel.async0pen2() within browser/extensions/pdfjs. r=ydelendik
browser/extensions/pdfjs/content/PdfStreamConverter.jsm
--- a/browser/extensions/pdfjs/content/PdfStreamConverter.jsm
+++ b/browser/extensions/pdfjs/content/PdfStreamConverter.jsm
@@ -155,22 +155,20 @@ function getLocalizedString(strings, id,
   return id;
 }
 
 function makeContentReadable(obj, window) {
   /* jshint -W027 */
   return Cu.cloneInto(obj, window);
 }
 
-function createNewChannel(uri, node, principal) {
+function createNewChannel(uri) {
   return NetUtil.newChannel({
     uri: uri,
-    loadingNode: node,
-    loadingPrincipal: principal,
-    contentPolicyType: Ci.nsIContentPolicy.TYPE_OTHER,
+    loadUsingSystemPrincipal: true
   });
 }
 
 function asyncFetchChannel(channel, callback) {
   return NetUtil.asyncFetch(channel, callback);
 }
 
 // PDF data storage
@@ -261,17 +259,17 @@ ChromeActions.prototype = {
       filename = 'document.pdf';
     }
     var blobUri = NetUtil.newURI(blobUrl);
     var extHelperAppSvc =
           Cc['@mozilla.org/uriloader/external-helper-app-service;1'].
              getService(Ci.nsIExternalHelperAppService);
 
     var docIsPrivate = this.isInPrivateBrowsing();
-    var netChannel = createNewChannel(blobUri, this.domWindow.document, null);
+    var netChannel = createNewChannel(blobUri);
     if ('nsIPrivateBrowsingChannel' in Ci &&
         netChannel instanceof Ci.nsIPrivateBrowsingChannel) {
       netChannel.setPrivate(docIsPrivate);
     }
     asyncFetchChannel(netChannel, function(aInputStream, aResult) {
       if (!Components.isSuccessCode(aResult)) {
         if (sendResponse) {
           sendResponse(true);
@@ -288,16 +286,17 @@ ChromeActions.prototype = {
         channel.contentDisposition = Ci.nsIChannel.DISPOSITION_ATTACHMENT;
         if (self.contentDispositionFilename && !data.isAttachment) {
           channel.contentDispositionFilename = self.contentDispositionFilename;
         } else {
           channel.contentDispositionFilename = filename;
         }
       } catch (e) {}
       channel.setURI(originalUri);
+      channel.loadInfo = netChannel.loadInfo;
       channel.contentStream = aInputStream;
       if ('nsIPrivateBrowsingChannel' in Ci &&
           channel instanceof Ci.nsIPrivateBrowsingChannel) {
         channel.setPrivate(docIsPrivate);
       }
 
       var listener = {
         extListener: null,
@@ -323,17 +322,17 @@ ChromeActions.prototype = {
         },
         onDataAvailable: function(aRequest, aContext, aInputStream, aOffset,
                                   aCount) {
           this.extListener.onDataAvailable(aRequest, aContext, aInputStream,
                                            aOffset, aCount);
         }
       };
 
-      channel.asyncOpen(listener, null);
+      channel.asyncOpen2(listener);
     });
   },
   getLocale: function() {
     return getStringPref('general.useragent.locale', 'en-US');
   },
   getStrings: function(data) {
     try {
       // Lazy initialization of localizedStrings
@@ -968,31 +967,31 @@ PdfStreamConverter.prototype = {
 
     // Creating storage for PDF data
     var contentLength = aRequest.contentLength;
     this.dataListener = new PdfDataListener(contentLength);
     this.binaryStream = Cc['@mozilla.org/binaryinputstream;1']
                         .createInstance(Ci.nsIBinaryInputStream);
 
     // Create a new channel that is viewer loaded as a resource.
-    var systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
-    var channel = createNewChannel(PDF_VIEWER_WEB_PAGE, null, systemPrincipal);
+    var channel = createNewChannel(PDF_VIEWER_WEB_PAGE);
 
     var listener = this.listener;
     var dataListener = this.dataListener;
     // Proxy all the request observer calls, when it gets to onStopRequest
     // we can get the dom window.  We also intentionally pass on the original
     // request(aRequest) below so we don't overwrite the original channel and
     // trigger an assertion.
     var proxy = {
       onStartRequest: function(request, context) {
-        listener.onStartRequest(aRequest, context);
+        listener.onStartRequest(aRequest, aContext);
       },
       onDataAvailable: function(request, context, inputStream, offset, count) {
-        listener.onDataAvailable(aRequest, context, inputStream, offset, count);
+        listener.onDataAvailable(aRequest, aContext, inputStream,
+                                 offset, count);
       },
       onStopRequest: function(request, context, statusCode) {
         // We get the DOM window here instead of before the request since it
         // may have changed during a redirect.
         var domWindow = getDOMWindow(channel);
         var actions;
         if (rangeRequest || streamRequest) {
           actions = new RangedChromeActions(
@@ -1005,17 +1004,17 @@ PdfStreamConverter.prototype = {
         var requestListener = new RequestListener(actions);
         domWindow.addEventListener(PDFJS_EVENT_ID, function(event) {
           requestListener.receive(event);
         }, false, true);
         if (actions.supportsIntegratedFind()) {
           var findEventManager = new FindEventManager(domWindow);
           findEventManager.bind();
         }
-        listener.onStopRequest(aRequest, context, statusCode);
+        listener.onStopRequest(aRequest, aContext, statusCode);
 
         if (domWindow.frameElement) {
           var isObjectEmbed = domWindow.frameElement.tagName !== 'IFRAME' ||
             domWindow.frameElement.className === 'previewPluginContentFrame';
           PdfJsTelemetry.onEmbed(isObjectEmbed);
         }
       }
     };
@@ -1031,17 +1030,17 @@ PdfStreamConverter.prototype = {
     // e.g. useful for NoScript
     var ssm = Cc['@mozilla.org/scriptsecuritymanager;1']
                 .getService(Ci.nsIScriptSecurityManager);
     var uri = NetUtil.newURI(PDF_VIEWER_WEB_PAGE, null, null);
     var attrs = aRequest.loadInfo.originAttributes;
     var resourcePrincipal;
     resourcePrincipal = ssm.createCodebasePrincipal(uri, attrs);
     aRequest.owner = resourcePrincipal;
-    channel.asyncOpen(proxy, aContext);
+    channel.asyncOpen2(proxy);
   },
 
   // nsIRequestObserver::onStopRequest
   onStopRequest: function(aRequest, aContext, aStatusCode) {
     if (!this.dataListener) {
       // Do nothing
       return;
     }