blob: 5cd341611bb4842783daea9d3aec846809f36f1e [file] [log] [blame]
[email protected]e0d22e82012-01-04 00:46:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]87b0d82e2011-10-07 21:02:592// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]b65bdda2011-12-23 23:35:315#include "ash/shell.h"
[email protected]87b0d82e2011-10-07 21:02:596
[email protected]f7eb89c2011-12-13 09:48:547#include <algorithm>
[email protected]0039db92012-05-09 04:11:458#include <string>
dchengcbf0d9d2015-12-27 22:49:239#include <utility>
[email protected]f7eb89c2011-12-13 09:48:5410
[email protected]60d677d2014-05-30 13:07:0211#include "ash/accelerators/accelerator_delegate.h"
jamescook01bf23e72017-01-09 19:58:1512#include "ash/accelerators/magnifier_key_scroller.h"
13#include "ash/accelerators/spoken_feedback_toggler.h"
sky15ef0aa2017-01-20 18:55:5914#include "ash/app_list/app_list_delegate_impl.h"
sky0702b272016-06-03 22:10:4115#include "ash/aura/wm_shell_aura.h"
[email protected]55398d22013-10-10 19:49:2016#include "ash/autoclick/autoclick_controller.h"
James Cook643b7182017-03-05 22:02:5817#include "ash/common/accelerators/accelerator_controller.h"
sky07a24d42017-03-09 23:57:3018#include "ash/common/accelerators/ash_focus_manager_factory.h"
19#include "ash/common/accessibility_delegate.h"
James Cook6316a552017-03-05 21:46:2120#include "ash/common/ash_constants.h"
sky79fa34712017-03-20 23:46:4721#include "ash/common/cast_config_controller.h"
sky07a24d42017-03-09 23:57:3022#include "ash/common/devtools/ash_devtools_css_agent.h"
23#include "ash/common/devtools/ash_devtools_dom_agent.h"
sky79fa34712017-03-20 23:46:4724#include "ash/common/focus_cycler.h"
James Cook643b7182017-03-05 22:02:5825#include "ash/common/frame/custom_frame_view_ash.h"
James Cook6316a552017-03-05 21:46:2126#include "ash/common/gpu_support.h"
27#include "ash/common/keyboard/keyboard_ui.h"
28#include "ash/common/login_status.h"
sky5ab16472017-03-21 19:35:0829#include "ash/common/media_controller.h"
30#include "ash/common/new_window_controller.h"
sky07a24d42017-03-09 23:57:3031#include "ash/common/palette_delegate.h"
sky5ad143a2017-03-22 04:31:2332#include "ash/common/session/session_controller.h"
James Cook6316a552017-03-05 21:46:2133#include "ash/common/session/session_state_delegate.h"
sky5ad143a2017-03-22 04:31:2334#include "ash/common/shelf/shelf_controller.h"
35#include "ash/common/shelf/shelf_delegate.h"
36#include "ash/common/shelf/shelf_model.h"
37#include "ash/common/shelf/shelf_window_watcher.h"
James Cook643b7182017-03-05 22:02:5838#include "ash/common/shelf/wm_shelf.h"
James Cook6316a552017-03-05 21:46:2139#include "ash/common/shell_delegate.h"
sky00c813f2017-03-08 22:48:5540#include "ash/common/shell_observer.h"
sky5b45ed82017-03-27 02:54:2341#include "ash/common/shutdown_controller.h"
sky79fa34712017-03-20 23:46:4742#include "ash/common/system/brightness_control_delegate.h"
James Cook6def4d9d2017-03-05 22:13:4743#include "ash/common/system/chromeos/bluetooth/bluetooth_notification_controller.h"
jamescookac6724332017-03-21 02:54:4344#include "ash/common/system/chromeos/bluetooth/tray_bluetooth_helper.h"
sky79fa34712017-03-20 23:46:4745#include "ash/common/system/chromeos/brightness/brightness_controller_chromeos.h"
46#include "ash/common/system/chromeos/keyboard_brightness_controller.h"
James Cook6def4d9d2017-03-05 22:13:4747#include "ash/common/system/chromeos/network/sms_observer.h"
sky5b45ed82017-03-27 02:54:2348#include "ash/common/system/chromeos/network/vpn_list.h"
James Cook6def4d9d2017-03-05 22:13:4749#include "ash/common/system/chromeos/power/power_status.h"
sky79fa34712017-03-20 23:46:4750#include "ash/common/system/chromeos/session/logout_confirmation_controller.h"
51#include "ash/common/system/keyboard_brightness_control_delegate.h"
52#include "ash/common/system/locale/locale_notification_controller.h"
James Cook6def4d9d2017-03-05 22:13:4753#include "ash/common/system/status_area_widget.h"
sky07a24d42017-03-09 23:57:3054#include "ash/common/system/toast/toast_manager.h"
sky79fa34712017-03-20 23:46:4755#include "ash/common/system/tray/system_tray_controller.h"
James Cook6def4d9d2017-03-05 22:13:4756#include "ash/common/system/tray/system_tray_delegate.h"
sky79fa34712017-03-20 23:46:4757#include "ash/common/system/tray/system_tray_notifier.h"
sky07a24d42017-03-09 23:57:3058#include "ash/common/wallpaper/wallpaper_controller.h"
James Cook6316a552017-03-05 21:46:2159#include "ash/common/wallpaper/wallpaper_delegate.h"
James Cook643b7182017-03-05 22:02:5860#include "ash/common/wm/container_finder.h"
sky5ab16472017-03-21 19:35:0861#include "ash/common/wm/immersive_context_ash.h"
James Cook643b7182017-03-05 22:02:5862#include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
63#include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h"
64#include "ash/common/wm/mru_window_tracker.h"
sky5b45ed82017-03-27 02:54:2365#include "ash/common/wm/overview/window_selector_controller.h"
James Cook643b7182017-03-05 22:02:5866#include "ash/common/wm/root_window_finder.h"
67#include "ash/common/wm/system_modal_container_layout_manager.h"
sky5b45ed82017-03-27 02:54:2368#include "ash/common/wm/window_cycle_controller.h"
James Cook643b7182017-03-05 22:02:5869#include "ash/common/wm/window_positioner.h"
70#include "ash/common/wm/workspace_controller.h"
James Cook6316a552017-03-05 21:46:2171#include "ash/common/wm_shell.h"
72#include "ash/common/wm_window.h"
[email protected]87ec2202014-02-06 06:24:2773#include "ash/display/cursor_window_controller.h"
jamescook01bf23e72017-01-09 19:58:1574#include "ash/display/display_color_manager_chromeos.h"
stevenjb537c5c3f2016-01-20 23:38:1275#include "ash/display/display_configuration_controller.h"
jamescook01bf23e72017-01-09 19:58:1576#include "ash/display/display_error_observer_chromeos.h"
[email protected]682990f2013-01-10 06:49:1177#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2778#include "ash/display/mouse_cursor_event_filter.h"
jamescook01bf23e72017-01-09 19:58:1579#include "ash/display/projecting_observer_chromeos.h"
80#include "ash/display/resolution_notification_controller.h"
rjkroege2c9305402016-09-07 00:21:4581#include "ash/display/screen_ash.h"
jamescook01bf23e72017-01-09 19:58:1582#include "ash/display/screen_orientation_controller_chromeos.h"
[email protected]8d625fb2012-07-18 16:40:0683#include "ash/display/screen_position_controller.h"
jamescook01bf23e72017-01-09 19:58:1584#include "ash/display/shutdown_observer_chromeos.h"
oshimae2818922015-07-28 01:18:5285#include "ash/display/window_tree_host_manager.h"
[email protected]f4c92b382012-08-28 00:59:5986#include "ash/drag_drop/drag_drop_controller.h"
[email protected]59ccade2013-10-17 17:56:4087#include "ash/first_run/first_run_helper_impl.h"
[email protected]f4c92b382012-08-28 00:59:5988#include "ash/high_contrast/high_contrast_controller.h"
oshima5e0fff82015-06-27 01:31:3089#include "ash/ime/input_method_event_handler.h"
sammiequon203ae022016-09-18 17:23:4290#include "ash/laser/laser_pointer_controller.h"
[email protected]f4c92b382012-08-28 00:59:5991#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5492#include "ash/magnifier/partial_magnification_controller.h"
jamescook8800b8232016-10-19 12:46:2793#include "ash/public/cpp/shell_window_ids.h"
[email protected]d90b8392012-06-13 09:34:5694#include "ash/root_window_controller.h"
[email protected]1b4c7472014-05-15 18:32:2395#include "ash/shell_init_params.h"
jamescook01bf23e72017-01-09 19:58:1596#include "ash/sticky_keys/sticky_keys_controller.h"
James Cook6def4d9d2017-03-05 22:13:4797#include "ash/system/chromeos/power/power_event_observer.h"
98#include "ash/system/chromeos/power/video_activity_notifier.h"
99#include "ash/system/chromeos/screen_layout_observer.h"
kylechar55f0eaf22017-01-11 22:57:37100#include "ash/touch/ash_touch_transform_controller.h"
oshima5a296e82016-04-29 01:32:27101#include "ash/utility/screenshot_controller.h"
jamescook01bf23e72017-01-09 19:58:15102#include "ash/virtual_keyboard_controller.h"
[email protected]39718b52012-12-03 17:24:56103#include "ash/wm/ash_focus_rules.h"
[email protected]c0ff0342013-02-27 00:41:29104#include "ash/wm/ash_native_cursor_manager.h"
[email protected]262f8bd2012-03-23 19:30:27105#include "ash/wm/event_client_impl.h"
skyb7b54092016-08-19 16:00:09106#include "ash/wm/immersive_handler_factory_ash.h"
[email protected]ab4f8c92013-05-30 19:07:47107#include "ash/wm/lock_state_controller.h"
[email protected]9ae32df2012-07-26 03:25:18108#include "ash/wm/overlay_event_filter.h"
sky6624a7af2016-05-27 18:47:49109#include "ash/wm/overview/scoped_overview_animation_settings_factory_aura.h"
[email protected]e0d22e82012-01-04 00:46:57110#include "ash/wm/power_button_controller.h"
[email protected]e4a181cc2012-03-17 02:20:57111#include "ash/wm/resize_shadow_controller.h"
hidehiko6821ca42016-06-18 11:12:23112#include "ash/wm/screen_pinning_controller.h"
[email protected]435b212e2012-04-05 19:43:37113#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:27114#include "ash/wm/system_modal_container_event_filter.h"
[email protected]3537d472014-01-15 05:45:31115#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:58116#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:02117#include "ash/wm/window_animations.h"
[email protected]f059c6942012-07-21 14:27:57118#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:59119#include "ash/wm/window_util.h"
[email protected]f296be72011-10-11 15:40:00120#include "base/bind.h"
jamescook01bf23e72017-01-09 19:58:15121#include "base/bind_helpers.h"
jamescookfda159002016-10-21 18:48:57122#include "base/command_line.h"
dchenga94547472016-04-08 08:41:11123#include "base/memory/ptr_util.h"
jamescook01bf23e72017-01-09 19:58:15124#include "base/sys_info.h"
tzik0dd58d42017-02-15 08:26:52125#include "base/threading/sequenced_worker_pool.h"
primiano7182d7b2015-01-30 18:02:03126#include "base/trace_event/trace_event.h"
jamescook01bf23e72017-01-09 19:58:15127#include "chromeos/audio/audio_a11y_controller.h"
128#include "chromeos/chromeos_switches.h"
129#include "chromeos/dbus/dbus_thread_manager.h"
reveman24158982017-01-10 05:58:45130#include "chromeos/system/devicemode.h"
sky07a24d42017-03-09 23:57:30131#include "components/ui_devtools/devtools_server.h"
skyb073203a2017-03-13 16:59:16132#include "services/preferences/public/cpp/pref_client_store.h"
133#include "services/preferences/public/interfaces/preferences.mojom.h"
derat94887a22017-01-20 18:17:25134#include "services/service_manager/public/cpp/connector.h"
135#include "services/ui/public/interfaces/constants.mojom.h"
sky7db5ccf2017-03-14 21:52:29136#include "ui/app_list/presenter/app_list.h"
[email protected]2c456102011-12-26 06:26:34137#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:44138#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:58139#include "ui/aura/layout_manager.h"
derat94887a22017-01-20 18:17:25140#include "ui/aura/mus/user_activity_forwarder.h"
[email protected]87b0d82e2011-10-07 21:02:59141#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:26142#include "ui/aura/window_event_dispatcher.h"
[email protected]2d4817742012-12-17 20:16:18143#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:17144#include "ui/base/user_activity/user_activity_detector.h"
jamescook01bf23e72017-01-09 19:58:15145#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]116302fc2012-05-05 21:45:41146#include "ui/compositor/layer.h"
147#include "ui/compositor/layer_animator.h"
oshimaf84b0da722016-04-27 19:47:19148#include "ui/display/display.h"
jamescook01bf23e72017-01-09 19:58:15149#include "ui/display/manager/chromeos/display_change_observer.h"
150#include "ui/display/manager/chromeos/display_configurator.h"
rjkroege72f8154f2016-10-29 00:49:02151#include "ui/display/manager/display_manager.h"
oshimaf84b0da722016-04-27 19:47:19152#include "ui/display/screen.h"
[email protected]3e670aa2013-12-02 19:04:32153#include "ui/events/event_target_iterator.h"
sky4ec2be82017-01-06 17:38:32154#include "ui/gfx/geometry/insets.h"
[email protected]9ec0f452012-05-31 15:58:53155#include "ui/gfx/image/image_skia.h"
[email protected]b6ba05d902013-10-04 21:38:45156#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28157#include "ui/keyboard/keyboard_switches.h"
[email protected]f1d5c3a2013-04-23 17:42:56158#include "ui/keyboard/keyboard_util.h"
[email protected]d7f30a72013-10-05 05:09:41159#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04160#include "ui/views/corewm/tooltip_controller.h"
sky07a24d42017-03-09 23:57:30161#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:58162#include "ui/views/widget/native_widget_aura.h"
163#include "ui/views/widget/widget.h"
[email protected]60d677d2014-05-30 13:07:02164#include "ui/wm/core/accelerator_filter.h"
[email protected]ee3ed10772014-03-11 22:02:01165#include "ui/wm/core/compound_event_filter.h"
166#include "ui/wm/core/focus_controller.h"
[email protected]ee3ed10772014-03-11 22:02:01167#include "ui/wm/core/shadow_controller.h"
168#include "ui/wm/core/visibility_controller.h"
169#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59170
oshimae001c8c2016-04-13 23:49:04171#if defined(USE_X11)
kylechar731f85f92016-12-01 20:50:46172#include "ui/display/manager/chromeos/x11/native_display_delegate_x11.h"
jamescook01bf23e72017-01-09 19:58:15173#include "ui/gfx/x/x11_types.h" // nogncheck
oshimae001c8c2016-04-13 23:49:04174#endif
175
176#if defined(USE_OZONE)
177#include "ui/display/types/native_display_delegate.h"
178#include "ui/ozone/public/ozone_platform.h"
179#endif
[email protected]70b3e7d52012-06-02 22:12:25180
[email protected]55f593352011-12-24 05:42:46181namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59182
183namespace {
[email protected]671a2ae2011-10-13 21:53:23184
[email protected]615922f2012-02-07 02:41:15185using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45186using views::Widget;
187
[email protected]b5756e22012-11-30 01:32:02188// A Corewm VisibilityController subclass that calls the Ash animation routine
189// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14190class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02191 public:
192 AshVisibilityController() {}
dcheng1f4538e2014-10-27 23:57:05193 ~AshVisibilityController() override {}
[email protected]b5756e22012-11-30 01:32:02194
195 private:
[email protected]e319c7e2014-03-14 19:56:14196 // Overridden from ::wm::VisibilityController:
dcheng1f4538e2014-10-27 23:57:05197 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
198 bool visible) override {
[email protected]b5756e22012-11-30 01:32:02199 return AnimateOnChildWindowVisibilityChanged(window, visible);
200 }
201
202 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
203};
204
[email protected]87b0d82e2011-10-07 21:02:59205} // namespace
206
[email protected]cac10fc62011-10-07 23:22:56207// static
achuith287b26e2015-09-03 17:49:18208Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13209// static
sky00f98a372017-01-11 06:03:49210aura::WindowTreeClient* Shell::window_tree_client_ = nullptr;
211// static
skya8b222f2017-01-12 15:47:13212aura::WindowManagerClient* Shell::window_manager_client_ = nullptr;
213// static
[email protected]9488d4d2012-02-29 18:32:37214bool Shell::initially_hide_cursor_ = false;
[email protected]2b4cd302012-02-24 20:21:13215
216////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56217// Shell, public:
218
[email protected]cac10fc62011-10-07 23:22:56219// static
[email protected]1b4c7472014-05-15 18:32:23220Shell* Shell::CreateInstance(const ShellInitParams& init_params) {
[email protected]3266c2b92011-11-14 00:06:08221 CHECK(!instance_);
skyabcae812017-01-18 17:01:34222 WmShell* wm_shell = init_params.wm_shell;
223 if (!wm_shell)
skyb073203a2017-03-13 16:59:16224 wm_shell = new WmShellAura();
225 instance_ = new Shell(base::WrapUnique<ShellDelegate>(init_params.delegate),
226 base::WrapUnique<WmShell>(wm_shell));
[email protected]1b4c7472014-05-15 18:32:23227 instance_->Init(init_params);
[email protected]3266c2b92011-11-14 00:06:08228 return instance_;
229}
230
231// static
skyb073203a2017-03-13 16:59:16232Shell* Shell::Get() {
oshima9eea82da2014-09-13 01:11:07233 CHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56234 return instance_;
235}
236
[email protected]6377a002011-11-10 20:26:47237// static
[email protected]b3b7bcd2012-03-06 19:35:45238bool Shell::HasInstance() {
239 return !!instance_;
240}
241
242// static
[email protected]ef589af2011-12-03 01:07:15243void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47244 delete instance_;
[email protected]6377a002011-11-10 20:26:47245}
246
[email protected]e73bd7802012-02-17 20:10:34247// static
[email protected]093b8d642014-04-03 20:59:28248RootWindowController* Shell::GetPrimaryRootWindowController() {
oshima9eea82da2014-09-13 01:11:07249 CHECK(HasInstance());
[email protected]093b8d642014-04-03 20:59:28250 return GetRootWindowController(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23251}
252
253// static
254Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
oshima9eea82da2014-09-13 01:11:07255 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34256 RootWindowControllerList root_window_controllers;
257 for (WmWindow* root_window : instance_->wm_shell_->GetAllRootWindows())
258 root_window_controllers.push_back(root_window->GetRootWindowController());
259 return root_window_controllers;
[email protected]d90b8392012-06-13 09:34:56260}
261
262// static
thanhphc90f49ca2017-03-03 17:48:53263RootWindowController* Shell::GetRootWindowControllerWithDisplayId(
264 int64_t display_id) {
265 CHECK(HasInstance());
266 WmWindow* root_window =
267 instance_->wm_shell_->GetRootWindowForDisplayId(display_id);
268 return root_window ? root_window->GetRootWindowController() : nullptr;
269}
270
271// static
[email protected]bf9cdb362013-10-25 19:22:45272aura::Window* Shell::GetPrimaryRootWindow() {
oshima9eea82da2014-09-13 01:11:07273 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34274 return instance_->wm_shell_->GetPrimaryRootWindow()->aura_window();
[email protected]e73bd7802012-02-17 20:10:34275}
276
[email protected]7b0f7502012-06-11 00:12:39277// static
sky27344382017-03-08 21:30:32278aura::Window* Shell::GetRootWindowForNewWindows() {
279 CHECK(Shell::HasInstance());
280 return WmWindow::GetAuraWindow(Shell::GetWmRootWindowForNewWindows());
[email protected]a857dbe2012-05-30 22:10:14281}
282
[email protected]7b0f7502012-06-11 00:12:39283// static
sky27344382017-03-08 21:30:32284WmWindow* Shell::GetWmRootWindowForNewWindows() {
285 CHECK(Shell::HasInstance());
286 Shell* shell = Shell::GetInstance();
287 if (shell->scoped_root_window_for_new_windows_)
288 return shell->scoped_root_window_for_new_windows_;
289 return shell->root_window_for_new_windows_;
mfomitcheva1a8aa62016-05-03 16:23:26290}
291
292// static
[email protected]c9390bd2013-11-08 20:33:13293aura::Window::Windows Shell::GetAllRootWindows() {
oshima9eea82da2014-09-13 01:11:07294 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34295 aura::Window::Windows windows;
296 for (WmWindow* window : instance_->wm_shell_->GetAllRootWindows())
297 windows.push_back(window->aura_window());
298 return windows;
[email protected]be65be362012-06-15 07:38:23299}
300
301// static
jamescookb8dcef522016-06-25 14:42:55302aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) {
[email protected]7b0f7502012-06-11 00:12:39303 return root_window->GetChildById(container_id);
304}
305
306// static
[email protected]bf9cdb362013-10-25 19:22:45307const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38308 int container_id) {
309 return root_window->GetChildById(container_id);
310}
311
[email protected]57b8bb352012-01-11 05:11:46312views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
313 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04314 // Use translucent-style window frames for dialogs.
[email protected]85501fe2013-10-18 10:15:27315 return new CustomFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46316}
317
[email protected]2e236a52012-06-27 22:21:47318void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44319 const gfx::Insets& insets) {
sky92f5587f2017-02-16 19:13:07320 wm_shell_->SetDisplayWorkAreaInsets(WmWindow::Get(contains), insets);
[email protected]1a2145b2012-03-13 21:09:17321}
322
skye79274a2016-06-08 05:39:02323void Shell::OnLoginStateChanged(LoginStatus status) {
sky00c813f2017-03-08 22:48:55324 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18325 observer.OnLoginStateChanged(status);
[email protected]82d3954ae2012-04-20 09:02:22326}
327
328void Shell::OnAppTerminating() {
sky00c813f2017-03-08 22:48:55329 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18330 observer.OnAppTerminating();
[email protected]82d3954ae2012-04-20 09:02:22331}
332
333void Shell::OnLockStateChanged(bool locked) {
sky00c813f2017-03-08 22:48:55334 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18335 observer.OnLockStateChanged(locked);
[email protected]ae298142013-08-10 15:30:29336#ifndef NDEBUG
337 // Make sure that there is no system modal in Lock layer when unlocked.
338 if (!locked) {
skye02e09e2017-03-09 22:54:23339 aura::Window::Windows containers = wm::GetContainersFromAllRootWindows(
340 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
341 for (aura::Window* container : containers)
342 DCHECK(container->children().empty());
[email protected]ae298142013-08-10 15:30:29343 }
344#endif
[email protected]82d3954ae2012-04-20 09:02:22345}
346
[email protected]58868abf2014-01-17 23:45:33347void Shell::OnCastingSessionStartedOrStopped(bool started) {
sky00c813f2017-03-08 22:48:55348 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18349 observer.OnCastingSessionStartedOrStopped(started);
[email protected]58868abf2014-01-17 23:45:33350}
351
sky80556bc42016-06-07 22:46:13352void Shell::OnRootWindowAdded(WmWindow* root_window) {
sky00c813f2017-03-08 22:48:55353 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18354 observer.OnRootWindowAdded(root_window);
[email protected]0e3e7cb2014-04-12 05:18:25355}
356
[email protected]51f438112013-11-18 19:32:50357void Shell::CreateKeyboard() {
[email protected]51f438112013-11-18 19:32:50358 InitKeyboard();
jamescookb8dcef522016-06-25 14:42:55359 GetPrimaryRootWindowController()->ActivateKeyboard(
360 keyboard::KeyboardController::GetInstance());
[email protected]51f438112013-11-18 19:32:50361}
362
[email protected]e1b299b2014-01-29 23:53:41363void Shell::DeactivateKeyboard() {
jamescookc3fbf0952016-06-29 06:48:31364 // TODO(jamescook): Move keyboard create and hide into WmShell.
sky79fa34712017-03-20 23:46:47365 keyboard_ui_->Hide();
[email protected]a0b3fb882014-04-07 19:26:03366 if (keyboard::KeyboardController::GetInstance()) {
[email protected]e1b299b2014-01-29 23:53:41367 RootWindowControllerList controllers = GetAllRootWindowControllers();
368 for (RootWindowControllerList::iterator iter = controllers.begin();
jamescookb8dcef522016-06-25 14:42:55369 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:03370 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]e1b299b2014-01-29 23:53:41371 }
372 }
achuith287b26e2015-09-03 17:49:18373 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]e1b299b2014-01-29 23:53:41374}
375
[email protected]da285852014-05-27 19:53:43376bool Shell::ShouldSaveDisplaySettings() {
skyabcae812017-01-18 17:01:34377 DCHECK(!wm_shell_->IsRunningInMash());
jamescookb8dcef522016-06-25 14:42:55378 return !(
379 screen_orientation_controller_->ignore_display_configuration_updates() ||
380 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43381}
[email protected]da285852014-05-27 19:53:43382
sky5ad143a2017-03-22 04:31:23383ShelfModel* Shell::shelf_model() {
384 return shelf_controller_->model();
385}
386
sky27344382017-03-08 21:30:32387aura::client::ActivationClient* Shell::activation_client() {
388 return focus_controller_.get();
389}
390
[email protected]c758fbf2012-03-25 22:53:59391void Shell::UpdateShelfVisibility() {
jamescookb551aba2016-09-01 01:00:16392 for (WmWindow* root : wm_shell_->GetAllRootWindows())
393 root->GetRootWindowController()->GetShelf()->UpdateVisibilityState();
[email protected]c758fbf2012-03-25 22:53:59394}
395
[email protected]88d71122012-10-18 07:11:01396WebNotificationTray* Shell::GetWebNotificationTray() {
jamescook612205f2016-05-26 06:02:11397 return GetPrimaryRootWindowController()
jamescookb551aba2016-09-01 01:00:16398 ->GetStatusAreaWidget()
jamescook612205f2016-05-26 06:02:11399 ->web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28400}
401
[email protected]a0afeb12012-12-10 22:57:09402bool Shell::HasPrimaryStatusArea() {
jamescookb551aba2016-09-01 01:00:16403 return !!GetPrimaryRootWindowController()->GetStatusAreaWidget();
[email protected]31f19e32012-10-30 22:31:23404}
405
[email protected]a0afeb12012-12-10 22:57:09406SystemTray* Shell::GetPrimarySystemTray() {
407 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42408}
409
[email protected]2b8a9bb2013-07-01 22:43:40410void Shell::SetTouchHudProjectionEnabled(bool enabled) {
411 if (is_touch_hud_projection_enabled_ == enabled)
412 return;
413
[email protected]2b8a9bb2013-07-01 22:43:40414 is_touch_hud_projection_enabled_ = enabled;
sky00c813f2017-03-08 22:48:55415 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18416 observer.OnTouchHudProjectionToggled(enabled);
[email protected]2b8a9bb2013-07-01 22:43:40417}
418
mswa7e8a5f2016-03-01 04:15:06419FirstRunHelper* Shell::CreateFirstRunHelper() {
420 return new FirstRunHelperImpl;
[email protected]59ccade2013-10-17 17:56:40421}
[email protected]87ec2202014-02-06 06:24:27422
sky5ad143a2017-03-22 04:31:23423void Shell::CreateShelfView() {
424 // Must occur after SessionController creation and user login.
425 DCHECK(session_controller());
426 DCHECK_GT(session_controller()->NumberOfLoggedInUsers(), 0);
427 CreateShelfDelegate();
428
429 for (WmWindow* root_window : wm_shell_->GetAllRootWindows())
430 root_window->GetRootWindowController()->CreateShelfView();
431}
432
yawanodc5533b32017-02-23 11:04:38433void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
434 window_tree_host_manager_->cursor_window_controller()
435 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
436}
437
[email protected]87ec2202014-02-06 06:24:27438void Shell::SetCursorCompositingEnabled(bool enabled) {
oshimae2818922015-07-28 01:18:52439 window_tree_host_manager_->cursor_window_controller()
440 ->SetCursorCompositingEnabled(enabled);
[email protected]87ec2202014-02-06 06:24:27441 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
442}
[email protected]59ccade2013-10-17 17:56:40443
[email protected]f9466702012-09-17 16:35:27444void Shell::DoInitialWorkspaceAnimation() {
jamescookb8dcef522016-06-25 14:42:55445 return GetPrimaryRootWindowController()
446 ->workspace_controller()
447 ->DoInitialAnimation();
[email protected]f9466702012-09-17 16:35:27448}
449
sky00c813f2017-03-08 22:48:55450void Shell::AddShellObserver(ShellObserver* observer) {
451 shell_observers_.AddObserver(observer);
452}
453
454void Shell::RemoveShellObserver(ShellObserver* observer) {
455 shell_observers_.RemoveObserver(observer);
456}
457
sky7db5ccf2017-03-14 21:52:29458void Shell::ShowAppList() {
459 // Show the app list on the default display for new windows.
460 app_list_->Show(
461 GetWmRootWindowForNewWindows()->GetDisplayNearestWindow().id());
462}
463
464void Shell::DismissAppList() {
465 app_list_->Dismiss();
466}
467
468void Shell::ToggleAppList() {
469 // Toggle the app list on the default display for new windows.
470 app_list_->ToggleAppList(
471 GetWmRootWindowForNewWindows()->GetDisplayNearestWindow().id());
472}
473
474bool Shell::IsAppListVisible() const {
475 return app_list_->IsVisible();
476}
477
478bool Shell::GetAppListTargetVisibility() const {
479 return app_list_->GetTargetVisibility();
480}
481
sky5ad143a2017-03-22 04:31:23482void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
483 for (WmWindow* root_window : wm_shell_->GetAllRootWindows()) {
484 root_window->GetRootWindowController()->UpdateAfterLoginStatusChange(
485 status);
486 }
487}
488
sky00c813f2017-03-08 22:48:55489void Shell::NotifyMaximizeModeStarted() {
490 for (auto& observer : shell_observers_)
491 observer.OnMaximizeModeStarted();
492}
493
494void Shell::NotifyMaximizeModeEnding() {
495 for (auto& observer : shell_observers_)
496 observer.OnMaximizeModeEnding();
497}
498
499void Shell::NotifyMaximizeModeEnded() {
500 for (auto& observer : shell_observers_)
501 observer.OnMaximizeModeEnded();
502}
503
504void Shell::NotifyOverviewModeStarting() {
505 for (auto& observer : shell_observers_)
506 observer.OnOverviewModeStarting();
507}
508
509void Shell::NotifyOverviewModeEnded() {
510 for (auto& observer : shell_observers_)
511 observer.OnOverviewModeEnded();
512}
513
514void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
515 WmWindow* root_window) {
516 for (auto& observer : shell_observers_)
517 observer.OnFullscreenStateChanged(is_fullscreen, root_window);
518}
519
520void Shell::NotifyPinnedStateChanged(WmWindow* pinned_window) {
521 for (auto& observer : shell_observers_)
522 observer.OnPinnedStateChanged(pinned_window);
523}
524
xiyuan38160182017-03-14 22:50:13525void Shell::NotifyVirtualKeyboardActivated(bool activated,
526 WmWindow* root_window) {
sky00c813f2017-03-08 22:48:55527 for (auto& observer : shell_observers_)
xiyuan38160182017-03-14 22:50:13528 observer.OnVirtualKeyboardStateChanged(activated, root_window);
sky00c813f2017-03-08 22:48:55529}
530
531void Shell::NotifyShelfCreatedForRootWindow(WmWindow* root_window) {
532 for (auto& observer : shell_observers_)
533 observer.OnShelfCreatedForRootWindow(root_window);
534}
535
536void Shell::NotifyShelfAlignmentChanged(WmWindow* root_window) {
537 for (auto& observer : shell_observers_)
538 observer.OnShelfAlignmentChanged(root_window);
539}
540
541void Shell::NotifyShelfAutoHideBehaviorChanged(WmWindow* root_window) {
542 for (auto& observer : shell_observers_)
543 observer.OnShelfAutoHideBehaviorChanged(root_window);
544}
545
[email protected]b6ba05d902013-10-04 21:38:45546////////////////////////////////////////////////////////////////////////////////
547// Shell, private:
548
skyb073203a2017-03-13 16:59:16549Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
550 std::unique_ptr<WmShell> wm_shell)
skyabcae812017-01-18 17:01:34551 : wm_shell_(std::move(wm_shell)),
sky79fa34712017-03-20 23:46:47552 brightness_control_delegate_(
553 base::MakeUnique<system::BrightnessControllerChromeos>()),
554 cast_config_(base::MakeUnique<CastConfigController>()),
555 focus_cycler_(base::MakeUnique<FocusCycler>()),
sky5ab16472017-03-21 19:35:08556 immersive_context_(base::MakeUnique<ImmersiveContextAsh>()),
sky79fa34712017-03-20 23:46:47557 keyboard_brightness_control_delegate_(
558 base::MakeUnique<KeyboardBrightnessController>()),
559 locale_notification_controller_(
560 base::MakeUnique<LocaleNotificationController>()),
sky5ab16472017-03-21 19:35:08561 media_controller_(base::MakeUnique<MediaController>()),
562 new_window_controller_(base::MakeUnique<NewWindowController>()),
sky5ad143a2017-03-22 04:31:23563 session_controller_(base::MakeUnique<SessionController>()),
564 shelf_controller_(base::MakeUnique<ShelfController>()),
skyb073203a2017-03-13 16:59:16565 shell_delegate_(std::move(shell_delegate)),
sky5b45ed82017-03-27 02:54:23566 shutdown_controller_(base::MakeUnique<ShutdownController>()),
sky79fa34712017-03-20 23:46:47567 system_tray_controller_(base::MakeUnique<SystemTrayController>()),
sky5b45ed82017-03-27 02:54:23568 system_tray_notifier_(base::MakeUnique<SystemTrayNotifier>()),
569 vpn_list_(base::MakeUnique<VpnList>()),
570 window_cycle_controller_(base::MakeUnique<WindowCycleController>()),
571 window_selector_controller_(base::MakeUnique<WindowSelectorController>()),
sky7db5ccf2017-03-14 21:52:29572 app_list_(base::MakeUnique<app_list::AppList>()),
yusukes1168eda2016-04-27 07:52:08573 link_handler_model_factory_(nullptr),
jamescookac6724332017-03-21 02:54:43574 tray_bluetooth_helper_(base::MakeUnique<TrayBluetoothHelper>()),
kylechar7a067ec2017-01-07 01:16:28575 display_configurator_(new display::DisplayConfigurator()),
sadrul7a8785e2016-02-12 21:54:35576 native_cursor_manager_(nullptr),
[email protected]b6ba05d902013-10-04 21:38:45577 simulate_modal_window_open_for_testing_(false),
msw3f439af2016-09-08 22:35:26578 is_touch_hud_projection_enabled_(false) {
skyabcae812017-01-18 17:01:34579 // TODO(sky): better refactor cash/mash dependencies. Perhaps put all cash
580 // state on WmShellAura. http://crbug.com/671246.
581
582 if (!wm_shell_->IsRunningInMash()) {
skyb073203a2017-03-13 16:59:16583 gpu_support_.reset(shell_delegate_->CreateGPUSupport());
skyabcae812017-01-18 17:01:34584 display_manager_.reset(ScreenAsh::CreateDisplayManager());
585 window_tree_host_manager_.reset(new WindowTreeHostManager);
586 user_metrics_recorder_.reset(new UserMetricsRecorder);
587 }
[email protected]b6ba05d902013-10-04 21:38:45588
[email protected]093b8d642014-04-03 20:59:28589 PowerStatus::Initialize();
sky5ad143a2017-03-22 04:31:23590
591 session_controller_->AddSessionStateObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45592}
593
594Shell::~Shell() {
595 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
596
skyabcae812017-01-18 17:01:34597 const bool is_mash = wm_shell_->IsRunningInMash();
598
599 if (!is_mash)
600 user_metrics_recorder_->OnShellShuttingDown();
bruthigc24d11f2015-06-09 21:30:03601
skyb073203a2017-03-13 16:59:16602 shell_delegate_->PreShutdown();
[email protected]050e77182014-03-25 15:29:16603
[email protected]b6ba05d902013-10-04 21:38:45604 // Remove the focus from any window. This will prevent overhead and side
605 // effects (e.g. crashes) from changing focus during shutdown.
606 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18607 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45608
609 // Please keep in same order as in Init() because it's easy to miss one.
610 if (window_modality_controller_)
611 window_modality_controller_.reset();
skyabcae812017-01-18 17:01:34612 if (!is_mash) {
613 RemovePreTargetHandler(
614 window_tree_host_manager_->input_method_event_handler());
615 }
jamescook01bf23e72017-01-09 19:58:15616
[email protected]e4ea52362014-02-15 03:21:06617 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
618 magnifier_key_scroll_handler_.reset();
619
620 RemovePreTargetHandler(speech_feedback_handler_.get());
621 speech_feedback_handler_.reset();
jamescook01bf23e72017-01-09 19:58:15622
[email protected]b6ba05d902013-10-04 21:38:45623 RemovePreTargetHandler(overlay_filter_.get());
[email protected]3537d472014-01-15 05:45:31624 RemovePreTargetHandler(accelerator_filter_.get());
625 RemovePreTargetHandler(event_transformation_handler_.get());
626 RemovePreTargetHandler(toplevel_window_event_handler_.get());
627 RemovePostTargetHandler(toplevel_window_event_handler_.get());
skyabcae812017-01-18 17:01:34628 if (!is_mash) {
629 RemovePreTargetHandler(system_gesture_filter_.get());
630 RemovePreTargetHandler(mouse_cursor_filter_.get());
631 }
hariank0dd03dd2016-07-14 23:47:33632 RemovePreTargetHandler(modality_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45633
634 // TooltipController is deleted with the Shell so removing its references.
635 RemovePreTargetHandler(tooltip_controller_.get());
636
jonross0af45212015-01-13 18:55:46637 screen_orientation_controller_.reset();
yiyixa68ade512016-09-01 17:38:13638 screen_layout_observer_.reset();
jonross0af45212015-01-13 18:55:46639
jamescook01bf23e72017-01-09 19:58:15640 // Destroy the virtual keyboard controller before the maximize mode controller
641 // since the latters destructor triggers events that the former is listening
642 // to but no longer cares about.
rsadambbaf2c82015-01-07 17:54:13643 virtual_keyboard_controller_.reset();
jonross0af45212015-01-13 18:55:46644
[email protected]2a57beb52014-06-09 20:02:26645 // Destroy maximize mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57646 // need to be removed.
sky5ab16472017-03-21 19:35:08647 maximize_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57648
jdufault551152e2016-01-27 19:48:43649 // Destroy the keyboard before closing the shelf, since it will invoke a shelf
650 // layout.
651 DeactivateKeyboard();
652
sky07a24d42017-03-09 23:57:30653 toast_manager_.reset();
yoshiki32f51632016-03-24 01:24:43654
jdufault551152e2016-01-27 19:48:43655 // Destroy SystemTrayDelegate before destroying the status area(s). Make sure
656 // to deinitialize the shelf first, as it is initialized after the delegate.
jamescookb551aba2016-09-01 01:00:16657 for (WmWindow* root : wm_shell_->GetAllRootWindows())
658 root->GetRootWindowController()->GetShelf()->ShutdownShelfWidget();
jamescookac6724332017-03-21 02:54:43659 tray_bluetooth_helper_.reset();
sky79fa34712017-03-20 23:46:47660 DeleteSystemTrayDelegate();
[email protected]b6ba05d902013-10-04 21:38:45661
[email protected]b6ba05d902013-10-04 21:38:45662 // Drag-and-drop must be canceled prior to close all windows.
663 drag_drop_controller_.reset();
664
jamescookb8dcef522016-06-25 14:42:55665// Controllers who have WindowObserver added must be deleted
666// before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03667
[email protected]8c9d12a2013-12-06 18:39:03668 // VideoActivityNotifier must be deleted before |video_detector_| is
669 // deleted because it's observing video activity through
derat83b761392016-07-11 16:44:44670 // VideoDetector::Observer interface.
[email protected]8c9d12a2013-12-06 18:39:03671 video_activity_notifier_.reset();
[email protected]8c9d12a2013-12-06 18:39:03672 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25673 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03674
675 shadow_controller_.reset();
676 resize_shadow_controller_.reset();
677
sky37f0dd12016-07-19 18:00:59678 // Has to happen before ~MruWindowTracker.
sky5b45ed82017-03-27 02:54:23679 window_cycle_controller_.reset();
680 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03681
skyabcae812017-01-18 17:01:34682 CloseAllRootWindowChildWindows();
683
afakhry58159392015-05-22 02:45:52684 // MruWindowTracker must be destroyed after all windows have been deleted to
685 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
686 // path. (crbug.com/485438).
sky5ab16472017-03-21 19:35:08687 mru_window_tracker_.reset();
[email protected]b6ba05d902013-10-04 21:38:45688
[email protected]b6ba05d902013-10-04 21:38:45689 // These need a valid Shell instance to clean up properly, so explicitly
690 // delete them before invalidating the instance.
691 // Alphabetical. TODO(oshima): sort.
692 magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45693 tooltip_controller_.reset();
694 event_client_.reset();
[email protected]3537d472014-01-15 05:45:31695 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45696 visibility_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45697
698 power_button_controller_.reset();
699 lock_state_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45700
hidehiko6821ca42016-06-18 11:12:23701 screen_pinning_controller_.reset();
702
[email protected]b6ba05d902013-10-04 21:38:45703 resolution_notification_controller_.reset();
oshima5a296e82016-04-29 01:32:27704 screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49705 mouse_cursor_filter_.reset();
hariank0dd03dd2016-07-14 23:47:33706 modality_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45707
[email protected]03122891a2014-05-13 23:56:49708 touch_transformer_controller_.reset();
warx533c8f62016-04-12 01:19:43709 audio_a11y_controller_.reset();
sammiequon203ae022016-09-18 17:23:42710 laser_pointer_controller_.reset();
711 partial_magnification_controller_.reset();
warx533c8f62016-04-12 01:19:43712
[email protected]b6ba05d902013-10-04 21:38:45713 // This also deletes all RootWindows. Note that we invoke Shutdown() on
oshimae2818922015-07-28 01:18:52714 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
715 // destruction
[email protected]b6ba05d902013-10-04 21:38:45716 // of its owned RootWindowControllers relies on the value.
rjkroege2c9305402016-09-07 00:21:45717 ScreenAsh::CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12718 display_configuration_controller_.reset();
dtseng4ae0a882016-04-15 21:39:27719
sky15ef0aa2017-01-20 18:55:59720 // AppListDelegateImpl depends upon AppList.
721 app_list_delegate_impl_.reset();
722
sky07a24d42017-03-09 23:57:30723 // These members access Shell in their destructors.
724 wallpaper_controller_.reset();
725 accessibility_delegate_.reset();
726
727 // Balances the Install() in Initialize().
728 views::FocusManagerFactory::Install(nullptr);
729
sky5ad143a2017-03-22 04:31:23730 // ShelfWindowWatcher has window observers and a pointer to the shelf model.
731 shelf_window_watcher_.reset();
732
733 // ShelfItemDelegate subclasses it owns have complex cleanup to run (e.g. ARC
734 // shelf items in Chrome) so explicitly shutdown early.
735 shelf_model()->DestroyItemDelegates();
736
737 // Must be destroyed before FocusController.
738 shelf_delegate_.reset();
739
740 // Removes itself as an observer of |pref_store_|.
741 shelf_controller_.reset();
742
jamescook428f986f2016-07-15 19:13:25743 wm_shell_->Shutdown();
sky5ad143a2017-03-22 04:31:23744
sky27344382017-03-08 21:30:32745 // Depends on |focus_controller_|, so must be destroyed before.
oshimae2818922015-07-28 01:18:52746 window_tree_host_manager_.reset();
sky27344382017-03-08 21:30:32747 focus_controller_->RemoveObserver(this);
748 focus_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45749 screen_position_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45750
robert.bradfordab052492015-05-06 11:09:56751 display_color_manager_.reset();
[email protected]7bc49bd2014-01-22 09:30:34752 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11753 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45754 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11755 display_configurator_->RemoveObserver(display_error_observer_.get());
jdufault88fb76652015-04-30 22:36:43756 if (projecting_observer_) {
[email protected]1e31cbd2014-04-07 20:06:11757 display_configurator_->RemoveObserver(projecting_observer_.get());
sky00c813f2017-03-08 22:48:55758 RemoveShellObserver(projecting_observer_.get());
jdufault88fb76652015-04-30 22:36:43759 }
[email protected]b6ba05d902013-10-04 21:38:45760 display_change_observer_.reset();
kylechar98748a52016-12-03 01:33:22761 shutdown_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45762
[email protected]093b8d642014-04-03 20:59:28763 PowerStatus::Shutdown();
pneubeck8be1f5422014-10-09 16:46:18764
765 // Ensure that DBusThreadManager outlives this Shell.
766 DCHECK(chromeos::DBusThreadManager::IsInitialized());
[email protected]b6ba05d902013-10-04 21:38:45767
sky88bd4be62016-06-09 17:34:41768 // Needs to happen right before |instance_| is reset.
769 wm_shell_.reset();
sky5ad143a2017-03-22 04:31:23770 session_controller_->RemoveSessionStateObserver(this);
skyb073203a2017-03-13 16:59:16771 wallpaper_delegate_.reset();
772 pref_store_ = nullptr;
773 shell_delegate_.reset();
sky88bd4be62016-06-09 17:34:41774
[email protected]b6ba05d902013-10-04 21:38:45775 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18776 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45777}
778
[email protected]1b4c7472014-05-15 18:32:23779void Shell::Init(const ShellInitParams& init_params) {
skyabcae812017-01-18 17:01:34780 const bool is_mash = wm_shell_->IsRunningInMash();
781
sky07a24d42017-03-09 23:57:30782 blocking_pool_ = init_params.blocking_pool;
783
skyb073203a2017-03-13 16:59:16784 wallpaper_delegate_ = shell_delegate_->CreateWallpaperDelegate();
785
786 // Can be null in tests.
787 if (shell_delegate_->GetShellConnector()) {
788 prefs::mojom::PreferencesServiceFactoryPtr pref_factory_ptr;
789 shell_delegate_->GetShellConnector()->BindInterface(
790 prefs::mojom::kServiceName, &pref_factory_ptr);
791 pref_store_ = new preferences::PrefClientStore(std::move(pref_factory_ptr));
792 }
793
sky07a24d42017-03-09 23:57:30794 // Some delegates access WmShell during their construction. Create them here
795 // instead of the WmShell constructor.
skyb073203a2017-03-13 16:59:16796 accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate());
797 palette_delegate_ = shell_delegate_->CreatePaletteDelegate();
sky07a24d42017-03-09 23:57:30798 toast_manager_ = base::MakeUnique<ToastManager>();
799
sky07a24d42017-03-09 23:57:30800 // Install the custom factory early on so that views::FocusManagers for Tray,
801 // Shelf, and WallPaper could be created by the factory.
802 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
803
804 wallpaper_controller_ = base::MakeUnique<WallpaperController>(blocking_pool_);
805
806 // Start devtools server
807 devtools_server_ = ui::devtools::UiDevToolsServer::Create(nullptr);
808 if (devtools_server_) {
809 auto dom_backend = base::MakeUnique<devtools::AshDevToolsDOMAgent>();
810 auto css_backend =
811 base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_backend.get());
812 auto devtools_client = base::MakeUnique<ui::devtools::UiDevToolsClient>(
813 "Ash", devtools_server_.get());
814 devtools_client->AddAgent(std::move(dom_backend));
815 devtools_client->AddAgent(std::move(css_backend));
816 devtools_server_->AttachClient(std::move(devtools_client));
817 }
jamescook3daef412016-07-14 23:53:30818
sky15ef0aa2017-01-20 18:55:59819 if (is_mash)
820 app_list_delegate_impl_ = base::MakeUnique<AppListDelegateImpl>();
821
skyabcae812017-01-18 17:01:34822 // TODO(sky): move creation to WmShell.
823 if (!is_mash)
824 immersive_handler_factory_ = base::MakeUnique<ImmersiveHandlerFactoryAsh>();
skyb7b54092016-08-19 16:00:09825
sky6624a7af2016-05-27 18:47:49826 scoped_overview_animation_settings_factory_.reset(
827 new ScopedOverviewAnimationSettingsFactoryAura);
sky5ab16472017-03-21 19:35:08828 window_positioner_ = base::MakeUnique<WindowPositioner>();
sky984c1892016-04-20 00:00:34829
skyabcae812017-01-18 17:01:34830 if (!is_mash) {
831 native_cursor_manager_ = new AshNativeCursorManager;
832 cursor_manager_.reset(
833 new CursorManager(base::WrapUnique(native_cursor_manager_)));
834 }
skyfee520c2016-02-11 19:57:46835
skyb073203a2017-03-13 16:59:16836 shell_delegate_->PreInit();
skyabcae812017-01-18 17:01:34837 bool display_initialized = true;
838 if (!is_mash) {
839 display_initialized = display_manager_->InitFromCommandLine();
stevenjb537c5c3f2016-01-20 23:38:12840
skyabcae812017-01-18 17:01:34841 display_configuration_controller_.reset(new DisplayConfigurationController(
842 display_manager_.get(), window_tree_host_manager_.get()));
stevenjb537c5c3f2016-01-20 23:38:12843
oshimae001c8c2016-04-13 23:49:04844#if defined(USE_OZONE)
skyabcae812017-01-18 17:01:34845 display_configurator_->Init(
846 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(),
847 !gpu_support_->IsPanelFittingDisabled());
oshimae001c8c2016-04-13 23:49:04848#elif defined(USE_X11)
skyabcae812017-01-18 17:01:34849 display_configurator_->Init(
850 base::MakeUnique<display::NativeDisplayDelegateX11>(),
851 !gpu_support_->IsPanelFittingDisabled());
oshimae001c8c2016-04-13 23:49:04852#endif
skyabcae812017-01-18 17:01:34853 }
[email protected]0249a6532013-10-31 06:53:34854
pneubeck8be1f5422014-10-09 16:46:18855 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell.
856 chromeos::DBusThreadManager* dbus_thread_manager =
857 chromeos::DBusThreadManager::Get();
858 projecting_observer_.reset(
859 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient()));
[email protected]1e31cbd2014-04-07 20:06:11860 display_configurator_->AddObserver(projecting_observer_.get());
sky00c813f2017-03-08 22:48:55861 AddShellObserver(projecting_observer_.get());
[email protected]72bce522014-02-10 21:11:26862
reveman24158982017-01-10 05:58:45863 if (!display_initialized && chromeos::IsRunningAsSystemCompositor()) {
kylecharf2e4e412016-12-04 04:21:35864 display_change_observer_ = base::MakeUnique<display::DisplayChangeObserver>(
kylechar98748a52016-12-03 01:33:22865 display_configurator_.get(), display_manager_.get());
866
867 shutdown_observer_ =
868 base::MakeUnique<ShutdownObserver>(display_configurator_.get());
869
[email protected]b6ba05d902013-10-04 21:38:45870 // Register |display_change_observer_| first so that the rest of
871 // observer gets invoked after the root windows are configured.
[email protected]1e31cbd2014-04-07 20:06:11872 display_configurator_->AddObserver(display_change_observer_.get());
[email protected]093b8d642014-04-03 20:59:28873 display_error_observer_.reset(new DisplayErrorObserver());
[email protected]1e31cbd2014-04-07 20:06:11874 display_configurator_->AddObserver(display_error_observer_.get());
875 display_configurator_->set_state_controller(display_change_observer_.get());
876 display_configurator_->set_mirroring_controller(display_manager_.get());
877 display_configurator_->ForceInitialConfigure(
jamescookfda159002016-10-21 18:48:57878 base::CommandLine::ForCurrentProcess()->HasSwitch(
879 chromeos::switches::kFirstExecAfterBoot)
880 ? kChromeOsBootColor
881 : 0);
[email protected]b6ba05d902013-10-04 21:38:45882 display_initialized = true;
883 }
msw3f439af2016-09-08 22:35:26884 display_color_manager_.reset(new DisplayColorManager(
885 display_configurator_.get(), init_params.blocking_pool));
stevenjb537c5c3f2016-01-20 23:38:12886
[email protected]b6ba05d902013-10-04 21:38:45887 if (!display_initialized)
[email protected]0249a6532013-10-31 06:53:34888 display_manager_->InitDefaultDisplay();
[email protected]b6ba05d902013-10-04 21:38:45889
skyabcae812017-01-18 17:01:34890 if (!is_mash) {
891 display_manager_->RefreshFontParams();
[email protected]68d6080e2014-08-21 23:06:32892
skyabcae812017-01-18 17:01:34893 aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
894 aura::Env::GetInstance()->set_context_factory_private(
895 init_params.context_factory_private);
896 }
[email protected]ecca62b2013-10-09 16:18:53897
[email protected]b6ba05d902013-10-04 21:38:45898 // The WindowModalityController needs to be at the front of the input event
899 // pretarget handler list to ensure that it processes input events when modal
900 // windows are active.
jamescookb8dcef522016-06-25 14:42:55901 window_modality_controller_.reset(new ::wm::WindowModalityController(this));
[email protected]b6ba05d902013-10-04 21:38:45902
[email protected]e319c7e2014-03-14 19:56:14903 env_filter_.reset(new ::wm::CompoundEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45904 AddPreTargetHandler(env_filter_.get());
905
sky27344382017-03-08 21:30:32906 // FocusController takes ownership of AshFocusRules.
907 focus_controller_ =
908 base::MakeUnique<::wm::FocusController>(new wm::AshFocusRules());
909 focus_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45910
[email protected]093b8d642014-04-03 20:59:28911 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:45912
skyabcae812017-01-18 17:01:34913 wm_shell_->CreatePrimaryHost();
sky27344382017-03-08 21:30:32914 root_window_for_new_windows_ = WmWindow::Get(GetPrimaryRootWindow());
[email protected]b6ba05d902013-10-04 21:38:45915
skyabcae812017-01-18 17:01:34916 if (!is_mash) {
917 resolution_notification_controller_.reset(
918 new ResolutionNotificationController);
919 }
[email protected]b6ba05d902013-10-04 21:38:45920
deratc6250a02017-01-25 05:51:53921 if (cursor_manager_) {
oshimaf84b0da722016-04-27 19:47:19922 cursor_manager_->SetDisplay(
923 display::Screen::GetScreen()->GetPrimaryDisplay());
deratc6250a02017-01-25 05:51:53924 }
[email protected]b6ba05d902013-10-04 21:38:45925
sky81a2d792017-03-17 19:14:39926 accelerator_controller_ = wm_shell_->CreateAcceleratorController();
sky5ab16472017-03-21 19:35:08927 maximize_mode_controller_ = base::MakeUnique<MaximizeModeController>();
[email protected]b6ba05d902013-10-04 21:38:45928
skyabcae812017-01-18 17:01:34929 if (!is_mash) {
930 AddPreTargetHandler(
931 window_tree_host_manager_->input_method_event_handler());
932 }
oshima5e0fff82015-06-27 01:31:30933
spange9b51272014-12-11 01:20:10934 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06935 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
spange9b51272014-12-11 01:20:10936 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06937 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:39938
[email protected]b6ba05d902013-10-04 21:38:45939 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:45940
derat2d4e62d2015-01-09 16:09:17941 // ui::UserActivityDetector passes events to observers, so let them get
[email protected]b6ba05d902013-10-04 21:38:45942 // rewritten first.
derat2d4e62d2015-01-09 16:09:17943 user_activity_detector_.reset(new ui::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:45944
[email protected]093b8d642014-04-03 20:59:28945 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45946 AddPreTargetHandler(overlay_filter_.get());
sky00c813f2017-03-08 22:48:55947 AddShellObserver(overlay_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45948
[email protected]60d677d2014-05-30 13:07:02949 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
dchenga94547472016-04-08 08:41:11950 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
sky81a2d792017-03-17 19:14:39951 accelerator_controller_->accelerator_history()));
[email protected]b6ba05d902013-10-04 21:38:45952 AddPreTargetHandler(accelerator_filter_.get());
953
[email protected]093b8d642014-04-03 20:59:28954 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:45955 AddPreTargetHandler(event_transformation_handler_.get());
956
skycf67ed5a2016-05-23 19:38:39957 toplevel_window_event_handler_.reset(
sky0702b272016-06-03 22:10:41958 new ToplevelWindowEventHandler(wm_shell_.get()));
[email protected]3537d472014-01-15 05:45:31959
skyabcae812017-01-18 17:01:34960 if (!is_mash) {
961 system_gesture_filter_.reset(new SystemGestureEventFilter);
962 AddPreTargetHandler(system_gesture_filter_.get());
963 }
[email protected]b6ba05d902013-10-04 21:38:45964
[email protected]354520b2014-06-21 04:31:01965 sticky_keys_controller_.reset(new StickyKeysController);
skyabcae812017-01-18 17:01:34966 if (!is_mash) {
967 screen_pinning_controller_.reset(
968 new ScreenPinningController(window_tree_host_manager_.get()));
969 }
[email protected]354520b2014-06-21 04:31:01970
jamescookd9f152f2016-11-15 00:53:08971 lock_state_controller_ =
sky5b45ed82017-03-27 02:54:23972 base::MakeUnique<LockStateController>(shutdown_controller_.get());
jamescookb8dcef522016-06-25 14:42:55973 power_button_controller_.reset(
974 new PowerButtonController(lock_state_controller_.get()));
[email protected]685442f32014-02-28 10:40:06975 // Pass the initial display state to PowerButtonController.
976 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:09977 display_configurator_->cached_displays());
jamescook01bf23e72017-01-09 19:58:15978
sky00c813f2017-03-08 22:48:55979 AddShellObserver(lock_state_controller_.get());
[email protected]b6ba05d902013-10-04 21:38:45980
derat94887a22017-01-20 18:17:25981 // The connector is unavailable in some tests.
skyb073203a2017-03-13 16:59:16982 if (is_mash && shell_delegate_->GetShellConnector()) {
derat94887a22017-01-20 18:17:25983 ui::mojom::UserActivityMonitorPtr user_activity_monitor;
skyb073203a2017-03-13 16:59:16984 shell_delegate_->GetShellConnector()->BindInterface(ui::mojom::kServiceName,
985 &user_activity_monitor);
derat94887a22017-01-20 18:17:25986 user_activity_forwarder_ = base::MakeUnique<aura::UserActivityForwarder>(
987 std::move(user_activity_monitor), user_activity_detector_.get());
988 }
989
[email protected]093b8d642014-04-03 20:59:28990 drag_drop_controller_.reset(new DragDropController);
oshima5a296e82016-04-29 01:32:27991 // |screenshot_controller_| needs to be created (and prepended as a
mukai19274bdd2015-02-24 22:37:48992 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
oshima5a296e82016-04-29 01:32:27993 // process mouse events prior to screenshot session.
mukai19274bdd2015-02-24 22:37:48994 // See http://crbug.com/459214
oshima5a296e82016-04-29 01:32:27995 screenshot_controller_.reset(new ScreenshotController());
skyabcae812017-01-18 17:01:34996 if (!is_mash) {
997 mouse_cursor_filter_.reset(new MouseCursorEventFilter());
998 PrependPreTargetHandler(mouse_cursor_filter_.get());
999 }
[email protected]b6ba05d902013-10-04 21:38:451000
1001 // Create Controllers that may need root window.
1002 // TODO(oshima): Move as many controllers before creating
1003 // RootWindowController as possible.
1004 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:451005
sammiequon203ae022016-09-18 17:23:421006 laser_pointer_controller_.reset(new LaserPointerController());
1007 partial_magnification_controller_.reset(new PartialMagnificationController());
sammiequon203ae022016-09-18 17:23:421008
jamescookb8dcef522016-06-25 14:42:551009 magnification_controller_.reset(MagnificationController::CreateInstance());
sky5ab16472017-03-21 19:35:081010 mru_window_tracker_ = base::MakeUnique<MruWindowTracker>();
[email protected]b6ba05d902013-10-04 21:38:451011
[email protected]55398d22013-10-10 19:49:201012 autoclick_controller_.reset(AutoclickController::CreateInstance());
1013
[email protected]b6ba05d902013-10-04 21:38:451014 high_contrast_controller_.reset(new HighContrastController);
1015 video_detector_.reset(new VideoDetector);
[email protected]b6ba05d902013-10-04 21:38:451016
oshimaebbe63772015-02-19 18:41:321017 tooltip_controller_.reset(new views::corewm::TooltipController(
dchenga94547472016-04-08 08:41:111018 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451019 AddPreTargetHandler(tooltip_controller_.get());
1020
hariank0dd03dd2016-07-14 23:47:331021 modality_filter_.reset(new SystemModalContainerEventFilter(this));
1022 AddPreTargetHandler(modality_filter_.get());
1023
[email protected]093b8d642014-04-03 20:59:281024 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451025
skyb073203a2017-03-13 16:59:161026 session_state_delegate_.reset(shell_delegate_->CreateSessionStateDelegate());
skyabcae812017-01-18 17:01:341027 // Must occur after Shell has installed its early pre-target handlers (for
1028 // example, WindowModalityController).
jamescook0a9d02e2016-08-23 00:20:051029 wm_shell_->CreatePointerWatcherAdapter();
[email protected]b6ba05d902013-10-04 21:38:451030
[email protected]093b8d642014-04-03 20:59:281031 resize_shadow_controller_.reset(new ResizeShadowController());
sky27344382017-03-08 21:30:321032 shadow_controller_.reset(new ::wm::ShadowController(focus_controller_.get()));
[email protected]b6ba05d902013-10-04 21:38:451033
sky79fa34712017-03-20 23:46:471034 SetSystemTrayDelegate(
skyb073203a2017-03-13 16:59:161035 base::WrapUnique(shell_delegate_->CreateSystemTrayDelegate()));
[email protected]b6ba05d902013-10-04 21:38:451036
jamescookac6724332017-03-21 02:54:431037 // May trigger initialization of the Bluetooth adapter.
1038 tray_bluetooth_helper_->Initialize();
1039
kylechar55f0eaf22017-01-11 22:57:371040 // Create AshTouchTransformController before
oshimae2818922015-07-28 01:18:521041 // WindowTreeHostManager::InitDisplays()
kylechar55f0eaf22017-01-11 22:57:371042 // since AshTouchTransformController listens on
oshimae2818922015-07-28 01:18:521043 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
skyabcae812017-01-18 17:01:341044 if (!is_mash) {
1045 touch_transformer_controller_.reset(new AshTouchTransformController(
1046 display_configurator_.get(), display_manager_.get()));
1047 }
[email protected]03122891a2014-05-13 23:56:491048
sky79fa34712017-03-20 23:46:471049 keyboard_ui_ = wm_shell_->CreateKeyboardUI();
skyfee520c2016-02-11 19:57:461050
skyabcae812017-01-18 17:01:341051 wm_shell_->InitHosts(init_params);
[email protected]b6ba05d902013-10-04 21:38:451052
rsadam9172bc8a2014-10-29 23:37:381053 // Needs to be created after InitDisplays() since it may cause the virtual
1054 // keyboard to be deployed.
skyabcae812017-01-18 17:01:341055 if (!is_mash)
1056 virtual_keyboard_controller_.reset(new VirtualKeyboardController);
rsadam9172bc8a2014-10-29 23:37:381057
warx533c8f62016-04-12 01:19:431058 audio_a11y_controller_.reset(new chromeos::AudioA11yController);
warx533c8f62016-04-12 01:19:431059
msw0e91d932016-08-25 22:34:091060 // Initialize the wallpaper after the RootWindowController has been created,
1061 // otherwise the widget will not paint when restoring after a browser crash.
1062 // Also, initialize after display initialization to ensure correct sizing.
skyb073203a2017-03-13 16:59:161063 wallpaper_delegate_->InitializeWallpaper();
[email protected]b6ba05d902013-10-04 21:38:451064
sadrul7a8785e2016-02-12 21:54:351065 if (cursor_manager_) {
1066 if (initially_hide_cursor_)
1067 cursor_manager_->HideCursor();
1068 cursor_manager_->SetCursor(ui::kCursorPointer);
1069 }
[email protected]b6ba05d902013-10-04 21:38:451070
[email protected]093b8d642014-04-03 20:59:281071 power_event_observer_.reset(new PowerEventObserver());
[email protected]ded58fd2013-10-09 07:56:551072 user_activity_notifier_.reset(
[email protected]b0fa7012014-04-16 12:50:571073 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
[email protected]ded58fd2013-10-09 07:56:551074 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281075 new VideoActivityNotifier(video_detector_.get()));
1076 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
skyabcae812017-01-18 17:01:341077 if (!is_mash) {
1078 screen_orientation_controller_.reset(new ScreenOrientationController());
1079 screen_layout_observer_.reset(new ScreenLayoutObserver());
1080 }
yiyix90cfee22017-02-16 05:38:181081 sms_observer_.reset(new SmsObserver());
jamescook01bf23e72017-01-09 19:58:151082
[email protected]b6ba05d902013-10-04 21:38:451083 // The compositor thread and main message loop have to be running in
1084 // order to create mirror window. Run it after the main message loop
1085 // is started.
skyabcae812017-01-18 17:01:341086 if (!is_mash)
1087 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031088
sky00c813f2017-03-08 22:48:551089 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:181090 observer.OnShellInitialized();
phweiss0bf64c52015-11-17 12:56:181091
skyabcae812017-01-18 17:01:341092 if (!is_mash)
1093 user_metrics_recorder_->OnShellInitialized();
[email protected]b6ba05d902013-10-04 21:38:451094}
1095
[email protected]51f438112013-11-18 19:32:501096void Shell::InitKeyboard() {
[email protected]b6ba05d902013-10-04 21:38:451097 if (keyboard::IsKeyboardEnabled()) {
[email protected]a0b3fb882014-04-07 19:26:031098 if (keyboard::KeyboardController::GetInstance()) {
[email protected]b6ba05d902013-10-04 21:38:451099 RootWindowControllerList controllers = GetAllRootWindowControllers();
1100 for (RootWindowControllerList::iterator iter = controllers.begin();
1101 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:031102 (*iter)->DeactivateKeyboard(
1103 keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:451104 }
1105 }
[email protected]a0b3fb882014-04-07 19:26:031106 keyboard::KeyboardController::ResetInstance(
skyb073203a2017-03-13 16:59:161107 new keyboard::KeyboardController(shell_delegate_->CreateKeyboardUI(),
1108 virtual_keyboard_controller_.get()));
[email protected]b6ba05d902013-10-04 21:38:451109 }
1110}
1111
[email protected]41baaed2013-11-09 04:18:261112void Shell::InitRootWindow(aura::Window* root_window) {
sky27344382017-03-08 21:30:321113 DCHECK(focus_controller_);
[email protected]d90b8392012-06-13 09:34:561114 DCHECK(visibility_controller_.get());
1115 DCHECK(drag_drop_controller_.get());
[email protected]d90b8392012-06-13 09:34:561116
sky27344382017-03-08 21:30:321117 aura::client::SetFocusClient(root_window, focus_controller_.get());
1118 aura::client::SetActivationClient(root_window, focus_controller_.get());
1119 root_window->AddPreTargetHandler(focus_controller_.get());
[email protected]d90b8392012-06-13 09:34:561120 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
1121 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]8d625fb2012-07-18 16:40:061122 aura::client::SetScreenPositionClient(root_window,
1123 screen_position_controller_.get());
sadrul7a8785e2016-02-12 21:54:351124 aura::client::SetCursorClient(root_window, cursor_manager_.get());
[email protected]54a37cdc2012-07-25 19:16:011125 aura::client::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381126 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561127
[email protected]3537d472014-01-15 05:45:311128 aura::client::SetWindowMoveClient(root_window,
jamescookb8dcef522016-06-25 14:42:551129 toplevel_window_event_handler_.get());
[email protected]3537d472014-01-15 05:45:311130 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1131 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
[email protected]d90b8392012-06-13 09:34:561132}
1133
sky79fa34712017-03-20 23:46:471134void Shell::SetSystemTrayDelegate(
1135 std::unique_ptr<SystemTrayDelegate> delegate) {
1136 DCHECK(delegate);
1137 system_tray_delegate_ = std::move(delegate);
1138 system_tray_delegate_->Initialize();
1139 // Accesses WmShell in its constructor.
1140 logout_confirmation_controller_.reset(new LogoutConfirmationController(
1141 base::Bind(&SystemTrayController::SignOut,
1142 base::Unretained(system_tray_controller_.get()))));
1143}
1144
1145void Shell::DeleteSystemTrayDelegate() {
1146 DCHECK(system_tray_delegate_);
1147 // Accesses WmShell in its destructor.
1148 logout_confirmation_controller_.reset();
1149 system_tray_delegate_.reset();
1150}
1151
skyabcae812017-01-18 17:01:341152void Shell::CloseAllRootWindowChildWindows() {
1153 for (WmWindow* wm_root_window : wm_shell_->GetAllRootWindows()) {
1154 aura::Window* root_window = wm_root_window->aura_window();
1155 RootWindowController* controller = GetRootWindowController(root_window);
1156 if (controller) {
1157 controller->CloseChildWindows();
1158 } else {
1159 while (!root_window->children().empty()) {
1160 aura::Window* child = root_window->children()[0];
1161 delete child;
1162 }
1163 }
1164 }
1165}
1166
sky5ad143a2017-03-22 04:31:231167void Shell::CreateShelfDelegate() {
1168 // May be called multiple times as shelves are created and destroyed.
1169 if (shelf_delegate_)
1170 return;
1171 // Must occur after SessionController creation and user login because
1172 // Chrome's implementation of ShelfDelegate assumes it can get information
1173 // about multi-profile login state.
1174 DCHECK(session_controller());
1175 DCHECK_GT(session_controller()->NumberOfLoggedInUsers(), 0);
1176 shelf_delegate_.reset(shell_delegate_->CreateShelfDelegate(shelf_model()));
1177 shelf_window_watcher_ = base::MakeUnique<ShelfWindowWatcher>(shelf_model());
1178}
1179
[email protected]c0ce80e2012-10-05 23:28:271180bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1181 RootWindowControllerList controllers = GetAllRootWindowControllers();
oshima9a61ecf2016-06-18 10:43:051182 for (RootWindowController* controller : controllers) {
1183 if (controller->CanWindowReceiveEvents(window))
[email protected]602022b2014-03-31 17:07:311184 return true;
[email protected]c0ce80e2012-10-05 23:28:271185 }
1186 return false;
1187}
1188
[email protected]049cf34b2012-12-07 17:15:481189////////////////////////////////////////////////////////////////////////////////
1190// Shell, ui::EventTarget overrides:
1191
[email protected]869f6352012-12-06 20:47:171192bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411193 return true;
1194}
1195
1196ui::EventTarget* Shell::GetParentTarget() {
[email protected]ff0278852013-11-05 22:35:481197 return aura::Env::GetInstance();
[email protected]5097e692012-10-30 22:08:411198}
1199
dchenga94547472016-04-08 08:41:111200std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1201 return std::unique_ptr<ui::EventTargetIterator>();
[email protected]3e670aa2013-12-02 19:04:321202}
1203
1204ui::EventTargeter* Shell::GetEventTargeter() {
1205 NOTREACHED();
achuith287b26e2015-09-03 17:49:181206 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321207}
1208
sky27344382017-03-08 21:30:321209void Shell::OnWindowActivated(
1210 aura::client::ActivationChangeObserver::ActivationReason reason,
1211 aura::Window* gained_active,
1212 aura::Window* lost_active) {
1213 WmWindow* gained_active_wm = WmWindow::Get(gained_active);
1214 if (gained_active_wm)
1215 root_window_for_new_windows_ = gained_active_wm->GetRootWindow();
1216}
1217
sky5ad143a2017-03-22 04:31:231218void Shell::SessionStateChanged(session_manager::SessionState state) {
1219 // Create the shelf when a session becomes active. It's safe to do this
1220 // multiple times (e.g. initial login vs. multiprofile add session).
1221 if (state == session_manager::SessionState::ACTIVE) {
1222 CreateShelfView();
1223
1224 if (!wm_shell_->IsRunningInMash()) {
1225 // Recreate the keyboard after initial login and after multiprofile login.
1226 CreateKeyboard();
1227 }
1228 }
1229
1230 // Only trigger an update in mash because with classic ash chrome calls
1231 // UpdateAfterLoginStatusChange() directly.
1232 if (wm_shell_->IsRunningInMash()) {
1233 // TODO(jamescook): Should this call Shell::OnLoginStatusChanged() too?
1234 UpdateAfterLoginStatusChange(session_controller_->GetLoginStatus());
1235 }
1236}
1237
[email protected]55f593352011-12-24 05:42:461238} // namespace ash