| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/event_bindings.h" | 5 #include "chrome/renderer/extensions/event_bindings.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); | 65 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); |
| 66 | 66 |
| 67 if (args[0]->IsString()) { | 67 if (args[0]->IsString()) { |
| 68 ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args); | 68 ExtensionImpl* self = GetFromArguments<ExtensionImpl>(args); |
| 69 const ChromeV8ContextSet& context_set = | 69 const ChromeV8ContextSet& context_set = |
| 70 self->extension_dispatcher()->v8_context_set(); | 70 self->extension_dispatcher()->v8_context_set(); |
| 71 ChromeV8Context* context = context_set.GetCurrent(); | 71 ChromeV8Context* context = context_set.GetCurrent(); |
| 72 CHECK(context); | 72 CHECK(context); |
| 73 std::string event_name(*v8::String::AsciiValue(args[0])); | 73 std::string event_name(*v8::String::AsciiValue(args[0])); |
| 74 | 74 |
| 75 ExtensionDispatcher* extension_dispatcher = self->extension_dispatcher(); | |
| 76 if (!extension_dispatcher->CheckCurrentContextAccessToExtensionAPI( | |
| 77 event_name)) | |
| 78 return v8::Undefined(); | |
| 79 | |
| 80 EventListenerCounts& listener_counts = | 75 EventListenerCounts& listener_counts = |
| 81 g_listener_counts.Get()[context->extension_id()]; | 76 g_listener_counts.Get()[context->extension_id()]; |
| 82 if (++listener_counts[event_name] == 1) { | 77 if (++listener_counts[event_name] == 1) { |
| 83 content::RenderThread::Get()->Send( | 78 content::RenderThread::Get()->Send( |
| 84 new ExtensionHostMsg_AddListener(context->extension_id(), | 79 new ExtensionHostMsg_AddListener(context->extension_id(), |
| 85 event_name)); | 80 event_name, |
| 81 context->context_type())); |
| 86 } | 82 } |
| 87 | 83 |
| 88 // This is called the first time the page has added a listener. Since | 84 // This is called the first time the page has added a listener. Since |
| 89 // the background page is the only lazy page, we know this is the first | 85 // the background page is the only lazy page, we know this is the first |
| 90 // time this listener has been registered. | 86 // time this listener has been registered. |
| 91 if (self->IsLazyBackgroundPage(context->extension_id())) { | 87 if (self->IsLazyBackgroundPage(context->extension_id())) { |
| 92 content::RenderThread::Get()->Send( | 88 content::RenderThread::Get()->Send( |
| 93 new ExtensionHostMsg_AddLazyListener(context->extension_id(), | 89 new ExtensionHostMsg_AddLazyListener(context->extension_id(), |
| 94 event_name)); | 90 event_name, |
| 91 context->context_type())); |
| 95 } | 92 } |
| 96 } | 93 } |
| 97 | 94 |
| 98 return v8::Undefined(); | 95 return v8::Undefined(); |
| 99 } | 96 } |
| 100 | 97 |
| 101 static v8::Handle<v8::Value> DetachEvent(const v8::Arguments& args) { | 98 static v8::Handle<v8::Value> DetachEvent(const v8::Arguments& args) { |
| 102 DCHECK(args.Length() == 2); | 99 DCHECK(args.Length() == 2); |
| 103 // TODO(erikkay) should enforce that event name is a string in the bindings | 100 // TODO(erikkay) should enforce that event name is a string in the bindings |
| 104 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); | 101 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 return (extension && extension->has_lazy_background_page() && | 146 return (extension && extension->has_lazy_background_page() && |
| 150 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 147 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
| 151 } | 148 } |
| 152 }; | 149 }; |
| 153 | 150 |
| 154 } // namespace | 151 } // namespace |
| 155 | 152 |
| 156 ChromeV8Extension* EventBindings::Get(ExtensionDispatcher* dispatcher) { | 153 ChromeV8Extension* EventBindings::Get(ExtensionDispatcher* dispatcher) { |
| 157 return new ExtensionImpl(dispatcher); | 154 return new ExtensionImpl(dispatcher); |
| 158 } | 155 } |
| OLD | NEW |