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/extensions/api/automation_internal/automation_internal_
api.h" | 5 #include "chrome/browser/extensions/api/automation_internal/automation_internal_
api.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/extensions/api/automation_internal.h" | 14 #include "chrome/common/extensions/api/automation_internal.h" |
15 #include "content/public/browser/ax_event_notification_details.h" | 15 #include "content/public/browser/ax_event_notification_details.h" |
16 #include "content/public/browser/browser_accessibility_state.h" | 16 #include "content/public/browser/browser_accessibility_state.h" |
17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
20 #include "content/public/browser/notification_types.h" | 20 #include "content/public/browser/notification_types.h" |
| 21 #include "content/public/browser/render_process_host.h" |
21 #include "content/public/browser/render_view_host.h" | 22 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/render_widget_host.h" | 23 #include "content/public/browser/render_widget_host.h" |
| 24 #include "content/public/browser/render_widget_host.h" |
23 #include "content/public/browser/render_widget_host_view.h" | 25 #include "content/public/browser/render_widget_host_view.h" |
24 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
25 #include "extensions/browser/event_router.h" | 27 #include "extensions/browser/event_router.h" |
26 #include "extensions/browser/extension_system.h" | 28 #include "extensions/browser/extension_system.h" |
27 #include "ui/accessibility/ax_enums.h" | 29 #include "ui/accessibility/ax_enums.h" |
28 #include "ui/accessibility/ax_node_data.h" | 30 #include "ui/accessibility/ax_node_data.h" |
29 | 31 |
30 namespace extensions { | 32 namespace extensions { |
31 class AutomationWebContentsObserver; | 33 class AutomationWebContentsObserver; |
32 } // namespace extensions | 34 } // namespace extensions |
(...skipping 10 matching lines...) Expand all Loading... |
43 void DispatchEvent(content::BrowserContext* context, | 45 void DispatchEvent(content::BrowserContext* context, |
44 const std::string& event_name, | 46 const std::string& event_name, |
45 scoped_ptr<base::ListValue> args) { | 47 scoped_ptr<base::ListValue> args) { |
46 if (context && extensions::ExtensionSystem::Get(context)->event_router()) { | 48 if (context && extensions::ExtensionSystem::Get(context)->event_router()) { |
47 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 49 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
48 event->restrict_to_browser_context = context; | 50 event->restrict_to_browser_context = context; |
49 ExtensionSystem::Get(context)->event_router()->BroadcastEvent(event.Pass()); | 51 ExtensionSystem::Get(context)->event_router()->BroadcastEvent(event.Pass()); |
50 } | 52 } |
51 } | 53 } |
52 | 54 |
| 55 // Helper to get an ActionType from a |ListValue|. |
| 56 bool GetActionType(base::ListValue* value, |
| 57 int position, |
| 58 api::automation_internal::ActionType* out_type) { |
| 59 std::string action_value; |
| 60 if (!value->GetString(position, &action_value)) |
| 61 return false; |
| 62 *out_type = api::automation_internal::ParseActionType( |
| 63 action_value); |
| 64 return true; |
| 65 } |
| 66 |
53 } // namespace | 67 } // namespace |
54 | 68 |
55 // Helper class that receives accessibility data from |WebContents|. | 69 // Helper class that receives accessibility data from |WebContents|. |
56 class AutomationWebContentsObserver | 70 class AutomationWebContentsObserver |
57 : public content::WebContentsObserver, | 71 : public content::WebContentsObserver, |
58 public content::WebContentsUserData<AutomationWebContentsObserver> { | 72 public content::WebContentsUserData<AutomationWebContentsObserver> { |
59 public: | 73 public: |
60 virtual ~AutomationWebContentsObserver() {} | 74 virtual ~AutomationWebContentsObserver() {} |
61 | 75 |
62 // content::WebContentsObserver overrides. | 76 // content::WebContentsObserver overrides. |
63 virtual void AccessibilityEventReceived( | 77 virtual void AccessibilityEventReceived( |
64 const std::vector<content::AXEventNotificationDetails>& details) | 78 const std::vector<content::AXEventNotificationDetails>& details) |
65 OVERRIDE { | 79 OVERRIDE { |
66 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 80 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
67 switches::kEnableAutomationAPI)) { | 81 switches::kEnableAutomationAPI)) { |
68 return; | 82 return; |
69 } | 83 } |
70 | 84 |
71 std::vector<content::AXEventNotificationDetails>::const_iterator iter = | 85 std::vector<content::AXEventNotificationDetails>::const_iterator iter = |
72 details.begin(); | 86 details.begin(); |
73 for (; iter != details.end(); iter++) { | 87 for (; iter != details.end(); iter++) { |
74 scoped_ptr<base::ListValue> args(new base::ListValue()); | 88 scoped_ptr<base::ListValue> args(new base::ListValue()); |
75 const content::AXEventNotificationDetails& event = *iter; | 89 const content::AXEventNotificationDetails& event = *iter; |
| 90 int process_id = event.process_id; |
76 int routing_id = event.routing_id; | 91 int routing_id = event.routing_id; |
77 | 92 |
78 base::DictionaryValue* axTreeUpdate = new base::DictionaryValue(); | 93 base::DictionaryValue* axTreeUpdate = new base::DictionaryValue(); |
79 // TODO(dtseng): These strings should be auto-generated by the IDL | 94 // TODO(dtseng): These strings should be auto-generated by the IDL |
80 // compiler. | 95 // compiler. |
| 96 axTreeUpdate->Set("process_id", |
| 97 base::Value::CreateIntegerValue(process_id)); |
81 axTreeUpdate->Set("routing_id", | 98 axTreeUpdate->Set("routing_id", |
82 base::Value::CreateIntegerValue(routing_id)); | 99 base::Value::CreateIntegerValue(routing_id)); |
83 axTreeUpdate->SetString("event_type", ToString(iter->event_type)); | 100 axTreeUpdate->SetString("event_type", ToString(iter->event_type)); |
84 base::ListValue* nodes = new base::ListValue(); | 101 base::ListValue* nodes = new base::ListValue(); |
85 axTreeUpdate->Set("nodes", nodes); | 102 axTreeUpdate->Set("nodes", nodes); |
86 for (size_t i = 0; i < event.nodes.size(); i++) { | 103 for (size_t i = 0; i < event.nodes.size(); i++) { |
87 const ui::AXNodeData& node = event.nodes[i]; | 104 const ui::AXNodeData& node = event.nodes[i]; |
88 AddNodeData(node, nodes); | 105 AddNodeData(node, nodes); |
89 } | 106 } |
90 args->Append(axTreeUpdate); | 107 args->Append(axTreeUpdate); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 content::RenderWidgetHost* rwh = | 229 content::RenderWidgetHost* rwh = |
213 contents->GetRenderWidgetHostView()->GetRenderWidgetHost(); | 230 contents->GetRenderWidgetHostView()->GetRenderWidgetHost(); |
214 if (!rwh) | 231 if (!rwh) |
215 return false; | 232 return false; |
216 | 233 |
217 AutomationWebContentsObserver::CreateForWebContents(contents); | 234 AutomationWebContentsObserver::CreateForWebContents(contents); |
218 | 235 |
219 rwh->EnableTreeOnlyAccessibilityMode(); | 236 rwh->EnableTreeOnlyAccessibilityMode(); |
220 | 237 |
221 results_ = api::automation_internal::EnableCurrentTab::Results::Create( | 238 results_ = api::automation_internal::EnableCurrentTab::Results::Create( |
222 rwh->GetRoutingID()); | 239 rwh->GetProcess()->GetID(), rwh->GetRoutingID()); |
223 | 240 |
224 SendResponse(true); | 241 SendResponse(true); |
225 return true; | 242 return true; |
226 } | 243 } |
227 | 244 |
| 245 bool AutomationInternalPerformActionFunction::RunImpl() { |
| 246 int process_id; |
| 247 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &process_id)); |
| 248 |
| 249 int routing_id; |
| 250 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &routing_id)); |
| 251 |
| 252 int automation_node_id; |
| 253 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &automation_node_id)); |
| 254 |
| 255 api::automation_internal::ActionType action_type = |
| 256 api::automation_internal::ACTION_TYPE_NONE; |
| 257 EXTENSION_FUNCTION_VALIDATE(GetActionType(args_.get(), 3, &action_type)); |
| 258 |
| 259 content::RenderWidgetHost* rwh = |
| 260 content::RenderWidgetHost::FromID(process_id, routing_id); |
| 261 |
| 262 switch (action_type) { |
| 263 case api::automation_internal::ACTION_TYPE_DO_DEFAULT: |
| 264 rwh->AccessibilityDoDefaultAction(automation_node_id); |
| 265 break; |
| 266 case api::automation_internal::ACTION_TYPE_FOCUS: |
| 267 rwh->AccessibilitySetFocus(automation_node_id); |
| 268 break; |
| 269 case api::automation_internal::ACTION_TYPE_MAKE_VISIBLE: |
| 270 rwh->AccessibilityScrollToMakeVisible(automation_node_id, gfx::Rect()); |
| 271 break; |
| 272 case api::automation_internal::ACTION_TYPE_SET_SELECTION: { |
| 273 extensions::api::automation_internal::SetSelectionParams params; |
| 274 base::DictionaryValue* opt_args = NULL; |
| 275 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(4, &opt_args)); |
| 276 EXTENSION_FUNCTION_VALIDATE( |
| 277 extensions::api::automation_internal::SetSelectionParams::Populate( |
| 278 *opt_args, ¶ms)); |
| 279 rwh->AccessibilitySetTextSelection( |
| 280 automation_node_id, params.start_index, params.end_index); |
| 281 break; |
| 282 } |
| 283 default: |
| 284 NOTREACHED(); |
| 285 } |
| 286 return true; |
| 287 } |
| 288 |
228 } // namespace extensions | 289 } // namespace extensions |
OLD | NEW |