Have the sync setup dialog do the right thing if identity.fxaccounts.enabled=true
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 19 Dec 2013 16:38:35 +1100
changeset 161533 9039f1de78296d97259c3c088b13dcebba2d7148
parent 161532 9c26c558c80cc68b77946011f94f2a862610fd14
child 161534 31f9d496d6171d79dce915d04ea663bc09078f67
push id4124
push userkwierso@gmail.com
push dateSat, 21 Dec 2013 03:02:52 +0000
treeherderfx-team@f644da1c9331 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone29.0a1
Have the sync setup dialog do the right thing if identity.fxaccounts.enabled=true
browser/base/content/browser-syncui.js
browser/components/preferences/in-content/sync.js
browser/components/preferences/in-content/sync.xul
browser/components/preferences/sync.js
browser/components/preferences/sync.xul
--- a/browser/base/content/browser-syncui.js
+++ b/browser/base/content/browser-syncui.js
@@ -274,23 +274,30 @@ let gSyncUI = {
    * @param wizardType
    *        Indicates type of wizard to launch:
    *          null    -- regular set up wizard
    *          "pair"  -- pair a device first
    *          "reset" -- reset sync
    */
 
   openSetup: function SUI_openSetup(wizardType) {
-    let win = Services.wm.getMostRecentWindow("Weave:AccountSetup");
-    if (win)
-      win.focus();
-    else {
-      window.openDialog("chrome://browser/content/sync/setup.xul",
-                        "weaveSetup", "centerscreen,chrome,resizable=no",
-                        wizardType);
+    let xps = Components.classes["@mozilla.org/weave/service;1"]
+                                .getService(Components.interfaces.nsISupports)
+                                .wrappedJSObject;
+    if (xps.fxAccountsEnabled) {
+      switchToTabHavingURI("about:accounts", true);
+    } else {
+      let win = Services.wm.getMostRecentWindow("Weave:AccountSetup");
+      if (win)
+        win.focus();
+      else {
+        window.openDialog("chrome://browser/content/sync/setup.xul",
+                          "weaveSetup", "centerscreen,chrome,resizable=no",
+                          wizardType);
+      }
     }
   },
 
   openAddDevice: function () {
     if (!Weave.Utils.ensureMPUnlocked())
       return;
 
     let win = Services.wm.getMostRecentWindow("Sync:AddDevice");
--- a/browser/components/preferences/in-content/sync.js
+++ b/browser/components/preferences/in-content/sync.js
@@ -86,16 +86,23 @@ let gSyncPane = {
       Services.strings.createBundle("chrome://browser/locale/preferences/preferences.properties");
     this.updateWeavePrefs();
   },
 
   updateWeavePrefs: function () {
     if (Weave.Status.service == Weave.CLIENT_NOT_CONFIGURED ||
         Weave.Svc.Prefs.get("firstSync", "") == "notReady") {
       this.page = PAGE_NO_ACCOUNT;
+      let service = Components.classes["@mozilla.org/weave/service;1"]
+                    .getService(Components.interfaces.nsISupports)
+                    .wrappedJSObject;
+      // no concept of "pair" in an fxAccounts world.
+      if (service.fxAccountsEnabled) {
+        document.getElementById("pairDevice").hidden = true;
+      }
     } else if (Weave.Status.login == Weave.LOGIN_FAILED_INVALID_PASSPHRASE ||
                Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED) {
       this.needsUpdate();
     } else {
       this.page = PAGE_HAS_ACCOUNT;
       document.getElementById("accountName").value = Weave.Service.identity.account;
       document.getElementById("syncComputerName").value = Weave.Service.clientsEngine.localName;
       document.getElementById("tosPP").hidden = this._usingCustomServer;
@@ -143,23 +150,32 @@ let gSyncPane = {
    * 
    * @param wizardType
    *        Indicates type of wizard to launch:
    *          null    -- regular set up wizard
    *          "pair"  -- pair a device first
    *          "reset" -- reset sync
    */
   openSetup: function (wizardType) {
-    let win = Services.wm.getMostRecentWindow("Weave:AccountSetup");
-    if (win)
-      win.focus();
-    else {
-      window.openDialog("chrome://browser/content/sync/setup.xul",
-                        "weaveSetup", "centerscreen,chrome,resizable=no",
-                        wizardType);
+    let service = Components.classes["@mozilla.org/weave/service;1"]
+                  .getService(Components.interfaces.nsISupports)
+                  .wrappedJSObject;
+
+    if (service.fxAccountsEnabled) {
+      let win = Services.wm.getMostRecentWindow("navigator:browser");
+      win.switchToTabHavingURI("about:accounts", true);
+    } else {
+      let win = Services.wm.getMostRecentWindow("Weave:AccountSetup");
+      if (win)
+        win.focus();
+      else {
+        window.openDialog("chrome://browser/content/sync/setup.xul",
+                          "weaveSetup", "centerscreen,chrome,resizable=no",
+                          wizardType);
+      }
     }
   },
 
   openQuotaDialog: function () {
     let win = Services.wm.getMostRecentWindow("Sync:ViewQuota");
     if (win)
       win.focus();
     else 
--- a/browser/components/preferences/in-content/sync.xul
+++ b/browser/components/preferences/in-content/sync.xul
@@ -33,20 +33,22 @@
     <spacer flex="1"/>
     <description id="syncDesc">
       &weaveDesc.label;
     </description>
     <separator/>
     <label class="text-link"
            onclick="event.stopPropagation(); gSyncPane.openSetup(null);"
            value="&setupButton.label;"/>
-    <separator/>
-    <label class="text-link"
-           onclick="event.stopPropagation(); gSyncPane.openSetup('pair');"
-           value="&pairDevice.label;"/>
+    <vbox id="pairDevice">
+      <separator/>
+      <label class="text-link"
+             onclick="event.stopPropagation(); gSyncPane.openSetup('pair');"
+             value="&pairDevice.label;"/>
+    </vbox>
     <spacer flex="3"/>
   </vbox>
 
   <vbox id="hasAccount">
     <groupbox class="syncGroupBox">
       <!-- label is set to account name -->
       <caption id="accountCaption" align="center">
         <image id="accountCaptionImage"/>
--- a/browser/components/preferences/sync.js
+++ b/browser/components/preferences/sync.js
@@ -86,16 +86,23 @@ let gSyncPane = {
       Services.strings.createBundle("chrome://browser/locale/preferences/preferences.properties");
     this.updateWeavePrefs();
   },
 
   updateWeavePrefs: function () {
     if (Weave.Status.service == Weave.CLIENT_NOT_CONFIGURED ||
         Weave.Svc.Prefs.get("firstSync", "") == "notReady") {
       this.page = PAGE_NO_ACCOUNT;
+      let service = Components.classes["@mozilla.org/weave/service;1"]
+                    .getService(Components.interfaces.nsISupports)
+                    .wrappedJSObject;
+      // no concept of "pair" in an fxAccounts world.
+      if (service.fxAccountsEnabled) {
+        document.getElementById("pairDevice").hidden = true;
+      }
     } else if (Weave.Status.login == Weave.LOGIN_FAILED_INVALID_PASSPHRASE ||
                Weave.Status.login == Weave.LOGIN_FAILED_LOGIN_REJECTED) {
       this.needsUpdate();
     } else {
       this.page = PAGE_HAS_ACCOUNT;
       document.getElementById("accountName").value = Weave.Service.identity.account;
       document.getElementById("syncComputerName").value = Weave.Service.clientsEngine.localName;
       document.getElementById("tosPP").hidden = this._usingCustomServer;
@@ -146,23 +153,34 @@ let gSyncPane = {
    *
    * @param wizardType
    *        Indicates type of wizard to launch:
    *          null    -- regular set up wizard
    *          "pair"  -- pair a device first
    *          "reset" -- reset sync
    */
   openSetup: function (wizardType) {
-    let win = Services.wm.getMostRecentWindow("Weave:AccountSetup");
-    if (win) {
-      win.focus();
+    let service = Components.classes["@mozilla.org/weave/service;1"]
+                  .getService(Components.interfaces.nsISupports)
+                  .wrappedJSObject;
+
+    if (service.fxAccountsEnabled) {
+      let win = Services.wm.getMostRecentWindow("navigator:browser");
+      win.switchToTabHavingURI("about:accounts", true);
+      // seeing as we are doing this in a tab we close the prefs dialog.
+      window.close();
     } else {
-      window.openDialog("chrome://browser/content/sync/setup.xul",
-                        "weaveSetup", "centerscreen,chrome,resizable=no",
-                        wizardType);
+      let win = Services.wm.getMostRecentWindow("Weave:AccountSetup");
+      if (win) {
+        win.focus();
+      } else {
+        window.openDialog("chrome://browser/content/sync/setup.xul",
+                          "weaveSetup", "centerscreen,chrome,resizable=no",
+                          wizardType);
+      }
     }
   },
 
   openQuotaDialog: function () {
     let win = Services.wm.getMostRecentWindow("Sync:ViewQuota");
     if (win) {
       win.focus();
     } else {
--- a/browser/components/preferences/sync.xul
+++ b/browser/components/preferences/sync.xul
@@ -42,20 +42,22 @@
           <spacer flex="1"/>
           <description id="syncDesc">
             &weaveDesc.label;
           </description>
           <separator/>
           <label class="text-link"
                  onclick="event.stopPropagation(); gSyncPane.openSetup(null);"
                  value="&setupButton.label;"/>
-          <separator/>
-          <label class="text-link"
-                 onclick="event.stopPropagation(); gSyncPane.openSetup('pair');"
-                 value="&pairDevice.label;"/>
+          <vbox id="pairDevice">
+            <separator/>
+            <label class="text-link"
+                   onclick="event.stopPropagation(); gSyncPane.openSetup('pair');"
+                   value="&pairDevice.label;"/>
+          </vbox>
           <spacer flex="3"/>
         </vbox>
 
         <vbox id="hasAccount">
           <groupbox class="syncGroupBox">
             <!-- label is set to account name -->
             <caption id="accountCaption" align="center">
               <image id="accountCaptionImage"/>