From babd8df1769a82b1b65a9e394a68cf695ed179dd Mon Sep 17 00:00:00 2001 From: Brendan Dahl Date: Mon, 29 Oct 2012 12:44:18 -0700 Subject: [PATCH] Un-inline pdf.js for the extension/mozcentral and remove fetch pdf by content code. --- .../firefox/components/PdfStreamConverter.js | 60 ++++++------------- make.js | 6 +- src/api.js | 12 +--- web/viewer-snippet-firefox-extension.html | 13 +--- web/viewer.js | 2 +- 5 files changed, 25 insertions(+), 68 deletions(-) diff --git a/extensions/firefox/components/PdfStreamConverter.js b/extensions/firefox/components/PdfStreamConverter.js index bf170fd56..9af39cbc1 100644 --- a/extensions/firefox/components/PdfStreamConverter.js +++ b/extensions/firefox/components/PdfStreamConverter.js @@ -544,21 +544,6 @@ PdfStreamConverter.prototype = { if (!isEnabled()) throw Cr.NS_ERROR_NOT_IMPLEMENTED; - var useFetchByChrome = getBoolPref(PREF_PREFIX + '.fetchByChrome', true); - if (!useFetchByChrome) { - // Ignoring HTTP POST requests -- pdf.js has to repeat the request. - var skipConversion = false; - try { - var request = aCtxt; - request.QueryInterface(Ci.nsIHttpChannel); - skipConversion = (request.requestMethod !== 'GET'); - } catch (e) { - // Non-HTTP request... continue normally. - } - if (skipConversion) - throw Cr.NS_ERROR_NOT_IMPLEMENTED; - } - // Store the listener passed to us this.listener = aListener; }, @@ -577,22 +562,15 @@ PdfStreamConverter.prototype = { // nsIRequestObserver::onStartRequest onStartRequest: function(aRequest, aContext) { - // Setup the request so we can use it below. aRequest.QueryInterface(Ci.nsIChannel); - var useFetchByChrome = getBoolPref(PREF_PREFIX + '.fetchByChrome', true); - var dataListener; - if (useFetchByChrome) { - // Creating storage for PDF data - var contentLength = aRequest.contentLength; - dataListener = new PdfDataListener(contentLength); - this.dataListener = dataListener; - this.binaryStream = Cc['@mozilla.org/binaryinputstream;1'] - .createInstance(Ci.nsIBinaryInputStream); - } else { - // Cancel the request so the viewer can handle it. - aRequest.cancel(Cr.NS_BINDING_ABORTED); - } + // Creating storage for PDF data + var contentLength = aRequest.contentLength; + var dataListener = new PdfDataListener(contentLength); + this.dataListener = dataListener; + this.binaryStream = Cc['@mozilla.org/binaryinputstream;1'] + .createInstance(Ci.nsIBinaryInputStream); + // Change the content type so we don't get stuck in a loop. aRequest.contentType = 'text/html'; @@ -642,19 +620,17 @@ PdfStreamConverter.prototype = { channel.originalURI = aRequest.URI; channel.loadGroup = aRequest.loadGroup; - if (useFetchByChrome) { - // We can use resource principal when data is fetched by the chrome - // e.g. useful for NoScript - var securityManager = Cc['@mozilla.org/scriptsecuritymanager;1'] - .getService(Ci.nsIScriptSecurityManager); - var uri = ioService.newURI(PDF_VIEWER_WEB_PAGE, null, null); - // FF16 and below had getCodebasePrincipal, it was replaced by - // getNoAppCodebasePrincipal (bug 758258). - var resourcePrincipal = 'getNoAppCodebasePrincipal' in securityManager ? - securityManager.getNoAppCodebasePrincipal(uri) : - securityManager.getCodebasePrincipal(uri); - aRequest.owner = resourcePrincipal; - } + // We can use resource principal when data is fetched by the chrome + // e.g. useful for NoScript + var securityManager = Cc['@mozilla.org/scriptsecuritymanager;1'] + .getService(Ci.nsIScriptSecurityManager); + var uri = ioService.newURI(PDF_VIEWER_WEB_PAGE, null, null); + // FF16 and below had getCodebasePrincipal, it was replaced by + // getNoAppCodebasePrincipal (bug 758258). + var resourcePrincipal = 'getNoAppCodebasePrincipal' in securityManager ? + securityManager.getNoAppCodebasePrincipal(uri) : + securityManager.getCodebasePrincipal(uri); + aRequest.owner = resourcePrincipal; channel.asyncOpen(proxy, aContext); }, diff --git a/make.js b/make.js index 7ac2e28c1..52e405199 100644 --- a/make.js +++ b/make.js @@ -354,7 +354,8 @@ target.firefox = function() { FIREFOX_BUILD_CONTENT_DIR + '/web'] ], preprocess: [ - [COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web'] + [COMMON_WEB_FILES_PREPROCESS, FIREFOX_BUILD_CONTENT_DIR + '/web'], + [BUILD_TARGET, FIREFOX_BUILD_CONTENT_DIR + BUILD_TARGET] ] }; builder.build(setup); @@ -462,7 +463,8 @@ target.mozcentral = function() { ['extensions/firefox/tools/l10n.js', MOZCENTRAL_CONTENT_DIR + '/web'] ], preprocess: [ - [COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web'] + [COMMON_WEB_FILES_PREPROCESS, MOZCENTRAL_CONTENT_DIR + '/web'], + [BUILD_TARGET, MOZCENTRAL_CONTENT_DIR + BUILD_TARGET] ] }; builder.build(setup); diff --git a/src/api.js b/src/api.js index 02bb87941..5d64e3d09 100644 --- a/src/api.js +++ b/src/api.js @@ -456,19 +456,9 @@ var WorkerTransport = (function WorkerTransportClosure() { } try { - var worker; -//#if !(FIREFOX || MOZCENTRAL) // Some versions of FF can't create a worker on localhost, see: // https://bugzilla.mozilla.org/show_bug.cgi?id=683280 - worker = new Worker(workerSrc); -//#else -// // The firefox extension can't load the worker from the resource:// -// // url so we have to inline the script and then use the blob loader. -// var script = document.querySelector('#PDFJS_SCRIPT_TAG'); -// var blob = PDFJS.createBlob(script.textContent, script.type); -// var blobUrl = window.URL.createObjectURL(blob); -// worker = new Worker(blobUrl); -//#endif + var worker = new Worker(workerSrc); var messageHandler = new MessageHandler('main', worker); this.messageHandler = messageHandler; diff --git a/web/viewer-snippet-firefox-extension.html b/web/viewer-snippet-firefox-extension.html index 5b8cc9eaf..83f10cf55 100644 --- a/web/viewer-snippet-firefox-extension.html +++ b/web/viewer-snippet-firefox-extension.html @@ -1,15 +1,4 @@ - - + diff --git a/web/viewer.js b/web/viewer.js index 7caab488e..d69f1f4c7 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -44,7 +44,7 @@ var FindStates = { var ANNOT_MIN_SIZE = 10; -//#if (GENERIC || CHROME) +//#if (FIREFOX || MOZCENTRAL || B2G || GENERIC || CHROME) //PDFJS.workerSrc = '../build/pdf.js'; //#endif