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 9ed4a394313a449f9994f3557edf14360a300eb8..10a5ae9c1d14790af1bae5d6a2e5f22d24597751 100644 |
--- a/chrome/browser/extensions/api/automation_internal/automation_internal_api.cc |
+++ b/chrome/browser/extensions/api/automation_internal/automation_internal_api.cc |
@@ -12,12 +12,14 @@ |
#include "chrome/browser/ui/tabs/tab_strip_model.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/extensions/api/automation_internal.h" |
+#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
|
#include "content/public/browser/ax_event_notification_details.h" |
#include "content/public/browser/browser_accessibility_state.h" |
#include "content/public/browser/browser_thread.h" |
#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_view.h" |
@@ -50,6 +52,17 @@ void DispatchEvent(content::BrowserContext* context, |
} |
} |
+ // Helper to get an ActionType from a |ListValue|. |
+ bool GetActionType(base::ListValue* value, |
+ int position, |
+ api::automation_internal::ActionType* type) { |
+ std::string action_value; |
+ if (!value->GetString(position, &action_value)) |
+ return false; |
+ return api::automation_internal::ParseActionType( |
+ action_value); |
+ } |
+ |
} // namespace |
// Helper class that receives accessibility data from |WebContents|. |
@@ -73,11 +86,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)); |
@@ -220,10 +236,53 @@ bool AutomationInternalEnableCurrentTabFunction::RunImpl() { |
rwh->EnableFullAccessibilityMode(); |
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; |
+ EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &automation_id)); |
+ |
+ api::automation_internal::ActionType action_type = |
+ api::automation_internal::ACTION_TYPE_NONE; |
+ EXTENSION_FUNCTION_VALIDATE(GetActionType(args_.get(), 3, &action_type)); |
+ |
+ content::RenderWidgetHostImpl* rwhi = |
+ content::RenderWidgetHostImpl::FromID(process_id, routing_id); |
+ |
+ switch (action_type) { |
+ case api::automation_internal::ACTION_TYPE_DO_DEFAULT: |
+ rwhi->AccessibilityDoDefaultAction(automation_id); |
+ break; |
+ case api::automation_internal::ACTION_TYPE_FOCUS: |
+ rwhi->AccessibilitySetFocus(automation_id); |
+ break; |
+ case api::automation_internal::ACTION_TYPE_MAKE_VISIBLE: |
+ rwhi->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)); |
+ rwhi->AccessibilitySetTextSelection( |
+ automation_id, start_index, end_index); |
+ break; |
+ } |
+ default: |
+ NOTREACHED(); |
+ } |
+ return true; |
+} |
+ |
} // namespace extensions |