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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
14 #include "extensions/browser/event_router.h" | 14 #include "extensions/browser/event_router.h" |
15 #include "ipc/ipc_message.h" | 15 #include "ipc/ipc_message.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 #include "url/origin.h" |
17 | 18 |
18 using base::DictionaryValue; | 19 using base::DictionaryValue; |
19 | 20 |
20 namespace extensions { | 21 namespace extensions { |
21 | 22 |
22 typedef EventFilter::MatcherID MatcherID; | 23 typedef EventFilter::MatcherID MatcherID; |
23 | 24 |
24 // static | 25 // static |
25 std::unique_ptr<EventListener> EventListener::ForExtension( | 26 std::unique_ptr<EventListener> EventListener::ForExtension( |
26 const std::string& event_name, | 27 const std::string& event_name, |
27 const std::string& extension_id, | 28 const std::string& extension_id, |
28 content::RenderProcessHost* process, | 29 content::RenderProcessHost* process, |
29 std::unique_ptr<base::DictionaryValue> filter) { | 30 std::unique_ptr<base::DictionaryValue> filter) { |
30 return base::WrapUnique(new EventListener(event_name, extension_id, GURL(), | 31 return base::WrapUnique(new EventListener(event_name, extension_id, GURL(), |
31 process, std::move(filter))); | 32 process, std::move(filter))); |
32 } | 33 } |
33 | 34 |
34 // static | 35 // static |
35 std::unique_ptr<EventListener> EventListener::ForURL( | 36 std::unique_ptr<EventListener> EventListener::ForURL( |
36 const std::string& event_name, | 37 const std::string& event_name, |
37 const GURL& listener_url, | 38 const GURL& listener_url, |
38 content::RenderProcessHost* process, | 39 content::RenderProcessHost* process, |
39 std::unique_ptr<base::DictionaryValue> filter) { | 40 std::unique_ptr<base::DictionaryValue> filter) { |
40 return base::WrapUnique(new EventListener(event_name, "", listener_url, | 41 // Use only the origin to identify the event listener, e.g. chrome://settings |
| 42 // for chrome://settings/accounts, to avoid multiple events being triggered |
| 43 // for the same process. See crbug.com/536858 for details. // TODO(devlin): If |
| 44 // we dispatched events to processes more intelligently this could be avoided. |
| 45 return base::WrapUnique(new EventListener(event_name, "", |
| 46 url::Origin(listener_url).GetURL(), |
41 process, std::move(filter))); | 47 process, std::move(filter))); |
42 } | 48 } |
43 | 49 |
44 EventListener::~EventListener() {} | 50 EventListener::~EventListener() {} |
45 | 51 |
46 bool EventListener::Equals(const EventListener* other) const { | 52 bool EventListener::Equals(const EventListener* other) const { |
47 // We don't check matcher_id equality because we want a listener with a | 53 // We don't check matcher_id equality because we want a listener with a |
48 // filter that hasn't been added to EventFilter to match one that is | 54 // filter that hasn't been added to EventFilter to match one that is |
49 // equivalent but has. | 55 // equivalent but has. |
50 return event_name_ == other->event_name_ && | 56 return event_name_ == other->event_name_ && |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 return; | 284 return; |
279 event_filter_.RemoveEventMatcher(listener->matcher_id()); | 285 event_filter_.RemoveEventMatcher(listener->matcher_id()); |
280 CHECK_EQ(1u, listeners_by_matcher_id_.erase(listener->matcher_id())); | 286 CHECK_EQ(1u, listeners_by_matcher_id_.erase(listener->matcher_id())); |
281 } | 287 } |
282 | 288 |
283 bool EventListenerMap::IsFilteredEvent(const Event& event) const { | 289 bool EventListenerMap::IsFilteredEvent(const Event& event) const { |
284 return filtered_events_.count(event.event_name) > 0u; | 290 return filtered_events_.count(event.event_name) > 0u; |
285 } | 291 } |
286 | 292 |
287 } // namespace extensions | 293 } // namespace extensions |
OLD | NEW |