Bug 1389525 - Add async version of nsISessionStartup::willOverrideHomepage. r?mikedeboer draft
authorDão Gottwald <dao@mozilla.com>
Fri, 11 Aug 2017 17:26:35 +0200
changeset 644929 b47cfe76d9ca7796d456237ed2df030ddbd4a353
parent 644465 253a8560dc34456d2e8a13065e4b3eb5ecf6704f
child 725755 888f91c4c210fa25f0090faf679e0571f483c78c
push id73595
push userdgottwald@mozilla.com
push dateFri, 11 Aug 2017 15:26:55 +0000
reviewersmikedeboer
bugs1389525
milestone57.0a1
Bug 1389525 - Add async version of nsISessionStartup::willOverrideHomepage. r?mikedeboer MozReview-Commit-ID: 7zVR8H8cpB3
browser/components/sessionstore/nsISessionStartup.idl
browser/components/sessionstore/nsSessionStartup.js
--- a/browser/components/sessionstore/nsISessionStartup.idl
+++ b/browser/components/sessionstore/nsISessionStartup.idl
@@ -43,16 +43,24 @@ interface nsISessionStartup: nsISupports
    * This is meant to be an optimization for the average case that loading the
    * session file finishes before we may want to start loading the default
    * homepage. Should this be called before the session file has been read it
    * will just return false.
    */
   readonly attribute bool willOverrideHomepage;
 
   /**
+   * Returns a promise that resolves to a boolean indicating whether we will
+   * restore a session that ends up replacing the homepage. The browser uses
+   * this to not start loading the homepage if we're going to stop its load
+   * anyway shortly after.
+   */
+  readonly attribute jsval willOverrideHomepagePromise;
+
+  /**
    * What type of session we're restoring.
    * NO_SESSION       There is no data available from the previous session
    * RECOVER_SESSION  The last session crashed. It will either be restored or
    *                  about:sessionrestore will be shown.
    * RESUME_SESSION   The previous session should be restored at startup
    * DEFER_SESSION    The previous session is fine, but it shouldn't be restored
    *                  without explicit action (with the exception of pinned tabs)
    */
--- a/browser/components/sessionstore/nsSessionStartup.js
+++ b/browser/components/sessionstore/nsSessionStartup.js
@@ -329,16 +329,28 @@ SessionStartup.prototype = {
       // If there are valid windows with not only pinned tabs, signal that we
       // will override the default homepage by restoring a session.
       return windows && windows.some(w => w.tabs.some(t => !t.pinned));
     }
     return false;
   },
 
   /**
+   * Returns a promise that resolves to a boolean indicating whether we will
+   * restore a session that ends up replacing the homepage. The browser uses
+   * this to not start loading the homepage if we're going to stop its load
+   * anyway shortly after.
+   */
+  get willOverrideHomepagePromise() {
+    return new Promise(resolve => {
+      resolve(this.willOverrideHomepage);
+    });
+  },
+
+  /**
    * Get the type of pending session store, if any.
    */
   get sessionType() {
     return this._sessionType;
   },
 
   /**
    * Get whether the previous session crashed.