| 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> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "chrome/browser/extensions/api/tabs/tabs.h" | 14 #include "chrome/browser/extensions/api/tabs/tabs.h" |
| 15 #include "chrome/browser/extensions/extension_toolbar_model.h" | 15 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list_observer.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 19 #if defined(TOOLKIT_VIEWS) | 19 #if defined(TOOLKIT_VIEWS) |
| 20 #include "ui/views/focus/widget_focus_manager.h" | 20 #include "ui/views/focus/widget_focus_manager.h" |
| 21 #elif defined(TOOLKIT_GTK) | 21 #elif defined(TOOLKIT_GTK) |
| 22 #include "ui/base/x/active_window_watcher_x_observer.h" | 22 #include "ui/base/x/active_window_watcher_x_observer.h" |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 class WebContents; | 26 class WebContents; |
| 27 } | 27 } |
| 28 | 28 |
| 29 // The ExtensionBrowserEventRouter listens to Browser window & tab events | 29 // The ExtensionBrowserEventRouter listens to Browser window & tab events |
| 30 // and routes them to listeners inside extension process renderers. | 30 // and routes them to listeners inside extension process renderers. |
| 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 chrome::BrowserListObserver, |
| 41 public content::NotificationObserver { | 41 public content::NotificationObserver { |
| 42 public: | 42 public: |
| 43 explicit ExtensionBrowserEventRouter(Profile* profile); | 43 explicit ExtensionBrowserEventRouter(Profile* profile); |
| 44 virtual ~ExtensionBrowserEventRouter(); | 44 virtual ~ExtensionBrowserEventRouter(); |
| 45 | 45 |
| 46 // Must be called once. Subsequent calls have no effect. | 46 // Must be called once. Subsequent calls have no effect. |
| 47 void Init(); | 47 void Init(); |
| 48 | 48 |
| 49 // BrowserList::Observer | 49 // chrome::BrowserListObserver |
| 50 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; | 50 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; |
| 51 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | 51 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; |
| 52 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE; | 52 virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE; |
| 53 | 53 |
| 54 #if defined(TOOLKIT_VIEWS) | 54 #if defined(TOOLKIT_VIEWS) |
| 55 virtual void OnNativeFocusChange(gfx::NativeView focused_before, | 55 virtual void OnNativeFocusChange(gfx::NativeView focused_before, |
| 56 gfx::NativeView focused_now) OVERRIDE; | 56 gfx::NativeView focused_now) OVERRIDE; |
| 57 #elif defined(TOOLKIT_GTK) | 57 #elif defined(TOOLKIT_GTK) |
| 58 virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE; | 58 virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE; |
| 59 #endif | 59 #endif |
| 60 | 60 |
| 61 // Called from Observe() on BROWSER_WINDOW_READY (not a part of | 61 // Called from Observe() on BROWSER_WINDOW_READY (not a part of |
| 62 // BrowserList::Observer). | 62 // chrome::BrowserListObserver). |
| 63 void OnBrowserWindowReady(Browser* browser); | 63 void OnBrowserWindowReady(Browser* browser); |
| 64 | 64 |
| 65 // TabStripModelObserver | 65 // TabStripModelObserver |
| 66 virtual void TabInsertedAt(TabContents* contents, int index, | 66 virtual void TabInsertedAt(TabContents* contents, int index, |
| 67 bool active) OVERRIDE; | 67 bool active) OVERRIDE; |
| 68 virtual void TabClosingAt(TabStripModel* tab_strip_model, | 68 virtual void TabClosingAt(TabStripModel* tab_strip_model, |
| 69 TabContents* contents, | 69 TabContents* contents, |
| 70 int index) OVERRIDE; | 70 int index) OVERRIDE; |
| 71 virtual void TabDetachedAt(TabContents* contents, int index) OVERRIDE; | 71 virtual void TabDetachedAt(TabContents* contents, int index) OVERRIDE; |
| 72 virtual void ActiveTabChanged(TabContents* old_contents, | 72 virtual void ActiveTabChanged(TabContents* old_contents, |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 Profile* focused_profile_; | 234 Profile* focused_profile_; |
| 235 | 235 |
| 236 // The currently focused window. We keep this so as to avoid sending multiple | 236 // The currently focused window. We keep this so as to avoid sending multiple |
| 237 // windows.onFocusChanged events with the same windowId. | 237 // windows.onFocusChanged events with the same windowId. |
| 238 int focused_window_id_; | 238 int focused_window_id_; |
| 239 | 239 |
| 240 DISALLOW_COPY_AND_ASSIGN(ExtensionBrowserEventRouter); | 240 DISALLOW_COPY_AND_ASSIGN(ExtensionBrowserEventRouter); |
| 241 }; | 241 }; |
| 242 | 242 |
| 243 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_EVENT_ROUTER_H_ | 243 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_BROWSER_EVENT_ROUTER_H_ |
| OLD | NEW |