Skip to content

Commit 5283289

Browse files
committed
Merge pull request mozilla#1673 from brendandahl/fallback
Add fallback option for the extension.
2 parents 15d1851 + 0cb1a08 commit 5283289

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

extensions/firefox/components/PdfStreamConverter.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const MAX_DATABASE_LENGTH = 4096;
1616

1717
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
1818
Cu.import('resource://gre/modules/Services.jsm');
19+
Cu.import('resource://gre/modules/NetUtil.jsm');
1920

2021
let privateBrowsing = Cc['@mozilla.org/privatebrowsing;1']
2122
.getService(Ci.nsIPrivateBrowsingService);
@@ -64,7 +65,37 @@ function ChromeActions() {
6465
}
6566
ChromeActions.prototype = {
6667
download: function(data) {
67-
Services.wm.getMostRecentWindow('navigator:browser').saveURL(data);
68+
let mimeService = Cc['@mozilla.org/mime;1'].getService(Ci.nsIMIMEService);
69+
var handlerInfo = mimeService.
70+
getFromTypeAndExtension('application/pdf', 'pdf');
71+
var uri = NetUtil.newURI(data);
72+
73+
var extHelperAppSvc =
74+
Cc['@mozilla.org/uriloader/external-helper-app-service;1'].
75+
getService(Ci.nsIExternalHelperAppService);
76+
var frontWindow = Cc['@mozilla.org/embedcomp/window-watcher;1'].
77+
getService(Ci.nsIWindowWatcher).activeWindow;
78+
var ioService = Services.io;
79+
var channel = ioService.newChannel(data, null, null);
80+
var listener = {
81+
extListener: null,
82+
onStartRequest: function(aRequest, aContext) {
83+
this.extListener = extHelperAppSvc.doContent('application/pdf',
84+
aRequest, frontWindow, false);
85+
this.extListener.onStartRequest(aRequest, aContext);
86+
},
87+
onStopRequest: function(aRequest, aContext, aStatusCode) {
88+
if (this.extListener)
89+
this.extListener.onStopRequest(aRequest, aContext, aStatusCode);
90+
},
91+
onDataAvailable: function(aRequest, aContext, aInputStream, aOffset,
92+
aCount) {
93+
this.extListener.onDataAvailable(aRequest, aContext, aInputStream,
94+
aOffset, aCount);
95+
}
96+
};
97+
98+
channel.asyncOpen(listener, null);
6899
},
69100
setDatabase: function(data) {
70101
if (this.inPrivateBrowswing)

0 commit comments

Comments
 (0)