Chromium Code Reviews

Side by Side Diff: chrome/browser/extensions/extension_browser_event_router.h

Issue 6125003: Make ExtensionBrowserEventRouter owned by ExtensionService.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/singleton.h"
14 #include "chrome/browser/browser_list.h" 13 #include "chrome/browser/browser_list.h"
15 #include "chrome/browser/extensions/extension_tabs_module.h" 14 #include "chrome/browser/extensions/extension_tabs_module.h"
16 #include "chrome/browser/tabs/tab_strip_model_observer.h" 15 #include "chrome/browser/tabs/tab_strip_model_observer.h"
17 #include "chrome/common/notification_registrar.h" 16 #include "chrome/common/notification_registrar.h"
18 #if defined(TOOLKIT_VIEWS) 17 #if defined(TOOLKIT_VIEWS)
19 #include "views/view.h" 18 #include "views/view.h"
20 #include "views/focus/focus_manager.h" 19 #include "views/focus/focus_manager.h"
21 #elif defined(TOOLKIT_GTK) 20 #elif defined(TOOLKIT_GTK)
22 #include "app/active_window_watcher_x.h" 21 #include "app/active_window_watcher_x.h"
23 #endif 22 #endif
24 23
25 // The ExtensionBrowserEventRouter listens to Browser window & tab events 24 // The ExtensionBrowserEventRouter listens to Browser window & tab events
26 // and routes them to listeners inside extension process renderers. 25 // and routes them to listeners inside extension process renderers.
27 // ExtensionBrowserEventRouter listens to *all* events, but will only route 26 // ExtensionBrowserEventRouter listens to *all* events, but will only route
28 // events from windows/tabs within a profile to extension processes in the same 27 // events from windows/tabs within a profile to extension processes in the same
29 // profile. 28 // profile.
30 class ExtensionBrowserEventRouter : public TabStripModelObserver, 29 class ExtensionBrowserEventRouter : public TabStripModelObserver,
31 #if defined(TOOLKIT_VIEWS) 30 #if defined(TOOLKIT_VIEWS)
32 public views::WidgetFocusChangeListener, 31 public views::WidgetFocusChangeListener,
33 #elif defined(TOOLKIT_GTK) 32 #elif defined(TOOLKIT_GTK)
34 public ActiveWindowWatcherX::Observer, 33 public ActiveWindowWatcherX::Observer,
35 #endif 34 #endif
36 public BrowserList::Observer, 35 public BrowserList::Observer,
37 public NotificationObserver { 36 public NotificationObserver {
38 public: 37 public:
39 // Get Browser-Global instance. 38 explicit ExtensionBrowserEventRouter(Profile* profile);
40 static ExtensionBrowserEventRouter* GetInstance(); 39 ~ExtensionBrowserEventRouter();
41 40
42 // Must be called once. Subsequent calls have no effect. 41 // Must be called once. Subsequent calls have no effect.
43 void Init(Profile* profile); 42 void Init();
44 43
45 // BrowserList::Observer 44 // BrowserList::Observer
46 virtual void OnBrowserAdded(const Browser* browser); 45 virtual void OnBrowserAdded(const Browser* browser);
47 virtual void OnBrowserRemoved(const Browser* browser); 46 virtual void OnBrowserRemoved(const Browser* browser);
48 virtual void OnBrowserSetLastActive(const Browser* browser); 47 virtual void OnBrowserSetLastActive(const Browser* browser);
49 48
50 #if defined(TOOLKIT_VIEWS) 49 #if defined(TOOLKIT_VIEWS)
51 virtual void NativeFocusWillChange(gfx::NativeView focused_before, 50 virtual void NativeFocusWillChange(gfx::NativeView focused_before,
52 gfx::NativeView focused_now); 51 gfx::NativeView focused_now);
53 #elif defined(TOOLKIT_GTK) 52 #elif defined(TOOLKIT_GTK)
(...skipping 68 matching lines...)
122 // in for a browser. 121 // in for a browser.
123 void RegisterForBrowserNotifications(const Browser* browser); 122 void RegisterForBrowserNotifications(const Browser* browser);
124 123
125 // Register ourselves to receive the various notifications we are interested 124 // Register ourselves to receive the various notifications we are interested
126 // in for a tab. 125 // in for a tab.
127 void RegisterForTabNotifications(TabContents* contents); 126 void RegisterForTabNotifications(TabContents* contents);
128 127
129 // Removes notifications added in RegisterForTabNotifications. 128 // Removes notifications added in RegisterForTabNotifications.
130 void UnregisterForTabNotifications(TabContents* contents); 129 void UnregisterForTabNotifications(TabContents* contents);
131 130
132 ExtensionBrowserEventRouter();
133 ~ExtensionBrowserEventRouter();
134 friend struct DefaultSingletonTraits<ExtensionBrowserEventRouter>;
135
136 NotificationRegistrar registrar_; 131 NotificationRegistrar registrar_;
137 132
138 bool initialized_; 133 bool initialized_;
139 134
140 // Maintain some information about known tabs, so we can: 135 // Maintain some information about known tabs, so we can:
141 // 136 //
142 // - distinguish between tab creation and tab insertion 137 // - distinguish between tab creation and tab insertion
143 // - not send tab-detached after tab-removed 138 // - not send tab-detached after tab-removed
144 // - reduce the "noise" of TabChangedAt() when sending events to extensions 139 // - reduce the "noise" of TabChangedAt() when sending events to extensions
145 class TabEntry { 140 class TabEntry {
(...skipping 37 matching lines...)
183 int focused_window_id_; 178 int focused_window_id_;
184 179
185 // The main profile (non-OTR) profile which will be used to send events not 180 // The main profile (non-OTR) profile which will be used to send events not
186 // associated with any browser. 181 // associated with any browser.
187 Profile* profile_; 182 Profile* profile_;
188 183
189 DISALLOW_COPY_AND_ASSIGN(ExtensionBrowserEventRouter); 184 DISALLOW_COPY_AND_ASSIGN(ExtensionBrowserEventRouter);
190 }; 185 };
191 186
192 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_EVENT_ROUTER_H_ 187 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_EVENT_ROUTER_H_
OLDNEW

Powered by Google App Engine