From 19549bb7d6191cc6e79cc806b0fbf9c0598db192 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Sat, 15 Jul 2017 01:50:15 +0200 Subject: [PATCH] [CRX] Integrate cursorToolOnLoad pref + migration logic Add UI for the cursorToolOnLoad pref in the UI of the Chrome extension. Add logic to migrate the enableHandToolOnLoad pref to cursorToolOnLoad. For past values in the mutable extension storage area: 1. If enableHandToolOnLoad=true, save cursorToolOnLoad=1. 2. Remove enableHandToolOnLoad. For the managed extension storage, which is immutable since it is based on administrative policies, use the following logic: 1. If enableHandToolOnLoad=true and cursorToolOnLoad=0 (default). set cursorToolOnLoad=0 and assume enableHandToolOnLoad=false. 2. As usual, managed preferences can (and will) be overridden by the user. The first migration logic is in extensions/chromium/options/migration.js and can be removed after a few months / less than many years. The second migration logic is in web/chromecom.js, and should be kept around for a long while (many years). The need for this migration logic arises from the change by: https://github.com/mozilla/pdf.js/pull/7635 --- extensions/chromium/options/migration.js | 29 +++++++++++++++++++++ extensions/chromium/options/options.html | 12 +++++++++ extensions/chromium/options/options.js | 19 ++++++++++++++ extensions/chromium/preferences_schema.json | 1 + web/chromecom.js | 13 ++++++++- 5 files changed, 73 insertions(+), 1 deletion(-) diff --git a/extensions/chromium/options/migration.js b/extensions/chromium/options/migration.js index 7073fc5bc7e80..0ecaf2d96e4e4 100644 --- a/extensions/chromium/options/migration.js +++ b/extensions/chromium/options/migration.js @@ -29,6 +29,8 @@ limitations under the License. storageLocal.get(storageKeys, function(values) { if (!values || !Object.keys(values).length) { // No local storage - nothing to migrate. + // ... except possibly for a renamed preference name. + migrateRenamedStorage(); return; } migrateToSyncStorage(values); @@ -63,7 +65,34 @@ limitations under the License. // the migration successful. console.log( 'Successfully migrated preferences from local to sync storage.'); + migrateRenamedStorage(); }); }); } + + // TODO: Remove this migration code somewhere in the future, when most users + // have had their chance of migrating to the new preference format. + // Note: We cannot modify managed preferences, so the migration logic is + // duplicated in web/chromecom.js too. + function migrateRenamedStorage() { + storageSync.get([ + 'enableHandToolOnLoad', + 'cursorToolOnLoad', + ], function(items) { + // Migration code for https://github.com/mozilla/pdf.js/pull/7635. + if (typeof items.enableHandToolOnLoad === 'boolean') { + if (items.enableHandToolOnLoad) { + storageSync.set({ + cursorToolOnLoad: 1, + }, function() { + if (!chrome.runtime.lastError) { + storageSync.remove('enableHandToolOnLoad'); + } + }); + } else { + storageSync.remove('enableHandToolOnLoad'); + } + } + }); + } })(); diff --git a/extensions/chromium/options/options.html b/extensions/chromium/options/options.html index 901cd95e2cf42..6a00062e123cb 100644 --- a/extensions/chromium/options/options.html +++ b/extensions/chromium/options/options.html @@ -80,6 +80,18 @@ + +