Commit 7a12e222 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Chromium LUCI CQ

[Autofill Assistant] Introduce a new SEND_FEEDBACK chip type.

This CL introduces a new SEND_FEEDBACK chip type that shows the feedback
form when it is selected.

This new chip type can only be used inside a Prompt atm, but follow-up
CLs will expose the feedback chip for more use cases (e.g. client
errors).

Bug: b/173401004
Change-Id: Idea938ed9f3706ab88be7da2bcf1c34be5a3eb5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2617923Reviewed-by: default avatarClemens Arbesser <arbesser@google.com>
Commit-Queue: Jordan Demeulenaere <jdemeulenaere@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841488}
parent acc5fa20
...@@ -384,6 +384,20 @@ public class AutofillAssistantUiController { ...@@ -384,6 +384,20 @@ public class AutofillAssistantUiController {
return chip; return chip;
} }
/**
* Creates a feedback button button. It shows the feedback form and then *directly* executes
* {@code actionIndex}.
*/
@CalledByNative
private AssistantChip createFeedbackButton(int icon, String text, int actionIndex,
boolean disabled, boolean sticky, boolean visible,
@Nullable String contentDescription) {
AssistantChip chip = AssistantChip.createHairlineAssistantChip(
icon, text, disabled, sticky, visible, contentDescription);
chip.setSelectedListener(() -> safeNativeOnFeedbackButtonClicked(actionIndex));
return chip;
}
// TODO(arbesser): Remove this and use methods in {@code AssistantChip} instead. // TODO(arbesser): Remove this and use methods in {@code AssistantChip} instead.
@CalledByNative @CalledByNative
private static void appendChipToList(List<AssistantChip> chips, AssistantChip chip) { private static void appendChipToList(List<AssistantChip> chips, AssistantChip chip) {
...@@ -461,6 +475,13 @@ public class AutofillAssistantUiController { ...@@ -461,6 +475,13 @@ public class AutofillAssistantUiController {
} }
} }
private void safeNativeOnFeedbackButtonClicked(int index) {
if (mNativeUiController != 0) {
AutofillAssistantUiControllerJni.get().onFeedbackButtonClicked(
mNativeUiController, AutofillAssistantUiController.this, index);
}
}
private void safeNativeOnKeyboardVisibilityChanged(boolean visible) { private void safeNativeOnKeyboardVisibilityChanged(boolean visible) {
if (mNativeUiController != 0) { if (mNativeUiController != 0) {
AutofillAssistantUiControllerJni.get().onKeyboardVisibilityChanged( AutofillAssistantUiControllerJni.get().onKeyboardVisibilityChanged(
...@@ -503,6 +524,8 @@ public class AutofillAssistantUiController { ...@@ -503,6 +524,8 @@ public class AutofillAssistantUiController {
long nativeUiControllerAndroid, AutofillAssistantUiController caller, int index); long nativeUiControllerAndroid, AutofillAssistantUiController caller, int index);
void onCloseButtonClicked( void onCloseButtonClicked(
long nativeUiControllerAndroid, AutofillAssistantUiController caller); long nativeUiControllerAndroid, AutofillAssistantUiController caller);
void onFeedbackButtonClicked(
long nativeUiControllerAndroid, AutofillAssistantUiController caller, int index);
void onKeyboardVisibilityChanged(long nativeUiControllerAndroid, void onKeyboardVisibilityChanged(long nativeUiControllerAndroid,
AutofillAssistantUiController caller, boolean visible); AutofillAssistantUiController caller, boolean visible);
void setVisible(long nativeUiControllerAndroid, AutofillAssistantUiController caller, void setVisible(long nativeUiControllerAndroid, AutofillAssistantUiController caller,
......
...@@ -751,6 +751,18 @@ void UiControllerAndroid::UpdateActions( ...@@ -751,6 +751,18 @@ void UiControllerAndroid::UpdateActions(
: nullptr); : nullptr);
break; break;
case FEEDBACK_ACTION:
// A "Send feedback" button which will show the feedback form before
// executing the action.
jchip = Java_AutofillAssistantUiController_createFeedbackButton(
env, java_object_, chip.icon,
ConvertUTF8ToJavaString(env, chip.text), i, !action.enabled(),
chip.sticky, chip.visible,
chip.is_content_description_set
? ConvertUTF8ToJavaString(env, chip.content_description)
: nullptr);
break;
case CANCEL_ACTION: case CANCEL_ACTION:
// A Cancel button sneaks in an UNDO snackbar before executing the // A Cancel button sneaks in an UNDO snackbar before executing the
// action, while a close button behaves like a normal button. // action, while a close button behaves like a normal button.
...@@ -856,6 +868,22 @@ void UiControllerAndroid::OnCloseButtonClicked( ...@@ -856,6 +868,22 @@ void UiControllerAndroid::OnCloseButtonClicked(
DestroySelf(); DestroySelf();
} }
void UiControllerAndroid::OnFeedbackButtonClicked(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
jint index) {
// Show the feedback form then directly run the associated action.
// Unfortunately there is no way to associate a callback to run after the user
// actually sent (or close) the form, so we have to continue directly after
// showing it. It should be good enough, given that in most use cases we will
// directly stop.
Java_AutofillAssistantUiController_showFeedback(
env, java_object_,
ConvertUTF8ToJavaString(env, ui_delegate_->GetDebugContext()));
OnUserActionSelected(env, jcaller, index);
}
void UiControllerAndroid::OnKeyboardVisibilityChanged( void UiControllerAndroid::OnKeyboardVisibilityChanged(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller, const base::android::JavaParamRef<jobject>& jcaller,
......
...@@ -194,6 +194,10 @@ class UiControllerAndroid : public ControllerObserver { ...@@ -194,6 +194,10 @@ class UiControllerAndroid : public ControllerObserver {
void OnCloseButtonClicked( void OnCloseButtonClicked(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller); const base::android::JavaParamRef<jobject>& jcaller);
void OnFeedbackButtonClicked(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
jint actionIndex);
void OnKeyboardVisibilityChanged( void OnKeyboardVisibilityChanged(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller, const base::android::JavaParamRef<jobject>& jcaller,
......
...@@ -445,6 +445,7 @@ base::android::ScopedJavaLocalRef<jobject> CreateJavaAssistantChip( ...@@ -445,6 +445,7 @@ base::android::ScopedJavaLocalRef<jobject> CreateJavaAssistantChip(
case NORMAL_ACTION: case NORMAL_ACTION:
case CANCEL_ACTION: case CANCEL_ACTION:
case CLOSE_ACTION: case CLOSE_ACTION:
case FEEDBACK_ACTION:
return Java_AssistantChip_createHairlineAssistantChip( return Java_AssistantChip_createHairlineAssistantChip(
env, chip.icon(), env, chip.icon(),
base::android::ConvertUTF8ToJavaString(env, chip.text()), base::android::ConvertUTF8ToJavaString(env, chip.text()),
......
...@@ -271,6 +271,12 @@ enum ChipType { ...@@ -271,6 +271,12 @@ enum ChipType {
// HIGHLIGHTED_ACTION. // HIGHLIGHTED_ACTION.
DONE_ACTION = 6; DONE_ACTION = 6;
// A "Send feedback" chip, which will show the feedback form when clicked.
//
// Note that when this is used inside a script, we will continue the script
// normally once the user has clicked the chip.
FEEDBACK_ACTION = 7;
reserved 2; reserved 2;
} }
......
...@@ -117,6 +117,7 @@ ActionResponseType GetActionResponseType(const ProcessedActionProto& proto) { ...@@ -117,6 +117,7 @@ ActionResponseType GetActionResponseType(const ProcessedActionProto& proto) {
case HIGHLIGHTED_ACTION: case HIGHLIGHTED_ACTION:
case NORMAL_ACTION: case NORMAL_ACTION:
case CANCEL_ACTION: case CANCEL_ACTION:
case FEEDBACK_ACTION:
return ActionResponseType::UNKNOWN; return ActionResponseType::UNKNOWN;
case CLOSE_ACTION: case CLOSE_ACTION:
return ActionResponseType::PROMPT_CLOSE; return ActionResponseType::PROMPT_CLOSE;
......
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