OLD | NEW |
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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 filter_copy.reset(filter_->DeepCopy()); | 55 filter_copy.reset(filter_->DeepCopy()); |
56 return scoped_ptr<EventListener>(new EventListener( | 56 return scoped_ptr<EventListener>(new EventListener( |
57 event_name_, extension_id_, listener_url_, process_, filter_copy.Pass())); | 57 event_name_, extension_id_, listener_url_, process_, filter_copy.Pass())); |
58 } | 58 } |
59 | 59 |
60 bool EventListener::IsLazy() const { | 60 bool EventListener::IsLazy() const { |
61 return !process_; | 61 return !process_; |
62 } | 62 } |
63 | 63 |
64 void EventListener::MakeLazy() { | 64 void EventListener::MakeLazy() { |
65 process_ = NULL; | 65 process_ = nullptr; |
66 } | 66 } |
67 | 67 |
68 content::BrowserContext* EventListener::GetBrowserContext() const { | 68 content::BrowserContext* EventListener::GetBrowserContext() const { |
69 return process_ ? process_->GetBrowserContext() : NULL; | 69 return process_ ? process_->GetBrowserContext() : nullptr; |
70 } | 70 } |
71 | 71 |
72 EventListener::EventListener(const std::string& event_name, | 72 EventListener::EventListener(const std::string& event_name, |
73 const std::string& extension_id, | 73 const std::string& extension_id, |
74 const GURL& listener_url, | 74 const GURL& listener_url, |
75 content::RenderProcessHost* process, | 75 content::RenderProcessHost* process, |
76 scoped_ptr<DictionaryValue> filter) | 76 scoped_ptr<DictionaryValue> filter) |
77 : event_name_(event_name), | 77 : event_name_(event_name), |
78 extension_id_(extension_id), | 78 extension_id_(extension_id), |
79 listener_url_(listener_url), | 79 listener_url_(listener_url), |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 191 } |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 void EventListenerMap::LoadUnfilteredLazyListeners( | 195 void EventListenerMap::LoadUnfilteredLazyListeners( |
196 const std::string& extension_id, | 196 const std::string& extension_id, |
197 const std::set<std::string>& event_names) { | 197 const std::set<std::string>& event_names) { |
198 for (std::set<std::string>::const_iterator it = event_names.begin(); | 198 for (std::set<std::string>::const_iterator it = event_names.begin(); |
199 it != event_names.end(); ++it) { | 199 it != event_names.end(); ++it) { |
200 AddListener(EventListener::ForExtension( | 200 AddListener(EventListener::ForExtension( |
201 *it, extension_id, NULL, scoped_ptr<DictionaryValue>())); | 201 *it, extension_id, nullptr, scoped_ptr<DictionaryValue>())); |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 void EventListenerMap::LoadFilteredLazyListeners( | 205 void EventListenerMap::LoadFilteredLazyListeners( |
206 const std::string& extension_id, | 206 const std::string& extension_id, |
207 const DictionaryValue& filtered) { | 207 const DictionaryValue& filtered) { |
208 for (DictionaryValue::Iterator it(filtered); !it.IsAtEnd(); it.Advance()) { | 208 for (DictionaryValue::Iterator it(filtered); !it.IsAtEnd(); it.Advance()) { |
209 // We skip entries if they are malformed. | 209 // We skip entries if they are malformed. |
210 const base::ListValue* filter_list = NULL; | 210 const base::ListValue* filter_list = nullptr; |
211 if (!it.value().GetAsList(&filter_list)) | 211 if (!it.value().GetAsList(&filter_list)) |
212 continue; | 212 continue; |
213 for (size_t i = 0; i < filter_list->GetSize(); i++) { | 213 for (size_t i = 0; i < filter_list->GetSize(); i++) { |
214 const DictionaryValue* filter = NULL; | 214 const DictionaryValue* filter = nullptr; |
215 if (!filter_list->GetDictionary(i, &filter)) | 215 if (!filter_list->GetDictionary(i, &filter)) |
216 continue; | 216 continue; |
217 AddListener(EventListener::ForExtension( | 217 AddListener( |
218 it.key(), extension_id, NULL, make_scoped_ptr(filter->DeepCopy()))); | 218 EventListener::ForExtension(it.key(), |
| 219 extension_id, |
| 220 nullptr, |
| 221 make_scoped_ptr(filter->DeepCopy()))); |
219 } | 222 } |
220 } | 223 } |
221 } | 224 } |
222 | 225 |
223 std::set<const EventListener*> EventListenerMap::GetEventListeners( | 226 std::set<const EventListener*> EventListenerMap::GetEventListeners( |
224 const Event& event) { | 227 const Event& event) { |
225 std::set<const EventListener*> interested_listeners; | 228 std::set<const EventListener*> interested_listeners; |
226 if (IsFilteredEvent(event)) { | 229 if (IsFilteredEvent(event)) { |
227 // Look up the interested listeners via the EventFilter. | 230 // Look up the interested listeners via the EventFilter. |
228 std::set<MatcherID> ids = | 231 std::set<MatcherID> ids = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 return; | 273 return; |
271 event_filter_.RemoveEventMatcher(listener->matcher_id()); | 274 event_filter_.RemoveEventMatcher(listener->matcher_id()); |
272 CHECK_EQ(1u, listeners_by_matcher_id_.erase(listener->matcher_id())); | 275 CHECK_EQ(1u, listeners_by_matcher_id_.erase(listener->matcher_id())); |
273 } | 276 } |
274 | 277 |
275 bool EventListenerMap::IsFilteredEvent(const Event& event) const { | 278 bool EventListenerMap::IsFilteredEvent(const Event& event) const { |
276 return filtered_events_.count(event.event_name) > 0u; | 279 return filtered_events_.count(event.event_name) > 0u; |
277 } | 280 } |
278 | 281 |
279 } // namespace extensions | 282 } // namespace extensions |
OLD | NEW |