diff --git a/extensions/firefox/components/PdfStreamConverter.js b/extensions/firefox/components/PdfStreamConverter.js index 49fd134ae..39376a791 100644 --- a/extensions/firefox/components/PdfStreamConverter.js +++ b/extensions/firefox/components/PdfStreamConverter.js @@ -13,14 +13,25 @@ const PDFJS_EVENT_ID = 'pdf.js.message'; const PDF_CONTENT_TYPE = 'application/pdf'; const EXT_PREFIX = 'extensions.uriloader@pdf.js'; const MAX_DATABASE_LENGTH = 4096; +const FIREFOX_ID = '{ec8030f7-c20a-464f-9b0e-13a3a9e97384}'; +const SEAMONKEY_ID = '{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}'; Cu.import('resource://gre/modules/XPCOMUtils.jsm'); Cu.import('resource://gre/modules/Services.jsm'); Cu.import('resource://gre/modules/NetUtil.jsm'); -let privateBrowsing = Cc['@mozilla.org/privatebrowsing;1'] - .getService(Ci.nsIPrivateBrowsingService); -let inPrivateBrowswing = privateBrowsing.privateBrowsingEnabled; +let appInfo = Cc['@mozilla.org/xre/app-info;1'] + .getService(Ci.nsIXULAppInfo); +let privateBrowsing, inPrivateBrowsing; + +if (appInfo.ID === FIREFOX_ID) { + privateBrowsing = Cc['@mozilla.org/privatebrowsing;1'] + .getService(Ci.nsIPrivateBrowsingService); + inPrivateBrowsing = privateBrowsing.privateBrowsingEnabled; +} else if (appInfo.ID === SEAMONKEY_ID) { + privateBrowsing = null; + inPrivateBrowsing = false; +} function getBoolPref(pref, def) { try { @@ -61,8 +72,8 @@ function getDOMWindow(aChannel) { // All the priviledged actions. function ChromeActions() { - this.inPrivateBrowswing = privateBrowsing.privateBrowsingEnabled; } + ChromeActions.prototype = { download: function(data) { let mimeService = Cc['@mozilla.org/mime;1'].getService(Ci.nsIMIMEService); @@ -98,7 +109,7 @@ ChromeActions.prototype = { channel.asyncOpen(listener, null); }, setDatabase: function(data) { - if (this.inPrivateBrowswing) + if (inPrivateBrowsing) return; // Protect against something sending tons of data to setDatabase. if (data.length > MAX_DATABASE_LENGTH) @@ -106,7 +117,7 @@ ChromeActions.prototype = { setStringPref(EXT_PREFIX + '.database', data); }, getDatabase: function() { - if (this.inPrivateBrowswing) + if (inPrivateBrowsing) return '{}'; return getStringPref(EXT_PREFIX + '.database', '{}'); }, diff --git a/extensions/firefox/install.rdf b/extensions/firefox/install.rdf index d7eea9319..a5094c19a 100644 --- a/extensions/firefox/install.rdf +++ b/extensions/firefox/install.rdf @@ -8,11 +8,22 @@ PDF Viewer PDFJSSCRIPT_VERSION + + {ec8030f7-c20a-464f-9b0e-13a3a9e97384} 6.0 - 14.0a1 + 15.0a1 + + + + + + + {92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a} + 2.1.* + 2.12a1 true diff --git a/src/api.js b/src/api.js index bbab680ce..1efb22caa 100644 --- a/src/api.js +++ b/src/api.js @@ -8,10 +8,12 @@ * e.g. No cross domain requests without CORS. * * @param {string|TypedAray} source Either a url to a PDF is located or a - * typed array already populated with data. + * typed array (Uint8Array) already populated with data. + * @param {Object} headers An object containing the http headers like this: + * { Authorization: "BASIC XXX" }. * @return {Promise} A promise that is resolved with {PDFDocumentProxy} object. */ -PDFJS.getDocument = function getDocument(source) { +PDFJS.getDocument = function getDocument(source, headers) { var promise = new PDFJS.Promise(); var transport = new WorkerTransport(promise); if (typeof source === 'string') { @@ -29,7 +31,8 @@ PDFJS.getDocument = function getDocument(source) { error: function getPDFError(e) { promise.reject('Unexpected server response of ' + e.target.status + '.'); - } + }, + headers: headers }, function getPDFLoad(data) { transport.sendData(data); diff --git a/src/core.js b/src/core.js index 6a5ec275c..99a8dd161 100644 --- a/src/core.js +++ b/src/core.js @@ -31,7 +31,19 @@ function getPdf(arg, callback) { params = { url: arg }; var xhr = new XMLHttpRequest(); + xhr.open('GET', params.url); + + var headers = params.headers; + if (headers) { + for (var property in headers) { + if (typeof headers[property] === 'undefined') + continue; + + xhr.setRequestHeader(property, params.headers[property]); + } + } + xhr.mozResponseType = xhr.responseType = 'arraybuffer'; var protocol = params.url.indexOf(':') < 0 ? window.location.protocol : params.url.substring(0, params.url.indexOf(':') + 1);