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 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" | 5 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/wm/window_util.h" | 8 #include "ash/wm/window_util.h" |
| 9 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll
er.h" |
9 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
12 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
13 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/browser/web_applications/web_app.h" | 16 #include "chrome/browser/web_applications/web_app.h" |
16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_contents_view.h" | 18 #include "content/public/browser/web_contents_view.h" |
18 #include "ui/aura/client/activation_client.h" | 19 #include "ui/aura/client/activation_client.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 65 |
65 void BrowserStatusMonitor::OnWindowActivated(aura::Window* gained_active, | 66 void BrowserStatusMonitor::OnWindowActivated(aura::Window* gained_active, |
66 aura::Window* lost_active) { | 67 aura::Window* lost_active) { |
67 Browser* browser = chrome::FindBrowserWithWindow(lost_active); | 68 Browser* browser = chrome::FindBrowserWithWindow(lost_active); |
68 content::WebContents* active_contents = NULL; | 69 content::WebContents* active_contents = NULL; |
69 | 70 |
70 if (browser) { | 71 if (browser) { |
71 active_contents = browser->tab_strip_model()->GetActiveWebContents(); | 72 active_contents = browser->tab_strip_model()->GetActiveWebContents(); |
72 if (active_contents) | 73 if (active_contents) |
73 UpdateAppState(active_contents); | 74 UpdateAppState(active_contents); |
| 75 UpdateBrowserItemStatus(); |
74 } | 76 } |
75 | 77 |
76 browser = chrome::FindBrowserWithWindow(gained_active); | 78 browser = chrome::FindBrowserWithWindow(gained_active); |
77 if (browser) { | 79 if (browser) { |
78 active_contents = browser->tab_strip_model()->GetActiveWebContents(); | 80 active_contents = browser->tab_strip_model()->GetActiveWebContents(); |
79 if (active_contents) | 81 if (active_contents) |
80 UpdateAppState(active_contents); | 82 UpdateAppState(active_contents); |
| 83 UpdateBrowserItemStatus(); |
81 } | 84 } |
82 } | 85 } |
83 | 86 |
84 void BrowserStatusMonitor::OnWindowDestroyed(aura::Window* window) { | 87 void BrowserStatusMonitor::OnWindowDestroyed(aura::Window* window) { |
85 // Remove RootWindow and its ActivationClient from observed list. | 88 // Remove RootWindow and its ActivationClient from observed list. |
86 observed_root_windows_.Remove(window); | 89 observed_root_windows_.Remove(window); |
87 observed_activation_clients_.Remove(aura::client::GetActivationClient( | 90 observed_activation_clients_.Remove(aura::client::GetActivationClient( |
88 static_cast<aura::RootWindow*>(window))); | 91 static_cast<aura::RootWindow*>(window))); |
89 } | 92 } |
90 | 93 |
(...skipping 10 matching lines...) Expand all Loading... |
101 } | 104 } |
102 } | 105 } |
103 | 106 |
104 void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) { | 107 void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) { |
105 browser->tab_strip_model()->RemoveObserver(this); | 108 browser->tab_strip_model()->RemoveObserver(this); |
106 | 109 |
107 if (browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end()) { | 110 if (browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end()) { |
108 launcher_controller_->UnlockV1AppWithID(browser_to_app_id_map_[browser]); | 111 launcher_controller_->UnlockV1AppWithID(browser_to_app_id_map_[browser]); |
109 browser_to_app_id_map_.erase(browser); | 112 browser_to_app_id_map_.erase(browser); |
110 } | 113 } |
111 launcher_controller_->UpdateBrowserItemStatus(); | 114 UpdateBrowserItemStatus(); |
112 } | 115 } |
113 | 116 |
114 void BrowserStatusMonitor::OnDisplayBoundsChanged( | 117 void BrowserStatusMonitor::OnDisplayBoundsChanged( |
115 const gfx::Display& display) { | 118 const gfx::Display& display) { |
116 // Do nothing here. | 119 // Do nothing here. |
117 } | 120 } |
118 | 121 |
119 void BrowserStatusMonitor::OnDisplayAdded(const gfx::Display& new_display) { | 122 void BrowserStatusMonitor::OnDisplayAdded(const gfx::Display& new_display) { |
120 // Add a new RootWindow and its ActivationClient to observed list. | 123 // Add a new RootWindow and its ActivationClient to observed list. |
121 aura::RootWindow* root_window = ash::Shell::GetInstance()-> | 124 aura::RootWindow* root_window = ash::Shell::GetInstance()-> |
(...skipping 22 matching lines...) Expand all Loading... |
144 if (old_contents) | 147 if (old_contents) |
145 browser = chrome::FindBrowserWithWebContents(old_contents); | 148 browser = chrome::FindBrowserWithWebContents(old_contents); |
146 | 149 |
147 // Update immediately on a tab change. | 150 // Update immediately on a tab change. |
148 if (browser && | 151 if (browser && |
149 (TabStripModel::kNoTab != | 152 (TabStripModel::kNoTab != |
150 browser->tab_strip_model()->GetIndexOfWebContents(old_contents))) | 153 browser->tab_strip_model()->GetIndexOfWebContents(old_contents))) |
151 UpdateAppState(old_contents); | 154 UpdateAppState(old_contents); |
152 | 155 |
153 UpdateAppState(new_contents); | 156 UpdateAppState(new_contents); |
| 157 UpdateBrowserItemStatus(); |
154 } | 158 } |
155 | 159 |
156 void BrowserStatusMonitor::TabInsertedAt(content::WebContents* contents, | 160 void BrowserStatusMonitor::TabInsertedAt(content::WebContents* contents, |
157 int index, | 161 int index, |
158 bool foreground) { | 162 bool foreground) { |
159 UpdateAppState(contents); | 163 UpdateAppState(contents); |
| 164 UpdateBrowserItemStatus(); |
160 } | 165 } |
161 | 166 |
162 void BrowserStatusMonitor::TabDetachedAt(content::WebContents* contents, | 167 void BrowserStatusMonitor::TabDetachedAt(content::WebContents* contents, |
163 int index) { | 168 int index) { |
164 launcher_controller_->UpdateAppState( | 169 launcher_controller_->UpdateAppState( |
165 contents, ChromeLauncherController::APP_STATE_REMOVED); | 170 contents, ChromeLauncherController::APP_STATE_REMOVED); |
| 171 UpdateBrowserItemStatus(); |
166 } | 172 } |
167 | 173 |
168 void BrowserStatusMonitor::TabChangedAt( | 174 void BrowserStatusMonitor::TabChangedAt( |
169 content::WebContents* contents, | 175 content::WebContents* contents, |
170 int index, | 176 int index, |
171 TabStripModelObserver::TabChangeType change_type) { | 177 TabStripModelObserver::TabChangeType change_type) { |
172 UpdateAppState(contents); | 178 UpdateAppState(contents); |
| 179 UpdateBrowserItemStatus(); |
173 } | 180 } |
174 | 181 |
175 void BrowserStatusMonitor::TabReplacedAt(TabStripModel* tab_strip_model, | 182 void BrowserStatusMonitor::TabReplacedAt(TabStripModel* tab_strip_model, |
176 content::WebContents* old_contents, | 183 content::WebContents* old_contents, |
177 content::WebContents* new_contents, | 184 content::WebContents* new_contents, |
178 int index) { | 185 int index) { |
179 launcher_controller_->UpdateAppState( | 186 launcher_controller_->UpdateAppState( |
180 old_contents, | 187 old_contents, |
181 ChromeLauncherController::APP_STATE_REMOVED); | 188 ChromeLauncherController::APP_STATE_REMOVED); |
182 UpdateAppState(new_contents); | 189 UpdateAppState(new_contents); |
| 190 UpdateBrowserItemStatus(); |
183 } | 191 } |
184 | 192 |
185 void BrowserStatusMonitor::UpdateAppState(content::WebContents* contents) { | 193 void BrowserStatusMonitor::UpdateAppState(content::WebContents* contents) { |
186 if (!contents) | 194 if (!contents) |
187 return; | 195 return; |
188 | 196 |
189 ChromeLauncherController::AppState app_state = | 197 ChromeLauncherController::AppState app_state = |
190 ChromeLauncherController::APP_STATE_INACTIVE; | 198 ChromeLauncherController::APP_STATE_INACTIVE; |
191 | 199 |
192 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 200 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
193 if (browser->tab_strip_model()->GetActiveWebContents() == contents) { | 201 if (browser->tab_strip_model()->GetActiveWebContents() == contents) { |
194 if (browser->window()->IsActive()) | 202 if (browser->window()->IsActive()) |
195 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; | 203 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; |
196 else | 204 else |
197 app_state = ChromeLauncherController::APP_STATE_ACTIVE; | 205 app_state = ChromeLauncherController::APP_STATE_ACTIVE; |
198 } | 206 } |
199 | 207 |
200 launcher_controller_->UpdateAppState(contents, app_state); | 208 launcher_controller_->UpdateAppState(contents, app_state); |
201 } | 209 } |
| 210 |
| 211 void BrowserStatusMonitor::UpdateBrowserItemStatus() { |
| 212 launcher_controller_->GetBrowserShortcutLauncherItemController()-> |
| 213 UpdateBrowserItemStatus(); |
| 214 } |
OLD | NEW |