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

Side by Side Diff: chrome/browser/ui/ash/accessibility/automation_manager_ash.cc

Issue 1003283002: Enable chrome.automation.getDesktop on all aura platforms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Actions. Created 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/ash/accessibility/automation_manager_ash.h"
6
7 #include <vector>
8
9 #include "base/memory/singleton.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/extensions/api/automation_internal/automation_util.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "content/public/browser/ax_event_notification_details.h"
14 #include "content/public/browser/browser_context.h"
15 #include "ui/aura/window.h"
16 #include "ui/views/accessibility/ax_aura_obj_cache.h"
17 #include "ui/views/accessibility/ax_aura_obj_wrapper.h"
18 #include "ui/views/view.h"
19 #include "ui/views/widget/widget.h"
20
21 using content::BrowserContext;
22
23 // static
24 AutomationManagerAsh* AutomationManagerAsh::GetInstance() {
25 return Singleton<AutomationManagerAsh>::get();
26 }
27
28 void AutomationManagerAsh::Enable(BrowserContext* context) {
29 enabled_ = true;
30 if (!current_tree_.get())
31 current_tree_.reset(new AXTreeSourceAsh());
32 ResetSerializer();
33 SendEvent(context, current_tree_->GetRoot(), ui::AX_EVENT_LOAD_COMPLETE);
34 if (!pending_alert_text_.empty()) {
35 HandleAlert(context, pending_alert_text_);
36 pending_alert_text_.clear();
37 }
38 }
39
40 void AutomationManagerAsh::Disable() {
41 enabled_ = false;
42
43 // Reset the serializer to save memory.
44 current_tree_serializer_->Reset();
45 }
46
47 void AutomationManagerAsh::HandleEvent(BrowserContext* context,
48 views::View* view,
49 ui::AXEvent event_type) {
50 if (!enabled_)
51 return;
52
53 if (!context && g_browser_process->profile_manager())
54 context = g_browser_process->profile_manager()->GetLastUsedProfile();
55
56 if (!context) {
57 LOG(WARNING) << "Accessibility notification but no browser context";
58 return;
59 }
60
61 views::AXAuraObjWrapper* aura_obj =
62 views::AXAuraObjCache::GetInstance()->GetOrCreate(view);
63 SendEvent(context, aura_obj, event_type);
64 }
65
66 void AutomationManagerAsh::HandleAlert(content::BrowserContext* context,
67 const std::string& text) {
68 if (!enabled_) {
69 pending_alert_text_ = text;
70 return;
71 }
72
73 views::AXAuraObjWrapper* obj =
74 static_cast<AXRootObjWrapper*>(current_tree_->GetRoot())
75 ->GetAlertForText(text);
76 SendEvent(context, obj, ui::AX_EVENT_ALERT);
77 }
78
79 void AutomationManagerAsh::DoDefault(int32 id) {
80 CHECK(enabled_);
81 current_tree_->DoDefault(id);
82 }
83
84 void AutomationManagerAsh::Focus(int32 id) {
85 CHECK(enabled_);
86 current_tree_->Focus(id);
87 }
88
89 void AutomationManagerAsh::MakeVisible(int32 id) {
90 CHECK(enabled_);
91 current_tree_->MakeVisible(id);
92 }
93
94 void AutomationManagerAsh::SetSelection(int32 id, int32 start, int32 end) {
95 CHECK(enabled_);
96 current_tree_->SetSelection(id, start, end);
97 }
98
99 AutomationManagerAsh::AutomationManagerAsh() : enabled_(false) {
100 }
101
102 AutomationManagerAsh::~AutomationManagerAsh() {}
103
104 void AutomationManagerAsh::ResetSerializer() {
105 current_tree_serializer_.reset(
106 new ui::AXTreeSerializer<views::AXAuraObjWrapper*>(
107 current_tree_.get()));
108 }
109
110 void AutomationManagerAsh::SendEvent(BrowserContext* context,
111 views::AXAuraObjWrapper* aura_obj,
112 ui::AXEvent event_type) {
113 ui::AXTreeUpdate update;
114 current_tree_serializer_->SerializeChanges(aura_obj, &update);
115
116 // Route this event to special process/routing ids recognized by the
117 // Automation API as the desktop tree.
118 // TODO(dtseng): Would idealy define these special desktop constants in idl.
119 content::AXEventNotificationDetails detail(update.node_id_to_clear,
120 update.nodes,
121 event_type,
122 aura_obj->GetID(),
123 0, /* process_id */
124 0 /* routing_id */);
125 std::vector<content::AXEventNotificationDetails> details;
126 details.push_back(detail);
127 extensions::automation_util::DispatchAccessibilityEventsToAutomation(
128 details, context, gfx::Vector2d());
129 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698