Bug 1624044 - Wait for SessionStartup initialization before using it in willCheckDefaultBrowser. r=dao
authorHarry Twyford <htwyford@mozilla.com>
Tue, 24 Mar 2020 16:36:00 +0000
changeset 520237 53361841567a250c71e6cb849de18d1b4e0894e5
parent 520236 154f0e6408f677723b1c9a737cf8f4d2d4b8ea64
child 520238 4aa0213b560375eeded5d6c79b35e316418ab6f8
push id37246
push useropoprus@mozilla.com
push dateWed, 25 Mar 2020 03:40:33 +0000
treeherdermozilla-central@14b59d4adc95 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1624044, 1622195
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1624044 - Wait for SessionStartup initialization before using it in willCheckDefaultBrowser. r=dao The sessionType getter in SessionStartup sets its internal state if there isn't already one. Since the willCheckDefaultBrowser call added in bug 1622195 happens very early, SessionStartup isn't initialized yet so its state is set to "never restore". Differential Revision: https://phabricator.services.mozilla.com/D67902
browser/components/BrowserGlue.jsm
browser/components/urlbar/UrlbarProviderSearchTips.jsm
--- a/browser/components/BrowserGlue.jsm
+++ b/browser/components/BrowserGlue.jsm
@@ -3429,24 +3429,24 @@ BrowserGlue.prototype = {
       }
     }
 
     // Update the migration version.
     Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
   },
 
   _maybeShowDefaultBrowserPrompt() {
-    const willPrompt = DefaultBrowserCheck.willCheckDefaultBrowser(
-      /* isStartupCheck */ true
+    DefaultBrowserCheck.willCheckDefaultBrowser(/* isStartupCheck */ true).then(
+      willPrompt => {
+        if (!willPrompt) {
+          return;
+        }
+        DefaultBrowserCheck.prompt(BrowserWindowTracker.getTopWindow());
+      }
     );
-    if (!willPrompt) {
-      return;
-    }
-
-    DefaultBrowserCheck.prompt(BrowserWindowTracker.getTopWindow());
   },
 
   async _migrateMatchBucketsPrefForUI66() {
     // This does two related things.
     //
     // (1) Profiles created on or after Firefox 57's release date were eligible
     // for a Shield study that changed the browser.urlbar.matchBuckets pref in
     // order to show search suggestions above history/bookmarks in the urlbar
@@ -4431,17 +4431,17 @@ var DefaultBrowserCheck = {
   },
 
   /**
    * Checks if the default browser check prompt will be shown.
    * @param {boolean} isStartupCheck
    *   If true, prefs will be set and telemetry will be recorded.
    * @returns {boolean} True if the default browser check prompt will be shown.
    */
-  willCheckDefaultBrowser(isStartupCheck) {
+  async willCheckDefaultBrowser(isStartupCheck) {
     // Perform default browser checking.
     if (!ShellService) {
       return false;
     }
 
     let shouldCheck =
       !AppConstants.DEBUG && ShellService.shouldCheckDefaultBrowser;
 
@@ -4461,16 +4461,19 @@ var DefaultBrowserCheck = {
         "browser.shell.didSkipDefaultBrowserCheckOnFirstRun"
       );
 
     const usePromptLimit = !AppConstants.RELEASE_OR_BETA;
     let promptCount = usePromptLimit
       ? Services.prefs.getIntPref("browser.shell.defaultBrowserCheckCount")
       : 0;
 
+    // If SessionStartup's state is not initialized, checking sessionType will set
+    // its internal state to "do not restore".
+    await SessionStartup.onceInitialized;
     let willRecoverSession =
       SessionStartup.sessionType == SessionStartup.RECOVER_SESSION;
 
     // Don't show the prompt if we're already the default browser.
     let isDefault = false;
     let isDefaultError = false;
     try {
       isDefault = ShellService.isDefaultBrowser(isStartupCheck, false);
--- a/browser/components/urlbar/UrlbarProviderSearchTips.jsm
+++ b/browser/components/urlbar/UrlbarProviderSearchTips.jsm
@@ -307,17 +307,17 @@ class ProviderSearchTips extends UrlbarP
    */
   async _maybeShowTipForUrl(urlStr) {
     let instance = {};
     this._maybeShowTipForUrlInstance = instance;
 
     let ignoreShowLimits = UrlbarPrefs.get("searchTips.test.ignoreShowLimits");
 
     // Don't show a tip if the browser is already showing some other notification.
-    if (isBrowserShowingNotification() && !ignoreShowLimits) {
+    if ((await isBrowserShowingNotification()) && !ignoreShowLimits) {
       return;
     }
 
     // Don't show a tip if the browser has been updated recently.
     let date = await lastBrowserUpdateDate();
     if (Date.now() - date <= LAST_UPDATE_THRESHOLD_MS && !ignoreShowLimits) {
       return;
     }
@@ -365,17 +365,17 @@ class ProviderSearchTips extends UrlbarP
       }
 
       this.currentTip = tip;
       window.gURLBar.search("", { focus: tip == TIPS.ONBOARD });
     }, SHOW_TIP_DELAY_MS);
   }
 }
 
-function isBrowserShowingNotification() {
+async function isBrowserShowingNotification() {
   let window = BrowserWindowTracker.getTopWindow();
 
   // urlbar view and notification box (info bar)
   if (
     window.gURLBar.view.isOpen ||
     window.gHighPriorityNotificationBox.currentNotification ||
     window.gBrowser.getNotificationBox().currentNotification
   ) {
@@ -416,17 +416,17 @@ function isBrowserShowingNotification() 
     if (node.getAttribute("open") == "true") {
       return true;
     }
   }
 
   // On startup, the default browser check normally opens after the Search Tip.
   // As a result, we can't check for the prompt's presence, but we can check if
   // it plans on opening.
-  const willPrompt = DefaultBrowserCheck.willCheckDefaultBrowser(
+  const willPrompt = await DefaultBrowserCheck.willCheckDefaultBrowser(
     /* isStartupCheck */ false
   );
   if (willPrompt) {
     return true;
   }
 
   return false;
 }