Commit e2c5c0bc authored by Mathias Carlen's avatar Mathias Carlen Committed by Commit Bot

[Autofill Assistant] Hook up script selection.

Connect selecting a script in the UI with the native side so that it can
be routed to the executor.

R=gogerald@chromium.org, szermatt@chromium.org

Bug: 806868
Change-Id: Icf85027c2e50a073d805dbcb3e99017ce66b5850
Reviewed-on: https://chromium-review.googlesource.com/1206373Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589719}
parent 5ed48053
...@@ -19,7 +19,7 @@ import org.chromium.content_public.browser.WebContents; ...@@ -19,7 +19,7 @@ import org.chromium.content_public.browser.WebContents;
* Autofill Assistant related UIs and forward UI events to native side. * Autofill Assistant related UIs and forward UI events to native side.
*/ */
@JNINamespace("autofill_assistant") @JNINamespace("autofill_assistant")
public class AutofillAssistantUiController { public class AutofillAssistantUiController implements BottomBarController.Client {
private final long mUiControllerAndroid; private final long mUiControllerAndroid;
private final BottomBarController mBottomBarController; private final BottomBarController mBottomBarController;
...@@ -58,7 +58,12 @@ public class AutofillAssistantUiController { ...@@ -58,7 +58,12 @@ public class AutofillAssistantUiController {
} }
}); });
mBottomBarController = new BottomBarController(activity); mBottomBarController = new BottomBarController(activity, this);
}
@Override
public void onScriptSelected(String scriptPath) {
nativeOnScriptSelected(mUiControllerAndroid, scriptPath);
} }
@CalledByNative @CalledByNative
...@@ -86,4 +91,5 @@ public class AutofillAssistantUiController { ...@@ -86,4 +91,5 @@ public class AutofillAssistantUiController {
// native methods. // native methods.
private native long nativeInit(WebContents webContents); private native long nativeInit(WebContents webContents);
private native void nativeDestroy(long nativeUiControllerAndroid); private native void nativeDestroy(long nativeUiControllerAndroid);
private native void nativeOnScriptSelected(long nativeUiControllerAndroid, String scriptPath);
} }
...@@ -23,17 +23,34 @@ class BottomBarController { ...@@ -23,17 +23,34 @@ class BottomBarController {
private static final String SCRIPTS_STATUS_MESSAGE = "Scripts"; private static final String SCRIPTS_STATUS_MESSAGE = "Scripts";
private final Activity mActivity; private final Activity mActivity;
private final Client mClient;
private final LinearLayout mBottomBar; private final LinearLayout mBottomBar;
private ViewGroup mScriptsViewContainer; private ViewGroup mScriptsViewContainer;
private TextView mStatusMessageView; private TextView mStatusMessageView;
/**
* This is a client interface that relays interactions from the UI.
*
* Java version of the native autofill_assistant::UiDelegate.
*/
public interface Client {
/**
* Called when a script has been selected.
*
* @param scriptPath The path for the selected script.
*/
void onScriptSelected(String scriptPath);
}
/** /**
* Constructs a bottom bar. * Constructs a bottom bar.
* *
* @param activity The Activity * @param activity The Activity
* @param client The client to forward events to
*/ */
public BottomBarController(Activity activity) { public BottomBarController(Activity activity, Client client) {
mActivity = activity; mActivity = activity;
mClient = client;
mBottomBar = createBottomBar(); mBottomBar = createBottomBar();
((ViewGroup) mActivity.findViewById(R.id.coordinator)).addView(mBottomBar); ((ViewGroup) mActivity.findViewById(R.id.coordinator)).addView(mBottomBar);
...@@ -64,9 +81,10 @@ class BottomBarController { ...@@ -64,9 +81,10 @@ class BottomBarController {
if (scripts.length == 0) { if (scripts.length == 0) {
return; return;
} }
for (String script : scripts) { for (String script : scripts) {
mScriptsViewContainer.addView(createScriptView(script)); TextView scriptView = createScriptView(script);
scriptView.setOnClickListener((unusedView) -> { mClient.onScriptSelected(script); });
mScriptsViewContainer.addView(scriptView);
} }
} }
......
...@@ -75,6 +75,15 @@ void UiControllerAndroid::UpdateScripts( ...@@ -75,6 +75,15 @@ void UiControllerAndroid::UpdateScripts(
env, java_autofill_assistant_ui_controller_, jscripts); env, java_autofill_assistant_ui_controller_, jscripts);
} }
void UiControllerAndroid::OnScriptSelected(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
const JavaParamRef<jstring>& jscript_path) {
std::string script_path;
base::android::ConvertJavaStringToUTF8(env, jscript_path, &script_path);
ui_delegate_->OnScriptSelected(script_path);
}
void UiControllerAndroid::ChooseAddress( void UiControllerAndroid::ChooseAddress(
base::OnceCallback<void(const std::string&)> callback) { base::OnceCallback<void(const std::string&)> callback) {
// TODO(crbug.com/806868): Implement ChooseAddress. // TODO(crbug.com/806868): Implement ChooseAddress.
......
...@@ -38,6 +38,10 @@ class UiControllerAndroid : public UiController, public Client { ...@@ -38,6 +38,10 @@ class UiControllerAndroid : public UiController, public Client {
// Called by Java. // Called by Java.
void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); void Destroy(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
void OnScriptSelected(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
const base::android::JavaParamRef<jstring>& jscript_path);
private: private:
// Java-side AutofillAssistantUiController object. // Java-side AutofillAssistantUiController object.
......
...@@ -77,6 +77,10 @@ void Controller::OnClickOverlay() { ...@@ -77,6 +77,10 @@ void Controller::OnClickOverlay() {
// TODO(crbug.com/806868): Stop executing scripts. // TODO(crbug.com/806868): Stop executing scripts.
} }
void Controller::OnScriptSelected(const std::string& script_path) {
// TODO(crbug.com/806868): Forward to the execution engine.
}
void Controller::OnDestroy() { void Controller::OnDestroy() {
delete this; delete this;
} }
......
...@@ -52,6 +52,7 @@ class Controller : public ScriptExecutorDelegate, ...@@ -52,6 +52,7 @@ class Controller : public ScriptExecutorDelegate,
// Overrides content::UiDelegate: // Overrides content::UiDelegate:
void OnClickOverlay() override; void OnClickOverlay() override;
void OnDestroy() override; void OnDestroy() override;
void OnScriptSelected(const std::string& script_path) override;
// Overrides ScriptTracker::Listener: // Overrides ScriptTracker::Listener:
void OnRunnableScriptsChanged( void OnRunnableScriptsChanged(
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_UI_DELEGATE_H_ #ifndef COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_UI_DELEGATE_H_
#define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_UI_DELEGATE_H_ #define COMPONENTS_AUTOFILL_ASSISTANT_BROWSER_UI_DELEGATE_H_
#include <string>
namespace autofill_assistant { namespace autofill_assistant {
// UI delegate called for script executions. // UI delegate called for script executions.
class UiDelegate { class UiDelegate {
...@@ -18,6 +20,9 @@ class UiDelegate { ...@@ -18,6 +20,9 @@ class UiDelegate {
// detached from the associated activity. // detached from the associated activity.
virtual void OnDestroy() = 0; virtual void OnDestroy() = 0;
// Called when a script has been selected.
virtual void OnScriptSelected(const std::string& script_path) = 0;
protected: protected:
UiDelegate() = default; UiDelegate() = default;
}; };
......
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