OLD | NEW |
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/renderer/extensions/automation_internal_custom_bindings.h" | 5 #include "chrome/renderer/extensions/automation_internal_custom_bindings.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/common/extensions/manifest_handlers/automation.h" | 10 #include "chrome/common/extensions/manifest_handlers/automation.h" |
| 11 #include "content/public/renderer/v8_value_converter.h" |
11 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
12 #include "extensions/common/manifest.h" | 13 #include "extensions/common/manifest.h" |
13 #include "extensions/renderer/script_context.h" | 14 #include "extensions/renderer/script_context.h" |
| 15 #include "ui/accessibility/ax_enums.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 // Helper to convert an enum to a V8 object. |
| 20 template <typename EnumType> |
| 21 v8::Local<v8::Object> ToEnumObject(v8::Isolate* isolate, |
| 22 EnumType start_after, |
| 23 EnumType end_at) { |
| 24 v8::Local<v8::Object> object = v8::Object::New(isolate); |
| 25 for (int i = start_after + 1; i <= end_at; ++i) { |
| 26 v8::Local<v8::String> value = v8::String::NewFromUtf8( |
| 27 isolate, ui::ToString(static_cast<EnumType>(i)).c_str()); |
| 28 object->Set(value, value); |
| 29 } |
| 30 return object; |
| 31 } |
| 32 |
| 33 } // namespace |
14 | 34 |
15 namespace extensions { | 35 namespace extensions { |
16 | 36 |
17 AutomationInternalCustomBindings::AutomationInternalCustomBindings( | 37 AutomationInternalCustomBindings::AutomationInternalCustomBindings( |
18 ScriptContext* context) : ObjectBackedNativeHandler(context) { | 38 ScriptContext* context) : ObjectBackedNativeHandler(context) { |
19 RouteFunction( | 39 RouteFunction( |
20 "IsInteractPermitted", | 40 "IsInteractPermitted", |
21 base::Bind(&AutomationInternalCustomBindings::IsInteractPermitted, | 41 base::Bind(&AutomationInternalCustomBindings::IsInteractPermitted, |
22 base::Unretained(this))); | 42 base::Unretained(this))); |
| 43 RouteFunction( |
| 44 "GetSchemaAdditions", |
| 45 base::Bind(&AutomationInternalCustomBindings::GetSchemaAdditions, |
| 46 base::Unretained(this))); |
23 } | 47 } |
24 | 48 |
25 AutomationInternalCustomBindings::~AutomationInternalCustomBindings() { | 49 AutomationInternalCustomBindings::~AutomationInternalCustomBindings() { |
26 } | 50 } |
27 | 51 |
28 void AutomationInternalCustomBindings::IsInteractPermitted( | 52 void AutomationInternalCustomBindings::IsInteractPermitted( |
29 const v8::FunctionCallbackInfo<v8::Value>& args) { | 53 const v8::FunctionCallbackInfo<v8::Value>& args) { |
30 const Extension* extension = context()->extension(); | 54 const Extension* extension = context()->extension(); |
31 CHECK(extension); | 55 CHECK(extension); |
32 const AutomationInfo* automation_info = AutomationInfo::Get(extension); | 56 const AutomationInfo* automation_info = AutomationInfo::Get(extension); |
33 CHECK(automation_info); | 57 CHECK(automation_info); |
34 args.GetReturnValue().Set( | 58 args.GetReturnValue().Set( |
35 v8::Boolean::New(GetIsolate(), automation_info->interact)); | 59 v8::Boolean::New(GetIsolate(), automation_info->interact)); |
36 } | 60 } |
37 | 61 |
| 62 void AutomationInternalCustomBindings::GetSchemaAdditions( |
| 63 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 64 v8::Local<v8::Object> additions = v8::Object::New(GetIsolate()); |
| 65 |
| 66 additions->Set( |
| 67 v8::String::NewFromUtf8(GetIsolate(), "EventType"), |
| 68 ToEnumObject(GetIsolate(), ui::AX_EVENT_NONE, ui::AX_EVENT_LAST)); |
| 69 |
| 70 additions->Set( |
| 71 v8::String::NewFromUtf8(GetIsolate(), "RoleType"), |
| 72 ToEnumObject(GetIsolate(), ui::AX_ROLE_NONE, ui::AX_ROLE_LAST)); |
| 73 |
| 74 additions->Set( |
| 75 v8::String::NewFromUtf8(GetIsolate(), "StateType"), |
| 76 ToEnumObject(GetIsolate(), ui::AX_STATE_NONE, ui::AX_STATE_LAST)); |
| 77 |
| 78 args.GetReturnValue().Set(additions); |
| 79 } |
| 80 |
38 } // namespace extensions | 81 } // namespace extensions |
OLD | NEW |