Bug 311614: Show update dialog in front of the browser window if one needs to be displayed after startup. r=rstrong,mhowell
authorStephen A Pohl <spohl.mozilla.bugs@gmail.com>
Fri, 13 May 2016 23:36:37 -0400
changeset 491538 128140f36993ae225a2602f7dea3148bb124f501
parent 491537 007fbe0337935553935559bc57650eece290686a
child 491539 ccc38fd400731910be189e6aab353ec25b9936c0
push id47343
push userbmo:dothayer@mozilla.com
push dateWed, 01 Mar 2017 22:58:58 +0000
reviewersrstrong, mhowell
bugs311614
milestone49.0a1
Bug 311614: Show update dialog in front of the browser window if one needs to be displayed after startup. r=rstrong,mhowell
toolkit/mozapps/update/nsUpdateService.js
--- a/toolkit/mozapps/update/nsUpdateService.js
+++ b/toolkit/mozapps/update/nsUpdateService.js
@@ -187,16 +187,31 @@ const DEFAULT_SOCKET_MAX_ERRORS = 10;
 
 // The number of milliseconds to wait before retrying a connection error.
 const DEFAULT_UPDATE_RETRY_TIMEOUT = 2000;
 
 // Default maximum number of elevation cancelations per update version before
 // giving up.
 const DEFAULT_MAX_OSX_CANCELATIONS = 3;
 
+// This maps app IDs to their respective notification topic which signals when
+// app startup is complete.
+const APPID_TO_TOPIC = {
+  // Firefox
+  "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}": "sessionstore-windows-restored",
+  // SeaMonkey
+  "{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}": "sessionstore-windows-restored",
+  // Fennec
+  "{aa3c5121-dab2-40e2-81ca-7ea25febc110}": "sessionstore-windows-restored",
+  // Thunderbird
+  "{3550f703-e582-4d05-9a08-453d09bdfdc6}": "mail-startup-done",
+  // Instantbird
+  "{33cb9019-c295-46dd-be21-8c4936574bee}": "xul-window-visible",
+};
+
 var gLocale = null;
 var gUpdateMutexHandle = null;
 
 // Gonk only
 var gSDCardMountLock = null;
 
 // Gonk only
 XPCOMUtils.defineLazyGetter(this, "gExtStorage", function aus_gExtStorage() {
@@ -1960,16 +1975,34 @@ UpdateService.prototype = {
    * @param   topic
    *          The notification name
    * @param   data
    *          Additional data
    */
   observe: function AUS_observe(subject, topic, data) {
     switch (topic) {
       case "post-update-processing":
+        let appInfoID1 = Cc["@mozilla.org/xre/app-info;1"]
+                           .getService(Ci.nsIXULAppInfo).ID;
+        if (appInfoID1 in APPID_TO_TOPIC) {
+          // Delay post-update processing to ensure that possible update
+          // dialogs are shown in front of the app window, if possible.
+          // See bug 311614.
+          Services.obs.addObserver(this, APPID_TO_TOPIC[appInfoID1], false);
+          break;
+        }
+        // intentional fallthrough
+      case "sessionstore-windows-restored":
+      case "mail-startup-done":
+      case "xul-window-visible":
+        let appInfoID2 = Cc["@mozilla.org/xre/app-info;1"]
+                           .getService(Ci.nsIXULAppInfo).ID;
+        if (appInfoID2 in APPID_TO_TOPIC) {
+          Services.obs.removeObserver(this, APPID_TO_TOPIC[appInfoID2]);
+        }
         // Clean up any extant updates
         this._postUpdateProcessing();
         break;
       case "network:offline-status-changed":
         this._offlineStatusChanged(data);
         break;
       case "nsPref:changed":
         if (data == PREF_APP_UPDATE_LOG) {