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 "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
18 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_sender.h" |
19 | 19 |
20 class GURL; | 20 class GURL; |
21 class ExtensionHost; | 21 class ExtensionHost; |
22 class ExtensionDevToolsManager; | 22 class ExtensionDevToolsManager; |
23 class Profile; | 23 class Profile; |
24 | 24 |
25 namespace content { | 25 namespace content { |
26 class RenderProcessHost; | 26 class RenderProcessHost; |
27 } | 27 } |
28 | 28 |
29 namespace extensions { | 29 namespace extensions { |
30 class Extension; | 30 class Extension; |
31 } | 31 } |
32 | 32 |
33 class ExtensionEventRouter : public content::NotificationObserver { | 33 class ExtensionEventRouter : public content::NotificationObserver { |
34 public: | 34 public: |
35 // These constants convey the state of our knowledge of whether we're in | 35 // These constants convey the state of our knowledge of whether we're in |
36 // a user-caused gesture as part of DispatchEvent. | 36 // a user-caused gesture as part of DispatchEvent. |
37 enum UserGestureState { | 37 enum UserGestureState { |
38 USER_GESTURE_UNKNOWN = 0, | 38 USER_GESTURE_UNKNOWN = 0, |
39 USER_GESTURE_ENABLED = 1, | 39 USER_GESTURE_ENABLED = 1, |
40 USER_GESTURE_NOT_ENABLED = 2, | 40 USER_GESTURE_NOT_ENABLED = 2, |
41 }; | 41 }; |
42 | 42 |
43 // Sends an event via ipc_sender to the given extension. Can be called on | 43 // Sends an event via ipc_sender to the given extension. Can be called on |
44 // any thread. | 44 // any thread. |
45 static void DispatchEvent(IPC::Message::Sender* ipc_sender, | 45 static void DispatchEvent(IPC::Sender* ipc_sender, |
46 const std::string& extension_id, | 46 const std::string& extension_id, |
47 const std::string& event_name, | 47 const std::string& event_name, |
48 const std::string& event_args, | 48 const std::string& event_args, |
49 const GURL& event_url, | 49 const GURL& event_url, |
50 UserGestureState user_gesture); | 50 UserGestureState user_gesture); |
51 | 51 |
52 explicit ExtensionEventRouter(Profile* profile); | 52 explicit ExtensionEventRouter(Profile* profile); |
53 virtual ~ExtensionEventRouter(); | 53 virtual ~ExtensionEventRouter(); |
54 | 54 |
55 // Add or remove the process/extension pair as a listener for |event_name|. | 55 // Add or remove the process/extension pair as a listener for |event_name|. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 // The list of all the lazy (non-persistent) background pages that are | 205 // 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 | 206 // listening to events. This is just a cache of the real list, which is |
207 // stored on disk in the extension prefs. | 207 // stored on disk in the extension prefs. |
208 ListenerMap lazy_listeners_; | 208 ListenerMap lazy_listeners_; |
209 | 209 |
210 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); | 210 DISALLOW_COPY_AND_ASSIGN(ExtensionEventRouter); |
211 }; | 211 }; |
212 | 212 |
213 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ | 213 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_EVENT_ROUTER_H_ |
OLD | NEW |