}
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)