Bug 1420974 - API to open bookmarks in new tab, r?mixedpuppy
This introduces browserSettings.openBookmarksInNewTabs which exposes
the browser.tabs.loadBookmarksInTabs preference to extensions.
MozReview-Commit-ID: AZlir2GoiCo
--- a/toolkit/components/extensions/ext-browserSettings.js
+++ b/toolkit/components/extensions/ext-browserSettings.js
@@ -73,33 +73,43 @@ ExtensionPreferencesManager.addSetting("
let returnObj = {};
for (let pref of this.prefNames) {
returnObj[pref] = value;
}
return returnObj;
},
});
+ExtensionPreferencesManager.addSetting("contextMenuShowEvent", {
+ prefNames: [
+ "ui.context_menus.after_mouseup",
+ ],
+
+ setCallback(value) {
+ return {[this.prefNames[0]]: value === "mouseup"};
+ },
+});
+
ExtensionPreferencesManager.addSetting("imageAnimationBehavior", {
prefNames: [
"image.animation_mode",
],
setCallback(value) {
return {[this.prefNames[0]]: value};
},
});
-ExtensionPreferencesManager.addSetting("contextMenuShowEvent", {
+ExtensionPreferencesManager.addSetting("openBookmarksInNewTabs", {
prefNames: [
- "ui.context_menus.after_mouseup",
+ "browser.tabs.loadBookmarksInTabs",
],
setCallback(value) {
- return {[this.prefNames[0]]: value === "mouseup"};
+ return {[this.prefNames[0]]: value};
},
});
ExtensionPreferencesManager.addSetting("webNotificationsDisabled", {
prefNames: [
"permissions.default.desktop-notification",
],
@@ -119,32 +129,16 @@ this.browserSettings = class extends Ext
return Services.prefs.getCharPref("dom.popup_allowed_events") != "";
}),
cacheEnabled: getSettingsAPI(extension,
"cacheEnabled",
() => {
return Services.prefs.getBoolPref("browser.cache.disk.enable") &&
Services.prefs.getBoolPref("browser.cache.memory.enable");
}),
- homepageOverride: getSettingsAPI(extension,
- HOMEPAGE_OVERRIDE_SETTING,
- () => {
- return Services.prefs.getComplexValue(
- HOMEPAGE_URL_PREF, Ci.nsIPrefLocalizedString).data;
- }, undefined, true),
- imageAnimationBehavior: getSettingsAPI(extension,
- "imageAnimationBehavior",
- () => {
- return Services.prefs.getCharPref("image.animation_mode");
- }),
- newTabPageOverride: getSettingsAPI(extension,
- NEW_TAB_OVERRIDE_SETTING,
- () => {
- return aboutNewTabService.newTabURL;
- }, URL_STORE_TYPE, true),
contextMenuShowEvent: Object.assign(
getSettingsAPI(
extension,
"contextMenuShowEvent",
() => {
if (AppConstants.platform === "win") {
return "mouseup";
}
@@ -164,16 +158,37 @@ this.browserSettings = class extends Ext
details.value === "mousedown")) {
return false;
}
return ExtensionPreferencesManager.setSetting(
extension.id, "contextMenuShowEvent", details.value);
},
}
),
+ homepageOverride: getSettingsAPI(extension,
+ HOMEPAGE_OVERRIDE_SETTING,
+ () => {
+ return Services.prefs.getComplexValue(
+ HOMEPAGE_URL_PREF, Ci.nsIPrefLocalizedString).data;
+ }, undefined, true),
+ imageAnimationBehavior: getSettingsAPI(extension,
+ "imageAnimationBehavior",
+ () => {
+ return Services.prefs.getCharPref("image.animation_mode");
+ }),
+ newTabPageOverride: getSettingsAPI(extension,
+ NEW_TAB_OVERRIDE_SETTING,
+ () => {
+ return aboutNewTabService.newTabURL;
+ }, URL_STORE_TYPE, true),
+ openBookmarksInNewTabs: getSettingsAPI(extension,
+ "openBookmarksInNewTabs",
+ () => {
+ return Services.prefs.getBoolPref("browser.tabs.loadBookmarksInTabs");
+ }),
webNotificationsDisabled: getSettingsAPI(extension,
"webNotificationsDisabled",
() => {
let prefValue =
Services.prefs.getIntPref(
"permissions.default.desktop-notification", null);
return prefValue === PERM_DENY_ACTION;
}),
--- a/toolkit/components/extensions/schemas/browser_settings.json
+++ b/toolkit/components/extensions/schemas/browser_settings.json
@@ -39,31 +39,35 @@
"allowPopupsForUserEvents": {
"$ref": "types.Setting",
"description": "Allows or disallows pop-up windows from opening in response to user events."
},
"cacheEnabled": {
"$ref": "types.Setting",
"description": "Enables or disables the browser cache."
},
+ "contextMenuShowEvent": {
+ "$ref": "types.Setting",
+ "description": "Controls after which mouse event context menus popup. This setting's value is of type ContextMenuMouseEvent, which has possible values of <code>mouseup</code> and <code>mousedown</code>."
+ },
"homepageOverride": {
"$ref": "types.Setting",
"description": "Returns the value of the overridden home page. Read-only."
},
"imageAnimationBehavior": {
"$ref": "types.Setting",
"description": "Controls the behaviour of image animation in the browser. This setting's value is of type ImageAnimationBehavior, defaulting to <code>normal</code>."
},
"newTabPageOverride": {
"$ref": "types.Setting",
"description": "Returns the value of the overridden new tab page. Read-only."
},
- "contextMenuShowEvent": {
+ "openBookmarksInNewTabs": {
"$ref": "types.Setting",
- "description": "Controls after which mouse event context menus popup. This setting's value is of type ContextMenuMouseEvent, which has possible values of <code>mouseup</code> and <code>mousedown</code>."
+ "description": "This boolean setting controls whether bookmarks are opened in the current tab or in a new tab."
},
"webNotificationsDisabled": {
"$ref": "types.Setting",
"description": "Disables webAPI notifications."
}
}
}
]
--- a/toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_browserSettings.js
@@ -24,16 +24,17 @@ add_task(async function test_browser_set
// Create an object to hold the values to which we will initialize the prefs.
const PREFS = {
"browser.cache.disk.enable": true,
"browser.cache.memory.enable": true,
"dom.popup_allowed_events": Preferences.get("dom.popup_allowed_events"),
"image.animation_mode": "none",
"permissions.default.desktop-notification": PERM_UNKNOWN_ACTION,
"ui.context_menus.after_mouseup": false,
+ "browser.tabs.loadBookmarksInTabs": false,
};
async function background() {
browser.test.onMessage.addListener(async (msg, apiName, value) => {
let apiObj = browser.browserSettings[apiName];
let result = await apiObj.set({value});
if (msg === "set") {
browser.test.assertTrue(result, "set returns true.");
@@ -140,16 +141,23 @@ add_task(async function test_browser_set
await testNoOpSetting("contextMenuShowEvent", "mousedown",
{"ui.context_menus.after_mouseup": AppConstants.platform === "win"});
} else {
await testSetting(
"contextMenuShowEvent", "mousedown",
{"ui.context_menus.after_mouseup": false});
}
+ await testSetting(
+ "openBookmarksInNewTabs", true,
+ {"browser.tabs.loadBookmarksInTabs": true});
+ await testSetting(
+ "openBookmarksInNewTabs", false,
+ {"browser.tabs.loadBookmarksInTabs": false});
+
await extension.unload();
await promiseShutdownManager();
});
add_task(async function test_bad_value() {
async function background() {
await browser.test.assertRejects(
browser.browserSettings.contextMenuShowEvent.set({value: "bad"}),