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 #ifndef CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_ | 5 #ifndef CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_ |
6 #define CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_ | 6 #define CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "chrome/common/extensions/api/automation.h" | |
10 #include "extensions/renderer/object_backed_native_handler.h" | 9 #include "extensions/renderer/object_backed_native_handler.h" |
11 #include "ipc/ipc_message.h" | 10 #include "ipc/ipc_message.h" |
12 #include "ui/accessibility/ax_tree.h" | 11 #include "ui/accessibility/ax_tree.h" |
13 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
14 | 13 |
15 struct ExtensionMsg_AccessibilityEventParams; | 14 struct ExtensionMsg_AccessibilityEventParams; |
16 | 15 |
17 namespace extensions { | 16 namespace extensions { |
18 | 17 |
19 class AutomationMessageFilter; | 18 class AutomationMessageFilter; |
20 | 19 |
21 struct TreeCache { | |
22 TreeCache(); | |
23 ~TreeCache(); | |
24 | |
25 int tab_id; | |
26 int tree_id; | |
27 | |
28 gfx::Vector2d location_offset; | |
29 ui::AXTree tree; | |
30 }; | |
31 | |
32 // The native component of custom bindings for the chrome.automationInternal | 20 // The native component of custom bindings for the chrome.automationInternal |
33 // API. | 21 // API. |
34 class AutomationInternalCustomBindings : public ObjectBackedNativeHandler, | 22 class AutomationInternalCustomBindings : public ObjectBackedNativeHandler { |
35 public ui::AXTreeDelegate { | |
36 public: | 23 public: |
37 explicit AutomationInternalCustomBindings(ScriptContext* context); | 24 explicit AutomationInternalCustomBindings(ScriptContext* context); |
38 | 25 |
39 ~AutomationInternalCustomBindings() override; | 26 ~AutomationInternalCustomBindings() override; |
40 | 27 |
41 void OnMessageReceived(const IPC::Message& message); | 28 bool OnMessageReceived(const IPC::Message& message); |
42 | 29 |
43 private: | 30 private: |
44 // Returns whether this extension has the "interact" permission set (either | 31 // Returns whether this extension has the "interact" permission set (either |
45 // explicitly or implicitly after manifest parsing). | 32 // explicitly or implicitly after manifest parsing). |
46 void IsInteractPermitted(const v8::FunctionCallbackInfo<v8::Value>& args); | 33 void IsInteractPermitted(const v8::FunctionCallbackInfo<v8::Value>& args); |
47 | 34 |
48 // Returns an object with bindings that will be added to the | 35 // Returns an object with bindings that will be added to the |
49 // chrome.automation namespace. | 36 // chrome.automation namespace. |
50 void GetSchemaAdditions(const v8::FunctionCallbackInfo<v8::Value>& args); | 37 void GetSchemaAdditions(const v8::FunctionCallbackInfo<v8::Value>& args); |
51 | 38 |
52 // Get the routing ID for the extension. | 39 // Get the routing ID for the extension. |
53 void GetRoutingID(const v8::FunctionCallbackInfo<v8::Value>& args); | 40 void GetRoutingID(const v8::FunctionCallbackInfo<v8::Value>& args); |
54 | 41 |
55 // This is called by automation_internal_custom_bindings.js to indicate | |
56 // that an API was called that needs access to accessibility trees. This | |
57 // enables the MessageFilter that allows us to listen to accessibility | |
58 // events forwarded to this process. | |
59 void StartCachingAccessibilityTrees( | |
60 const v8::FunctionCallbackInfo<v8::Value>& args); | |
61 | |
62 // Called when an accessibility tree is destroyed and needs to be | |
63 // removed from our cache. | |
64 // Args: int ax_tree_id | |
65 void DestroyAccessibilityTree( | |
66 const v8::FunctionCallbackInfo<v8::Value>& args); | |
67 | |
68 // | |
69 // Access the cached accessibility trees and properties of their nodes. | |
70 // | |
71 | |
72 // Args: int ax_tree_id, Returns: int root_node_id. | |
73 void GetRootID(const v8::FunctionCallbackInfo<v8::Value>& args); | |
74 | |
75 // Args: int ax_tree_id, int node_id, Returns: int parent_node_id. | |
76 void GetParentID(const v8::FunctionCallbackInfo<v8::Value>& args); | |
77 | |
78 // Args: int ax_tree_id, int node_id, Returns: int child_count. | |
79 void GetChildCount(const v8::FunctionCallbackInfo<v8::Value>& args); | |
80 | |
81 // Args: int ax_tree_id, int node_id, Returns: int child_id. | |
82 void GetChildIDAtIndex(const v8::FunctionCallbackInfo<v8::Value>& args); | |
83 | |
84 // Args: int ax_tree_id, int node_id, Returns: int index_in_parent. | |
85 void GetIndexInParent(const v8::FunctionCallbackInfo<v8::Value>& args); | |
86 | |
87 // Args: int ax_tree_id, int node_id | |
88 // Returns: JS object with a string key for each state flag that's set. | |
89 void GetState(const v8::FunctionCallbackInfo<v8::Value>& args); | |
90 | |
91 // Args: int ax_tree_id, int node_id, Returns: string role_name | |
92 void GetRole(const v8::FunctionCallbackInfo<v8::Value>& args); | |
93 | |
94 // Args: int ax_tree_id, int node_id | |
95 // Returns: JS object with {left, top, width, height} | |
96 void GetLocation(const v8::FunctionCallbackInfo<v8::Value>& args); | |
97 | |
98 // Args: int ax_tree_id, int node_id, string attribute_name | |
99 // Returns: string attribute_value. | |
100 void GetStringAttribute(const v8::FunctionCallbackInfo<v8::Value>& args); | |
101 | |
102 // Args: int ax_tree_id, int node_id, string attribute_name | |
103 // Returns: bool attribute_value. | |
104 void GetBoolAttribute(const v8::FunctionCallbackInfo<v8::Value>& args); | |
105 | |
106 // Args: int ax_tree_id, int node_id, string attribute_name | |
107 // Returns: int attribute_value. | |
108 void GetIntAttribute(const v8::FunctionCallbackInfo<v8::Value>& args); | |
109 | |
110 // Args: int ax_tree_id, int node_id, string attribute_name | |
111 // Returns: float attribute_value. | |
112 void GetFloatAttribute(const v8::FunctionCallbackInfo<v8::Value>& args); | |
113 | |
114 // Args: int ax_tree_id, int node_id, string attribute_name | |
115 // Returns: JS array of int attribute_values. | |
116 void GetIntListAttribute(const v8::FunctionCallbackInfo<v8::Value>& args); | |
117 | |
118 // Args: int ax_tree_id, int node_id, string attribute_name | |
119 // Returns: string attribute_value. | |
120 void GetHtmlAttribute(const v8::FunctionCallbackInfo<v8::Value>& args); | |
121 | |
122 // | |
123 // Helper functions. | |
124 // | |
125 | |
126 // Throw an exception if we get bad arguments. | |
127 void ThrowInvalidArgumentsException( | |
128 const v8::FunctionCallbackInfo<v8::Value>& args); | |
129 | |
130 // For any function that takes int ax_tree_id, int node_id as its first | |
131 // two arguments, returns the tree and node it corresponds to, or returns | |
132 // false if not found. | |
133 bool GetNodeHelper( | |
134 const v8::FunctionCallbackInfo<v8::Value>& args, | |
135 TreeCache** out_cache, | |
136 ui::AXNode** out_node); | |
137 | |
138 // For any function that takes int ax_tree_id, int node_id, string attr | |
139 // as its first, returns the node it corresponds to and the string as | |
140 // a UTF8 string. | |
141 bool GetAttributeHelper( | |
142 const v8::FunctionCallbackInfo<v8::Value>& args, | |
143 ui::AXNode** out_node, | |
144 std::string* out_attribute_name); | |
145 | |
146 // Create a V8 string from a string. | |
147 v8::Local<v8::Value> CreateV8String(const char* str); | |
148 v8::Local<v8::Value> CreateV8String(const std::string& str); | |
149 | |
150 // Handle accessibility events from the browser process. | 42 // Handle accessibility events from the browser process. |
151 void OnAccessibilityEvent( | 43 void OnAccessibilityEvent( |
152 const ExtensionMsg_AccessibilityEventParams& params); | 44 const ExtensionMsg_AccessibilityEventParams& params); |
153 | 45 |
154 // AXTreeDelegate implementation. | |
155 void OnNodeWillBeDeleted(ui::AXTree* tree, ui::AXNode* node) override; | |
156 void OnSubtreeWillBeDeleted(ui::AXTree* tree, ui::AXNode* node) override; | |
157 void OnNodeCreated(ui::AXTree* tree, ui::AXNode* node) override; | |
158 void OnNodeChanged(ui::AXTree* tree, ui::AXNode* node) override; | |
159 void OnAtomicUpdateFinished(ui::AXTree* tree, | |
160 bool root_changed, | |
161 const std::vector<Change>& changes) override; | |
162 | |
163 void SendTreeChangeEvent(api::automation::TreeChangeType change_type, | |
164 ui::AXTree* tree, | |
165 ui::AXNode* node); | |
166 | |
167 base::hash_map<int, TreeCache*> tree_id_to_tree_cache_map_; | |
168 base::hash_map<ui::AXTree*, TreeCache*> axtree_to_tree_cache_map_; | |
169 scoped_refptr<AutomationMessageFilter> message_filter_; | 46 scoped_refptr<AutomationMessageFilter> message_filter_; |
170 | 47 |
171 DISALLOW_COPY_AND_ASSIGN(AutomationInternalCustomBindings); | 48 DISALLOW_COPY_AND_ASSIGN(AutomationInternalCustomBindings); |
172 }; | 49 }; |
173 | 50 |
174 } // namespace extensions | 51 } // namespace extensions |
175 | 52 |
176 #endif // CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_ | 53 #endif // CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_ |
OLD | NEW |