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

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

Issue 1457683009: Complete live region support in ChromeVox Next. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 AutomationInternalCustomBindings* owner_; 259 AutomationInternalCustomBindings* owner_;
260 bool removed_; 260 bool removed_;
261 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 261 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
262 262
263 DISALLOW_COPY_AND_ASSIGN(AutomationMessageFilter); 263 DISALLOW_COPY_AND_ASSIGN(AutomationMessageFilter);
264 }; 264 };
265 265
266 AutomationInternalCustomBindings::AutomationInternalCustomBindings( 266 AutomationInternalCustomBindings::AutomationInternalCustomBindings(
267 ScriptContext* context) 267 ScriptContext* context)
268 : ObjectBackedNativeHandler(context), is_active_profile_(true) { 268 : ObjectBackedNativeHandler(context),
269 is_active_profile_(true),
270 tree_change_observer_mask_(
271 api::automation::TREE_CHANGE_OBSERVER_MASK_NOTREECHANGES) {
269 // It's safe to use base::Unretained(this) here because these bindings 272 // It's safe to use base::Unretained(this) here because these bindings
270 // will only be called on a valid AutomationInternalCustomBindings instance 273 // will only be called on a valid AutomationInternalCustomBindings instance
271 // and none of the functions have any side effects. 274 // and none of the functions have any side effects.
272 #define ROUTE_FUNCTION(FN) \ 275 #define ROUTE_FUNCTION(FN) \
273 RouteFunction(#FN, \ 276 RouteFunction(#FN, \
274 base::Bind(&AutomationInternalCustomBindings::FN, \ 277 base::Bind(&AutomationInternalCustomBindings::FN, \
275 base::Unretained(this))) 278 base::Unretained(this)))
276 ROUTE_FUNCTION(IsInteractPermitted); 279 ROUTE_FUNCTION(IsInteractPermitted);
277 ROUTE_FUNCTION(GetSchemaAdditions); 280 ROUTE_FUNCTION(GetSchemaAdditions);
278 ROUTE_FUNCTION(GetRoutingID); 281 ROUTE_FUNCTION(GetRoutingID);
279 ROUTE_FUNCTION(StartCachingAccessibilityTrees); 282 ROUTE_FUNCTION(StartCachingAccessibilityTrees);
280 ROUTE_FUNCTION(DestroyAccessibilityTree); 283 ROUTE_FUNCTION(DestroyAccessibilityTree);
284 ROUTE_FUNCTION(SetTreeChangeObserverMask);
281 ROUTE_FUNCTION(GetChildIDAtIndex); 285 ROUTE_FUNCTION(GetChildIDAtIndex);
282 #undef ROUTE_FUNCTION 286 #undef ROUTE_FUNCTION
283 287
284 // Bindings that take a Tree ID and return a property of the tree. 288 // Bindings that take a Tree ID and return a property of the tree.
285 289
286 RouteTreeIDFunction( 290 RouteTreeIDFunction(
287 "GetRootID", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, 291 "GetRootID", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
288 TreeCache* cache) { 292 TreeCache* cache) {
289 result.Set(v8::Integer::New(isolate, cache->tree.root()->id())); 293 result.Set(v8::Integer::New(isolate, cache->tree.root()->id()));
290 }); 294 });
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 auto iter = tree_id_to_tree_cache_map_.find(tree_id); 567 auto iter = tree_id_to_tree_cache_map_.find(tree_id);
564 if (iter == tree_id_to_tree_cache_map_.end()) 568 if (iter == tree_id_to_tree_cache_map_.end())
565 return; 569 return;
566 570
567 TreeCache* cache = iter->second; 571 TreeCache* cache = iter->second;
568 tree_id_to_tree_cache_map_.erase(tree_id); 572 tree_id_to_tree_cache_map_.erase(tree_id);
569 axtree_to_tree_cache_map_.erase(&cache->tree); 573 axtree_to_tree_cache_map_.erase(&cache->tree);
570 delete cache; 574 delete cache;
571 } 575 }
572 576
577 void AutomationInternalCustomBindings::SetTreeChangeObserverMask(
578 const v8::FunctionCallbackInfo<v8::Value>& args) {
579 if (args.Length() != 1 || !args[0]->IsString()) {
580 ThrowInvalidArgumentsException(this);
581 return;
582 }
583
584 std::string mask_str = *v8::String::Utf8Value(args[0]);
585 tree_change_observer_mask_ =
Peter Lundblad 2015/11/20 13:42:59 What catches invalid values?
dmazzoni 2015/11/23 20:16:50 ParseTreeChangeObserverMask is autogenerated, it t
586 api::automation::ParseTreeChangeObserverMask(mask_str);
587 }
588
573 void AutomationInternalCustomBindings::RouteTreeIDFunction( 589 void AutomationInternalCustomBindings::RouteTreeIDFunction(
574 const std::string& name, 590 const std::string& name,
575 TreeIDFunction callback) { 591 TreeIDFunction callback) {
576 scoped_refptr<TreeIDWrapper> wrapper = new TreeIDWrapper(this, callback); 592 scoped_refptr<TreeIDWrapper> wrapper = new TreeIDWrapper(this, callback);
577 RouteFunction(name, base::Bind(&TreeIDWrapper::Run, wrapper)); 593 RouteFunction(name, base::Bind(&TreeIDWrapper::Run, wrapper));
578 } 594 }
579 595
580 void AutomationInternalCustomBindings::RouteNodeIDFunction( 596 void AutomationInternalCustomBindings::RouteNodeIDFunction(
581 const std::string& name, 597 const std::string& name,
582 NodeIDFunction callback) { 598 NodeIDFunction callback) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 } 748 }
733 749
734 void AutomationInternalCustomBindings::SendTreeChangeEvent( 750 void AutomationInternalCustomBindings::SendTreeChangeEvent(
735 api::automation::TreeChangeType change_type, 751 api::automation::TreeChangeType change_type,
736 ui::AXTree* tree, 752 ui::AXTree* tree,
737 ui::AXNode* node) { 753 ui::AXNode* node) {
738 // Don't send tree change events when it's not the active profile. 754 // Don't send tree change events when it's not the active profile.
739 if (!is_active_profile_) 755 if (!is_active_profile_)
740 return; 756 return;
741 757
758 if (node->data().role != ui::AX_ROLE_EMBEDDED_OBJECT &&
759 node->data().role != ui::AX_ROLE_WEB_VIEW) {
760 switch (tree_change_observer_mask_) {
761 case api::automation::TREE_CHANGE_OBSERVER_MASK_NOTREECHANGES:
762 default:
763 return;
764 case api::automation::TREE_CHANGE_OBSERVER_MASK_LIVEREGIONTREECHANGES:
765 if (!node->data().HasStringAttribute(
766 ui::AX_ATTR_CONTAINER_LIVE_STATUS) &&
767 node->data().role != ui::AX_ROLE_ALERT) {
768 return;
769 }
770 break;
771 case api::automation::TREE_CHANGE_OBSERVER_MASK_ALLTREECHANGES:
772 break;
773 }
774 }
775
742 auto iter = axtree_to_tree_cache_map_.find(tree); 776 auto iter = axtree_to_tree_cache_map_.find(tree);
743 if (iter == axtree_to_tree_cache_map_.end()) 777 if (iter == axtree_to_tree_cache_map_.end())
744 return; 778 return;
745 779
746 int tree_id = iter->second->tree_id; 780 int tree_id = iter->second->tree_id;
747 781
748 v8::Isolate* isolate = GetIsolate(); 782 v8::Isolate* isolate = GetIsolate();
749 v8::HandleScope handle_scope(isolate); 783 v8::HandleScope handle_scope(isolate);
750 v8::Context::Scope context_scope(context()->v8_context()); 784 v8::Context::Scope context_scope(context()->v8_context());
751 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 3U)); 785 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 3U));
752 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); 786 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id));
753 args->Set(1U, v8::Integer::New(GetIsolate(), node->id())); 787 args->Set(1U, v8::Integer::New(GetIsolate(), node->id()));
754 args->Set(2U, CreateV8String(isolate, ToString(change_type))); 788 args->Set(2U, CreateV8String(isolate, ToString(change_type)));
755 context()->DispatchEvent("automationInternal.onTreeChange", args); 789 context()->DispatchEvent("automationInternal.onTreeChange", args);
756 } 790 }
757 791
758 } // namespace extensions 792 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698