OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_ | 5 #ifndef CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_ |
6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_ | 6 #define CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "ash/shelf/scoped_observer_with_duplicated_sources.h" | 11 #include "ash/shelf/scoped_observer_with_duplicated_sources.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/scoped_observer.h" | 14 #include "base/scoped_observer.h" |
| 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
15 #include "chrome/browser/ui/browser_list_observer.h" | 16 #include "chrome/browser/ui/browser_list_observer.h" |
16 #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/web_contents_observer.h" |
17 #include "ui/aura/client/activation_change_observer.h" | 19 #include "ui/aura/client/activation_change_observer.h" |
18 #include "ui/aura/window_observer.h" | 20 #include "ui/aura/window_observer.h" |
19 #include "ui/gfx/display_observer.h" | 21 #include "ui/gfx/display_observer.h" |
20 | 22 |
21 namespace aura { | 23 namespace aura { |
22 class Window; | 24 class Window; |
23 | 25 |
24 namespace client { | 26 namespace client { |
25 class ActivationClient; | 27 class ActivationClient; |
26 } | 28 } |
27 } // namespace aura | 29 } // namespace aura |
28 | 30 |
29 class Browser; | 31 class Browser; |
30 class ChromeLauncherController; | |
31 | 32 |
32 // BrowserStatusMonitor monitors creation/deletion of Browser and its | 33 // BrowserStatusMonitor monitors creation/deletion of Browser and its |
33 // TabStripModel to keep the launcher representation up to date as the | 34 // TabStripModel to keep the launcher representation up to date as the |
34 // active tab changes. | 35 // active tab changes. |
35 class BrowserStatusMonitor : public aura::client::ActivationChangeObserver, | 36 class BrowserStatusMonitor : public aura::client::ActivationChangeObserver, |
36 public aura::WindowObserver, | 37 public aura::WindowObserver, |
37 public chrome::BrowserListObserver, | 38 public chrome::BrowserListObserver, |
38 public gfx::DisplayObserver, | 39 public gfx::DisplayObserver, |
39 public TabStripModelObserver { | 40 public TabStripModelObserver { |
40 public: | 41 public: |
41 explicit BrowserStatusMonitor(ChromeLauncherController* launcher_controller); | 42 explicit BrowserStatusMonitor(ChromeLauncherController* launcher_controller); |
42 virtual ~BrowserStatusMonitor(); | 43 virtual ~BrowserStatusMonitor(); |
43 | 44 |
| 45 // A shortcut to call the ChromeLauncherController's UpdateAppState(). |
| 46 void UpdateAppItemState(content::WebContents* contents, |
| 47 ChromeLauncherController::AppState app_state); |
| 48 |
| 49 // A shortcut to call the BrowserShortcutLauncherItemController's |
| 50 // UpdateBrowserItemState(). |
| 51 void UpdateBrowserItemState(); |
| 52 |
44 // aura::client::ActivationChangeObserver overrides: | 53 // aura::client::ActivationChangeObserver overrides: |
45 virtual void OnWindowActivated(aura::Window* gained_active, | 54 virtual void OnWindowActivated(aura::Window* gained_active, |
46 aura::Window* lost_active) OVERRIDE; | 55 aura::Window* lost_active) OVERRIDE; |
47 | 56 |
48 // aura::WindowObserver overrides: | 57 // aura::WindowObserver overrides: |
49 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; | 58 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; |
50 | 59 |
51 // chrome::BrowserListObserver overrides: | 60 // chrome::BrowserListObserver overrides: |
52 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; | 61 virtual void OnBrowserAdded(Browser* browser) OVERRIDE; |
53 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; | 62 virtual void OnBrowserRemoved(Browser* browser) OVERRIDE; |
54 | 63 |
55 // gfx::DisplayObserver overrides: | 64 // gfx::DisplayObserver overrides: |
56 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE; | 65 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE; |
57 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE; | 66 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE; |
58 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE; | 67 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE; |
59 | 68 |
60 // TabStripModelObserver overrides: | 69 // TabStripModelObserver overrides: |
61 virtual void ActiveTabChanged(content::WebContents* old_contents, | 70 virtual void ActiveTabChanged(content::WebContents* old_contents, |
62 content::WebContents* new_contents, | 71 content::WebContents* new_contents, |
63 int index, | 72 int index, |
64 int reason) OVERRIDE; | 73 int reason) OVERRIDE; |
65 virtual void TabInsertedAt(content::WebContents* contents, | |
66 int index, | |
67 bool foreground) OVERRIDE; | |
68 virtual void TabDetachedAt(content::WebContents* contents, | |
69 int index) OVERRIDE; | |
70 virtual void TabChangedAt( | |
71 content::WebContents* contents, | |
72 int index, | |
73 TabStripModelObserver::TabChangeType change_type) OVERRIDE; | |
74 virtual void TabReplacedAt(TabStripModel* tab_strip_model, | 74 virtual void TabReplacedAt(TabStripModel* tab_strip_model, |
75 content::WebContents* old_contents, | 75 content::WebContents* old_contents, |
76 content::WebContents* new_contents, | 76 content::WebContents* new_contents, |
77 int index) OVERRIDE; | 77 int index) OVERRIDE; |
| 78 virtual void TabInsertedAt(content::WebContents* contents, |
| 79 int index, |
| 80 bool foreground) OVERRIDE; |
| 81 virtual void TabClosingAt(TabStripModel* tab_strip_mode, |
| 82 content::WebContents* contents, |
| 83 int index) OVERRIDE; |
78 | 84 |
79 private: | 85 private: |
| 86 // This class monitors the WebContent of the all tab and notifies a navigation |
| 87 // to the BrowserStatusMonitor. |
| 88 class LocalWebContentsObserver : public content::WebContentsObserver { |
| 89 public: |
| 90 LocalWebContentsObserver(content::WebContents* contents, |
| 91 BrowserStatusMonitor* monitor); |
| 92 virtual ~LocalWebContentsObserver(); |
| 93 |
| 94 // content::WebContentsObserver overrides: |
| 95 virtual void DidNavigateMainFrame( |
| 96 const content::LoadCommittedDetails& details, |
| 97 const content::FrameNavigateParams& params) OVERRIDE; |
| 98 |
| 99 private: |
| 100 BrowserStatusMonitor* monitor_; |
| 101 |
| 102 DISALLOW_COPY_AND_ASSIGN(LocalWebContentsObserver); |
| 103 }; |
| 104 |
80 typedef std::map<Browser*, std::string> BrowserToAppIDMap; | 105 typedef std::map<Browser*, std::string> BrowserToAppIDMap; |
| 106 typedef std::map<content::WebContents*, LocalWebContentsObserver*> |
| 107 WebContentsToObserverMap; |
81 | 108 |
82 // Update app state for |contents| and browser state. | 109 // Create LocalWebContentsObserver for |contents|. |
83 void UpdateAppAndBrowserState(content::WebContents* contents); | 110 void AddWebContentsObserver(content::WebContents* contents); |
84 | 111 |
85 // A shortcut to call the BrowserShortcutLauncherItemController's | 112 // Remove LocalWebContentsObserver for |contents|. |
86 // UpdateBrowserItemState(). | 113 void RemoveWebContentsObserver(content::WebContents* contents); |
87 void UpdateBrowserItemState(); | |
88 | 114 |
89 ChromeLauncherController* launcher_controller_; | 115 ChromeLauncherController* launcher_controller_; |
90 | 116 |
91 // Hold all observed activation clients. | 117 // Hold all observed activation clients. |
92 ScopedObserverWithDuplicatedSources<aura::client::ActivationClient, | 118 ScopedObserverWithDuplicatedSources<aura::client::ActivationClient, |
93 aura::client::ActivationChangeObserver> observed_activation_clients_; | 119 aura::client::ActivationChangeObserver> observed_activation_clients_; |
94 | 120 |
95 // Hold all observed root windows. | 121 // Hold all observed root windows. |
96 ScopedObserver<aura::Window, aura::WindowObserver> observed_root_windows_; | 122 ScopedObserver<aura::Window, aura::WindowObserver> observed_root_windows_; |
97 | 123 |
98 BrowserToAppIDMap browser_to_app_id_map_; | 124 BrowserToAppIDMap browser_to_app_id_map_; |
99 | 125 |
| 126 WebContentsToObserverMap webcontents_to_observer_map_; |
| 127 |
100 DISALLOW_COPY_AND_ASSIGN(BrowserStatusMonitor); | 128 DISALLOW_COPY_AND_ASSIGN(BrowserStatusMonitor); |
101 }; | 129 }; |
102 | 130 |
103 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_ | 131 #endif // CHROME_BROWSER_UI_ASH_LAUNCHER_BROWSER_STATUS_MONITOR_H_ |
OLD | NEW |