[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.
This commit is contained in:
Rob Wu 2018-02-16 17:34:34 +01:00
parent a89071bdef
commit fc83ce1aae
2 changed files with 17 additions and 3 deletions

View File

@ -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.",

View File

@ -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 {