Chromium Code Reviews| Index: chrome/browser/extensions/api/automation_internal/automation_internal_api.cc |
| diff --git a/chrome/browser/extensions/api/automation_internal/automation_internal_api.cc b/chrome/browser/extensions/api/automation_internal/automation_internal_api.cc |
| index f48c91b5640360699270b7d8f10f71c0eeb45d8e..e89f1b6e4374a6292ddb4e955d3cb97676d9c273 100644 |
| --- a/chrome/browser/extensions/api/automation_internal/automation_internal_api.cc |
| +++ b/chrome/browser/extensions/api/automation_internal/automation_internal_api.cc |
| @@ -18,8 +18,10 @@ |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/notification_source.h" |
| #include "content/public/browser/notification_types.h" |
| +#include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/render_widget_host.h" |
| +#include "content/public/browser/render_widget_host.h" |
| #include "content/public/browser/render_widget_host_view.h" |
| #include "content/public/browser/web_contents.h" |
| #include "extensions/browser/event_router.h" |
| @@ -50,6 +52,18 @@ void DispatchEvent(content::BrowserContext* context, |
| } |
| } |
| + // Helper to get an ActionType from a |ListValue|. |
| + bool GetActionType(base::ListValue* value, |
| + int position, |
| + api::automation_internal::ActionType* out_type) { |
| + std::string action_value; |
| + if (!value->GetString(position, &action_value)) |
| + return false; |
| + *out_type = api::automation_internal::ParseActionType( |
| + action_value); |
| + return true; |
| + } |
| + |
| } // namespace |
| // Helper class that receives accessibility data from |WebContents|. |
| @@ -73,11 +87,14 @@ class AutomationWebContentsObserver |
| for (; iter != details.end(); iter++) { |
| scoped_ptr<base::ListValue> args(new base::ListValue()); |
| const content::AXEventNotificationDetails& event = *iter; |
| + 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
|
| int routing_id = event.routing_id; |
| base::DictionaryValue* axTreeUpdate = new base::DictionaryValue(); |
| // TODO(dtseng): These strings should be auto-generated by the IDL |
| // compiler. |
| + axTreeUpdate->Set("process_id", |
| + base::Value::CreateIntegerValue(process_id)); |
| axTreeUpdate->Set("routing_id", |
| base::Value::CreateIntegerValue(routing_id)); |
| axTreeUpdate->SetString("event_type", ToString(iter->event_type)); |
| @@ -219,10 +236,51 @@ bool AutomationInternalEnableCurrentTabFunction::RunImpl() { |
| rwh->EnableTreeOnlyAccessibilityMode(); |
| results_ = api::automation_internal::EnableCurrentTab::Results::Create( |
| - rwh->GetRoutingID()); |
| + rwh->GetProcess()->GetID(), rwh->GetRoutingID()); |
| SendResponse(true); |
| return true; |
| } |
| +bool AutomationInternalPerformActionFunction::RunImpl() { |
| + int process_id; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &process_id)); |
| + |
| + int routing_id; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(1, &routing_id)); |
| + |
| + 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.
|
| + EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &automation_id)); |
| + 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.
|
| + api::automation_internal::ACTION_TYPE_NONE; |
| + EXTENSION_FUNCTION_VALIDATE(GetActionType(args_.get(), 3, &action_type)); |
| + 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.
|
| + content::RenderWidgetHost::FromID(process_id, routing_id); |
| + |
| + switch (action_type) { |
| + 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).
|
| + rwh->AccessibilityDoDefaultAction(automation_id); |
| + break; |
| + case api::automation_internal::ACTION_TYPE_FOCUS: |
| + rwh->AccessibilitySetFocus(automation_id); |
| + break; |
| + case api::automation_internal::ACTION_TYPE_MAKE_VISIBLE: |
| + rwh->AccessibilityScrollToMakeVisible(automation_id, gfx::Rect()); |
| + break; |
| + case api::automation_internal::ACTION_TYPE_SET_SELECTION: { |
| + int start_index = 0, end_index = 0; |
| + base::ListValue* opt_args; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetList(4, &opt_args)); |
| + EXTENSION_FUNCTION_VALIDATE(opt_args->GetInteger(0, &start_index)); |
| + EXTENSION_FUNCTION_VALIDATE(opt_args->GetInteger(1, &end_index)); |
| + rwh->AccessibilitySetTextSelection( |
| + automation_id, start_index, end_index); |
| + break; |
| + } |
| + default: |
| + NOTREACHED(); |
| + } |
| + return true; |
| +} |
| + |
| } // namespace extensions |