From: Brendan Dahl Date: Mon, 4 Jun 2012 18:16:02 +0000 (-0700) Subject: Merge upstream. X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=16b1fa1e98a1011f5aa77044424e5449a8e1420a;p=pdf.js.git Merge upstream. --- 16b1fa1e98a1011f5aa77044424e5449a8e1420a diff --cc extensions/firefox/components/PdfStreamConverter.js index 9e5dcbe,691aec6..8980fcc --- a/extensions/firefox/components/PdfStreamConverter.js +++ b/extensions/firefox/components/PdfStreamConverter.js @@@ -128,37 -123,65 +128,58 @@@ function ChromeActions(domWindow) } ChromeActions.prototype = { - download: function(data) { - var handlerInfo = Svc.mime - .getFromTypeAndExtension('application/pdf', 'pdf'); - var uri = NetUtil.newURI(data); - + download: function(data, sendResponse) { + var originalUrl = data.originalUrl; + // The data may not be downloaded so we need just retry getting the pdf with + // the original url. + var blobUrl = data.blobUrl || originalUrl; - + var originalUri = NetUtil.newURI(originalUrl); + var blobUri = NetUtil.newURI(blobUrl); - - let mimeService = Cc['@mozilla.org/mime;1'].getService(Ci.nsIMIMEService); - var handlerInfo = mimeService. - getFromTypeAndExtension('application/pdf', 'pdf'); - var extHelperAppSvc = Cc['@mozilla.org/uriloader/external-helper-app-service;1']. -- getService(Ci.nsIExternalHelperAppService); ++ getService(Ci.nsIExternalHelperAppService); var frontWindow = Cc['@mozilla.org/embedcomp/window-watcher;1']. -- getService(Ci.nsIWindowWatcher).activeWindow; ++ getService(Ci.nsIWindowWatcher).activeWindow; var ioService = Services.io; - var channel = ioService.newChannel(data, null, null); - var listener = { - extListener: null, - onStartRequest: function(aRequest, aContext) { - this.extListener = extHelperAppSvc.doContent('application/pdf', - aRequest, frontWindow, false); - this.extListener.onStartRequest(aRequest, aContext); - }, - onStopRequest: function(aRequest, aContext, aStatusCode) { - if (this.extListener) - this.extListener.onStopRequest(aRequest, aContext, aStatusCode); - }, - onDataAvailable: function(aRequest, aContext, aInputStream, aOffset, - aCount) { - this.extListener.onDataAvailable(aRequest, aContext, aInputStream, - aOffset, aCount); + var channel = ioService.newChannel(originalUrl, null, null); + - + NetUtil.asyncFetch(blobUri, function(aInputStream, aResult) { + if (!Components.isSuccessCode(aResult)) { + if (sendResponse) + sendResponse(true); + return; } - }; + // Create a nsIInputStreamChannel so we can set the url on the channel + // so the filename will be correct. + let channel = Cc['@mozilla.org/network/input-stream-channel;1']. - createInstance(Ci.nsIInputStreamChannel); ++ createInstance(Ci.nsIInputStreamChannel); + channel.setURI(originalUri); + channel.contentStream = aInputStream; + channel.QueryInterface(Ci.nsIChannel); + + var listener = { + extListener: null, + onStartRequest: function(aRequest, aContext) { + this.extListener = extHelperAppSvc.doContent('application/pdf', + aRequest, frontWindow, false); + this.extListener.onStartRequest(aRequest, aContext); + }, + onStopRequest: function(aRequest, aContext, aStatusCode) { + if (this.extListener) + this.extListener.onStopRequest(aRequest, aContext, aStatusCode); + // Notify the content code we're done downloading. + if (sendResponse) + sendResponse(false); + }, + onDataAvailable: function(aRequest, aContext, aInputStream, aOffset, + aCount) { + this.extListener.onDataAvailable(aRequest, aContext, aInputStream, + aOffset, aCount); + } + }; - channel.asyncOpen(listener, null); + channel.asyncOpen(listener, null); + }); }, setDatabase: function(data) { if (inPrivateBrowsing)