| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/common/wm_shell.h" | 5 #include "ash/common/wm_shell.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/accelerators/accelerator_controller.h" | 9 #include "ash/common/accelerators/accelerator_controller.h" |
| 10 #include "ash/common/accelerators/ash_focus_manager_factory.h" | 10 #include "ash/common/accelerators/ash_focus_manager_factory.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "ash/common/system/tray/system_tray_notifier.h" | 39 #include "ash/common/system/tray/system_tray_notifier.h" |
| 40 #include "ash/common/wallpaper/wallpaper_controller.h" | 40 #include "ash/common/wallpaper/wallpaper_controller.h" |
| 41 #include "ash/common/wallpaper/wallpaper_delegate.h" | 41 #include "ash/common/wallpaper/wallpaper_delegate.h" |
| 42 #include "ash/common/wm/immersive_context_ash.h" | 42 #include "ash/common/wm/immersive_context_ash.h" |
| 43 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 43 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 44 #include "ash/common/wm/mru_window_tracker.h" | 44 #include "ash/common/wm/mru_window_tracker.h" |
| 45 #include "ash/common/wm/overview/window_selector_controller.h" | 45 #include "ash/common/wm/overview/window_selector_controller.h" |
| 46 #include "ash/common/wm/root_window_finder.h" | 46 #include "ash/common/wm/root_window_finder.h" |
| 47 #include "ash/common/wm/system_modal_container_layout_manager.h" | 47 #include "ash/common/wm/system_modal_container_layout_manager.h" |
| 48 #include "ash/common/wm/window_cycle_controller.h" | 48 #include "ash/common/wm/window_cycle_controller.h" |
| 49 #include "ash/common/wm_activation_observer.h" |
| 49 #include "ash/common/wm_window.h" | 50 #include "ash/common/wm_window.h" |
| 50 #include "ash/public/cpp/shell_window_ids.h" | 51 #include "ash/public/cpp/shell_window_ids.h" |
| 51 #include "ash/root_window_controller.h" | 52 #include "ash/root_window_controller.h" |
| 53 #include "ash/shell.h" |
| 52 #include "base/bind.h" | 54 #include "base/bind.h" |
| 53 #include "base/logging.h" | 55 #include "base/logging.h" |
| 54 #include "base/memory/ptr_util.h" | 56 #include "base/memory/ptr_util.h" |
| 55 #include "services/preferences/public/cpp/pref_observer_store.h" | 57 #include "services/preferences/public/cpp/pref_observer_store.h" |
| 56 #include "services/preferences/public/interfaces/preferences.mojom.h" | 58 #include "services/preferences/public/interfaces/preferences.mojom.h" |
| 57 #include "services/service_manager/public/cpp/connector.h" | 59 #include "services/service_manager/public/cpp/connector.h" |
| 58 #include "ui/app_list/presenter/app_list.h" | 60 #include "ui/app_list/presenter/app_list.h" |
| 59 #include "ui/display/display.h" | 61 #include "ui/display/display.h" |
| 60 #include "ui/views/focus/focus_manager_factory.h" | 62 #include "ui/views/focus/focus_manager_factory.h" |
| 63 #include "ui/wm/public/activation_client.h" |
| 61 | 64 |
| 62 namespace ash { | 65 namespace ash { |
| 63 | 66 |
| 64 // static | 67 // static |
| 65 WmShell* WmShell::instance_ = nullptr; | 68 WmShell* WmShell::instance_ = nullptr; |
| 66 | 69 |
| 70 WmShell::~WmShell() { |
| 71 session_controller_->RemoveSessionStateObserver(this); |
| 72 } |
| 73 |
| 67 // static | 74 // static |
| 68 void WmShell::Set(WmShell* instance) { | 75 void WmShell::Set(WmShell* instance) { |
| 69 instance_ = instance; | 76 instance_ = instance; |
| 70 } | 77 } |
| 71 | 78 |
| 72 // static | 79 // static |
| 73 WmShell* WmShell::Get() { | 80 WmShell* WmShell::Get() { |
| 74 return instance_; | 81 return instance_; |
| 75 } | 82 } |
| 76 | 83 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 100 base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_backend.get()); | 107 base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_backend.get()); |
| 101 auto devtools_client = base::MakeUnique<ui::devtools::UiDevToolsClient>( | 108 auto devtools_client = base::MakeUnique<ui::devtools::UiDevToolsClient>( |
| 102 "Ash", devtools_server_.get()); | 109 "Ash", devtools_server_.get()); |
| 103 devtools_client->AddAgent(std::move(dom_backend)); | 110 devtools_client->AddAgent(std::move(dom_backend)); |
| 104 devtools_client->AddAgent(std::move(css_backend)); | 111 devtools_client->AddAgent(std::move(css_backend)); |
| 105 devtools_server_->AttachClient(std::move(devtools_client)); | 112 devtools_server_->AttachClient(std::move(devtools_client)); |
| 106 } | 113 } |
| 107 } | 114 } |
| 108 | 115 |
| 109 void WmShell::Shutdown() { | 116 void WmShell::Shutdown() { |
| 117 if (added_activation_observer_) |
| 118 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 119 |
| 110 // These members access WmShell in their destructors. | 120 // These members access WmShell in their destructors. |
| 111 wallpaper_controller_.reset(); | 121 wallpaper_controller_.reset(); |
| 112 accessibility_delegate_.reset(); | 122 accessibility_delegate_.reset(); |
| 113 | 123 |
| 114 // ShelfWindowWatcher has window observers and a pointer to the shelf model. | 124 // ShelfWindowWatcher has window observers and a pointer to the shelf model. |
| 115 shelf_window_watcher_.reset(); | 125 shelf_window_watcher_.reset(); |
| 116 // ShelfItemDelegate subclasses it owns have complex cleanup to run (e.g. ARC | 126 // ShelfItemDelegate subclasses it owns have complex cleanup to run (e.g. ARC |
| 117 // shelf items in Chrome) so explicitly shutdown early. | 127 // shelf items in Chrome) so explicitly shutdown early. |
| 118 shelf_model()->DestroyItemDelegates(); | 128 shelf_model()->DestroyItemDelegates(); |
| 119 // Must be destroyed before FocusClient. | 129 // Must be destroyed before FocusClient. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 void WmShell::NotifyShelfAlignmentChanged(WmWindow* root_window) { | 217 void WmShell::NotifyShelfAlignmentChanged(WmWindow* root_window) { |
| 208 for (auto& observer : shell_observers_) | 218 for (auto& observer : shell_observers_) |
| 209 observer.OnShelfAlignmentChanged(root_window); | 219 observer.OnShelfAlignmentChanged(root_window); |
| 210 } | 220 } |
| 211 | 221 |
| 212 void WmShell::NotifyShelfAutoHideBehaviorChanged(WmWindow* root_window) { | 222 void WmShell::NotifyShelfAutoHideBehaviorChanged(WmWindow* root_window) { |
| 213 for (auto& observer : shell_observers_) | 223 for (auto& observer : shell_observers_) |
| 214 observer.OnShelfAutoHideBehaviorChanged(root_window); | 224 observer.OnShelfAutoHideBehaviorChanged(root_window); |
| 215 } | 225 } |
| 216 | 226 |
| 227 void WmShell::AddActivationObserver(WmActivationObserver* observer) { |
| 228 if (!added_activation_observer_) { |
| 229 added_activation_observer_ = true; |
| 230 Shell::GetInstance()->activation_client()->AddObserver(this); |
| 231 } |
| 232 activation_observers_.AddObserver(observer); |
| 233 } |
| 234 |
| 235 void WmShell::RemoveActivationObserver(WmActivationObserver* observer) { |
| 236 activation_observers_.RemoveObserver(observer); |
| 237 } |
| 238 |
| 217 void WmShell::AddShellObserver(ShellObserver* observer) { | 239 void WmShell::AddShellObserver(ShellObserver* observer) { |
| 218 shell_observers_.AddObserver(observer); | 240 shell_observers_.AddObserver(observer); |
| 219 } | 241 } |
| 220 | 242 |
| 221 void WmShell::RemoveShellObserver(ShellObserver* observer) { | 243 void WmShell::RemoveShellObserver(ShellObserver* observer) { |
| 222 shell_observers_.RemoveObserver(observer); | 244 shell_observers_.RemoveObserver(observer); |
| 223 } | 245 } |
| 224 | 246 |
| 225 void WmShell::OnLockStateEvent(LockStateObserver::EventType event) { | 247 void WmShell::OnLockStateEvent(LockStateObserver::EventType event) { |
| 226 for (auto& observer : lock_state_observers_) | 248 for (auto& observer : lock_state_observers_) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 295 |
| 274 prefs::mojom::PreferencesManagerPtr pref_manager_ptr; | 296 prefs::mojom::PreferencesManagerPtr pref_manager_ptr; |
| 275 // Can be null in tests. | 297 // Can be null in tests. |
| 276 if (!delegate_->GetShellConnector()) | 298 if (!delegate_->GetShellConnector()) |
| 277 return; | 299 return; |
| 278 delegate_->GetShellConnector()->BindInterface(prefs::mojom::kServiceName, | 300 delegate_->GetShellConnector()->BindInterface(prefs::mojom::kServiceName, |
| 279 &pref_manager_ptr); | 301 &pref_manager_ptr); |
| 280 pref_store_ = new preferences::PrefObserverStore(std::move(pref_manager_ptr)); | 302 pref_store_ = new preferences::PrefObserverStore(std::move(pref_manager_ptr)); |
| 281 } | 303 } |
| 282 | 304 |
| 283 WmShell::~WmShell() { | |
| 284 session_controller_->RemoveSessionStateObserver(this); | |
| 285 } | |
| 286 | |
| 287 RootWindowController* WmShell::GetPrimaryRootWindowController() { | 305 RootWindowController* WmShell::GetPrimaryRootWindowController() { |
| 288 return GetPrimaryRootWindow()->GetRootWindowController(); | 306 return GetPrimaryRootWindow()->GetRootWindowController(); |
| 289 } | 307 } |
| 290 | 308 |
| 291 WmWindow* WmShell::GetRootWindowForNewWindows() { | 309 WmWindow* WmShell::GetRootWindowForNewWindows() { |
| 292 if (scoped_root_window_for_new_windows_) | 310 if (scoped_root_window_for_new_windows_) |
| 293 return scoped_root_window_for_new_windows_; | 311 return scoped_root_window_for_new_windows_; |
| 294 return root_window_for_new_windows_; | 312 return root_window_for_new_windows_; |
| 295 } | 313 } |
| 296 | 314 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 accelerator_controller_ = std::move(accelerator_controller); | 434 accelerator_controller_ = std::move(accelerator_controller); |
| 417 } | 435 } |
| 418 | 436 |
| 419 void WmShell::SessionStateChanged(session_manager::SessionState state) { | 437 void WmShell::SessionStateChanged(session_manager::SessionState state) { |
| 420 // Create the shelf when a session becomes active. It's safe to do this | 438 // Create the shelf when a session becomes active. It's safe to do this |
| 421 // multiple times (e.g. initial login vs. multiprofile add session). | 439 // multiple times (e.g. initial login vs. multiprofile add session). |
| 422 if (state == session_manager::SessionState::ACTIVE) | 440 if (state == session_manager::SessionState::ACTIVE) |
| 423 CreateShelf(); | 441 CreateShelf(); |
| 424 } | 442 } |
| 425 | 443 |
| 444 void WmShell::OnWindowActivated( |
| 445 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 446 aura::Window* gained_active, |
| 447 aura::Window* lost_active) { |
| 448 WmWindow* gained_active_wm = WmWindow::Get(gained_active); |
| 449 WmWindow* lost_active_wm = WmWindow::Get(lost_active); |
| 450 if (gained_active_wm) |
| 451 set_root_window_for_new_windows(gained_active_wm->GetRootWindow()); |
| 452 for (auto& observer : activation_observers_) |
| 453 observer.OnWindowActivated(gained_active_wm, lost_active_wm); |
| 454 } |
| 455 |
| 456 void WmShell::OnAttemptToReactivateWindow(aura::Window* request_active, |
| 457 aura::Window* actual_active) { |
| 458 for (auto& observer : activation_observers_) { |
| 459 observer.OnAttemptToReactivateWindow(WmWindow::Get(request_active), |
| 460 WmWindow::Get(actual_active)); |
| 461 } |
| 462 } |
| 463 |
| 426 } // namespace ash | 464 } // namespace ash |
| OLD | NEW |