зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset cf30ec111af9 (bug 1410412) for failing bc at browser_ext_chrome_settings_overrides_home.js on a CLOSED TREE
This commit is contained in:
Родитель
ce368a3740
Коммит
e911160415
|
@ -225,17 +225,17 @@ this.urlbar = class extends ExtensionAPI {
|
||||||
},
|
},
|
||||||
}).api(),
|
}).api(),
|
||||||
|
|
||||||
openViewOnFocus: getSettingsAPI({
|
openViewOnFocus: getSettingsAPI(
|
||||||
context,
|
context.extension.id,
|
||||||
name: "openViewOnFocus",
|
"openViewOnFocus",
|
||||||
callback: () => UrlbarPrefs.get("openViewOnFocus"),
|
() => UrlbarPrefs.get("openViewOnFocus")
|
||||||
}),
|
),
|
||||||
|
|
||||||
engagementTelemetry: getSettingsAPI({
|
engagementTelemetry: getSettingsAPI(
|
||||||
context,
|
context.extension.id,
|
||||||
name: "engagementTelemetry",
|
"engagementTelemetry",
|
||||||
callback: () => UrlbarPrefs.get("eventTelemetry.enabled"),
|
() => UrlbarPrefs.get("eventTelemetry.enabled")
|
||||||
}),
|
),
|
||||||
|
|
||||||
contextualTip: {
|
contextualTip: {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
|
|
||||||
var EXPORTED_SYMBOLS = ["ExtensionPreferencesManager"];
|
var EXPORTED_SYMBOLS = ["ExtensionPreferencesManager"];
|
||||||
|
|
||||||
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
||||||
|
|
||||||
const { Management } = ChromeUtils.import(
|
const { Management } = ChromeUtils.import(
|
||||||
"resource://gre/modules/Extension.jsm",
|
"resource://gre/modules/Extension.jsm",
|
||||||
null
|
null
|
||||||
|
@ -43,17 +41,6 @@ ChromeUtils.defineModuleGetter(
|
||||||
"Preferences",
|
"Preferences",
|
||||||
"resource://gre/modules/Preferences.jsm"
|
"resource://gre/modules/Preferences.jsm"
|
||||||
);
|
);
|
||||||
ChromeUtils.defineModuleGetter(
|
|
||||||
this,
|
|
||||||
"ExtensionCommon",
|
|
||||||
"resource://gre/modules/ExtensionCommon.jsm"
|
|
||||||
);
|
|
||||||
|
|
||||||
const { ExtensionUtils } = ChromeUtils.import(
|
|
||||||
"resource://gre/modules/ExtensionUtils.jsm"
|
|
||||||
);
|
|
||||||
|
|
||||||
const { ExtensionError } = ExtensionUtils;
|
|
||||||
|
|
||||||
XPCOMUtils.defineLazyGetter(this, "defaultPreferences", function() {
|
XPCOMUtils.defineLazyGetter(this, "defaultPreferences", function() {
|
||||||
return new Preferences({ defaultBranch: true });
|
return new Preferences({ defaultBranch: true });
|
||||||
|
@ -65,12 +52,12 @@ Management.on("uninstall", (type, { id }) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Management.on("disable", (type, id) => {
|
Management.on("disable", (type, id) => {
|
||||||
ExtensionPreferencesManager.disableAll(id);
|
this.ExtensionPreferencesManager.disableAll(id);
|
||||||
});
|
});
|
||||||
|
|
||||||
Management.on("startup", async (type, extension) => {
|
Management.on("startup", async (type, extension) => {
|
||||||
if (extension.startupReason == "ADDON_ENABLE") {
|
if (extension.startupReason == "ADDON_ENABLE") {
|
||||||
ExtensionPreferencesManager.enableAll(extension.id);
|
this.ExtensionPreferencesManager.enableAll(extension.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/* eslint-enable mozilla/balanced-listeners */
|
/* eslint-enable mozilla/balanced-listeners */
|
||||||
|
@ -128,8 +115,6 @@ function settingsUpdate(initialValue) {
|
||||||
/**
|
/**
|
||||||
* Loops through a set of prefs, either setting or resetting them.
|
* Loops through a set of prefs, either setting or resetting them.
|
||||||
*
|
*
|
||||||
* @param {string} name
|
|
||||||
* The api name of the setting.
|
|
||||||
* @param {Object} setting
|
* @param {Object} setting
|
||||||
* An object that represents a setting, which will have a setCallback
|
* An object that represents a setting, which will have a setCallback
|
||||||
* property. If a onPrefsChanged function is provided it will be called
|
* property. If a onPrefsChanged function is provided it will be called
|
||||||
|
@ -138,7 +123,7 @@ function settingsUpdate(initialValue) {
|
||||||
* An object that represents an item handed back from the setting store
|
* An object that represents an item handed back from the setting store
|
||||||
* from which the new pref values can be calculated.
|
* from which the new pref values can be calculated.
|
||||||
*/
|
*/
|
||||||
function setPrefs(name, setting, item) {
|
function setPrefs(setting, item) {
|
||||||
let prefs = item.initialValue || setting.setCallback(item.value);
|
let prefs = item.initialValue || setting.setCallback(item.value);
|
||||||
let changed = false;
|
let changed = false;
|
||||||
for (let pref of setting.prefNames) {
|
for (let pref of setting.prefNames) {
|
||||||
|
@ -155,7 +140,6 @@ function setPrefs(name, setting, item) {
|
||||||
if (changed && typeof setting.onPrefsChanged == "function") {
|
if (changed && typeof setting.onPrefsChanged == "function") {
|
||||||
setting.onPrefsChanged(item);
|
setting.onPrefsChanged(item);
|
||||||
}
|
}
|
||||||
Management.emit(`extension-setting-changed:${name}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -197,7 +181,7 @@ async function processSetting(id, name, action) {
|
||||||
) {
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
setPrefs(name, setting, item);
|
setPrefs(setting, item);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -259,7 +243,7 @@ this.ExtensionPreferencesManager = {
|
||||||
settingsUpdate.bind(setting)
|
settingsUpdate.bind(setting)
|
||||||
);
|
);
|
||||||
if (item) {
|
if (item) {
|
||||||
setPrefs(name, setting, item);
|
setPrefs(setting, item);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -415,18 +399,18 @@ this.ExtensionPreferencesManager = {
|
||||||
/**
|
/**
|
||||||
* Returns an API object with get/set/clear used for a setting.
|
* Returns an API object with get/set/clear used for a setting.
|
||||||
*
|
*
|
||||||
* @param {string|object} extensionId or params object
|
* @param {string} extensionId
|
||||||
* @param {string} name
|
* @param {string} name
|
||||||
* The unique id of the setting.
|
* The unique id of the setting.
|
||||||
* @param {Function} callback
|
* @param {Function} callback
|
||||||
* The function that retreives the current setting from prefs.
|
* The function that retreives the current setting from prefs.
|
||||||
* @param {string} storeType
|
* @param {string} storeType
|
||||||
* The name of the store in ExtensionSettingsStore.
|
* The name of the store in ExtensionSettingsStore.
|
||||||
* Defaults to STORE_TYPE.
|
* Defaults to STORE_TYPE.
|
||||||
* @param {boolean} readOnly
|
* @param {boolean} readOnly
|
||||||
* @param {Function} validate
|
* @param {Function} validate
|
||||||
* Utility function for any specific validation, such as checking
|
* Utility function for any specific validation, such as checking
|
||||||
* for supported platform. Function should throw an error if necessary.
|
* for supported platform. Function should throw an error if necessary.
|
||||||
*
|
*
|
||||||
* @returns {object} API object with get/set/clear methods
|
* @returns {object} API object with get/set/clear methods
|
||||||
*/
|
*/
|
||||||
|
@ -438,70 +422,7 @@ this.ExtensionPreferencesManager = {
|
||||||
readOnly = false,
|
readOnly = false,
|
||||||
validate = () => {}
|
validate = () => {}
|
||||||
) {
|
) {
|
||||||
if (arguments.length > 1) {
|
return {
|
||||||
Services.console.logStringMessage(
|
|
||||||
`ExtensionPreferencesManager.getSettingsAPI for ${name} should be updated to use a single paramater object.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return ExtensionPreferencesManager._getSettingsAPI(
|
|
||||||
arguments.length === 1
|
|
||||||
? extensionId
|
|
||||||
: {
|
|
||||||
extensionId,
|
|
||||||
name,
|
|
||||||
callback,
|
|
||||||
storeType,
|
|
||||||
readOnly,
|
|
||||||
validate,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an API object with get/set/clear used for a setting.
|
|
||||||
*
|
|
||||||
* @param {object} params The params object contains the following:
|
|
||||||
* {BaseContext} context
|
|
||||||
* {string} extensionId, optional to support old API
|
|
||||||
* {string} name
|
|
||||||
* The unique id of the setting.
|
|
||||||
* {Function} callback
|
|
||||||
* The function that retreives the current setting from prefs.
|
|
||||||
* {string} storeType
|
|
||||||
* The name of the store in ExtensionSettingsStore.
|
|
||||||
* Defaults to STORE_TYPE.
|
|
||||||
* {boolean} readOnly
|
|
||||||
* {Function} validate
|
|
||||||
* Utility function for any specific validation, such as checking
|
|
||||||
* for supported platform. Function should throw an error if necessary.
|
|
||||||
*
|
|
||||||
* @returns {object} API object with get/set/clear methods
|
|
||||||
*/
|
|
||||||
_getSettingsAPI(params) {
|
|
||||||
let {
|
|
||||||
extensionId,
|
|
||||||
context,
|
|
||||||
name,
|
|
||||||
callback,
|
|
||||||
storeType,
|
|
||||||
readOnly = false,
|
|
||||||
onChange,
|
|
||||||
validate = () => {},
|
|
||||||
} = params;
|
|
||||||
if (!extensionId) {
|
|
||||||
extensionId = context.extension.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
const checkScope = details => {
|
|
||||||
let { scope } = details;
|
|
||||||
if (scope && scope !== "regular") {
|
|
||||||
throw new ExtensionError(
|
|
||||||
`Firefox does not support the ${scope} settings scope.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let settingsAPI = {
|
|
||||||
async get(details) {
|
async get(details) {
|
||||||
validate();
|
validate();
|
||||||
let levelOfControl = details.incognito
|
let levelOfControl = details.incognito
|
||||||
|
@ -522,7 +443,6 @@ this.ExtensionPreferencesManager = {
|
||||||
},
|
},
|
||||||
set(details) {
|
set(details) {
|
||||||
validate();
|
validate();
|
||||||
checkScope(details);
|
|
||||||
if (!readOnly) {
|
if (!readOnly) {
|
||||||
return ExtensionPreferencesManager.setSetting(
|
return ExtensionPreferencesManager.setSetting(
|
||||||
extensionId,
|
extensionId,
|
||||||
|
@ -534,44 +454,11 @@ this.ExtensionPreferencesManager = {
|
||||||
},
|
},
|
||||||
clear(details) {
|
clear(details) {
|
||||||
validate();
|
validate();
|
||||||
checkScope(details);
|
|
||||||
if (!readOnly) {
|
if (!readOnly) {
|
||||||
return ExtensionPreferencesManager.removeSetting(extensionId, name);
|
return ExtensionPreferencesManager.removeSetting(extensionId, name);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
onChange,
|
|
||||||
};
|
};
|
||||||
// Any caller using the old call signature will not have passed
|
|
||||||
// context to us. This should only be experimental addons in the
|
|
||||||
// wild.
|
|
||||||
if (onChange === undefined && context) {
|
|
||||||
// Some settings that are read-only may not have called addSetting, in
|
|
||||||
// which case we have no way to listen on the pref changes.
|
|
||||||
let setting = settingsMap.get(name);
|
|
||||||
if (!setting) {
|
|
||||||
Services.console.logStringMessage(
|
|
||||||
`ExtensionPreferencesManager API ${name} created but addSetting was not called.`
|
|
||||||
);
|
|
||||||
return settingsAPI;
|
|
||||||
}
|
|
||||||
|
|
||||||
settingsAPI.onChange = new ExtensionCommon.EventManager({
|
|
||||||
context,
|
|
||||||
name: `${name}.onChange`,
|
|
||||||
register: fire => {
|
|
||||||
let listener = async () => {
|
|
||||||
fire.async({
|
|
||||||
details: await settingsAPI.get({}),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Management.on(`extension-setting-changed:${name}`, listener);
|
|
||||||
return () => {
|
|
||||||
Management.off(`extension-setting-changed:${name}`, listener);
|
|
||||||
};
|
|
||||||
},
|
|
||||||
}).api();
|
|
||||||
}
|
|
||||||
return settingsAPI;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -78,14 +78,6 @@ ExtensionPreferencesManager.addSetting("contextMenuShowEvent", {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
ExtensionPreferencesManager.addSetting(HOMEPAGE_OVERRIDE_SETTING, {
|
|
||||||
prefNames: [HOMEPAGE_URL_PREF],
|
|
||||||
|
|
||||||
setCallback() {
|
|
||||||
throw new Error("Unable to set read-only setting");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
ExtensionPreferencesManager.addSetting("ftpProtocolEnabled", {
|
ExtensionPreferencesManager.addSetting("ftpProtocolEnabled", {
|
||||||
prefNames: ["network.ftp.enabled"],
|
prefNames: ["network.ftp.enabled"],
|
||||||
|
|
||||||
|
@ -169,53 +161,47 @@ this.browserSettings = class extends ExtensionAPI {
|
||||||
let { extension } = context;
|
let { extension } = context;
|
||||||
return {
|
return {
|
||||||
browserSettings: {
|
browserSettings: {
|
||||||
allowPopupsForUserEvents: getSettingsAPI({
|
allowPopupsForUserEvents: getSettingsAPI(
|
||||||
context,
|
extension.id,
|
||||||
name: "allowPopupsForUserEvents",
|
"allowPopupsForUserEvents",
|
||||||
callback() {
|
() => {
|
||||||
return Services.prefs.getCharPref("dom.popup_allowed_events") != "";
|
return Services.prefs.getCharPref("dom.popup_allowed_events") != "";
|
||||||
},
|
}
|
||||||
|
),
|
||||||
|
cacheEnabled: getSettingsAPI(extension.id, "cacheEnabled", () => {
|
||||||
|
return (
|
||||||
|
Services.prefs.getBoolPref("browser.cache.disk.enable") &&
|
||||||
|
Services.prefs.getBoolPref("browser.cache.memory.enable")
|
||||||
|
);
|
||||||
}),
|
}),
|
||||||
cacheEnabled: getSettingsAPI({
|
closeTabsByDoubleClick: getSettingsAPI(
|
||||||
context,
|
extension.id,
|
||||||
name: "cacheEnabled",
|
"closeTabsByDoubleClick",
|
||||||
callback() {
|
() => {
|
||||||
return (
|
|
||||||
Services.prefs.getBoolPref("browser.cache.disk.enable") &&
|
|
||||||
Services.prefs.getBoolPref("browser.cache.memory.enable")
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
closeTabsByDoubleClick: getSettingsAPI({
|
|
||||||
context,
|
|
||||||
name: "closeTabsByDoubleClick",
|
|
||||||
callback() {
|
|
||||||
return Services.prefs.getBoolPref(
|
return Services.prefs.getBoolPref(
|
||||||
"browser.tabs.closeTabByDblclick"
|
"browser.tabs.closeTabByDblclick"
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
validate() {
|
undefined,
|
||||||
|
false,
|
||||||
|
() => {
|
||||||
if (AppConstants.platform == "android") {
|
if (AppConstants.platform == "android") {
|
||||||
throw new ExtensionError(
|
throw new ExtensionError(
|
||||||
`android is not a supported platform for the closeTabsByDoubleClick setting.`
|
`android is not a supported platform for the closeTabsByDoubleClick setting.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
contextMenuShowEvent: Object.assign(
|
contextMenuShowEvent: Object.assign(
|
||||||
getSettingsAPI({
|
getSettingsAPI(extension.id, "contextMenuShowEvent", () => {
|
||||||
context,
|
if (AppConstants.platform === "win") {
|
||||||
name: "contextMenuShowEvent",
|
return "mouseup";
|
||||||
callback() {
|
}
|
||||||
if (AppConstants.platform === "win") {
|
let prefValue = Services.prefs.getBoolPref(
|
||||||
return "mouseup";
|
"ui.context_menus.after_mouseup",
|
||||||
}
|
null
|
||||||
let prefValue = Services.prefs.getBoolPref(
|
);
|
||||||
"ui.context_menus.after_mouseup",
|
return prefValue ? "mouseup" : "mousedown";
|
||||||
null
|
|
||||||
);
|
|
||||||
return prefValue ? "mouseup" : "mousedown";
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
set: details => {
|
set: details => {
|
||||||
|
@ -241,121 +227,94 @@ this.browserSettings = class extends ExtensionAPI {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
ftpProtocolEnabled: getSettingsAPI({
|
ftpProtocolEnabled: getSettingsAPI(
|
||||||
context,
|
extension.id,
|
||||||
name: "ftpProtocolEnabled",
|
"ftpProtocolEnabled",
|
||||||
callback() {
|
() => {
|
||||||
return Services.prefs.getBoolPref("network.ftp.enabled");
|
return Services.prefs.getBoolPref("network.ftp.enabled");
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
homepageOverride: getSettingsAPI({
|
homepageOverride: getSettingsAPI(
|
||||||
context,
|
extension.id,
|
||||||
name: HOMEPAGE_OVERRIDE_SETTING,
|
HOMEPAGE_OVERRIDE_SETTING,
|
||||||
callback() {
|
() => {
|
||||||
return Services.prefs.getStringPref(HOMEPAGE_URL_PREF);
|
return Services.prefs.getStringPref(HOMEPAGE_URL_PREF);
|
||||||
},
|
},
|
||||||
readOnly: true,
|
undefined,
|
||||||
}),
|
true
|
||||||
imageAnimationBehavior: getSettingsAPI({
|
),
|
||||||
context,
|
imageAnimationBehavior: getSettingsAPI(
|
||||||
name: "imageAnimationBehavior",
|
extension.id,
|
||||||
callback() {
|
"imageAnimationBehavior",
|
||||||
|
() => {
|
||||||
return Services.prefs.getCharPref("image.animation_mode");
|
return Services.prefs.getCharPref("image.animation_mode");
|
||||||
},
|
}
|
||||||
|
),
|
||||||
|
newTabPosition: getSettingsAPI(extension.id, "newTabPosition", () => {
|
||||||
|
if (Services.prefs.getBoolPref("browser.tabs.insertAfterCurrent")) {
|
||||||
|
return "afterCurrent";
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
Services.prefs.getBoolPref("browser.tabs.insertRelatedAfterCurrent")
|
||||||
|
) {
|
||||||
|
return "relatedAfterCurrent";
|
||||||
|
}
|
||||||
|
return "atEnd";
|
||||||
}),
|
}),
|
||||||
newTabPosition: getSettingsAPI({
|
newTabPageOverride: getSettingsAPI(
|
||||||
context,
|
extension.id,
|
||||||
name: "newTabPosition",
|
NEW_TAB_OVERRIDE_SETTING,
|
||||||
callback() {
|
() => {
|
||||||
if (Services.prefs.getBoolPref("browser.tabs.insertAfterCurrent")) {
|
|
||||||
return "afterCurrent";
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
Services.prefs.getBoolPref(
|
|
||||||
"browser.tabs.insertRelatedAfterCurrent"
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return "relatedAfterCurrent";
|
|
||||||
}
|
|
||||||
return "atEnd";
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
newTabPageOverride: getSettingsAPI({
|
|
||||||
context,
|
|
||||||
name: NEW_TAB_OVERRIDE_SETTING,
|
|
||||||
callback() {
|
|
||||||
return aboutNewTabService.newTabURL;
|
return aboutNewTabService.newTabURL;
|
||||||
},
|
},
|
||||||
storeType: URL_STORE_TYPE,
|
URL_STORE_TYPE,
|
||||||
readOnly: true,
|
true
|
||||||
onChange: new ExtensionCommon.EventManager({
|
),
|
||||||
context,
|
openBookmarksInNewTabs: getSettingsAPI(
|
||||||
name: `${NEW_TAB_OVERRIDE_SETTING}.onChange`,
|
extension.id,
|
||||||
register: fire => {
|
"openBookmarksInNewTabs",
|
||||||
let listener = (text, id) => {
|
() => {
|
||||||
fire.async({
|
|
||||||
details: {
|
|
||||||
levelOfControl: "not_controllable",
|
|
||||||
value: aboutNewTabService.newTabURL,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Services.obs.addObserver(listener, "newtab-url-changed");
|
|
||||||
return () => {
|
|
||||||
Services.obs.removeObserver(listener, "newtab-url-changed");
|
|
||||||
};
|
|
||||||
},
|
|
||||||
}).api(),
|
|
||||||
}),
|
|
||||||
openBookmarksInNewTabs: getSettingsAPI({
|
|
||||||
context,
|
|
||||||
name: "openBookmarksInNewTabs",
|
|
||||||
callback() {
|
|
||||||
return Services.prefs.getBoolPref(
|
return Services.prefs.getBoolPref(
|
||||||
"browser.tabs.loadBookmarksInTabs"
|
"browser.tabs.loadBookmarksInTabs"
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
openSearchResultsInNewTabs: getSettingsAPI({
|
openSearchResultsInNewTabs: getSettingsAPI(
|
||||||
context,
|
extension.id,
|
||||||
name: "openSearchResultsInNewTabs",
|
"openSearchResultsInNewTabs",
|
||||||
callback() {
|
() => {
|
||||||
return Services.prefs.getBoolPref("browser.search.openintab");
|
return Services.prefs.getBoolPref("browser.search.openintab");
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
openUrlbarResultsInNewTabs: getSettingsAPI({
|
openUrlbarResultsInNewTabs: getSettingsAPI(
|
||||||
context,
|
extension.id,
|
||||||
name: "openUrlbarResultsInNewTabs",
|
"openUrlbarResultsInNewTabs",
|
||||||
callback() {
|
() => {
|
||||||
return Services.prefs.getBoolPref("browser.urlbar.openintab");
|
return Services.prefs.getBoolPref("browser.urlbar.openintab");
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
webNotificationsDisabled: getSettingsAPI({
|
webNotificationsDisabled: getSettingsAPI(
|
||||||
context,
|
extension.id,
|
||||||
name: "webNotificationsDisabled",
|
"webNotificationsDisabled",
|
||||||
callback() {
|
() => {
|
||||||
let prefValue = Services.prefs.getIntPref(
|
let prefValue = Services.prefs.getIntPref(
|
||||||
"permissions.default.desktop-notification",
|
"permissions.default.desktop-notification",
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
return prefValue === PERM_DENY_ACTION;
|
return prefValue === PERM_DENY_ACTION;
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
overrideDocumentColors: Object.assign(
|
overrideDocumentColors: Object.assign(
|
||||||
getSettingsAPI({
|
getSettingsAPI(extension.id, "overrideDocumentColors", () => {
|
||||||
context,
|
let prefValue = Services.prefs.getIntPref(
|
||||||
name: "overrideDocumentColors",
|
"browser.display.document_color_use"
|
||||||
callback() {
|
);
|
||||||
let prefValue = Services.prefs.getIntPref(
|
if (prefValue === 1) {
|
||||||
"browser.display.document_color_use"
|
return "never";
|
||||||
);
|
} else if (prefValue === 2) {
|
||||||
if (prefValue === 1) {
|
return "always";
|
||||||
return "never";
|
}
|
||||||
} else if (prefValue === 2) {
|
return "high-contrast-only";
|
||||||
return "always";
|
|
||||||
}
|
|
||||||
return "high-contrast-only";
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
set: details => {
|
set: details => {
|
||||||
|
@ -385,16 +344,12 @@ this.browserSettings = class extends ExtensionAPI {
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
useDocumentFonts: Object.assign(
|
useDocumentFonts: Object.assign(
|
||||||
getSettingsAPI({
|
getSettingsAPI(extension.id, "useDocumentFonts", () => {
|
||||||
context,
|
return (
|
||||||
name: "useDocumentFonts",
|
Services.prefs.getIntPref(
|
||||||
callback() {
|
"browser.display.use_document_fonts"
|
||||||
return (
|
) !== 0
|
||||||
Services.prefs.getIntPref(
|
);
|
||||||
"browser.display.use_document_fonts"
|
|
||||||
) !== 0
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
set: details => {
|
set: details => {
|
||||||
|
|
|
@ -104,14 +104,15 @@ this.captivePortal = class extends ExtensionAPI {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
}).api(),
|
}).api(),
|
||||||
canonicalURL: getSettingsAPI({
|
canonicalURL: getSettingsAPI(
|
||||||
context,
|
context.extension.id,
|
||||||
name: "captiveURL",
|
"captiveURL",
|
||||||
callback() {
|
() => {
|
||||||
return Services.prefs.getStringPref("captivedetect.canonicalURL");
|
return Services.prefs.getStringPref("captivedetect.canonicalURL");
|
||||||
},
|
},
|
||||||
readOnly: true,
|
undefined,
|
||||||
}),
|
true
|
||||||
|
),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@ ChromeUtils.defineModuleGetter(
|
||||||
var { ExtensionPreferencesManager } = ChromeUtils.import(
|
var { ExtensionPreferencesManager } = ChromeUtils.import(
|
||||||
"resource://gre/modules/ExtensionPreferencesManager.jsm"
|
"resource://gre/modules/ExtensionPreferencesManager.jsm"
|
||||||
);
|
);
|
||||||
var { getSettingsAPI } = ExtensionPreferencesManager;
|
|
||||||
|
var { ExtensionError } = ExtensionUtils;
|
||||||
|
|
||||||
const cookieSvc = Ci.nsICookieService;
|
const cookieSvc = Ci.nsICookieService;
|
||||||
|
|
||||||
|
@ -27,6 +28,42 @@ const cookieBehaviorValues = new Map([
|
||||||
["reject_trackers", cookieSvc.BEHAVIOR_REJECT_TRACKER],
|
["reject_trackers", cookieSvc.BEHAVIOR_REJECT_TRACKER],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const checkScope = scope => {
|
||||||
|
if (scope && scope !== "regular") {
|
||||||
|
throw new ExtensionError(
|
||||||
|
`Firefox does not support the ${scope} settings scope.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getPrivacyAPI = (extension, name, callback) => {
|
||||||
|
return {
|
||||||
|
async get(details) {
|
||||||
|
return {
|
||||||
|
levelOfControl: details.incognito
|
||||||
|
? "not_controllable"
|
||||||
|
: await ExtensionPreferencesManager.getLevelOfControl(
|
||||||
|
extension.id,
|
||||||
|
name
|
||||||
|
),
|
||||||
|
value: await callback(),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
set(details) {
|
||||||
|
checkScope(details.scope);
|
||||||
|
return ExtensionPreferencesManager.setSetting(
|
||||||
|
extension.id,
|
||||||
|
name,
|
||||||
|
details.value
|
||||||
|
);
|
||||||
|
},
|
||||||
|
clear(details) {
|
||||||
|
checkScope(details.scope);
|
||||||
|
return ExtensionPreferencesManager.removeSetting(extension.id, name);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// Add settings objects for supported APIs to the preferences manager.
|
// Add settings objects for supported APIs to the preferences manager.
|
||||||
ExtensionPreferencesManager.addSetting("network.networkPredictionEnabled", {
|
ExtensionPreferencesManager.addSetting("network.networkPredictionEnabled", {
|
||||||
prefNames: [
|
prefNames: [
|
||||||
|
@ -180,13 +217,14 @@ ExtensionPreferencesManager.addSetting("websites.trackingProtectionMode", {
|
||||||
|
|
||||||
this.privacy = class extends ExtensionAPI {
|
this.privacy = class extends ExtensionAPI {
|
||||||
getAPI(context) {
|
getAPI(context) {
|
||||||
|
let { extension } = context;
|
||||||
return {
|
return {
|
||||||
privacy: {
|
privacy: {
|
||||||
network: {
|
network: {
|
||||||
networkPredictionEnabled: getSettingsAPI({
|
networkPredictionEnabled: getPrivacyAPI(
|
||||||
context,
|
extension,
|
||||||
name: "network.networkPredictionEnabled",
|
"network.networkPredictionEnabled",
|
||||||
callback() {
|
() => {
|
||||||
return (
|
return (
|
||||||
Preferences.get("network.predictor.enabled") &&
|
Preferences.get("network.predictor.enabled") &&
|
||||||
Preferences.get("network.prefetch-next") &&
|
Preferences.get("network.prefetch-next") &&
|
||||||
|
@ -194,19 +232,19 @@ this.privacy = class extends ExtensionAPI {
|
||||||
0 &&
|
0 &&
|
||||||
!Preferences.get("network.dns.disablePrefetch")
|
!Preferences.get("network.dns.disablePrefetch")
|
||||||
);
|
);
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
peerConnectionEnabled: getSettingsAPI({
|
peerConnectionEnabled: getPrivacyAPI(
|
||||||
context,
|
extension,
|
||||||
name: "network.peerConnectionEnabled",
|
"network.peerConnectionEnabled",
|
||||||
callback() {
|
() => {
|
||||||
return Preferences.get("media.peerconnection.enabled");
|
return Preferences.get("media.peerconnection.enabled");
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
webRTCIPHandlingPolicy: getSettingsAPI({
|
webRTCIPHandlingPolicy: getPrivacyAPI(
|
||||||
context,
|
extension,
|
||||||
name: "network.webRTCIPHandlingPolicy",
|
"network.webRTCIPHandlingPolicy",
|
||||||
callback() {
|
() => {
|
||||||
if (Preferences.get("media.peerconnection.ice.proxy_only")) {
|
if (Preferences.get("media.peerconnection.ice.proxy_only")) {
|
||||||
return "proxy_only";
|
return "proxy_only";
|
||||||
}
|
}
|
||||||
|
@ -232,25 +270,25 @@ this.privacy = class extends ExtensionAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
return "default";
|
return "default";
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
services: {
|
services: {
|
||||||
passwordSavingEnabled: getSettingsAPI({
|
passwordSavingEnabled: getPrivacyAPI(
|
||||||
context,
|
extension,
|
||||||
name: "services.passwordSavingEnabled",
|
"services.passwordSavingEnabled",
|
||||||
callback() {
|
() => {
|
||||||
return Preferences.get("signon.rememberSignons");
|
return Preferences.get("signon.rememberSignons");
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
},
|
},
|
||||||
|
|
||||||
websites: {
|
websites: {
|
||||||
cookieConfig: getSettingsAPI({
|
cookieConfig: getPrivacyAPI(
|
||||||
context,
|
extension,
|
||||||
name: "websites.cookieConfig",
|
"websites.cookieConfig",
|
||||||
callback() {
|
() => {
|
||||||
let prefValue = Preferences.get("network.cookie.cookieBehavior");
|
let prefValue = Preferences.get("network.cookie.cookieBehavior");
|
||||||
return {
|
return {
|
||||||
behavior: Array.from(cookieBehaviorValues.entries()).find(
|
behavior: Array.from(cookieBehaviorValues.entries()).find(
|
||||||
|
@ -260,40 +298,40 @@ this.privacy = class extends ExtensionAPI {
|
||||||
Preferences.get("network.cookie.lifetimePolicy") ===
|
Preferences.get("network.cookie.lifetimePolicy") ===
|
||||||
cookieSvc.ACCEPT_SESSION,
|
cookieSvc.ACCEPT_SESSION,
|
||||||
};
|
};
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
firstPartyIsolate: getSettingsAPI({
|
firstPartyIsolate: getPrivacyAPI(
|
||||||
context,
|
extension,
|
||||||
name: "websites.firstPartyIsolate",
|
"websites.firstPartyIsolate",
|
||||||
callback() {
|
() => {
|
||||||
return Preferences.get("privacy.firstparty.isolate");
|
return Preferences.get("privacy.firstparty.isolate");
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
hyperlinkAuditingEnabled: getSettingsAPI({
|
hyperlinkAuditingEnabled: getPrivacyAPI(
|
||||||
context,
|
extension,
|
||||||
name: "websites.hyperlinkAuditingEnabled",
|
"websites.hyperlinkAuditingEnabled",
|
||||||
callback() {
|
() => {
|
||||||
return Preferences.get("browser.send_pings");
|
return Preferences.get("browser.send_pings");
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
referrersEnabled: getSettingsAPI({
|
referrersEnabled: getPrivacyAPI(
|
||||||
context,
|
extension,
|
||||||
name: "websites.referrersEnabled",
|
"websites.referrersEnabled",
|
||||||
callback() {
|
() => {
|
||||||
return Preferences.get("network.http.sendRefererHeader") !== 0;
|
return Preferences.get("network.http.sendRefererHeader") !== 0;
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
resistFingerprinting: getSettingsAPI({
|
resistFingerprinting: getPrivacyAPI(
|
||||||
context,
|
extension,
|
||||||
name: "websites.resistFingerprinting",
|
"websites.resistFingerprinting",
|
||||||
callback() {
|
() => {
|
||||||
return Preferences.get("privacy.resistFingerprinting");
|
return Preferences.get("privacy.resistFingerprinting");
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
trackingProtectionMode: getSettingsAPI({
|
trackingProtectionMode: getPrivacyAPI(
|
||||||
context,
|
extension,
|
||||||
name: "websites.trackingProtectionMode",
|
"websites.trackingProtectionMode",
|
||||||
callback() {
|
() => {
|
||||||
if (Preferences.get("privacy.trackingprotection.enabled")) {
|
if (Preferences.get("privacy.trackingprotection.enabled")) {
|
||||||
return "always";
|
return "always";
|
||||||
} else if (
|
} else if (
|
||||||
|
@ -302,8 +340,8 @@ this.privacy = class extends ExtensionAPI {
|
||||||
return "private_browsing";
|
return "private_browsing";
|
||||||
}
|
}
|
||||||
return "never";
|
return "never";
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -173,10 +173,10 @@ this.proxy = class extends ExtensionAPI {
|
||||||
}).api(),
|
}).api(),
|
||||||
|
|
||||||
settings: Object.assign(
|
settings: Object.assign(
|
||||||
getSettingsAPI({
|
getSettingsAPI(
|
||||||
context,
|
extension.id,
|
||||||
name: "proxy.settings",
|
"proxy.settings",
|
||||||
callback() {
|
() => {
|
||||||
let prefValue = Services.prefs.getIntPref("network.proxy.type");
|
let prefValue = Services.prefs.getIntPref("network.proxy.type");
|
||||||
let proxyConfig = {
|
let proxyConfig = {
|
||||||
proxyType: Array.from(PROXY_TYPES_MAP.entries()).find(
|
proxyType: Array.from(PROXY_TYPES_MAP.entries()).find(
|
||||||
|
@ -214,14 +214,16 @@ this.proxy = class extends ExtensionAPI {
|
||||||
return proxyConfig;
|
return proxyConfig;
|
||||||
},
|
},
|
||||||
// proxy.settings is unsupported on android.
|
// proxy.settings is unsupported on android.
|
||||||
validate() {
|
undefined,
|
||||||
|
false,
|
||||||
|
() => {
|
||||||
if (AppConstants.platform == "android") {
|
if (AppConstants.platform == "android") {
|
||||||
throw new ExtensionError(
|
throw new ExtensionError(
|
||||||
`proxy.settings is not supported on android.`
|
`proxy.settings is not supported on android.`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}),
|
),
|
||||||
{
|
{
|
||||||
set: details => {
|
set: details => {
|
||||||
if (AppConstants.platform === "android") {
|
if (AppConstants.platform === "android") {
|
||||||
|
|
|
@ -133,6 +133,7 @@
|
||||||
"name": "onChange",
|
"name": "onChange",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"description": "Fired after the setting changes.",
|
"description": "Fired after the setting changes.",
|
||||||
|
"unsupported": true,
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|
|
@ -40,20 +40,8 @@ add_task(async function test_browser_settings() {
|
||||||
};
|
};
|
||||||
|
|
||||||
async function background() {
|
async function background() {
|
||||||
let listeners = new Set([]);
|
|
||||||
browser.test.onMessage.addListener(async (msg, apiName, value) => {
|
browser.test.onMessage.addListener(async (msg, apiName, value) => {
|
||||||
let apiObj = browser.browserSettings[apiName];
|
let apiObj = browser.browserSettings[apiName];
|
||||||
// Don't add more than one listner per apiName. We leave the
|
|
||||||
// listener to ensure we do not get more calls than we expect.
|
|
||||||
if (!listeners.has(apiName)) {
|
|
||||||
apiObj.onChange.addListener(details => {
|
|
||||||
browser.test.sendMessage("onChange", {
|
|
||||||
details: details.details,
|
|
||||||
setting: apiName,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
listeners.add(apiName);
|
|
||||||
}
|
|
||||||
let result = await apiObj.set({ value });
|
let result = await apiObj.set({ value });
|
||||||
if (msg === "set") {
|
if (msg === "set") {
|
||||||
browser.test.assertTrue(result, "set returns true.");
|
browser.test.assertTrue(result, "set returns true.");
|
||||||
|
@ -91,13 +79,6 @@ add_task(async function test_browser_settings() {
|
||||||
async function testSetting(setting, value, expected, expectedValue = value) {
|
async function testSetting(setting, value, expected, expectedValue = value) {
|
||||||
extension.sendMessage("set", setting, value);
|
extension.sendMessage("set", setting, value);
|
||||||
let data = await extension.awaitMessage("settingData");
|
let data = await extension.awaitMessage("settingData");
|
||||||
let dataChange = await extension.awaitMessage("onChange");
|
|
||||||
equal(setting, dataChange.setting, "onChange fired");
|
|
||||||
equal(
|
|
||||||
data.value,
|
|
||||||
dataChange.details.value,
|
|
||||||
"onChange fired with correct value"
|
|
||||||
);
|
|
||||||
deepEqual(
|
deepEqual(
|
||||||
data.value,
|
data.value,
|
||||||
expectedValue,
|
expectedValue,
|
||||||
|
@ -193,12 +174,12 @@ add_task(async function test_browser_settings() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await testSetting("ftpProtocolEnabled", false, {
|
|
||||||
"network.ftp.enabled": false,
|
|
||||||
});
|
|
||||||
await testSetting("ftpProtocolEnabled", true, {
|
await testSetting("ftpProtocolEnabled", true, {
|
||||||
"network.ftp.enabled": true,
|
"network.ftp.enabled": true,
|
||||||
});
|
});
|
||||||
|
await testSetting("ftpProtocolEnabled", false, {
|
||||||
|
"network.ftp.enabled": false,
|
||||||
|
});
|
||||||
|
|
||||||
await testSetting("newTabPosition", "afterCurrent", {
|
await testSetting("newTabPosition", "afterCurrent", {
|
||||||
"browser.tabs.insertRelatedAfterCurrent": false,
|
"browser.tabs.insertRelatedAfterCurrent": false,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче