| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/values.h" |
| 16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 18 #include "ipc/ipc_sender.h" | 19 #include "ipc/ipc_sender.h" |
| 19 | 20 |
| 20 class GURL; | 21 class GURL; |
| 21 class ExtensionHost; | 22 class ExtensionHost; |
| 22 class ExtensionDevToolsManager; | 23 class ExtensionDevToolsManager; |
| 23 class Profile; | 24 class Profile; |
| 24 | 25 |
| 25 namespace content { | 26 namespace content { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 38 USER_GESTURE_UNKNOWN = 0, | 39 USER_GESTURE_UNKNOWN = 0, |
| 39 USER_GESTURE_ENABLED = 1, | 40 USER_GESTURE_ENABLED = 1, |
| 40 USER_GESTURE_NOT_ENABLED = 2, | 41 USER_GESTURE_NOT_ENABLED = 2, |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 // Sends an event via ipc_sender to the given extension. Can be called on | 44 // Sends an event via ipc_sender to the given extension. Can be called on |
| 44 // any thread. | 45 // any thread. |
| 45 static void DispatchEvent(IPC::Sender* ipc_sender, | 46 static void DispatchEvent(IPC::Sender* ipc_sender, |
| 46 const std::string& extension_id, | 47 const std::string& extension_id, |
| 47 const std::string& event_name, | 48 const std::string& event_name, |
| 49 const base::Value& event_args, |
| 50 const GURL& event_url, |
| 51 UserGestureState user_gesture); |
| 52 |
| 53 // This invocation is deprecated. All future consumers of this API should be |
| 54 // sending Values as event arguments, using the above version. |
| 55 static void DispatchEvent(IPC::Sender* ipc_sender, |
| 56 const std::string& extension_id, |
| 57 const std::string& event_name, |
| 48 const std::string& event_args, | 58 const std::string& event_args, |
| 49 const GURL& event_url, | 59 const GURL& event_url, |
| 50 UserGestureState user_gesture); | 60 UserGestureState user_gesture); |
| 51 | 61 |
| 52 explicit ExtensionEventRouter(Profile* profile); | 62 explicit ExtensionEventRouter(Profile* profile); |
| 53 virtual ~ExtensionEventRouter(); | 63 virtual ~ExtensionEventRouter(); |
| 54 | 64 |
| 55 // Add or remove the process/extension pair as a listener for |event_name|. | 65 // Add or remove the process/extension pair as a listener for |event_name|. |
| 56 // Note that multiple extensions can share a process due to process | 66 // Note that multiple extensions can share a process due to process |
| 57 // collapsing. Also, a single extension can have 2 processes if it is a split | 67 // collapsing. Also, a single extension can have 2 processes if it is a split |
| (...skipping 30 matching lines...) Expand all Loading... |
| 88 void DispatchEventToRenderers( | 98 void DispatchEventToRenderers( |
| 89 const std::string& event_name, | 99 const std::string& event_name, |
| 90 const std::string& event_args, | 100 const std::string& event_args, |
| 91 Profile* restrict_to_profile, | 101 Profile* restrict_to_profile, |
| 92 const GURL& event_url); | 102 const GURL& event_url); |
| 93 | 103 |
| 94 // Same as above, except only send the event to the given extension. | 104 // Same as above, except only send the event to the given extension. |
| 95 virtual void DispatchEventToExtension( | 105 virtual void DispatchEventToExtension( |
| 96 const std::string& extension_id, | 106 const std::string& extension_id, |
| 97 const std::string& event_name, | 107 const std::string& event_name, |
| 108 const base::Value& event_args, |
| 109 Profile* restrict_to_profile, |
| 110 const GURL& event_url); |
| 111 |
| 112 // This invocation is deprecated. The above variant which uses a Value for |
| 113 // event_args is to be used instead. |
| 114 virtual void DispatchEventToExtension( |
| 115 const std::string& extension_id, |
| 116 const std::string& event_name, |
| 98 const std::string& event_args, | 117 const std::string& event_args, |
| 99 Profile* restrict_to_profile, | 118 Profile* restrict_to_profile, |
| 100 const GURL& event_url); | 119 const GURL& event_url); |
| 101 | 120 |
| 102 // Dispatch an event to particular extension. Also include an | 121 // Dispatch an event to particular extension. Also include an |
| 103 // explicit user gesture indicator. | 122 // explicit user gesture indicator. |
| 104 virtual void DispatchEventToExtension( | 123 virtual void DispatchEventToExtension( |
| 105 const std::string& extension_id, | 124 const std::string& extension_id, |
| 106 const std::string& event_name, | 125 const std::string& event_name, |
| 107 const std::string& event_args, | 126 const std::string& event_args, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 const linked_ptr<ExtensionEvent>& event); | 180 const linked_ptr<ExtensionEvent>& event); |
| 162 | 181 |
| 163 // Returns false when the event is scoped to a profile and the listening | 182 // Returns false when the event is scoped to a profile and the listening |
| 164 // extension does not have access to events from that profile. Also fills | 183 // extension does not have access to events from that profile. Also fills |
| 165 // |event_args| with the proper arguments to send, which may differ if | 184 // |event_args| with the proper arguments to send, which may differ if |
| 166 // the event crosses the incognito boundary. | 185 // the event crosses the incognito boundary. |
| 167 bool CanDispatchEventToProfile( | 186 bool CanDispatchEventToProfile( |
| 168 Profile* profile, | 187 Profile* profile, |
| 169 const extensions::Extension* extension, | 188 const extensions::Extension* extension, |
| 170 const linked_ptr<ExtensionEvent>& event, | 189 const linked_ptr<ExtensionEvent>& event, |
| 171 const std::string** event_args); | 190 const base::Value** event_args); |
| 172 | 191 |
| 173 // Ensures that all lazy background pages that are interested in the given | 192 // Ensures that all lazy background pages that are interested in the given |
| 174 // event are loaded, and queues the event if the page is not ready yet. | 193 // event are loaded, and queues the event if the page is not ready yet. |
| 175 // If |extension_id| is non-empty, we load only that extension's page | 194 // If |extension_id| is non-empty, we load only that extension's page |
| 176 // (assuming it is interested in the event). | 195 // (assuming it is interested in the event). |
| 177 void LoadLazyBackgroundPagesForEvent( | 196 void LoadLazyBackgroundPagesForEvent( |
| 178 const std::string& extension_id, | 197 const std::string& extension_id, |
| 179 const linked_ptr<ExtensionEvent>& event); | 198 const linked_ptr<ExtensionEvent>& event); |
| 180 | 199 |
| 181 // Possibly loads given extension's background page in preparation to | 200 // Possibly loads given extension's background page in preparation to |
| (...skipping 22 matching lines...) Expand all Loading... |
| 204 | 223 |
| 205 // The list of all the lazy (non-persistent) background pages that are | 224 // The list of all the lazy (non-persistent) background pages that are |
| 206 // listening to events. This is just a cache of the real list, which is | 225 // listening to events. This is just a cache of the real list, which is |
| 207 // stored on disk in the extension prefs. | 226 // stored on disk in the extension prefs. |
| 208 ListenerMap lazy_listeners_; | 227 ListenerMap lazy_listeners_; |
| 209 | 228 |
| 210 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); | 229 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); |
| 211 }; | 230 }; |
| 212 | 231 |
| 213 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ | 232 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
| OLD | NEW |