Bug 661055 - Add restorableObjectsCount getter to SessionStore.jsm r?mikedeboer draft
authorIan Moody <moz-ian@perix.co.uk>
Thu, 05 Oct 2017 23:03:48 +0100
changeset 711814 623df240de974670f0ef50d725eca9b0c65ab575
parent 711692 8062887ff0d9382ea84177f2c21f62dc0e613d9e
child 711815 f6d5a4fdf6d5b4f33b4aaa2159a6d7a1093572a8
push id93157
push usermoz-ian@perix.co.uk
push dateThu, 14 Dec 2017 19:49:43 +0000
reviewersmikedeboer
bugs661055
milestone59.0a1
Bug 661055 - Add restorableObjectsCount getter to SessionStore.jsm r?mikedeboer This returns an object of the form { windows: int, tabs: int } which indicates the number of windows and tabs that can be restored from the previous session. MozReview-Commit-ID: LM2yIwaK9IP
browser/components/sessionstore/SessionStore.jsm
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -205,16 +205,27 @@ function debug(aMsg) {
  * A global value to tell that fingerprinting resistance is enabled or not.
  * If it's enabled, the session restore won't restore the window's size and
  * size mode.
  * This value is controlled by preference privacy.resistFingerprinting.
  */
 var gResistFingerprintingEnabled = false;
 
 this.SessionStore = {
+  /**
+   * Returns the counts of windows and tabs restorable from previous session
+   *
+   * @returns {Object.<string, number>} an object with the keys:
+   *            - windows: number of restorable windows
+   *            - tabs: number of restorable tabs
+   */
+  get restorableObjectsCount() {
+    return SessionStoreInternal.restorableObjectsCount;
+  },
+
   get promiseInitialized() {
     return SessionStoreInternal.promiseInitialized;
   },
 
   get promiseAllWindowsRestored() {
     return SessionStoreInternal.promiseAllWindowsRestored;
   },
 
@@ -547,16 +558,27 @@ var SessionStoreInternal = {
     deferred.promise = new Promise((resolve, reject) => {
       deferred.resolve = resolve;
       deferred.reject = reject;
     });
 
     return deferred;
   })(),
 
+  /**
+   * Returns the counts of windows and tabs restorable from previous session
+   *
+   * @returns {Object.<string, number>} an object with the keys:
+   *            - windows: number of restorable windows
+   *            - tabs: number of restorable tabs
+   */
+  get restorableObjectsCount() {
+    return LastSession.restorableObjectsCount;
+  },
+
   get promiseAllWindowsRestored() {
     return this._deferredAllWindowsRestored.promise;
   },
 
   // Promise that is resolved when we're ready to initialize
   // and restore the session.
   _promiseReadyForInitialization: null,
 
@@ -5084,16 +5106,29 @@ var DirtyWindows = {
 
 // The state from the previous session (after restoring pinned tabs). This
 // state is persisted and passed through to the next session during an app
 // restart to make the third party add-on warning not trash the deferred
 // session
 var LastSession = {
   _state: null,
 
+  /**
+   * Returns the counts of windows and tabs in the session
+   *
+   * @returns {Object.<string, number>} an object with the keys:
+   *            - windows: number of restorable windows
+   *            - tabs: number of restorable tabs
+   */
+  get restorableObjectsCount() {
+    let windows = this._state.windows.length;
+    let tabs = this._state.windows.reduce((acc, win) => acc + win.tabs.length, 0);
+    return {windows, tabs};
+  },
+
   get canRestore() {
     return !!this._state;
   },
 
   getState() {
     return this._state;
   },