From 683b511f20e2550b6f580173f0e626f14e3ee06e Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Sun, 25 Aug 2024 20:34:03 +0200 Subject: [PATCH] [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. --- extensions/chromium/extension-router.js | 1 - extensions/chromium/icon19.png | Bin 679 -> 0 bytes extensions/chromium/icon38.png | Bin 1300 -> 0 bytes extensions/chromium/manifest.json | 20 +--- extensions/chromium/pageAction/background.js | 45 -------- extensions/chromium/pageAction/popup.html | 44 -------- extensions/chromium/pageAction/popup.js | 25 ----- extensions/chromium/pdfHandler-vcros.js | 102 ------------------- extensions/chromium/pdfHandler.html | 2 - web/chromecom.js | 3 - web/pdf_history.js | 9 -- 11 files changed, 1 insertion(+), 250 deletions(-) delete mode 100644 extensions/chromium/icon19.png delete mode 100644 extensions/chromium/icon38.png delete mode 100644 extensions/chromium/pageAction/background.js delete mode 100644 extensions/chromium/pageAction/popup.html delete mode 100644 extensions/chromium/pageAction/popup.js delete mode 100644 extensions/chromium/pdfHandler-vcros.js diff --git a/extensions/chromium/extension-router.js b/extensions/chromium/extension-router.js index ecb9004d8..a128a30d1 100644 --- a/extensions/chromium/extension-router.js +++ b/extensions/chromium/extension-router.js @@ -23,7 +23,6 @@ limitations under the License. var schemes = [ "http", "https", - "ftp", "file", "chrome-extension", "blob", diff --git a/extensions/chromium/icon19.png b/extensions/chromium/icon19.png deleted file mode 100644 index 1f67a12883e1ffdbcb1a69a6b86dfebd8ac80349..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 679 zcmV;Y0$BZtP){sKXvTe%$!ZojY&2^+IvtH=KMUSy6|&eNMkScg>mK<<|3>bi>>n5*AKz2@Vaz zKOiv0_Vu&e6FJs!H2&D zQ#E~FWstap1afn8DShPRN_G1Jr=jZ36IJFOMUVy$W zTU>%frr(1zJ77*vnAHuMeHbWUx!?JO5E1~V_runupgw?sZS!Gisc`XFS=i?3 z5FG~h&bc{%1ngVyApA{e{X6{iUdbyva{#{f$cOd*7p8XtUkPS*g<%cBdRP+1*Pa3F zTAe@i%L|C-)U`e=n}UFK`wi}2fQ$QJT1Sws!T#l?U|)JPidZo_vZik{`Q$btH_p6I zllL15m@AfTOEvw@Vq)VkOmkZyL%>YSzFAXPR7|YYt0yu_47+(>r@^$W zW2&alc=YJeH)UX@HtNgH&)Y`R^;xE6A9WU^=GbFe{%}*L{#&$eybHe;J-Gu-`O?^JCr6Z`(E|FYK^eCgTDPMVBHqwZ_1 zR%?X)uf<~d%51Sbz_DZg`|rOE*z>ZfMV^PfzQJfb+HAJmr_H6!$&P3YI!`{>IiW}d zT|K?RkysqTP+0YNeM1h1Gh(yZ?G~%`HwJ#+Y&PG_gYUy$g*`_ZfR)&Ln9SzuxzD@Y z_g5anW_LIu9>23u;Pj4RvhK4XY zHjc@uX{6F=sH%!WDIC-LIGoNfGt5^CY%!S1YWFec)qDG0fdSAQU?q!qie6TtB z8xv{*Ok|)QrSq1Ozp+*}=_cL<^6lv)SSppu^<}Dm*ra=I0_7`B9h3@?E&vJ2)7+5B zG93j|RmvkvN?-&DEJYm@0R5FsqY@Zqb17BiWezF$WFFz!Meee=Q{PVYDudsbqm~-+)-cn73&#Sw2T~u=gH;q_H93qFu%PCF$?4s)LCQ_U3b> ziArs-Vsq6u*n>AIzm$($u5YH|{t~f^cbkble;aVj8bx4pU>(wRH_buoO>Vx^-g7U! z$U@YB=Ho}w9JM`?#A7I(;dTJ2BmJ=jV=g0yJ-J7cI5En0b>g6yNF+s{XeV?~ z@~of7I)B1Yq2@9Ns4{6lIElff5-*$1^4$5|sqM z6oX;5mJ-l2rp-54oU!7i9EGaV9COauksl)bnwfur1tyBYiZ!SLG*=ryxKu!Cb}F5r zY&I+XI;v$U`?W#lnyWc9MO6iafYCup2%vIcYGLf>vC)x#8EonK=bwL>dFPvd;aVYi z(7{@iN(MT*-_Y)x; ziNfvi_S$SV2Ui!rHknM9^4M!um|K9=>bcq5FzD@EIs93xb7&", @@ -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:*", diff --git a/extensions/chromium/pageAction/background.js b/extensions/chromium/pageAction/background.js deleted file mode 100644 index e19697039..000000000 --- a/extensions/chromium/pageAction/background.js +++ /dev/null @@ -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); - } - }); -})(); diff --git a/extensions/chromium/pageAction/popup.html b/extensions/chromium/pageAction/popup.html deleted file mode 100644 index f18ff2752..000000000 --- a/extensions/chromium/pageAction/popup.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - - - - - diff --git a/extensions/chromium/pageAction/popup.js b/extensions/chromium/pageAction/popup.js deleted file mode 100644 index 317759452..000000000 --- a/extensions/chromium/pageAction/popup.js +++ /dev/null @@ -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(); -} diff --git a/extensions/chromium/pdfHandler-vcros.js b/extensions/chromium/pdfHandler-vcros.js deleted file mode 100644 index e584d3ac8..000000000 --- a/extensions/chromium/pdfHandler-vcros.js +++ /dev/null @@ -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); - } - ); - } - } -})(); diff --git a/extensions/chromium/pdfHandler.html b/extensions/chromium/pdfHandler.html index a87cec438..7a5a036e9 100644 --- a/extensions/chromium/pdfHandler.html +++ b/extensions/chromium/pdfHandler.html @@ -18,7 +18,5 @@ limitations under the License. - - diff --git a/web/chromecom.js b/web/chromecom.js index b33e44537..cb95a89c2 100644 --- a/web/chromecom.js +++ b/web/chromecom.js @@ -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); })(); diff --git a/web/pdf_history.js b/web/pdf_history.js index 5d3baa38d..6c965ffbb 100644 --- a/web/pdf_history.js +++ b/web/pdf_history.js @@ -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) {