[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
This commit is contained in:
parent
ca3c08f12b
commit
19549bb7d6
@ -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');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
@ -80,6 +80,18 @@ body {
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="cursorToolOnLoad-template">
|
||||
<div class="settings-row">
|
||||
<label>
|
||||
<span></span>
|
||||
<select>
|
||||
<option value="0">Text selection tool</option>
|
||||
<option value="1">Hand tool</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="externalLinkTarget-template">
|
||||
<div class="settings-row">
|
||||
<label>
|
||||
|
@ -79,6 +79,8 @@ Promise.all([
|
||||
renderPreference = renderDefaultZoomValue(prefSchema.title);
|
||||
} else if (prefName === 'sidebarViewOnLoad') {
|
||||
renderPreference = renderSidebarViewOnLoad(prefSchema.title);
|
||||
} else if (prefName === 'cursorToolOnLoad') {
|
||||
renderPreference = renderCursorToolOnLoad(prefSchema.title);
|
||||
} else if (prefName === 'externalLinkTarget') {
|
||||
renderPreference = renderExternalLinkTarget(prefSchema.title);
|
||||
} else {
|
||||
@ -198,6 +200,23 @@ function renderSidebarViewOnLoad(shortDescription) {
|
||||
return renderPreference;
|
||||
}
|
||||
|
||||
function renderCursorToolOnLoad(shortDescription) {
|
||||
var wrapper = importTemplate('cursorToolOnLoad-template');
|
||||
var select = wrapper.querySelector('select');
|
||||
select.onchange = function() {
|
||||
storageArea.set({
|
||||
cursorToolOnLoad: parseInt(this.value),
|
||||
});
|
||||
};
|
||||
wrapper.querySelector('span').textContent = shortDescription;
|
||||
document.getElementById('settings-boxes').appendChild(wrapper);
|
||||
|
||||
function renderPreference(value) {
|
||||
select.value = value;
|
||||
}
|
||||
return renderPreference;
|
||||
}
|
||||
|
||||
function renderExternalLinkTarget(shortDescription) {
|
||||
var wrapper = importTemplate('externalLinkTarget-template');
|
||||
var select = wrapper.querySelector('select');
|
||||
|
@ -27,6 +27,7 @@
|
||||
"default": 0
|
||||
},
|
||||
"enableHandToolOnLoad": {
|
||||
"description": "Deprecated. Set cursorToolOnLoad to 1 to enable the hand tool by default.",
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
|
@ -328,7 +328,18 @@ 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, getPreferences);
|
||||
chrome.storage.managed.get(this.defaults, function(items) {
|
||||
// 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 the old enableHandToolOnLoad has a non-default value,
|
||||
// and cursorToolOnLoad has a default value, migrate.
|
||||
items.enableHandToolOnLoad = false;
|
||||
items.cursorToolOnLoad = 1;
|
||||
}
|
||||
getPreferences(items);
|
||||
});
|
||||
} else {
|
||||
// Managed storage not supported, e.g. in old Chromium versions.
|
||||
getPreferences(this.defaults);
|
||||
|
Loading…
x
Reference in New Issue
Block a user