Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: chrome/renderer/extensions/automation_internal_custom_bindings.cc

Issue 1407413002: Move some AX attrs from AXNodeData to AXTreeData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Finish automation API changes Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 RouteFunction(#FN, \ 109 RouteFunction(#FN, \
110 base::Bind(&AutomationInternalCustomBindings::FN, \ 110 base::Bind(&AutomationInternalCustomBindings::FN, \
111 base::Unretained(this))) 111 base::Unretained(this)))
112 112
113 ROUTE_FUNCTION(IsInteractPermitted); 113 ROUTE_FUNCTION(IsInteractPermitted);
114 ROUTE_FUNCTION(GetSchemaAdditions); 114 ROUTE_FUNCTION(GetSchemaAdditions);
115 ROUTE_FUNCTION(GetRoutingID); 115 ROUTE_FUNCTION(GetRoutingID);
116 ROUTE_FUNCTION(StartCachingAccessibilityTrees); 116 ROUTE_FUNCTION(StartCachingAccessibilityTrees);
117 ROUTE_FUNCTION(DestroyAccessibilityTree); 117 ROUTE_FUNCTION(DestroyAccessibilityTree);
118 ROUTE_FUNCTION(GetRootID); 118 ROUTE_FUNCTION(GetRootID);
119 ROUTE_FUNCTION(GetDocURL);
David Tseng 2015/10/19 18:21:38 I would like to see us to re-use get*Attribute her
120 ROUTE_FUNCTION(GetDocTitle);
121 ROUTE_FUNCTION(GetDocLoaded);
122 ROUTE_FUNCTION(GetDocLoadingProgress);
123 ROUTE_FUNCTION(GetAnchorObjectID);
124 ROUTE_FUNCTION(GetAnchorOffset);
125 ROUTE_FUNCTION(GetFocusObjectID);
126 ROUTE_FUNCTION(GetFocusOffset);
119 ROUTE_FUNCTION(GetParentID); 127 ROUTE_FUNCTION(GetParentID);
120 ROUTE_FUNCTION(GetChildCount); 128 ROUTE_FUNCTION(GetChildCount);
121 ROUTE_FUNCTION(GetChildIDAtIndex); 129 ROUTE_FUNCTION(GetChildIDAtIndex);
122 ROUTE_FUNCTION(GetIndexInParent); 130 ROUTE_FUNCTION(GetIndexInParent);
123 ROUTE_FUNCTION(GetState); 131 ROUTE_FUNCTION(GetState);
124 ROUTE_FUNCTION(GetRole); 132 ROUTE_FUNCTION(GetRole);
125 ROUTE_FUNCTION(GetLocation); 133 ROUTE_FUNCTION(GetLocation);
126 ROUTE_FUNCTION(GetStringAttribute); 134 ROUTE_FUNCTION(GetStringAttribute);
127 ROUTE_FUNCTION(GetBoolAttribute); 135 ROUTE_FUNCTION(GetBoolAttribute);
128 ROUTE_FUNCTION(GetIntAttribute); 136 ROUTE_FUNCTION(GetIntAttribute);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 ui::AXNode* root = cache->tree.root(); 238 ui::AXNode* root = cache->tree.root();
231 239
232 // The root can be null if this is called from an onTreeChange callback. 240 // The root can be null if this is called from an onTreeChange callback.
233 if (!root) 241 if (!root)
234 return; 242 return;
235 243
236 int root_id = root->id(); 244 int root_id = root->id();
237 args.GetReturnValue().Set(v8::Integer::New(GetIsolate(), root_id)); 245 args.GetReturnValue().Set(v8::Integer::New(GetIsolate(), root_id));
238 } 246 }
239 247
248 void AutomationInternalCustomBindings::GetDocURL(
249 const v8::FunctionCallbackInfo<v8::Value>& args) {
250 if (args.Length() != 1 || !args[0]->IsNumber()) {
251 ThrowInvalidArgumentsException(args);
252 return;
253 }
254
255 int tree_id = args[0]->Int32Value();
256 const auto iter = tree_id_to_tree_cache_map_.find(tree_id);
257 if (iter == tree_id_to_tree_cache_map_.end())
258 return;
259
260 TreeCache* cache = iter->second;
261 args.GetReturnValue().Set(
262 v8::String::NewFromUtf8(GetIsolate(), cache->tree.data().url.c_str()));
263 }
264
265 void AutomationInternalCustomBindings::GetDocTitle(
266 const v8::FunctionCallbackInfo<v8::Value>& args) {
267 if (args.Length() != 1 || !args[0]->IsNumber()) {
268 ThrowInvalidArgumentsException(args);
269 return;
270 }
271
272 int tree_id = args[0]->Int32Value();
273 const auto iter = tree_id_to_tree_cache_map_.find(tree_id);
274 if (iter == tree_id_to_tree_cache_map_.end())
275 return;
276
277 TreeCache* cache = iter->second;
278 args.GetReturnValue().Set(
279 v8::String::NewFromUtf8(GetIsolate(), cache->tree.data().title.c_str()));
280 }
281
282 void AutomationInternalCustomBindings::GetDocLoaded(
283 const v8::FunctionCallbackInfo<v8::Value>& args) {
284 if (args.Length() != 1 || !args[0]->IsNumber()) {
285 ThrowInvalidArgumentsException(args);
286 return;
287 }
288
289 int tree_id = args[0]->Int32Value();
290 const auto iter = tree_id_to_tree_cache_map_.find(tree_id);
291 if (iter == tree_id_to_tree_cache_map_.end())
292 return;
293
294 TreeCache* cache = iter->second;
295 args.GetReturnValue().Set(
296 v8::Boolean::New(GetIsolate(), cache->tree.data().loaded));
297 }
298
299 void AutomationInternalCustomBindings::GetDocLoadingProgress(
300 const v8::FunctionCallbackInfo<v8::Value>& args) {
301 if (args.Length() != 1 || !args[0]->IsNumber()) {
302 ThrowInvalidArgumentsException(args);
303 return;
304 }
305
306 int tree_id = args[0]->Int32Value();
307 const auto iter = tree_id_to_tree_cache_map_.find(tree_id);
308 if (iter == tree_id_to_tree_cache_map_.end())
309 return;
310
311 TreeCache* cache = iter->second;
312 args.GetReturnValue().Set(
313 v8::Number::New(GetIsolate(), cache->tree.data().loading_progress));
314 }
315
316 void AutomationInternalCustomBindings::GetAnchorObjectID(
317 const v8::FunctionCallbackInfo<v8::Value>& args) {
318 if (args.Length() != 1 || !args[0]->IsNumber()) {
319 ThrowInvalidArgumentsException(args);
320 return;
321 }
322
323 int tree_id = args[0]->Int32Value();
324 const auto iter = tree_id_to_tree_cache_map_.find(tree_id);
325 if (iter == tree_id_to_tree_cache_map_.end())
326 return;
327
328 TreeCache* cache = iter->second;
329 args.GetReturnValue().Set(
330 v8::Number::New(GetIsolate(), cache->tree.data().sel_anchor_object_id));
331 }
332
333 void AutomationInternalCustomBindings::GetAnchorOffset(
334 const v8::FunctionCallbackInfo<v8::Value>& args) {
335 if (args.Length() != 1 || !args[0]->IsNumber()) {
336 ThrowInvalidArgumentsException(args);
337 return;
338 }
339
340 int tree_id = args[0]->Int32Value();
341 const auto iter = tree_id_to_tree_cache_map_.find(tree_id);
342 if (iter == tree_id_to_tree_cache_map_.end())
343 return;
344
345 TreeCache* cache = iter->second;
346 args.GetReturnValue().Set(
347 v8::Number::New(GetIsolate(), cache->tree.data().sel_anchor_offset));
348 }
349
350 void AutomationInternalCustomBindings::GetFocusObjectID(
351 const v8::FunctionCallbackInfo<v8::Value>& args) {
352 if (args.Length() != 1 || !args[0]->IsNumber()) {
353 ThrowInvalidArgumentsException(args);
354 return;
355 }
356
357 int tree_id = args[0]->Int32Value();
358 const auto iter = tree_id_to_tree_cache_map_.find(tree_id);
359 if (iter == tree_id_to_tree_cache_map_.end())
360 return;
361
362 TreeCache* cache = iter->second;
363 args.GetReturnValue().Set(
364 v8::Number::New(GetIsolate(), cache->tree.data().sel_focus_object_id));
365 }
366
367 void AutomationInternalCustomBindings::GetFocusOffset(
368 const v8::FunctionCallbackInfo<v8::Value>& args) {
369 if (args.Length() != 1 || !args[0]->IsNumber()) {
370 ThrowInvalidArgumentsException(args);
371 return;
372 }
373
374 int tree_id = args[0]->Int32Value();
375 const auto iter = tree_id_to_tree_cache_map_.find(tree_id);
376 if (iter == tree_id_to_tree_cache_map_.end())
377 return;
378
379 TreeCache* cache = iter->second;
380 args.GetReturnValue().Set(
381 v8::Number::New(GetIsolate(), cache->tree.data().sel_focus_offset));
382 }
383
240 void AutomationInternalCustomBindings::GetParentID( 384 void AutomationInternalCustomBindings::GetParentID(
241 const v8::FunctionCallbackInfo<v8::Value>& args) { 385 const v8::FunctionCallbackInfo<v8::Value>& args) {
242 ui::AXNode* node = nullptr; 386 ui::AXNode* node = nullptr;
243 if (!GetNodeHelper(args, nullptr, &node)) 387 if (!GetNodeHelper(args, nullptr, &node))
244 return; 388 return;
245 389
246 if (!node->parent()) 390 if (!node->parent())
247 return; 391 return;
248 392
249 int parent_id = node->parent()->id(); 393 int parent_id = node->parent()->id();
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 event_params->Set(CreateV8String("treeID"), 698 event_params->Set(CreateV8String("treeID"),
555 v8::Integer::New(GetIsolate(), params.tree_id)); 699 v8::Integer::New(GetIsolate(), params.tree_id));
556 event_params->Set(CreateV8String("targetID"), 700 event_params->Set(CreateV8String("targetID"),
557 v8::Integer::New(GetIsolate(), params.id)); 701 v8::Integer::New(GetIsolate(), params.id));
558 event_params->Set(CreateV8String("eventType"), 702 event_params->Set(CreateV8String("eventType"),
559 CreateV8String(ToString(params.event_type))); 703 CreateV8String(ToString(params.event_type)));
560 args->Set(0U, event_params); 704 args->Set(0U, event_params);
561 context()->DispatchEvent("automationInternal.onAccessibilityEvent", args); 705 context()->DispatchEvent("automationInternal.onAccessibilityEvent", args);
562 } 706 }
563 707
708 void AutomationInternalCustomBindings::OnTreeDataChanged(ui::AXTree* tree) {}
709
564 void AutomationInternalCustomBindings::OnNodeWillBeDeleted(ui::AXTree* tree, 710 void AutomationInternalCustomBindings::OnNodeWillBeDeleted(ui::AXTree* tree,
565 ui::AXNode* node) { 711 ui::AXNode* node) {
566 SendTreeChangeEvent( 712 SendTreeChangeEvent(
567 api::automation::TREE_CHANGE_TYPE_NODEREMOVED, 713 api::automation::TREE_CHANGE_TYPE_NODEREMOVED,
568 tree, node); 714 tree, node);
569 } 715 }
570 716
571 void AutomationInternalCustomBindings::OnSubtreeWillBeDeleted( 717 void AutomationInternalCustomBindings::OnSubtreeWillBeDeleted(
572 ui::AXTree* tree, 718 ui::AXTree* tree,
573 ui::AXNode* node) { 719 ui::AXNode* node) {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 v8::HandleScope handle_scope(GetIsolate()); 783 v8::HandleScope handle_scope(GetIsolate());
638 v8::Context::Scope context_scope(context()->v8_context()); 784 v8::Context::Scope context_scope(context()->v8_context());
639 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 3U)); 785 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 3U));
640 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); 786 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id));
641 args->Set(1U, v8::Integer::New(GetIsolate(), node->id())); 787 args->Set(1U, v8::Integer::New(GetIsolate(), node->id()));
642 args->Set(2U, CreateV8String(ToString(change_type))); 788 args->Set(2U, CreateV8String(ToString(change_type)));
643 context()->DispatchEvent("automationInternal.onTreeChange", args); 789 context()->DispatchEvent("automationInternal.onTreeChange", args);
644 } 790 }
645 791
646 } // namespace extensions 792 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698