From 353a43cb46e34ee82b3458df1138952282973aec Mon Sep 17 00:00:00 2001 From: asraniel Date: Sun, 6 May 2012 21:24:42 +0200 Subject: [PATCH 1/7] Add first API change, not working yet --- src/api.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/api.js b/src/api.js index bbab680ce..b3415c08e 100644 --- a/src/api.js +++ b/src/api.js @@ -8,10 +8,10 @@ * 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. * @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 +29,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); From 315071ca28ab1bdba6f1a27558f507f41a48d962 Mon Sep 17 00:00:00 2001 From: asraniel Date: Sun, 6 May 2012 21:32:30 +0200 Subject: [PATCH 2/7] Add stub for the last piece of the puzzle --- src/core.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/core.js b/src/core.js index 6a5ec275c..908ba63af 100644 --- a/src/core.js +++ b/src/core.js @@ -31,6 +31,11 @@ function getPdf(arg, callback) { params = { url: arg }; var xhr = new XMLHttpRequest(); + + if(params.headers){ + //TODO: Code this, use xhr.setRequestHeader(key, value); + } + xhr.open('GET', params.url); xhr.mozResponseType = xhr.responseType = 'arraybuffer'; var protocol = params.url.indexOf(':') < 0 ? window.location.protocol : From 7786e4fefbc4bc2f5f8301b8aaa89c8180ff8999 Mon Sep 17 00:00:00 2001 From: beat Date: Mon, 7 May 2012 09:17:00 +0200 Subject: [PATCH 3/7] Make authentication work --- src/api.js | 2 ++ src/core.js | 11 +++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/api.js b/src/api.js index b3415c08e..0c4865841 100644 --- a/src/api.js +++ b/src/api.js @@ -9,6 +9,8 @@ * * @param {string|TypedAray} source Either a url to a PDF is located or a * 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, headers) { diff --git a/src/core.js b/src/core.js index 908ba63af..e999550ca 100644 --- a/src/core.js +++ b/src/core.js @@ -32,11 +32,14 @@ function getPdf(arg, callback) { var xhr = new XMLHttpRequest(); - if(params.headers){ - //TODO: Code this, use xhr.setRequestHeader(key, value); - } - xhr.open('GET', params.url); + if(params.headers){ + for(var property in params.headers){ + if(typeof(params.headers[property]) !== undefined){ + 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); From e11cad884c1c0af012e422e26c8b45905548361a Mon Sep 17 00:00:00 2001 From: beat Date: Tue, 8 May 2012 14:17:51 +0200 Subject: [PATCH 4/7] code style fixes --- src/api.js | 4 ++-- src/core.js | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/api.js b/src/api.js index 0c4865841..1efb22caa 100644 --- a/src/api.js +++ b/src/api.js @@ -10,7 +10,7 @@ * @param {string|TypedAray} source Either a url to a PDF is located or a * typed array (Uint8Array) already populated with data. * @param {Object} headers An object containing the http headers like this: - * { Authorization: "BASIC XXX" } + * { Authorization: "BASIC XXX" }. * @return {Promise} A promise that is resolved with {PDFDocumentProxy} object. */ PDFJS.getDocument = function getDocument(source, headers) { @@ -32,7 +32,7 @@ PDFJS.getDocument = function getDocument(source, headers) { promise.reject('Unexpected server response of ' + e.target.status + '.'); }, - headers: headers + headers: headers }, function getPDFLoad(data) { transport.sendData(data); diff --git a/src/core.js b/src/core.js index e999550ca..c6d8b743c 100644 --- a/src/core.js +++ b/src/core.js @@ -33,13 +33,17 @@ function getPdf(arg, callback) { var xhr = new XMLHttpRequest(); xhr.open('GET', params.url); - if(params.headers){ - for(var property in params.headers){ - if(typeof(params.headers[property]) !== undefined){ - xhr.setRequestHeader(property, params.headers[property]); - } + + 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); From e1146b64adf3d9408e8679d06136aab6db6978f8 Mon Sep 17 00:00:00 2001 From: beat Date: Tue, 8 May 2012 16:34:46 +0200 Subject: [PATCH 5/7] fix 4 lint errors --- src/core.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core.js b/src/core.js index c6d8b743c..99a8dd161 100644 --- a/src/core.js +++ b/src/core.js @@ -31,19 +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); From bf64240dc315ed4974769995716e93592f5010eb Mon Sep 17 00:00:00 2001 From: Jakob Miland Date: Sat, 12 May 2012 15:16:53 +0200 Subject: [PATCH 6/7] SeaMonkey support without SMILE --- .../firefox/components/PdfStreamConverter.js | 23 ++++++++++++++----- extensions/firefox/install.rdf | 11 +++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) 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..a8177834e 100644 --- a/extensions/firefox/install.rdf +++ b/extensions/firefox/install.rdf @@ -8,6 +8,8 @@ PDF Viewer PDFJSSCRIPT_VERSION + + {ec8030f7-c20a-464f-9b0e-13a3a9e97384} @@ -15,6 +17,15 @@ 14.0a1 + + + + + {92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a} + 2.1.* + 2.9.* + + true Mozilla Uses HTML5 to display PDF files directly in Firefox. From 7b5c69cac5aee49df014bd9e93aa559f8aed0e38 Mon Sep 17 00:00:00 2001 From: Jakob Miland Date: Sat, 12 May 2012 19:42:27 +0200 Subject: [PATCH 7/7] Updated Firefox and SeaMonkey's maxVersion --- extensions/firefox/install.rdf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/firefox/install.rdf b/extensions/firefox/install.rdf index a8177834e..a5094c19a 100644 --- a/extensions/firefox/install.rdf +++ b/extensions/firefox/install.rdf @@ -14,7 +14,7 @@ {ec8030f7-c20a-464f-9b0e-13a3a9e97384} 6.0 - 14.0a1 + 15.0a1 @@ -23,7 +23,7 @@ {92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a} 2.1.* - 2.9.* + 2.12a1 true