Bug 1409433 - Handle contextmenu clicks in non-tab content r=aswan
authorTomislav Jovanovic <tomica@gmail.com>
Wed, 01 Nov 2017 23:00:33 +0100
changeset 443107 759c687e02d2f3191c445076060b44070d75daed
parent 443101 8570b22fc8f3555afde251370959982e138080bf
child 443108 e16e1fb28941643189f84f7d9d9e05cb1db74df2
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1409433
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1409433 - Handle contextmenu clicks in non-tab content r=aswan MozReview-Commit-ID: BSTb0ATBfbh
browser/components/extensions/ext-menus.js
browser/components/extensions/test/browser/browser_ext_sidebarAction_contextMenu.js
--- a/browser/components/extensions/ext-menus.js
+++ b/browser/components/extensions/ext-menus.js
@@ -233,17 +233,17 @@ var gMenuBuilder = {
           }
         }
         // Select the clicked radio item.
         item.checked = true;
       }
 
       item.tabManager.addActiveTabPermission();
 
-      let tab = item.tabManager.convert(contextData.tab);
+      let tab = contextData.tab && item.tabManager.convert(contextData.tab);
       let info = item.getClickInfo(contextData, wasChecked);
 
       const map = {shiftKey: "Shift", altKey: "Alt", metaKey: "Command", ctrlKey: "Ctrl"};
       info.modifiers = Object.keys(map).filter(key => event[key]).map(key => map[key]);
       if (event.ctrlKey && AppConstants.platform === "macosx") {
         info.modifiers.push("MacCtrl");
       }
 
@@ -668,17 +668,18 @@ this.menusInternal = class extends Exten
           let root = gRootItems.get(extension);
           if (root) {
             root.remove();
           }
         },
 
         onClicked: new EventManager(context, "menusInternal.onClicked", fire => {
           let listener = (event, info, tab) => {
-            context.withPendingBrowser(tab.linkedBrowser,
+            let {linkedBrowser} = tab || tabTracker.activeTab;
+            context.withPendingBrowser(linkedBrowser,
                                        () => fire.sync(info, tab));
           };
 
           extension.on("webext-menu-menuitem-click", listener);
           return () => {
             extension.off("webext-menu-menuitem-click", listener);
           };
         }).api(),
--- a/browser/components/extensions/test/browser/browser_ext_sidebarAction_contextMenu.js
+++ b/browser/components/extensions/test/browser/browser_ext_sidebarAction_contextMenu.js
@@ -31,16 +31,19 @@ let extData = {
     },
   },
 
   background: function() {
     browser.contextMenus.create({
       id: "clickme-page",
       title: "Click me!",
       contexts: ["all"],
+      onclick(info, tab) {
+        browser.test.sendMessage("menu-click", tab);
+      },
     });
   },
 };
 
 let contextMenuItems = {
   "context-navigation": "hidden",
   "context-sep-navigation": "hidden",
   "context-viewsource": "",
@@ -54,17 +57,21 @@ add_task(async function sidebar_contextm
   let extension = ExtensionTestUtils.loadExtension(extData);
   await extension.startup();
   // Test sidebar is opened on install
   await extension.awaitMessage("sidebar");
 
   let contentAreaContextMenu = await openContextMenuInSidebar();
   let item = contentAreaContextMenu.getElementsByAttribute("label", "Click me!");
   is(item.length, 1, "contextMenu item for page was found");
+
+  item[0].click();
   await closeContextMenu(contentAreaContextMenu);
+  let tab = await extension.awaitMessage("menu-click");
+  is(tab, null, "tab argument is optional, and missing in clicks from sidebars");
 
   await extension.unload();
 });
 
 
 add_task(async function sidebar_contextmenu_hidden_items() {
   let extension = ExtensionTestUtils.loadExtension(extData);
   await extension.startup();