diff --git a/extensions/chrome/manifest.json b/extensions/chrome/manifest.json index 9b34437b2..63c77905a 100644 --- a/extensions/chrome/manifest.json +++ b/extensions/chrome/manifest.json @@ -1,11 +1,15 @@ { - "name": "uriloader@pdf.js", - "version": "0.1", - "description": "Read PDF Document", + "manifest_version": 2, + "name": "PDF Viewer", + "version": "PDFJSSCRIPT_VERSION", + "description": "Uses HTML5 to display PDF files directly in Chrome.", "permissions": [ "webRequest", "webRequestBlocking", "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..d1906ee69 --- /dev/null +++ b/extensions/chrome/pdfHandler.js @@ -0,0 +1,39 @@ +/* +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..807b3dd7c 100755 --- a/make.js +++ b/make.js @@ -581,7 +581,9 @@ 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'] @@ -593,6 +595,10 @@ target.chrome = function() { }; builder.build(setup); + // Update the build version number + sed('-i', /PDFJSSCRIPT_VERSION/, EXTENSION_VERSION, + CHROME_BUILD_DIR + '/manifest.json'); + // Bundle the files to a Chrome extension file .crx if path to key is set var pem = env['PDFJS_CHROME_KEY']; if (!pem) { diff --git a/web/viewer-snippet.html b/web/viewer-snippet.html index 3d535169e..294ecc294 100644 --- a/web/viewer-snippet.html +++ b/web/viewer-snippet.html @@ -2,7 +2,3 @@ - diff --git a/web/viewer.html b/web/viewer.html index 0ad48703e..2b705b72f 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -29,7 +29,7 @@ limitations under the License. - + @@ -82,13 +82,13 @@ limitations under the License.