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

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: Remove repricated API. Created 6 years, 8 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/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
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;
aboxhall 2014/04/01 17:49:51 We may wish to consider combining these into some
David Tseng 2014/04/01 21:27:15 I'm ok either way. Leaving them separate means we
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
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_id;
aboxhall 2014/04/01 17:49:51 node_id maybe? Or automation_node_id?
David Tseng 2014/04/01 21:27:15 Sure, automation_node_id.
253 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &automation_id));
254 api::automation_internal::ActionType action_type =
aboxhall 2014/04/01 17:49:51 Nit: newline above this line
David Tseng 2014/04/01 21:27:15 Done.
255 api::automation_internal::ACTION_TYPE_NONE;
256 EXTENSION_FUNCTION_VALIDATE(GetActionType(args_.get(), 3, &action_type));
257 content::RenderWidgetHost* rwh =
aboxhall 2014/04/01 17:49:51 Nit: newline above this line (i.e. group declaring
David Tseng 2014/04/01 21:27:15 Done.
258 content::RenderWidgetHost::FromID(process_id, routing_id);
259
260 switch (action_type) {
261 case api::automation_internal::ACTION_TYPE_DO_DEFAULT:
aboxhall 2014/04/01 17:49:51 Nit: these case statements are all indented, but d
David Tseng 2014/04/01 21:27:15 Done. (emacs c-mode tab indent failed me here).
262 rwh->AccessibilityDoDefaultAction(automation_id);
263 break;
264 case api::automation_internal::ACTION_TYPE_FOCUS:
265 rwh->AccessibilitySetFocus(automation_id);
266 break;
267 case api::automation_internal::ACTION_TYPE_MAKE_VISIBLE:
268 rwh->AccessibilityScrollToMakeVisible(automation_id, gfx::Rect());
269 break;
270 case api::automation_internal::ACTION_TYPE_SET_SELECTION: {
271 int start_index = 0, end_index = 0;
272 base::ListValue* opt_args;
273 EXTENSION_FUNCTION_VALIDATE(args_->GetList(4, &opt_args));
274 EXTENSION_FUNCTION_VALIDATE(opt_args->GetInteger(0, &start_index));
275 EXTENSION_FUNCTION_VALIDATE(opt_args->GetInteger(1, &end_index));
276 rwh->AccessibilitySetTextSelection(
277 automation_id, start_index, end_index);
278 break;
279 }
280 default:
281 NOTREACHED();
282 }
283 return true;
284 }
285
228 } // namespace extensions 286 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698