Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / renderer / extensions / automation_internal_custom_bindings.h
blobc4f2cd23850cfc59bbc3e764b434aa2a19d99c14
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
3 // found in the LICENSE file.
5 #ifndef CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_
6 #define CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_
8 #include "base/compiler_specific.h"
9 #include "chrome/common/extensions/api/automation.h"
10 #include "extensions/renderer/object_backed_native_handler.h"
11 #include "ipc/ipc_message.h"
12 #include "ui/accessibility/ax_tree.h"
13 #include "v8/include/v8.h"
15 struct ExtensionMsg_AccessibilityEventParams;
17 namespace extensions {
19 class AutomationMessageFilter;
21 struct TreeCache {
22 TreeCache();
23 ~TreeCache();
25 int tab_id;
26 int tree_id;
28 gfx::Vector2d location_offset;
29 ui::AXTree tree;
32 // The native component of custom bindings for the chrome.automationInternal
33 // API.
34 class AutomationInternalCustomBindings : public ObjectBackedNativeHandler,
35 public ui::AXTreeDelegate {
36 public:
37 explicit AutomationInternalCustomBindings(ScriptContext* context);
39 ~AutomationInternalCustomBindings() override;
41 void OnMessageReceived(const IPC::Message& message);
43 private:
44 // Returns whether this extension has the "interact" permission set (either
45 // explicitly or implicitly after manifest parsing).
46 void IsInteractPermitted(const v8::FunctionCallbackInfo<v8::Value>& args);
48 // Returns an object with bindings that will be added to the
49 // chrome.automation namespace.
50 void GetSchemaAdditions(const v8::FunctionCallbackInfo<v8::Value>& args);
52 // Get the routing ID for the extension.
53 void GetRoutingID(const v8::FunctionCallbackInfo<v8::Value>& args);
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);
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);
69 // Access the cached accessibility trees and properties of their nodes.
72 // Args: int ax_tree_id, Returns: int root_node_id.
73 void GetRootID(const v8::FunctionCallbackInfo<v8::Value>& args);
75 // Args: int ax_tree_id, int node_id, Returns: int parent_node_id.
76 void GetParentID(const v8::FunctionCallbackInfo<v8::Value>& args);
78 // Args: int ax_tree_id, int node_id, Returns: int child_count.
79 void GetChildCount(const v8::FunctionCallbackInfo<v8::Value>& args);
81 // Args: int ax_tree_id, int node_id, Returns: int child_id.
82 void GetChildIDAtIndex(const v8::FunctionCallbackInfo<v8::Value>& args);
84 // Args: int ax_tree_id, int node_id, Returns: int index_in_parent.
85 void GetIndexInParent(const v8::FunctionCallbackInfo<v8::Value>& args);
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);
91 // Args: int ax_tree_id, int node_id, Returns: string role_name
92 void GetRole(const v8::FunctionCallbackInfo<v8::Value>& args);
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);
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);
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);
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);
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);
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);
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);
123 // Helper functions.
126 // Throw an exception if we get bad arguments.
127 void ThrowInvalidArgumentsException(
128 const v8::FunctionCallbackInfo<v8::Value>& args);
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);
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);
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);
150 // Handle accessibility events from the browser process.
151 void OnAccessibilityEvent(
152 const ExtensionMsg_AccessibilityEventParams& params);
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;
163 void SendTreeChangeEvent(api::automation::TreeChangeType change_type,
164 ui::AXTree* tree,
165 ui::AXNode* node);
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_;
171 DISALLOW_COPY_AND_ASSIGN(AutomationInternalCustomBindings);
174 } // namespace extensions
176 #endif // CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_