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

Side by Side Diff: extensions/browser/event_listener_map.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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/event_listener_map.h" 5 #include "extensions/browser/event_listener_map.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "content/public/browser/render_process_host.h" 8 #include "content/public/browser/render_process_host.h"
9 #include "extensions/browser/event_router.h" 9 #include "extensions/browser/event_router.h"
10 #include "ipc/ipc_message.h" 10 #include "ipc/ipc_message.h"
11 #include "url/gurl.h"
11 12
12 using base::DictionaryValue; 13 using base::DictionaryValue;
13 14
14 namespace extensions { 15 namespace extensions {
15 16
16 typedef EventFilter::MatcherID MatcherID; 17 typedef EventFilter::MatcherID MatcherID;
17 18
18 EventListener::EventListener(const std::string& event_name, 19 EventListener::EventListener(const std::string& event_name,
19 const std::string& extension_id, 20 const std::string& extension_id,
21 const GURL& listener_url,
20 content::RenderProcessHost* process, 22 content::RenderProcessHost* process,
21 scoped_ptr<DictionaryValue> filter) 23 scoped_ptr<DictionaryValue> filter)
22 : event_name_(event_name), 24 : event_name_(event_name),
23 extension_id_(extension_id), 25 extension_id_(extension_id),
26 listener_url_(listener_url),
24 process_(process), 27 process_(process),
25 filter_(filter.Pass()), 28 filter_(filter.Pass()),
26 matcher_id_(-1) { 29 matcher_id_(-1) {
27 } 30 }
28 31
29 EventListener::~EventListener() {} 32 EventListener::~EventListener() {}
30 33
31 bool EventListener::Equals(const EventListener* other) const { 34 bool EventListener::Equals(const EventListener* other) const {
32 // We don't check matcher_id equality because we want a listener with a 35 // We don't check matcher_id equality because we want a listener with a
33 // filter that hasn't been added to EventFilter to match one that is 36 // filter that hasn't been added to EventFilter to match one that is
34 // equivalent but has. 37 // equivalent but has.
35 return event_name_ == other->event_name_ && 38 return event_name_ == other->event_name_ &&
36 extension_id_ == other->extension_id_ && process_ == other->process_ && 39 extension_id_ == other->extension_id_ &&
40 listener_url_ == other->listener_url_ && process_ == other->process_ &&
37 ((!!filter_.get()) == (!!other->filter_.get())) && 41 ((!!filter_.get()) == (!!other->filter_.get())) &&
38 (!filter_.get() || filter_->Equals(other->filter_.get())); 42 (!filter_.get() || filter_->Equals(other->filter_.get()));
39 } 43 }
40 44
41 scoped_ptr<EventListener> EventListener::Copy() const { 45 scoped_ptr<EventListener> EventListener::Copy() const {
42 scoped_ptr<DictionaryValue> filter_copy; 46 scoped_ptr<DictionaryValue> filter_copy;
43 if (filter_) 47 if (filter_)
44 filter_copy.reset(filter_->DeepCopy()); 48 filter_copy.reset(filter_->DeepCopy());
45 return scoped_ptr<EventListener>(new EventListener( 49 return scoped_ptr<EventListener>(new EventListener(
46 event_name_, extension_id_, process_, filter_copy.Pass())); 50 event_name_, extension_id_, listener_url_, process_, filter_copy.Pass()));
47 } 51 }
48 52
49 bool EventListener::IsLazy() const { 53 bool EventListener::IsLazy() const {
50 return !process_; 54 return !process_;
51 } 55 }
52 56
53 void EventListener::MakeLazy() { 57 void EventListener::MakeLazy() {
54 process_ = NULL; 58 process_ = NULL;
55 } 59 }
56 60
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 141 }
138 return false; 142 return false;
139 } 143 }
140 144
141 bool EventListenerMap::HasProcessListener(content::RenderProcessHost* process, 145 bool EventListenerMap::HasProcessListener(content::RenderProcessHost* process,
142 const std::string& extension_id) { 146 const std::string& extension_id) {
143 for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end(); 147 for (ListenerMap::iterator it = listeners_.begin(); it != listeners_.end();
144 it++) { 148 it++) {
145 for (ListenerList::iterator it2 = it->second.begin(); 149 for (ListenerList::iterator it2 = it->second.begin();
146 it2 != it->second.end(); it2++) { 150 it2 != it->second.end(); it2++) {
151 // TODO(kalman): Thread listener_url into here?
147 if ((*it2)->process() == process && 152 if ((*it2)->process() == process &&
148 (*it2)->extension_id() == extension_id) 153 (*it2)->extension_id() == extension_id)
149 return true; 154 return true;
150 } 155 }
151 } 156 }
152 return false; 157 return false;
153 } 158 }
154 159
155 void EventListenerMap::RemoveLazyListenersForExtension( 160 void EventListenerMap::RemoveLazyListenersForExtension(
156 const std::string& extension_id) { 161 const std::string& extension_id) {
(...skipping 10 matching lines...) Expand all
167 } 172 }
168 } 173 }
169 } 174 }
170 175
171 void EventListenerMap::LoadUnfilteredLazyListeners( 176 void EventListenerMap::LoadUnfilteredLazyListeners(
172 const std::string& extension_id, 177 const std::string& extension_id,
173 const std::set<std::string>& event_names) { 178 const std::set<std::string>& event_names) {
174 for (std::set<std::string>::const_iterator it = event_names.begin(); 179 for (std::set<std::string>::const_iterator it = event_names.begin();
175 it != event_names.end(); ++it) { 180 it != event_names.end(); ++it) {
176 AddListener(scoped_ptr<EventListener>(new EventListener( 181 AddListener(scoped_ptr<EventListener>(new EventListener(
177 *it, extension_id, NULL, scoped_ptr<DictionaryValue>()))); 182 *it, extension_id, GURL(), NULL, scoped_ptr<DictionaryValue>())));
178 } 183 }
179 } 184 }
180 185
181 void EventListenerMap::LoadFilteredLazyListeners( 186 void EventListenerMap::LoadFilteredLazyListeners(
182 const std::string& extension_id, 187 const std::string& extension_id,
183 const DictionaryValue& filtered) { 188 const DictionaryValue& filtered) {
184 for (DictionaryValue::Iterator it(filtered); !it.IsAtEnd(); it.Advance()) { 189 for (DictionaryValue::Iterator it(filtered); !it.IsAtEnd(); it.Advance()) {
185 // We skip entries if they are malformed. 190 // We skip entries if they are malformed.
186 const base::ListValue* filter_list = NULL; 191 const base::ListValue* filter_list = NULL;
187 if (!it.value().GetAsList(&filter_list)) 192 if (!it.value().GetAsList(&filter_list))
188 continue; 193 continue;
189 for (size_t i = 0; i < filter_list->GetSize(); i++) { 194 for (size_t i = 0; i < filter_list->GetSize(); i++) {
190 const DictionaryValue* filter = NULL; 195 const DictionaryValue* filter = NULL;
191 if (!filter_list->GetDictionary(i, &filter)) 196 if (!filter_list->GetDictionary(i, &filter))
192 continue; 197 continue;
193 AddListener(scoped_ptr<EventListener>(new EventListener( 198 AddListener(scoped_ptr<EventListener>(
194 it.key(), extension_id, NULL, 199 new EventListener(it.key(),
195 scoped_ptr<DictionaryValue>(filter->DeepCopy())))); 200 extension_id,
201 GURL(),
202 NULL,
203 scoped_ptr<DictionaryValue>(filter->DeepCopy()))));
196 } 204 }
197 } 205 }
198 } 206 }
199 207
200 std::set<const EventListener*> EventListenerMap::GetEventListeners( 208 std::set<const EventListener*> EventListenerMap::GetEventListeners(
201 const Event& event) { 209 const Event& event) {
202 std::set<const EventListener*> interested_listeners; 210 std::set<const EventListener*> interested_listeners;
203 if (IsFilteredEvent(event)) { 211 if (IsFilteredEvent(event)) {
204 // Look up the interested listeners via the EventFilter. 212 // Look up the interested listeners via the EventFilter.
205 std::set<MatcherID> ids = 213 std::set<MatcherID> ids =
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 return; 255 return;
248 event_filter_.RemoveEventMatcher(listener->matcher_id()); 256 event_filter_.RemoveEventMatcher(listener->matcher_id());
249 CHECK_EQ(1u, listeners_by_matcher_id_.erase(listener->matcher_id())); 257 CHECK_EQ(1u, listeners_by_matcher_id_.erase(listener->matcher_id()));
250 } 258 }
251 259
252 bool EventListenerMap::IsFilteredEvent(const Event& event) const { 260 bool EventListenerMap::IsFilteredEvent(const Event& event) const {
253 return filtered_events_.count(event.event_name) > 0u; 261 return filtered_events_.count(event.event_name) > 0u;
254 } 262 }
255 263
256 } // namespace extensions 264 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/event_listener_map.h ('k') | extensions/browser/event_listener_map_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698