Backed out changeset cfc47df74537 (bug 1333403)

--HG--
rename : browser/components/extensions/ext-c-menus.js => browser/components/extensions/ext-c-contextMenus.js
rename : browser/components/extensions/ext-menus.js => browser/components/extensions/ext-contextMenus.js
rename : browser/components/extensions/schemas/menus.json => browser/components/extensions/schemas/context_menus.json
rename : browser/components/extensions/schemas/menus_internal.json => browser/components/extensions/schemas/context_menus_internal.json
rename : browser/components/extensions/test/browser/browser_ext_menus.js => browser/components/extensions/test/browser/browser_ext_contextMenus_chrome.js
This commit is contained in:
Sebastian Hengst 2017-06-10 16:06:44 +02:00
Родитель ddda5460bc
Коммит 7f39e1a3f2
12 изменённых файлов: 69 добавлений и 133 удалений

Просмотреть файл

@ -115,6 +115,14 @@ extensions.registerModules({
["commands"],
],
},
contextMenus: {
url: "chrome://browser/content/ext-contextMenus.js",
schema: "chrome://browser/content/schemas/context_menus.json",
scopes: ["addon_parent"],
paths: [
["contextMenus"],
],
},
devtools: {
url: "chrome://browser/content/ext-devtools.js",
schema: "chrome://browser/content/schemas/devtools.json",
@ -156,16 +164,6 @@ extensions.registerModules({
["history"],
],
},
// This module supports the "menus" and "contextMenus" namespaces,
// and because of permissions, the module name must differ from both.
menusInternal: {
url: "chrome://browser/content/ext-menus.js",
schema: "chrome://browser/content/schemas/menus.json",
scopes: ["addon_parent"],
paths: [
["menusInternal"],
],
},
omnibox: {
url: "chrome://browser/content/ext-omnibox.js",
schema: "chrome://browser/content/schemas/omnibox.json",

Просмотреть файл

@ -22,13 +22,11 @@ extensions.registerModules({
["devtools", "panels"],
],
},
// Because of permissions, the module name must differ from both namespaces.
menusInternal: {
url: "chrome://browser/content/ext-c-menus.js",
contextMenus: {
url: "chrome://browser/content/ext-c-contextMenus.js",
scopes: ["addon_child"],
paths: [
["contextMenus"],
["menus"],
],
},
omnibox: {

Просмотреть файл

@ -36,7 +36,7 @@ class ContextMenusClickPropHandler {
// The `onclick` function MUST be owned by `this.context`.
setListener(id, onclick) {
if (this.onclickMap.size === 0) {
this.context.childManager.getParentEvent("menusInternal.onClicked").addListener(this.dispatchEvent);
this.context.childManager.getParentEvent("contextMenus.onClicked").addListener(this.dispatchEvent);
this.context.callOnClose(this);
}
this.onclickMap.set(id, onclick);
@ -63,7 +63,7 @@ class ContextMenusClickPropHandler {
return;
}
if (this.onclickMap.size === 0) {
this.context.childManager.getParentEvent("menusInternal.onClicked").removeListener(this.dispatchEvent);
this.context.childManager.getParentEvent("contextMenus.onClicked").removeListener(this.dispatchEvent);
this.context.forgetOnClose(this);
}
let propHandlerMap = gPropHandlers.get(this.context.extension);
@ -101,19 +101,19 @@ class ContextMenusClickPropHandler {
}
}
this.menusInternal = class extends ExtensionAPI {
this.contextMenus = class extends ExtensionAPI {
getAPI(context) {
let onClickedProp = new ContextMenusClickPropHandler(context);
let api = {
menus: {
return {
contextMenus: {
create(createProperties, callback) {
if (createProperties.id === null) {
createProperties.id = ++gNextMenuItemID;
}
let {onclick} = createProperties;
delete createProperties.onclick;
context.childManager.callParentAsyncFunction("menusInternal.create", [
context.childManager.callParentAsyncFunction("contextMenus.createInternal", [
createProperties,
]).then(() => {
if (onclick) {
@ -129,7 +129,7 @@ this.menusInternal = class extends ExtensionAPI {
update(id, updateProperties) {
let {onclick} = updateProperties;
delete updateProperties.onclick;
return context.childManager.callParentAsyncFunction("menusInternal.update", [
return context.childManager.callParentAsyncFunction("contextMenus.update", [
id,
updateProperties,
]).then(() => {
@ -144,7 +144,7 @@ this.menusInternal = class extends ExtensionAPI {
remove(id) {
onClickedProp.unsetListenerFromAnyContext(id);
return context.childManager.callParentAsyncFunction("menusInternal.remove", [
return context.childManager.callParentAsyncFunction("contextMenus.remove", [
id,
]);
},
@ -152,30 +152,9 @@ this.menusInternal = class extends ExtensionAPI {
removeAll() {
onClickedProp.deleteAllListenersFromExtension();
return context.childManager.callParentAsyncFunction("menusInternal.removeAll", []);
return context.childManager.callParentAsyncFunction("contextMenus.removeAll", []);
},
onClicked: new SingletonEventManager(context, "menus.onClicked", fire => {
let listener = (info, tab) => {
fire.async(info, tab);
};
let event = context.childManager.getParentEvent("menusInternal.onClicked");
event.addListener(listener);
return () => {
event.removeListener(listener);
};
}).api(),
},
};
const result = {};
if (context.extension.hasPermission("menus")) {
result.menus = api.menus;
}
if (context.extension.hasPermission("contextMenus")) {
result.contextMenus = api.menus;
}
return result;
}
};

Просмотреть файл

@ -25,7 +25,7 @@ const ACTION_MENU_TOP_LEVEL_LIMIT = 6;
// Map[Extension -> Map[ID -> MenuItem]]
// Note: we want to enumerate all the menu items so
// this cannot be a weak map.
var gMenuMap = new Map();
var gContextMenuMap = new Map();
// Map[Extension -> MenuItem]
var gRootItems = new Map();
@ -40,7 +40,7 @@ var gNextRadioGroupID = 0;
var gMaxLabelLength = 64;
var gMenuBuilder = {
// When a new menu is opened, this function is called and
// When a new contextMenu is opened, this function is called and
// we populate the |xulMenu| with all the items from extensions
// to be displayed. We always clear all the items again when
// popuphidden fires.
@ -258,7 +258,7 @@ var gMenuBuilder = {
info.modifiers.push("MacCtrl");
}
// Allow menus to open various actions supported in webext prior
// Allow context menu's to open various actions supported in webext prior
// to notifying onclicked.
let actionFor = {
_execute_page_action: global.pageActionFor,
@ -270,7 +270,7 @@ var gMenuBuilder = {
actionFor(item.extension).triggerAction(win);
}
item.extension.emit("webext-menu-menuitem-click", info, tab);
item.extension.emit("webext-contextmenu-menuitem-click", info, tab);
});
return element;
@ -414,7 +414,7 @@ MenuItem.prototype = {
if (this.hasOwnProperty("_id")) {
throw new Error("Id of a MenuItem cannot be changed");
}
let isIdUsed = gMenuMap.get(this.extension).has(id);
let isIdUsed = gContextMenuMap.get(this.extension).has(id);
if (isIdUsed) {
throw new Error("Id already exists");
}
@ -429,7 +429,7 @@ MenuItem.prototype = {
if (parentId === undefined) {
return;
}
let menuMap = gMenuMap.get(this.extension);
let menuMap = gContextMenuMap.get(this.extension);
if (!menuMap.has(parentId)) {
throw new Error("Could not find any MenuItem with id: " + parentId);
}
@ -450,7 +450,7 @@ MenuItem.prototype = {
if (parentId === undefined) {
this.root.addChild(this);
} else {
let menuMap = gMenuMap.get(this.extension);
let menuMap = gContextMenuMap.get(this.extension);
menuMap.get(parentId).addChild(this);
}
},
@ -497,7 +497,7 @@ MenuItem.prototype = {
child.remove();
}
let menuMap = gMenuMap.get(this.extension);
let menuMap = gContextMenuMap.get(this.extension);
menuMap.delete(this.id);
if (this.root == this) {
gRootItems.delete(this.extension);
@ -577,7 +577,7 @@ MenuItem.prototype = {
// While any extensions are active, this Tracker registers to observe/listen
// for contex-menu events from both content and chrome.
const menuTracker = {
const contextMenuTracker = {
register() {
Services.obs.addObserver(this, "on-build-contextmenu");
for (const window of windowTracker.browserWindows()) {
@ -602,7 +602,7 @@ const menuTracker = {
onWindowOpen(window) {
const menu = window.document.getElementById("tabContextMenu");
menu.addEventListener("popupshowing", menuTracker);
menu.addEventListener("popupshowing", contextMenuTracker);
},
handleEvent(event) {
@ -618,15 +618,15 @@ const menuTracker = {
var gExtensionCount = 0;
this.menusInternal = class extends ExtensionAPI {
this.contextMenus = class extends ExtensionAPI {
onShutdown(reason) {
let {extension} = this;
if (gMenuMap.has(extension)) {
gMenuMap.delete(extension);
if (gContextMenuMap.has(extension)) {
gContextMenuMap.delete(extension);
gRootItems.delete(extension);
if (--gExtensionCount == 0) {
menuTracker.unregister();
contextMenuTracker.unregister();
}
}
}
@ -634,30 +634,30 @@ this.menusInternal = class extends ExtensionAPI {
getAPI(context) {
let {extension} = context;
gMenuMap.set(extension, new Map());
gContextMenuMap.set(extension, new Map());
if (++gExtensionCount == 1) {
menuTracker.register();
contextMenuTracker.register();
}
return {
menusInternal: {
create: function(createProperties) {
contextMenus: {
createInternal: function(createProperties) {
// Note that the id is required by the schema. If the addon did not set
// it, the implementation of menus.create in the child should
// it, the implementation of contextMenus.create in the child should
// have added it.
let menuItem = new MenuItem(extension, createProperties);
gMenuMap.get(extension).set(menuItem.id, menuItem);
gContextMenuMap.get(extension).set(menuItem.id, menuItem);
},
update: function(id, updateProperties) {
let menuItem = gMenuMap.get(extension).get(id);
let menuItem = gContextMenuMap.get(extension).get(id);
if (menuItem) {
menuItem.setProps(updateProperties);
}
},
remove: function(id) {
let menuItem = gMenuMap.get(extension).get(id);
let menuItem = gContextMenuMap.get(extension).get(id);
if (menuItem) {
menuItem.remove();
}
@ -670,14 +670,14 @@ this.menusInternal = class extends ExtensionAPI {
}
},
onClicked: new SingletonEventManager(context, "menusInternal.onClicked", fire => {
onClicked: new SingletonEventManager(context, "contextMenus.onClicked", fire => {
let listener = (event, info, tab) => {
fire.async(info, tab);
};
extension.on("webext-menu-menuitem-click", listener);
extension.on("webext-contextmenu-menuitem-click", listener);
return () => {
extension.off("webext-menu-menuitem-click", listener);
extension.off("webext-contextmenu-menuitem-click", listener);
};
}).api(),
},

Просмотреть файл

@ -3,4 +3,4 @@ category webextension-scripts utils chrome://browser/content/ext-utils.js
category webextension-scripts-devtools browser chrome://browser/content/ext-c-browser.js
category webextension-scripts-addon browser chrome://browser/content/ext-c-browser.js
category webextension-schemas menus_internal chrome://browser/content/schemas/menus_internal.json
category webextension-schemas context_menus_internal chrome://browser/content/schemas/context_menus_internal.json

Просмотреть файл

@ -18,13 +18,13 @@ browser.jar:
content/browser/ext-browsingData.js
content/browser/ext-chrome-settings-overrides.js
content/browser/ext-commands.js
content/browser/ext-contextMenus.js
content/browser/ext-devtools.js
content/browser/ext-devtools-inspectedWindow.js
content/browser/ext-devtools-network.js
content/browser/ext-devtools-panels.js
content/browser/ext-geckoProfiler.js
content/browser/ext-history.js
content/browser/ext-menus.js
content/browser/ext-omnibox.js
content/browser/ext-pageAction.js
content/browser/ext-sessions.js
@ -34,9 +34,9 @@ browser.jar:
content/browser/ext-utils.js
content/browser/ext-windows.js
content/browser/ext-c-browser.js
content/browser/ext-c-contextMenus.js
content/browser/ext-c-devtools-inspectedWindow.js
content/browser/ext-c-devtools-panels.js
content/browser/ext-c-devtools.js
content/browser/ext-c-menus.js
content/browser/ext-c-omnibox.js
content/browser/ext-c-tabs.js

Просмотреть файл

@ -11,7 +11,6 @@
"choices": [{
"type": "string",
"enum": [
"menus",
"contextMenus"
]
}]
@ -20,14 +19,8 @@
},
{
"namespace": "contextMenus",
"description": "Use the <code>browser.contextMenus</code> API to add items to the browser's context menu. You can choose what types of objects your context menu additions apply to, such as images, hyperlinks, and pages.",
"permissions": ["contextMenus"],
"description": "Use the browser.contextMenus API to add items to the browser's context menu. You can choose what types of objects your context menu additions apply to, such as images, hyperlinks, and pages.",
"$import": "menus"
},
{
"namespace": "menus",
"permissions": ["menus"],
"description": "Use the browser.menus API to add items to the browser's menus. You can choose what types of objects your context menu additions apply to, such as images, hyperlinks, and pages.",
"properties": {
"ACTION_MENU_TOP_LEVEL_LIMIT": {
"value": 6,
@ -271,7 +264,7 @@
"parameters": [
{
"name": "info",
"$ref": "menusInternal.OnClickData"
"$ref": "contextMenusInternal.OnClickData"
},
{
"name": "tab",

Просмотреть файл

@ -4,8 +4,7 @@
[
{
"namespace": "menusInternal",
"allowedContexts": ["addon_parent_only"],
"namespace": "contextMenusInternal",
"description": "Use the <code>browser.contextMenus</code> API to add items to the browser's context menu. You can choose what types of objects your context menu additions apply to, such as images, hyperlinks, and pages.",
"types": [
{

Просмотреть файл

@ -8,14 +8,14 @@ browser.jar:
content/browser/schemas/browsing_data.json
content/browser/schemas/chrome_settings_overrides.json
content/browser/schemas/commands.json
content/browser/schemas/context_menus.json
content/browser/schemas/context_menus_internal.json
content/browser/schemas/devtools.json
content/browser/schemas/devtools_inspected_window.json
content/browser/schemas/devtools_network.json
content/browser/schemas/devtools_panels.json
content/browser/schemas/geckoProfiler.json
content/browser/schemas/history.json
content/browser/schemas/menus.json
content/browser/schemas/menus_internal.json
content/browser/schemas/omnibox.json
content/browser/schemas/page_action.json
content/browser/schemas/sessions.json

Просмотреть файл

@ -52,6 +52,7 @@ skip-if = (os == 'win' && !debug) # bug 1352668
[browser_ext_contentscript_connect.js]
[browser_ext_contextMenus.js]
[browser_ext_contextMenus_checkboxes.js]
[browser_ext_contextMenus_chrome.js]
[browser_ext_contextMenus_commands.js]
[browser_ext_contextMenus_icons.js]
[browser_ext_contextMenus_onclick.js]
@ -71,7 +72,6 @@ skip-if = (os == 'win' && !debug) # bug 1352668
[browser_ext_incognito_views.js]
[browser_ext_incognito_popup.js]
[browser_ext_lastError.js]
[browser_ext_menus.js]
[browser_ext_omnibox.js]
skip-if = debug || asan # Bug 1354681
[browser_ext_optionsPage_browser_style.js]

Просмотреть файл

@ -3,55 +3,25 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
add_task(async function test_permissions() {
function background() {
browser.test.sendMessage("apis", {
menus: typeof browser.menus,
contextMenus: typeof browser.contextMenus,
menusInternal: typeof browser.menusInternal,
});
}
const first = ExtensionTestUtils.loadExtension({manifest: {permissions: ["menus"]}, background});
const second = ExtensionTestUtils.loadExtension({manifest: {permissions: ["contextMenus"]}, background});
await first.startup();
await second.startup();
const apis1 = await first.awaitMessage("apis");
const apis2 = await second.awaitMessage("apis");
is(apis1.menus, "object", "browser.menus available with 'menus' permission");
is(apis1.contextMenus, "undefined", "browser.contextMenus unavailable with 'menus' permission");
is(apis1.menusInternal, "undefined", "browser.menusInternal is never available");
is(apis2.menus, "undefined", "browser.menus unavailable with 'contextMenus' permission");
is(apis2.contextMenus, "object", "browser.contextMenus unavailable with 'contextMenus' permission");
is(apis2.menusInternal, "undefined", "browser.menusInternal is never available");
await first.unload();
await second.unload();
});
add_task(async function test_actionContextMenus() {
const manifest = {
page_action: {},
browser_action: {},
permissions: ["menus"],
permissions: ["contextMenus"],
};
async function background() {
const contexts = ["page_action", "browser_action"];
const parentId = browser.menus.create({contexts, title: "parent"});
await browser.menus.create({parentId, title: "click A"});
await browser.menus.create({parentId, title: "click B"});
const parentId = browser.contextMenus.create({contexts, title: "parent"});
await browser.contextMenus.create({parentId, title: "click A"});
await browser.contextMenus.create({parentId, title: "click B"});
for (let i = 1; i < 9; i++) {
await browser.menus.create({contexts, id: `${i}`, title: `click ${i}`});
await browser.contextMenus.create({contexts, id: `${i}`, title: `click ${i}`});
}
browser.menus.onClicked.addListener((info, tab) => {
browser.contextMenus.onClicked.addListener((info, tab) => {
browser.test.sendMessage("click", {info, tab});
});
@ -100,19 +70,19 @@ add_task(async function test_actionContextMenus() {
add_task(async function test_tabContextMenu() {
const first = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["menus"],
permissions: ["contextMenus"],
},
async background() {
await browser.menus.create({
await browser.contextMenus.create({
id: "alpha-beta-parent", title: "alpha-beta parent", contexts: ["tab"],
});
await browser.menus.create({parentId: "alpha-beta-parent", title: "alpha"});
await browser.menus.create({parentId: "alpha-beta-parent", title: "beta"});
await browser.contextMenus.create({parentId: "alpha-beta-parent", title: "alpha"});
await browser.contextMenus.create({parentId: "alpha-beta-parent", title: "beta"});
await browser.menus.create({title: "dummy", contexts: ["page"]});
await browser.contextMenus.create({title: "dummy", contexts: ["page"]});
browser.menus.onClicked.addListener((info, tab) => {
browser.contextMenus.onClicked.addListener((info, tab) => {
browser.test.sendMessage("click", {info, tab});
});
@ -123,10 +93,10 @@ add_task(async function test_tabContextMenu() {
const second = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["menus"],
permissions: ["contextMenus"],
},
async background() {
await browser.menus.create({title: "gamma", contexts: ["tab"]});
await browser.contextMenus.create({title: "gamma", contexts: ["tab"]});
browser.test.sendMessage("ready");
},
});
@ -173,14 +143,14 @@ add_task(async function test_tabContextMenu() {
add_task(async function test_onclick_frameid() {
const manifest = {
permissions: ["menus"],
permissions: ["contextMenus"],
};
function background() {
function onclick(info) {
browser.test.sendMessage("click", info);
}
browser.menus.create({contexts: ["frame", "page"], title: "modify", onclick});
browser.contextMenus.create({contexts: ["frame", "page"], title: "modify", onclick});
browser.test.sendMessage("ready");
}

Просмотреть файл

@ -1077,7 +1077,6 @@ class SchemaAPIManager extends EventEmitter {
}
_initModule(info, cls) {
// FIXME: This both a) does nothing, and b) is not used anymore.
cls.namespaceName = cls.namespaceName;
cls.scopes = new Set(info.scopes);