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..5c5f1a53c2bef816c45082d467c706c08d34d528 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; |
| 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,54 @@ 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_node_id; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &automation_node_id)); |
|
not at google - send to devlin
2014/04/02 21:52:14
the schema compiler will generate all of this for
David Tseng
2014/04/03 01:27:41
Done.
|
| + |
| + api::automation_internal::ActionType action_type = |
| + api::automation_internal::ACTION_TYPE_NONE; |
| + EXTENSION_FUNCTION_VALIDATE(GetActionType(args_.get(), 3, &action_type)); |
| + |
| + content::RenderWidgetHost* rwh = |
| + content::RenderWidgetHost::FromID(process_id, routing_id); |
| + |
| + switch (action_type) { |
| + case api::automation_internal::ACTION_TYPE_DO_DEFAULT: |
| + rwh->AccessibilityDoDefaultAction(automation_node_id); |
| + break; |
| + case api::automation_internal::ACTION_TYPE_FOCUS: |
| + rwh->AccessibilitySetFocus(automation_node_id); |
| + break; |
| + case api::automation_internal::ACTION_TYPE_MAKE_VISIBLE: |
| + rwh->AccessibilityScrollToMakeVisible(automation_node_id, gfx::Rect()); |
| + break; |
| + case api::automation_internal::ACTION_TYPE_SET_SELECTION: { |
| + extensions::api::automation_internal::SetSelectionParams params; |
| + base::DictionaryValue* opt_args = NULL; |
| + EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(4, &opt_args)); |
| + EXTENSION_FUNCTION_VALIDATE( |
| + extensions::api::automation_internal::SetSelectionParams::Populate( |
| + *opt_args, ¶ms)); |
| + rwh->AccessibilitySetTextSelection( |
| + automation_node_id, params.start_index, params.end_index); |
| + break; |
| + } |
| + default: |
| + NOTREACHED(); |
| + } |
| + return true; |
| +} |
| + |
| } // namespace extensions |