| 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" | |
| 11 #include "ash/common/accessibility_delegate.h" | |
| 12 #include "ash/common/cast_config_controller.h" | 10 #include "ash/common/cast_config_controller.h" |
| 13 #include "ash/common/devtools/ash_devtools_css_agent.h" | |
| 14 #include "ash/common/devtools/ash_devtools_dom_agent.h" | |
| 15 #include "ash/common/focus_cycler.h" | 11 #include "ash/common/focus_cycler.h" |
| 16 #include "ash/common/keyboard/keyboard_ui.h" | 12 #include "ash/common/keyboard/keyboard_ui.h" |
| 17 #include "ash/common/media_controller.h" | 13 #include "ash/common/media_controller.h" |
| 18 #include "ash/common/new_window_controller.h" | 14 #include "ash/common/new_window_controller.h" |
| 19 #include "ash/common/palette_delegate.h" | |
| 20 #include "ash/common/session/session_controller.h" | 15 #include "ash/common/session/session_controller.h" |
| 21 #include "ash/common/session/session_state_delegate.h" | 16 #include "ash/common/session/session_state_delegate.h" |
| 22 #include "ash/common/shelf/app_list_shelf_item_delegate.h" | 17 #include "ash/common/shelf/app_list_shelf_item_delegate.h" |
| 23 #include "ash/common/shelf/shelf_controller.h" | 18 #include "ash/common/shelf/shelf_controller.h" |
| 24 #include "ash/common/shelf/shelf_delegate.h" | 19 #include "ash/common/shelf/shelf_delegate.h" |
| 25 #include "ash/common/shelf/shelf_model.h" | 20 #include "ash/common/shelf/shelf_model.h" |
| 26 #include "ash/common/shelf/shelf_window_watcher.h" | 21 #include "ash/common/shelf/shelf_window_watcher.h" |
| 27 #include "ash/common/shell_delegate.h" | 22 #include "ash/common/shell_delegate.h" |
| 28 #include "ash/common/shutdown_controller.h" | 23 #include "ash/common/shutdown_controller.h" |
| 29 #include "ash/common/system/brightness_control_delegate.h" | 24 #include "ash/common/system/brightness_control_delegate.h" |
| 30 #include "ash/common/system/chromeos/brightness/brightness_controller_chromeos.h
" | 25 #include "ash/common/system/chromeos/brightness/brightness_controller_chromeos.h
" |
| 31 #include "ash/common/system/chromeos/keyboard_brightness_controller.h" | 26 #include "ash/common/system/chromeos/keyboard_brightness_controller.h" |
| 32 #include "ash/common/system/chromeos/network/vpn_list.h" | 27 #include "ash/common/system/chromeos/network/vpn_list.h" |
| 33 #include "ash/common/system/chromeos/session/logout_confirmation_controller.h" | 28 #include "ash/common/system/chromeos/session/logout_confirmation_controller.h" |
| 34 #include "ash/common/system/keyboard_brightness_control_delegate.h" | 29 #include "ash/common/system/keyboard_brightness_control_delegate.h" |
| 35 #include "ash/common/system/locale/locale_notification_controller.h" | 30 #include "ash/common/system/locale/locale_notification_controller.h" |
| 36 #include "ash/common/system/toast/toast_manager.h" | |
| 37 #include "ash/common/system/tray/system_tray_controller.h" | 31 #include "ash/common/system/tray/system_tray_controller.h" |
| 38 #include "ash/common/system/tray/system_tray_delegate.h" | 32 #include "ash/common/system/tray/system_tray_delegate.h" |
| 39 #include "ash/common/system/tray/system_tray_notifier.h" | 33 #include "ash/common/system/tray/system_tray_notifier.h" |
| 40 #include "ash/common/wallpaper/wallpaper_controller.h" | |
| 41 #include "ash/common/wallpaper/wallpaper_delegate.h" | 34 #include "ash/common/wallpaper/wallpaper_delegate.h" |
| 42 #include "ash/common/wm/immersive_context_ash.h" | 35 #include "ash/common/wm/immersive_context_ash.h" |
| 43 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | 36 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 44 #include "ash/common/wm/mru_window_tracker.h" | 37 #include "ash/common/wm/mru_window_tracker.h" |
| 45 #include "ash/common/wm/overview/window_selector_controller.h" | 38 #include "ash/common/wm/overview/window_selector_controller.h" |
| 46 #include "ash/common/wm/root_window_finder.h" | 39 #include "ash/common/wm/root_window_finder.h" |
| 47 #include "ash/common/wm/system_modal_container_layout_manager.h" | 40 #include "ash/common/wm/system_modal_container_layout_manager.h" |
| 48 #include "ash/common/wm/window_cycle_controller.h" | 41 #include "ash/common/wm/window_cycle_controller.h" |
| 49 #include "ash/common/wm_window.h" | 42 #include "ash/common/wm_window.h" |
| 50 #include "ash/public/cpp/shell_window_ids.h" | 43 #include "ash/public/cpp/shell_window_ids.h" |
| 51 #include "ash/root_window_controller.h" | 44 #include "ash/root_window_controller.h" |
| 52 #include "ash/shell.h" | 45 #include "ash/shell.h" |
| 53 #include "base/bind.h" | 46 #include "base/bind.h" |
| 54 #include "base/logging.h" | 47 #include "base/logging.h" |
| 55 #include "base/memory/ptr_util.h" | 48 #include "base/memory/ptr_util.h" |
| 56 #include "base/threading/sequenced_worker_pool.h" | |
| 57 #include "services/preferences/public/cpp/pref_client_store.h" | 49 #include "services/preferences/public/cpp/pref_client_store.h" |
| 58 #include "services/preferences/public/interfaces/preferences.mojom.h" | 50 #include "services/preferences/public/interfaces/preferences.mojom.h" |
| 59 #include "services/service_manager/public/cpp/connector.h" | 51 #include "services/service_manager/public/cpp/connector.h" |
| 60 #include "ui/app_list/presenter/app_list.h" | 52 #include "ui/app_list/presenter/app_list.h" |
| 61 #include "ui/display/display.h" | 53 #include "ui/display/display.h" |
| 62 #include "ui/views/focus/focus_manager_factory.h" | |
| 63 | 54 |
| 64 namespace ash { | 55 namespace ash { |
| 65 | 56 |
| 66 // static | 57 // static |
| 67 WmShell* WmShell::instance_ = nullptr; | 58 WmShell* WmShell::instance_ = nullptr; |
| 68 | 59 |
| 69 WmShell::~WmShell() { | 60 WmShell::~WmShell() { |
| 70 session_controller_->RemoveSessionStateObserver(this); | 61 session_controller_->RemoveSessionStateObserver(this); |
| 71 } | 62 } |
| 72 | 63 |
| 73 // static | 64 // static |
| 74 void WmShell::Set(WmShell* instance) { | 65 void WmShell::Set(WmShell* instance) { |
| 75 instance_ = instance; | 66 instance_ = instance; |
| 76 } | 67 } |
| 77 | 68 |
| 78 // static | 69 // static |
| 79 WmShell* WmShell::Get() { | 70 WmShell* WmShell::Get() { |
| 80 return instance_; | 71 return instance_; |
| 81 } | 72 } |
| 82 | 73 |
| 83 void WmShell::Initialize(const scoped_refptr<base::SequencedWorkerPool>& pool) { | |
| 84 blocking_pool_ = pool; | |
| 85 | |
| 86 // Some delegates access WmShell during their construction. Create them here | |
| 87 // instead of the WmShell constructor. | |
| 88 accessibility_delegate_.reset(delegate_->CreateAccessibilityDelegate()); | |
| 89 palette_delegate_ = delegate_->CreatePaletteDelegate(); | |
| 90 toast_manager_.reset(new ToastManager); | |
| 91 | |
| 92 // Create the app list item in the shelf data model. | |
| 93 AppListShelfItemDelegate::CreateAppListItemAndDelegate(shelf_model()); | |
| 94 | |
| 95 // Install the custom factory early on so that views::FocusManagers for Tray, | |
| 96 // Shelf, and WallPaper could be created by the factory. | |
| 97 views::FocusManagerFactory::Install(new AshFocusManagerFactory); | |
| 98 | |
| 99 wallpaper_controller_.reset(new WallpaperController(blocking_pool_)); | |
| 100 | |
| 101 // Start devtools server | |
| 102 devtools_server_ = ui::devtools::UiDevToolsServer::Create(nullptr); | |
| 103 if (devtools_server_) { | |
| 104 auto dom_backend = base::MakeUnique<devtools::AshDevToolsDOMAgent>(this); | |
| 105 auto css_backend = | |
| 106 base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_backend.get()); | |
| 107 auto devtools_client = base::MakeUnique<ui::devtools::UiDevToolsClient>( | |
| 108 "Ash", devtools_server_.get()); | |
| 109 devtools_client->AddAgent(std::move(dom_backend)); | |
| 110 devtools_client->AddAgent(std::move(css_backend)); | |
| 111 devtools_server_->AttachClient(std::move(devtools_client)); | |
| 112 } | |
| 113 } | |
| 114 | |
| 115 void WmShell::Shutdown() { | 74 void WmShell::Shutdown() { |
| 116 // These members access WmShell in their destructors. | |
| 117 wallpaper_controller_.reset(); | |
| 118 accessibility_delegate_.reset(); | |
| 119 | |
| 120 // ShelfWindowWatcher has window observers and a pointer to the shelf model. | 75 // ShelfWindowWatcher has window observers and a pointer to the shelf model. |
| 121 shelf_window_watcher_.reset(); | 76 shelf_window_watcher_.reset(); |
| 122 // ShelfItemDelegate subclasses it owns have complex cleanup to run (e.g. ARC | 77 // ShelfItemDelegate subclasses it owns have complex cleanup to run (e.g. ARC |
| 123 // shelf items in Chrome) so explicitly shutdown early. | 78 // shelf items in Chrome) so explicitly shutdown early. |
| 124 shelf_model()->DestroyItemDelegates(); | 79 shelf_model()->DestroyItemDelegates(); |
| 125 // Must be destroyed before FocusClient. | 80 // Must be destroyed before FocusClient. |
| 126 shelf_delegate_.reset(); | 81 shelf_delegate_.reset(); |
| 127 | 82 |
| 128 // Balances the Install() in Initialize(). | |
| 129 views::FocusManagerFactory::Install(nullptr); | |
| 130 | |
| 131 // Removes itself as an observer of |pref_store_|. | 83 // Removes itself as an observer of |pref_store_|. |
| 132 shelf_controller_.reset(); | 84 shelf_controller_.reset(); |
| 133 } | 85 } |
| 134 | 86 |
| 135 ShelfModel* WmShell::shelf_model() { | 87 ShelfModel* WmShell::shelf_model() { |
| 136 return shelf_controller_->model(); | 88 return shelf_controller_->model(); |
| 137 } | 89 } |
| 138 | 90 |
| 139 void WmShell::ShowContextMenu(const gfx::Point& location_in_screen, | 91 void WmShell::ShowContextMenu(const gfx::Point& location_in_screen, |
| 140 ui::MenuSourceType source_type) { | 92 ui::MenuSourceType source_type) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 142 |
| 191 void WmShell::RemoveLockStateObserver(LockStateObserver* observer) { | 143 void WmShell::RemoveLockStateObserver(LockStateObserver* observer) { |
| 192 lock_state_observers_.RemoveObserver(observer); | 144 lock_state_observers_.RemoveObserver(observer); |
| 193 } | 145 } |
| 194 | 146 |
| 195 void WmShell::SetShelfDelegateForTesting( | 147 void WmShell::SetShelfDelegateForTesting( |
| 196 std::unique_ptr<ShelfDelegate> test_delegate) { | 148 std::unique_ptr<ShelfDelegate> test_delegate) { |
| 197 shelf_delegate_ = std::move(test_delegate); | 149 shelf_delegate_ = std::move(test_delegate); |
| 198 } | 150 } |
| 199 | 151 |
| 200 void WmShell::SetPaletteDelegateForTesting( | |
| 201 std::unique_ptr<PaletteDelegate> palette_delegate) { | |
| 202 palette_delegate_ = std::move(palette_delegate); | |
| 203 } | |
| 204 | |
| 205 WmShell::WmShell(std::unique_ptr<ShellDelegate> shell_delegate) | 152 WmShell::WmShell(std::unique_ptr<ShellDelegate> shell_delegate) |
| 206 : delegate_(std::move(shell_delegate)), | 153 : delegate_(std::move(shell_delegate)), |
| 207 app_list_(base::MakeUnique<app_list::AppList>()), | 154 app_list_(base::MakeUnique<app_list::AppList>()), |
| 208 brightness_control_delegate_( | 155 brightness_control_delegate_( |
| 209 base::MakeUnique<system::BrightnessControllerChromeos>()), | 156 base::MakeUnique<system::BrightnessControllerChromeos>()), |
| 210 cast_config_(base::MakeUnique<CastConfigController>()), | 157 cast_config_(base::MakeUnique<CastConfigController>()), |
| 211 focus_cycler_(base::MakeUnique<FocusCycler>()), | 158 focus_cycler_(base::MakeUnique<FocusCycler>()), |
| 212 immersive_context_(base::MakeUnique<ImmersiveContextAsh>()), | 159 immersive_context_(base::MakeUnique<ImmersiveContextAsh>()), |
| 213 keyboard_brightness_control_delegate_( | 160 keyboard_brightness_control_delegate_( |
| 214 base::MakeUnique<KeyboardBrightnessController>()), | 161 base::MakeUnique<KeyboardBrightnessController>()), |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 299 } |
| 353 | 300 |
| 354 void WmShell::CreateMruWindowTracker() { | 301 void WmShell::CreateMruWindowTracker() { |
| 355 mru_window_tracker_.reset(new MruWindowTracker); | 302 mru_window_tracker_.reset(new MruWindowTracker); |
| 356 } | 303 } |
| 357 | 304 |
| 358 void WmShell::DeleteMruWindowTracker() { | 305 void WmShell::DeleteMruWindowTracker() { |
| 359 mru_window_tracker_.reset(); | 306 mru_window_tracker_.reset(); |
| 360 } | 307 } |
| 361 | 308 |
| 362 void WmShell::DeleteToastManager() { | |
| 363 toast_manager_.reset(); | |
| 364 } | |
| 365 | |
| 366 void WmShell::SetAcceleratorController( | 309 void WmShell::SetAcceleratorController( |
| 367 std::unique_ptr<AcceleratorController> accelerator_controller) { | 310 std::unique_ptr<AcceleratorController> accelerator_controller) { |
| 368 accelerator_controller_ = std::move(accelerator_controller); | 311 accelerator_controller_ = std::move(accelerator_controller); |
| 369 } | 312 } |
| 370 | 313 |
| 371 void WmShell::SessionStateChanged(session_manager::SessionState state) { | 314 void WmShell::SessionStateChanged(session_manager::SessionState state) { |
| 372 // Create the shelf when a session becomes active. It's safe to do this | 315 // Create the shelf when a session becomes active. It's safe to do this |
| 373 // multiple times (e.g. initial login vs. multiprofile add session). | 316 // multiple times (e.g. initial login vs. multiprofile add session). |
| 374 if (state == session_manager::SessionState::ACTIVE) | 317 if (state == session_manager::SessionState::ACTIVE) |
| 375 CreateShelfView(); | 318 CreateShelfView(); |
| 376 } | 319 } |
| 377 | 320 |
| 378 } // namespace ash | 321 } // namespace ash |
| OLD | NEW |