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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "extensions/renderer/script_context.h" | 24 #include "extensions/renderer/script_context.h" |
25 #include "ipc/message_filter.h" | 25 #include "ipc/message_filter.h" |
26 #include "ui/accessibility/ax_enums.h" | 26 #include "ui/accessibility/ax_enums.h" |
27 #include "ui/accessibility/ax_node.h" | 27 #include "ui/accessibility/ax_node.h" |
28 #include "ui/gfx/geometry/rect_conversions.h" | 28 #include "ui/gfx/geometry/rect_conversions.h" |
29 | 29 |
30 namespace extensions { | 30 namespace extensions { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Helper to convert an enum to a V8 object. | |
35 template <typename EnumType> | |
36 v8::Local<v8::Object> ToEnumObject(v8::Isolate* isolate, | |
37 EnumType start_after, | |
38 EnumType end_at) { | |
39 v8::Local<v8::Object> object = v8::Object::New(isolate); | |
40 for (int i = start_after + 1; i <= end_at; ++i) { | |
41 v8::Local<v8::String> value = v8::String::NewFromUtf8( | |
42 isolate, ui::ToString(static_cast<EnumType>(i)).c_str()); | |
43 object->Set(value, value); | |
44 } | |
45 return object; | |
46 } | |
47 | |
48 void ThrowInvalidArgumentsException( | 34 void ThrowInvalidArgumentsException( |
49 AutomationInternalCustomBindings* automation_bindings) { | 35 AutomationInternalCustomBindings* automation_bindings) { |
50 v8::Isolate* isolate = automation_bindings->GetIsolate(); | 36 v8::Isolate* isolate = automation_bindings->GetIsolate(); |
51 automation_bindings->GetIsolate()->ThrowException( | 37 automation_bindings->GetIsolate()->ThrowException( |
52 v8::String::NewFromUtf8( | 38 v8::String::NewFromUtf8( |
53 isolate, | 39 isolate, |
54 "Invalid arguments to AutomationInternalCustomBindings function", | 40 "Invalid arguments to AutomationInternalCustomBindings function", |
55 v8::NewStringType::kNormal) | 41 v8::NewStringType::kNormal) |
56 .ToLocalChecked()); | 42 .ToLocalChecked()); |
57 | 43 |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 void AutomationInternalCustomBindings::StartCachingAccessibilityTrees( | 760 void AutomationInternalCustomBindings::StartCachingAccessibilityTrees( |
775 const v8::FunctionCallbackInfo<v8::Value>& args) { | 761 const v8::FunctionCallbackInfo<v8::Value>& args) { |
776 if (!message_filter_) | 762 if (!message_filter_) |
777 message_filter_ = new AutomationMessageFilter(this); | 763 message_filter_ = new AutomationMessageFilter(this); |
778 } | 764 } |
779 | 765 |
780 void AutomationInternalCustomBindings::GetSchemaAdditions( | 766 void AutomationInternalCustomBindings::GetSchemaAdditions( |
781 const v8::FunctionCallbackInfo<v8::Value>& args) { | 767 const v8::FunctionCallbackInfo<v8::Value>& args) { |
782 v8::Local<v8::Object> additions = v8::Object::New(GetIsolate()); | 768 v8::Local<v8::Object> additions = v8::Object::New(GetIsolate()); |
783 | 769 |
784 additions->Set( | |
785 v8::String::NewFromUtf8(GetIsolate(), "EventType"), | |
786 ToEnumObject(GetIsolate(), ui::AX_EVENT_NONE, ui::AX_EVENT_LAST)); | |
787 | |
788 additions->Set( | |
789 v8::String::NewFromUtf8(GetIsolate(), "RoleType"), | |
790 ToEnumObject(GetIsolate(), ui::AX_ROLE_NONE, ui::AX_ROLE_LAST)); | |
791 | |
792 additions->Set( | |
793 v8::String::NewFromUtf8(GetIsolate(), "StateType"), | |
794 ToEnumObject(GetIsolate(), ui::AX_STATE_NONE, ui::AX_STATE_LAST)); | |
795 | |
796 additions->Set( | |
797 v8::String::NewFromUtf8(GetIsolate(), "TreeChangeType"), | |
798 ToEnumObject(GetIsolate(), ui::AX_MUTATION_NONE, ui::AX_MUTATION_LAST)); | |
799 | |
800 v8::Local<v8::Object> name_from_type(v8::Object::New(GetIsolate())); | 770 v8::Local<v8::Object> name_from_type(v8::Object::New(GetIsolate())); |
801 for (int i = ui::AX_NAME_FROM_NONE; i <= ui::AX_NAME_FROM_LAST; ++i) { | 771 for (int i = ui::AX_NAME_FROM_NONE; i <= ui::AX_NAME_FROM_LAST; ++i) { |
802 name_from_type->Set( | 772 name_from_type->Set( |
803 v8::Integer::New(GetIsolate(), i), | 773 v8::Integer::New(GetIsolate(), i), |
804 CreateV8String(GetIsolate(), | 774 CreateV8String(GetIsolate(), |
805 ui::ToString(static_cast<ui::AXNameFrom>(i)))); | 775 ui::ToString(static_cast<ui::AXNameFrom>(i)))); |
806 } | 776 } |
807 | 777 |
808 additions->Set(v8::String::NewFromUtf8(GetIsolate(), "NameFromType"), | 778 additions->Set(v8::String::NewFromUtf8(GetIsolate(), "NameFromType"), |
809 name_from_type); | 779 name_from_type); |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 2U)); | 1385 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 2U)); |
1416 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); | 1386 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); |
1417 v8::Local<v8::Array> nodes(v8::Array::New(GetIsolate(), ids.size())); | 1387 v8::Local<v8::Array> nodes(v8::Array::New(GetIsolate(), ids.size())); |
1418 args->Set(1U, nodes); | 1388 args->Set(1U, nodes); |
1419 for (size_t i = 0; i < ids.size(); ++i) | 1389 for (size_t i = 0; i < ids.size(); ++i) |
1420 nodes->Set(i, v8::Integer::New(GetIsolate(), ids[i])); | 1390 nodes->Set(i, v8::Integer::New(GetIsolate(), ids[i])); |
1421 context()->DispatchEvent("automationInternal.onNodesRemoved", args); | 1391 context()->DispatchEvent("automationInternal.onNodesRemoved", args); |
1422 } | 1392 } |
1423 | 1393 |
1424 } // namespace extensions | 1394 } // namespace extensions |
OLD | NEW |