@@ -16,6 +16,7 @@ const MAX_DATABASE_LENGTH = 4096;
16
16
17
17
Cu .import ('resource://gre/modules/XPCOMUtils.jsm' );
18
18
Cu .import ('resource://gre/modules/Services.jsm' );
19
+ Cu .import ('resource://gre/modules/NetUtil.jsm' );
19
20
20
21
let privateBrowsing = Cc ['@mozilla.org/privatebrowsing;1' ]
21
22
.getService (Ci .nsIPrivateBrowsingService );
@@ -64,7 +65,37 @@ function ChromeActions() {
64
65
}
65
66
ChromeActions .prototype = {
66
67
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 );
68
99
},
69
100
setDatabase : function (data ) {
70
101
if (this .inPrivateBrowswing )
0 commit comments