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" | |
14 | 16 |
15 namespace extensions { | 17 namespace extensions { |
16 | 18 |
17 AutomationInternalCustomBindings::AutomationInternalCustomBindings( | 19 AutomationInternalCustomBindings::AutomationInternalCustomBindings( |
18 ScriptContext* context) : ObjectBackedNativeHandler(context) { | 20 ScriptContext* context) : ObjectBackedNativeHandler(context) { |
19 RouteFunction( | 21 RouteFunction( |
20 "IsInteractPermitted", | 22 "IsInteractPermitted", |
21 base::Bind(&AutomationInternalCustomBindings::IsInteractPermitted, | 23 base::Bind(&AutomationInternalCustomBindings::IsInteractPermitted, |
22 base::Unretained(this))); | 24 base::Unretained(this))); |
25 RouteFunction( | |
26 "GetSchemaAdditions", | |
27 base::Bind(&AutomationInternalCustomBindings::GetSchemaAdditions, | |
28 base::Unretained(this))); | |
23 } | 29 } |
24 | 30 |
25 AutomationInternalCustomBindings::~AutomationInternalCustomBindings() { | 31 AutomationInternalCustomBindings::~AutomationInternalCustomBindings() { |
26 } | 32 } |
27 | 33 |
28 void AutomationInternalCustomBindings::IsInteractPermitted( | 34 void AutomationInternalCustomBindings::IsInteractPermitted( |
29 const v8::FunctionCallbackInfo<v8::Value>& args) { | 35 const v8::FunctionCallbackInfo<v8::Value>& args) { |
30 const Extension* extension = context()->extension(); | 36 const Extension* extension = context()->extension(); |
31 CHECK(extension); | 37 CHECK(extension); |
32 const AutomationInfo* automation_info = AutomationInfo::Get(extension); | 38 const AutomationInfo* automation_info = AutomationInfo::Get(extension); |
33 CHECK(automation_info); | 39 CHECK(automation_info); |
34 args.GetReturnValue().Set( | 40 args.GetReturnValue().Set( |
35 v8::Boolean::New(GetIsolate(), automation_info->interact)); | 41 v8::Boolean::New(GetIsolate(), automation_info->interact)); |
36 } | 42 } |
37 | 43 |
44 void AutomationInternalCustomBindings::GetSchemaAdditions( | |
45 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
46 using v8::Local; | |
47 using v8::Object; | |
48 using v8::String; | |
49 | |
50 Local<Object> ret = Object::New(GetIsolate()); | |
not at google - send to devlin
2014/05/29 18:26:21
s/ret/additions/ ?
David Tseng
2014/05/29 19:04:40
Done.
| |
51 | |
52 Local<Object> event_enum = Object::New(GetIsolate()); | |
53 for (int i = ui::AX_EVENT_NONE; | |
54 i <= ui::AX_EVENT_LAST; | |
55 ++i) { | |
not at google - send to devlin
2014/05/29 18:26:21
should fit on 1 line? (might as well just "git cl
David Tseng
2014/05/29 19:04:40
Done.
| |
56 Local<String> value = | |
aboxhall
2014/05/29 18:35:49
The formatting here is also a little weird, I thin
David Tseng
2014/05/29 19:04:40
Done; (git cl formatted)
| |
57 String::NewFromUtf8(GetIsolate(), | |
58 ui::ToString(static_cast<ui::AXEvent>(i)).c_str()); | |
59 event_enum->Set(value, value); | |
60 } | |
61 ret->Set(String::NewFromUtf8(GetIsolate(), "Event"), event_enum); | |
62 | |
63 Local<Object> role_enum = Object::New(GetIsolate()); | |
64 for (int j = ui::AX_ROLE_NONE; | |
65 j <= ui::AX_ROLE_LAST; | |
66 ++j) { | |
67 Local<String> value = | |
68 String::NewFromUtf8(GetIsolate(), | |
69 ui::ToString(static_cast<ui::AXRole>(j)).c_str()); | |
70 role_enum->Set(value, value); | |
71 } | |
72 ret->Set(String::NewFromUtf8(GetIsolate(), "Role"), role_enum); | |
73 | |
74 Local<Object> state_enum = Object::New(GetIsolate()); | |
75 for (int k = ui::AX_STATE_NONE; | |
76 k <= ui::AX_STATE_LAST; | |
77 ++k) { | |
78 Local<String> value = | |
79 String::NewFromUtf8(GetIsolate(), | |
80 ui::ToString(static_cast<ui::AXState>(k)).c_str()); | |
81 state_enum->Set(value, value); | |
82 } | |
not at google - send to devlin
2014/05/29 18:26:21
you should be able to simplify this a lot with tem
David Tseng
2014/05/29 19:04:40
No worries :); I like templates too (less code is
| |
83 ret->Set(String::NewFromUtf8(GetIsolate(), "State"), state_enum); | |
84 | |
85 args.GetReturnValue().Set(ret); | |
86 } | |
87 | |
38 } // namespace extensions | 88 } // namespace extensions |
OLD | NEW |