bug 581319 - Warn people on startup if they run an old build with updates disabled, r=Neil a=me for triggering builds after buildbot upgrade on CLOSED TREE
authorRobert Kaiser <kairo@kairo.at>
Sun, 12 Dec 2010 00:44:11 +0100
changeset 6819 609b77dd2e8af811813ff4cc13245faf009ca2ce
parent 6818 26c975e35f4c1cd90b610030ccf2902eecede2d0
child 6820 009256f3df67774624aa9a2dff69c5c036fa12e7
push idunknown
push userunknown
push dateunknown
reviewersNeil, me
bugs581319
bug 581319 - Warn people on startup if they run an old build with updates disabled, r=Neil a=me for triggering builds after buildbot upgrade on CLOSED TREE
suite/common/src/nsSuiteGlue.js
suite/locales/en-US/chrome/common/notification.properties
--- a/suite/common/src/nsSuiteGlue.js
+++ b/suite/common/src/nsSuiteGlue.js
@@ -240,16 +240,19 @@ SuiteGlue.prototype = {
     // Load the "more info" page for a locked places.sqlite
     // This property is set earlier in the startup process:
     // nsPlacesDBFlush loads after profile-after-change and initializes
     // the history service, which sends out places-database-locked
     // which sets this property.
     if (this._isPlacesDatabaseLocked) {
       this._showPlacesLockedNotificationBox(aWindow);
     }
+    // Detect if updates are off and warn for outdated builds.
+    if (this._shouldShowUpdateWarning())
+      this._showUpdateWarning(aWindow);
   },
 
   // profile shutdown handler (contains profile cleanup routines)
   _onProfileShutdown: function()
   {
     this._shutdownPlaces();
     Sanitizer.checkAndSanitize();
   },
@@ -457,16 +460,74 @@ SuiteGlue.prototype = {
     // Stick the notification onto the selected tab of the active browser window.
     aSubject.getBrowser().getNotificationBox().showRightsNotification();
 
     // Set pref to indicate we've shown the notficiation.
     var currentVersion = Services.prefs.getIntPref("browser.rights.version");
     Services.prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true);
   },
 
+  /*
+   * _shouldShowUpdateWarning - Determines if the user should be warned about
+   * having updates off and an old build that likely should be updated.
+   */
+  _shouldShowUpdateWarning: function () {
+    // Look for an unconditional override pref. If set, do what it says.
+    // (true --> never show, false --> always show)
+    try {
+      return !Services.prefs.getBoolPref("app.updatecheck.override");
+    } catch (e) { }
+    // If updates are enabled, we don't need to worry.
+    if (Services.prefs.getBoolPref("app.update.enabled"))
+      return false;
+    var maxAge = 90 * 86400; // 90 days
+    var now = Math.round(Date.now() / 1000);
+    // If there was an automated update tried in the interval, don't worry.
+    var lastUpdateTime = Services.prefs.getIntPref("app.update.lastUpdateTime.background-update-timer");
+    if (lastUpdateTime + maxAge > now)
+      return false;
+
+    var buildID = Services.appinfo.appBuildID;
+    // construct build date from ID
+    var buildDate = new Date(buildID.substr(0, 4),
+                             buildID.substr(4, 2) - 1,
+                             buildID.substr(6, 2));
+    var buildTime = Math.round(buildDate / 1000);
+    // We should warn if the build is older than the max age.
+    return (buildTime + maxAge <= now);
+  },
+
+  _showUpdateWarning: function(aSubject) {
+    // Stick the notification onto the selected tab of the active browser window.
+    var brandBundle  = Services.strings.createBundle("chrome://branding/locale/brand.properties");
+    var applicationName = brandBundle.GetStringFromName("brandShortName");
+    var notificationBundle = Services.strings.createBundle("chrome://communicator/locale/notification.properties");
+    var title = notificationBundle.GetStringFromName("updatePrompt.title");
+    var text = notificationBundle.formatStringFromName("updatePrompt.text", [applicationName], 1);
+    var buttonText = notificationBundle.GetStringFromName("updatePromptCheckButton.label");
+    var accessKey = notificationBundle.GetStringFromName("updatePromptCheckButton.accessKey");
+
+    var buttons = [{
+      label: buttonText,
+      accessKey: accessKey,
+      popup: null,
+      callback: function(aNotificationBar, aButton) {
+        Components.classes["@mozilla.org/updates/update-prompt;1"]
+                  .createInstance(Components.interfaces.nsIUpdatePrompt)
+                  .checkForUpdates();
+      }
+    }];
+
+    var notifyBox = aSubject.getBrowser().getNotificationBox();
+    var box = notifyBox.appendNotification(text, title, null,
+                                           notifyBox.PRIORITY_CRITICAL_MEDIUM,
+                                           buttons);
+    box.persistence = -1; // Until user closes it
+  },
+
   /**
    * Initialize Places
    * - imports the bookmarks html file if bookmarks database is empty, try to
    *   restore bookmarks from a JSON backup if the backend indicates that the
    *   database was corrupt.
    *
    * These prefs can be set up by the frontend:
    *
@@ -706,17 +767,17 @@ SuiteGlue.prototype = {
       label: buttonText,
       accessKey: accessKey,
       popup: null,
       callback: function(aNotificationBar, aButton) {
         aSubject.openHelp(helpTopic, helpRDF);
       }
     }];
 
-    var notifyBox = aSubject.gBrowser.getNotificationBox();
+    var notifyBox = aSubject.getBrowser().getNotificationBox();
     var box = notifyBox.appendNotification(text, title, null,
                                            notifyBox.PRIORITY_CRITICAL_MEDIUM,
                                            buttons);
     box.persistence = -1; // Until user closes it
   },
 
   _updatePrefs: function()
   {
--- a/suite/locales/en-US/chrome/common/notification.properties
+++ b/suite/locales/en-US/chrome/common/notification.properties
@@ -61,8 +61,15 @@ geolocation.fileWantsToKnow=The file %S 
 geolocation.learnMore=Learn Moreā€¦
 geolocation.remember=Remember for this website
 
 # Block autorefresh
 refreshBlocked.goButton=Allow
 refreshBlocked.goButton.accesskey=A
 refreshBlocked.refreshLabel=%S prevented this page from automatically reloading.
 refreshBlocked.redirectLabel=%S prevented this page from automatically redirecting to another page.
+
+# LOCALIZATION NOTE (updatePrompt.text)
+# %S will be replaced with the application name.
+updatePrompt.title=Outdated Version
+updatePrompt.text=Your copy of %S is old and probably has known security flaws, but you have disabled automated update checks. Please update to a newer version.
+updatePromptCheckButton.label=Check for Updates
+updatePromptCheckButton.accessKey=C