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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/extensions/automation_internal_custom_bindings.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/extensions/automation_internal_custom_bindings.cc
diff --git a/chrome/renderer/extensions/automation_internal_custom_bindings.cc b/chrome/renderer/extensions/automation_internal_custom_bindings.cc
index f7d5fe9039df30cd7f033ae030f8adb6458610dd..ac63b587200da51c7eb7187475f83a3ad1d79e24 100644
--- a/chrome/renderer/extensions/automation_internal_custom_bindings.cc
+++ b/chrome/renderer/extensions/automation_internal_custom_bindings.cc
@@ -21,6 +21,7 @@
#include "content/public/renderer/render_view.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest.h"
+#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/renderer/extension_bindings_system.h"
#include "extensions/renderer/script_context.h"
#include "ipc/message_filter.h"
@@ -424,10 +425,21 @@ AutomationInternalCustomBindings::AutomationInternalCustomBindings(
: ObjectBackedNativeHandler(context),
is_active_profile_(true),
tree_change_observer_overall_filter_(0),
- bindings_system_(bindings_system) {
-// It's safe to use base::Unretained(this) here because these bindings
-// will only be called on a valid AutomationInternalCustomBindings instance
-// and none of the functions have any side effects.
+ bindings_system_(bindings_system),
+ should_ignore_context_(false) {
+ // We will ignore this instance if the extension has a background page and
+ // this context is not that background page. In all other cases, we will have
+ // multiple instances floating around in the same process.
+ if (context && context->extension()) {
+ const GURL background_page_url =
+ extensions::BackgroundInfo::GetBackgroundURL(context->extension());
+ should_ignore_context_ = background_page_url != "" &&
+ background_page_url != context->url();
+ }
+
+ // It's safe to use base::Unretained(this) here because these bindings
+ // will only be called on a valid AutomationInternalCustomBindings instance
+ // and none of the functions have any side effects.
#define ROUTE_FUNCTION(FN) \
RouteFunction(#FN, "automation", \
base::Bind(&AutomationInternalCustomBindings::FN, \
@@ -767,6 +779,9 @@ void AutomationInternalCustomBindings::GetRoutingID(
void AutomationInternalCustomBindings::StartCachingAccessibilityTrees(
const v8::FunctionCallbackInfo<v8::Value>& args) {
+ if (should_ignore_context_)
+ return;
+
if (!message_filter_)
message_filter_ = new AutomationMessageFilter(this);
}
« 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