From 088c6e17e8ed9ceb3396cbf9e0f16ac9a77f0000 Mon Sep 17 00:00:00 2001 From: Michael Payne Date: Wed, 5 Sep 2012 22:52:17 -0700 Subject: [PATCH] changes to allow chrome extension to load changes to remove inline scripts, update manifest version, fix make.js so compatibility.js isn't included for chrome. Due to new Chrome extension changes outlined at http://developer.chrome.com/extensions/manifestVersion.html --- extensions/chrome/manifest.json | 7 ++++-- extensions/chrome/pdfHandler.html | 28 +---------------------- extensions/chrome/pdfHandler.js | 38 +++++++++++++++++++++++++++++++ make.js | 3 ++- web/inline.js | 1 + web/viewer-snippet.html | 5 +--- web/viewer.html | 2 +- 7 files changed, 49 insertions(+), 35 deletions(-) create mode 100644 extensions/chrome/pdfHandler.js create mode 100644 web/inline.js diff --git a/extensions/chrome/manifest.json b/extensions/chrome/manifest.json index 9b34437b2..7d11f678a 100644 --- a/extensions/chrome/manifest.json +++ b/extensions/chrome/manifest.json @@ -1,11 +1,14 @@ { + "manifest_version": 2, "name": "uriloader@pdf.js", "version": "0.1", "description": "Read PDF Document", "permissions": [ "webRequest", "webRequestBlocking", - "http://*/*.pdf", + "http://*/*.pdf", "https://*/*.pdf", "file:///*/*.pdf" ], - "background_page": "pdfHandler.html" + "background": { + "page": "pdfHandler.html" + } } diff --git a/extensions/chrome/pdfHandler.html b/extensions/chrome/pdfHandler.html index 35375de73..7a64ecd16 100644 --- a/extensions/chrome/pdfHandler.html +++ b/extensions/chrome/pdfHandler.html @@ -14,30 +14,4 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> - - + diff --git a/extensions/chrome/pdfHandler.js b/extensions/chrome/pdfHandler.js new file mode 100644 index 000000000..f91944803 --- /dev/null +++ b/extensions/chrome/pdfHandler.js @@ -0,0 +1,38 @@ +/* +Copyright 2012 Mozilla Foundation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +function isPdfDownloadable(details) { + return details.url.indexOf('pdfjs.action=download') >= 0; +} + +chrome.webRequest.onBeforeRequest.addListener( + function(details) { + if (isPdfDownloadable(details)) + return; + + var viewerPage = 'content/web/viewer.html'; + var url = chrome.extension.getURL(viewerPage) + + '?file=' + encodeURIComponent(details.url); + return { redirectUrl: url }; + }, + { + urls: [ + "http://*/*.pdf", "https://*/*.pdf", + "file://*/*.pdf" + ], + types: [ "main_frame" ] + }, + ["blocking"]); diff --git a/make.js b/make.js index 88fec48cf..d024f7aab 100755 --- a/make.js +++ b/make.js @@ -52,6 +52,7 @@ target.all = function() { // Files that need to be included in every build. var COMMON_WEB_FILES = ['web/viewer.css', + 'web/inline.js', 'web/images', 'web/debugger.js'], COMMON_WEB_FILES_PREPROCESS = @@ -581,7 +582,7 @@ target.chrome = function() { defines: defines, copy: [ [COMMON_WEB_FILES, CHROME_BUILD_CONTENT_DIR + '/web'], - [['extensions/chrome/*.json', 'extensions/chrome/*.html'], + [['extensions/chrome/*.json', 'extensions/chrome/*.html', 'extensions/chrome/*.js'], CHROME_BUILD_DIR], [BUILD_TARGET, CHROME_BUILD_CONTENT_DIR + BUILD_TARGET], ['external/webL10n/l10n.js', CHROME_BUILD_CONTENT_DIR + '/web'] diff --git a/web/inline.js b/web/inline.js new file mode 100644 index 000000000..a965e8cbd --- /dev/null +++ b/web/inline.js @@ -0,0 +1 @@ + PDFJS.workerSrc = "../build/pdf.js"; \ No newline at end of file diff --git a/web/viewer-snippet.html b/web/viewer-snippet.html index 3d535169e..975d48f9b 100644 --- a/web/viewer-snippet.html +++ b/web/viewer-snippet.html @@ -2,7 +2,4 @@ - + diff --git a/web/viewer.html b/web/viewer.html index 0ad48703e..b82e55050 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -29,7 +29,7 @@ limitations under the License. - +