Bug 1479031 - Use destructuring assignment for optional loadTabs parameters. draft
authorDão Gottwald <dao@mozilla.com>
Fri, 27 Jul 2018 19:00:40 +0200
changeset 823579 f531bb618719c81b691914fbe4e44a0b7af13791
parent 823465 87bcafe428a4ad6017e59b915581ae00aa863407
push id117734
push userdgottwald@mozilla.com
push dateFri, 27 Jul 2018 17:01:05 +0000
bugs1479031
milestone63.0a1
Bug 1479031 - Use destructuring assignment for optional loadTabs parameters. MozReview-Commit-ID: FMRObafFcS9
browser/base/content/tabbrowser.js
browser/base/content/test/performance/head.js
browser/base/content/test/tabs/browser_new_tab_insert_position.js
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -1398,123 +1398,119 @@ window._gBrowser = {
       name: aName
     });
     if (!bgLoad)
       this.selectedTab = tab;
 
     return tab;
   },
 
-  loadTabs(aURIs, aLoadInBackground, aReplace) {
-    let aTriggeringPrincipal;
-    let aAllowThirdPartyFixup;
-    let aTargetTab;
-    let aNewIndex = -1;
-    let aPostDatas = [];
-    let aUserContextId;
-    if (arguments.length == 2 &&
-        typeof arguments[1] == "object") {
-      let params = arguments[1];
-      aLoadInBackground = params.inBackground;
-      aReplace = params.replace;
-      aAllowThirdPartyFixup = params.allowThirdPartyFixup;
-      aTargetTab = params.targetTab;
-      aNewIndex = typeof params.newIndex === "number" ?
-        params.newIndex : aNewIndex;
-      aPostDatas = params.postDatas || aPostDatas;
-      aUserContextId = params.userContextId;
-      aTriggeringPrincipal = params.triggeringPrincipal;
-    }
-
-    if (!aURIs.length)
+  loadTabs(aURIs, {
+    allowThirdPartyFixup,
+    inBackground,
+    newIndex,
+    postDatas,
+    replace,
+    targetTab,
+    triggeringPrincipal,
+    userContextId,
+  } = {}) {
+    if (!aURIs.length) {
       return;
+    }
 
     // The tab selected after this new tab is closed (i.e. the new tab's
     // "owner") is the next adjacent tab (i.e. not the previously viewed tab)
     // when several urls are opened here (i.e. closing the first should select
     // the next of many URLs opened) or if the pref to have UI links opened in
     // the background is set (i.e. the link is not being opened modally)
     //
     // i.e.
     //    Number of URLs    Load UI Links in BG       Focus Last Viewed?
     //    == 1              false                     YES
     //    == 1              true                      NO
     //    > 1               false/true                NO
     var multiple = aURIs.length > 1;
-    var owner = multiple || aLoadInBackground ? null : this.selectedTab;
+    var owner = multiple || inBackground ? null : this.selectedTab;
     var firstTabAdded = null;
     var targetTabIndex = -1;
 
+    if (typeof newIndex != "number") {
+      newIndex = -1;
+    }
+
     // When bulk opening tabs, such as from a bookmark folder, we want to insertAfterCurrent
     // if necessary, but we also will set the bulkOrderedOpen flag so that the bookmarks
     // open in the same order they are in the folder.
-    if (multiple && aNewIndex < 0 && Services.prefs.getBoolPref("browser.tabs.insertAfterCurrent")) {
-      aNewIndex = this.selectedTab._tPos + 1;
-    }
-
-    if (aReplace) {
+    if (multiple &&
+        newIndex < 0 &&
+        Services.prefs.getBoolPref("browser.tabs.insertAfterCurrent")) {
+      newIndex = this.selectedTab._tPos + 1;
+    }
+
+    if (replace) {
       let browser;
-      if (aTargetTab) {
-        browser = this.getBrowserForTab(aTargetTab);
-        targetTabIndex = aTargetTab._tPos;
+      if (targetTab) {
+        browser = this.getBrowserForTab(targetTab);
+        targetTabIndex = targetTab._tPos;
       } else {
         browser = this.selectedBrowser;
         targetTabIndex = this.tabContainer.selectedIndex;
       }
       let flags = Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
-      if (aAllowThirdPartyFixup) {
+      if (allowThirdPartyFixup) {
         flags |= Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP |
           Ci.nsIWebNavigation.LOAD_FLAGS_FIXUP_SCHEME_TYPOS;
       }
       try {
         browser.loadURI(aURIs[0], {
           flags,
-          postData: aPostDatas[0],
-          triggeringPrincipal: aTriggeringPrincipal,
+          postData: postDatas && postDatas[0],
+          triggeringPrincipal,
         });
       } catch (e) {
         // Ignore failure in case a URI is wrong, so we can continue
         // opening the next ones.
       }
     } else {
       let params = {
         ownerTab: owner,
         skipAnimation: multiple,
-        allowThirdPartyFixup: aAllowThirdPartyFixup,
-        postData: aPostDatas[0],
-        userContextId: aUserContextId,
-        triggeringPrincipal: aTriggeringPrincipal,
+        allowThirdPartyFixup,
+        postData: postDatas && postDatas[0],
+        userContextId,
+        triggeringPrincipal,
         bulkOrderedOpen: multiple,
       };
-      if (aNewIndex > -1) {
-        params.index = aNewIndex;
+      if (newIndex > -1) {
+        params.index = newIndex;
       }
       firstTabAdded = this.addTab(aURIs[0], params);
-      if (aNewIndex > -1) {
+      if (newIndex > -1) {
         targetTabIndex = firstTabAdded._tPos;
       }
     }
 
     let tabNum = targetTabIndex;
     for (let i = 1; i < aURIs.length; ++i) {
       let params = {
         skipAnimation: true,
-        allowThirdPartyFixup: aAllowThirdPartyFixup,
-        postData: aPostDatas[i],
-        userContextId: aUserContextId,
-        triggeringPrincipal: aTriggeringPrincipal,
+        allowThirdPartyFixup,
+        postData: postDatas && postDatas[i],
+        userContextId,
+        triggeringPrincipal,
         bulkOrderedOpen: true,
       };
       if (targetTabIndex > -1) {
         params.index = ++tabNum;
       }
       this.addTab(aURIs[i], params);
     }
 
-    if (firstTabAdded && !aLoadInBackground) {
+    if (firstTabAdded && !inBackground) {
       this.selectedTab = firstTabAdded;
     }
   },
 
   updateBrowserRemoteness(aBrowser, aShouldBeRemote, {
     newFrameloader,
     opener,
     remoteType,
--- a/browser/base/content/test/performance/head.js
+++ b/browser/base/content/test/performance/head.js
@@ -300,17 +300,17 @@ function computeMaxTabCount() {
  *        How many about:blank tabs to open.
  */
 async function createTabs(howMany) {
   let uris = [];
   while (howMany--) {
     uris.push("about:blank");
   }
 
-  gBrowser.loadTabs(uris, true, false);
+  gBrowser.loadTabs(uris, { inBackground: true });
 
   await BrowserTestUtils.waitForCondition(() => {
     return Array.from(gBrowser.tabs).every(tab => tab._fullyOpen);
   });
 }
 
 /**
  * Removes all of the tabs except the originally selected
--- a/browser/base/content/test/tabs/browser_new_tab_insert_position.js
+++ b/browser/base/content/test/tabs/browser_new_tab_insert_position.js
@@ -149,17 +149,17 @@ async function doTest(aInsertRelatedAfte
   verifyTabState(newState);
 
   // Bug 1442679 - Test bulk opening with loadTabs loads the tabs in order
 
   let loadPromises = Promise.all(bulkLoad.map(url => BrowserTestUtils.waitForNewTab(gBrowser, url, false, true)));
   // loadTabs will insertAfterCurrent
   let nextTab = aInsertAfterCurrent ? gBrowser.selectedTab._tPos + 1 : gBrowser.tabs.length;
 
-  gBrowser.loadTabs(bulkLoad, true);
+  gBrowser.loadTabs(bulkLoad, { inBackground: true });
   await loadPromises;
   for (let i = nextTab, j = 0; j < bulkLoad.length; i++, j++) {
     is(gBrowser.tabs[i].linkedBrowser.currentURI.spec, bulkLoad[j], `bulkLoad tab pos ${i} matched`);
   }
 
   // Now we want to test that positioning remains correct after a session restore.
 
   // Restore pre-test state so we can restore and test tab ordering.