OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> |
(...skipping 16 matching lines...) Expand all Loading... | |
27 } | 27 } |
28 | 28 |
29 class ExtensionEventRouter : public content::NotificationObserver { | 29 class ExtensionEventRouter : public content::NotificationObserver { |
30 public: | 30 public: |
31 // Sends an event via ipc_sender to the given extension. Can be called on | 31 // Sends an event via ipc_sender to the given extension. Can be called on |
32 // any thread. | 32 // any thread. |
33 static void DispatchEvent(IPC::Message::Sender* ipc_sender, | 33 static void DispatchEvent(IPC::Message::Sender* ipc_sender, |
34 const std::string& extension_id, | 34 const std::string& extension_id, |
35 const std::string& event_name, | 35 const std::string& event_name, |
36 const std::string& event_args, | 36 const std::string& event_args, |
37 const GURL& event_url); | 37 const GURL& event_url, |
38 bool user_caused = false); | |
Aaron Boodman
2012/02/03 20:18:47
I suggest consistently using the term 'user_gestur
Aaron Boodman
2012/02/03 20:18:47
Also, consider using an enum for this flag, like:
Matt Perry
2012/02/03 20:34:41
Default arguments are forbidden by the style guide
Greg Billock
2012/02/03 22:57:56
My plan was to only set the gesture indicator when
Greg Billock
2012/02/06 22:58:01
Done.
Greg Billock
2012/02/06 22:58:01
Done.
Greg Billock
2012/02/06 22:58:01
Done.
| |
38 | 39 |
39 explicit ExtensionEventRouter(Profile* profile); | 40 explicit ExtensionEventRouter(Profile* profile); |
40 virtual ~ExtensionEventRouter(); | 41 virtual ~ExtensionEventRouter(); |
41 | 42 |
42 // Add or remove the process/extension pair as a listener for |event_name|. | 43 // Add or remove the process/extension pair as a listener for |event_name|. |
43 // Note that multiple extensions can share a process due to process | 44 // Note that multiple extensions can share a process due to process |
44 // collapsing. Also, a single extension can have 2 processes if it is a split | 45 // collapsing. Also, a single extension can have 2 processes if it is a split |
45 // mode extension. | 46 // mode extension. |
46 void AddEventListener(const std::string& event_name, | 47 void AddEventListener(const std::string& event_name, |
47 content::RenderProcessHost* process, | 48 content::RenderProcessHost* process, |
(...skipping 12 matching lines...) Expand all Loading... | |
60 // Send an event to every registered extension renderer. If | 61 // Send an event to every registered extension renderer. If |
61 // |restrict_to_profile| is non-NULL, then the event will not be sent to other | 62 // |restrict_to_profile| is non-NULL, then the event will not be sent to other |
62 // profiles unless the extension has permission (e.g. incognito tab update -> | 63 // profiles unless the extension has permission (e.g. incognito tab update -> |
63 // normal profile only works if extension is allowed incognito access). If | 64 // normal profile only works if extension is allowed incognito access). If |
64 // |event_url| is not empty, the event is only sent to extension with host | 65 // |event_url| is not empty, the event is only sent to extension with host |
65 // permissions for this url. | 66 // permissions for this url. |
66 void DispatchEventToRenderers( | 67 void DispatchEventToRenderers( |
67 const std::string& event_name, | 68 const std::string& event_name, |
68 const std::string& event_args, | 69 const std::string& event_args, |
69 Profile* restrict_to_profile, | 70 Profile* restrict_to_profile, |
70 const GURL& event_url); | 71 const GURL& event_url, |
72 bool user_caused = false); | |
71 | 73 |
72 // Same as above, except only send the event to the given extension. | 74 // Same as above, except only send the event to the given extension. |
73 virtual void DispatchEventToExtension( | 75 virtual void DispatchEventToExtension( |
74 const std::string& extension_id, | 76 const std::string& extension_id, |
75 const std::string& event_name, | 77 const std::string& event_name, |
76 const std::string& event_args, | 78 const std::string& event_args, |
77 Profile* restrict_to_profile, | 79 Profile* restrict_to_profile, |
78 const GURL& event_url); | 80 const GURL& event_url, |
81 bool user_caused = false); | |
79 | 82 |
80 // Send different versions of an event to extensions in different profiles. | 83 // Send different versions of an event to extensions in different profiles. |
81 // This is used in the case of sending one event to extensions that have | 84 // This is used in the case of sending one event to extensions that have |
82 // incognito access, and another event to extensions that don't (here), | 85 // incognito access, and another event to extensions that don't (here), |
83 // in order to avoid sending 2 events to "spanning" extensions. | 86 // in order to avoid sending 2 events to "spanning" extensions. |
84 // If |cross_incognito_profile| is non-NULL and different from | 87 // If |cross_incognito_profile| is non-NULL and different from |
85 // restrict_to_profile, send the event with cross_incognito_args to the | 88 // restrict_to_profile, send the event with cross_incognito_args to the |
86 // extensions in that profile that can't cross incognito. | 89 // extensions in that profile that can't cross incognito. |
87 void DispatchEventsToRenderersAcrossIncognito( | 90 void DispatchEventsToRenderersAcrossIncognito( |
88 const std::string& event_name, | 91 const std::string& event_name, |
89 const std::string& event_args, | 92 const std::string& event_args, |
90 Profile* restrict_to_profile, | 93 Profile* restrict_to_profile, |
91 const std::string& cross_incognito_args, | 94 const std::string& cross_incognito_args, |
92 const GURL& event_url); | 95 const GURL& event_url, |
96 bool user_caused = false); | |
93 | 97 |
94 // Record the Event Ack from the renderer. (One less event in-flight.) | 98 // Record the Event Ack from the renderer. (One less event in-flight.) |
95 void OnExtensionEventAck(const std::string& extension_id); | 99 void OnExtensionEventAck(const std::string& extension_id); |
96 | 100 |
97 // Check if there are any Extension Events that have not yet been acked by | 101 // Check if there are any Extension Events that have not yet been acked by |
98 // the renderer. | 102 // the renderer. |
99 bool HasInFlightEvents(const std::string& extension_id); | 103 bool HasInFlightEvents(const std::string& extension_id); |
100 | 104 |
101 protected: | 105 protected: |
102 // The details of an event to be dispatched. | 106 // The details of an event to be dispatched. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 148 |
145 // Track of the number of dispatched events that have not yet sent an | 149 // Track of the number of dispatched events that have not yet sent an |
146 // ACK from the renderer. | 150 // ACK from the renderer. |
147 void IncrementInFlightEvents(const Extension* extension); | 151 void IncrementInFlightEvents(const Extension* extension); |
148 std::map<std::string, int> in_flight_events_; | 152 std::map<std::string, int> in_flight_events_; |
149 | 153 |
150 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); | 154 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); |
151 }; | 155 }; |
152 | 156 |
153 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ | 157 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
OLD | NEW |