From 394a716e2c1e07cbaa5c226113ae83bd901a7a58 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. --- 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 | 11 +++++++++++ 5 files changed, 73 insertions(+) diff --git a/extensions/chromium/options/migration.js b/extensions/chromium/options/migration.js index 0ecaf2d96e4e47..ca547850c42149 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 6a00062e123cbe..64d3f1a5a1ecc7 100644 --- a/extensions/chromium/options/options.html +++ b/extensions/chromium/options/options.html @@ -92,6 +92,19 @@ + +