From fc83ce1aae895d7f23356f761fce031f9810839c Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Fri, 16 Feb 2018 17:34:34 +0100 Subject: [PATCH 1/3] [CRX] Restore migration logic for managed enableHandToolOnLoad pref This partially reverts df0836b9b8bdfe7c8924a7409455abf7ba54b647. The entry in preferences_schema.json is restored because that is required to make managed preferences visible to the extension code. The default key is still removed from default_preferences.json, because this change only concerns the Chrome extension, not the other parts of PDF.js. To account for the missing key, the deprecated key was added back in chromecom.js The key needs to be restored in preferences_schema.json too, because that's the only way to make managed preferences visible. I'm using `Object.assign`, which was introduced in Chrome 45, so the preference module will break in Chrome 45 and earlier. This is fine, because we do not support Chrome before 49. --- extensions/chromium/preferences_schema.json | 5 +++++ web/chromecom.js | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/extensions/chromium/preferences_schema.json b/extensions/chromium/preferences_schema.json index 6ab4be3e6961a..5f365e6610d21 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.", diff --git a/web/chromecom.js b/web/chromecom.js index 53336146787cf..43419db8e6f0f 100644 --- a/web/chromecom.js +++ b/web/chromecom.js @@ -308,16 +308,25 @@ 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) { + + // 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, + }, this.defaults); + + chrome.storage.managed.get(defaultManagedPrefs, function(items) { + items = items || defaultManagedPrefs; // Migration code for https://github.com/mozilla/pdf.js/pull/7635. // Never remove this, because we have no means of modifying managed // preferences. - if (items && items.enableHandToolOnLoad && !items.cursorToolOnLoad) { + if (items.enableHandToolOnLoad && !items.cursorToolOnLoad) { // if the old enableHandToolOnLoad has a non-default value, // and cursorToolOnLoad has a default value, migrate. - items.enableHandToolOnLoad = false; items.cursorToolOnLoad = 1; } + delete items.enableHandToolOnLoad; getPreferences(items); }); } else { From 94a49fa0483c928219a5669b1627ec2f1189021f Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Fri, 16 Feb 2018 18:02:05 +0100 Subject: [PATCH 2/3] [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 0ecaf2d96e4e4..ca547850c4214 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 6a00062e123cb..5b856920295d2 100644 --- a/extensions/chromium/options/options.html +++ b/extensions/chromium/options/options.html @@ -92,6 +92,19 @@ + +