Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3134)

Unified Diff: chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_arc_home_service.cc

Issue 2768093005: Send voice interaction structure from cros to Arc. (Closed)
Patch Set: address trybot error Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_arc_home_service.cc
diff --git a/chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_arc_home_service.cc b/chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_arc_home_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..88a94484cbbd714db177841ae8dd80f660c965f0
--- /dev/null
+++ b/chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_arc_home_service.cc
@@ -0,0 +1,126 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_arc_home_service.h"
+
+#include <utility>
+#include <vector>
+
+#include "ash/common/wm_shell.h"
+#include "ash/shell.h"
+#include "base/logging.h"
+#include "base/strings/string16.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "components/arc/arc_bridge_service.h"
+#include "components/arc/instance_holder.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/voice_interaction_helper.h"
+#include "ui/aura/window.h"
+#include "ui/snapshot/snapshot.h"
+#include "ui/wm/public/activation_client.h"
+
+namespace arc {
+
+namespace {
+
+void CreateVoiceInteractionStructure(
xiyuan 2017/04/03 19:01:07 Why not use mojo typemapping ?
Muyuan 2017/04/03 20:25:35 The idea here is to try to share the code with htt
xiyuan 2017/04/03 21:32:11 Can you add a comment to document the intention?
Muyuan 2017/04/03 23:00:33 Done.
+ mojom::VoiceInteractionStructurePtr& structure,
xiyuan 2017/04/03 19:01:07 Prefer to make the function to return VoiceInterac
Muyuan 2017/04/03 20:25:35 Done.
+ const content::AXViewStructure* view_structure) {
+ structure->text = view_structure->text;
+ structure->text_size = view_structure->text_size;
+
+ structure->bold = view_structure->bold;
+ structure->italic = view_structure->italic;
+ structure->underline = view_structure->underline;
+ structure->line_through = view_structure->line_through;
+ structure->color = view_structure->color;
+ structure->bgcolor = view_structure->bgcolor;
+
+ structure->class_name = view_structure->class_name;
+ structure->rect = view_structure->rect;
+
+ if (view_structure->has_selection) {
+ auto selection = mojom::TextSelection::New();
+ selection->start_selection = view_structure->start_selection;
+ selection->end_selection = view_structure->end_selection;
+ structure->selection = std::move(selection);
+ }
+ for (auto& child : view_structure->children) {
+ auto c = mojom::VoiceInteractionStructure::New();
+ CreateVoiceInteractionStructure(c, child.get());
+ structure->children.push_back(std::move(c));
+ }
+}
+
+void RequestVoiceInteractionStructureCallback(
+ const base::Callback<void(mojom::VoiceInteractionStructurePtr)>& callback,
+ const content::AXViewStructure* result) {
+ auto structure = mojom::VoiceInteractionStructure::New();
+ if (result != nullptr)
+ CreateVoiceInteractionStructure(structure, result);
+ callback.Run(std::move(structure));
+}
+
+} // namespace
+
+ArcVoiceInteractionArcHomeService::ArcVoiceInteractionArcHomeService(
+ ArcBridgeService* bridge_service)
+ : ArcService(bridge_service), binding_(this) {
+ arc_bridge_service()->voice_interaction_arc_home()->AddObserver(this);
+}
+
+ArcVoiceInteractionArcHomeService::~ArcVoiceInteractionArcHomeService() {
+ arc_bridge_service()->voice_interaction_arc_home()->RemoveObserver(this);
+}
+
+void ArcVoiceInteractionArcHomeService::OnInstanceReady() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ mojom::VoiceInteractionArcHomeInstance* home_instance =
+ ARC_GET_INSTANCE_FOR_METHOD(
+ arc_bridge_service()->voice_interaction_arc_home(), Init);
+ DCHECK(home_instance);
+ home_instance->Init(binding_.CreateInterfacePtrAndBind());
+}
+
+void ArcVoiceInteractionArcHomeService::OnInstanceClosed() {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+}
+
+void ArcVoiceInteractionArcHomeService::GetVoiceInteractionStructure(
+ const GetVoiceInteractionStructureCallback& callback) {
+ auto structure = mojom::VoiceInteractionStructure::New();
xiyuan 2017/04/03 19:01:07 nit: is this used?
Muyuan 2017/04/03 20:25:35 Done.
+ aura::client::ActivationClient* activation_client =
xiyuan 2017/04/03 19:01:07 nit: get rid of |activation_client| and inline it
Muyuan 2017/04/03 20:25:35 Done.
+ ash::Shell::GetInstance()->activation_client();
+ aura::Window* focused = activation_client->GetActiveWindow();
+ if (!focused) {
+ callback.Run(mojom::VoiceInteractionStructure::New());
+ return;
+ }
+ Browser* browser = BrowserList::GetInstance()->GetLastActive();
+ if (!browser || browser->window()->GetNativeWindow() != focused) {
xiyuan 2017/04/03 19:01:07 Can we use browser->window()->IsActive() instead?
Muyuan 2017/04/03 20:25:35 Done.
+ // TODO(muyuanli): retrieve context for apps.
+ LOG(ERROR) << "Retrieving context from apps is not implemented.";
+ callback.Run(mojom::VoiceInteractionStructure::New());
+ return;
+ }
+
+ content::WebContents* web_contents =
+ browser->tab_strip_model()->GetActiveWebContents();
+ // Do not process incognito tab.
+ if (web_contents->GetBrowserContext()->IsOffTheRecord()) {
+ callback.Run(mojom::VoiceInteractionStructure::New());
+ return;
+ }
+
+ content::GetAXViewStructure(
+ web_contents,
+ base::Bind(&RequestVoiceInteractionStructureCallback, callback));
+}
+
+} // namespace arc

Powered by Google App Engine
This is Rietveld 408576698