Bug 618434 - Show errors when JPAKE fails [r=mfinkle, a=blocking-fennec]
authorWes Johnston <wjohnston@mozilla.com>
Mon, 31 Jan 2011 14:08:19 -0800
changeset 67335 c331861c7b138af315ff492e3ef56cd28af261f8
parent 67334 ec7e1eebc28187d47999502769f37bc2f9853d1e
child 67336 8b0e4ac2b00160478fc0239fd5a9ce0d562de8e6
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, blocking-fennec
bugs618434
Bug 618434 - Show errors when JPAKE fails [r=mfinkle, a=blocking-fennec]
mobile/chrome/content/sync.js
mobile/locales/en-US/chrome/sync.properties
--- a/mobile/chrome/content/sync.js
+++ b/mobile/chrome/content/sync.js
@@ -93,16 +93,25 @@ let WeaveGlue = {
     }
   },
 
   open: function open() {
     let container = document.getElementById("syncsetup-container");
     if (!container.hidden)
       return;
 
+    // Services.io.offline is lying to us, so we use the NetworkLinkService instead
+    let nls = Cc["@mozilla.org/network/network-link-service;1"].getService(Ci.nsINetworkLinkService);
+    if (!nls.isLinkUp) {
+      Services.prompt.alert(window,
+                             this._bundle.GetStringFromName("sync.setup.error.title"),
+                             this._bundle.GetStringFromName("sync.setup.error.network"));
+      return;
+    }
+
     // Clear up any previous JPAKE codes
     this.abortEasySetup();
 
     // Show the connect UI
     container.hidden = false;
     document.getElementById("syncsetup-simple").hidden = false;
     document.getElementById("syncsetup-fallback").hidden = true;
 
@@ -125,23 +134,43 @@ let WeaveGlue = {
       onAbort: function onAbort(aError) {
         self.jpake = null;
 
         // No error means manual abort. Ignore.
         if (!aError)
           return;
 
         // Automatically go to manual setup if we couldn't acquire a channel.
-        if (aError == Weave.JPAKE_ERROR_CHANNEL) {
-          self.openManual();
-          return;
+        let brandShortName = Strings.brand.GetStringFromName("brandShortName");
+        let tryAgain = self._bundle.GetStringFromName("sync.setup.tryagain");
+        let manualSetup = self._bundle.GetStringFromName("sync.setup.manual");
+        let buttonFlags = Ci.nsIPrompt.BUTTON_POS_1_DEFAULT +
+                         (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_0) +
+                         (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_1) +
+                         (Ci.nsIPrompt.BUTTON_TITLE_CANCEL    * Ci.nsIPrompt.BUTTON_POS_2);
+
+        let button = Services.prompt.confirmEx(window,
+                               self._bundle.GetStringFromName("sync.setup.error.title"),
+                               self._bundle.formatStringFromName("sync.setup.error.nodata", [brandShortName], 1),
+                               buttonFlags, tryAgain, manualSetup, null, "", {});
+        switch (button) {
+          case 0:
+            // we have to build a new JPAKEClient here rather than reuse the old one
+            container.hidden = true;
+            self.open();
+            break;
+          case 1:
+            self.openManual();
+            break;
+          case 2:
+          default:
+            self.abortEasySetup();
+            self.close();
+            break;
         }
-
-        // Restart on all other errors.
-        self.open();
       }
     });
     this.jpake.receiveNoPIN();
   },
 
   openManual: function openManual() {
     this.abortEasySetup();
 
--- a/mobile/locales/en-US/chrome/sync.properties
+++ b/mobile/locales/en-US/chrome/sync.properties
@@ -15,8 +15,13 @@ notificationDisconnect.button=Undo
 # LOCALIZATION NOTE (sync.clientUpdate, sync.remoteUpdate):
 # #1 is the "application name"
 # #2 is the "version"
 sync.update.client=#1 #2 is not compatible with the latest version of Firefox Sync. Please update to the latest version.
 sync.update.remote=#1 #2 is not compatible with older versions of Firefox Sync. Please update Firefox on your other computer(s).
 sync.update.title=Firefox Sync
 sync.update.button=Learn More
 sync.update.close=Close
+sync.setup.error.title=Cannot Setup Sync
+sync.setup.error.network=No internet connection available
+sync.setup.error.nodata=%S could not connect to Sync. Would you like to try again?
+sync.setup.tryagain=Try again
+sync.setup.manual=Manual setup