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

Side by Side Diff: extensions/renderer/event_bindings.cc

Issue 411733002: WIP: diff which plumbs through the event URL. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « extensions/common/features/simple_feature.cc ('k') | extensions/renderer/resources/binding.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/renderer/event_bindings.h" 5 #include "extensions/renderer/event_bindings.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 CHECK(args[0]->IsString()); 143 CHECK(args[0]->IsString());
144 144
145 std::string event_name = *v8::String::Utf8Value(args[0]->ToString()); 145 std::string event_name = *v8::String::Utf8Value(args[0]->ToString());
146 146
147 if (!dispatcher_->CheckContextAccessToExtensionAPI(event_name, context())) 147 if (!dispatcher_->CheckContextAccessToExtensionAPI(event_name, context()))
148 return; 148 return;
149 149
150 std::string extension_id = context()->GetExtensionID(); 150 std::string extension_id = context()->GetExtensionID();
151 EventListenerCounts& listener_counts = g_listener_counts.Get()[extension_id]; 151 EventListenerCounts& listener_counts = g_listener_counts.Get()[extension_id];
152 if (++listener_counts[event_name] == 1) { 152 if (++listener_counts[event_name] == 1) {
153 content::RenderThread::Get()->Send( 153 content::RenderThread::Get()->Send(new ExtensionHostMsg_AddListener(
154 new ExtensionHostMsg_AddListener(extension_id, event_name)); 154 extension_id, context()->GetURL(), event_name));
155 } 155 }
156 156
157 // This is called the first time the page has added a listener. Since 157 // This is called the first time the page has added a listener. Since
158 // the background page is the only lazy page, we know this is the first 158 // the background page is the only lazy page, we know this is the first
159 // time this listener has been registered. 159 // time this listener has been registered.
160 if (IsLazyBackgroundPage(context()->GetRenderView(), 160 if (IsLazyBackgroundPage(context()->GetRenderView(),
161 context()->extension())) { 161 context()->extension())) {
162 content::RenderThread::Get()->Send( 162 content::RenderThread::Get()->Send(
163 new ExtensionHostMsg_AddLazyListener(extension_id, event_name)); 163 new ExtensionHostMsg_AddLazyListener(extension_id, event_name));
164 } 164 }
165 } 165 }
166 166
167 void EventBindings::DetachEvent( 167 void EventBindings::DetachEvent(
168 const v8::FunctionCallbackInfo<v8::Value>& args) { 168 const v8::FunctionCallbackInfo<v8::Value>& args) {
169 CHECK_EQ(2, args.Length()); 169 CHECK_EQ(2, args.Length());
170 CHECK(args[0]->IsString()); 170 CHECK(args[0]->IsString());
171 CHECK(args[1]->IsBoolean()); 171 CHECK(args[1]->IsBoolean());
172 172
173 std::string event_name = *v8::String::Utf8Value(args[0]); 173 std::string event_name = *v8::String::Utf8Value(args[0]);
174 bool is_manual = args[1]->BooleanValue(); 174 bool is_manual = args[1]->BooleanValue();
175 175
176 std::string extension_id = context()->GetExtensionID(); 176 std::string extension_id = context()->GetExtensionID();
177 EventListenerCounts& listener_counts = g_listener_counts.Get()[extension_id]; 177 EventListenerCounts& listener_counts = g_listener_counts.Get()[extension_id];
178 178
179 if (--listener_counts[event_name] == 0) { 179 if (--listener_counts[event_name] == 0) {
180 content::RenderThread::Get()->Send( 180 content::RenderThread::Get()->Send(new ExtensionHostMsg_RemoveListener(
181 new ExtensionHostMsg_RemoveListener(extension_id, event_name)); 181 extension_id, context()->GetURL(), event_name));
182 } 182 }
183 183
184 // DetachEvent is called when the last listener for the context is 184 // DetachEvent is called when the last listener for the context is
185 // removed. If the context is the background page, and it removes the 185 // removed. If the context is the background page, and it removes the
186 // last listener manually, then we assume that it is no longer interested 186 // last listener manually, then we assume that it is no longer interested
187 // in being awakened for this event. 187 // in being awakened for this event.
188 if (is_manual && IsLazyBackgroundPage(context()->GetRenderView(), 188 if (is_manual && IsLazyBackgroundPage(context()->GetRenderView(),
189 context()->extension())) { 189 context()->extension())) {
190 content::RenderThread::Get()->Send( 190 content::RenderThread::Get()->Send(
191 new ExtensionHostMsg_RemoveLazyListener(extension_id, event_name)); 191 new ExtensionHostMsg_RemoveLazyListener(extension_id, event_name));
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 300 }
301 301
302 scoped_ptr<EventMatcher> EventBindings::ParseEventMatcher( 302 scoped_ptr<EventMatcher> EventBindings::ParseEventMatcher(
303 base::DictionaryValue* filter_dict) { 303 base::DictionaryValue* filter_dict) {
304 return scoped_ptr<EventMatcher>(new EventMatcher( 304 return scoped_ptr<EventMatcher>(new EventMatcher(
305 scoped_ptr<base::DictionaryValue>(filter_dict->DeepCopy()), 305 scoped_ptr<base::DictionaryValue>(filter_dict->DeepCopy()),
306 context()->GetRenderView()->GetRoutingID())); 306 context()->GetRenderView()->GetRoutingID()));
307 } 307 }
308 308
309 } // namespace extensions 309 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/simple_feature.cc ('k') | extensions/renderer/resources/binding.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698