From 83003499b76196691fbcb429b6b623eb32c904ac Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Thu, 25 Oct 2012 10:35:06 -0700 Subject: [PATCH] Forward original request to avoid firefox assertion. --- .../firefox/components/PdfStreamConverter.js | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/extensions/firefox/components/PdfStreamConverter.js b/extensions/firefox/components/PdfStreamConverter.js index 7ca248178..480b6b5e7 100644 --- a/extensions/firefox/components/PdfStreamConverter.js +++ b/extensions/firefox/components/PdfStreamConverter.js @@ -95,7 +95,9 @@ function log(aMsg) { } function getDOMWindow(aChannel) { - var requestor = aChannel.notificationCallbacks; + var requestor = aChannel.notificationCallbacks ? + aChannel.notificationCallbacks : + aChannel.loadGroup.notificationCallbacks; var win = requestor.getInterface(Components.interfaces.nsIDOMWindow); return win; } @@ -591,6 +593,8 @@ PdfStreamConverter.prototype = { // Cancel the request so the viewer can handle it. aRequest.cancel(Cr.NS_BINDING_ABORTED); } + // Change the content type so we don't get stuck in a loop. + aRequest.contentType = 'text/html'; // Create a new channel that is viewer loaded as a resource. var ioService = Services.io; @@ -598,17 +602,20 @@ PdfStreamConverter.prototype = { PDF_VIEWER_WEB_PAGE, null, null); var listener = this.listener; - var self = this; // Proxy all the request observer calls, when it gets to onStopRequest - // we can get the dom window. + // 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() { - listener.onStartRequest.apply(listener, arguments); + onStartRequest: function(request, context) { + listener.onStartRequest(aRequest, context); }, - onDataAvailable: function() { - listener.onDataAvailable.apply(listener, arguments); + onDataAvailable: function(request, context, inputStream, offset, count) { + listener.onDataAvailable(aRequest, context, inputStream, offset, count); }, - onStopRequest: function() { + 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); // Double check the url is still the correct one. if (domWindow.document.documentURIObject.equals(aRequest.URI)) { @@ -624,14 +631,17 @@ PdfStreamConverter.prototype = { chromeWindow); findEventManager.bind(); } + } else { + log('Dom window url did not match request url.'); } - listener.onStopRequest.apply(listener, arguments); + listener.onStopRequest(aRequest, context, statusCode); } }; // Keep the URL the same so the browser sees it as the same. channel.originalURI = aRequest.URI; - channel.asyncOpen(proxy, aContext); + channel.loadGroup = aRequest.loadGroup; + if (useFetchByChrome) { // We can use resource principal when data is fetched by the chrome // e.g. useful for NoScript @@ -645,6 +655,7 @@ PdfStreamConverter.prototype = { securityManager.getCodebasePrincipal(uri); channel.owner = resourcePrincipal; } + channel.asyncOpen(proxy, aContext); }, // nsIRequestObserver::onStopRequest