| OLD | NEW |
| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 | 94 |
| 95 AutomationInternalCustomBindings* owner_; | 95 AutomationInternalCustomBindings* owner_; |
| 96 bool removed_; | 96 bool removed_; |
| 97 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 97 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 98 | 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(AutomationMessageFilter); | 99 DISALLOW_COPY_AND_ASSIGN(AutomationMessageFilter); |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 AutomationInternalCustomBindings::AutomationInternalCustomBindings( | 102 AutomationInternalCustomBindings::AutomationInternalCustomBindings( |
| 103 ScriptContext* context) : ObjectBackedNativeHandler(context) { | 103 ScriptContext* context) |
| 104 : ObjectBackedNativeHandler(context), |
| 105 is_active_profile_(true) { |
| 104 // It's safe to use base::Unretained(this) here because these bindings | 106 // It's safe to use base::Unretained(this) here because these bindings |
| 105 // will only be called on a valid AutomationInternalCustomBindings instance | 107 // will only be called on a valid AutomationInternalCustomBindings instance |
| 106 // and none of the functions have any side effects. | 108 // and none of the functions have any side effects. |
| 107 #define ROUTE_FUNCTION(FN) \ | 109 #define ROUTE_FUNCTION(FN) \ |
| 108 RouteFunction(#FN, \ | 110 RouteFunction(#FN, \ |
| 109 base::Bind(&AutomationInternalCustomBindings::FN, \ | 111 base::Bind(&AutomationInternalCustomBindings::FN, \ |
| 110 base::Unretained(this))) | 112 base::Unretained(this))) |
| 111 | 113 |
| 112 ROUTE_FUNCTION(IsInteractPermitted); | 114 ROUTE_FUNCTION(IsInteractPermitted); |
| 113 ROUTE_FUNCTION(GetSchemaAdditions); | 115 ROUTE_FUNCTION(GetSchemaAdditions); |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 const std::string& str) { | 513 const std::string& str) { |
| 512 return v8::String::NewFromUtf8( | 514 return v8::String::NewFromUtf8( |
| 513 GetIsolate(), str.c_str(), v8::String::kNormalString, str.length()); | 515 GetIsolate(), str.c_str(), v8::String::kNormalString, str.length()); |
| 514 } | 516 } |
| 515 | 517 |
| 516 // | 518 // |
| 517 // Handle accessibility events from the browser process. | 519 // Handle accessibility events from the browser process. |
| 518 // | 520 // |
| 519 | 521 |
| 520 void AutomationInternalCustomBindings::OnAccessibilityEvent( | 522 void AutomationInternalCustomBindings::OnAccessibilityEvent( |
| 521 const ExtensionMsg_AccessibilityEventParams& params) { | 523 const ExtensionMsg_AccessibilityEventParams& params, |
| 524 bool is_active_profile) { |
| 525 is_active_profile_ = is_active_profile; |
| 522 int tree_id = params.tree_id; | 526 int tree_id = params.tree_id; |
| 523 TreeCache* cache; | 527 TreeCache* cache; |
| 524 auto iter = tree_id_to_tree_cache_map_.find(tree_id); | 528 auto iter = tree_id_to_tree_cache_map_.find(tree_id); |
| 525 if (iter == tree_id_to_tree_cache_map_.end()) { | 529 if (iter == tree_id_to_tree_cache_map_.end()) { |
| 526 cache = new TreeCache(); | 530 cache = new TreeCache(); |
| 527 cache->tab_id = -1; | 531 cache->tab_id = -1; |
| 528 cache->tree_id = params.tree_id; | 532 cache->tree_id = params.tree_id; |
| 529 cache->tree.SetDelegate(this); | 533 cache->tree.SetDelegate(this); |
| 530 tree_id_to_tree_cache_map_.insert(std::make_pair(tree_id, cache)); | 534 tree_id_to_tree_cache_map_.insert(std::make_pair(tree_id, cache)); |
| 531 axtree_to_tree_cache_map_.insert(std::make_pair(&cache->tree, cache)); | 535 axtree_to_tree_cache_map_.insert(std::make_pair(&cache->tree, cache)); |
| 532 } else { | 536 } else { |
| 533 cache = iter->second; | 537 cache = iter->second; |
| 534 } | 538 } |
| 535 | 539 |
| 540 // Update the internal state whether it's the active profile or not. |
| 536 cache->location_offset = params.location_offset; | 541 cache->location_offset = params.location_offset; |
| 537 if (!cache->tree.Unserialize(params.update)) { | 542 if (!cache->tree.Unserialize(params.update)) { |
| 538 LOG(ERROR) << cache->tree.error(); | 543 LOG(ERROR) << cache->tree.error(); |
| 539 return; | 544 return; |
| 540 } | 545 } |
| 541 | 546 |
| 547 // Don't send the event if it's not the active profile. |
| 548 if (!is_active_profile) |
| 549 return; |
| 550 |
| 542 v8::HandleScope handle_scope(GetIsolate()); | 551 v8::HandleScope handle_scope(GetIsolate()); |
| 543 v8::Context::Scope context_scope(context()->v8_context()); | 552 v8::Context::Scope context_scope(context()->v8_context()); |
| 544 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 1U)); | 553 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 1U)); |
| 545 v8::Local<v8::Object> event_params(v8::Object::New(GetIsolate())); | 554 v8::Local<v8::Object> event_params(v8::Object::New(GetIsolate())); |
| 546 event_params->Set(CreateV8String("treeID"), | 555 event_params->Set(CreateV8String("treeID"), |
| 547 v8::Integer::New(GetIsolate(), params.tree_id)); | 556 v8::Integer::New(GetIsolate(), params.tree_id)); |
| 548 event_params->Set(CreateV8String("targetID"), | 557 event_params->Set(CreateV8String("targetID"), |
| 549 v8::Integer::New(GetIsolate(), params.id)); | 558 v8::Integer::New(GetIsolate(), params.id)); |
| 550 event_params->Set(CreateV8String("eventType"), | 559 event_params->Set(CreateV8String("eventType"), |
| 551 CreateV8String(ToString(params.event_type))); | 560 CreateV8String(ToString(params.event_type))); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 tree, node); | 618 tree, node); |
| 610 break; | 619 break; |
| 611 } | 620 } |
| 612 } | 621 } |
| 613 } | 622 } |
| 614 | 623 |
| 615 void AutomationInternalCustomBindings::SendTreeChangeEvent( | 624 void AutomationInternalCustomBindings::SendTreeChangeEvent( |
| 616 api::automation::TreeChangeType change_type, | 625 api::automation::TreeChangeType change_type, |
| 617 ui::AXTree* tree, | 626 ui::AXTree* tree, |
| 618 ui::AXNode* node) { | 627 ui::AXNode* node) { |
| 628 // Don't send tree change events when it's not the active profile. |
| 629 if (!is_active_profile_) |
| 630 return; |
| 631 |
| 619 auto iter = axtree_to_tree_cache_map_.find(tree); | 632 auto iter = axtree_to_tree_cache_map_.find(tree); |
| 620 if (iter == axtree_to_tree_cache_map_.end()) | 633 if (iter == axtree_to_tree_cache_map_.end()) |
| 621 return; | 634 return; |
| 622 | 635 |
| 623 int tree_id = iter->second->tree_id; | 636 int tree_id = iter->second->tree_id; |
| 624 | 637 |
| 625 v8::HandleScope handle_scope(GetIsolate()); | 638 v8::HandleScope handle_scope(GetIsolate()); |
| 626 v8::Context::Scope context_scope(context()->v8_context()); | 639 v8::Context::Scope context_scope(context()->v8_context()); |
| 627 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 3U)); | 640 v8::Local<v8::Array> args(v8::Array::New(GetIsolate(), 3U)); |
| 628 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); | 641 args->Set(0U, v8::Integer::New(GetIsolate(), tree_id)); |
| 629 args->Set(1U, v8::Integer::New(GetIsolate(), node->id())); | 642 args->Set(1U, v8::Integer::New(GetIsolate(), node->id())); |
| 630 args->Set(2U, CreateV8String(ToString(change_type))); | 643 args->Set(2U, CreateV8String(ToString(change_type))); |
| 631 context()->DispatchEvent("automationInternal.onTreeChange", args); | 644 context()->DispatchEvent("automationInternal.onTreeChange", args); |
| 632 } | 645 } |
| 633 | 646 |
| 634 } // namespace extensions | 647 } // namespace extensions |
| OLD | NEW |