B2G/gecko/browser/components/sessionstore/src/SessionStore.jsm
/**
   * Sets the tabs restoring order with the following priority:
   * Selected tab, pinned tabs, optimized visible tabs, other visible tabs and
   * hidden tabs.
   * @param aTabBrowser
   *        Tab browser object
   * @param aTabs
   *        Array of tab references
   * @param aTabData
   *        Array of tab data
   * @param aSelectedTab
   *        Index of selected tab (1 is first tab, 0 no selected tab)
   */
Sets the tabs restoring order with the following priority:
Selected tab, pinned tabs, optimized visible tabs, other visible tabs and
hidden tabs.
@param aTabBrowser
Tab browser object
@param aTabs
Array of tab references
@param aTabData
Array of tab data
@param aSelectedTab
Index of selected tab (1 is first tab, 0 no selected tab)
Sets the tabs restoring order with the following priority : Selected tab pinned tabs optimized visible tabs other visible tabs and hidden tabs . @param aTabBrowser Tab browser object @param aTabs Array of tab references @param aTabData Array of tab data @param aSelectedTab Index of selected tab ( 1 is first tab 0 no selected tab )
function ssi__setTabsRestoringOrder(
    aTabBrowser, aTabs, aTabData, aSelectedTab) {
    let selectedTab;
    if (aSelectedTab > 0 && aTabs[aSelectedTab - 1]) {
      selectedTab = aTabs[aSelectedTab - 1];
    }
    let pinnedTabs = [];
    let pinnedTabsData = [];
    let hiddenTabs = [];
    let hiddenTabsData = [];
    if (aTabs.length > 1) {
      for (let t = aTabs.length - 1; t >= 0; t--) {
        if (aTabData[t].pinned) {
          pinnedTabs.unshift(aTabs.splice(t, 1)[0]);
          pinnedTabsData.unshift(aTabData.splice(t, 1)[0]);
        } else if (aTabData[t].hidden) {
          hiddenTabs.unshift(aTabs.splice(t, 1)[0]);
          hiddenTabsData.unshift(aTabData.splice(t, 1)[0]);
        }
      }
    }
    if (selectedTab) {
      let selectedTabIndex = aTabs.indexOf(selectedTab);
      if (selectedTabIndex > 0) {
        let scrollSize = aTabBrowser.tabContainer.mTabstrip.scrollClientSize;
        let tabWidth = aTabs[0].getBoundingClientRect().width;
        let maxVisibleTabs = Math.ceil(scrollSize / tabWidth);
        if (maxVisibleTabs < aTabs.length) {
          let firstVisibleTab = 0;
          let nonVisibleTabsCount = aTabs.length - maxVisibleTabs;
          if (nonVisibleTabsCount >= selectedTabIndex) {
            firstVisibleTab = selectedTabIndex;
          } else {
            firstVisibleTab = nonVisibleTabsCount;
          }
          aTabs = aTabs.splice(firstVisibleTab, maxVisibleTabs).concat(aTabs);
          aTabData =
            aTabData.splice(firstVisibleTab, maxVisibleTabs).concat(aTabData);
        }
      }
    }
    aTabs = pinnedTabs.concat(aTabs, hiddenTabs);
    aTabData = pinnedTabsData.concat(aTabData, hiddenTabsData);
    if (selectedTab) {
      let selectedTabIndex = aTabs.indexOf(selectedTab);
      if (selectedTabIndex > 0) {
        aTabs = aTabs.splice(selectedTabIndex, 1).concat(aTabs);
        aTabData = aTabData.splice(selectedTabIndex, 1).concat(aTabData);
      }
      aTabBrowser.selectedTab = selectedTab;
    }
    return [aTabs, aTabData];
  }
function ssi__setTabsRestoringOrder ( aTabBrowser , aTabs , aTabData , aSelectedTab ) { let selectedTab ; if ( aSelectedTab > 0 && aTabs [ aSelectedTab - 1 ] ) { selectedTab = aTabs [ aSelectedTab - 1 ] ; } let pinnedTabs = [ ] ; let pinnedTabsData = [ ] ; let hiddenTabs = [ ] ; let hiddenTabsData = [ ] ; if ( aTabs . length > 1 ) { for ( let t = aTabs . length - 1 ; t >= 0 ; t -- ) { if ( aTabData [ t ] . pinned ) { pinnedTabs . unshift ( aTabs . splice ( t , 1 ) [ 0 ] ) ; pinnedTabsData . unshift ( aTabData . splice ( t , 1 ) [ 0 ] ) ; } else if ( aTabData [ t ] . hidden ) { hiddenTabs . unshift ( aTabs . splice ( t , 1 ) [ 0 ] ) ; hiddenTabsData . unshift ( aTabData . splice ( t , 1 ) [ 0 ] ) ; } } } if ( selectedTab ) { let selectedTabIndex = aTabs . indexOf ( selectedTab ) ; if ( selectedTabIndex > 0 ) { let scrollSize = aTabBrowser . tabContainer . mTabstrip . scrollClientSize ; let tabWidth = aTabs [ 0 ] . getBoundingClientRect ( ) . width ; let maxVisibleTabs = Math . ceil ( scrollSize / tabWidth ) ; if ( maxVisibleTabs < aTabs . length ) { let firstVisibleTab = 0 ; let nonVisibleTabsCount = aTabs . length - maxVisibleTabs ; if ( nonVisibleTabsCount >= selectedTabIndex ) { firstVisibleTab = selectedTabIndex ; } else { firstVisibleTab = nonVisibleTabsCount ; } aTabs = aTabs . splice ( firstVisibleTab , maxVisibleTabs ) . concat ( aTabs ) ; aTabData = aTabData . splice ( firstVisibleTab , maxVisibleTabs ) . concat ( aTabData ) ; } } } aTabs = pinnedTabs . concat ( aTabs , hiddenTabs ) ; aTabData = pinnedTabsData . concat ( aTabData , hiddenTabsData ) ; if ( selectedTab ) { let selectedTabIndex = aTabs . indexOf ( selectedTab ) ; if ( selectedTabIndex > 0 ) { aTabs = aTabs . splice ( selectedTabIndex , 1 ) . concat ( aTabs ) ; aTabData = aTabData . splice ( selectedTabIndex , 1 ) . concat ( aTabData ) ; } aTabBrowser . selectedTab = selectedTab ; } return [ aTabs , aTabData ] ; }
Sets the tabs restoring order with the following priority:
 Selected tab, pinned tabs, optimized visible tabs, other visible tabs and
 hidden tabs.
Sets the tabs restoring order with the following priority : Selected tab pinned tabs optimized visible tabs other visible tabs and hidden tabs .
// Store the selected tab. Need to substract one to get the index in aTabs. // Store the pinned tabs and hidden tabs. // Optimize the visible tabs only if there is a selected tab. // Selected tab is leftmost since we scroll to it when possible. // Selected tab is rightmost or no more room to scroll right. // Merge the stored tabs in order. // Load the selected tab to the first position and select it.