2015-01-07 02:22:35 +09:00
|
|
|
/*
|
|
|
|
Copyright 2015 Mozilla Foundation
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
2016-05-23 22:50:07 +09:00
|
|
|
var storageAreaName = chrome.storage.sync ? 'sync' : 'local';
|
|
|
|
var storageArea = chrome.storage[storageAreaName];
|
2015-01-07 02:22:35 +09:00
|
|
|
|
|
|
|
Promise.all([
|
|
|
|
new Promise(function getManagedPrefs(resolve) {
|
2016-05-23 22:50:07 +09:00
|
|
|
if (!chrome.storage.managed) {
|
|
|
|
resolve({});
|
|
|
|
return;
|
|
|
|
}
|
2015-01-07 02:22:35 +09:00
|
|
|
// Get preferences as set by the system administrator.
|
|
|
|
chrome.storage.managed.get(null, function(prefs) {
|
|
|
|
// Managed storage may be disabled, e.g. in Opera.
|
|
|
|
resolve(prefs || {});
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
new Promise(function getUserPrefs(resolve) {
|
2016-05-23 22:50:07 +09:00
|
|
|
storageArea.get(null, function(prefs) {
|
2015-01-07 02:22:35 +09:00
|
|
|
resolve(prefs || {});
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
new Promise(function getStorageSchema(resolve) {
|
|
|
|
// Get the storage schema - a dictionary of preferences.
|
|
|
|
var x = new XMLHttpRequest();
|
|
|
|
var schema_location = chrome.runtime.getManifest().storage.managed_schema;
|
|
|
|
x.open('get', chrome.runtime.getURL(schema_location));
|
|
|
|
x.onload = function() {
|
|
|
|
resolve(x.response.properties);
|
|
|
|
};
|
|
|
|
x.responseType = 'json';
|
|
|
|
x.send();
|
|
|
|
})
|
|
|
|
]).then(function(values) {
|
|
|
|
var managedPrefs = values[0];
|
|
|
|
var userPrefs = values[1];
|
|
|
|
var schema = values[2];
|
|
|
|
function getPrefValue(prefName) {
|
|
|
|
if (prefName in userPrefs) {
|
|
|
|
return userPrefs[prefName];
|
|
|
|
} else if (prefName in managedPrefs) {
|
|
|
|
return managedPrefs[prefName];
|
|
|
|
}
|
|
|
|
return schema[prefName].default;
|
|
|
|
}
|
|
|
|
var prefNames = Object.keys(schema);
|
|
|
|
var renderPreferenceFunctions = {};
|
|
|
|
// Render options
|
|
|
|
prefNames.forEach(function(prefName) {
|
|
|
|
var prefSchema = schema[prefName];
|
|
|
|
if (!prefSchema.title) {
|
|
|
|
// Don't show preferences if the title is missing.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A DOM element with a method renderPreference.
|
|
|
|
var renderPreference;
|
|
|
|
if (prefSchema.type === 'boolean') {
|
|
|
|
// Most prefs are booleans, render them in a generic way.
|
|
|
|
renderPreference = renderBooleanPref(prefSchema.title,
|
|
|
|
prefSchema.description,
|
|
|
|
prefName);
|
|
|
|
} else if (prefName === 'defaultZoomValue') {
|
|
|
|
renderPreference = renderDefaultZoomValue(prefSchema.title);
|
|
|
|
} else if (prefName === 'sidebarViewOnLoad') {
|
|
|
|
renderPreference = renderSidebarViewOnLoad(prefSchema.title);
|
2017-07-15 08:50:15 +09:00
|
|
|
} else if (prefName === 'cursorToolOnLoad') {
|
|
|
|
renderPreference = renderCursorToolOnLoad(prefSchema.title);
|
[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.
2018-02-17 02:02:05 +09:00
|
|
|
} else if (prefName === 'textLayerMode') {
|
|
|
|
renderPreference = renderTextLayerMode(prefSchema.title);
|
2016-05-25 07:32:32 +09:00
|
|
|
} else if (prefName === 'externalLinkTarget') {
|
|
|
|
renderPreference = renderExternalLinkTarget(prefSchema.title);
|
2015-01-07 02:22:35 +09:00
|
|
|
} else {
|
|
|
|
// Should NEVER be reached. Only happens if a new type of preference is
|
|
|
|
// added to the storage manifest.
|
|
|
|
console.error('Don\'t know how to handle ' + prefName + '!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
renderPreference(getPrefValue(prefName));
|
|
|
|
renderPreferenceFunctions[prefName] = renderPreference;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Names of preferences that are displayed in the UI.
|
|
|
|
var renderedPrefNames = Object.keys(renderPreferenceFunctions);
|
|
|
|
|
|
|
|
// Reset button to restore default settings.
|
|
|
|
document.getElementById('reset-button').onclick = function() {
|
|
|
|
userPrefs = {};
|
2016-05-23 22:50:07 +09:00
|
|
|
storageArea.remove(prefNames, function() {
|
2015-01-07 02:22:35 +09:00
|
|
|
renderedPrefNames.forEach(function(prefName) {
|
|
|
|
renderPreferenceFunctions[prefName](getPrefValue(prefName));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Automatically update the UI when the preferences were changed elsewhere.
|
|
|
|
chrome.storage.onChanged.addListener(function(changes, areaName) {
|
2016-05-23 22:50:07 +09:00
|
|
|
var prefs = areaName === storageAreaName ? userPrefs :
|
2015-01-07 02:22:35 +09:00
|
|
|
areaName === 'managed' ? managedPrefs : null;
|
|
|
|
if (prefs) {
|
|
|
|
renderedPrefNames.forEach(function(prefName) {
|
|
|
|
var prefChanges = changes[prefName];
|
|
|
|
if (prefChanges) {
|
|
|
|
if ('newValue' in prefChanges) {
|
|
|
|
userPrefs[prefName] = prefChanges.newValue;
|
|
|
|
} else {
|
|
|
|
// Otherwise the pref was deleted
|
|
|
|
delete userPrefs[prefName];
|
|
|
|
}
|
|
|
|
renderPreferenceFunctions[prefName](getPrefValue(prefName));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}).then(null, console.error.bind(console));
|
|
|
|
|
|
|
|
function importTemplate(id) {
|
|
|
|
return document.importNode(document.getElementById(id).content, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helpers to create UI elements that display the preference, and return a
|
|
|
|
// function which updates the UI with the preference.
|
|
|
|
|
|
|
|
function renderBooleanPref(shortDescription, description, prefName) {
|
|
|
|
var wrapper = importTemplate('checkbox-template');
|
|
|
|
wrapper.title = description;
|
|
|
|
|
|
|
|
var checkbox = wrapper.querySelector('input[type="checkbox"]');
|
|
|
|
checkbox.onchange = function() {
|
|
|
|
var pref = {};
|
|
|
|
pref[prefName] = this.checked;
|
2016-05-23 22:50:07 +09:00
|
|
|
storageArea.set(pref);
|
2015-01-07 02:22:35 +09:00
|
|
|
};
|
|
|
|
wrapper.querySelector('span').textContent = shortDescription;
|
|
|
|
document.getElementById('settings-boxes').appendChild(wrapper);
|
|
|
|
|
|
|
|
function renderPreference(value) {
|
|
|
|
checkbox.checked = value;
|
|
|
|
}
|
|
|
|
return renderPreference;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderDefaultZoomValue(shortDescription) {
|
|
|
|
var wrapper = importTemplate('defaultZoomValue-template');
|
|
|
|
var select = wrapper.querySelector('select');
|
|
|
|
select.onchange = function() {
|
2016-05-23 22:50:07 +09:00
|
|
|
storageArea.set({
|
Fix inconsistent spacing and trailing commas in objects in `extensions/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in one big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/extensions/firefox/content/PdfStreamConverter.jsm b/extensions/firefox/content/PdfStreamConverter.jsm
index ea91a71a..0d59dad1 100644
--- a/extensions/firefox/content/PdfStreamConverter.jsm
+++ b/extensions/firefox/content/PdfStreamConverter.jsm
@@ -773,7 +773,8 @@ class RequestListener {
response = function sendResponse(aResponse) {
try {
var listener = doc.createEvent("CustomEvent");
- let detail = Cu.cloneInto({ response: aResponse, }, doc.defaultView);
+ let detail = Cu.cloneInto({ response: aResponse, },
+ doc.defaultView);
listener.initCustomEvent("pdf.js.response", true, false, detail);
return message.dispatchEvent(listener);
} catch (e) {
```
2017-06-01 20:22:23 +09:00
|
|
|
defaultZoomValue: this.value,
|
2015-01-07 02:22:35 +09:00
|
|
|
});
|
|
|
|
};
|
|
|
|
wrapper.querySelector('span').textContent = shortDescription;
|
|
|
|
document.getElementById('settings-boxes').appendChild(wrapper);
|
|
|
|
|
|
|
|
function renderPreference(value) {
|
|
|
|
value = value || 'auto';
|
|
|
|
select.value = value;
|
|
|
|
var customOption = select.querySelector('option.custom-zoom');
|
|
|
|
if (select.selectedIndex === -1 && value) {
|
|
|
|
// Custom zoom percentage, e.g. set via managed preferences.
|
|
|
|
// [zoom] or [zoom],[left],[top]
|
|
|
|
customOption.text = value.indexOf(',') > 0 ? value : value + '%';
|
|
|
|
customOption.value = value;
|
|
|
|
customOption.hidden = false;
|
|
|
|
customOption.selected = true;
|
|
|
|
} else {
|
|
|
|
customOption.hidden = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return renderPreference;
|
|
|
|
}
|
|
|
|
|
|
|
|
function renderSidebarViewOnLoad(shortDescription) {
|
|
|
|
var wrapper = importTemplate('sidebarViewOnLoad-template');
|
|
|
|
var select = wrapper.querySelector('select');
|
|
|
|
select.onchange = function() {
|
2016-05-23 22:50:07 +09:00
|
|
|
storageArea.set({
|
Fix inconsistent spacing and trailing commas in objects in `extensions/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in one big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/extensions/firefox/content/PdfStreamConverter.jsm b/extensions/firefox/content/PdfStreamConverter.jsm
index ea91a71a..0d59dad1 100644
--- a/extensions/firefox/content/PdfStreamConverter.jsm
+++ b/extensions/firefox/content/PdfStreamConverter.jsm
@@ -773,7 +773,8 @@ class RequestListener {
response = function sendResponse(aResponse) {
try {
var listener = doc.createEvent("CustomEvent");
- let detail = Cu.cloneInto({ response: aResponse, }, doc.defaultView);
+ let detail = Cu.cloneInto({ response: aResponse, },
+ doc.defaultView);
listener.initCustomEvent("pdf.js.response", true, false, detail);
return message.dispatchEvent(listener);
} catch (e) {
```
2017-06-01 20:22:23 +09:00
|
|
|
sidebarViewOnLoad: parseInt(this.value),
|
2015-01-07 02:22:35 +09:00
|
|
|
});
|
|
|
|
};
|
|
|
|
wrapper.querySelector('span').textContent = shortDescription;
|
|
|
|
document.getElementById('settings-boxes').appendChild(wrapper);
|
|
|
|
|
|
|
|
function renderPreference(value) {
|
|
|
|
select.value = value;
|
|
|
|
}
|
|
|
|
return renderPreference;
|
|
|
|
}
|
2016-05-25 07:32:32 +09:00
|
|
|
|
2017-07-15 08:50:15 +09:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
[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.
2018-02-17 02:02:05 +09:00
|
|
|
function renderTextLayerMode(shortDescription) {
|
|
|
|
var wrapper = importTemplate('textLayerMode-template');
|
|
|
|
var select = wrapper.querySelector('select');
|
|
|
|
select.onchange = function() {
|
|
|
|
storageArea.set({
|
|
|
|
textLayerMode: parseInt(this.value),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
wrapper.querySelector('span').textContent = shortDescription;
|
|
|
|
document.getElementById('settings-boxes').appendChild(wrapper);
|
|
|
|
|
|
|
|
function renderPreference(value) {
|
|
|
|
select.value = value;
|
|
|
|
}
|
|
|
|
return renderPreference;
|
|
|
|
}
|
|
|
|
|
2016-05-25 07:32:32 +09:00
|
|
|
function renderExternalLinkTarget(shortDescription) {
|
|
|
|
var wrapper = importTemplate('externalLinkTarget-template');
|
|
|
|
var select = wrapper.querySelector('select');
|
|
|
|
select.onchange = function() {
|
2016-05-23 22:50:07 +09:00
|
|
|
storageArea.set({
|
Fix inconsistent spacing and trailing commas in objects in `extensions/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in one big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/extensions/firefox/content/PdfStreamConverter.jsm b/extensions/firefox/content/PdfStreamConverter.jsm
index ea91a71a..0d59dad1 100644
--- a/extensions/firefox/content/PdfStreamConverter.jsm
+++ b/extensions/firefox/content/PdfStreamConverter.jsm
@@ -773,7 +773,8 @@ class RequestListener {
response = function sendResponse(aResponse) {
try {
var listener = doc.createEvent("CustomEvent");
- let detail = Cu.cloneInto({ response: aResponse, }, doc.defaultView);
+ let detail = Cu.cloneInto({ response: aResponse, },
+ doc.defaultView);
listener.initCustomEvent("pdf.js.response", true, false, detail);
return message.dispatchEvent(listener);
} catch (e) {
```
2017-06-01 20:22:23 +09:00
|
|
|
externalLinkTarget: parseInt(this.value),
|
2016-05-25 07:32:32 +09:00
|
|
|
});
|
|
|
|
};
|
|
|
|
wrapper.querySelector('span').textContent = shortDescription;
|
|
|
|
document.getElementById('settings-boxes').appendChild(wrapper);
|
|
|
|
|
|
|
|
function renderPreference(value) {
|
|
|
|
select.value = value;
|
|
|
|
}
|
|
|
|
return renderPreference;
|
|
|
|
}
|