diff --git a/web/app.js b/web/app.js index 9d3ad5538..b02cf0c3a 100644 --- a/web/app.js +++ b/web/app.js @@ -1568,12 +1568,12 @@ function webViewerInitialized() { if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { let queryString = document.location.search.substring(1); let params = parseQueryString(queryString); - file = 'file' in params ? params.file : appConfig.defaultUrl; + file = 'file' in params ? params.file : AppOptions.get('defaultUrl'); validateFileURL(file); } else if (PDFJSDev.test('FIREFOX || MOZCENTRAL')) { file = window.location.href.split('#')[0]; } else if (PDFJSDev.test('CHROME')) { - file = appConfig.defaultUrl; + file = AppOptions.get('defaultUrl'); } if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { diff --git a/web/app_options.js b/web/app_options.js index 27f80d93c..49a214850 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -27,6 +27,11 @@ const OptionKind = { * compare with the format of `default_preferences.json`. */ const defaultOptions = { + defaultUrl: { + /** @type {string} */ + value: 'compressed.tracemonkey-pldi-09.pdf', + kind: OptionKind.VIEWER, + }, defaultZoomValue: { /** @type {string} */ value: '', diff --git a/web/viewer.js b/web/viewer.js index ecd7bc6cf..1c3fbb240 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -16,18 +16,18 @@ 'use strict'; -let DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf'; - 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. let queryString = document.location.search.slice(1); let m = /(^|&)file=([^&]*)/.exec(queryString); - DEFAULT_URL = m ? decodeURIComponent(m[2]) : ''; + defaultUrl = m ? decodeURIComponent(m[2]) : ''; // Example: chrome-extension://.../http://example.com/file.pdf - let humanReadableUrl = '/' + DEFAULT_URL + location.hash; + let humanReadableUrl = '/' + defaultUrl + location.hash; history.replaceState(history.state, '', humanReadableUrl); if (top === window) { chrome.runtime.sendMessage('showPageAction'); @@ -172,7 +172,6 @@ function getViewerConfiguration() { printContainer: document.getElementById('printContainer'), openFileInputName: 'fileInput', debuggerScriptPath: './debugger.js', - defaultUrl: DEFAULT_URL, }; } @@ -190,6 +189,10 @@ function webViewerLoad() { app.PDFViewerApplication.run(config); }); } else { + if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) { + pdfjsWebAppOptions.AppOptions.set('defaultUrl', defaultUrl); + } + window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication; window.PDFViewerApplicationOptions = pdfjsWebAppOptions.AppOptions; pdfjsWebApp.PDFViewerApplication.run(config);