Bug 669199 - Remove ability to enable/disable sync from preferences UI (r=mbrubeck)
authorLucas Rocha <lucasr@mozilla.com>
Fri, 23 Sep 2011 13:17:58 -0700
changeset 78746 81d4441e31a95b5ea11e4d66351fda9636135693
parent 78745 eadc362c79291197357478b4e081b934e37be4a8
child 78747 cd648ccf5f96b03bc09a125b2fd66670570e7f0e
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs669199
milestone9.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 669199 - Remove ability to enable/disable sync from preferences UI (r=mbrubeck)
mobile/app/mobile.js
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.xul
mobile/chrome/content/sync.js
mobile/locales/en-US/chrome/sync.dtd
--- a/mobile/app/mobile.js
+++ b/mobile/app/mobile.js
@@ -549,18 +549,16 @@ pref("font.default.x-baltic", "SwissA");
 pref("font.default.x-central-euro", "SwissA");
 pref("font.default.x-cyrillic", "SwissA");
 pref("font.default.x-unicode", "SwissA");
 pref("font.default.x-user-def", "SwissA");
 pref("font.default.x-western", "SwissA");
 #endif
 
 #ifdef MOZ_SERVICES_SYNC
-pref("browser.sync.enabled", true);
-
 // sync service
 pref("services.sync.client.type", "mobile");
 pref("services.sync.registerEngines", "Tab,Bookmarks,Form,History,Password,Prefs");
 pref("services.sync.autoconnectDelay", 5);
 
 // prefs to sync by default
 pref("services.sync.prefs.sync.browser.startup.homepage.title", true);
 pref("services.sync.prefs.sync.browser.startup.homepage", true);
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -1220,30 +1220,16 @@ var BrowserUI = {
         AwesomeScreen.activePanel = HistoryList;
         break;
       case "cmd_remoteTabs":
         if (Weave.Status.checkSetup() == Weave.CLIENT_NOT_CONFIGURED) {
           // We have to set activePanel before showing sync's dialog
           // to make the sure the dialog stacking is correct.
           AwesomeScreen.activePanel = RemoteTabsList;
           WeaveGlue.open();
-        } else if (!Weave.Service.isLoggedIn && !Services.prefs.getBoolPref("browser.sync.enabled")) {
-          // unchecked the relative command button
-          document.getElementById("remotetabs-button").removeAttribute("checked");
-
-          BrowserUI.showPanel("prefs-container");
-          let prefsBox = document.getElementById("prefs-list");
-          let syncArea = document.getElementById("prefs-sync");
-          if (prefsBox && syncArea) {
-            let prefsBoxY = prefsBox.firstChild.boxObject.screenY;
-            let syncAreaY = syncArea.boxObject.screenY;
-            setTimeout(function() {
-              prefsBox.scrollBoxObject.scrollTo(0, syncAreaY - prefsBoxY);
-            }, 0);
-          }
         } else {
           AwesomeScreen.activePanel = RemoteTabsList;
         }
 
         break;
       case "cmd_quit":
         // Only close one window
         this._closeOrQuit();
--- a/mobile/chrome/content/browser.xul
+++ b/mobile/chrome/content/browser.xul
@@ -471,19 +471,18 @@
                         <menuitem id="prefs-homepage-default" label="&homepage.default;" value="default"/>
                         <menuitem id="prefs-homepage-none" label="&homepage.none;" value="none"/>
                         <menuitem id="prefs-homepage-currentpage" label="&homepage.currentpage;" value="currentpage"/>
                       </menupopup>
                     </menulist>
                   </setting>
 #ifdef MOZ_SERVICES_SYNC
                   <settings id="prefs-sync" label="&sync.title;">
-                    <setting id="sync-autosync" pref="browser.sync.enabled" type="bool" title="&sync.synchronize;" oninputchanged="WeaveGlue.toggleSyncEnabled();"/>
-                    <setting id="sync-connect" title="&sync.notconnected;" type="control" collapsed="true">
-                      <button label="&sync.connect;" oncommand="WeaveGlue.open();" />
+                    <setting id="sync-connect" title="&sync.notconnected;" type="control">
+                      <button label="&sync.connect;" oncommand="WeaveGlue.tryConnect();" />
                     </setting>
                     <setting id="sync-connected" class="setting-group" title="&sync.connected;" type="control" collapsed="true">
                       <button id="sync-details" label="&sync.details;" type="checkbox" autocheck="false" checked="false" oncommand="WeaveGlue.showDetails();" />
                     </setting>
                     <setting id="sync-sync" class="setting-subgroup" type="control" collapsed="true">
                       <button id="sync-syncButton" label="&sync.syncNow;" oncommand="WeaveGlue.sync();"/>
                     </setting>
                     <setting id="sync-device" class="setting-subgroup" type="string" title="&sync.deviceName;" onchange="WeaveGlue.changeName(this);" collapsed="true"/>
--- a/mobile/chrome/content/sync.js
+++ b/mobile/chrome/content/sync.js
@@ -47,31 +47,25 @@ let WeaveGlue = {
 
     this._bundle = Services.strings.createBundle("chrome://browser/locale/sync.properties");
     this._msg = document.getElementById("prefs-messages");
 
     this._addListeners();
 
     this.setupData = { account: "", password: "" , synckey: "", serverURL: "" };
 
-    let enableSync = Services.prefs.getBoolPref("browser.sync.enabled");
-    if (enableSync)
-      this._elements.connect.collapsed = false;
-
     // Generating keypairs is expensive on mobile, so disable it
     if (Weave.Status.checkSetup() != Weave.CLIENT_NOT_CONFIGURED) {
-      if (enableSync) {
-        // Put the settings UI into a state of "connecting..." if we are going to auto-connect
-        this._elements.connect.firstChild.disabled = true;
-        this._elements.connect.setAttribute("title", this._bundle.GetStringFromName("connecting.label"));
+      // Put the settings UI into a state of "connecting..." if we are going to auto-connect
+      this._elements.connect.firstChild.disabled = true;
+      this._elements.connect.setAttribute("title", this._bundle.GetStringFromName("connecting.label"));
 
-        try {
-          this._elements.device.value = Services.prefs.getCharPref("services.sync.client.name");
-        } catch(e) {}
-      }
+      try {
+        this._elements.device.value = Services.prefs.getCharPref("services.sync.client.name");
+      } catch(e) {}
     } else if (Weave.Status.login != Weave.LOGIN_FAILED_NO_USERNAME) {
       this.loadSetupData();
     }
   },
 
   abortEasySetup: function abortEasySetup() {
     document.getElementById("syncsetup-code1").value = "....";
     document.getElementById("syncsetup-code2").value = "....";
@@ -252,46 +246,43 @@ let WeaveGlue = {
     // Show the connect UI detail settings
     let show = this._elements.sync.collapsed;
     this._elements.details.checked = show;
     this._elements.sync.collapsed = !show;
     this._elements.device.collapsed = !show;
     this._elements.disconnect.collapsed = !show;
   },
 
-  toggleSyncEnabled: function toggleSyncEnabled() {
-    let enabled = this._elements.autosync.value;
-    if (enabled) {
-      // Attempt to go back online
-      if (this.setupData) {
-        if (this.setupData.serverURL && this.setupData.serverURL.length)
-          Weave.Service.serverURL = this.setupData.serverURL;
-
-        // We might still be in the middle of a sync from before Sync was disabled, so
-        // let's force the UI into a state that the Sync code feels comfortable
-        this.observe(null, "", "");
+  tryConnect: function login() {
+    // If Sync is not configured, simply show the setup dialog
+    if (Weave.Status.checkSetup() == Weave.CLIENT_NOT_CONFIGURED) {
+      this.open();
+      return;
+    }
 
-        // Now try to re-connect. If successful, this will reset the UI into the
-        // correct state automatically.
-        Weave.Service.login(Weave.Service.username, this.setupData.password, this.setupData.synckey);
-      } else {
-        // We can't just go back online. We need to be setup again.
-        this._elements.connected.collapsed = true;
-        this._elements.connect.collapsed = false;
-      }
-    } else {
-      this._elements.connect.collapsed = true;
-      this._elements.connected.collapsed = true;
-      Weave.Service.logout();
+    // If user is already logged-in, try to connect straight away
+    if (Weave.Service.isLoggedIn) {
+      this.connect();
+      return;
     }
 
-    // Close any 'Undo' notification, if one is present
-    let notification = this._msg.getNotificationWithValue("undo-disconnect");
-    if (notification)
-      notification.close();
+    // No setup data, do nothing
+    if (!this.setupData)
+      return;
+
+    if (this.setupData.serverURL && this.setupData.serverURL.length)
+      Weave.Service.serverURL = this.setupData.serverURL;
+
+    // We might still be in the middle of a sync from before Sync was disabled, so
+    // let's force the UI into a state that the Sync code feels comfortable
+    this.observe(null, "", "");
+
+    // Now try to re-connect. If successful, this will reset the UI into the
+    // correct state automatically.
+    Weave.Service.login(Weave.Service.username, this.setupData.password, this.setupData.synckey);
   },
 
   connect: function connect(aSetupData) {
     // Use setup data to pre-configure manual fields
     if (aSetupData)
       this.setupData = aSetupData;
 
     // Cause the Sync system to reset internals if we seem to be switching accounts
@@ -375,17 +366,17 @@ let WeaveGlue = {
 
     // Get all the setting nodes from the add-ons display
     let elements = {};
     let setupids = ["account", "password", "synckey", "usecustomserver", "customserver"];
     setupids.forEach(function(id) {
       elements[id] = document.getElementById("syncsetup-" + id);
     });
 
-    let settingids = ["device", "connect", "connected", "disconnect", "sync", "autosync", "details"];
+    let settingids = ["device", "connect", "connected", "disconnect", "sync", "details"];
     settingids.forEach(function(id) {
       elements[id] = document.getElementById("sync-" + id);
     });
 
     // Replace the getter with the collection of settings
     delete this._elements;
     return this._elements = elements;
   },
@@ -396,38 +387,25 @@ let WeaveGlue = {
 
     // Can't do anything before settings are loaded
     if (this._elements == null)
       return;
 
     // Make some aliases
     let connect = this._elements.connect;
     let connected = this._elements.connected;
-    let autosync = this._elements.autosync;
     let details = this._elements.details;
     let device = this._elements.device;
     let disconnect = this._elements.disconnect;
     let sync = this._elements.sync;
 
-    let syncEnabled = autosync.value;
     let loggedIn = Weave.Service.isLoggedIn;
 
-    // Sync may successfully log in after it was temporarily disabled by a
-    // canceled master password entry.  If so, then re-enable it.
-    if (loggedIn && !syncEnabled)
-      syncEnabled = autosync.value = true;
-
-    // If Sync is not enabled, hide the connection row visibility
-    if (syncEnabled) {
-      connect.collapsed = loggedIn;
-      connected.collapsed = !loggedIn;
-    } else {
-      connect.collapsed = true;
-      connected.collapsed = true;
-    }
+    connect.collapsed = loggedIn;
+    connected.collapsed = !loggedIn;
 
     if (!loggedIn) {
       connect.setAttribute("title", this._bundle.GetStringFromName("notconnected.label"));
       connect.firstChild.disabled = false;
       details.checked = false;
       sync.collapsed = true;
       device.collapsed = true;
       disconnect.collapsed = true;
@@ -460,24 +438,20 @@ let WeaveGlue = {
     if (lastSync != null) {
       let syncDate = new Date(lastSync).toLocaleFormat("%a %R");
       let dateStr = this._bundle.formatStringFromName("lastSync2.label", [syncDate], 1);
       sync.setAttribute("title", dateStr);
     }
 
     // Show what went wrong with login if necessary
     if (aTopic == "weave:service:login:error") {
-      if (Weave.Status.login == "service.master_password_locked") {
-        // Disable sync temporarily. Sync will try again after a set interval,
-        // or if the user presses the button to enable it again.
-        autosync.value = false;
-        this.toggleSyncEnabled();
-      } else {
+      if (Weave.Status.login == "service.master_password_locked")
+        Weave.Service.logout();
+      else
         connect.setAttribute("desc", Weave.Utils.getErrorString(Weave.Status.login));
-      }
     } else {
       connect.removeAttribute("desc");
     }
 
     // Init the setup data if we just logged in
     if (!this.setupData && aTopic == "weave:service:login:finish")
       this.loadSetupData();
 
--- a/mobile/locales/en-US/chrome/sync.dtd
+++ b/mobile/locales/en-US/chrome/sync.dtd
@@ -1,14 +1,13 @@
 <!ENTITY sync.title                 "Sync">
 <!ENTITY sync.notconnected          "Not connected">
 <!ENTITY sync.connect               "Connect">
 <!ENTITY sync.connected             "Connected">
 <!ENTITY sync.details               "Details">
-<!ENTITY sync.synchronize           "Enable Sync">
 <!ENTITY sync.deviceName            "This device">
 <!ENTITY sync.disconnect            "Disconnect">
 <!ENTITY sync.syncNow               "Sync Now">
 
 <!ENTITY sync.setup.title           "Connect to Sync">
 <!ENTITY sync.setup.jpake           "From a Firefox Sync-connected computer, go to Sync options and select &#x0022;Add a device&#x0022;">
 <!ENTITY sync.fallback              "I'm not near my computer…">
 <!ENTITY sync.setup.manual          "Enter your Sync account information">