From ddda5460bc2ad7c688a9d3a3de2294edf12f82dc Mon Sep 17 00:00:00 2001 From: Sebastian Hengst Date: Sat, 10 Jun 2017 16:06:12 +0200 Subject: [PATCH] Backed out changeset d842c744941e (bug 1333403) --- browser/components/extensions/ext-menus.js | 18 +++---- .../test/browser/browser_ext_menus.js | 51 +------------------ .../extensions/test/browser/head.js | 2 +- .../components/extensions/ExtensionCommon.jsm | 12 ++++- 4 files changed, 21 insertions(+), 62 deletions(-) diff --git a/browser/components/extensions/ext-menus.js b/browser/components/extensions/ext-menus.js index e6f24a670b5e..6ecd0e290c38 100644 --- a/browser/components/extensions/ext-menus.js +++ b/browser/components/extensions/ext-menus.js @@ -616,23 +616,16 @@ const menuTracker = { }, }; +var gExtensionCount = 0; + this.menusInternal = class extends ExtensionAPI { - constructor(extension) { - super(extension); - - if (!gMenuMap.size) { - menuTracker.register(); - } - gMenuMap.set(extension, new Map()); - } - onShutdown(reason) { let {extension} = this; if (gMenuMap.has(extension)) { gMenuMap.delete(extension); gRootItems.delete(extension); - if (!gMenuMap.size) { + if (--gExtensionCount == 0) { menuTracker.unregister(); } } @@ -641,6 +634,11 @@ this.menusInternal = class extends ExtensionAPI { getAPI(context) { let {extension} = context; + gMenuMap.set(extension, new Map()); + if (++gExtensionCount == 1) { + menuTracker.register(); + } + return { menusInternal: { create: function(createProperties) { diff --git a/browser/components/extensions/test/browser/browser_ext_menus.js b/browser/components/extensions/test/browser/browser_ext_menus.js index 2993b666355c..0d871760a415 100644 --- a/browser/components/extensions/test/browser/browser_ext_menus.js +++ b/browser/components/extensions/test/browser/browser_ext_menus.js @@ -3,8 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ "use strict"; -const PAGE = "http://mochi.test:8888/browser/browser/components/extensions/test/browser/context.html"; - add_task(async function test_permissions() { function background() { browser.test.sendMessage("apis", { @@ -187,7 +185,8 @@ add_task(async function test_onclick_frameid() { } const extension = ExtensionTestUtils.loadExtension({manifest, background}); - const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE); + const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, + "http://mochi.test:8888/browser/browser/components/extensions/test/browser/context.html"); await extension.startup(); await extension.awaitMessage("ready"); @@ -209,49 +208,3 @@ add_task(async function test_onclick_frameid() { await BrowserTestUtils.removeTab(tab); await extension.unload(); }); - -add_task(async function test_multiple_contexts_init() { - const manifest = { - permissions: ["menus"], - }; - - function background() { - browser.menus.create({id: "parent", title: "parent"}); - browser.tabs.create({url: "tab.html", active: false}); - } - - const files = { - "tab.html": "", - "tab.js": function() { - browser.menus.create({parentId: "parent", id: "child", title: "child"}); - - browser.menus.onClicked.addListener(info => { - browser.test.sendMessage("click", info); - }); - - browser.test.sendMessage("ready"); - }, - }; - - const tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, PAGE); - const extension = ExtensionTestUtils.loadExtension({manifest, background, files}); - - await extension.startup(); - await extension.awaitMessage("ready"); - - const menu = await openContextMenu(); - const items = menu.getElementsByAttribute("label", "parent"); - - is(items.length, 1, "Found parent menu item"); - is(items[0].tagName, "menu", "And it has children"); - - const popup = await openSubmenu(items[0]); - is(popup.firstChild.label, "child", "Correct child menu item"); - await closeExtensionContextMenu(popup.firstChild); - - const info = await extension.awaitMessage("click"); - is(info.menuItemId, "child", "onClicked the correct item"); - - await BrowserTestUtils.removeTab(tab); - await extension.unload(); -}); diff --git a/browser/components/extensions/test/browser/head.js b/browser/components/extensions/test/browser/head.js index 652a3ea2a128..ae6a7e9d4541 100644 --- a/browser/components/extensions/test/browser/head.js +++ b/browser/components/extensions/test/browser/head.js @@ -309,7 +309,7 @@ async function closeExtensionContextMenu(itemToSelect, modifiers = {}) { let contentAreaContextMenu = document.getElementById("contentAreaContextMenu"); let popupHiddenPromise = BrowserTestUtils.waitForEvent(contentAreaContextMenu, "popuphidden"); EventUtils.synthesizeMouseAtCenter(itemToSelect, modifiers); - return popupHiddenPromise; + await popupHiddenPromise; } async function openChromeContextMenu(menuId, target, win = window) { diff --git a/toolkit/components/extensions/ExtensionCommon.jsm b/toolkit/components/extensions/ExtensionCommon.jsm index bcf81ebb7ccb..086e7198dcf0 100644 --- a/toolkit/components/extensions/ExtensionCommon.jsm +++ b/toolkit/components/extensions/ExtensionCommon.jsm @@ -1010,7 +1010,7 @@ class SchemaAPIManager extends EventEmitter { module.loaded = true; - return this.global[name]; + return this._initModule(module, this.global[name]); } /** * aSynchronously loads an API module, if not already loaded, and @@ -1037,7 +1037,7 @@ class SchemaAPIManager extends EventEmitter { module.loaded = true; - return this.global[name]; + return this._initModule(module, this.global[name]); }); return module.asyncLoaded; @@ -1076,6 +1076,14 @@ class SchemaAPIManager extends EventEmitter { return true; } + _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); + + return cls; + } + _checkLoadModule(module, name) { if (!module) { throw new Error(`Module '${name}' does not exist`);