B2G/gecko/browser/components/sessionstore/src/SessionStore.jsm
/**
   * Restores the specified tab. If the tab can't be restored (eg, no history or
   * calling gotoIndex fails), then state changes will be rolled back.
   * This method will check if gTabsProgressListener is attached to the tab's
   * window, ensuring that we don't get caught without one.
   * This method removes the session history listener right before starting to
   * attempt a load. This will prevent cases of "stuck" listeners.
   * If this method returns false, then it is up to the caller to decide what to
   * do. In the common case (restoreNextTab), we will want to then attempt to
   * restore the next tab. In the other case (selecting the tab, reloading the
   * tab), the caller doesn't actually want to do anything if no page is loaded.
   *
   * @param aTab
   *        the tab to restore
   *
   * @returns true/false indicating whether or not a load actually happened
   */
Restores the specified tab. If the tab can't be restored , then state changes will be rolled back.
This method will check if gTabsProgressListener is attached to the tab's
window, ensuring that we don't get caught without one.
This method removes the session history listener right before starting to
attempt a load. This will prevent cases of "stuck" listeners.
If this method returns false, then it is up to the caller to decide what to
do. In the common case (restoreNextTab), we will want to then attempt to
restore the next tab. In the other case (selecting the tab, reloading the
tab), the caller doesn't actually want to do anything if no page is loaded.

@param aTab
the tab to restore

@returns true/false indicating whether or not a load actually happened
Restores the specified tab . If the tab can ' t be restored then state changes will be rolled back . This method will check if gTabsProgressListener is attached to the tab ' s window ensuring that we don ' t get caught without one . This method removes the session history listener right before starting to attempt a load . This will prevent cases of " stuck " listeners . If this method returns false then it is up to the caller to decide what to do . In the common case ( restoreNextTab ) we will want to then attempt to restore the next tab . In the other case ( selecting the tab reloading the tab ) the caller doesn ' t actually want to do anything if no page is loaded . @param aTab the tab to restore @returns true / false indicating whether or not a load actually happened
function ssi_restoreTab(aTab) {
    let window = aTab.ownerDocument.defaultView;
    let browser = aTab.linkedBrowser;
    let tabData = browser.__SS_data;
    let didStartLoad = false;
    this._ensureTabsProgressListener(window);
    this._removeTabFromTabsToRestore(aTab);
    this._tabsRestoringCount++;
    browser.__SS_restoreState = TAB_STATE_RESTORING;
    aTab.removeAttribute("pending");
    this._removeSHistoryListener(aTab);
    let activeIndex = (tabData.index || tabData.entries.length) - 1;
    if (activeIndex >= tabData.entries.length)
      activeIndex = tabData.entries.length - 1;
    browser.webNavigation.setCurrentURI(this._getURIFromString("about:blank"));
    if (activeIndex > -1) {
      browser.__SS_restore_data = tabData.entries[activeIndex] || {};
      browser.__SS_restore_pageStyle = tabData.pageStyle || "";
      browser.__SS_restore_tab = aTab;
      didStartLoad = true;
      try {
        browser.webNavigation.sessionHistory.getEntryAtIndex(activeIndex, true);
        browser.webNavigation.sessionHistory.reloadCurrentEntry();
      }
      catch (ex) {
        aTab.removeAttribute("busy");
        didStartLoad = false;
      }
    }
    if (tabData.userTypedValue) {
      browser.userTypedValue = tabData.userTypedValue;
      if (tabData.userTypedClear) {
        browser.__SS_restore_data = { url: null };
        browser.__SS_restore_tab = aTab;
        if (didStartLoad)
          browser.stop();
        didStartLoad = true;
        browser.loadURIWithFlags(tabData.userTypedValue,
                                 Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP);
      }
    }
    if (!didStartLoad) {
      this._sendTabRestoredNotification(aTab);
      this._resetTabRestoringState(aTab);
    }
    return didStartLoad;
  }
function ssi_restoreTab ( aTab ) { let window = aTab . ownerDocument . defaultView ; let browser = aTab . linkedBrowser ; let tabData = browser . __SS_data ; let didStartLoad = false ; this . _ensureTabsProgressListener ( window ) ; this . _removeTabFromTabsToRestore ( aTab ) ; this . _tabsRestoringCount ++ ; browser . __SS_restoreState = TAB_STATE_RESTORING ; aTab . removeAttribute ( "pending" ) ; this . _removeSHistoryListener ( aTab ) ; let activeIndex = ( tabData . index || tabData . entries . length ) - 1 ; if ( activeIndex >= tabData . entries . length ) activeIndex = tabData . entries . length - 1 ; browser . webNavigation . setCurrentURI ( this . _getURIFromString ( "about:blank" ) ) ; if ( activeIndex > - 1 ) { browser . __SS_restore_data = tabData . entries [ activeIndex ] || { } ; browser . __SS_restore_pageStyle = tabData . pageStyle || "" ; browser . __SS_restore_tab = aTab ; didStartLoad = true ; try { browser . webNavigation . sessionHistory . getEntryAtIndex ( activeIndex , true ) ; browser . webNavigation . sessionHistory . reloadCurrentEntry ( ) ; } catch ( ex ) { aTab . removeAttribute ( "busy" ) ; didStartLoad = false ; } } if ( tabData . userTypedValue ) { browser . userTypedValue = tabData . userTypedValue ; if ( tabData . userTypedClear ) { browser . __SS_restore_data = { url : null } ; browser . __SS_restore_tab = aTab ; if ( didStartLoad ) browser . stop ( ) ; didStartLoad = true ; browser . loadURIWithFlags ( tabData . userTypedValue , Ci . nsIWebNavigation . LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP ) ; } } if ( ! didStartLoad ) { this . _sendTabRestoredNotification ( aTab ) ; this . _resetTabRestoringState ( aTab ) ; } return didStartLoad ; }
Restores the specified tab.
Restores the specified tab .
// There are cases within where we haven't actually started a load. In that // that case we'll reset state changes we made and return false to the caller // can handle appropriately. // Make sure that the tabs progress listener is attached to this window // Make sure that this tab is removed from _tabsToRestore // Increase our internal count. // Set this tab's state to restoring // Remove the history listener, since we no longer need it once we start restoring // Reset currentURI.  This creates a new session history entry with a new // doc identifier, so we need to explicitly save and restore the old doc // identifier (corresponding to the SHEntry at activeIndex) below. // Attach data that will be restored on "load" event, after tab is restored. // restore those aspects of the currently active documents which are not // preserved in the plain history entries (mainly scroll state and text data) // In order to work around certain issues in session history, we need to // force session history to update its internal index and call reload // instead of gotoIndex. See bug 597315. // ignore page load errors // Handle userTypedValue. Setting userTypedValue seems to update gURLbar // as needed. Calling loadURI will cancel form filling in restoreDocument // Make it so that we'll enter restoreDocument on page load. We will // fire SSTabRestored from there. We don't have any form data to restore // so we can just set the URL to null. // If we didn't start a load, then we won't reset this tab through the usual // channel (via the progress listener), so reset the tab ourselves. We will // also send SSTabRestored since this tab has technically been restored.