Index: chrome/renderer/extensions/event_bindings.cc |
diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc |
index 12435a53efce78465995cf0c53547cbffb5598b5..bbf16f5e897ecf32aba83de052259bcd11eacac8 100644 |
--- a/chrome/renderer/extensions/event_bindings.cc |
+++ b/chrome/renderer/extensions/event_bindings.cc |
@@ -72,8 +72,9 @@ base::LazyInstance<EventFilter> g_event_filter = LAZY_INSTANCE_INITIALIZER; |
// TODO(koz): Merge this into EventBindings. |
class ExtensionImpl : public ChromeV8Extension { |
public: |
- explicit ExtensionImpl(Dispatcher* dispatcher) |
- : ChromeV8Extension(dispatcher) { |
+ explicit ExtensionImpl(Dispatcher* dispatcher, |
+ v8::Handle<v8::Context> v8_context) |
+ : ChromeV8Extension(dispatcher, v8_context) { |
RouteStaticFunction("AttachEvent", &AttachEvent); |
RouteStaticFunction("DetachEvent", &DetachEvent); |
RouteStaticFunction("AttachFilteredEvent", &AttachFilteredEvent); |
@@ -94,10 +95,10 @@ class ExtensionImpl : public ChromeV8Extension { |
std::string event_name = *v8::String::AsciiValue(args[0]->ToString()); |
Dispatcher* dispatcher = self->dispatcher(); |
const ChromeV8ContextSet& context_set = dispatcher->v8_context_set(); |
- ChromeV8Context* context = context_set.GetCurrent(); |
+ ChromeV8Context* context = context_set.GetByV8Context(self->v8_context()); |
CHECK(context); |
- if (!dispatcher->CheckCurrentContextAccessToExtensionAPI(event_name)) |
+ if (!dispatcher->CheckContextAccessToExtensionAPI(event_name, context)) |
return v8::Undefined(); |
std::string extension_id = context->GetExtensionID(); |
@@ -111,7 +112,7 @@ class ExtensionImpl : public ChromeV8Extension { |
// This is called the first time the page has added a listener. Since |
// the background page is the only lazy page, we know this is the first |
// time this listener has been registered. |
- if (IsLazyBackgroundPage(context->extension())) { |
+ if (IsLazyBackgroundPage(self->GetRenderView(), context->extension())) { |
content::RenderThread::Get()->Send( |
new ExtensionHostMsg_AddLazyListener(extension_id, event_name)); |
} |
@@ -131,7 +132,7 @@ class ExtensionImpl : public ChromeV8Extension { |
ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args); |
Dispatcher* dispatcher = self->dispatcher(); |
const ChromeV8ContextSet& context_set = dispatcher->v8_context_set(); |
- ChromeV8Context* context = context_set.GetCurrent(); |
+ ChromeV8Context* context = context_set.GetByV8Context(self->v8_context()); |
if (!context) |
return v8::Undefined(); |
@@ -148,7 +149,8 @@ class ExtensionImpl : public ChromeV8Extension { |
// removed. If the context is the background page, and it removes the |
// last listener manually, then we assume that it is no longer interested |
// in being awakened for this event. |
- if (is_manual && IsLazyBackgroundPage(context->extension())) { |
+ if (is_manual && IsLazyBackgroundPage(self->GetRenderView(), |
+ context->extension())) { |
content::RenderThread::Get()->Send( |
new ExtensionHostMsg_RemoveLazyListener(extension_id, event_name)); |
} |
@@ -169,14 +171,14 @@ class ExtensionImpl : public ChromeV8Extension { |
ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args); |
Dispatcher* dispatcher = self->dispatcher(); |
const ChromeV8ContextSet& context_set = dispatcher->v8_context_set(); |
- ChromeV8Context* context = context_set.GetCurrent(); |
+ ChromeV8Context* context = context_set.GetByV8Context(self->v8_context()); |
DCHECK(context); |
if (!context) |
return v8::Integer::New(-1); |
std::string event_name = *v8::String::AsciiValue(args[0]); |
// This method throws an exception if it returns false. |
- if (!dispatcher->CheckCurrentContextAccessToExtensionAPI(event_name)) |
+ if (!dispatcher->CheckContextAccessToExtensionAPI(event_name, context)) |
return v8::Undefined(); |
std::string extension_id = context->GetExtensionID(); |
@@ -188,8 +190,8 @@ class ExtensionImpl : public ChromeV8Extension { |
content::V8ValueConverter::create()); |
base::DictionaryValue* filter_dict = NULL; |
- base::Value* filter_value = converter->FromV8Value(args[1]->ToObject(), |
- v8::Context::GetCurrent()); |
+ base::Value* filter_value = |
+ converter->FromV8Value(args[1]->ToObject(), context->v8_context()); |
if (!filter_value) |
return v8::Integer::New(-1); |
if (!filter_value->GetAsDictionary(&filter_dict)) { |
@@ -204,7 +206,8 @@ class ExtensionImpl : public ChromeV8Extension { |
// Only send IPCs the first time a filter gets added. |
if (AddFilter(event_name, extension_id, filter.get())) { |
- bool lazy = IsLazyBackgroundPage(context->extension()); |
+ bool lazy = IsLazyBackgroundPage(self->GetRenderView(), |
+ context->extension()); |
content::RenderThread::Get()->Send( |
new ExtensionHostMsg_AddFilteredListener(extension_id, event_name, |
*filter, lazy)); |
@@ -253,7 +256,7 @@ class ExtensionImpl : public ChromeV8Extension { |
ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args); |
Dispatcher* dispatcher = self->dispatcher(); |
const ChromeV8ContextSet& context_set = dispatcher->v8_context_set(); |
- ChromeV8Context* context = context_set.GetCurrent(); |
+ ChromeV8Context* context = context_set.GetByV8Context(self->v8_context()); |
if (!context) |
return v8::Undefined(); |
@@ -270,7 +273,8 @@ class ExtensionImpl : public ChromeV8Extension { |
// Only send IPCs the last time a filter gets removed. |
if (RemoveFilter(event_name, extension_id, event_matcher->value())) { |
- bool lazy = is_manual && IsLazyBackgroundPage(context->extension()); |
+ bool lazy = is_manual && IsLazyBackgroundPage(self->GetRenderView(), |
+ context->extension()); |
content::RenderThread::Get()->Send( |
new ExtensionHostMsg_RemoveFilteredListener(extension_id, event_name, |
*event_matcher->value(), |
@@ -311,11 +315,10 @@ class ExtensionImpl : public ChromeV8Extension { |
} |
private: |
- static bool IsLazyBackgroundPage(const Extension* extension) { |
- content::RenderView* render_view = GetCurrentRenderView(); |
+ static bool IsLazyBackgroundPage(content::RenderView* render_view, |
+ const Extension* extension) { |
if (!render_view) |
return false; |
- |
ExtensionHelper* helper = ExtensionHelper::Get(render_view); |
return (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && |
helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
@@ -331,8 +334,9 @@ class ExtensionImpl : public ChromeV8Extension { |
} // namespace |
// static |
-ChromeV8Extension* EventBindings::Get(Dispatcher* dispatcher) { |
- return new ExtensionImpl(dispatcher); |
+ChromeV8Extension* EventBindings::Create(Dispatcher* dispatcher, |
+ v8::Handle<v8::Context> context) { |
+ return new ExtensionImpl(dispatcher, context); |
} |
} // namespace extensions |