Bug 1615934 - Send tab ID with composeAction.onClicked event. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 17 Feb 2020 15:55:31 +1300
changeset 37373 80f6ca1e8ac7b52f9181b0ffe74518b86f30e56a
parent 37372 2996d7ac481a5afe5dda71ced6a2109f71051a83
child 37374 f7de7594255dd0e01891014614643002988a59f7
push id2566
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:20:31 +0000
treeherdercomm-beta@a352facfa0a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1615934
Bug 1615934 - Send tab ID with composeAction.onClicked event. r=mkmelin
mail/components/extensions/parent/ext-composeAction.js
mail/components/extensions/schemas/composeAction.json
mail/components/extensions/test/browser/browser_ext_composeAction.js
--- a/mail/components/extensions/parent/ext-composeAction.js
+++ b/mail/components/extensions/parent/ext-composeAction.js
@@ -62,9 +62,33 @@ this.composeAction = class extends Toolb
       Services.xulStore.setValue(
         windowURL,
         "composeToolbar2",
         "currentset",
         currentSet.join(",")
       );
     }
   }
+
+  getAPI(context) {
+    let { extension } = context;
+    let { windowManager } = extension;
+
+    let action = this;
+    let api = super.getAPI(context);
+    api.composeAction.onClicked = new EventManager({
+      context,
+      name: "composeAction.onClicked",
+      inputHandling: true,
+      register: fire => {
+        let listener = (event, window) => {
+          let win = windowManager.wrapWindow(window);
+          fire.sync(win.activeTab.id);
+        };
+        action.on("click", listener);
+        return () => {
+          action.off("click", listener);
+        };
+      },
+    }).api();
+    return api;
+  }
 };
--- a/mail/components/extensions/schemas/composeAction.json
+++ b/mail/components/extensions/schemas/composeAction.json
@@ -406,13 +406,18 @@
       }
     ],
     "events": [
       {
         "name": "onClicked",
         "type": "function",
         "description": "Fired when a toolbar action icon is clicked.  This event will not fire if the toolbar action has a popup.",
         "parameters": [
+          {
+            "name": "tabId",
+            "type": "integer",
+            "minimum": 1
+          }
         ]
       }
     ]
   }
 ]
--- a/mail/components/extensions/test/browser/browser_ext_composeAction.js
+++ b/mail/components/extensions/test/browser/browser_ext_composeAction.js
@@ -123,17 +123,18 @@ add_task(async function setup() {
 
   window.gFolderTreeView.selectFolder(rootFolder);
   await new Promise(resolve => executeSoon(resolve));
 });
 
 add_task(async function the_test() {
   async function background_nopopup() {
     browser.test.log("nopopup background script ran");
-    browser.composeAction.onClicked.addListener(async () => {
+    browser.composeAction.onClicked.addListener(async tabId => {
+      browser.test.log(`tabId is ${tabId}`);
       await browser.composeAction.setTitle({ title: "New title" });
       await new Promise(setTimeout);
       browser.test.sendMessage("composeAction");
     });
 
     browser.test.sendMessage();
   }