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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 RouteNodeIDPlusAttributeFunction( | 696 RouteNodeIDPlusAttributeFunction( |
711 "GetHtmlAttribute", | 697 "GetHtmlAttribute", |
712 [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, | 698 [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, |
713 ui::AXNode* node, const std::string& attribute_name) { | 699 ui::AXNode* node, const std::string& attribute_name) { |
714 std::string attr_value; | 700 std::string attr_value; |
715 if (!node->data().GetHtmlAttribute(attribute_name.c_str(), &attr_value)) | 701 if (!node->data().GetHtmlAttribute(attribute_name.c_str(), &attr_value)) |
716 return; | 702 return; |
717 | 703 |
718 result.Set(v8::String::NewFromUtf8(isolate, attr_value.c_str())); | 704 result.Set(v8::String::NewFromUtf8(isolate, attr_value.c_str())); |
719 }); | 705 }); |
| 706 RouteNodeIDFunction( |
| 707 "GetNameFrom", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, |
| 708 TreeCache* cache, ui::AXNode* node) { |
| 709 ui::AXNameFrom name_from = static_cast<ui::AXNameFrom>( |
| 710 node->data().GetIntAttribute(ui::AX_ATTR_NAME_FROM)); |
| 711 std::string name_from_str = ui::ToString(name_from); |
| 712 result.Set(v8::String::NewFromUtf8(isolate, name_from_str.c_str())); |
| 713 }); |
720 } | 714 } |
721 | 715 |
722 AutomationInternalCustomBindings::~AutomationInternalCustomBindings() {} | 716 AutomationInternalCustomBindings::~AutomationInternalCustomBindings() {} |
723 | 717 |
724 void AutomationInternalCustomBindings::Invalidate() { | 718 void AutomationInternalCustomBindings::Invalidate() { |
725 ObjectBackedNativeHandler::Invalidate(); | 719 ObjectBackedNativeHandler::Invalidate(); |
726 | 720 |
727 if (message_filter_) | 721 if (message_filter_) |
728 message_filter_->Detach(); | 722 message_filter_->Detach(); |
729 | 723 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 void AutomationInternalCustomBindings::StartCachingAccessibilityTrees( | 768 void AutomationInternalCustomBindings::StartCachingAccessibilityTrees( |
775 const v8::FunctionCallbackInfo<v8::Value>& args) { | 769 const v8::FunctionCallbackInfo<v8::Value>& args) { |
776 if (!message_filter_) | 770 if (!message_filter_) |
777 message_filter_ = new AutomationMessageFilter(this); | 771 message_filter_ = new AutomationMessageFilter(this); |
778 } | 772 } |
779 | 773 |
780 void AutomationInternalCustomBindings::GetSchemaAdditions( | 774 void AutomationInternalCustomBindings::GetSchemaAdditions( |
781 const v8::FunctionCallbackInfo<v8::Value>& args) { | 775 const v8::FunctionCallbackInfo<v8::Value>& args) { |
782 v8::Local<v8::Object> additions = v8::Object::New(GetIsolate()); | 776 v8::Local<v8::Object> additions = v8::Object::New(GetIsolate()); |
783 | 777 |
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())); | 778 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) { | 779 for (int i = ui::AX_NAME_FROM_NONE; i <= ui::AX_NAME_FROM_LAST; ++i) { |
802 name_from_type->Set( | 780 name_from_type->Set( |
803 v8::Integer::New(GetIsolate(), i), | 781 v8::Integer::New(GetIsolate(), i), |
804 CreateV8String(GetIsolate(), | 782 CreateV8String(GetIsolate(), |
805 ui::ToString(static_cast<ui::AXNameFrom>(i)))); | 783 ui::ToString(static_cast<ui::AXNameFrom>(i)))); |
806 } | 784 } |
807 | 785 |
808 additions->Set(v8::String::NewFromUtf8(GetIsolate(), "NameFromType"), | 786 additions->Set(v8::String::NewFromUtf8(GetIsolate(), "NameFromType"), |
809 name_from_type); | 787 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)); | 1393 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 2U)); |
1416 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); | 1394 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); |
1417 v8::Local<v8::Array> nodes(v8::Array::New(GetIsolate(), ids.size())); | 1395 v8::Local<v8::Array> nodes(v8::Array::New(GetIsolate(), ids.size())); |
1418 args->Set(1U, nodes); | 1396 args->Set(1U, nodes); |
1419 for (size_t i = 0; i < ids.size(); ++i) | 1397 for (size_t i = 0; i < ids.size(); ++i) |
1420 nodes->Set(i, v8::Integer::New(GetIsolate(), ids[i])); | 1398 nodes->Set(i, v8::Integer::New(GetIsolate(), ids[i])); |
1421 context()->DispatchEvent("automationInternal.onNodesRemoved", args); | 1399 context()->DispatchEvent("automationInternal.onNodesRemoved", args); |
1422 } | 1400 } |
1423 | 1401 |
1424 } // namespace extensions | 1402 } // namespace extensions |
OLD | NEW |