diff --git a/extensions/chromium/options/migration.js b/extensions/chromium/options/migration.js index 0ecaf2d96..ca547850c 100644 --- a/extensions/chromium/options/migration.js +++ b/extensions/chromium/options/migration.js @@ -78,6 +78,9 @@ limitations under the License. storageSync.get([ 'enableHandToolOnLoad', 'cursorToolOnLoad', + 'disableTextLayer', + 'enhanceTextSelection', + 'textLayerMode', ], function(items) { // Migration code for https://github.com/mozilla/pdf.js/pull/7635. if (typeof items.enableHandToolOnLoad === 'boolean') { @@ -93,6 +96,23 @@ limitations under the License. storageSync.remove('enableHandToolOnLoad'); } } + // Migration code for https://github.com/mozilla/pdf.js/pull/9479. + if (typeof items.disableTextLayer === 'boolean') { + var textLayerMode = items.disableTextLayer ? 0 : + items.enhanceTextSelection ? 2 : 1; + if (textLayerMode !== 1) { + // Overwrite if computed textLayerMode is not the default value (1). + storageSync.set({ + textLayerMode: textLayerMode, + }, function() { + if (!chrome.runtime.lastError) { + storageSync.remove(['disableTextLayer', 'enhanceTextSelection']); + } + }); + } else { + storageSync.remove(['disableTextLayer', 'enhanceTextSelection']); + } + } }); } })(); diff --git a/extensions/chromium/options/options.html b/extensions/chromium/options/options.html index 6a00062e1..5b8569202 100644 --- a/extensions/chromium/options/options.html +++ b/extensions/chromium/options/options.html @@ -92,6 +92,19 @@ body { + + + + + + Disable text selection + Enable text selection + Enable enhanced mode (experimental) + + + + + diff --git a/extensions/chromium/options/options.js b/extensions/chromium/options/options.js index 87700db24..2b5d005f5 100644 --- a/extensions/chromium/options/options.js +++ b/extensions/chromium/options/options.js @@ -81,6 +81,8 @@ Promise.all([ renderPreference = renderSidebarViewOnLoad(prefSchema.title); } else if (prefName === 'cursorToolOnLoad') { renderPreference = renderCursorToolOnLoad(prefSchema.title); + } else if (prefName === 'textLayerMode') { + renderPreference = renderTextLayerMode(prefSchema.title); } else if (prefName === 'externalLinkTarget') { renderPreference = renderExternalLinkTarget(prefSchema.title); } else { @@ -217,6 +219,23 @@ function renderCursorToolOnLoad(shortDescription) { return renderPreference; } +function renderTextLayerMode(shortDescription) { + var wrapper = importTemplate('textLayerMode-template'); + var select = wrapper.querySelector('select'); + select.onchange = function() { + storageArea.set({ + textLayerMode: parseInt(this.value), + }); + }; + wrapper.querySelector('span').textContent = shortDescription; + document.getElementById('settings-boxes').appendChild(wrapper); + + function renderPreference(value) { + select.value = value; + } + return renderPreference; +} + function renderExternalLinkTarget(shortDescription) { var wrapper = importTemplate('externalLinkTarget-template'); var select = wrapper.querySelector('select'); diff --git a/extensions/chromium/preferences_schema.json b/extensions/chromium/preferences_schema.json index 6ab4be3e6..46d2d0c60 100644 --- a/extensions/chromium/preferences_schema.json +++ b/extensions/chromium/preferences_schema.json @@ -26,6 +26,11 @@ ], "default": 0 }, + "enableHandToolOnLoad": { + "description": "DEPRECATED. Set cursorToolOnLoad to 1 to enable the hand tool by default.", + "type": "boolean", + "default": false + }, "cursorToolOnLoad": { "title": "Cursor tool on load", "description": "The cursor tool that is enabled upon load.\n 0 = Text selection tool.\n 1 = Hand tool.", @@ -70,6 +75,16 @@ "type": "boolean", "default": false }, + "disableTextLayer": { + "description": "DEPRECATED. Set textLayerMode to 0 to disable the text selection layer by default.", + "type": "boolean", + "default": false + }, + "enhanceTextSelection": { + "description": "DEPRECATED. Set textLayerMode to 2 to use the enhanced text selection layer by default.", + "type": "boolean", + "default": false + }, "textLayerMode": { "title": "Text layer mode", "description": "Controls if the text layer is enabled, and the selection mode that is used.\n 0 = Disabled.\n 1 = Enabled.\n 2 = (Experimental) Enabled, with enhanced text selection.", diff --git a/gulpfile.js b/gulpfile.js index 4d2bdc808..3568da316 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -192,6 +192,13 @@ function getVersionJSON() { function checkChromePreferencesFile(chromePrefsPath, webPrefsPath) { var chromePrefs = JSON.parse(fs.readFileSync(chromePrefsPath).toString()); var chromePrefsKeys = Object.keys(chromePrefs.properties); + chromePrefsKeys = chromePrefsKeys.filter(function (key) { + var description = chromePrefs.properties[key].description; + // Deprecated keys are allowed in the managed preferences file. + // The code maintained is responsible for adding migration logic to + // extensions/chromium/options/migration.js and web/chromecom.js . + return !description || !description.startsWith('DEPRECATED.'); + }); chromePrefsKeys.sort(); var webPrefs = JSON.parse(fs.readFileSync(webPrefsPath).toString()); var webPrefsKeys = Object.keys(webPrefs); diff --git a/web/chromecom.js b/web/chromecom.js index 533361467..a4605b353 100644 --- a/web/chromecom.js +++ b/web/chromecom.js @@ -308,16 +308,43 @@ class ChromePreferences extends BasePreferences { // Get preferences as set by the system administrator. // See extensions/chromium/preferences_schema.json for more information. // These preferences can be overridden by the user. - chrome.storage.managed.get(this.defaults, function(items) { - // Migration code for https://github.com/mozilla/pdf.js/pull/7635. + + // Deprecated preferences are removed from web/default_preferences.json, + // but kept in extensions/chromium/preferences_schema.json for backwards + // compatibility with managed preferences. + let defaultManagedPrefs = Object.assign({ + enableHandToolOnLoad: false, + disableTextLayer: false, + enhanceTextSelection: false, + }, this.defaults); + + chrome.storage.managed.get(defaultManagedPrefs, function(items) { + items = items || defaultManagedPrefs; + // Migration logic for deprecated preferences: If the new preference + // is not defined by an administrator (i.e. the value is the same as + // the default value), and a deprecated preference is set with a + // non-default value, migrate the deprecated preference value to the + // new preference value. // Never remove this, because we have no means of modifying managed // preferences. - if (items && items.enableHandToolOnLoad && !items.cursorToolOnLoad) { - // if the old enableHandToolOnLoad has a non-default value, - // and cursorToolOnLoad has a default value, migrate. - items.enableHandToolOnLoad = false; + + // Migration code for https://github.com/mozilla/pdf.js/pull/7635. + if (items.enableHandToolOnLoad && !items.cursorToolOnLoad) { items.cursorToolOnLoad = 1; } + delete items.enableHandToolOnLoad; + + // Migration code for https://github.com/mozilla/pdf.js/pull/9479. + if (items.textLayerMode !== 1) { + if (items.disableTextLayer) { + items.textLayerMode = 0; + } else if (items.enhanceTextSelection) { + items.textLayerMode = 2; + } + } + delete items.disableTextLayer; + delete items.enhanceTextSelection; + getPreferences(items); }); } else {