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

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

Issue 2782753002: Ensure only one instance of AutomationInternalCustomBindings for background page extensions (Closed)
Patch Set: Rebase. Created 3 years, 8 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
« no previous file with comments | « chrome/renderer/extensions/automation_internal_custom_bindings.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/common/extensions/api/automation_api_constants.h" 16 #include "chrome/common/extensions/api/automation_api_constants.h"
17 #include "chrome/common/extensions/chrome_extension_messages.h" 17 #include "chrome/common/extensions/chrome_extension_messages.h"
18 #include "chrome/common/extensions/manifest_handlers/automation.h" 18 #include "chrome/common/extensions/manifest_handlers/automation.h"
19 #include "content/public/renderer/render_frame.h" 19 #include "content/public/renderer/render_frame.h"
20 #include "content/public/renderer/render_thread.h" 20 #include "content/public/renderer/render_thread.h"
21 #include "content/public/renderer/render_view.h" 21 #include "content/public/renderer/render_view.h"
22 #include "extensions/common/extension.h" 22 #include "extensions/common/extension.h"
23 #include "extensions/common/manifest.h" 23 #include "extensions/common/manifest.h"
24 #include "extensions/common/manifest_handlers/background_info.h"
24 #include "extensions/renderer/extension_bindings_system.h" 25 #include "extensions/renderer/extension_bindings_system.h"
25 #include "extensions/renderer/script_context.h" 26 #include "extensions/renderer/script_context.h"
26 #include "ipc/message_filter.h" 27 #include "ipc/message_filter.h"
27 #include "ui/accessibility/ax_enums.h" 28 #include "ui/accessibility/ax_enums.h"
28 #include "ui/accessibility/ax_node.h" 29 #include "ui/accessibility/ax_node.h"
29 #include "ui/gfx/geometry/rect_conversions.h" 30 #include "ui/gfx/geometry/rect_conversions.h"
30 31
31 namespace extensions { 32 namespace extensions {
32 33
33 namespace { 34 namespace {
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 418
418 DISALLOW_COPY_AND_ASSIGN(AutomationMessageFilter); 419 DISALLOW_COPY_AND_ASSIGN(AutomationMessageFilter);
419 }; 420 };
420 421
421 AutomationInternalCustomBindings::AutomationInternalCustomBindings( 422 AutomationInternalCustomBindings::AutomationInternalCustomBindings(
422 ScriptContext* context, 423 ScriptContext* context,
423 ExtensionBindingsSystem* bindings_system) 424 ExtensionBindingsSystem* bindings_system)
424 : ObjectBackedNativeHandler(context), 425 : ObjectBackedNativeHandler(context),
425 is_active_profile_(true), 426 is_active_profile_(true),
426 tree_change_observer_overall_filter_(0), 427 tree_change_observer_overall_filter_(0),
427 bindings_system_(bindings_system) { 428 bindings_system_(bindings_system),
428 // It's safe to use base::Unretained(this) here because these bindings 429 should_ignore_context_(false) {
429 // will only be called on a valid AutomationInternalCustomBindings instance 430 // We will ignore this instance if the extension has a background page and
430 // and none of the functions have any side effects. 431 // this context is not that background page. In all other cases, we will have
432 // multiple instances floating around in the same process.
433 if (context && context->extension()) {
434 const GURL background_page_url =
435 extensions::BackgroundInfo::GetBackgroundURL(context->extension());
436 should_ignore_context_ = background_page_url != "" &&
437 background_page_url != context->url();
438 }
439
440 // It's safe to use base::Unretained(this) here because these bindings
441 // will only be called on a valid AutomationInternalCustomBindings instance
442 // and none of the functions have any side effects.
431 #define ROUTE_FUNCTION(FN) \ 443 #define ROUTE_FUNCTION(FN) \
432 RouteFunction(#FN, "automation", \ 444 RouteFunction(#FN, "automation", \
433 base::Bind(&AutomationInternalCustomBindings::FN, \ 445 base::Bind(&AutomationInternalCustomBindings::FN, \
434 base::Unretained(this))) 446 base::Unretained(this)))
435 ROUTE_FUNCTION(IsInteractPermitted); 447 ROUTE_FUNCTION(IsInteractPermitted);
436 ROUTE_FUNCTION(GetSchemaAdditions); 448 ROUTE_FUNCTION(GetSchemaAdditions);
437 ROUTE_FUNCTION(GetRoutingID); 449 ROUTE_FUNCTION(GetRoutingID);
438 ROUTE_FUNCTION(StartCachingAccessibilityTrees); 450 ROUTE_FUNCTION(StartCachingAccessibilityTrees);
439 ROUTE_FUNCTION(DestroyAccessibilityTree); 451 ROUTE_FUNCTION(DestroyAccessibilityTree);
440 ROUTE_FUNCTION(AddTreeChangeObserver); 452 ROUTE_FUNCTION(AddTreeChangeObserver);
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 } 772 }
761 773
762 void AutomationInternalCustomBindings::GetRoutingID( 774 void AutomationInternalCustomBindings::GetRoutingID(
763 const v8::FunctionCallbackInfo<v8::Value>& args) { 775 const v8::FunctionCallbackInfo<v8::Value>& args) {
764 int routing_id = context()->GetRenderFrame()->GetRenderView()->GetRoutingID(); 776 int routing_id = context()->GetRenderFrame()->GetRenderView()->GetRoutingID();
765 args.GetReturnValue().Set(v8::Integer::New(GetIsolate(), routing_id)); 777 args.GetReturnValue().Set(v8::Integer::New(GetIsolate(), routing_id));
766 } 778 }
767 779
768 void AutomationInternalCustomBindings::StartCachingAccessibilityTrees( 780 void AutomationInternalCustomBindings::StartCachingAccessibilityTrees(
769 const v8::FunctionCallbackInfo<v8::Value>& args) { 781 const v8::FunctionCallbackInfo<v8::Value>& args) {
782 if (should_ignore_context_)
783 return;
784
770 if (!message_filter_) 785 if (!message_filter_)
771 message_filter_ = new AutomationMessageFilter(this); 786 message_filter_ = new AutomationMessageFilter(this);
772 } 787 }
773 788
774 void AutomationInternalCustomBindings::GetSchemaAdditions( 789 void AutomationInternalCustomBindings::GetSchemaAdditions(
775 const v8::FunctionCallbackInfo<v8::Value>& args) { 790 const v8::FunctionCallbackInfo<v8::Value>& args) {
776 v8::Local<v8::Object> additions = v8::Object::New(GetIsolate()); 791 v8::Local<v8::Object> additions = v8::Object::New(GetIsolate());
777 792
778 v8::Local<v8::Object> name_from_type(v8::Object::New(GetIsolate())); 793 v8::Local<v8::Object> name_from_type(v8::Object::New(GetIsolate()));
779 for (int i = ui::AX_NAME_FROM_NONE; i <= ui::AX_NAME_FROM_LAST; ++i) { 794 for (int i = ui::AX_NAME_FROM_NONE; i <= ui::AX_NAME_FROM_LAST; ++i) {
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 for (auto id : ids) 1403 for (auto id : ids)
1389 nodes->AppendInteger(id); 1404 nodes->AppendInteger(id);
1390 args.Append(std::move(nodes)); 1405 args.Append(std::move(nodes));
1391 } 1406 }
1392 1407
1393 bindings_system_->DispatchEventInContext("automationInternal.onNodesRemoved", 1408 bindings_system_->DispatchEventInContext("automationInternal.onNodesRemoved",
1394 &args, nullptr, context()); 1409 &args, nullptr, context());
1395 } 1410 }
1396 1411
1397 } // namespace extensions 1412 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/automation_internal_custom_bindings.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698