Commit 8b8c29c2 authored by wutao's avatar wutao Committed by Commit Bot

assistant: Add button support in notification UI

This is UI side code to handle buttons in assistant notification.

Bug: b/117295934
Test: manual.
Change-Id: I61144f418ba7af127c09892707ba442e8c5f5e65
Reviewed-on: https://chromium-review.googlesource.com/c/1274826
Commit-Queue: Tao Wu <wutao@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600129}
parent 7ae9eb4e
......@@ -5,6 +5,7 @@
#include "ash/assistant/assistant_notification_controller.h"
#include "ash/assistant/assistant_controller.h"
#include "ash/assistant/util/deep_link_util.h"
#include "ash/new_window_controller.h"
#include "ash/public/cpp/vector_icons/vector_icons.h"
#include "ash/public/interfaces/voice_interaction_controller.mojom.h"
......@@ -54,16 +55,27 @@ class AssistantNotificationDelegate
void Click(const base::Optional<int>& button_index,
const base::Optional<base::string16>& reply) override {
const auto& action_url =
button_index.has_value()
? notification_->buttons[button_index.value()]->action_url
: notification_->action_url;
// Open the action url if it is valid.
if (notification_->action_url.is_valid() && assistant_controller_) {
assistant_controller_->OpenUrl(notification_->action_url);
if (action_url.is_valid() &&
(action_url.SchemeIsHTTPOrHTTPS() ||
assistant::util::IsDeepLinkUrl(action_url)) &&
assistant_controller_) {
assistant_controller_->OpenUrl(action_url);
Close(/*by_user=*/true);
return;
}
if (notification_controller_) {
// TODO(wutao): support buttons with different |action_index|.
// Action index 0 is the top level action and the first button's action
// index is 1.
const int action_index =
button_index.has_value() ? button_index.value() + 1 : 0;
notification_controller_->RetrieveNotification(notification_.Clone(),
/*action_index=*/0);
action_index);
}
}
......@@ -138,13 +150,17 @@ void AssistantNotificationController::OnShowNotification(
message_center::MessageCenter* message_center =
message_center::MessageCenter::Get();
message_center::RichNotificationData optional_field;
message_center::RichNotificationData data;
for (const auto& button : notification->buttons) {
data.buttons.push_back(
message_center::ButtonInfo(base::UTF8ToUTF16(button->label)));
}
std::unique_ptr<message_center::Notification> system_notification =
message_center::Notification::CreateSystemNotification(
message_center::NOTIFICATION_TYPE_SIMPLE,
GetNotificationId(notification->grouping_key), title, message,
display_source, GURL(), notifier_id_, optional_field,
display_source, GURL(), notifier_id_, data,
new AssistantNotificationDelegate(weak_factory_.GetWeakPtr(),
assistant_controller_->GetWeakPtr(),
notification.Clone()),
......
......@@ -441,6 +441,10 @@ void AssistantManagerServiceImpl::OnShowNotification(
notification_ptr->opaque_token = notification.opaque_token;
notification_ptr->grouping_key = notification.grouping_key;
notification_ptr->obfuscated_gaia_id = notification.obfuscated_gaia_id;
for (const auto& button : notification.buttons) {
notification_ptr->buttons.push_back(mojom::AssistantNotificationButton::New(
button.label, GURL(button.action_url)));
}
main_thread_task_runner_->PostTask(
FROM_HERE,
......
......@@ -45,9 +45,12 @@ interface Assistant {
AssistantNotificationSubscriber subscriber);
// Retrieves a notification. A voiceless interaction will be sent to server to
// retrieve the notification payload, which can trigger other assistant's
// events such as OnTextResponse to show the result in the UI. The reteived
// notification will be removed from the UI.
// retrieve the notification of |action_index|, which can trigger other
// Assistant events such as OnTextResponse to show the result in the UI. The
// retrieved notification will be removed from the UI.
// |action_index| is the index of the tapped action. The main UI in the
// notification contains the top level action, which index is 0. The buttons
// have the additional actions, which are indexed starting from 1.
RetrieveNotification(AssistantNotification notification, int32 action_index);
// Dismisses a notification.
......@@ -184,6 +187,15 @@ struct AssistantSuggestion {
url.mojom.Url action_url;
};
// Models a notification button.
struct AssistantNotificationButton {
// Display text of the button.
string label;
// Optional URL to open when the tap action is invoked on the button.
url.mojom.Url action_url;
};
// Models an Assistant notification.
struct AssistantNotification {
// Title of the notification.
......@@ -192,9 +204,13 @@ struct AssistantNotification {
// Body text of the notification.
string message;
// URL to open when the tap action is invoked on the notification.
// Optional URL to open when the tap action is invoked on the notification
// main UI.
url.mojom.Url action_url;
// List of buttons in the notification.
array<AssistantNotificationButton> buttons;
// An id that uniquely identifies a notification.
string notification_id;
......
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