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_BROWSER_EVENT_ROUTER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "chrome/browser/extensions/api/tabs/tabs.h" | 13 #include "chrome/browser/extensions/api/tabs/tabs.h" |
14 #include "chrome/browser/extensions/extension_toolbar_model.h" | 14 #include "chrome/browser/extensions/extension_toolbar_model.h" |
15 #include "chrome/browser/ui/browser_list_observer.h" | 15 #include "chrome/browser/ui/browser_list_observer.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
17 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
18 #if defined(TOOLKIT_VIEWS) | 18 #if defined(TOOLKIT_VIEWS) |
19 #include "ui/views/focus/widget_focus_manager.h" | 19 #include "ui/views/focus/widget_focus_manager.h" |
20 #elif defined(TOOLKIT_GTK) | 20 #elif defined(TOOLKIT_GTK) |
21 #include "ui/base/x/active_window_watcher_x_observer.h" | 21 #include "ui/base/x/active_window_watcher_x_observer.h" |
22 #endif | 22 #endif |
23 | 23 |
24 namespace content { | 24 namespace content { |
25 class WebContents; | 25 class WebContents; |
26 } | 26 } |
27 | 27 |
28 // The ExtensionBrowserEventRouter listens to Browser window & tab events | 28 namespace extensions { |
| 29 |
| 30 // The BrowserEventRouter listens to Browser window & tab events |
29 // and routes them to listeners inside extension process renderers. | 31 // and routes them to listeners inside extension process renderers. |
30 // ExtensionBrowserEventRouter listens to *all* events, but will only route | 32 // BrowserEventRouter listens to *all* events, but will only route |
31 // events from windows/tabs within a profile to extension processes in the same | 33 // events from windows/tabs within a profile to extension processes in the same |
32 // profile. | 34 // profile. |
33 class ExtensionBrowserEventRouter : public TabStripModelObserver, | 35 class BrowserEventRouter : public TabStripModelObserver, |
34 #if defined(TOOLKIT_VIEWS) | 36 #if defined(TOOLKIT_VIEWS) |
35 public views::WidgetFocusChangeListener, | 37 public views::WidgetFocusChangeListener, |
36 #elif defined(TOOLKIT_GTK) | 38 #elif defined(TOOLKIT_GTK) |
37 public ui::ActiveWindowWatcherXObserver, | 39 public ui::ActiveWindowWatcherXObserver, |
38 #endif | 40 #endif |
39 public chrome::BrowserListObserver, | 41 public chrome::BrowserListObserver, |
40 public content::NotificationObserver { | 42 public content::NotificationObserver { |
41 public: | 43 public: |
42 explicit ExtensionBrowserEventRouter(Profile* profile); | 44 explicit BrowserEventRouter(Profile* profile); |
43 virtual ~ExtensionBrowserEventRouter(); | 45 virtual ~BrowserEventRouter(); |
44 | 46 |
45 // Must be called once. Subsequent calls have no effect. | 47 // Must be called once. Subsequent calls have no effect. |
46 void Init(); | 48 void Init(); |
47 | 49 |
48 // chrome::BrowserListObserver | 50 // chrome::BrowserListObserver |
49 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; | 51 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; |
50 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | 52 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; |
51 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE; | 53 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE; |
52 | 54 |
53 #if defined(TOOLKIT_VIEWS) | 55 #if defined(TOOLKIT_VIEWS) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 const content::NotificationDetails& details) OVERRIDE; | 116 const content::NotificationDetails& details) OVERRIDE; |
115 private: | 117 private: |
116 // "Synthetic" event. Called from TabInsertedAt if new tab is detected. | 118 // "Synthetic" event. Called from TabInsertedAt if new tab is detected. |
117 void TabCreatedAt(content::WebContents* contents, int index, bool active); | 119 void TabCreatedAt(content::WebContents* contents, int index, bool active); |
118 | 120 |
119 // Internal processing of tab updated events. Is called by both TabChangedAt | 121 // Internal processing of tab updated events. Is called by both TabChangedAt |
120 // and Observe/NAV_ENTRY_COMMITTED. | 122 // and Observe/NAV_ENTRY_COMMITTED. |
121 void TabUpdated(content::WebContents* contents, bool did_navigate); | 123 void TabUpdated(content::WebContents* contents, bool did_navigate); |
122 | 124 |
123 // The DispatchEvent methods forward events to the |profile|'s event router. | 125 // The DispatchEvent methods forward events to the |profile|'s event router. |
124 // The ExtensionBrowserEventRouter listens to events for all profiles, | 126 // The BrowserEventRouter listens to events for all profiles, |
125 // so we avoid duplication by dropping events destined for other profiles. | 127 // so we avoid duplication by dropping events destined for other profiles. |
126 void DispatchEvent(Profile* profile, | 128 void DispatchEvent(Profile* profile, |
127 const char* event_name, | 129 const char* event_name, |
128 const std::string& json_args); | 130 const std::string& json_args); |
129 | 131 |
130 void DispatchEventToExtension(Profile* profile, | 132 void DispatchEventToExtension(Profile* profile, |
131 const std::string& extension_id, | 133 const std::string& extension_id, |
132 const char* event_name, | 134 const char* event_name, |
133 const std::string& json_args); | 135 const std::string& json_args); |
134 | 136 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 231 |
230 // The profile the currently focused window belongs to; either the main or | 232 // The profile the currently focused window belongs to; either the main or |
231 // incognito profile or NULL (none of the above). We remember this in order | 233 // incognito profile or NULL (none of the above). We remember this in order |
232 // to correctly handle focus changes between non-OTR and OTR windows. | 234 // to correctly handle focus changes between non-OTR and OTR windows. |
233 Profile* focused_profile_; | 235 Profile* focused_profile_; |
234 | 236 |
235 // The currently focused window. We keep this so as to avoid sending multiple | 237 // The currently focused window. We keep this so as to avoid sending multiple |
236 // windows.onFocusChanged events with the same windowId. | 238 // windows.onFocusChanged events with the same windowId. |
237 int focused_window_id_; | 239 int focused_window_id_; |
238 | 240 |
239 DISALLOW_COPY_AND_ASSIGN(ExtensionBrowserEventRouter); | 241 DISALLOW_COPY_AND_ASSIGN(BrowserEventRouter); |
240 }; | 242 }; |
241 | 243 |
242 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_EVENT_ROUTER_H_ | 244 } // namespace extensions |
| 245 |
| 246 #endif // CHROME_BROWSER_EXTENSIONS_BROWSER_EVENT_ROUTER_H_ |
OLD | NEW |