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

Unified Diff: chrome/renderer/extensions/event_bindings.cc

Issue 9386001: Implement a module system for the extension bindings JS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 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
Index: chrome/renderer/extensions/event_bindings.cc
diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc
index 9bab21a945d08f7f2261a6f47c3a2499b18d8a9a..f187f27c5c88cdb9489082dc9d9ddc7130d64fdd 100644
--- a/chrome/renderer/extensions/event_bindings.cc
+++ b/chrome/renderer/extensions/event_bindings.cc
@@ -39,25 +39,26 @@ using content::RenderThread;
namespace {
+// A map of event names to the number of contexts listening to that event.
+// We notify the browser about event listeners when we transition between 0
+// and 1.
+typedef std::map<std::string, int> EventListenerCounts;
+
+// A map of extension IDs to listener counts for that extension.
+base::LazyInstance<std::map<std::string, EventListenerCounts> >
+ g_listener_counts = LAZY_INSTANCE_INITIALIZER;
+
+// TODO(koz): Merge this into EventBindings.
class ExtensionImpl : public ChromeV8Extension {
public:
+
explicit ExtensionImpl(ExtensionDispatcher* dispatcher)
- : ChromeV8Extension("extensions/event.js",
- IDR_EVENT_BINDINGS_JS,
- dispatcher) {
+ : ChromeV8Extension(dispatcher) {
+ RouteStaticFunction("AttachEvent", &AttachEvent);
+ RouteStaticFunction("DetachEvent", &DetachEvent);
}
~ExtensionImpl() {}
- virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
- v8::Handle<v8::String> name) {
- if (name->Equals(v8::String::New("AttachEvent"))) {
- return v8::FunctionTemplate::New(AttachEvent, v8::External::New(this));
- } else if (name->Equals(v8::String::New("DetachEvent"))) {
- return v8::FunctionTemplate::New(DetachEvent, v8::External::New(this));
- }
- return ChromeV8Extension::GetNativeFunction(name);
- }
-
// Attach an event name to an object.
static v8::Handle<v8::Value> AttachEvent(const v8::Arguments& args) {
DCHECK(args.Length() == 1);
@@ -76,7 +77,7 @@ class ExtensionImpl : public ChromeV8Extension {
return v8::Undefined();
EventListenerCounts& listener_counts =
- self->listener_counts_[context->extension_id()];
+ g_listener_counts.Get()[context->extension_id()];
if (++listener_counts[event_name] == 1) {
content::RenderThread::Get()->Send(
new ExtensionHostMsg_AddListener(context->extension_id(),
@@ -110,7 +111,7 @@ class ExtensionImpl : public ChromeV8Extension {
return v8::Undefined();
EventListenerCounts& listener_counts =
- self->listener_counts_[context->extension_id()];
+ g_listener_counts.Get()[context->extension_id()];
std::string event_name(*v8::String::AsciiValue(args[0]));
bool is_manual = args[1]->BooleanValue();
@@ -135,10 +136,6 @@ class ExtensionImpl : public ChromeV8Extension {
}
private:
- // A map of event names to the number of contexts listening to that event.
- // We notify the browser about event listeners when we transition between 0
- // and 1.
- typedef std::map<std::string, int> EventListenerCounts;
bool IsLazyBackgroundPage(const std::string& extension_id) {
content::RenderView* render_view = GetCurrentRenderView();
@@ -151,14 +148,10 @@ class ExtensionImpl : public ChromeV8Extension {
return (extension && !extension->background_page_persists() &&
helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
}
-
- // A map of extension IDs to listener counts for that extension.
- std::map<std::string, EventListenerCounts> listener_counts_;
};
} // namespace
-v8::Extension* EventBindings::Get(ExtensionDispatcher* dispatcher) {
- static v8::Extension* extension = new ExtensionImpl(dispatcher);
- return extension;
+ChromeV8Extension* EventBindings::Get(ExtensionDispatcher* dispatcher) {
+ return new ExtensionImpl(dispatcher);
}
« no previous file with comments | « chrome/renderer/extensions/event_bindings.h ('k') | chrome/renderer/extensions/experimental.socket_custom_bindings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698