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 using v8::Local; | |
18 using v8::Object; | |
19 using v8::String; | |
not at google - send to devlin
2014/05/29 19:48:14
I would loosely prefer not doing "using" here, sin
David Tseng
2014/05/29 22:12:26
Reverted back to v8 prefixes.
| |
20 | |
21 namespace { | |
22 | |
23 // Helper to convert an enum to a V8 object. | |
24 template <typename EnumType> | |
25 Local<Object> ToEnumObject(v8::Isolate* isolate, | |
26 EnumType start_after, | |
27 EnumType end_at) { | |
28 Local<Object> object = Object::New(isolate); | |
29 for (int i = start_after + 1; i <= end_at; ++i) { | |
30 Local<String> value = String::NewFromUtf8( | |
31 isolate, ui::ToString(static_cast<EnumType>(i)).c_str()); | |
32 object->Set(value, value); | |
33 } | |
34 return object; | |
35 } | |
36 | |
37 } // namespace | |
14 | 38 |
15 namespace extensions { | 39 namespace extensions { |
16 | 40 |
17 AutomationInternalCustomBindings::AutomationInternalCustomBindings( | 41 AutomationInternalCustomBindings::AutomationInternalCustomBindings( |
18 ScriptContext* context) : ObjectBackedNativeHandler(context) { | 42 ScriptContext* context) : ObjectBackedNativeHandler(context) { |
19 RouteFunction( | 43 RouteFunction( |
20 "IsInteractPermitted", | 44 "IsInteractPermitted", |
21 base::Bind(&AutomationInternalCustomBindings::IsInteractPermitted, | 45 base::Bind(&AutomationInternalCustomBindings::IsInteractPermitted, |
22 base::Unretained(this))); | 46 base::Unretained(this))); |
47 RouteFunction( | |
48 "GetSchemaAdditions", | |
49 base::Bind(&AutomationInternalCustomBindings::GetSchemaAdditions, | |
50 base::Unretained(this))); | |
23 } | 51 } |
24 | 52 |
25 AutomationInternalCustomBindings::~AutomationInternalCustomBindings() { | 53 AutomationInternalCustomBindings::~AutomationInternalCustomBindings() { |
26 } | 54 } |
27 | 55 |
28 void AutomationInternalCustomBindings::IsInteractPermitted( | 56 void AutomationInternalCustomBindings::IsInteractPermitted( |
29 const v8::FunctionCallbackInfo<v8::Value>& args) { | 57 const v8::FunctionCallbackInfo<v8::Value>& args) { |
30 const Extension* extension = context()->extension(); | 58 const Extension* extension = context()->extension(); |
31 CHECK(extension); | 59 CHECK(extension); |
32 const AutomationInfo* automation_info = AutomationInfo::Get(extension); | 60 const AutomationInfo* automation_info = AutomationInfo::Get(extension); |
33 CHECK(automation_info); | 61 CHECK(automation_info); |
34 args.GetReturnValue().Set( | 62 args.GetReturnValue().Set( |
35 v8::Boolean::New(GetIsolate(), automation_info->interact)); | 63 v8::Boolean::New(GetIsolate(), automation_info->interact)); |
36 } | 64 } |
37 | 65 |
66 void AutomationInternalCustomBindings::GetSchemaAdditions( | |
67 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
68 Local<Object> additions = Object::New(GetIsolate()); | |
69 | |
70 additions->Set(String::NewFromUtf8(GetIsolate(), "EventType"), | |
71 ToEnumObject<ui::AXEvent>( | |
not at google - send to devlin
2014/05/29 19:48:14
hm, can C++ not guess that this is ui::AXEvent (et
David Tseng
2014/05/29 22:12:26
Looks like clang can infer the type from the argum
| |
72 GetIsolate(), ui::AX_EVENT_NONE, ui::AX_EVENT_LAST)); | |
73 | |
74 additions->Set(String::NewFromUtf8(GetIsolate(), "RoleType"), | |
75 ToEnumObject<ui::AXRole>( | |
76 GetIsolate(), ui::AX_ROLE_NONE, ui::AX_ROLE_LAST)); | |
77 | |
78 additions->Set(String::NewFromUtf8(GetIsolate(), "StateType"), | |
79 ToEnumObject<ui::AXState>( | |
80 GetIsolate(), ui::AX_STATE_NONE, ui::AX_STATE_LAST)); | |
81 | |
82 args.GetReturnValue().Set(additions); | |
83 } | |
84 | |
38 } // namespace extensions | 85 } // namespace extensions |
OLD | NEW |