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