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 std::string extension_id = context->GetExtensionID(); | 75 std::string extension_id = context->GetExtensionID(); |
81 EventListenerCounts& listener_counts = | 76 EventListenerCounts& listener_counts = |
82 g_listener_counts.Get()[extension_id]; | 77 g_listener_counts.Get()[extension_id]; |
83 if (++listener_counts[event_name] == 1) { | 78 if (++listener_counts[event_name] == 1) { |
84 content::RenderThread::Get()->Send( | 79 content::RenderThread::Get()->Send( |
85 new ExtensionHostMsg_AddListener(extension_id, event_name)); | 80 new ExtensionHostMsg_AddListener(extension_id, |
| 81 event_name, |
| 82 context->context_type())); |
86 } | 83 } |
87 | 84 |
88 // This is called the first time the page has added a listener. Since | 85 // 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 | 86 // the background page is the only lazy page, we know this is the first |
90 // time this listener has been registered. | 87 // time this listener has been registered. |
91 if (self->IsLazyBackgroundPage(context->extension())) { | 88 if (self->IsLazyBackgroundPage(context->extension())) { |
92 content::RenderThread::Get()->Send( | 89 content::RenderThread::Get()->Send( |
93 new ExtensionHostMsg_AddLazyListener(extension_id, event_name)); | 90 new ExtensionHostMsg_AddLazyListener(extension_id, |
| 91 event_name, |
| 92 context->context_type())); |
94 } | 93 } |
95 } | 94 } |
96 | 95 |
97 return v8::Undefined(); | 96 return v8::Undefined(); |
98 } | 97 } |
99 | 98 |
100 static v8::Handle<v8::Value> DetachEvent(const v8::Arguments& args) { | 99 static v8::Handle<v8::Value> DetachEvent(const v8::Arguments& args) { |
101 DCHECK(args.Length() == 2); | 100 DCHECK(args.Length() == 2); |
102 // TODO(erikkay) should enforce that event name is a string in the bindings | 101 // TODO(erikkay) should enforce that event name is a string in the bindings |
103 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); | 102 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 return (extension && extension->has_lazy_background_page() && | 144 return (extension && extension->has_lazy_background_page() && |
146 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 145 helper->view_type() == chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
147 } | 146 } |
148 }; | 147 }; |
149 | 148 |
150 } // namespace | 149 } // namespace |
151 | 150 |
152 ChromeV8Extension* EventBindings::Get(ExtensionDispatcher* dispatcher) { | 151 ChromeV8Extension* EventBindings::Get(ExtensionDispatcher* dispatcher) { |
153 return new ExtensionImpl(dispatcher); | 152 return new ExtensionImpl(dispatcher); |
154 } | 153 } |
OLD | NEW |