Chromium Code Reviews| 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/browser_shortcut_launcher_item_controll er.h" |
| 10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
| 13 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
| 14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/browser/web_applications/web_app.h" | 16 #include "chrome/browser/web_applications/web_app.h" |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/browser/web_contents_view.h" | 18 #include "content/public/browser/web_contents_view.h" |
| 19 #include "ui/aura/client/activation_client.h" | 19 #include "ui/aura/client/activation_client.h" |
| 20 #include "ui/aura/root_window.h" | 20 #include "ui/aura/root_window.h" |
| 21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 22 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
| 23 | 23 |
| 24 BrowserStatusMonitor::BrowserStatusMonitor( | 24 BrowserStatusMonitor::BrowserStatusMonitor( |
| 25 ChromeLauncherController* launcher_controller) | 25 ChromeLauncherController* launcher_controller) |
| 26 : launcher_controller_(launcher_controller), | 26 : launcher_controller_(launcher_controller), |
| 27 observed_activation_clients_(this), | 27 observed_activation_clients_(this), |
| 28 observed_root_windows_(this) { | 28 observed_root_windows_(this) { |
| 29 DCHECK(launcher_controller_); | 29 DCHECK(launcher_controller_); |
| 30 BrowserList* browser_list = | 30 BrowserList::AddObserver(this); |
| 31 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | |
| 32 | |
| 33 browser_list->AddObserver(this); | |
| 34 | 31 |
| 35 // This check needs for win7_aura. Without this, all tests in | 32 // This check needs for win7_aura. Without this, all tests in |
| 36 // ChromeLauncherController will fail in win7_aura. | 33 // ChromeLauncherController will fail in win7_aura. |
| 37 if (ash::Shell::HasInstance()) { | 34 if (ash::Shell::HasInstance()) { |
| 38 // We can't assume all RootWindows have the same ActivationClient. | 35 // We can't assume all RootWindows have the same ActivationClient. |
| 39 // Add a RootWindow and its ActivationClient to the observed list. | 36 // Add a RootWindow and its ActivationClient to the observed list. |
| 40 ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows(); | 37 ash::Shell::RootWindowList root_windows = ash::Shell::GetAllRootWindows(); |
| 41 ash::Shell::RootWindowList::const_iterator iter = root_windows.begin(); | 38 ash::Shell::RootWindowList::const_iterator iter = root_windows.begin(); |
| 42 for (; iter != root_windows.end(); ++iter) { | 39 for (; iter != root_windows.end(); ++iter) { |
| 43 // |observed_activation_clients_| can have the same activation client | 40 // |observed_activation_clients_| can have the same activation client |
| 44 // multiple times - which would be handled by the used | 41 // multiple times - which would be handled by the used |
| 45 // |ScopedObserverWithDuplicatedSources|. | 42 // |ScopedObserverWithDuplicatedSources|. |
| 46 observed_activation_clients_.Add( | 43 observed_activation_clients_.Add( |
| 47 aura::client::GetActivationClient(*iter)); | 44 aura::client::GetActivationClient(*iter)); |
| 48 observed_root_windows_.Add(static_cast<aura::Window*>(*iter)); | 45 observed_root_windows_.Add(static_cast<aura::Window*>(*iter)); |
| 49 } | 46 } |
| 50 ash::Shell::GetInstance()->GetScreen()->AddObserver(this); | 47 ash::Shell::GetInstance()->GetScreen()->AddObserver(this); |
| 51 } | 48 } |
| 52 } | 49 } |
| 53 | 50 |
| 54 BrowserStatusMonitor::~BrowserStatusMonitor() { | 51 BrowserStatusMonitor::~BrowserStatusMonitor() { |
| 55 // This check needs for win7_aura. Without this, all tests in | 52 // This check needs for win7_aura. Without this, all tests in |
| 56 // ChromeLauncherController will fail in win7_aura. | 53 // ChromeLauncherController will fail in win7_aura. |
| 57 if (ash::Shell::HasInstance()) | 54 if (ash::Shell::HasInstance()) |
| 58 ash::Shell::GetInstance()->GetScreen()->RemoveObserver(this); | 55 ash::Shell::GetInstance()->GetScreen()->RemoveObserver(this); |
| 59 | 56 |
| 60 BrowserList* browser_list = | 57 BrowserList::RemoveObserver(this); |
| 58 | |
| 59 BrowserList* brower_list = | |
| 61 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 60 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
| 62 | 61 for (BrowserList::const_iterator i = browser_list->begin(); |
| 63 browser_list->RemoveObserver(this); | 62 i != browser_list->end(); ++i) { |
| 63 OnBrowserRemoved(*i); | |
| 64 } | |
| 64 } | 65 } |
| 65 | 66 |
| 66 void BrowserStatusMonitor::OnWindowActivated(aura::Window* gained_active, | 67 void BrowserStatusMonitor::OnWindowActivated(aura::Window* gained_active, |
| 67 aura::Window* lost_active) { | 68 aura::Window* lost_active) { |
| 68 Browser* browser = chrome::FindBrowserWithWindow(lost_active); | 69 Browser* browser = chrome::FindBrowserWithWindow(lost_active); |
| 69 if (browser) { | 70 if (browser) { |
| 70 UpdateAppAndBrowserState( | 71 UpdateAppAndBrowserState( |
| 71 browser->tab_strip_model()->GetActiveWebContents()); | 72 browser->tab_strip_model()->GetActiveWebContents()); |
| 72 } | 73 } |
| 73 | 74 |
| 74 browser = chrome::FindBrowserWithWindow(gained_active); | 75 browser = chrome::FindBrowserWithWindow(gained_active); |
| 75 if (browser) { | 76 if (browser) { |
| 76 UpdateAppAndBrowserState( | 77 UpdateAppAndBrowserState( |
| 77 browser->tab_strip_model()->GetActiveWebContents()); | 78 browser->tab_strip_model()->GetActiveWebContents()); |
| 78 } | 79 } |
| 79 } | 80 } |
| 80 | 81 |
| 81 void BrowserStatusMonitor::OnWindowDestroyed(aura::Window* window) { | 82 void BrowserStatusMonitor::OnWindowDestroyed(aura::Window* window) { |
| 82 // Remove RootWindow and its ActivationClient from observed list. | 83 // Remove RootWindow and its ActivationClient from observed list. |
| 83 observed_root_windows_.Remove(window); | 84 observed_root_windows_.Remove(window); |
| 84 observed_activation_clients_.Remove(aura::client::GetActivationClient( | 85 observed_activation_clients_.Remove(aura::client::GetActivationClient( |
| 85 static_cast<aura::RootWindow*>(window))); | 86 static_cast<aura::RootWindow*>(window))); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void BrowserStatusMonitor::OnBrowserAdded(Browser* browser) { | 89 void BrowserStatusMonitor::OnBrowserAdded(Browser* browser) { |
| 90 if (browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) | |
| 91 return; | |
| 92 | |
| 89 browser->tab_strip_model()->AddObserver(this); | 93 browser->tab_strip_model()->AddObserver(this); |
| 90 | 94 |
| 91 if (browser->is_type_popup() && browser->is_app()) { | 95 if (browser->is_type_popup() && browser->is_app()) { |
| 92 std::string app_id = | 96 std::string app_id = |
| 93 web_app::GetExtensionIdFromApplicationName(browser->app_name()); | 97 web_app::GetExtensionIdFromApplicationName(browser->app_name()); |
| 94 if (!app_id.empty()) { | 98 if (!app_id.empty()) { |
| 95 browser_to_app_id_map_[browser] = app_id; | 99 browser_to_app_id_map_[browser] = app_id; |
| 96 launcher_controller_->LockV1AppWithID(app_id); | 100 launcher_controller_->LockV1AppWithID(app_id); |
| 97 } | 101 } |
| 98 } | 102 } |
| 99 } | 103 } |
| 100 | 104 |
| 101 void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) { | 105 void BrowserStatusMonitor::OnBrowserRemoved(Browser* browser) { |
| 106 if (browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) | |
| 107 return; | |
| 108 | |
| 102 browser->tab_strip_model()->RemoveObserver(this); | 109 browser->tab_strip_model()->RemoveObserver(this); |
| 103 | 110 |
| 104 if (browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end()) { | 111 if (browser_to_app_id_map_.find(browser) != browser_to_app_id_map_.end()) { |
| 105 launcher_controller_->UnlockV1AppWithID(browser_to_app_id_map_[browser]); | 112 launcher_controller_->UnlockV1AppWithID(browser_to_app_id_map_[browser]); |
| 106 browser_to_app_id_map_.erase(browser); | 113 browser_to_app_id_map_.erase(browser); |
| 107 } | 114 } |
| 108 UpdateBrowserItemState(); | 115 UpdateBrowserItemState(); |
| 109 } | 116 } |
| 110 | 117 |
| 111 void BrowserStatusMonitor::OnDisplayBoundsChanged( | 118 void BrowserStatusMonitor::OnDisplayBoundsChanged( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 134 } | 141 } |
| 135 | 142 |
| 136 void BrowserStatusMonitor::ActiveTabChanged(content::WebContents* old_contents, | 143 void BrowserStatusMonitor::ActiveTabChanged(content::WebContents* old_contents, |
| 137 content::WebContents* new_contents, | 144 content::WebContents* new_contents, |
| 138 int index, | 145 int index, |
| 139 int reason) { | 146 int reason) { |
| 140 Browser* browser = NULL; | 147 Browser* browser = NULL; |
| 141 if (old_contents) | 148 if (old_contents) |
| 142 browser = chrome::FindBrowserWithWebContents(old_contents); | 149 browser = chrome::FindBrowserWithWebContents(old_contents); |
| 143 | 150 |
| 151 if (browser && browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) | |
| 152 return; | |
|
Mr4D (OOO till 08-26)
2013/09/09 18:48:45
Maybe an early exit if !browser since it gets chec
sky
2013/09/09 19:29:28
I thought we still wanted to invoke UpdateAppAndBr
Mr4D (OOO till 08-26)
2013/09/09 19:38:28
I've meant early exit, but calling UpdateApp.. .
sky
2013/09/09 19:39:54
I'm going to leave it. If you feel strongly I'll u
| |
| 153 | |
| 144 // Update immediately on a tab change. | 154 // Update immediately on a tab change. |
| 145 if (browser && | 155 if (browser && |
| 146 (TabStripModel::kNoTab != | 156 (TabStripModel::kNoTab != |
| 147 browser->tab_strip_model()->GetIndexOfWebContents(old_contents))) { | 157 browser->tab_strip_model()->GetIndexOfWebContents(old_contents))) { |
| 148 launcher_controller_->UpdateAppState( | 158 launcher_controller_->UpdateAppState( |
| 149 old_contents, | 159 old_contents, |
| 150 ChromeLauncherController::APP_STATE_INACTIVE); | 160 ChromeLauncherController::APP_STATE_INACTIVE); |
| 151 } | 161 } |
| 152 | 162 |
| 153 UpdateAppAndBrowserState(new_contents); | 163 UpdateAppAndBrowserState(new_contents); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 183 UpdateAppAndBrowserState(new_contents); | 193 UpdateAppAndBrowserState(new_contents); |
| 184 } | 194 } |
| 185 | 195 |
| 186 void BrowserStatusMonitor::UpdateAppAndBrowserState( | 196 void BrowserStatusMonitor::UpdateAppAndBrowserState( |
| 187 content::WebContents* contents) { | 197 content::WebContents* contents) { |
| 188 if (contents) { | 198 if (contents) { |
| 189 ChromeLauncherController::AppState app_state = | 199 ChromeLauncherController::AppState app_state = |
| 190 ChromeLauncherController::APP_STATE_INACTIVE; | 200 ChromeLauncherController::APP_STATE_INACTIVE; |
| 191 | 201 |
| 192 Browser* browser = chrome::FindBrowserWithWebContents(contents); | 202 Browser* browser = chrome::FindBrowserWithWebContents(contents); |
| 203 if (browser && | |
|
Mr4D (OOO till 08-26)
2013/09/09 18:48:45
If browser is null it would crash later on as well
sky
2013/09/09 19:29:28
Good point. Added DCHECK.
| |
| 204 browser->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH) | |
| 205 return; | |
| 193 if (browser->tab_strip_model()->GetActiveWebContents() == contents) { | 206 if (browser->tab_strip_model()->GetActiveWebContents() == contents) { |
| 194 if (browser->window()->IsActive()) | 207 if (browser->window()->IsActive()) |
| 195 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; | 208 app_state = ChromeLauncherController::APP_STATE_WINDOW_ACTIVE; |
| 196 else | 209 else |
| 197 app_state = ChromeLauncherController::APP_STATE_ACTIVE; | 210 app_state = ChromeLauncherController::APP_STATE_ACTIVE; |
| 198 } | 211 } |
| 199 | 212 |
| 200 launcher_controller_->UpdateAppState(contents, app_state); | 213 launcher_controller_->UpdateAppState(contents, app_state); |
| 201 } | 214 } |
| 202 UpdateBrowserItemState(); | 215 UpdateBrowserItemState(); |
| 203 } | 216 } |
| 204 | 217 |
| 205 void BrowserStatusMonitor::UpdateBrowserItemState() { | 218 void BrowserStatusMonitor::UpdateBrowserItemState() { |
| 206 launcher_controller_->GetBrowserShortcutLauncherItemController()-> | 219 launcher_controller_->GetBrowserShortcutLauncherItemController()-> |
| 207 UpdateBrowserItemState(); | 220 UpdateBrowserItemState(); |
| 208 } | 221 } |
| OLD | NEW |