1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-28 23:28:16 +02:00

Add a download button in case the extension is not enough

This commit is contained in:
Vivien Nicolas 2011-10-19 03:20:50 +02:00
parent 401732336d
commit 6d2c5414bf
4 changed files with 651 additions and 13 deletions

View file

@ -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}'),