Commit 5a0f20b7 authored by Li Lin's avatar Li Lin Committed by Commit Bot

Launch Assistant when clicks on Quick Answers.

Bug: 1044413
Test: Manual
Change-Id: I59eb13ef6e80c72c49eb9c8271ed9f70c063a9aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2014120Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Li Lin <llin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734207}
parent f7909ba3
......@@ -6,12 +6,14 @@
#include <utility>
#include "ash/public/cpp/assistant/assistant_interface_binder.h"
#include "base/strings/utf_string_conversions.h"
#include "build/branding_buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/profiles/profile.h"
#include "chromeos/components/quick_answers/quick_answers_model.h"
#include "chromeos/services/assistant/public/mojom/assistant.mojom.h"
#include "components/renderer_context_menu/render_view_context_menu_proxy.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/context_menu_params.h"
......@@ -76,6 +78,7 @@ void QuickAnswersMenuObserver::InitMenu(
// Fetch Quick Answer.
QuickAnswersRequest request;
request.selected_text = selected_text;
query_ = request.selected_text;
quick_answers_client_->SendRequest(request);
}
......@@ -93,7 +96,8 @@ bool QuickAnswersMenuObserver::IsCommandIdEnabled(int command_id) {
}
void QuickAnswersMenuObserver::ExecuteCommand(int command_id) {
// TODO(llin): Implements Quick Answers click action.
if (command_id == IDC_CONTENT_CONTEXT_QUICK_ANSWERS_INLINE_QUERY)
SendAssistantQuery(query_);
}
void QuickAnswersMenuObserver::OnQuickAnswerReceived(
......@@ -132,3 +136,13 @@ void QuickAnswersMenuObserver::SetQuickAnswerClientForTesting(
quick_answers_client) {
quick_answers_client_ = std::move(quick_answers_client);
}
void QuickAnswersMenuObserver::SendAssistantQuery(const std::string& query) {
mojo::Remote<chromeos::assistant::mojom::AssistantController>
assistant_controller;
ash::AssistantInterfaceBinder::GetInstance()->BindController(
assistant_controller.BindNewPipeAndPassReceiver());
assistant_controller->StartTextInteraction(
query, /*allow_tts=*/false,
chromeos::assistant::mojom::AssistantQuerySource::kQuickAnswers);
}
......@@ -41,6 +41,8 @@ class QuickAnswersMenuObserver
quick_answers_client);
private:
void SendAssistantQuery(const std::string& query);
// The interface to add a context-menu item and update it.
RenderViewContextMenuProxy* proxy_;
......@@ -50,6 +52,9 @@ class QuickAnswersMenuObserver
// Whether the feature is enabled and all eligibility criteria are met (
// locale, consents, etc).
bool is_eligible_ = false;
// Query used to retrieve quick answer.
std::string query_;
};
#endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_QUICK_ANSWERS_MENU_OBSERVER_H_
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