OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/accessibility/automation_manager_views.h" | 5 #include "chrome/browser/ui/views/accessibility/automation_manager_views.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | |
10 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
11 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/extensions/api/automation_internal/automation_util.h" | 11 #include "chrome/browser/extensions/api/automation_internal/automation_util.h" |
13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/profiles/profile_manager.h" | 13 #include "chrome/browser/profiles/profile_manager.h" |
15 #include "chrome/common/chrome_switches.h" | |
16 #include "content/public/browser/ax_event_notification_details.h" | 14 #include "content/public/browser/ax_event_notification_details.h" |
15 #include "ui/views/accessibility/ax_aura_obj_cache.h" | |
16 #include "ui/views/accessibility/ax_aura_obj_wrapper.h" | |
17 #include "ui/views/view.h" | 17 #include "ui/views/view.h" |
18 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
19 | 19 |
20 // static | 20 // static |
21 AutomationManagerViews* AutomationManagerViews::GetInstance() { | 21 AutomationManagerViews* AutomationManagerViews::GetInstance() { |
22 return Singleton<AutomationManagerViews>::get(); | 22 return Singleton<AutomationManagerViews>::get(); |
23 } | 23 } |
24 | 24 |
25 void AutomationManagerViews::Enable() { | |
26 enabled_ = true; | |
27 if (current_tree_serializer_.get()) | |
aboxhall
2014/04/28 19:50:38
Why reset when Enable() is called, rather than Dis
David Tseng
2014/04/29 01:35:03
In case Enable() gets called by multiple clients.
| |
28 current_tree_serializer_->Reset(); | |
29 } | |
30 | |
31 void AutomationManagerViews::Disable() { | |
32 enabled_ = false; | |
33 } | |
34 | |
25 void AutomationManagerViews::HandleEvent(Profile* profile, | 35 void AutomationManagerViews::HandleEvent(Profile* profile, |
26 views::View* view, | 36 views::View* view, |
27 ui::AXEvent event_type) { | 37 ui::AXEvent event_type) { |
28 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 38 if (!enabled_) { |
29 switches::kEnableAutomationAPI)) { | |
30 return; | 39 return; |
31 } | 40 } |
32 | 41 |
33 // TODO(dtseng): Events should only be delivered to extensions with the | 42 // TODO(dtseng): Events should only be delivered to extensions with the |
34 // desktop permission. | 43 // desktop permission. |
35 views::Widget* widget = view->GetWidget(); | 44 views::Widget* widget = view->GetWidget(); |
36 if (!widget) | 45 if (!widget) |
37 return; | 46 return; |
38 | 47 |
39 if (!profile && g_browser_process->profile_manager()) { | 48 if (!profile && g_browser_process->profile_manager()) { |
40 profile = g_browser_process->profile_manager()->GetLastUsedProfile(); | 49 profile = g_browser_process->profile_manager()->GetLastUsedProfile(); |
41 } | 50 } |
42 if (!profile) { | 51 if (!profile) { |
43 LOG(WARNING) << "Accessibility notification but no profile"; | 52 LOG(WARNING) << "Accessibility notification but no profile"; |
44 return; | 53 return; |
45 } | 54 } |
46 | 55 |
47 if (!current_tree_.get() || | 56 if (!current_tree_.get()) { |
48 current_tree_->GetRoot()->GetWidget() != widget) { | 57 current_tree_.reset(new AXTreeSourceViews()); |
49 current_tree_.reset(new views::AXTreeSourceViews(widget)); | |
50 current_tree_serializer_.reset( | 58 current_tree_serializer_.reset( |
51 new ui::AXTreeSerializer<views::View*>(current_tree_.get())); | 59 new ui::AXTreeSerializer<views::AXAuraObjWrapper*>( |
52 // TODO(dtseng): Need to send a load complete and clear any previous desktop | 60 current_tree_.get())); |
53 // trees. | |
54 } | 61 } |
55 | 62 |
56 ui::AXTreeUpdate out_update; | 63 ui::AXTreeUpdate out_update; |
57 current_tree_serializer_->SerializeChanges(view, &out_update); | 64 views::AXAuraObjWrapper* obj = |
aboxhall
2014/04/28 19:50:38
Could we call this aura_obj or similar?
David Tseng
2014/04/29 01:35:03
Done.
| |
65 views::AXAuraObjCache::GetInstance()->GetOrCreate(view); | |
66 current_tree_serializer_->SerializeChanges(obj, &out_update); | |
58 | 67 |
59 // Route this event to special process/routing ids recognized by the | 68 // Route this event to special process/routing ids recognized by the |
60 // Automation API as the desktop tree. | 69 // Automation API as the desktop tree. |
61 | |
62 // TODO(dtseng): Would idealy define these special desktop constants in idl. | 70 // TODO(dtseng): Would idealy define these special desktop constants in idl. |
63 content::AXEventNotificationDetails detail(out_update.nodes, | 71 content::AXEventNotificationDetails detail(out_update.nodes, |
64 event_type, | 72 event_type, |
65 current_tree_->GetId(view), | 73 obj->GetID(), |
66 0, /* process_id */ | 74 0, /* process_id */ |
67 0 /* routing_id */); | 75 0 /* routing_id */); |
68 std::vector<content::AXEventNotificationDetails> details; | 76 std::vector<content::AXEventNotificationDetails> details; |
69 details.push_back(detail); | 77 details.push_back(detail); |
70 extensions::automation_util::DispatchAccessibilityEventsToAutomation( | 78 extensions::automation_util::DispatchAccessibilityEventsToAutomation( |
71 details, profile); | 79 details, profile); |
72 } | 80 } |
73 | 81 |
74 AutomationManagerViews::AutomationManagerViews() {} | 82 AutomationManagerViews::AutomationManagerViews() : enabled_(false) {} |
75 | 83 |
76 AutomationManagerViews:: ~AutomationManagerViews() {} | 84 AutomationManagerViews:: ~AutomationManagerViews() {} |
OLD | NEW |