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

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

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

Powered by Google App Engine
This is Rietveld 408576698