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 #ifndef EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ | 5 #ifndef EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ |
6 #define EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ | 6 #define EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "extensions/common/event_filter.h" | 14 #include "extensions/common/event_filter.h" |
| 15 #include "url/gurl.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 class DictionaryValue; | 18 class DictionaryValue; |
18 } | 19 } |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 class BrowserContext; | 22 class BrowserContext; |
22 class RenderProcessHost; | 23 class RenderProcessHost; |
23 } | 24 } |
24 | 25 |
25 class ListenerRemovalListener; | 26 class ListenerRemovalListener; |
26 | 27 |
27 namespace extensions { | 28 namespace extensions { |
28 struct Event; | 29 struct Event; |
29 | 30 |
30 // A listener for an extension event. A listener is essentially an endpoint | 31 // A listener for an extension event. A listener is essentially an endpoint |
31 // that an event can be dispatched to. | 32 // that an event can be dispatched to. |
32 // | 33 // |
33 // This is a lazy listener if |IsLazy| is returns true, and a filtered listener | 34 // This is a lazy listener if |IsLazy| is returns true, and a filtered listener |
34 // if |filter| is defined. | 35 // if |filter| is defined. |
35 // | 36 // |
36 // A lazy listener is added to an event to indicate that a lazy background page | 37 // A lazy listener is added to an event to indicate that a lazy background page |
37 // is listening to the event. It is associated with no process, so to dispatch | 38 // is listening to the event. It is associated with no process, so to dispatch |
38 // an event to a lazy listener one must start a process running the associated | 39 // an event to a lazy listener one must start a process running the associated |
39 // extension and dispatch the event to that. | 40 // extension and dispatch the event to that. |
40 // | |
41 class EventListener { | 41 class EventListener { |
42 public: | 42 public: |
43 // |filter| represents a generic filter structure that EventFilter knows how | 43 // |filter| represents a generic filter structure that EventFilter knows how |
44 // to filter events with. A typical filter instance will look like | 44 // to filter events with. A typical filter instance will look like |
45 // | 45 // |
46 // { | 46 // { |
47 // url: [{hostSuffix: 'google.com'}], | 47 // url: [{hostSuffix: 'google.com'}], |
48 // tabId: 5 | 48 // tabId: 5 |
49 // } | 49 // } |
50 EventListener(const std::string& event_name, | 50 EventListener(const std::string& event_name, |
51 const std::string& extension_id, | 51 const std::string& extension_id, |
| 52 const GURL& listener_url, |
52 content::RenderProcessHost* process, | 53 content::RenderProcessHost* process, |
53 scoped_ptr<base::DictionaryValue> filter); | 54 scoped_ptr<base::DictionaryValue> filter); |
54 ~EventListener(); | 55 ~EventListener(); |
55 | 56 |
56 bool Equals(const EventListener* other) const; | 57 bool Equals(const EventListener* other) const; |
57 | 58 |
58 scoped_ptr<EventListener> Copy() const; | 59 scoped_ptr<EventListener> Copy() const; |
59 | 60 |
60 // Returns true in the case of a lazy background page, and thus no process. | 61 // Returns true in the case of a lazy background page, and thus no process. |
61 bool IsLazy() const; | 62 bool IsLazy() const; |
62 | 63 |
63 // Modifies this listener to be a lazy listener, clearing process references. | 64 // Modifies this listener to be a lazy listener, clearing process references. |
64 void MakeLazy(); | 65 void MakeLazy(); |
65 | 66 |
66 // Returns the browser context associated with the listener, or NULL if | 67 // Returns the browser context associated with the listener, or NULL if |
67 // IsLazy. | 68 // IsLazy. |
68 content::BrowserContext* GetBrowserContext() const; | 69 content::BrowserContext* GetBrowserContext() const; |
69 | 70 |
70 const std::string event_name() const { return event_name_; } | 71 const std::string& event_name() const { return event_name_; } |
71 const std::string extension_id() const { return extension_id_; } | 72 const std::string& extension_id() const { return extension_id_; } |
| 73 const GURL& listener_url() const { return listener_url_; } |
72 content::RenderProcessHost* process() const { return process_; } | 74 content::RenderProcessHost* process() const { return process_; } |
73 base::DictionaryValue* filter() const { return filter_.get(); } | 75 base::DictionaryValue* filter() const { return filter_.get(); } |
74 EventFilter::MatcherID matcher_id() const { return matcher_id_; } | 76 EventFilter::MatcherID matcher_id() const { return matcher_id_; } |
75 void set_matcher_id(EventFilter::MatcherID id) { matcher_id_ = id; } | 77 void set_matcher_id(EventFilter::MatcherID id) { matcher_id_ = id; } |
76 | 78 |
77 private: | 79 private: |
78 const std::string event_name_; | 80 const std::string event_name_; |
79 const std::string extension_id_; | 81 const std::string extension_id_; |
| 82 const GURL listener_url_; |
80 content::RenderProcessHost* process_; | 83 content::RenderProcessHost* process_; |
81 scoped_ptr<base::DictionaryValue> filter_; | 84 scoped_ptr<base::DictionaryValue> filter_; |
82 EventFilter::MatcherID matcher_id_; // -1 if unset. | 85 EventFilter::MatcherID matcher_id_; // -1 if unset. |
83 | 86 |
84 DISALLOW_COPY_AND_ASSIGN(EventListener); | 87 DISALLOW_COPY_AND_ASSIGN(EventListener); |
85 }; | 88 }; |
86 | 89 |
87 // Holds listeners for extension events and can answer questions about which | 90 // Holds listeners for extension events and can answer questions about which |
88 // listeners are interested in what events. | 91 // listeners are interested in what events. |
89 class EventListenerMap { | 92 class EventListenerMap { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 std::map<EventFilter::MatcherID, EventListener*> listeners_by_matcher_id_; | 175 std::map<EventFilter::MatcherID, EventListener*> listeners_by_matcher_id_; |
173 | 176 |
174 EventFilter event_filter_; | 177 EventFilter event_filter_; |
175 | 178 |
176 DISALLOW_COPY_AND_ASSIGN(EventListenerMap); | 179 DISALLOW_COPY_AND_ASSIGN(EventListenerMap); |
177 }; | 180 }; |
178 | 181 |
179 } // namespace extensions | 182 } // namespace extensions |
180 | 183 |
181 #endif // EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ | 184 #endif // EXTENSIONS_BROWSER_EVENT_LISTENER_MAP_H_ |
OLD | NEW |