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
--- 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;
},