Merge pull request #16028 from Snuffleupagus/move-CHROME-rewriteUrlClosure

Move `rewriteUrlClosure` into the `web/chromecom.js` file
This commit is contained in:
Tim van der Meij 2023-02-11 19:02:32 +01:00 committed by GitHub
commit ddf05b0795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 20 deletions

View File

@ -27,6 +27,23 @@ if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME")) {
);
}
(function rewriteUrlClosure() {
// Run this code outside DOMContentLoaded to make sure that the URL
// is rewritten as soon as possible.
const queryString = document.location.search.slice(1);
const m = /(^|&)file=([^&]*)/.exec(queryString);
const defaultUrl = m ? decodeURIComponent(m[2]) : "";
// 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);
})();
const ChromeCom = {
/**
* Creates an event that the extension is listening for and will

View File

@ -36,26 +36,6 @@ window.PDFViewerApplication = PDFViewerApplication;
window.PDFViewerApplicationConstants = AppConstants;
window.PDFViewerApplicationOptions = AppOptions;
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) {
(function rewriteUrlClosure() {
// Run this code outside DOMContentLoaded to make sure that the URL
// is rewritten as soon as possible.
const queryString = document.location.search.slice(1);
const m = /(^|&)file=([^&]*)/.exec(queryString);
const defaultUrl = m ? decodeURIComponent(m[2]) : "";
// Example: chrome-extension://.../http://example.com/file.pdf
const humanReadableUrl = "/" + defaultUrl + location.hash;
history.replaceState(history.state, "", humanReadableUrl);
if (top === window) {
// eslint-disable-next-line no-undef
chrome.runtime.sendMessage("showPageAction");
}
AppOptions.set("defaultUrl", defaultUrl);
})();
}
function getViewerConfiguration() {
return {
appContainer: document.body,