mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Add a download button in case the extension is not enough
This commit is contained in:
parent
401732336d
commit
6d2c5414bf
4 changed files with 651 additions and 13 deletions
|
@ -20,16 +20,17 @@ function log(aMsg) {
|
|||
dump(msg + '\n');
|
||||
}
|
||||
|
||||
const NS_ERROR_WONT_HANDLE_CONTENT = 0x805d0001;
|
||||
function pdfContentHandler() {
|
||||
}
|
||||
|
||||
pdfContentHandler.prototype = {
|
||||
handleContent: function handleContent(aMimetype, aContext, aRequest) {
|
||||
if (aMimetype != PDF_CONTENT_TYPE)
|
||||
throw Cr.NS_ERROR_WONT_HANDLE_CONTENT;
|
||||
throw NS_ERROR_WONT_HANDLE_CONTENT;
|
||||
|
||||
if (!(aRequest instanceof Ci.nsIChannel))
|
||||
throw Cr.NS_ERROR_WONT_HANDLE_CONTENT;
|
||||
throw NS_ERROR_WONT_HANDLE_CONTENT;
|
||||
|
||||
let window = null;
|
||||
let callbacks = aRequest.notificationCallbacks ||
|
||||
|
@ -37,18 +38,26 @@ pdfContentHandler.prototype = {
|
|||
if (!callbacks)
|
||||
return;
|
||||
|
||||
window = callbacks.getInterface(Ci.nsIDOMWindow);
|
||||
|
||||
let url = null;
|
||||
try {
|
||||
url = Services.prefs.getCharPref('extensions.pdf.js.url');
|
||||
} catch(e) {
|
||||
log('Error retrieving the pdf.js base url - ' + e);
|
||||
throw NS_ERROR_WONT_HANDLE_CONTENT;
|
||||
}
|
||||
|
||||
// To allow a Download feature we need to ensure pdf.js
|
||||
// is not opened again if the request for opening an
|
||||
// application/pdf document has been done by itself.
|
||||
let location = window.location.toString();
|
||||
if (location.indexOf(url.replace('%s', '')) == 0)
|
||||
throw NS_ERROR_WONT_HANDLE_CONTENT;
|
||||
|
||||
aRequest.cancel(Cr.NS_BINDING_ABORTED);
|
||||
let uri = aRequest.URI;
|
||||
|
||||
try {
|
||||
let url = Services.prefs.getCharPref('extensions.pdf.js.url');
|
||||
url = url.replace('%s', uri.spec);
|
||||
|
||||
window = callbacks.getInterface(Ci.nsIDOMWindow);
|
||||
window.location = url;
|
||||
} catch (e) {
|
||||
log('Error retrieving the pdf.js base url - ' + e);
|
||||
}
|
||||
window.location = url.replace('%s', uri.spec);
|
||||
},
|
||||
|
||||
classID: Components.ID('{2278dfd0-b75c-11e0-8257-1ba3d93c9f1a}'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue