B2G/gecko/browser/components/privatebrowsing/src/nsPrivateBrowsingService.js
/**
   * Enter or leave private browsing mode.
   */
Enter or leave private browsing mode.
Enter or leave private browsing mode .
set privateBrowsingEnabled(val) {
    if (this._currentStatus != STATE_IDLE)
      throw Cr.NS_ERROR_FAILURE;
    if (val == this._inPrivateBrowsing)
      return;
    try {
      if (val) {
        if (!this._canEnterPrivateBrowsingMode())
          return;
      }
      else {
        if (!this._canLeavePrivateBrowsingMode())
          return;
      }
      this._ensureCanCloseWindows();
      this._currentStatus = STATE_TRANSITION_STARTED;
      this._autoStarted = this._prefs.getBoolPref("browser.privatebrowsing.autostart");
      this._inPrivateBrowsing = val != false;
      this._recordTransitionTime("started");
      let data = val ? "enter" : "exit";
      let quitting = Cc["@mozilla.org/supports-PRBool;1"].
                     createInstance(Ci.nsISupportsPRBool);
      quitting.data = this._quitting;
      this._obs.notifyObservers(quitting, "private-browsing-change-granted", data);
      this._onBeforePrivateBrowsingModeChange();
      this._obs.notifyObservers(quitting, "private-browsing", data);
      this._recordTransitionTime("prepared");
      this._onAfterPrivateBrowsingModeChange();
    } catch (ex) {
      for (let i = 0; i < this._windowsToClose.length; i++)
        this._windowsToClose[i].docShell.contentViewer.resetCloseWindow();
      if (ex != Cr.NS_ERROR_ABORT)
        Cu.reportError("Exception thrown while processing the " +
          "private browsing mode change request: " + ex.toString());
    } finally {
      this._windowsToClose = [];
      this._notifyIfTransitionComplete();
      this._lastChangedByCommandLine = false;
    }
  }
set privateBrowsingEnabled ( val ) { if ( this . _currentStatus != STATE_IDLE ) throw Cr . NS_ERROR_FAILURE ; if ( val == this . _inPrivateBrowsing ) return ; try { if ( val ) { if ( ! this . _canEnterPrivateBrowsingMode ( ) ) return ; } else { if ( ! this . _canLeavePrivateBrowsingMode ( ) ) return ; } this . _ensureCanCloseWindows ( ) ; this . _currentStatus = STATE_TRANSITION_STARTED ; this . _autoStarted = this . _prefs . getBoolPref ( "browser.privatebrowsing.autostart" ) ; this . _inPrivateBrowsing = val != false ; this . _recordTransitionTime ( "started" ) ; let data = val ? "enter" : "exit" ; let quitting = Cc [ "@mozilla.org/supports-PRBool;1" ] . createInstance ( Ci . nsISupportsPRBool ) ; quitting . data = this . _quitting ; this . _obs . notifyObservers ( quitting , "private-browsing-change-granted" , data ) ; this . _onBeforePrivateBrowsingModeChange ( ) ; this . _obs . notifyObservers ( quitting , "private-browsing" , data ) ; this . _recordTransitionTime ( "prepared" ) ; this . _onAfterPrivateBrowsingModeChange ( ) ; } catch ( ex ) { for ( let i = 0 ; i < this . _windowsToClose . length ; i ++ ) this . _windowsToClose [ i ] . docShell . contentViewer . resetCloseWindow ( ) ; if ( ex != Cr . NS_ERROR_ABORT ) Cu . reportError ( "Exception thrown while processing the " + "private browsing mode change request: " + ex . toString ( ) ) ; } finally { this . _windowsToClose = [ ] ; this . _notifyIfTransitionComplete ( ) ; this . _lastChangedByCommandLine = false ; } }
Enter or leave private browsing mode.
Enter or leave private browsing mode .
// Allowing observers to set the private browsing status from their // notification handlers is not desired, because it will change the // status of the service while it's in the process of another transition. // So, we detect a reentrant call here and throw an error. // This is documented in nsIPrivateBrowsingService.idl. // start the transition now that we know that we can // notify observers of the pending private browsing mode change // destroy the current session and start initial cleanup // load the appropriate session // We aborted the transition to/from private browsing, we must restore the // beforeunload handling on all the windows for which we switched it off. // We don't log an error when the transition is canceled from beforeunload