Bug 1356386 - Support for FxA sign-in deep links r=nechen
Adds support for opening FxA deep links, a la firefox://fxa-signin
Whitelisted set of query parameters::
- signin - expected to be the "magic token"
- entrypoint - for internal tracking purposes
- utm_* - all query parameters with utm_ prefix are allowed
Deep links are opened as: about:accounts?signin=<token>&entrypoint=<entrypoint>&utm_one=<utm1>....
MozReview-Commit-ID: LfGi1ChPvUr
--- a/mobile/android/base/java/org/mozilla/gecko/LauncherActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/LauncherActivity.java
@@ -31,22 +31,23 @@ import static org.mozilla.gecko.deeplink
import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_PREFERENCES;
import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_PREFERENCES_ACCESSIBILITY;
import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_PREFERENCES_NOTIFICATIONS;
import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_PREFERENCES_PRIAVACY;
import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_PREFERENCES_SEARCH;
import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_SAVE_AS_PDF;
import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_SIGN_UP;
import static org.mozilla.gecko.deeplink.DeepLinkContract.SUMO_DEFAULT_BROWSER;
+import static org.mozilla.gecko.deeplink.DeepLinkContract.LINK_FXA_SIGNIN;
+import org.mozilla.gecko.deeplink.DeepLinkContract;
/**
* Activity that receives incoming Intents and dispatches them to the appropriate activities (e.g. browser, custom tabs, web app).
*/
public class LauncherActivity extends Activity {
-
private static final String TAG = LauncherActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeckoAppShell.ensureCrashHandling();
@@ -215,15 +216,56 @@ public class LauncherActivity extends Ac
case LINK_PREFERENCES_PRIAVACY:
case LINK_PREFERENCES_SEARCH:
case LINK_PREFERENCES_NOTIFICATIONS:
case LINK_PREFERENCES_ACCESSIBILITY:
settingsIntent = new Intent(this, GeckoPreferences.class);
GeckoPreferences.setResourceToOpen(settingsIntent, host);
startActivityForResult(settingsIntent, ACTIVITY_REQUEST_PREFERENCES);
break;
+ case LINK_FXA_SIGNIN:
+ dispatchAccountsDeepLink(intent);
+ break;
default:
- Log.w(TAG, "unrecognized deep links");
+ Log.w(TAG, "Unrecognized deep link");
+ }
+ }
+
+ private void dispatchAccountsDeepLink(final SafeIntent safeIntent) {
+ final Intent intent = new Intent(Intent.ACTION_VIEW);
+
+ final Uri intentUri = safeIntent.getData();
+
+ final String accountsToken = intentUri.getQueryParameter(DeepLinkContract.ACCOUNTS_TOKEN_PARAM);
+ final String entryPoint = intentUri.getQueryParameter(DeepLinkContract.ACCOUNTS_ENTRYPOINT_PARAM);
+
+ String dispatchUri = AboutPages.ACCOUNTS + "?";
+
+ // If token is missing from the deep-link, we'll still open the accounts page.
+ if (accountsToken != null) {
+ dispatchUri = dispatchUri.concat(DeepLinkContract.ACCOUNTS_TOKEN_PARAM + "=" + accountsToken + "&");
}
+ // Pass through the entrypoint.
+ if (entryPoint != null) {
+ dispatchUri = dispatchUri.concat(DeepLinkContract.ACCOUNTS_ENTRYPOINT_PARAM + "=" + entryPoint + "&");
+ }
+
+ // Pass through any utm_* parameters.
+ for (String queryParam : intentUri.getQueryParameterNames()) {
+ if (queryParam.startsWith("utm_")) {
+ dispatchUri = dispatchUri.concat(queryParam + "=" + intentUri.getQueryParameter(queryParam) + "&");
+ }
+ }
+
+ try {
+ intent.setData(Uri.parse(dispatchUri));
+ } catch (Exception e) {
+ Log.w(TAG, "Could not parse accounts deep link.");
+ }
+
+ intent.setClassName(getApplicationContext(), AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
+
+ filterFlags(intent);
+ startActivity(intent);
}
}
--- a/mobile/android/base/java/org/mozilla/gecko/deeplink/DeepLinkContract.java
+++ b/mobile/android/base/java/org/mozilla/gecko/deeplink/DeepLinkContract.java
@@ -7,20 +7,25 @@ package org.mozilla.gecko.deeplink;
// This class defines the contract when using deep links
public class DeepLinkContract {
// Sumo page for setting Fennec as default browser
public static final String SUMO_DEFAULT_BROWSER = "https://support.mozilla.org/kb/make-firefox-default-browser-android?utm_source=inproduct&utm_medium=settings&utm_campaign=mobileandroid";
public static final String DEEP_LINK_SCHEME = "firefox";
+ public static final String LINK_FXA_SIGNIN = "fxa-signin";
+
public static final String LINK_DEFAULT_BROWSER = "default_browser";
public static final String LINK_SAVE_AS_PDF = "save_as_pdf";
public static final String LINK_BOOKMARK_LIST = "bookmark_list";
public static final String LINK_HISTORY_LIST = "history_list";
public static final String LINK_SIGN_UP = "sign_up";
public static final String LINK_PREFERENCES = "preferences";
public static final String LINK_PREFERENCES_PRIAVACY = "preferences_privacy";
public static final String LINK_PREFERENCES_SEARCH = "preferences_search";
public static final String LINK_PREFERENCES_NOTIFICATIONS = "preferences_notifications";
public static final String LINK_PREFERENCES_ACCESSIBILITY = "preferences_accessibility";
+ public static final String ACCOUNTS_TOKEN_PARAM = "signin";
+ public static final String ACCOUNTS_ENTRYPOINT_PARAM = "entrypoint";
+ public static final String ACCOUNTS_UTM_PREFIX = "utm_";
}