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/shelf/shelf_util.h" | 7 #include "ash/shelf/shelf_util.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 ChromeLauncherController::APP_STATE_INACTIVE; | 40 ChromeLauncherController::APP_STATE_INACTIVE; |
41 if (browser->window()->IsActive() && | 41 if (browser->window()->IsActive() && |
42 browser->tab_strip_model()->GetActiveWebContents() == web_contents()) | 42 browser->tab_strip_model()->GetActiveWebContents() == web_contents()) |
43 state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; | 43 state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; |
44 else if (browser->window()->IsActive()) | 44 else if (browser->window()->IsActive()) |
45 state = ChromeLauncherController::APP_STATE_ACTIVE; | 45 state = ChromeLauncherController::APP_STATE_ACTIVE; |
46 | 46 |
47 monitor_->UpdateAppItemState(web_contents(), state); | 47 monitor_->UpdateAppItemState(web_contents(), state); |
48 monitor_->UpdateBrowserItemState(); | 48 monitor_->UpdateBrowserItemState(); |
49 | 49 |
50 // Navigating may change the LauncherID associated with the WebContents. | 50 // Navigating may change the ShelfID associated with the WebContents. |
51 if (browser->tab_strip_model()->GetActiveWebContents() == web_contents()) { | 51 if (browser->tab_strip_model()->GetActiveWebContents() == web_contents()) { |
52 ash::SetLauncherIDForWindow( | 52 ash::SetShelfIDForWindow( |
53 monitor_->GetLauncherIDForWebContents(web_contents()), | 53 monitor_->GetShelfIDForWebContents(web_contents()), |
54 browser->window()->GetNativeWindow()); | 54 browser->window()->GetNativeWindow()); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 BrowserStatusMonitor::BrowserStatusMonitor( | 58 BrowserStatusMonitor::BrowserStatusMonitor( |
59 ChromeLauncherController* launcher_controller) | 59 ChromeLauncherController* launcher_controller) |
60 : launcher_controller_(launcher_controller), | 60 : launcher_controller_(launcher_controller), |
61 observed_activation_clients_(this), | 61 observed_activation_clients_(this), |
62 observed_root_windows_(this) { | 62 observed_root_windows_(this) { |
63 DCHECK(launcher_controller_); | 63 DCHECK(launcher_controller_); |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 (TabStripModel::kNoTab != | 228 (TabStripModel::kNoTab != |
229 browser->tab_strip_model()->GetIndexOfWebContents(old_contents))) | 229 browser->tab_strip_model()->GetIndexOfWebContents(old_contents))) |
230 UpdateAppItemState(old_contents, state); | 230 UpdateAppItemState(old_contents, state); |
231 | 231 |
232 if (new_contents) { | 232 if (new_contents) { |
233 state = browser->window()->IsActive() ? | 233 state = browser->window()->IsActive() ? |
234 ChromeLauncherController::APP_STATE_WINDOW_ACTIVE : | 234 ChromeLauncherController::APP_STATE_WINDOW_ACTIVE : |
235 ChromeLauncherController::APP_STATE_ACTIVE; | 235 ChromeLauncherController::APP_STATE_ACTIVE; |
236 UpdateAppItemState(new_contents, state); | 236 UpdateAppItemState(new_contents, state); |
237 UpdateBrowserItemState(); | 237 UpdateBrowserItemState(); |
238 ash::SetLauncherIDForWindow( | 238 ash::SetShelfIDForWindow(GetShelfIDForWebContents(new_contents), |
239 GetLauncherIDForWebContents(new_contents), | 239 browser->window()->GetNativeWindow()); |
240 browser->window()->GetNativeWindow()); | |
241 } | 240 } |
242 } | 241 } |
243 | 242 |
244 void BrowserStatusMonitor::TabReplacedAt(TabStripModel* tab_strip_model, | 243 void BrowserStatusMonitor::TabReplacedAt(TabStripModel* tab_strip_model, |
245 content::WebContents* old_contents, | 244 content::WebContents* old_contents, |
246 content::WebContents* new_contents, | 245 content::WebContents* new_contents, |
247 int index) { | 246 int index) { |
248 DCHECK(old_contents && new_contents); | 247 DCHECK(old_contents && new_contents); |
249 Browser* browser = chrome::FindBrowserWithWebContents(new_contents); | 248 Browser* browser = chrome::FindBrowserWithWebContents(new_contents); |
250 | 249 |
251 if (browser && browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) | 250 if (browser && browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) |
252 return; | 251 return; |
253 | 252 |
254 UpdateAppItemState(old_contents, | 253 UpdateAppItemState(old_contents, |
255 ChromeLauncherController::APP_STATE_REMOVED); | 254 ChromeLauncherController::APP_STATE_REMOVED); |
256 RemoveWebContentsObserver(old_contents); | 255 RemoveWebContentsObserver(old_contents); |
257 | 256 |
258 ChromeLauncherController::AppState state = | 257 ChromeLauncherController::AppState state = |
259 ChromeLauncherController::APP_STATE_ACTIVE; | 258 ChromeLauncherController::APP_STATE_ACTIVE; |
260 if (browser->window()->IsActive() && | 259 if (browser->window()->IsActive() && |
261 (tab_strip_model->GetActiveWebContents() == new_contents)) | 260 (tab_strip_model->GetActiveWebContents() == new_contents)) |
262 state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; | 261 state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; |
263 UpdateAppItemState(new_contents, state); | 262 UpdateAppItemState(new_contents, state); |
264 UpdateBrowserItemState(); | 263 UpdateBrowserItemState(); |
265 | 264 |
266 if (tab_strip_model->GetActiveWebContents() == new_contents) { | 265 if (tab_strip_model->GetActiveWebContents() == new_contents) { |
267 ash::SetLauncherIDForWindow( | 266 ash::SetShelfIDForWindow(GetShelfIDForWebContents(new_contents), |
268 GetLauncherIDForWebContents(new_contents), | 267 browser->window()->GetNativeWindow()); |
269 browser->window()->GetNativeWindow()); | |
270 } | 268 } |
271 | 269 |
272 AddWebContentsObserver(new_contents); | 270 AddWebContentsObserver(new_contents); |
273 } | 271 } |
274 | 272 |
275 void BrowserStatusMonitor::TabInsertedAt(content::WebContents* contents, | 273 void BrowserStatusMonitor::TabInsertedAt(content::WebContents* contents, |
276 int index, | 274 int index, |
277 bool foreground) { | 275 bool foreground) { |
278 // An inserted tab is not active - ActiveTabChanged() will be called to | 276 // An inserted tab is not active - ActiveTabChanged() will be called to |
279 // activate. We initialize therefore with |APP_STATE_INACTIVE|. | 277 // activate. We initialize therefore with |APP_STATE_INACTIVE|. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 326 } |
329 | 327 |
330 void BrowserStatusMonitor::RemoveWebContentsObserver( | 328 void BrowserStatusMonitor::RemoveWebContentsObserver( |
331 content::WebContents* contents) { | 329 content::WebContents* contents) { |
332 DCHECK(webcontents_to_observer_map_.find(contents) != | 330 DCHECK(webcontents_to_observer_map_.find(contents) != |
333 webcontents_to_observer_map_.end()); | 331 webcontents_to_observer_map_.end()); |
334 delete webcontents_to_observer_map_[contents]; | 332 delete webcontents_to_observer_map_[contents]; |
335 webcontents_to_observer_map_.erase(contents); | 333 webcontents_to_observer_map_.erase(contents); |
336 } | 334 } |
337 | 335 |
338 ash::LauncherID BrowserStatusMonitor::GetLauncherIDForWebContents( | 336 ash::ShelfID BrowserStatusMonitor::GetShelfIDForWebContents( |
339 content::WebContents* contents) { | 337 content::WebContents* contents) { |
340 return launcher_controller_->GetLauncherIDForWebContents(contents); | 338 return launcher_controller_->GetShelfIDForWebContents(contents); |
341 } | 339 } |
OLD | NEW |