Bug 1730931 - Supporting an array of cookieStoreId in the tabs.query API. r=robwu
authorRicha Sharma <onlinericha19@gmail.com>
Tue, 07 Dec 2021 13:46:53 +0000
changeset 601215 10ea0bedb311cb9cf28bd2f494e2c4cea69ca12c
parent 601214 d847e5e30768a6a69bccfc446739c4a9096af47b
child 601216 c6d5703087a2ee156eb56cd492e66f8c9d812189
push id154255
push userrob@robwu.nl
push dateTue, 07 Dec 2021 13:49:18 +0000
treeherderautoland@10ea0bedb311 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobwu
bugs1730931
milestone97.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 1730931 - Supporting an array of cookieStoreId in the tabs.query API. r=robwu Differential Revision: https://phabricator.services.mozilla.com/D125868
browser/components/extensions/schemas/tabs.json
browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
mobile/android/components/extensions/schemas/tabs.json
toolkit/components/extensions/parent/ext-tabs-base.js
--- a/browser/components/extensions/schemas/tabs.json
+++ b/browser/components/extensions/schemas/tabs.json
@@ -765,17 +765,25 @@
               },
               "index": {
                 "type": "integer",
                 "optional": true,
                 "minimum": 0,
                 "description": "The position of the tabs within their windows."
               },
               "cookieStoreId": {
-                "type": "string",
+                "choices": [ 
+                  {
+                    "type": "array",
+                    "items": { "type": "string" }
+                  },
+                  {
+                    "type": "string"
+                  }          
+                ],
                 "optional": true,
                 "description": "The CookieStoreId used for the tab."
               },
               "openerTabId": {
                 "type": "integer",
                 "minimum": 0,
                 "optional": true,
                 "description": "The ID of the tab that opened this tab. If specified, the opener tab must be in the same window as this tab."
--- a/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_cookieStoreId.js
@@ -268,8 +268,61 @@ add_task(async function tabs_query_cooki
       await browser.tabs.remove(tab.id);
       browser.test.sendMessage("done");
     },
   });
   await extension.startup();
   await extension.awaitMessage("done");
   await extension.unload();
 });
+
+add_task(async function tabs_query_multiple_cookiestoreId() {
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      permissions: ["cookies"],
+    },
+
+    async background() {
+      let tab1 = await browser.tabs.create({
+        cookieStoreId: "firefox-container-1",
+      });
+      browser.test.log(`Tab created for cookieStoreId:${tab1.cookieStoreId}`);
+
+      let tab2 = await browser.tabs.create({
+        cookieStoreId: "firefox-container-2",
+      });
+      browser.test.log(`Tab created for cookieStoreId:${tab2.cookieStoreId}`);
+
+      let tab3 = await browser.tabs.create({
+        cookieStoreId: "firefox-container-3",
+      });
+      browser.test.log(`Tab created for cookieStoreId:${tab3.cookieStoreId}`);
+
+      let tabs = await browser.tabs.query({
+        cookieStoreId: ["firefox-container-1", "firefox-container-2"],
+      });
+
+      browser.test.assertEq(
+        2,
+        tabs.length,
+        "Expecting tabs for firefox-container-1 and firefox-container-2"
+      );
+
+      browser.test.assertEq(
+        "firefox-container-1",
+        tabs[0].cookieStoreId,
+        "Expecting tab for firefox-container-1 cookieStoreId"
+      );
+
+      browser.test.assertEq(
+        "firefox-container-2",
+        tabs[1].cookieStoreId,
+        "Expecting tab forfirefox-container-2 cookieStoreId"
+      );
+
+      await browser.tabs.remove([tab1.id, tab2.id, tab3.id]);
+      browser.test.sendMessage("test-done");
+    },
+  });
+  await extension.startup();
+  await extension.awaitMessage("test-done");
+  await extension.unload();
+});
--- a/mobile/android/components/extensions/schemas/tabs.json
+++ b/mobile/android/components/extensions/schemas/tabs.json
@@ -560,17 +560,25 @@
               },
               "index": {
                 "type": "integer",
                 "optional": true,
                 "minimum": 0,
                 "description": "The position of the tabs within their windows."
               },
               "cookieStoreId": {
-                "type": "string",
+                "choices": [ 
+                  {
+                    "type": "array",
+                    "items": { "type": "string" }
+                  },
+                  {
+                    "type": "string"
+                  }          
+                ],
                 "optional": true,
                 "description": "The CookieStoreId used for the tab."
               }
             }
           },
           {
             "type": "function",
             "name": "callback",
--- a/toolkit/components/extensions/parent/ext-tabs-base.js
+++ b/toolkit/components/extensions/parent/ext-tabs-base.js
@@ -550,17 +550,16 @@ class TabBase {
    *
    * @returns {boolean}
    *        True if the tab matches the query.
    */
   matches(queryInfo) {
     const PROPS = [
       "active",
       "audible",
-      "cookieStoreId",
       "discarded",
       "hidden",
       "highlighted",
       "index",
       "openerTabId",
       "pinned",
       "status",
     ];
@@ -586,16 +585,23 @@ class TabBase {
       let match =
         typeof queryInfo.screen == "boolean"
           ? queryInfo.screen === !!state.screen
           : queryInfo.screen === state.screen;
       if (!match) {
         return false;
       }
     }
+
+    if (queryInfo.cookieStoreId) {
+      if (!queryInfo.cookieStoreId.includes(this.cookieStoreId)) {
+        return false;
+      }
+    }
+
     if (queryInfo.url || queryInfo.title) {
       if (!this.hasTabPermission) {
         return false;
       }
       // Using _uri and _title instead of url/title to avoid repeated permission checks.
       if (queryInfo.url && !queryInfo.url.matches(this._uri)) {
         return false;
       }
@@ -2011,16 +2017,20 @@ class TabManagerBase {
   *query(queryInfo = null, context = null) {
     if (queryInfo) {
       if (queryInfo.url !== null) {
         queryInfo.url = parseMatchPatterns([].concat(queryInfo.url), {
           restrictSchemes: false,
         });
       }
 
+      if (queryInfo.cookieStoreId !== null) {
+        queryInfo.cookieStoreId = [].concat(queryInfo.cookieStoreId);
+      }
+
       if (queryInfo.title !== null) {
         try {
           queryInfo.title = new MatchGlob(queryInfo.title);
         } catch (e) {
           throw new ExtensionError(`Invalid title: ${queryInfo.title}`);
         }
       }
     }