Move the defaultUrl parameter from the appConfig and into AppOptions instead

The `appConfig` contains (mostly) references to various DOM elements, used when initializing the viewer components.
Hence `defaultUrl` seem like a slightly better fit for the new `AppOptions` abstraction, not to mention that it should thus be easier to set/modify it for custom deployments of the default viewer.
This commit is contained in:
Jonas Jenwald 2018-02-17 23:25:23 +01:00
parent 81c550903f
commit 57165afb08
3 changed files with 15 additions and 7 deletions

View File

@ -1568,12 +1568,12 @@ function webViewerInitialized() {
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {
let queryString = document.location.search.substring(1); let queryString = document.location.search.substring(1);
let params = parseQueryString(queryString); let params = parseQueryString(queryString);
file = 'file' in params ? params.file : appConfig.defaultUrl; file = 'file' in params ? params.file : AppOptions.get('defaultUrl');
validateFileURL(file); validateFileURL(file);
} else if (PDFJSDev.test('FIREFOX || MOZCENTRAL')) { } else if (PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
file = window.location.href.split('#')[0]; file = window.location.href.split('#')[0];
} else if (PDFJSDev.test('CHROME')) { } else if (PDFJSDev.test('CHROME')) {
file = appConfig.defaultUrl; file = AppOptions.get('defaultUrl');
} }
if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) {

View File

@ -27,6 +27,11 @@ const OptionKind = {
* compare with the format of `default_preferences.json`. * compare with the format of `default_preferences.json`.
*/ */
const defaultOptions = { const defaultOptions = {
defaultUrl: {
/** @type {string} */
value: 'compressed.tracemonkey-pldi-09.pdf',
kind: OptionKind.VIEWER,
},
defaultZoomValue: { defaultZoomValue: {
/** @type {string} */ /** @type {string} */
value: '', value: '',

View File

@ -16,18 +16,18 @@
'use strict'; 'use strict';
let DEFAULT_URL = 'compressed.tracemonkey-pldi-09.pdf';
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) { if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
var defaultUrl; // eslint-disable-line no-var
(function rewriteUrlClosure() { (function rewriteUrlClosure() {
// Run this code outside DOMContentLoaded to make sure that the URL // Run this code outside DOMContentLoaded to make sure that the URL
// is rewritten as soon as possible. // is rewritten as soon as possible.
let queryString = document.location.search.slice(1); let queryString = document.location.search.slice(1);
let m = /(^|&)file=([^&]*)/.exec(queryString); let m = /(^|&)file=([^&]*)/.exec(queryString);
DEFAULT_URL = m ? decodeURIComponent(m[2]) : ''; defaultUrl = m ? decodeURIComponent(m[2]) : '';
// Example: chrome-extension://.../http://example.com/file.pdf // Example: chrome-extension://.../http://example.com/file.pdf
let humanReadableUrl = '/' + DEFAULT_URL + location.hash; let humanReadableUrl = '/' + defaultUrl + location.hash;
history.replaceState(history.state, '', humanReadableUrl); history.replaceState(history.state, '', humanReadableUrl);
if (top === window) { if (top === window) {
chrome.runtime.sendMessage('showPageAction'); chrome.runtime.sendMessage('showPageAction');
@ -172,7 +172,6 @@ function getViewerConfiguration() {
printContainer: document.getElementById('printContainer'), printContainer: document.getElementById('printContainer'),
openFileInputName: 'fileInput', openFileInputName: 'fileInput',
debuggerScriptPath: './debugger.js', debuggerScriptPath: './debugger.js',
defaultUrl: DEFAULT_URL,
}; };
} }
@ -190,6 +189,10 @@ function webViewerLoad() {
app.PDFViewerApplication.run(config); app.PDFViewerApplication.run(config);
}); });
} else { } else {
if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME')) {
pdfjsWebAppOptions.AppOptions.set('defaultUrl', defaultUrl);
}
window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication; window.PDFViewerApplication = pdfjsWebApp.PDFViewerApplication;
window.PDFViewerApplicationOptions = pdfjsWebAppOptions.AppOptions; window.PDFViewerApplicationOptions = pdfjsWebAppOptions.AppOptions;
pdfjsWebApp.PDFViewerApplication.run(config); pdfjsWebApp.PDFViewerApplication.run(config);