Commit 943ef7c0 authored by Stephane Zermatten's avatar Stephane Zermatten Committed by Commit Bot

[Autofill Assistant] Only enable when Intent contains a special parameter.

With this change, Autofill Assistant only runs when the feature is
enabled and the Intent contains:
org.chromium.chrome.browser.autofill_assistant.ENABLED.

Bug: 806868
Change-Id: I6bc81181b9f16a2d13e56ff657c6bd9076621808
Reviewed-on: https://chromium-review.googlesource.com/1254281
Commit-Queue: Stephane Zermatten <szermatt@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595754}
parent 9b0d7de6
...@@ -36,6 +36,9 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat ...@@ -36,6 +36,9 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
/** Variation url parameter name. */ /** Variation url parameter name. */
private static final String URL_PARAMETER_NAME = "url"; private static final String URL_PARAMETER_NAME = "url";
/** Special parameter that enables the feature. */
private static final String PARAMETER_ENABLED = "ENABLED";
private final long mUiControllerAndroid; private final long mUiControllerAndroid;
private final AutofillAssistantUiDelegate mUiDelegate; private final AutofillAssistantUiDelegate mUiDelegate;
...@@ -44,8 +47,9 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat ...@@ -44,8 +47,9 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
* *
* @return True if a controller can be constructed. * @return True if a controller can be constructed.
*/ */
public static boolean isConfigured() { public static boolean isConfigured(Bundle intentExtras) {
return !VariationsAssociatedData.getVariationParamValue(STUDY_NAME, URL_PARAMETER_NAME) return getBooleanParameter(intentExtras, PARAMETER_ENABLED)
&& !VariationsAssociatedData.getVariationParamValue(STUDY_NAME, URL_PARAMETER_NAME)
.isEmpty(); .isEmpty();
} }
...@@ -59,10 +63,9 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat ...@@ -59,10 +63,9 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
// nativeInit already. // nativeInit already.
mUiDelegate = new AutofillAssistantUiDelegate(activity, this); mUiDelegate = new AutofillAssistantUiDelegate(activity, this);
// TODO(crbug.com/806868): Treat parameter
// org.chromium.chrome.browser.autofill_assistant.ENABLED specially, and disable autofill
// assistant if it is false or unset.
Map<String, String> parameters = extractParameters(activity.getInitialIntent().getExtras()); Map<String, String> parameters = extractParameters(activity.getInitialIntent().getExtras());
parameters.remove(PARAMETER_ENABLED);
Tab activityTab = activity.getActivityTab(); Tab activityTab = activity.getActivityTab();
mUiControllerAndroid = nativeInit(activityTab.getWebContents(), mUiControllerAndroid = nativeInit(activityTab.getWebContents(),
parameters.keySet().toArray(new String[parameters.size()]), parameters.keySet().toArray(new String[parameters.size()]),
...@@ -105,6 +108,11 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat ...@@ -105,6 +108,11 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
nativeOnScriptSelected(mUiControllerAndroid, scriptPath); nativeOnScriptSelected(mUiControllerAndroid, scriptPath);
} }
/** Return the value if the given boolean parameter from the extras. */
private static boolean getBooleanParameter(Bundle extras, String parameterName) {
return extras.getBoolean(INTENT_EXTRA_PREFIX + parameterName, false);
}
/** Returns a map containing the extras starting with {@link #INTENT_EXTRA_PREFIX}. */ /** Returns a map containing the extras starting with {@link #INTENT_EXTRA_PREFIX}. */
private static Map<String, String> extractParameters(Bundle extras) { private static Map<String, String> extractParameters(Bundle extras) {
Map<String, String> result = new HashMap<>(); Map<String, String> result = new HashMap<>();
......
...@@ -680,11 +680,9 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent ...@@ -680,11 +680,9 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
getActivityTab().getWebContents()); getActivityTab().getWebContents());
} }
// TODO(crbug.com/806868): Only enable Autofill Assistant when the flag is enabled in the
// intent.
if (mAutofillAssistantUiController == null if (mAutofillAssistantUiController == null
&& ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT) && ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT)
&& AutofillAssistantUiController.isConfigured()) { && AutofillAssistantUiController.isConfigured(getInitialIntent().getExtras())) {
mAutofillAssistantUiController = new AutofillAssistantUiController(this); mAutofillAssistantUiController = new AutofillAssistantUiController(this);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment