@ -44,42 +44,37 @@ function ChromeActions() {
}
}
ChromeActions . prototype = {
ChromeActions . prototype = {
download : function ( data ) {
download : function ( data ) {
Services . wm . getMostRecentWindow ( 'navigator:browser' ) . saveURL ( data ) ;
} ,
fallback : function ( data ) {
let mimeService = Cc [ '@mozilla.org/mime;1' ] . getService ( Ci . nsIMIMEService ) ;
let mimeService = Cc [ '@mozilla.org/mime;1' ] . getService ( Ci . nsIMIMEService ) ;
var handlerInfo = mimeService .
var handlerInfo = mimeService .
getFromTypeAndExtension ( 'application/pdf' , 'pdf' ) ;
getFromTypeAndExtension ( 'application/pdf' , 'pdf' ) ;
var uri = NetUtil . newURI ( data ) ;
var uri = NetUtil . newURI ( data ) ;
var filename = Services . wm . getMostRecentWindow ( 'navigator:browser' ) .
getDefaultFileName ( 'document.pdf' , uri ) ;
var extHelperAppSvc =
// Create a temporary file to output to.
Cc [ '@mozilla.org/uriloader/external-helper-app-service;1' ] .
var file = Cc [ '@mozilla.org/file/directory_service;1' ] .
getService ( Ci . nsIExternalHelperAppService ) ;
getService ( Ci . nsIProperties ) .
var frontWindow = Cc [ '@mozilla.org/embedcomp/window-watcher;1' ] .
get ( 'TmpD' , Ci . nsIFile ) ;
getService ( Ci . nsIWindowWatcher ) . activeWindow ;
file . append ( filename ) ;
var ioService = Services . io ;
file . createUnique ( Ci . nsIFile . NORMAL _FILE _TYPE , parseInt ( '0666' , 8 ) ) ;
var channel = ioService . newChannel ( data , null , null ) ;
var listener = {
var ostream = Cc [ '@mozilla.org/network/file-output-stream;1' ] .
extListener : null ,
createInstance ( Ci . nsIFileOutputStream ) ;
onStartRequest : function ( aRequest , aContext ) {
ostream . init ( file , - 1 , - 1 , 0 ) ;
this . extListener = extHelperAppSvc . doContent ( 'application/pdf' ,
aRequest , frontWindow , false ) ;
// Fetch the file and once it's ready attempt to open it with the system's
this . extListener . onStartRequest ( aRequest , aContext ) ;
// default pdf handler.
} ,
NetUtil . asyncFetch ( uri , function ( istream , aResult ) {
onStopRequest : function ( aRequest , aContext , aStatusCode ) {
if ( ! Components . isSuccessCode ( aResult ) ) {
if ( this . extListener )
log ( 'Error: Fetching file failed with code ' + aResult ) ;
this . extListener . onStopRequest ( aRequest , aContext , aStatusCode ) ;
return ;
} ,
}
onDataAvailable : function ( aRequest , aContext , aInputStream , aOffset ,
NetUtil . asyncCopy ( istream , ostream , function ( aResult ) {
aCount ) {
if ( ! Components . isSuccessCode ( aResult ) ) {
this . extListener . onDataAvailable ( aRequest , aContext , aInputStream ,
log ( 'Error: Copying file failed with code: ' + aResult ) ;
aOffset , aCount ) ;
return ;
}
}
handlerInfo . preferredAction = Ci . nsIHandlerInfo . useSystemDefault ;
} ;
handlerInfo . launchWithFile ( file ) ;
} ) ;
channel . asyncOpen ( listener , null ) ;
} ) ;
} ,
} ,
setDatabase : function ( data ) {
setDatabase : function ( data ) {
if ( this . inPrivateBrowswing )
if ( this . inPrivateBrowswing )