mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-18 14:18:23 +02:00
[CRX] Remove obsolete manifest features
In preparation for migrating the Chrome extension to Manifest Version 3, this patch removes parts of the manifest that are obsolete and/or unsupported in MV3. Remove ftp mentions: ftp was dropped from 6 years ago, in Chrome 59. Remove file_browser_handlers: does not work on Chrome OS according to https://github.com/mozilla/pdf.js/issues/14161 . MV3 replacement needs a different manifest key and logic, which will be added later. Remove content_security_policy: MV3 does not support unsafe-eval CSP, and PDF.js does not require it. This may result in a mild performance degradation in PDFs that contain PostScript. Remove page_action logic: When this logic was originally introduced, Chrome showed page action buttons in the address bar, which enabled the extension to display the button on specific PDF viewer tabs only. In Chrome 49 (2016), pageActions were dropped from the address bar and put in an UI area that is hidden by default. The user can pin the button to be unconditionally visible on the toolbar, which is distracting. Because the UX is no longer serving the original needs, this patch removes page_action from the manifest.
This commit is contained in:
parent
cd99be0aa5
commit
683b511f20
11 changed files with 1 additions and 250 deletions
|
@ -23,7 +23,6 @@ limitations under the License.
|
|||
var schemes = [
|
||||
"http",
|
||||
"https",
|
||||
"ftp",
|
||||
"file",
|
||||
"chrome-extension",
|
||||
"blob",
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 679 B |
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB |
|
@ -10,7 +10,6 @@
|
|||
"16": "icon16.png"
|
||||
},
|
||||
"permissions": [
|
||||
"fileBrowserHandler",
|
||||
"webRequest",
|
||||
"webRequestBlocking",
|
||||
"<all_urls>",
|
||||
|
@ -20,21 +19,13 @@
|
|||
],
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["http://*/*", "https://*/*", "ftp://*/*", "file://*/*"],
|
||||
"matches": ["http://*/*", "https://*/*", "file://*/*"],
|
||||
"run_at": "document_start",
|
||||
"all_frames": true,
|
||||
"css": ["contentstyle.css"],
|
||||
"js": ["contentscript.js"]
|
||||
}
|
||||
],
|
||||
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
|
||||
"file_browser_handlers": [
|
||||
{
|
||||
"id": "open-as-pdf",
|
||||
"default_title": "Open with PDF Viewer",
|
||||
"file_filters": ["filesystem:*.pdf"]
|
||||
}
|
||||
],
|
||||
"storage": {
|
||||
"managed_schema": "preferences_schema.json"
|
||||
},
|
||||
|
@ -46,20 +37,11 @@
|
|||
"background": {
|
||||
"page": "pdfHandler.html"
|
||||
},
|
||||
"page_action": {
|
||||
"default_icon": {
|
||||
"19": "icon19.png",
|
||||
"38": "icon38.png"
|
||||
},
|
||||
"default_title": "Show PDF URL",
|
||||
"default_popup": "pageActionPopup.html"
|
||||
},
|
||||
"incognito": "split",
|
||||
"web_accessible_resources": [
|
||||
"content/web/viewer.html",
|
||||
"http:/*",
|
||||
"https:/*",
|
||||
"ftp:/*",
|
||||
"file:/*",
|
||||
"chrome-extension:/*",
|
||||
"blob:*",
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
Copyright 2014 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";
|
||||
|
||||
(function PageActionClosure() {
|
||||
/**
|
||||
* @param {number} tabId - ID of tab where the page action will be shown.
|
||||
* @param {string} url - URL to be displayed in page action.
|
||||
*/
|
||||
function showPageAction(tabId, displayUrl) {
|
||||
// rewriteUrlClosure in viewer.js ensures that the URL looks like
|
||||
// chrome-extension://[extensionid]/http://example.com/file.pdf
|
||||
var url = /^chrome-extension:\/\/[a-p]{32}\/([^#]+)/.exec(displayUrl);
|
||||
if (url) {
|
||||
url = url[1];
|
||||
chrome.pageAction.setPopup({
|
||||
tabId,
|
||||
popup: "/pageAction/popup.html?file=" + encodeURIComponent(url),
|
||||
});
|
||||
chrome.pageAction.show(tabId);
|
||||
} else {
|
||||
console.log("Unable to get PDF url from " + displayUrl);
|
||||
}
|
||||
}
|
||||
|
||||
chrome.runtime.onMessage.addListener(function (message, sender) {
|
||||
if (message === "showPageAction" && sender.tab) {
|
||||
showPageAction(sender.tab.id, sender.tab.url);
|
||||
}
|
||||
});
|
||||
})();
|
|
@ -1,44 +0,0 @@
|
|||
<!doctype html>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<style>
|
||||
html {
|
||||
/* maximum width of popup as defined in Chromium's source code as kMaxWidth
|
||||
//src/chrome/browser/ui/views/extensions/extension_popup.cc
|
||||
//src/chrome/browser/ui/gtk/extensions/extension_popup_gtk.cc
|
||||
*/
|
||||
width: 800px;
|
||||
/* in case Chromium decides to lower the value of kMaxWidth */
|
||||
max-width: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
body {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 5px;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body contentEditable="plaintext-only" spellcheck="false">
|
||||
<script src="popup.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,25 +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";
|
||||
|
||||
var url = location.search.match(/[&?]file=([^&]+)/i);
|
||||
if (url) {
|
||||
url = decodeURIComponent(url[1]);
|
||||
document.body.textContent = url;
|
||||
// Set cursor to end of the content-editable section.
|
||||
window.getSelection().selectAllChildren(document.body);
|
||||
window.getSelection().collapseToEnd();
|
||||
}
|
|
@ -1,102 +0,0 @@
|
|||
/*
|
||||
Copyright 2014 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.
|
||||
*/
|
||||
/* eslint strict: ["error", "function"] */
|
||||
/* globals getViewerURL */
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
if (!chrome.fileBrowserHandler) {
|
||||
// Not on Chromium OS, bail out
|
||||
return;
|
||||
}
|
||||
chrome.fileBrowserHandler.onExecute.addListener(onExecuteFileBrowserHandler);
|
||||
|
||||
/**
|
||||
* Invoked when "Open with PDF Viewer" is chosen in the File browser.
|
||||
*
|
||||
* @param {string} id File browser action ID as specified in
|
||||
* manifest.json
|
||||
* @param {Object} details Object of type FileHandlerExecuteEventDetails
|
||||
*/
|
||||
function onExecuteFileBrowserHandler(id, details) {
|
||||
if (id !== "open-as-pdf") {
|
||||
return;
|
||||
}
|
||||
var fileEntries = details.entries;
|
||||
// "tab_id" is the currently documented format, but it is inconsistent with
|
||||
// the other Chrome APIs that use "tabId" (http://crbug.com/179767)
|
||||
var tabId = details.tab_id || details.tabId;
|
||||
if (tabId > 0) {
|
||||
chrome.tabs.get(tabId, function (tab) {
|
||||
openViewer(tab && tab.windowId, fileEntries);
|
||||
});
|
||||
} else {
|
||||
// Re-use existing window, if available.
|
||||
chrome.windows.getLastFocused(function (chromeWindow) {
|
||||
var windowId = chromeWindow && chromeWindow.id;
|
||||
if (windowId) {
|
||||
chrome.windows.update(windowId, { focused: true });
|
||||
}
|
||||
openViewer(windowId, fileEntries);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the PDF Viewer for the given list of PDF files.
|
||||
*
|
||||
* @param {number} windowId
|
||||
* @param {Array} fileEntries List of Entry objects (HTML5 FileSystem API)
|
||||
*/
|
||||
function openViewer(windowId, fileEntries) {
|
||||
if (!fileEntries.length) {
|
||||
return;
|
||||
}
|
||||
var fileEntry = fileEntries.shift();
|
||||
var url = fileEntry.toURL();
|
||||
// Use drive: alias to get shorter (more human-readable) URLs.
|
||||
url = url.replace(
|
||||
/^filesystem:chrome-extension:\/\/[a-p]{32}\/external\//,
|
||||
"drive:"
|
||||
);
|
||||
url = getViewerURL(url);
|
||||
|
||||
if (windowId) {
|
||||
chrome.tabs.create(
|
||||
{
|
||||
windowId,
|
||||
active: true,
|
||||
url,
|
||||
},
|
||||
function () {
|
||||
openViewer(windowId, fileEntries);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
chrome.windows.create(
|
||||
{
|
||||
type: "normal",
|
||||
focused: true,
|
||||
url,
|
||||
},
|
||||
function (chromeWindow) {
|
||||
openViewer(chromeWindow.id, fileEntries);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
})();
|
|
@ -18,7 +18,5 @@ limitations under the License.
|
|||
<script src="preserve-referer.js"></script>
|
||||
<script src="pdfHandler.js"></script>
|
||||
<script src="extension-router.js"></script>
|
||||
<script src="pdfHandler-vcros.js"></script>
|
||||
<script src="pageAction/background.js"></script>
|
||||
<script src="suppress-update.js"></script>
|
||||
<script src="telemetry.js"></script>
|
||||
|
|
|
@ -36,9 +36,6 @@ if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME")) {
|
|||
// Example: chrome-extension://.../http://example.com/file.pdf
|
||||
const humanReadableUrl = "/" + defaultUrl + location.hash;
|
||||
history.replaceState(history.state, "", humanReadableUrl);
|
||||
if (top === window) {
|
||||
chrome.runtime.sendMessage("showPageAction");
|
||||
}
|
||||
|
||||
AppOptions.set("defaultUrl", defaultUrl);
|
||||
})();
|
||||
|
|
|
@ -394,15 +394,6 @@ class PDFHistory {
|
|||
} else {
|
||||
window.history.pushState(newState, "", newUrl);
|
||||
}
|
||||
|
||||
if (
|
||||
typeof PDFJSDev !== "undefined" &&
|
||||
PDFJSDev.test("CHROME") &&
|
||||
top === window
|
||||
) {
|
||||
// eslint-disable-next-line no-undef
|
||||
chrome.runtime.sendMessage("showPageAction");
|
||||
}
|
||||
}
|
||||
|
||||
#tryPushCurrentPosition(temporary = false) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue