From 94a49fa0483c928219a5669b1627ec2f1189021f Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Fri, 16 Feb 2018 18:02:05 +0100 Subject: [PATCH] [CRX] Make textLayerMode pref visible and add migration logic In a1cfa5f4d7c8fcf55e9f3b51a23885dca8782915, the textLayerMode preference was introduced, to replace the disableTextLayer and enhanceTextSelection preferences. As a result, the text selection preference was no longer visible in Chrome (because preferences are only rendered by default for boolean preferences, not for enumerations). This commit adds the necessary bits to extensions/chromium/options/options.{html,js} so that the textLayerMode preference can be changed again. Also, migration logic has been added to move over preferences from the old to the new names: - In web/chromecom.js, the logic is added to translate preferences that were set by an administrator (it is read-only, so this layer is unavoidable). - In extensions/chromium/options/migration.js, similar logic is added, except in this case the preference storage is writable, so this migration logic happens only once. The "enhanced text selection" mode is still experimental, so it has been marked as experimental to signal that there may be bugs. The list of tasks that block promotion to stable is at #7584. --- extensions/chromium/options/migration.js | 20 +++++++++++++++++ extensions/chromium/options/options.html | 13 +++++++++++ extensions/chromium/options/options.js | 19 ++++++++++++++++ extensions/chromium/preferences_schema.json | 10 +++++++++ web/chromecom.js | 24 ++++++++++++++++++--- 5 files changed, 83 insertions(+), 3 deletions(-) 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 { + +