Commit 63aeeb23 authored by Mathias Carlen's avatar Mathias Carlen Committed by Commit Bot

[Autofill Assistant] Pass name and path to Java.

We pass the name and path of a ScriptHandle to Java using two arrays of
strings. The java side reconstructs a list of ScriptHandle and uses that
to show the script names and trigger the script using the also provided
path to it.

Bug: 806868
Change-Id: I683ea8c20086af4b9dfe874953b82d43d4677521
Reviewed-on: https://chromium-review.googlesource.com/1213087
Commit-Queue: Mathias Carlen <mcarlen@chromium.org>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590402}
parent 2d480872
......@@ -14,6 +14,9 @@ import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.TabModel.TabSelectionType;
import org.chromium.content_public.browser.WebContents;
import java.util.ArrayList;
import java.util.List;
/**
* Bridge to native side autofill_assistant::UiControllerAndroid. It allows native side to control
* Autofill Assistant related UIs and forward UI events to native side.
......@@ -82,10 +85,13 @@ public class AutofillAssistantUiController implements BottomBarController.Client
}
@CalledByNative
private void onUpdateScripts(String[] scripts) {
// TODO(crbug.com/806868): Pass a Script handle instead of a string so that we can report
// back what script got selected.
mBottomBarController.updateScripts(scripts);
private void onUpdateScripts(String[] scriptNames, String[] scriptPaths) {
List<BottomBarController.ScriptHandle> scriptHandles = new ArrayList<>();
// Note that scriptNames and scriptPaths are one-on-one matched by index.
for (int i = 0; i < scriptNames.length; i++) {
scriptHandles.add(new BottomBarController.ScriptHandle(scriptNames[i], scriptPaths[i]));
}
mBottomBarController.updateScripts(scriptHandles);
}
// native methods.
......
......@@ -16,6 +16,8 @@ import android.widget.TextView;
import org.chromium.chrome.R;
import java.util.List;
import javax.annotation.Nullable;
/** Controller to interact with the bottom bar. */
......@@ -42,6 +44,32 @@ class BottomBarController {
void onScriptSelected(String scriptPath);
}
/**
* Java side equivalent of autofill_assistant::ScriptHandle.
*/
protected static class ScriptHandle {
/** The display name of this script. */
private final String mName;
/** The script path. */
private final String mPath;
/** Constructor. */
public ScriptHandle(String name, String path) {
mName = name;
mPath = path;
}
/** Returns the display name. */
public String getName() {
return mName;
}
/** Returns the script path. */
public String getPath() {
return mPath;
}
}
/**
* Constructs a bottom bar.
*
......@@ -76,14 +104,15 @@ class BottomBarController {
*
* @param scripts List of scripts to show.
*/
public void updateScripts(String[] scripts) {
public void updateScripts(List<ScriptHandle> scriptHandles) {
mScriptsViewContainer.removeAllViews();
if (scripts.length == 0) {
if (scriptHandles.isEmpty()) {
return;
}
for (String script : scripts) {
TextView scriptView = createScriptView(script);
scriptView.setOnClickListener((unusedView) -> { mClient.onScriptSelected(script); });
for (ScriptHandle scriptHandle : scriptHandles) {
TextView scriptView = createScriptView(scriptHandle.getName());
scriptView.setOnClickListener(
(unusedView) -> { mClient.onScriptSelected(scriptHandle.getPath()); });
mScriptsViewContainer.addView(scriptView);
}
}
......
......@@ -63,16 +63,17 @@ void UiControllerAndroid::HideOverlay() {
void UiControllerAndroid::UpdateScripts(
const std::vector<ScriptHandle>& scripts) {
// TODO(crbug.com/806868): Pass the handles directly instead of the path.
std::vector<std::string> script_paths;
std::vector<std::string> script_names;
for (const auto& script : scripts) {
script_paths.emplace_back(script.path);
script_names.emplace_back(script.name);
}
JNIEnv* env = AttachCurrentThread();
auto jscripts = base::android::ToJavaArrayOfStrings(env, script_paths);
Java_AutofillAssistantUiController_onUpdateScripts(
env, java_autofill_assistant_ui_controller_, jscripts);
env, java_autofill_assistant_ui_controller_,
base::android::ToJavaArrayOfStrings(env, script_names),
base::android::ToJavaArrayOfStrings(env, script_paths));
}
void UiControllerAndroid::OnScriptSelected(
......
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