OLD | NEW |
| (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/views/accessibility/automation_manager_views.h" | |
6 | |
7 #include <vector> | |
8 | |
9 #include "base/command_line.h" | |
10 #include "base/memory/singleton.h" | |
11 #include "chrome/browser/browser_process.h" | |
12 #include "chrome/browser/extensions/api/automation_internal/automation_util.h" | |
13 #include "chrome/browser/profiles/profile.h" | |
14 #include "chrome/browser/profiles/profile_manager.h" | |
15 #include "chrome/common/chrome_switches.h" | |
16 #include "content/public/browser/ax_event_notification_details.h" | |
17 #include "ui/views/view.h" | |
18 #include "ui/views/widget/widget.h" | |
19 | |
20 // static | |
21 AutomationManagerViews* AutomationManagerViews::GetInstance() { | |
22 return Singleton<AutomationManagerViews>::get(); | |
23 } | |
24 | |
25 void AutomationManagerViews::HandleEvent(Profile* profile, | |
26 views::View* view, | |
27 ui::AXEvent event_type) { | |
28 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
29 switches::kEnableAutomationAPI)) { | |
30 return; | |
31 } | |
32 | |
33 // TODO(dtseng): Events should only be delivered to extensions with the | |
34 // desktop permission. | |
35 views::Widget* widget = view->GetWidget(); | |
36 if (!widget) | |
37 return; | |
38 | |
39 if (!profile && g_browser_process->profile_manager()) { | |
40 profile = g_browser_process->profile_manager()->GetLastUsedProfile(); | |
41 } | |
42 if (!profile) { | |
43 LOG(WARNING) << "Accessibility notification but no profile"; | |
44 return; | |
45 } | |
46 | |
47 if (!current_tree_.get() || | |
48 current_tree_->GetRoot()->GetWidget() != widget) { | |
49 current_tree_.reset(new views::AXTreeSourceViews(widget)); | |
50 current_tree_serializer_.reset( | |
51 new ui::AXTreeSerializer<views::View*>(current_tree_.get())); | |
52 // TODO(dtseng): Need to send a load complete and clear any previous desktop | |
53 // trees. | |
54 } | |
55 | |
56 ui::AXTreeUpdate out_update; | |
57 current_tree_serializer_->SerializeChanges(view, &out_update); | |
58 | |
59 // Route this event to special process/routing ids recognized by the | |
60 // Automation API as the desktop tree. | |
61 | |
62 // TODO(dtseng): Would idealy define these special desktop constants in idl. | |
63 content::AXEventNotificationDetails detail(out_update.nodes, | |
64 event_type, | |
65 current_tree_->GetId(view), | |
66 0, /* process_id */ | |
67 0 /* routing_id */); | |
68 std::vector<content::AXEventNotificationDetails> details; | |
69 details.push_back(detail); | |
70 extensions::automation_util::DispatchAccessibilityEventsToAutomation( | |
71 details, profile); | |
72 } | |
73 | |
74 AutomationManagerViews::AutomationManagerViews() {} | |
75 | |
76 AutomationManagerViews:: ~AutomationManagerViews() {} | |
OLD | NEW |