Bug 1489814 - Add 'populate' parameter in 'tabs.highlight'. r=mixedpuppy a=pascalc
authorOriol Brufau <oriol-bugzilla@hotmail.com>
Fri, 05 Oct 2018 13:42:33 +0000
changeset 492873 253f11fbc824e50ded7fa9d1e6fb5046e0e86188
parent 492872 de127662180d7e2798660e75cee75523fdd056dd
child 492874 f997cf948ca01fc193119c3219fc35926fb8eb8e
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy, pascalc
bugs1489814
milestone63.0
Bug 1489814 - Add 'populate' parameter in 'tabs.highlight'. r=mixedpuppy a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D7240
browser/components/extensions/parent/ext-tabs.js
browser/components/extensions/schemas/tabs.json
browser/components/extensions/test/browser/browser_ext_tabs_highlight.js
--- a/browser/components/extensions/parent/ext-tabs.js
+++ b/browser/components/extensions/parent/ext-tabs.js
@@ -1300,32 +1300,32 @@ this.tabs = class extends ExtensionAPI {
           }
           return hidden;
         },
 
         highlight(highlightInfo) {
           if (!gMultiSelectEnabled) {
             throw new ExtensionError(`tabs.highlight is currently experimental and must be enabled with the ${MULTISELECT_PREFNAME} preference.`);
           }
-          let {windowId, tabs} = highlightInfo;
+          let {windowId, tabs, populate} = highlightInfo;
           if (windowId == null) {
             windowId = Window.WINDOW_ID_CURRENT;
           }
           let window = windowTracker.getWindow(windowId, context);
           if (!Array.isArray(tabs)) {
             tabs = [tabs];
           } else if (tabs.length == 0) {
             throw new ExtensionError("No highlighted tab.");
           }
           window.gBrowser.selectedTabs = tabs.map((tabIndex) => {
             let tab = window.gBrowser.tabs[tabIndex];
             if (!tab) {
               throw new ExtensionError("No tab at index: " + tabIndex);
             }
             return tab;
           });
-          return windowManager.convert(window, {populate: true});
+          return windowManager.convert(window, {populate});
         },
       },
     };
     return self;
   }
 };
--- a/browser/components/extensions/schemas/tabs.json
+++ b/browser/components/extensions/schemas/tabs.json
@@ -795,16 +795,22 @@
             "name": "highlightInfo",
             "properties": {
                "windowId": {
                  "type": "integer",
                  "optional": true,
                  "description": "The window that contains the tabs.",
                  "minimum": -2
                },
+               "populate": {
+                 "type": "boolean",
+                 "optional": true,
+                 "default": true,
+                 "description": "If true, the $(ref:windows.Window) returned will have a <var>tabs</var> property that contains a list of the $(ref:tabs.Tab) objects. The <code>Tab</code> objects only contain the <code>url</code>, <code>title</code> and <code>favIconUrl</code> properties if the extension's manifest file includes the <code>\"tabs\"</code> permission. If false, the $(ref:windows.Window) won't have the <var>tabs</var> property."
+               },
                "tabs": {
                  "description": "One or more tab indices to highlight.",
                  "choices": [
                    {"type": "array", "items": {"type": "integer", "minimum": 0}},
                    {"type": "integer"}
                  ]
                }
              }
--- a/browser/components/extensions/test/browser/browser_ext_tabs_highlight.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_highlight.js
@@ -63,16 +63,19 @@ add_task(async function test_highlighted
       await testHighlighted(1, [0]);
 
       browser.test.log("Highlight last tab");
       let window = await browser.tabs.highlight({tabs: 2});
       await testHighlighted(2, []);
 
       browser.test.assertEq(3, window.tabs.length, "Returned window should be populated");
 
+      window = await browser.tabs.highlight({tabs: 2, populate: false});
+      browser.test.assertFalse("tabs" in window, "Returned window shouldn't be populated");
+
       browser.test.notifyPass("test-finished");
     },
   });
 
   let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com/");
   let tab2 = await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.com/");
 
   await extension.startup();