Bug 1615934 - Send tab ID with compose.onBeforeSend event. r=mkmelin a=wsmwk
authorGeoff Lankow <geoff@darktrojan.net>
Mon, 17 Feb 2020 15:51:12 +1300
changeset 38174 685223c79e780fdeef4e14ed48c861e9b8478e2b
parent 38173 ec0a5a8cca852543292b24669975ac1fe54966d9
child 38175 f08f6af8f30b20fc5978e2343aa32295aaa141b4
push id398
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:10:28 +0000
reviewersmkmelin, wsmwk
bugs1615934
Bug 1615934 - Send tab ID with compose.onBeforeSend event. r=mkmelin a=wsmwk
mail/components/extensions/parent/ext-compose.js
mail/components/extensions/schemas/compose.json
mail/components/extensions/test/browser/browser_ext_compose_onBeforeSend.js
--- a/mail/components/extensions/parent/ext-compose.js
+++ b/mail/components/extensions/parent/ext-compose.js
@@ -157,16 +157,17 @@ var composeEventTracker = new (class ext
 
     let msgType = event.detail;
     let composeWindow = event.target;
 
     composeWindow.ToggleWindowLock(true);
 
     let results = await this.emit(
       "compose-before-send",
+      tabTracker.getId(composeWindow),
       getComposeState(composeWindow)
     );
     if (results) {
       for (let result of results) {
         if (!result) {
           continue;
         }
         if (result.cancel) {
@@ -204,18 +205,18 @@ this.compose = class extends ExtensionAP
     let { extension } = context;
     let { tabManager } = extension;
     return {
       compose: {
         onBeforeSend: new EventManager({
           context,
           name: "compose.onBeforeSend",
           register: fire => {
-            let listener = (event, details) => {
-              return fire.async(details);
+            let listener = (event, tabId, details) => {
+              return fire.async(tabId, details);
             };
 
             composeEventTracker.on("compose-before-send", listener);
             return () => {
               composeEventTracker.off("compose-before-send", listener);
             };
           },
         }).api(),
--- a/mail/components/extensions/schemas/compose.json
+++ b/mail/components/extensions/schemas/compose.json
@@ -116,16 +116,21 @@
         "name": "onBeforeSend",
         "type": "function",
         "description": "Fired when a message is about to be sent from the compose window.",
         "permissions": [
           "compose"
         ],
         "parameters": [
           {
+            "type": "integer",
+            "name": "tabId",
+            "minimum": 0
+          },
+          {
             "name": "details",
             "$ref": "ComposeDetails",
             "description": "The current state of the compose window. This is functionally the same as the :ref:`compose.getComposeDetails` function."
           }
         ],
         "returns": {
           "type": "object",
           "properties": {
--- a/mail/components/extensions/test/browser/browser_ext_compose_onBeforeSend.js
+++ b/mail/components/extensions/test/browser/browser_ext_compose_onBeforeSend.js
@@ -62,95 +62,97 @@ add_task(async () => {
         to: ["test@test.invalid"],
         subject: "Test",
       });
       let createdWindow = await createdWindowPromise;
       browser.test.assertEq("messageCompose", createdWindow.type);
 
       await checkWindow({ to: ["test@test.invalid"], subject: "Test" });
 
+      let [tab] = await browser.tabs.query({ windowId: createdWindow.id });
+
       // Send the message. No listeners exist, so sending should continue.
 
       await beginSend(true);
 
       // Add a non-cancelling listener. Sending should continue.
 
-      let listener1 = () => {
-        listener1.fired = true;
+      let listener1 = tabId => {
+        listener1.tabId = tabId;
         return {};
       };
       browser.compose.onBeforeSend.addListener(listener1);
       await beginSend(true);
-      browser.test.assertTrue(listener1.fired, "listener1 was fired");
+      browser.test.assertEq(tab.id, listener1.tabId, "listener1 was fired");
       browser.compose.onBeforeSend.removeListener(listener1);
 
       // Add a cancelling listener. Sending should not continue.
 
-      let listener2 = () => {
-        listener2.fired = true;
+      let listener2 = tabId => {
+        listener2.tabId = tabId;
         return { cancel: true };
       };
       browser.compose.onBeforeSend.addListener(listener2);
       await beginSend(false, false);
-      browser.test.assertTrue(listener2.fired, "listener2 was fired");
+      browser.test.assertEq(tab.id, listener2.tabId, "listener2 was fired");
       browser.compose.onBeforeSend.removeListener(listener2);
       await beginSend(true); // Removing the listener worked.
 
       // Add a listener returning a Promise. Resolve the Promise to unblock.
       // Sending should continue.
 
-      let listener3 = () => {
-        listener3.fired = true;
+      let listener3 = tabId => {
+        listener3.tabId = tabId;
         return new Promise(resolve => {
           listener3.resolve = resolve;
         });
       };
       browser.compose.onBeforeSend.addListener(listener3);
       await beginSend(false, true);
-      browser.test.assertTrue(listener3.fired, "listener3 was fired");
+      browser.test.assertEq(tab.id, listener3.tabId, "listener3 was fired");
       listener3.resolve({ cancel: false });
       await checkIfSent(true);
       browser.compose.onBeforeSend.removeListener(listener3);
 
       // Add a listener returning a Promise. Resolve the Promise to cancel.
       // Sending should not continue.
 
-      let listener4 = () => {
-        listener4.fired = true;
+      let listener4 = tabId => {
+        listener4.tabId = tabId;
         return new Promise(resolve => {
           listener4.resolve = resolve;
         });
       };
       browser.compose.onBeforeSend.addListener(listener4);
       await beginSend(false, true);
-      browser.test.assertTrue(listener4.fired, "listener4 was fired");
+      browser.test.assertEq(tab.id, listener4.tabId, "listener4 was fired");
       listener4.resolve({ cancel: true });
       await checkIfSent(false, false);
       browser.compose.onBeforeSend.removeListener(listener4);
       await beginSend(true); // Removing the listener worked.
 
       // Add a listener that changes the subject. Sending should continue and
       // the subject should change. This is largely the same code as tested in
       // browser_ext_compose_details.js, so just test that the change happens.
 
       // First check that the original headers are unmodified.
       await checkWindow({ to: ["test@test.invalid"], subject: "Test" });
 
-      let listener5 = details => {
-        listener5.fired = true;
+      let listener5 = (tabId, details) => {
+        listener5.tabId = tabId;
         listener5.details = details;
         return {
           details: {
             subject: "Changed by listener5",
           },
         };
       };
       browser.compose.onBeforeSend.addListener(listener5);
       await beginSend(true);
-      browser.test.assertTrue(listener5.fired, "listener5 was fired");
+      browser.test.assertEq(tab.id, listener5.tabId, "listener5 was fired");
       browser.test.assertEq(1, listener5.details.to.length);
       browser.test.assertEq(
         "test@test.invalid",
         listener5.details.to[0],
         "listener5 recipient correct"
       );
       browser.test.assertEq(
         "Test",