Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify setting the defaultUrl-option in the CHROME viewer (PR 12470 follow-up) #15052

Merged
merged 2 commits into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions web/app_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ const defaultOptions = {
value: 0,
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
},
defaultUrl: {
/** @type {string} */
value: "compressed.tracemonkey-pldi-09.pdf",
kind: OptionKind.VIEWER,
},
defaultZoomValue: {
/** @type {string} */
value: "",
Expand Down Expand Up @@ -296,6 +291,11 @@ if (
typeof PDFJSDev === "undefined" ||
PDFJSDev.test("!PRODUCTION || GENERIC")
) {
defaultOptions.defaultUrl = {
/** @type {string} */
value: "compressed.tracemonkey-pldi-09.pdf",
kind: OptionKind.VIEWER,
};
defaultOptions.disablePreferences = {
/** @type {boolean} */
value: typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING"),
Expand All @@ -320,6 +320,11 @@ if (

defaultOptions.renderer.kind += OptionKind.PREFERENCE;
} else if (PDFJSDev.test("CHROME")) {
defaultOptions.defaultUrl = {
/** @type {string} */
value: "",
kind: OptionKind.VIEWER,
};
defaultOptions.disableTelemetry = {
/** @type {boolean} */
value: false,
Expand Down
10 changes: 3 additions & 7 deletions web/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ window.PDFViewerApplication = PDFViewerApplication;
window.PDFViewerApplicationOptions = AppOptions;

if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) {
var defaultUrl; // eslint-disable-line no-var

(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);
defaultUrl = m ? decodeURIComponent(m[2]) : "";
const defaultUrl = m ? decodeURIComponent(m[2]) : "";

// Example: chrome-extension://.../http://example.com/file.pdf
const humanReadableUrl = "/" + defaultUrl + location.hash;
Expand All @@ -43,6 +41,8 @@ if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) {
// eslint-disable-next-line no-undef
chrome.runtime.sendMessage("showPageAction");
}

AppOptions.set("defaultUrl", defaultUrl);
})();
}

Expand Down Expand Up @@ -222,10 +222,6 @@ function webViewerLoad() {
PDFViewerApplication.run(config);
});
} else {
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("CHROME")) {
AppOptions.set("defaultUrl", defaultUrl);
}

if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("GENERIC")) {
// Give custom implementations of the default viewer a simpler way to
// set various `AppOptions`, by dispatching an event once all viewer
Expand Down