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

Side by Side Diff: chrome/browser/extensions/api/automation_internal/automation_internal_api.cc

Issue 203753002: Implement actions for Automation API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial patch. Created 6 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 | Annotate | Revision Log
OLDNEW
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/browser/renderer_host/render_widget_host_impl.h"
David Tseng 2014/03/24 22:46:37 This is an illegal include; @jam, what would you s
jam 2014/03/25 15:01:00 since you need methods from RenderWidgetHostImpl,
David Tseng 2014/03/25 17:14:19 Simple enough :). I wanted to be sure I was allowe
15 #include "content/public/browser/ax_event_notification_details.h" 16 #include "content/public/browser/ax_event_notification_details.h"
16 #include "content/public/browser/browser_accessibility_state.h" 17 #include "content/public/browser/browser_accessibility_state.h"
17 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
18 #include "content/public/browser/notification_service.h" 19 #include "content/public/browser/notification_service.h"
19 #include "content/public/browser/notification_source.h" 20 #include "content/public/browser/notification_source.h"
20 #include "content/public/browser/notification_types.h" 21 #include "content/public/browser/notification_types.h"
22 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/render_view_host.h" 23 #include "content/public/browser/render_view_host.h"
22 #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 {
(...skipping 12 matching lines...) Expand all
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* type) {
59 std::string action_value;
60 if (!value->GetString(position, &action_value))
61 return false;
62 return api::automation_internal::ParseActionType(
63 action_value);
64 }
65
53 } // namespace 66 } // namespace
54 67
55 // Helper class that receives accessibility data from |WebContents|. 68 // Helper class that receives accessibility data from |WebContents|.
56 class AutomationWebContentsObserver 69 class AutomationWebContentsObserver
57 : public content::WebContentsObserver, 70 : public content::WebContentsObserver,
58 public content::WebContentsUserData<AutomationWebContentsObserver> { 71 public content::WebContentsUserData<AutomationWebContentsObserver> {
59 public: 72 public:
60 virtual ~AutomationWebContentsObserver() {} 73 virtual ~AutomationWebContentsObserver() {}
61 74
62 // content::WebContentsObserver overrides. 75 // content::WebContentsObserver overrides.
63 virtual void AccessibilityEventReceived( 76 virtual void AccessibilityEventReceived(
64 const std::vector<content::AXEventNotificationDetails>& details) 77 const std::vector<content::AXEventNotificationDetails>& details)
65 OVERRIDE { 78 OVERRIDE {
66 if (!CommandLine::ForCurrentProcess()->HasSwitch( 79 if (!CommandLine::ForCurrentProcess()->HasSwitch(
67 switches::kEnableAutomationAPI)) { 80 switches::kEnableAutomationAPI)) {
68 return; 81 return;
69 } 82 }
70 83
71 std::vector<content::AXEventNotificationDetails>::const_iterator iter = 84 std::vector<content::AXEventNotificationDetails>::const_iterator iter =
72 details.begin(); 85 details.begin();
73 for (; iter != details.end(); iter++) { 86 for (; iter != details.end(); iter++) {
74 scoped_ptr<base::ListValue> args(new base::ListValue()); 87 scoped_ptr<base::ListValue> args(new base::ListValue());
75 const content::AXEventNotificationDetails& event = *iter; 88 const content::AXEventNotificationDetails& event = *iter;
89 int process_id = event.process_id;
76 int routing_id = event.routing_id; 90 int routing_id = event.routing_id;
77 91
78 base::DictionaryValue* axTreeUpdate = new base::DictionaryValue(); 92 base::DictionaryValue* axTreeUpdate = new base::DictionaryValue();
79 // TODO(dtseng): These strings should be auto-generated by the IDL 93 // TODO(dtseng): These strings should be auto-generated by the IDL
80 // compiler. 94 // compiler.
95 axTreeUpdate->Set("process_id",
96 base::Value::CreateIntegerValue(process_id));
81 axTreeUpdate->Set("routing_id", 97 axTreeUpdate->Set("routing_id",
82 base::Value::CreateIntegerValue(routing_id)); 98 base::Value::CreateIntegerValue(routing_id));
83 axTreeUpdate->SetString("event_type", ToString(iter->event_type)); 99 axTreeUpdate->SetString("event_type", ToString(iter->event_type));
84 base::ListValue* nodes = new base::ListValue(); 100 base::ListValue* nodes = new base::ListValue();
85 axTreeUpdate->Set("nodes", nodes); 101 axTreeUpdate->Set("nodes", nodes);
86 for (size_t i = 0; i < event.nodes.size(); i++) { 102 for (size_t i = 0; i < event.nodes.size(); i++) {
87 const ui::AXNodeData& node = event.nodes[i]; 103 const ui::AXNodeData& node = event.nodes[i];
88 AddNodeData(node, nodes); 104 AddNodeData(node, nodes);
89 } 105 }
90 args->Append(axTreeUpdate); 106 args->Append(axTreeUpdate);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 contents->GetRenderWidgetHostView()->GetRenderWidgetHost(); 229 contents->GetRenderWidgetHostView()->GetRenderWidgetHost();
214 if (!rwh) 230 if (!rwh)
215 return false; 231 return false;
216 232
217 // TODO(aboxhall): observe WebContents here - add to map?? 233 // TODO(aboxhall): observe WebContents here - add to map??
218 AutomationWebContentsObserver::CreateForWebContents(contents); 234 AutomationWebContentsObserver::CreateForWebContents(contents);
219 235
220 rwh->EnableFullAccessibilityMode(); 236 rwh->EnableFullAccessibilityMode();
221 237
222 results_ = api::automation_internal::EnableCurrentTab::Results::Create( 238 results_ = api::automation_internal::EnableCurrentTab::Results::Create(
223 rwh->GetRoutingID()); 239 rwh->GetProcess()->GetID(), rwh->GetRoutingID());
224 240
225 SendResponse(true); 241 SendResponse(true);
226 return true; 242 return true;
227 } 243 }
228 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_id;
253 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &automation_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::RenderWidgetHostImpl* rwhi =
260 content::RenderWidgetHostImpl::FromID(process_id, routing_id);
261
262 switch (action_type) {
263 case api::automation_internal::ACTION_TYPE_DO_DEFAULT:
264 rwhi->AccessibilityDoDefaultAction(automation_id);
265 break;
266 case api::automation_internal::ACTION_TYPE_FOCUS:
267 rwhi->AccessibilitySetFocus(automation_id);
268 break;
269 case api::automation_internal::ACTION_TYPE_MAKE_VISIBLE:
270 rwhi->AccessibilityScrollToMakeVisible(automation_id, gfx::Rect());
271 break;
272 case api::automation_internal::ACTION_TYPE_SET_SELECTION: {
273 int start_index = 0, end_index = 0;
274 base::ListValue* opt_args;
275 EXTENSION_FUNCTION_VALIDATE(args_->GetList(4, &opt_args));
276 EXTENSION_FUNCTION_VALIDATE(opt_args->GetInteger(0, &start_index));
277 EXTENSION_FUNCTION_VALIDATE(opt_args->GetInteger(1, &end_index));
278 rwhi->AccessibilitySetTextSelection(
279 automation_id, start_index, end_index);
280 break;
281 }
282 default:
283 NOTREACHED();
284 }
285 return true;
286 }
287
229 } // namespace extensions 288 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698