forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathautomation_internal_custom_bindings.h
188 lines (148 loc) · 7.04 KB
/
automation_internal_custom_bindings.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_
#define CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "chrome/common/extensions/api/automation.h"
#include "extensions/renderer/object_backed_native_handler.h"
#include "ipc/ipc_message.h"
#include "ui/accessibility/ax_tree.h"
#include "v8/include/v8.h"
struct ExtensionMsg_AccessibilityEventParams;
struct ExtensionMsg_AccessibilityLocationChangeParams;
namespace extensions {
class AutomationInternalCustomBindings;
class AutomationMessageFilter;
struct TreeCache {
TreeCache();
~TreeCache();
int tab_id;
int tree_id;
int parent_node_id_from_parent_tree;
gfx::Vector2d location_offset;
ui::AXTree tree;
AutomationInternalCustomBindings* owner;
};
struct TreeChangeObserver {
int id;
api::automation::TreeChangeObserverFilter filter;
};
// The native component of custom bindings for the chrome.automationInternal
// API.
class AutomationInternalCustomBindings : public ObjectBackedNativeHandler,
public ui::AXTreeDelegate {
public:
explicit AutomationInternalCustomBindings(ScriptContext* context);
~AutomationInternalCustomBindings() override;
void OnMessageReceived(const IPC::Message& message);
TreeCache* GetTreeCacheFromTreeID(int tree_id);
ui::AXNode* GetParent(ui::AXNode* node, TreeCache** in_out_cache);
ScriptContext* context() const {
return ObjectBackedNativeHandler::context();
}
private:
// ObjectBackedNativeHandler overrides:
void Invalidate() override;
// Returns whether this extension has the "interact" permission set (either
// explicitly or implicitly after manifest parsing).
void IsInteractPermitted(const v8::FunctionCallbackInfo<v8::Value>& args);
// Returns an object with bindings that will be added to the
// chrome.automation namespace.
void GetSchemaAdditions(const v8::FunctionCallbackInfo<v8::Value>& args);
// Get the routing ID for the extension.
void GetRoutingID(const v8::FunctionCallbackInfo<v8::Value>& args);
// This is called by automation_internal_custom_bindings.js to indicate
// that an API was called that needs access to accessibility trees. This
// enables the MessageFilter that allows us to listen to accessibility
// events forwarded to this process.
void StartCachingAccessibilityTrees(
const v8::FunctionCallbackInfo<v8::Value>& args);
// Called when an accessibility tree is destroyed and needs to be
// removed from our cache.
// Args: int ax_tree_id
void DestroyAccessibilityTree(
const v8::FunctionCallbackInfo<v8::Value>& args);
void AddTreeChangeObserver(const v8::FunctionCallbackInfo<v8::Value>& args);
void RemoveTreeChangeObserver(
const v8::FunctionCallbackInfo<v8::Value>& args);
void GetFocus(const v8::FunctionCallbackInfo<v8::Value>& args);
// Given an initial TreeCache, return the TreeCache and node of the focused
// node within this tree or a focused descendant tree.
bool GetFocusInternal(TreeCache* top_cache,
TreeCache** out_cache,
ui::AXNode** out_node);
void RouteTreeIDFunction(const std::string& name,
void (*callback)(v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
TreeCache* cache));
void RouteNodeIDFunction(const std::string& name,
void (*callback)(v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
TreeCache* cache,
ui::AXNode* node));
void RouteNodeIDPlusAttributeFunction(
const std::string& name,
void (*callback)(v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
ui::AXNode* node,
const std::string& attribute_name));
void RouteNodeIDPlusRangeFunction(
const std::string& name,
void (*callback)(v8::Isolate* isolate,
v8::ReturnValue<v8::Value> result,
TreeCache* cache,
ui::AXNode* node,
int start,
int end));
//
// Access the cached accessibility trees and properties of their nodes.
//
// Args: int ax_tree_id, int node_id, Returns: int child_id.
void GetChildIDAtIndex(const v8::FunctionCallbackInfo<v8::Value>& args);
// Args: int ax_tree_id, int node_id
// Returns: JS object with a map from html attribute key to value.
void GetHtmlAttributes(const v8::FunctionCallbackInfo<v8::Value>& args);
// Args: int ax_tree_id, int node_id
// Returns: JS object with a string key for each state flag that's set.
void GetState(const v8::FunctionCallbackInfo<v8::Value>& args);
//
// Helper functions.
//
// Handle accessibility events from the browser process.
void OnAccessibilityEvent(const ExtensionMsg_AccessibilityEventParams& params,
bool is_active_profile);
void OnAccessibilityLocationChange(
const ExtensionMsg_AccessibilityLocationChangeParams& params);
void UpdateOverallTreeChangeObserverFilter();
// AXTreeDelegate implementation.
void OnNodeDataWillChange(ui::AXTree* tree,
const ui::AXNodeData& old_node_data,
const ui::AXNodeData& new_node_data) override;
void OnTreeDataChanged(ui::AXTree* tree) override;
void OnNodeWillBeDeleted(ui::AXTree* tree, ui::AXNode* node) override;
void OnSubtreeWillBeDeleted(ui::AXTree* tree, ui::AXNode* node) override;
void OnNodeCreated(ui::AXTree* tree, ui::AXNode* node) override;
void OnNodeChanged(ui::AXTree* tree, ui::AXNode* node) override;
void OnAtomicUpdateFinished(ui::AXTree* tree,
bool root_changed,
const std::vector<Change>& changes) override;
void SendTreeChangeEvent(api::automation::TreeChangeType change_type,
ui::AXTree* tree,
ui::AXNode* node);
void SendChildTreeIDEvent(ui::AXTree* tree, ui::AXNode* node);
void SendNodesRemovedEvent(ui::AXTree* tree, const std::vector<int>& ids);
base::hash_map<int, TreeCache*> tree_id_to_tree_cache_map_;
base::hash_map<ui::AXTree*, TreeCache*> axtree_to_tree_cache_map_;
scoped_refptr<AutomationMessageFilter> message_filter_;
bool is_active_profile_;
std::vector<TreeChangeObserver> tree_change_observers_;
// A bit-map of api::automation::TreeChangeObserverFilter.
int tree_change_observer_overall_filter_;
std::vector<int> deleted_node_ids_;
std::vector<int> text_changed_node_ids_;
DISALLOW_COPY_AND_ASSIGN(AutomationInternalCustomBindings);
};
} // namespace extensions
#endif // CHROME_RENDERER_EXTENSIONS_AUTOMATION_INTERNAL_CUSTOM_BINDINGS_H_