Bug 1216100 - Handle "fxaccounts:sync_preferences" message in FxA WebChannel. r=vivek
authorNick Alexander <nalexander@mozilla.com>
Mon, 26 Oct 2015 16:31:19 -0700
changeset 304992 ad76ef77cd330aca3ced72e50b46aa4114447ca2
parent 304991 a63a4f62298e2036fd25e941600535b34d9fff69
child 304993 c8445cec6e86a343dbd4f092f1294b6020f0e9b4
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvivek
bugs1216100
milestone44.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 1216100 - Handle "fxaccounts:sync_preferences" message in FxA WebChannel. r=vivek The only wrinkle is that we don't always have an Activity context, so we always start a new task. We might want to revisit that decision.
mobile/android/base/AccountsHelper.java
mobile/android/modules/Accounts.jsm
mobile/android/modules/FxAccountsWebChannel.jsm
--- a/mobile/android/base/AccountsHelper.java
+++ b/mobile/android/base/AccountsHelper.java
@@ -52,32 +52,34 @@ public class AccountsHelper implements N
             return;
         }
         dispatcher.registerGeckoThreadListener(this,
                 "Accounts:CreateFirefoxAccountFromJSON",
                 "Accounts:UpdateFirefoxAccountFromJSON",
                 "Accounts:Create",
                 "Accounts:DeleteFirefoxAccount",
                 "Accounts:Exist",
-                "Accounts:ProfileUpdated");
+                "Accounts:ProfileUpdated",
+                "Accounts:ShowSyncPreferences");
     }
 
     public synchronized void uninit() {
         EventDispatcher dispatcher = EventDispatcher.getInstance();
         if (dispatcher == null) {
             Log.e(LOGTAG, "Gecko event dispatcher must not be null", new RuntimeException());
             return;
         }
         dispatcher.unregisterGeckoThreadListener(this,
                 "Accounts:CreateFirefoxAccountFromJSON",
                 "Accounts:UpdateFirefoxAccountFromJSON",
                 "Accounts:Create",
                 "Accounts:DeleteFirefoxAccount",
                 "Accounts:Exist",
-                "Accounts:ProfileUpdated");
+                "Accounts:ProfileUpdated",
+                "Accounts:ShowSyncPreferences");
     }
 
     @Override
     public void handleMessage(String event, NativeJSObject message, final EventCallback callback) {
         if (!RestrictedProfiles.isAllowed(mContext, Restriction.DISALLOW_MODIFY_ACCOUNTS)) {
             // We register for messages in all contexts; we drop, with a log and an error to JavaScript,
             // when the profile is restricted.  It's better to return errors than silently ignore messages.
             Log.e(LOGTAG, "Profile is not allowed to modify accounts!  Ignoring event: " + event);
@@ -265,11 +267,22 @@ public class AccountsHelper implements N
         } else if ("Accounts:ProfileUpdated".equals(event)) {
             final Account account = FirefoxAccounts.getFirefoxAccount(mContext);
             if (account == null) {
                 Log.w(LOGTAG, "Can't change profile of non-existent Firefox Account!; ignored");
                 return;
             }
             final AndroidFxAccount androidFxAccount = new AndroidFxAccount(mContext, account);
             androidFxAccount.fetchProfileJSON();
+        } else if ("Accounts:ShowSyncPreferences".equals(event)) {
+            final Account account = FirefoxAccounts.getFirefoxAccount(mContext);
+            if (account == null) {
+                Log.w(LOGTAG, "Can't change show Sync preferences of non-existent Firefox Account!; ignored");
+                return;
+            }
+            // We don't necessarily have an Activity context here, so we always start in a new task.
+            final Intent intent = new Intent(FxAccountConstants.ACTION_FXA_STATUS);
+            intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
+            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+            mContext.startActivity(intent);
         }
     }
 }
--- a/mobile/android/modules/Accounts.jsm
+++ b/mobile/android/modules/Accounts.jsm
@@ -153,10 +153,22 @@ var Accounts = Object.freeze({
    * It is an error if no Android Account exists.
    *
    * Returns a Promise that resolves to a boolean indicating success.
    */
   deleteFirefoxAccount: function () {
     return Messaging.sendRequestForResult({
       type: "Accounts:DeleteFirefoxAccount",
     });
+  },
+
+  showSyncPreferences: function () {
+    // Only show Sync preferences of an existing Android Account.
+    return Accounts.getFirefoxAccount().then(account => {
+      if (!account) {
+        throw new Error("Can't show Sync preferences of non-existent Firefox Account!");
+      }
+      return Messaging.sendRequestForResult({
+        type: "Accounts:ShowSyncPreferences"
+      });
+    });
   }
 });
--- a/mobile/android/modules/FxAccountsWebChannel.jsm
+++ b/mobile/android/modules/FxAccountsWebChannel.jsm
@@ -25,16 +25,17 @@ const log = Cu.import("resource://gre/mo
 const WEBCHANNEL_ID = "account_updates";
 
 const COMMAND_LOADED               = "fxaccounts:loaded";
 const COMMAND_CAN_LINK_ACCOUNT     = "fxaccounts:can_link_account";
 const COMMAND_LOGIN                = "fxaccounts:login";
 const COMMAND_CHANGE_PASSWORD      = "fxaccounts:change_password";
 const COMMAND_DELETE_ACCOUNT       = "fxaccounts:delete_account";
 const COMMAND_PROFILE_CHANGE       = "profile:change";
+const COMMAND_SYNC_PREFERENCES     = "fxaccounts:sync_preferences";
 
 const PREF_LAST_FXA_USER           = "identity.fxaccounts.lastSignedInUserHash";
 
 XPCOMUtils.defineLazyGetter(this, "strings",
                             () => Services.strings.createBundle("chrome://browser/locale/aboutAccounts.properties")); /*global strings */
 
 Object.defineProperty(this, "NativeWindow",
                       { get: () => Services.wm.getMostRecentWindow("navigator:browser").NativeWindow }); /*global NativeWindow */
@@ -345,16 +346,23 @@ this.FxAccountsWebChannel.prototype = {
               }
               return Accounts.notifyFirefoxAccountProfileChanged();
             })
             .catch(e => {
               log.e(e.toString());
             });
             break;
 
+          case COMMAND_SYNC_PREFERENCES:
+            Accounts.showSyncPreferences()
+            .catch(e => {
+              log.e(e.toString());
+            });
+            break;
+
           default:
             log.w("Ignoring unrecognized FxAccountsWebChannel command: " + JSON.stringify(command));
             break;
         }
       }
     };
 
     this._channelCallback = listener;