Upstream the changes from Bug 1242730 - Convert callsites to use channel.async0pen2() within browser/extensions/pdfjs (issue 7386)

Please see https://bugzilla.mozilla.org/show_bug.cgi?id=1242730.

Fixes 7386.
This commit is contained in:
Jonas Jenwald 2016-06-14 16:29:11 +02:00
parent a0a6e6d688
commit 6d7f6f1b86

View File

@ -148,14 +148,15 @@ function getLocalizedString(strings, id, property) {
return id; return id;
} }
function createNewChannel(uri, node, principal) { function createNewChannel(uri, node) {
//#if !MOZCENTRAL //#if !MOZCENTRAL
if (NetUtil.newChannel2) { if (NetUtil.newChannel2) {
var systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
return NetUtil.newChannel2(uri, return NetUtil.newChannel2(uri,
null, null,
null, null,
node, // aLoadingNode node, // aLoadingNode
principal, // aLoadingPrincipal systemPrincipal, // aLoadingPrincipal
null, // aTriggeringPrincipal null, // aTriggeringPrincipal
Ci.nsILoadInfo.SEC_NORMAL, Ci.nsILoadInfo.SEC_NORMAL,
Ci.nsIContentPolicy.TYPE_OTHER); Ci.nsIContentPolicy.TYPE_OTHER);
@ -163,12 +164,19 @@ function createNewChannel(uri, node, principal) {
//#endif //#endif
return NetUtil.newChannel({ return NetUtil.newChannel({
uri: uri, uri: uri,
loadingNode: node, loadUsingSystemPrincipal: true,
loadingPrincipal: principal,
contentPolicyType: Ci.nsIContentPolicy.TYPE_OTHER,
}); });
} }
function asyncOpenChannel(channel, listener, context) {
//#if !MOZCENTRAL
if (!channel.asyncOpen2) {
return channel.asyncOpen(listener, context);
}
//#endif
return channel.asyncOpen2(listener);
}
function asyncFetchChannel(channel, callback) { function asyncFetchChannel(channel, callback) {
//#if !MOZCENTRAL //#if !MOZCENTRAL
if (NetUtil.asyncFetch2) { if (NetUtil.asyncFetch2) {
@ -271,7 +279,7 @@ ChromeActions.prototype = {
getService(Ci.nsIExternalHelperAppService); getService(Ci.nsIExternalHelperAppService);
var docIsPrivate = this.isInPrivateBrowsing(); var docIsPrivate = this.isInPrivateBrowsing();
var netChannel = createNewChannel(blobUri, this.domWindow.document, null); var netChannel = createNewChannel(blobUri, this.domWindow.document);
if ('nsIPrivateBrowsingChannel' in Ci && if ('nsIPrivateBrowsingChannel' in Ci &&
netChannel instanceof Ci.nsIPrivateBrowsingChannel) { netChannel instanceof Ci.nsIPrivateBrowsingChannel) {
netChannel.setPrivate(docIsPrivate); netChannel.setPrivate(docIsPrivate);
@ -298,6 +306,7 @@ ChromeActions.prototype = {
} }
} catch (e) {} } catch (e) {}
channel.setURI(originalUri); channel.setURI(originalUri);
channel.loadInfo = netChannel.loadInfo;
channel.contentStream = aInputStream; channel.contentStream = aInputStream;
if ('nsIPrivateBrowsingChannel' in Ci && if ('nsIPrivateBrowsingChannel' in Ci &&
channel instanceof Ci.nsIPrivateBrowsingChannel) { channel instanceof Ci.nsIPrivateBrowsingChannel) {
@ -333,7 +342,7 @@ ChromeActions.prototype = {
} }
}; };
channel.asyncOpen(listener, null); asyncOpenChannel(channel, listener, null);
}); });
}, },
getLocale: function() { getLocale: function() {
@ -973,8 +982,7 @@ PdfStreamConverter.prototype = {
.createInstance(Ci.nsIBinaryInputStream); .createInstance(Ci.nsIBinaryInputStream);
// Create a new channel that is viewer loaded as a resource. // Create a new channel that is viewer loaded as a resource.
var systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal(); var channel = createNewChannel(PDF_VIEWER_WEB_PAGE, null);
var channel = createNewChannel(PDF_VIEWER_WEB_PAGE, null, systemPrincipal);
var listener = this.listener; var listener = this.listener;
var dataListener = this.dataListener; var dataListener = this.dataListener;
@ -984,10 +992,11 @@ PdfStreamConverter.prototype = {
// trigger an assertion. // trigger an assertion.
var proxy = { var proxy = {
onStartRequest: function(request, context) { onStartRequest: function(request, context) {
listener.onStartRequest(aRequest, context); listener.onStartRequest(aRequest, aContext);
}, },
onDataAvailable: function(request, context, inputStream, offset, count) { 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) { onStopRequest: function(request, context, statusCode) {
// We get the DOM window here instead of before the request since it // We get the DOM window here instead of before the request since it
@ -1010,7 +1019,7 @@ PdfStreamConverter.prototype = {
var findEventManager = new FindEventManager(domWindow); var findEventManager = new FindEventManager(domWindow);
findEventManager.bind(); findEventManager.bind();
} }
listener.onStopRequest(aRequest, context, statusCode); listener.onStopRequest(aRequest, aContext, statusCode);
if (domWindow.frameElement) { if (domWindow.frameElement) {
var isObjectEmbed = domWindow.frameElement.tagName !== 'IFRAME' || var isObjectEmbed = domWindow.frameElement.tagName !== 'IFRAME' ||
@ -1046,7 +1055,7 @@ PdfStreamConverter.prototype = {
} }
//#endif //#endif
aRequest.owner = resourcePrincipal; aRequest.owner = resourcePrincipal;
channel.asyncOpen(proxy, aContext); asyncOpenChannel(channel, proxy, aContext);
}, },
// nsIRequestObserver::onStopRequest // nsIRequestObserver::onStopRequest