diff options
Diffstat (limited to 'chrome/renderer/extensions/event_bindings.cc')
-rw-r--r-- | chrome/renderer/extensions/event_bindings.cc | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc index bbf16f5..12435a5 100644 --- a/chrome/renderer/extensions/event_bindings.cc +++ b/chrome/renderer/extensions/event_bindings.cc @@ -72,9 +72,8 @@ base::LazyInstance<EventFilter> g_event_filter = LAZY_INSTANCE_INITIALIZER; // TODO(koz): Merge this into EventBindings. class ExtensionImpl : public ChromeV8Extension { public: - explicit ExtensionImpl(Dispatcher* dispatcher, - v8::Handle<v8::Context> v8_context) - : ChromeV8Extension(dispatcher, v8_context) { + explicit ExtensionImpl(Dispatcher* dispatcher) + : ChromeV8Extension(dispatcher) { RouteStaticFunction("AttachEvent", &AttachEvent); RouteStaticFunction("DetachEvent", &DetachEvent); RouteStaticFunction("AttachFilteredEvent", &AttachFilteredEvent); @@ -95,10 +94,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.GetByV8Context(self->v8_context()); + ChromeV8Context* context = context_set.GetCurrent(); CHECK(context); - if (!dispatcher->CheckContextAccessToExtensionAPI(event_name, context)) + if (!dispatcher->CheckCurrentContextAccessToExtensionAPI(event_name)) return v8::Undefined(); std::string extension_id = context->GetExtensionID(); @@ -112,7 +111,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(self->GetRenderView(), context->extension())) { + if (IsLazyBackgroundPage(context->extension())) { content::RenderThread::Get()->Send( new ExtensionHostMsg_AddLazyListener(extension_id, event_name)); } @@ -132,7 +131,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.GetByV8Context(self->v8_context()); + ChromeV8Context* context = context_set.GetCurrent(); if (!context) return v8::Undefined(); @@ -149,8 +148,7 @@ 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(self->GetRenderView(), - context->extension())) { + if (is_manual && IsLazyBackgroundPage(context->extension())) { content::RenderThread::Get()->Send( new ExtensionHostMsg_RemoveLazyListener(extension_id, event_name)); } @@ -171,14 +169,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.GetByV8Context(self->v8_context()); + ChromeV8Context* context = context_set.GetCurrent(); 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->CheckContextAccessToExtensionAPI(event_name, context)) + if (!dispatcher->CheckCurrentContextAccessToExtensionAPI(event_name)) return v8::Undefined(); std::string extension_id = context->GetExtensionID(); @@ -190,8 +188,8 @@ class ExtensionImpl : public ChromeV8Extension { content::V8ValueConverter::create()); base::DictionaryValue* filter_dict = NULL; - base::Value* filter_value = - converter->FromV8Value(args[1]->ToObject(), context->v8_context()); + base::Value* filter_value = converter->FromV8Value(args[1]->ToObject(), + v8::Context::GetCurrent()); if (!filter_value) return v8::Integer::New(-1); if (!filter_value->GetAsDictionary(&filter_dict)) { @@ -206,8 +204,7 @@ 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(self->GetRenderView(), - context->extension()); + bool lazy = IsLazyBackgroundPage(context->extension()); content::RenderThread::Get()->Send( new ExtensionHostMsg_AddFilteredListener(extension_id, event_name, *filter, lazy)); @@ -256,7 +253,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.GetByV8Context(self->v8_context()); + ChromeV8Context* context = context_set.GetCurrent(); if (!context) return v8::Undefined(); @@ -273,8 +270,7 @@ 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(self->GetRenderView(), - context->extension()); + bool lazy = is_manual && IsLazyBackgroundPage(context->extension()); content::RenderThread::Get()->Send( new ExtensionHostMsg_RemoveFilteredListener(extension_id, event_name, *event_matcher->value(), @@ -315,10 +311,11 @@ class ExtensionImpl : public ChromeV8Extension { } private: - static bool IsLazyBackgroundPage(content::RenderView* render_view, - const Extension* extension) { + static bool IsLazyBackgroundPage(const Extension* extension) { + content::RenderView* render_view = GetCurrentRenderView(); 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); @@ -334,9 +331,8 @@ class ExtensionImpl : public ChromeV8Extension { } // namespace // static -ChromeV8Extension* EventBindings::Create(Dispatcher* dispatcher, - v8::Handle<v8::Context> context) { - return new ExtensionImpl(dispatcher, context); +ChromeV8Extension* EventBindings::Get(Dispatcher* dispatcher) { + return new ExtensionImpl(dispatcher); } } // namespace extensions |