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" | 9 #include "chrome/common/extensions/api/automation.h" |
10 #include "extensions/renderer/object_backed_native_handler.h" | 10 #include "extensions/renderer/object_backed_native_handler.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 // API. | 33 // API. |
34 class AutomationInternalCustomBindings : public ObjectBackedNativeHandler, | 34 class AutomationInternalCustomBindings : public ObjectBackedNativeHandler, |
35 public ui::AXTreeDelegate { | 35 public ui::AXTreeDelegate { |
36 public: | 36 public: |
37 explicit AutomationInternalCustomBindings(ScriptContext* context); | 37 explicit AutomationInternalCustomBindings(ScriptContext* context); |
38 | 38 |
39 ~AutomationInternalCustomBindings() override; | 39 ~AutomationInternalCustomBindings() override; |
40 | 40 |
41 void OnMessageReceived(const IPC::Message& message); | 41 void OnMessageReceived(const IPC::Message& message); |
42 | 42 |
| 43 TreeCache* GetTreeCacheFromTreeID(int tree_id); |
| 44 |
| 45 ScriptContext* context() const { |
| 46 return ObjectBackedNativeHandler::context(); |
| 47 } |
| 48 |
43 private: | 49 private: |
44 // Returns whether this extension has the "interact" permission set (either | 50 // Returns whether this extension has the "interact" permission set (either |
45 // explicitly or implicitly after manifest parsing). | 51 // explicitly or implicitly after manifest parsing). |
46 void IsInteractPermitted(const v8::FunctionCallbackInfo<v8::Value>& args); | 52 void IsInteractPermitted(const v8::FunctionCallbackInfo<v8::Value>& args); |
47 | 53 |
48 // Returns an object with bindings that will be added to the | 54 // Returns an object with bindings that will be added to the |
49 // chrome.automation namespace. | 55 // chrome.automation namespace. |
50 void GetSchemaAdditions(const v8::FunctionCallbackInfo<v8::Value>& args); | 56 void GetSchemaAdditions(const v8::FunctionCallbackInfo<v8::Value>& args); |
51 | 57 |
52 // Get the routing ID for the extension. | 58 // Get the routing ID for the extension. |
53 void GetRoutingID(const v8::FunctionCallbackInfo<v8::Value>& args); | 59 void GetRoutingID(const v8::FunctionCallbackInfo<v8::Value>& args); |
54 | 60 |
55 // This is called by automation_internal_custom_bindings.js to indicate | 61 // This is called by automation_internal_custom_bindings.js to indicate |
56 // that an API was called that needs access to accessibility trees. This | 62 // that an API was called that needs access to accessibility trees. This |
57 // enables the MessageFilter that allows us to listen to accessibility | 63 // enables the MessageFilter that allows us to listen to accessibility |
58 // events forwarded to this process. | 64 // events forwarded to this process. |
59 void StartCachingAccessibilityTrees( | 65 void StartCachingAccessibilityTrees( |
60 const v8::FunctionCallbackInfo<v8::Value>& args); | 66 const v8::FunctionCallbackInfo<v8::Value>& args); |
61 | 67 |
62 // Called when an accessibility tree is destroyed and needs to be | 68 // Called when an accessibility tree is destroyed and needs to be |
63 // removed from our cache. | 69 // removed from our cache. |
64 // Args: int ax_tree_id | 70 // Args: int ax_tree_id |
65 void DestroyAccessibilityTree( | 71 void DestroyAccessibilityTree( |
66 const v8::FunctionCallbackInfo<v8::Value>& args); | 72 const v8::FunctionCallbackInfo<v8::Value>& args); |
67 | 73 |
| 74 void RouteTreeIDFunction(const std::string& name, |
| 75 void (*callback)(v8::Isolate* isolate, |
| 76 v8::ReturnValue<v8::Value> result, |
| 77 TreeCache* cache)); |
| 78 |
| 79 void RouteNodeIDFunction(const std::string& name, |
| 80 void (*callback)(v8::Isolate* isolate, |
| 81 v8::ReturnValue<v8::Value> result, |
| 82 TreeCache* cache, |
| 83 ui::AXNode* node)); |
| 84 |
| 85 void RouteNodeIDPlusAttributeFunction( |
| 86 const std::string& name, |
| 87 void (*callback)(v8::Isolate* isolate, |
| 88 v8::ReturnValue<v8::Value> result, |
| 89 ui::AXNode* node, |
| 90 const std::string& attribute_name)); |
| 91 |
68 // | 92 // |
69 // Access the cached accessibility trees and properties of their nodes. | 93 // Access the cached accessibility trees and properties of their nodes. |
70 // | 94 // |
71 | 95 |
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. | 96 // Args: int ax_tree_id, int node_id, Returns: int parent_node_id. |
76 void GetParentID(const v8::FunctionCallbackInfo<v8::Value>& args); | 97 void GetParentID(const v8::FunctionCallbackInfo<v8::Value>& args); |
77 | 98 |
78 // Args: int ax_tree_id, int node_id, Returns: int child_count. | 99 // Args: int ax_tree_id, int node_id, Returns: int child_count. |
79 void GetChildCount(const v8::FunctionCallbackInfo<v8::Value>& args); | 100 void GetChildCount(const v8::FunctionCallbackInfo<v8::Value>& args); |
80 | 101 |
81 // Args: int ax_tree_id, int node_id, Returns: int child_id. | 102 // Args: int ax_tree_id, int node_id, Returns: int child_id. |
82 void GetChildIDAtIndex(const v8::FunctionCallbackInfo<v8::Value>& args); | 103 void GetChildIDAtIndex(const v8::FunctionCallbackInfo<v8::Value>& args); |
83 | 104 |
84 // Args: int ax_tree_id, int node_id, Returns: int index_in_parent. | 105 // Args: int ax_tree_id, int node_id, Returns: int index_in_parent. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 void GetIntListAttribute(const v8::FunctionCallbackInfo<v8::Value>& args); | 137 void GetIntListAttribute(const v8::FunctionCallbackInfo<v8::Value>& args); |
117 | 138 |
118 // Args: int ax_tree_id, int node_id, string attribute_name | 139 // Args: int ax_tree_id, int node_id, string attribute_name |
119 // Returns: string attribute_value. | 140 // Returns: string attribute_value. |
120 void GetHtmlAttribute(const v8::FunctionCallbackInfo<v8::Value>& args); | 141 void GetHtmlAttribute(const v8::FunctionCallbackInfo<v8::Value>& args); |
121 | 142 |
122 // | 143 // |
123 // Helper functions. | 144 // Helper functions. |
124 // | 145 // |
125 | 146 |
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. | 147 // Handle accessibility events from the browser process. |
151 void OnAccessibilityEvent(const ExtensionMsg_AccessibilityEventParams& params, | 148 void OnAccessibilityEvent(const ExtensionMsg_AccessibilityEventParams& params, |
152 bool is_active_profile); | 149 bool is_active_profile); |
153 | 150 |
154 // AXTreeDelegate implementation. | 151 // AXTreeDelegate implementation. |
| 152 void OnTreeDataChanged(ui::AXTree* tree) override; |
155 void OnNodeWillBeDeleted(ui::AXTree* tree, ui::AXNode* node) override; | 153 void OnNodeWillBeDeleted(ui::AXTree* tree, ui::AXNode* node) override; |
156 void OnSubtreeWillBeDeleted(ui::AXTree* tree, ui::AXNode* node) override; | 154 void OnSubtreeWillBeDeleted(ui::AXTree* tree, ui::AXNode* node) override; |
157 void OnNodeCreated(ui::AXTree* tree, ui::AXNode* node) override; | 155 void OnNodeCreated(ui::AXTree* tree, ui::AXNode* node) override; |
158 void OnNodeChanged(ui::AXTree* tree, ui::AXNode* node) override; | 156 void OnNodeChanged(ui::AXTree* tree, ui::AXNode* node) override; |
159 void OnAtomicUpdateFinished(ui::AXTree* tree, | 157 void OnAtomicUpdateFinished(ui::AXTree* tree, |
160 bool root_changed, | 158 bool root_changed, |
161 const std::vector<Change>& changes) override; | 159 const std::vector<Change>& changes) override; |
162 | 160 |
163 void SendTreeChangeEvent(api::automation::TreeChangeType change_type, | 161 void SendTreeChangeEvent(api::automation::TreeChangeType change_type, |
164 ui::AXTree* tree, | 162 ui::AXTree* tree, |
165 ui::AXNode* node); | 163 ui::AXNode* node); |
166 | 164 |
167 base::hash_map<int, TreeCache*> tree_id_to_tree_cache_map_; | 165 base::hash_map<int, TreeCache*> tree_id_to_tree_cache_map_; |
168 base::hash_map<ui::AXTree*, TreeCache*> axtree_to_tree_cache_map_; | 166 base::hash_map<ui::AXTree*, TreeCache*> axtree_to_tree_cache_map_; |
169 scoped_refptr<AutomationMessageFilter> message_filter_; | 167 scoped_refptr<AutomationMessageFilter> message_filter_; |
170 bool is_active_profile_; | 168 bool is_active_profile_; |
171 | 169 |
172 DISALLOW_COPY_AND_ASSIGN(AutomationInternalCustomBindings); | 170 DISALLOW_COPY_AND_ASSIGN(AutomationInternalCustomBindings); |
173 }; | 171 }; |
174 | 172 |
175 } // namespace extensions | 173 } // namespace extensions |
176 | 174 |
177 #endif // CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_ | 175 #endif // CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_ |
OLD | NEW |