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_EXTENSION_BROWSER_EVENT_ROUTER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_EVENT_ROUTER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_EVENT_ROUTER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 20 matching lines...) Expand all Loading... |
31 // ExtensionBrowserEventRouter listens to *all* events, but will only route | 31 // ExtensionBrowserEventRouter listens to *all* events, but will only route |
32 // events from windows/tabs within a profile to extension processes in the same | 32 // events from windows/tabs within a profile to extension processes in the same |
33 // profile. | 33 // profile. |
34 class ExtensionBrowserEventRouter : public TabStripModelObserver, | 34 class ExtensionBrowserEventRouter : public TabStripModelObserver, |
35 #if defined(TOOLKIT_VIEWS) | 35 #if defined(TOOLKIT_VIEWS) |
36 public views::WidgetFocusChangeListener, | 36 public views::WidgetFocusChangeListener, |
37 #elif defined(TOOLKIT_GTK) | 37 #elif defined(TOOLKIT_GTK) |
38 public ui::ActiveWindowWatcherXObserver, | 38 public ui::ActiveWindowWatcherXObserver, |
39 #endif | 39 #endif |
40 public BrowserList::Observer, | 40 public BrowserList::Observer, |
41 public ExtensionToolbarModel::Observer, | |
42 public content::NotificationObserver { | 41 public content::NotificationObserver { |
43 public: | 42 public: |
44 explicit ExtensionBrowserEventRouter(Profile* profile); | 43 explicit ExtensionBrowserEventRouter(Profile* profile); |
45 virtual ~ExtensionBrowserEventRouter(); | 44 virtual ~ExtensionBrowserEventRouter(); |
46 | 45 |
47 // Must be called once. Subsequent calls have no effect. | 46 // Must be called once. Subsequent calls have no effect. |
48 void Init(ExtensionToolbarModel* model); | 47 void Init(); |
49 | 48 |
50 // BrowserList::Observer | 49 // BrowserList::Observer |
51 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; | 50 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; |
52 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | 51 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; |
53 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE; | 52 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE; |
54 | 53 |
55 #if defined(TOOLKIT_VIEWS) | 54 #if defined(TOOLKIT_VIEWS) |
56 virtual void OnNativeFocusChange(gfx::NativeView focused_before, | 55 virtual void OnNativeFocusChange(gfx::NativeView focused_before, |
57 gfx::NativeView focused_now) OVERRIDE; | 56 gfx::NativeView focused_now) OVERRIDE; |
58 #elif defined(TOOLKIT_GTK) | 57 #elif defined(TOOLKIT_GTK) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 virtual void TabStripEmpty() OVERRIDE; | 89 virtual void TabStripEmpty() OVERRIDE; |
91 | 90 |
92 // Page Action execute event. | 91 // Page Action execute event. |
93 void PageActionExecuted(Profile* profile, | 92 void PageActionExecuted(Profile* profile, |
94 const std::string& extension_id, | 93 const std::string& extension_id, |
95 const std::string& page_action_id, | 94 const std::string& page_action_id, |
96 int tab_id, | 95 int tab_id, |
97 const std::string& url, | 96 const std::string& url, |
98 int button); | 97 int button); |
99 | 98 |
| 99 // Browser Action execute event. |
| 100 void BrowserActionExecuted(const std::string& extension_id, Browser* browser); |
| 101 |
100 // A keyboard shortcut resulted in an extension command. | 102 // A keyboard shortcut resulted in an extension command. |
101 void CommandExecuted(Profile* profile, | 103 void CommandExecuted(Profile* profile, |
102 const std::string& extension_id, | 104 const std::string& extension_id, |
103 const std::string& command); | 105 const std::string& command); |
104 | 106 |
105 // content::NotificationObserver. | 107 // content::NotificationObserver. |
106 virtual void Observe(int type, | 108 virtual void Observe(int type, |
107 const content::NotificationSource& source, | 109 const content::NotificationSource& source, |
108 const content::NotificationDetails& details) OVERRIDE; | 110 const content::NotificationDetails& details) OVERRIDE; |
109 private: | 111 private: |
110 // "Synthetic" event. Called from TabInsertedAt if new tab is detected. | 112 // "Synthetic" event. Called from TabInsertedAt if new tab is detected. |
111 void TabCreatedAt(content::WebContents* contents, int index, bool active); | 113 void TabCreatedAt(content::WebContents* contents, int index, bool active); |
112 | 114 |
113 // Internal processing of tab updated events. Is called by both TabChangedAt | 115 // Internal processing of tab updated events. Is called by both TabChangedAt |
114 // and Observe/NAV_ENTRY_COMMITTED. | 116 // and Observe/NAV_ENTRY_COMMITTED. |
115 void TabUpdated(content::WebContents* contents, bool did_navigate); | 117 void TabUpdated(content::WebContents* contents, bool did_navigate); |
116 | 118 |
117 // ExtensionToolbarModel::Observer. Browser Actions execute event. | |
118 virtual void BrowserActionExecuted(const std::string& extension_id, | |
119 Browser* browser) OVERRIDE; | |
120 | |
121 // The DispatchEvent methods forward events to the |profile|'s event router. | 119 // The DispatchEvent methods forward events to the |profile|'s event router. |
122 // The ExtensionBrowserEventRouter listens to events for all profiles, | 120 // The ExtensionBrowserEventRouter listens to events for all profiles, |
123 // so we avoid duplication by dropping events destined for other profiles. | 121 // so we avoid duplication by dropping events destined for other profiles. |
124 void DispatchEvent(Profile* profile, | 122 void DispatchEvent(Profile* profile, |
125 const char* event_name, | 123 const char* event_name, |
126 const std::string& json_args); | 124 const std::string& json_args); |
127 | 125 |
128 void DispatchEventToExtension(Profile* profile, | 126 void DispatchEventToExtension(Profile* profile, |
129 const std::string& extension_id, | 127 const std::string& extension_id, |
130 const char* event_name, | 128 const char* event_name, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 Profile* focused_profile_; | 229 Profile* focused_profile_; |
232 | 230 |
233 // The currently focused window. We keep this so as to avoid sending multiple | 231 // The currently focused window. We keep this so as to avoid sending multiple |
234 // windows.onFocusChanged events with the same windowId. | 232 // windows.onFocusChanged events with the same windowId. |
235 int focused_window_id_; | 233 int focused_window_id_; |
236 | 234 |
237 DISALLOW_COPY_AND_ASSIGN(ExtensionBrowserEventRouter); | 235 DISALLOW_COPY_AND_ASSIGN(ExtensionBrowserEventRouter); |
238 }; | 236 }; |
239 | 237 |
240 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_EVENT_ROUTER_H_ | 238 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_EVENT_ROUTER_H_ |
OLD | NEW |