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

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: Rebase Created 5 years 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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 386
387 AutomationInternalCustomBindings* owner_; 387 AutomationInternalCustomBindings* owner_;
388 bool removed_; 388 bool removed_;
389 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 389 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
390 390
391 DISALLOW_COPY_AND_ASSIGN(AutomationMessageFilter); 391 DISALLOW_COPY_AND_ASSIGN(AutomationMessageFilter);
392 }; 392 };
393 393
394 AutomationInternalCustomBindings::AutomationInternalCustomBindings( 394 AutomationInternalCustomBindings::AutomationInternalCustomBindings(
395 ScriptContext* context) 395 ScriptContext* context)
396 : ObjectBackedNativeHandler(context), is_active_profile_(true) { 396 : ObjectBackedNativeHandler(context),
397 is_active_profile_(true),
398 tree_change_observer_mask_(
399 api::automation::TREE_CHANGE_OBSERVER_MASK_NOTREECHANGES) {
397 // It's safe to use base::Unretained(this) here because these bindings 400 // It's safe to use base::Unretained(this) here because these bindings
398 // will only be called on a valid AutomationInternalCustomBindings instance 401 // will only be called on a valid AutomationInternalCustomBindings instance
399 // and none of the functions have any side effects. 402 // and none of the functions have any side effects.
400 #define ROUTE_FUNCTION(FN) \ 403 #define ROUTE_FUNCTION(FN) \
401 RouteFunction(#FN, \ 404 RouteFunction(#FN, \
402 base::Bind(&AutomationInternalCustomBindings::FN, \ 405 base::Bind(&AutomationInternalCustomBindings::FN, \
403 base::Unretained(this))) 406 base::Unretained(this)))
404 ROUTE_FUNCTION(IsInteractPermitted); 407 ROUTE_FUNCTION(IsInteractPermitted);
405 ROUTE_FUNCTION(GetSchemaAdditions); 408 ROUTE_FUNCTION(GetSchemaAdditions);
406 ROUTE_FUNCTION(GetRoutingID); 409 ROUTE_FUNCTION(GetRoutingID);
407 ROUTE_FUNCTION(StartCachingAccessibilityTrees); 410 ROUTE_FUNCTION(StartCachingAccessibilityTrees);
408 ROUTE_FUNCTION(DestroyAccessibilityTree); 411 ROUTE_FUNCTION(DestroyAccessibilityTree);
412 ROUTE_FUNCTION(SetTreeChangeObserverMask);
409 ROUTE_FUNCTION(GetChildIDAtIndex); 413 ROUTE_FUNCTION(GetChildIDAtIndex);
410 #undef ROUTE_FUNCTION 414 #undef ROUTE_FUNCTION
411 415
412 // Bindings that take a Tree ID and return a property of the tree. 416 // Bindings that take a Tree ID and return a property of the tree.
413 417
414 RouteTreeIDFunction( 418 RouteTreeIDFunction(
415 "GetRootID", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result, 419 "GetRootID", [](v8::Isolate* isolate, v8::ReturnValue<v8::Value> result,
416 TreeCache* cache) { 420 TreeCache* cache) {
417 result.Set(v8::Integer::New(isolate, cache->tree.root()->id())); 421 result.Set(v8::Integer::New(isolate, cache->tree.root()->id()));
418 }); 422 });
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 auto iter = tree_id_to_tree_cache_map_.find(tree_id); 729 auto iter = tree_id_to_tree_cache_map_.find(tree_id);
726 if (iter == tree_id_to_tree_cache_map_.end()) 730 if (iter == tree_id_to_tree_cache_map_.end())
727 return; 731 return;
728 732
729 TreeCache* cache = iter->second; 733 TreeCache* cache = iter->second;
730 tree_id_to_tree_cache_map_.erase(tree_id); 734 tree_id_to_tree_cache_map_.erase(tree_id);
731 axtree_to_tree_cache_map_.erase(&cache->tree); 735 axtree_to_tree_cache_map_.erase(&cache->tree);
732 delete cache; 736 delete cache;
733 } 737 }
734 738
739 void AutomationInternalCustomBindings::SetTreeChangeObserverMask(
740 const v8::FunctionCallbackInfo<v8::Value>& args) {
741 if (args.Length() != 1 || !args[0]->IsString()) {
742 ThrowInvalidArgumentsException(this);
743 return;
744 }
745
746 std::string mask_str = *v8::String::Utf8Value(args[0]);
747 tree_change_observer_mask_ =
748 api::automation::ParseTreeChangeObserverMask(mask_str);
749 }
750
735 void AutomationInternalCustomBindings::RouteTreeIDFunction( 751 void AutomationInternalCustomBindings::RouteTreeIDFunction(
736 const std::string& name, 752 const std::string& name,
737 TreeIDFunction callback) { 753 TreeIDFunction callback) {
738 scoped_refptr<TreeIDWrapper> wrapper = new TreeIDWrapper(this, callback); 754 scoped_refptr<TreeIDWrapper> wrapper = new TreeIDWrapper(this, callback);
739 RouteFunction(name, base::Bind(&TreeIDWrapper::Run, wrapper)); 755 RouteFunction(name, base::Bind(&TreeIDWrapper::Run, wrapper));
740 } 756 }
741 757
742 void AutomationInternalCustomBindings::RouteNodeIDFunction( 758 void AutomationInternalCustomBindings::RouteNodeIDFunction(
743 const std::string& name, 759 const std::string& name,
744 NodeIDFunction callback) { 760 NodeIDFunction callback) {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 } 918 }
903 919
904 void AutomationInternalCustomBindings::SendTreeChangeEvent( 920 void AutomationInternalCustomBindings::SendTreeChangeEvent(
905 api::automation::TreeChangeType change_type, 921 api::automation::TreeChangeType change_type,
906 ui::AXTree* tree, 922 ui::AXTree* tree,
907 ui::AXNode* node) { 923 ui::AXNode* node) {
908 // Don't send tree change events when it's not the active profile. 924 // Don't send tree change events when it's not the active profile.
909 if (!is_active_profile_) 925 if (!is_active_profile_)
910 return; 926 return;
911 927
928 if (node->data().role != ui::AX_ROLE_EMBEDDED_OBJECT &&
929 node->data().role != ui::AX_ROLE_WEB_VIEW) {
930 switch (tree_change_observer_mask_) {
931 case api::automation::TREE_CHANGE_OBSERVER_MASK_NOTREECHANGES:
932 default:
933 return;
934 case api::automation::TREE_CHANGE_OBSERVER_MASK_LIVEREGIONTREECHANGES:
935 if (!node->data().HasStringAttribute(
936 ui::AX_ATTR_CONTAINER_LIVE_STATUS) &&
937 node->data().role != ui::AX_ROLE_ALERT) {
938 return;
939 }
940 break;
941 case api::automation::TREE_CHANGE_OBSERVER_MASK_ALLTREECHANGES:
942 break;
943 }
944 }
945
912 auto iter = axtree_to_tree_cache_map_.find(tree); 946 auto iter = axtree_to_tree_cache_map_.find(tree);
913 if (iter == axtree_to_tree_cache_map_.end()) 947 if (iter == axtree_to_tree_cache_map_.end())
914 return; 948 return;
915 949
916 int tree_id = iter->second->tree_id; 950 int tree_id = iter->second->tree_id;
917 951
918 v8::Isolate* isolate = GetIsolate(); 952 v8::Isolate* isolate = GetIsolate();
919 v8::HandleScope handle_scope(isolate); 953 v8::HandleScope handle_scope(isolate);
920 v8::Context::Scope context_scope(context()->v8_context()); 954 v8::Context::Scope context_scope(context()->v8_context());
921 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 3U)); 955 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 3U));
922 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); 956 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id));
923 args->Set(1U, v8::Integer::New(GetIsolate(), node->id())); 957 args->Set(1U, v8::Integer::New(GetIsolate(), node->id()));
924 args->Set(2U, CreateV8String(isolate, ToString(change_type))); 958 args->Set(2U, CreateV8String(isolate, ToString(change_type)));
925 context()->DispatchEvent("automationInternal.onTreeChange", args); 959 context()->DispatchEvent("automationInternal.onTreeChange", args);
926 } 960 }
927 961
928 } // namespace extensions 962 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698