OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/memory/linked_ptr.h" | |
13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
14 #include "content/common/notification_observer.h" | 15 #include "content/common/notification_observer.h" |
15 #include "content/common/notification_registrar.h" | 16 #include "content/common/notification_registrar.h" |
16 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
17 | 18 |
18 class GURL; | 19 class GURL; |
19 class Extension; | 20 class Extension; |
20 class ExtensionDevToolsManager; | 21 class ExtensionDevToolsManager; |
21 class Profile; | 22 class Profile; |
22 class RenderProcessHost; | 23 class RenderProcessHost; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 // normal profile only works if extension is allowed incognito access). If | 59 // normal profile only works if extension is allowed incognito access). If |
59 // |event_url| is not empty, the event is only sent to extension with host | 60 // |event_url| is not empty, the event is only sent to extension with host |
60 // permissions for this url. | 61 // permissions for this url. |
61 void DispatchEventToRenderers( | 62 void DispatchEventToRenderers( |
62 const std::string& event_name, | 63 const std::string& event_name, |
63 const std::string& event_args, | 64 const std::string& event_args, |
64 Profile* restrict_to_profile, | 65 Profile* restrict_to_profile, |
65 const GURL& event_url); | 66 const GURL& event_url); |
66 | 67 |
67 // Same as above, except only send the event to the given extension. | 68 // Same as above, except only send the event to the given extension. |
68 void DispatchEventToExtension( | 69 virtual void DispatchEventToExtension( |
69 const std::string& extension_id, | 70 const std::string& extension_id, |
70 const std::string& event_name, | 71 const std::string& event_name, |
71 const std::string& event_args, | 72 const std::string& event_args, |
72 Profile* restrict_to_profile, | 73 Profile* restrict_to_profile, |
73 const GURL& event_url); | 74 const GURL& event_url); |
74 | 75 |
75 // Send different versions of an event to extensions in different profiles. | 76 // Send different versions of an event to extensions in different profiles. |
76 // This is used in the case of sending one event to extensions that have | 77 // This is used in the case of sending one event to extensions that have |
77 // incognito access, and another event to extensions that don't (here), | 78 // incognito access, and another event to extensions that don't (here), |
78 // in order to avoid sending 2 events to "spanning" extensions. | 79 // in order to avoid sending 2 events to "spanning" extensions. |
79 // If |cross_incognito_profile| is non-NULL and different from | 80 // If |cross_incognito_profile| is non-NULL and different from |
80 // restrict_to_profile, send the event with cross_incognito_args to the | 81 // restrict_to_profile, send the event with cross_incognito_args to the |
81 // extensions in that profile that can't cross incognito. | 82 // extensions in that profile that can't cross incognito. |
82 void DispatchEventsToRenderersAcrossIncognito( | 83 void DispatchEventsToRenderersAcrossIncognito( |
83 const std::string& event_name, | 84 const std::string& event_name, |
84 const std::string& event_args, | 85 const std::string& event_args, |
85 Profile* restrict_to_profile, | 86 Profile* restrict_to_profile, |
86 const std::string& cross_incognito_args, | 87 const std::string& cross_incognito_args, |
87 const GURL& event_url); | 88 const GURL& event_url); |
88 | 89 |
89 protected: | 90 protected: |
91 // The details of an event to be dispatched. | |
92 struct ExtensionEvent; | |
93 | |
90 // Shared by DispatchEvent*. If |extension_id| is empty, the event is | 94 // Shared by DispatchEvent*. If |extension_id| is empty, the event is |
91 // broadcast. | 95 // broadcast. |
92 virtual void DispatchEventImpl( | 96 // An event that just came off the pending list may not be delayed again. |
93 const std::string& extension_id, | 97 void DispatchEventImpl(const ExtensionEvent& event, bool was_pending); |
94 const std::string& event_name, | 98 |
95 const std::string& event_args, | 99 // Dispatch may be delayed if the extension has a lazy background page. |
96 Profile* restrict_to_profile, | 100 bool CanDispatchEventNow(const std::string& extension_id); |
97 const std::string& cross_incognito_args, | 101 |
98 const GURL& event_url); | 102 // Store the event so that it can be dispatched (in order received) |
103 // when the background page is done loading. | |
104 void AppendEvent(const ExtensionEvent& pending_event); | |
105 void DispatchPendingEvents(const std::string& extension_id); | |
99 | 106 |
100 private: | 107 private: |
101 // An extension listening to an event. | 108 // An extension listening to an event. |
102 struct EventListener; | 109 struct EventListener; |
103 | 110 |
104 virtual void Observe(int type, | 111 virtual void Observe(int type, |
105 const NotificationSource& source, | 112 const NotificationSource& source, |
106 const NotificationDetails& details); | 113 const NotificationDetails& details); |
107 | 114 |
108 Profile* profile_; | 115 Profile* profile_; |
109 | 116 |
110 NotificationRegistrar registrar_; | 117 NotificationRegistrar registrar_; |
111 | 118 |
112 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; | 119 scoped_refptr<ExtensionDevToolsManager> extension_devtools_manager_; |
113 | 120 |
114 // A map between an event name and a set of extensions that are listening | 121 // A map between an event name and a set of extensions that are listening |
115 // to that event. | 122 // to that event. |
116 typedef std::map<std::string, std::set<EventListener> > ListenerMap; | 123 typedef std::map<std::string, std::set<EventListener> > ListenerMap; |
117 ListenerMap listeners_; | 124 ListenerMap listeners_; |
118 | 125 |
126 // A map between an extension id and the queue of events pending | |
127 // the load of it's background page. | |
128 typedef std::vector<linked_ptr<const ExtensionEvent> > PendingEventsList; | |
Tessa MacDuff
2011/08/29 20:15:32
IfI make this a std::vector<ExtensionEvent> the er
| |
129 typedef std::map<std::string, | |
130 linked_ptr<PendingEventsList> > PendingEventsPerExtMap; | |
131 PendingEventsPerExtMap pending_events_; | |
132 | |
119 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); | 133 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); |
120 }; | 134 }; |
121 | 135 |
122 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ | 136 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
OLD | NEW |