From 088c6e17e8ed9ceb3396cbf9e0f16ac9a77f0000 Mon Sep 17 00:00:00 2001 From: Michael Payne Date: Wed, 5 Sep 2012 22:52:17 -0700 Subject: [PATCH 1/4] 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. - + From 7bc500af57f27832bd675136caa8cd1578be85c4 Mon Sep 17 00:00:00 2001 From: Michael Payne Date: Wed, 5 Sep 2012 22:54:36 -0700 Subject: [PATCH 2/4] added copyright --- web/inline.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/web/inline.js b/web/inline.js index a965e8cbd..334f804a0 100644 --- a/web/inline.js +++ b/web/inline.js @@ -1 +1,18 @@ - PDFJS.workerSrc = "../build/pdf.js"; \ No newline at end of file +/* 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. + */ + +'use strict'; + + PDFJS.workerSrc = "../build/pdf.js"; \ No newline at end of file From d6d4fc8046fe7b8427b2bc3d17a9a9be63583bfd Mon Sep 17 00:00:00 2001 From: Michael Payne Date: Thu, 6 Sep 2012 08:32:19 -0700 Subject: [PATCH 3/4] remove added inline.js file Moved inline Javascript function to viewer.js rather than create a new file --- web/inline.js | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 web/inline.js diff --git a/web/inline.js b/web/inline.js deleted file mode 100644 index 334f804a0..000000000 --- a/web/inline.js +++ /dev/null @@ -1,18 +0,0 @@ -/* 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. - */ - -'use strict'; - - PDFJS.workerSrc = "../build/pdf.js"; \ No newline at end of file From 6ca9245a39426b3a070b844ad2b84c70a01e1cf8 Mon Sep 17 00:00:00 2001 From: Michael Payne Date: Thu, 6 Sep 2012 08:33:07 -0700 Subject: [PATCH 4/4] Changes to allowed versioned building of Chrome extension that meets new Chrome extension security requirements --- extensions/chrome/manifest.json | 9 ++-- extensions/chrome/pdfHandler.js | 9 ++-- make.js | 9 +++- web/viewer-snippet.html | 1 - web/viewer.html | 30 ++++++------- web/viewer.js | 79 +++++++++++++++++++++++++++++++++ 6 files changed, 111 insertions(+), 26 deletions(-) diff --git a/extensions/chrome/manifest.json b/extensions/chrome/manifest.json index 7d11f678a..63c77905a 100644 --- a/extensions/chrome/manifest.json +++ b/extensions/chrome/manifest.json @@ -1,11 +1,12 @@ { "manifest_version": 2, - "name": "uriloader@pdf.js", - "version": "0.1", - "description": "Read PDF Document", + "name": "PDF Viewer", + "version": "PDFJSSCRIPT_VERSION", + "description": "Uses HTML5 to display PDF files directly in Chrome.", "permissions": [ "webRequest", "webRequestBlocking", - "http://*/*.pdf", "https://*/*.pdf", + "http://*/*.pdf", + "https://*/*.pdf", "file:///*/*.pdf" ], "background": { diff --git a/extensions/chrome/pdfHandler.js b/extensions/chrome/pdfHandler.js index f91944803..d1906ee69 100644 --- a/extensions/chrome/pdfHandler.js +++ b/extensions/chrome/pdfHandler.js @@ -30,9 +30,10 @@ chrome.webRequest.onBeforeRequest.addListener( }, { urls: [ - "http://*/*.pdf", "https://*/*.pdf", - "file://*/*.pdf" + 'http://*/*.pdf', + 'https://*/*.pdf', + 'file://*/*.pdf' ], - types: [ "main_frame" ] + types: ['main_frame'] }, - ["blocking"]); + ['blocking']); diff --git a/make.js b/make.js index d024f7aab..807b3dd7c 100755 --- a/make.js +++ b/make.js @@ -52,7 +52,6 @@ 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 = @@ -582,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/*.js'], + [['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'] @@ -594,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 975d48f9b..294ecc294 100644 --- a/web/viewer-snippet.html +++ b/web/viewer-snippet.html @@ -2,4 +2,3 @@ - diff --git a/web/viewer.html b/web/viewer.html index b82e55050..2b705b72f 100644 --- a/web/viewer.html +++ b/web/viewer.html @@ -82,13 +82,13 @@ limitations under the License.
- - -
@@ -99,8 +99,8 @@ limitations under the License.
@@ -118,16 +118,16 @@ limitations under the License.
-
-
- + @@ -135,19 +135,19 @@ limitations under the License. - - - - @@ -156,16 +156,16 @@ limitations under the License.
-
-
- diff --git a/web/viewer.js b/web/viewer.js index 31d15f31d..27002fabf 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -35,6 +35,7 @@ var RenderingStates = { FINISHED: 3 }; +PDFJS.workerSrc = '../build/pdf.js'; var mozL10n = document.mozL10n || document.webL10n; @@ -1938,6 +1939,84 @@ document.addEventListener('DOMContentLoaded', function webViewerLoad(evt) { PDFView.renderHighestPriority(); }); + document.getElementById('viewThumbnail').addEventListener('click', + function() { + PDFView.switchSidebarView('thumbs'); + }); + + document.getElementById('viewOutline').addEventListener('click', + function() { + PDFView.switchSidebarView('outline'); + }); + + document.getElementById('viewSearch').addEventListener('click', + function() { + PDFView.switchSidebarView('search'); + }); + + document.getElementById('searchButton').addEventListener('click', + function() { + PDFView.search(); + }); + + document.getElementById('previous').addEventListener('click', + function() { + PDFView.page--; + }); + + document.getElementById('next').addEventListener('click', + function() { + PDFView.page++; + }); + + document.querySelector('.zoomIn').addEventListener('click', + function() { + PDFView.zoomIn(); + }); + + document.querySelector('.zoomOut').addEventListener('click', + function() { + PDFView.zoomOut(); + }); + + document.getElementById('fullscreen').addEventListener('click', + function() { + PDFView.fullscreen(); + }); + + document.getElementById('openFile').addEventListener('click', + function() { + document.getElementById('fileInput').click(); + }); + + document.getElementById('print').addEventListener('click', + function() { + window.print(); + }); + + document.getElementById('download').addEventListener('click', + function() { + PDFView.download(); + }); + + document.getElementById('searchTermsInput').addEventListener('keydown', + function() { + if (event.keyCode == 13) { + PDFView.search(); + } + }); + + document.getElementById('pageNumber').addEventListener('change', + function() { + PDFView.page = this.value; + }); + + document.getElementById('scaleSelect').addEventListener('change', + function() { + PDFView.parseScale(this.value); + }); + + //#if (FIREFOX || MOZCENTRAL) //if (FirefoxCom.requestSync('getLoadingType') == 'passive') { // PDFView.setTitleUsingUrl(file);