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

Add a BasePreferences.getAll method and use it to fetch all Preferences at once in PDFViewerApplication._readPreferences; ensure that the externalLinkTarget option is correctly set when the viewer is embedded #9917

Merged
merged 3 commits into from
Jul 25, 2018
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
112 changes: 24 additions & 88 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ let PDFViewerApplication = {
}).then(() => {
return this._initializeL10n();
}).then(() => {
if (this.isViewerEmbedded &&
AppOptions.get('externalLinkTarget') === LinkTarget.NONE) {
// Prevent external links from "replacing" the viewer,
// when it's embedded in e.g. an <iframe> or an <object>.
AppOptions.set('externalLinkTarget', LinkTarget.TOP);
}
return this._initializeViewerComponents();
}).then(() => {
// Bind the various event handlers *after* the viewer has been
Expand All @@ -157,13 +163,6 @@ let PDFViewerApplication = {
this.eventBus.dispatch('localized');
});

if (this.isViewerEmbedded &&
AppOptions.get('externalLinkTarget') === LinkTarget.NONE) {
// Prevent external links from "replacing" the viewer,
// when it's embedded in e.g. an iframe or an object.
AppOptions.set('externalLinkTarget', LinkTarget.TOP);
}

this.initialized = true;
});
},
Expand All @@ -172,93 +171,30 @@ let PDFViewerApplication = {
* @private
*/
_readPreferences() {
let { preferences, } = this;

return Promise.all([
preferences.get('enableWebGL').then(function resolved(value) {
AppOptions.set('enableWebGL', value);
}),
preferences.get('sidebarViewOnLoad').then(function resolved(value) {
AppOptions.set('sidebarViewOnLoad', value);
}),
preferences.get('cursorToolOnLoad').then(function resolved(value) {
AppOptions.set('cursorToolOnLoad', value);
}),
preferences.get('pdfBugEnabled').then(function resolved(value) {
AppOptions.set('pdfBugEnabled', value);
}),
preferences.get('showPreviousViewOnLoad').then(function resolved(value) {
AppOptions.set('showPreviousViewOnLoad', value);
}),
preferences.get('defaultZoomValue').then(function resolved(value) {
AppOptions.set('defaultZoomValue', value);
}),
preferences.get('textLayerMode').then(function resolved(value) {
if (AppOptions.get('textLayerMode') === TextLayerMode.DISABLE) {
return;
}
AppOptions.set('textLayerMode', value);
}),
preferences.get('disableRange').then(function resolved(value) {
if (AppOptions.get('disableRange') === true) {
return;
}
AppOptions.set('disableRange', value);
}),
preferences.get('disableStream').then(function resolved(value) {
if (AppOptions.get('disableStream') === true) {
return;
}
AppOptions.set('disableStream', value);
}),
preferences.get('disableAutoFetch').then(function resolved(value) {
AppOptions.set('disableAutoFetch', value);
}),
preferences.get('disableFontFace').then(function resolved(value) {
if (AppOptions.get('disableFontFace') === true) {
return;
}
AppOptions.set('disableFontFace', value);
}),
preferences.get('useOnlyCssZoom').then(function resolved(value) {
AppOptions.set('useOnlyCssZoom', value);
}),
preferences.get('externalLinkTarget').then(function resolved(value) {
if (AppOptions.get('externalLinkTarget') !== LinkTarget.NONE) {
return;
// A subset of the Preferences that `AppOptions`, for compatibility reasons,
// is allowed to override if the `AppOptions` values matches the ones below.
const OVERRIDES = {
disableFontFace: true,
disableRange: true,
disableStream: true,
textLayerMode: TextLayerMode.DISABLE,
};

return this.preferences.getAll().then(function(prefs) {
for (let name in prefs) {
if ((name in OVERRIDES) && AppOptions.get(name) === OVERRIDES[name]) {
continue;
}
AppOptions.set('externalLinkTarget', value);
}),
preferences.get('renderer').then(function resolved(value) {
AppOptions.set('renderer', value);
}),
preferences.get('renderInteractiveForms').then(function resolved(value) {
AppOptions.set('renderInteractiveForms', value);
}),
preferences.get('disablePageMode').then(function resolved(value) {
AppOptions.set('disablePageMode', value);
}),
preferences.get('disablePageLabels').then(function resolved(value) {
AppOptions.set('disablePageLabels', value);
}),
preferences.get('enablePrintAutoRotate').then(function resolved(value) {
AppOptions.set('enablePrintAutoRotate', value);
}),
preferences.get('scrollModeOnLoad').then(function resolved(value) {
AppOptions.set('scrollModeOnLoad', value);
}),
preferences.get('spreadModeOnLoad').then(function resolved(value) {
AppOptions.set('spreadModeOnLoad', value);
}),
]).catch(function(reason) { });
AppOptions.set(name, prefs[name]);
}
}, function(reason) { });
},

/**
* @private
*/
_parseHashParameters() {
let { appConfig, } = this;
let waitOn = [];
const waitOn = [];

if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION') ||
AppOptions.get('pdfBugEnabled')) {
Expand Down Expand Up @@ -311,7 +247,7 @@ let PDFViewerApplication = {
case 'visible':
case 'shadow':
case 'hover':
let viewer = appConfig.viewerContainer;
let viewer = this.appConfig.viewerContainer;
viewer.classList.add('textLayer-' + hashParams['textlayer']);
break;
}
Expand Down
11 changes: 11 additions & 0 deletions web/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ class BasePreferences {
return defaultValue;
});
}

/**
* Get the values of all preferences.
* @return {Promise} A promise that is resolved with an {Object} containing
* the values of all preferences.
*/
getAll() {
return this._initializedPromise.then(() => {
return Object.assign(Object.create(null), this.defaults, this.prefs);
});
}
}

export {
Expand Down