B2G/gecko/browser/components/sessionstore/src/SessionStore.jsm
/**
   * See if aWindow is usable for use when restoring a previous session via
   * restoreLastSession. If usable, prepare it for use.
   *
   * @param aWindow
   *        the window to inspect & prepare
   * @returns [canUseWindow, canOverwriteTabs]
   *          canUseWindow: can the window be used to restore into
   *          canOverwriteTabs: all of the current tabs are home pages and we
   *                            can overwrite them
   */
See if aWindow is usable for use when restoring a previous session via
restoreLastSession. If usable, prepare it for use.

@param aWindow
the window to inspect & prepare
@returns [canUseWindow, canOverwriteTabs]
canUseWindow: can the window be used to restore into
canOverwriteTabs: all of the current tabs are home pages and we
can overwrite them
See if aWindow is usable for use when restoring a previous session via restoreLastSession . If usable prepare it for use . @param aWindow the window to inspect & prepare @returns [ canUseWindow canOverwriteTabs ] canUseWindow : can the window be used to restore into canOverwriteTabs : all of the current tabs are home pages and we can overwrite them
function ssi_prepWindowToRestoreInto(aWindow) {
    if (!aWindow)
      return [false, false];
    let canOverwriteTabs = false;
    let groupsData = this.getWindowValue(aWindow, "tabview-groups");
    if (groupsData) {
      groupsData = JSON.parse(groupsData);
      if (groupsData.totalNumber > 1)
        return [false, false];
    }
    let homePages = ["about:blank"];
    let removableTabs = [];
    let tabbrowser = aWindow.gBrowser;
    let normalTabsLen = tabbrowser.tabs.length - tabbrowser._numPinnedTabs;
    let startupPref = this._prefBranch.getIntPref("startup.page");
    if (startupPref == 1)
      homePages = homePages.concat(aWindow.gHomeButton.getHomePage().split("|"));
    for (let i = tabbrowser._numPinnedTabs; i < tabbrowser.tabs.length; i++) {
      let tab = tabbrowser.tabs[i];
      if (homePages.indexOf(tab.linkedBrowser.currentURI.spec) != -1) {
        removableTabs.push(tab);
      }
    }
    if (tabbrowser.tabs.length == removableTabs.length) {
      canOverwriteTabs = true;
    }
    else {
      for (let i = removableTabs.length - 1; i >= 0; i--) {
        tabbrowser.removeTab(removableTabs.pop(), { animate: false });
      }
    }
    return [true, canOverwriteTabs];
  }
function ssi_prepWindowToRestoreInto ( aWindow ) { if ( ! aWindow ) return [ false , false ] ; let canOverwriteTabs = false ; let groupsData = this . getWindowValue ( aWindow , "tabview-groups" ) ; if ( groupsData ) { groupsData = JSON . parse ( groupsData ) ; if ( groupsData . totalNumber > 1 ) return [ false , false ] ; } let homePages = [ "about:blank" ] ; let removableTabs = [ ] ; let tabbrowser = aWindow . gBrowser ; let normalTabsLen = tabbrowser . tabs . length - tabbrowser . _numPinnedTabs ; let startupPref = this . _prefBranch . getIntPref ( "startup.page" ) ; if ( startupPref == 1 ) homePages = homePages . concat ( aWindow . gHomeButton . getHomePage ( ) . split ( "|" ) ) ; for ( let i = tabbrowser . _numPinnedTabs ; i < tabbrowser . tabs . length ; i ++ ) { let tab = tabbrowser . tabs [ i ] ; if ( homePages . indexOf ( tab . linkedBrowser . currentURI . spec ) != - 1 ) { removableTabs . push ( tab ) ; } } if ( tabbrowser . tabs . length == removableTabs . length ) { canOverwriteTabs = true ; } else { for ( let i = removableTabs . length - 1 ; i >= 0 ; i -- ) { tabbrowser . removeTab ( removableTabs . pop ( ) , { animate : false } ) ; } } return [ true , canOverwriteTabs ] ; }
See if aWindow is usable for use when restoring a previous session via
 restoreLastSession.
See if aWindow is usable for use when restoring a previous session via restoreLastSession .
// We might be able to overwrite the existing tabs instead of just adding // the previous session's tabs to the end. This will be set if possible. // Step 1 of processing: // Inspect extData for Panorama identifiers. If found, then we want to // inspect further. If there is a single group, then we can use this // window. If there are multiple groups then we won't use this window. // If there are multiple groups, we don't want to use this window. // Step 2 of processing: // If we're still here, then the window is usable. Look at the open tabs in // comparison to home pages. If all the tabs are home pages then we'll end // up overwriting all of them. Otherwise we'll just close the tabs that // match home pages. Tabs with the about:blank URI will always be // overwritten. // If we're not overwriting all of the tabs, then close the home tabs.