From b754f9d878e51784fb0c6e2889a45ff7d6b42b0c Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Wed, 15 Jan 2014 22:58:55 +0100 Subject: [PATCH] Make streamsPrivate optional; remove manifest key Use streamsPrivate API when available. When the API is not available, the extension will still work on on http/https/file URLs, but not for POST requests or FTP. As of writing, the Chromium project has still not whitelisted the PDF Viewer extension in the Chrome Web Store. (extension ID oemmndcbldboiebfnladdacbdfmadadm) Request to whitelist PDF.js in Chromium: https://code.google.com/p/chromium/issues/detail?id=326949 Opera 19 has whitelisted the PDF Viewer extension from https://addons.opera.com/extensions/details/pdf-viewer/ (extension ID encfpfilknmenlmjemepncnlbbjlabkc) (https://github.com/Rob--W/pdf.js/issues/1#issuecomment-32357302) If you want to test the streamsPrivate feature in Chrome, edit the build/extensions/manifest.json and add the "key" again (see this commit for the value of this "key" field). --- extensions/chromium/manifest.json | 6 ------ extensions/chromium/pdfHandler-v2.js | 20 ++++++++++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/extensions/chromium/manifest.json b/extensions/chromium/manifest.json index c029d12a4..cd760480b 100644 --- a/extensions/chromium/manifest.json +++ b/extensions/chromium/manifest.json @@ -16,12 +16,6 @@ "storage", "streamsPrivate" ], - /* FOR demo & debugging purposes only! This key is required to get access to the streams API. - * This key forces the extension ID to be gbkeegbaiigmenfmjfclcdgdpimamgkj (= Chrome Office Viewer) - * This comment has been added to prevent it from being uploaded to the Chrome Web Store. - * Remove it when the PDF.js extensionID is whitelisted for the streamsPrivate API. - */ - "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC4zyYTii0VTKI7W2U6fDeAvs3YCVZeAt7C62IC64IDCMHvWy7SKMpOPjfg5v1PgYkFm+fGsCsVLN8NaF7fzYMVtjLc5bqhqPAi56Qidrqh1HxPAAYhwFQd5BVGhZmh1fySHXFPE8VI2tIHwRrASOtx67jbSEk4nBAcJz6n+eGq8QIDAQAB", "content_scripts": [{ "matches": [ "http://*/*", diff --git a/extensions/chromium/pdfHandler-v2.js b/extensions/chromium/pdfHandler-v2.js index 91b90bfb9..92c621134 100644 --- a/extensions/chromium/pdfHandler-v2.js +++ b/extensions/chromium/pdfHandler-v2.js @@ -17,8 +17,22 @@ limitations under the License. */ /* globals chrome, URL, getViewerURL */ +(function() { 'use strict'; +if (!chrome.streamsPrivate) { + // Aww, PDF.js is still not whitelisted... See http://crbug.com/326949 + console.warn('streamsPrivate not available, PDF from FTP or POST ' + + 'requests will not be displayed using this extension! ' + + 'See http://crbug.com/326949'); + chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { + if (message && message.action === 'getPDFStream') { + sendResponse(); + } + }); + return; +} + // // Stream URL storage manager // @@ -26,10 +40,6 @@ limitations under the License. // Hash map of "": { "": ["", ...], ... } var urlToStream = {}; -// Note: Execution of this script stops when the streamsPrivate API is -// not available, because an error will be thrown. Don't bother with -// catching and handling the error, because it is a great way to see -// when the streamsPrivate API is unavailable. chrome.streamsPrivate.onExecuteMimeTypeHandler.addListener(handleStream); // Chrome before 27 does not support tabIds on stream events. @@ -235,3 +245,5 @@ function handleWebNavigation(details) { }); } } + +})();