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).
This commit is contained in:
Rob Wu 2014-01-15 22:58:55 +01:00
parent af31ace940
commit b754f9d878
2 changed files with 16 additions and 10 deletions

View File

@ -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://*/*",

View File

@ -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 "<tab id>": { "<pdf url>": ["<stream url>", ...], ... }
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) {
});
}
}
})();