blob: 3a2b370605fc40d510b5136376790ac09d9df1f4 [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
James Cookb0bf8e82017-04-09 17:01:4411#include "ash/accelerators/accelerator_controller.h"
[email protected]60d677d2014-05-30 13:07:0212#include "ash/accelerators/accelerator_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4413#include "ash/accelerators/ash_focus_manager_factory.h"
jamescook01bf23e72017-01-09 19:58:1514#include "ash/accelerators/magnifier_key_scroller.h"
15#include "ash/accelerators/spoken_feedback_toggler.h"
James Cookb0bf8e82017-04-09 17:01:4416#include "ash/accessibility_delegate.h"
sky15ef0aa2017-01-20 18:55:5917#include "ash/app_list/app_list_delegate_impl.h"
James Cookb0bf8e82017-04-09 17:01:4418#include "ash/ash_constants.h"
sky11cf8db92017-04-10 23:38:0819#include "ash/aura/shell_port_classic.h"
[email protected]55398d22013-10-10 19:49:2020#include "ash/autoclick/autoclick_controller.h"
James Cookb0bf8e82017-04-09 17:01:4421#include "ash/cast_config_controller.h"
22#include "ash/devtools/ash_devtools_css_agent.h"
23#include "ash/devtools/ash_devtools_dom_agent.h"
[email protected]87ec2202014-02-06 06:24:2724#include "ash/display/cursor_window_controller.h"
jamescook01bf23e72017-01-09 19:58:1525#include "ash/display/display_color_manager_chromeos.h"
stevenjb537c5c3f2016-01-20 23:38:1226#include "ash/display/display_configuration_controller.h"
jamescook01bf23e72017-01-09 19:58:1527#include "ash/display/display_error_observer_chromeos.h"
[email protected]682990f2013-01-10 06:49:1128#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2729#include "ash/display/mouse_cursor_event_filter.h"
jamescook01bf23e72017-01-09 19:58:1530#include "ash/display/projecting_observer_chromeos.h"
31#include "ash/display/resolution_notification_controller.h"
rjkroege2c9305402016-09-07 00:21:4532#include "ash/display/screen_ash.h"
jamescook01bf23e72017-01-09 19:58:1533#include "ash/display/screen_orientation_controller_chromeos.h"
[email protected]8d625fb2012-07-18 16:40:0634#include "ash/display/screen_position_controller.h"
jamescook01bf23e72017-01-09 19:58:1535#include "ash/display/shutdown_observer_chromeos.h"
oshimae2818922015-07-28 01:18:5236#include "ash/display/window_tree_host_manager.h"
[email protected]f4c92b382012-08-28 00:59:5937#include "ash/drag_drop/drag_drop_controller.h"
[email protected]59ccade2013-10-17 17:56:4038#include "ash/first_run/first_run_helper_impl.h"
James Cookb0bf8e82017-04-09 17:01:4439#include "ash/focus_cycler.h"
40#include "ash/frame/custom_frame_view_ash.h"
41#include "ash/gpu_support.h"
[email protected]f4c92b382012-08-28 00:59:5942#include "ash/high_contrast/high_contrast_controller.h"
oshima5e0fff82015-06-27 01:31:3043#include "ash/ime/input_method_event_handler.h"
James Cookb0bf8e82017-04-09 17:01:4444#include "ash/keyboard/keyboard_ui.h"
sammiequon203ae022016-09-18 17:23:4245#include "ash/laser/laser_pointer_controller.h"
James Cookb0bf8e82017-04-09 17:01:4446#include "ash/login_status.h"
[email protected]f4c92b382012-08-28 00:59:5947#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5448#include "ash/magnifier/partial_magnification_controller.h"
James Cookb0bf8e82017-04-09 17:01:4449#include "ash/media_controller.h"
50#include "ash/new_window_controller.h"
51#include "ash/palette_delegate.h"
sky494c6cbd2017-03-27 20:57:4852#include "ash/public/cpp/config.h"
jamescook8800b8232016-10-19 12:46:2753#include "ash/public/cpp/shell_window_ids.h"
[email protected]d90b8392012-06-13 09:34:5654#include "ash/root_window_controller.h"
James Cookb0bf8e82017-04-09 17:01:4455#include "ash/session/session_controller.h"
56#include "ash/session/session_state_delegate.h"
57#include "ash/shelf/shelf_controller.h"
58#include "ash/shelf/shelf_delegate.h"
59#include "ash/shelf/shelf_model.h"
60#include "ash/shelf/shelf_window_watcher.h"
61#include "ash/shelf/wm_shelf.h"
62#include "ash/shell_delegate.h"
[email protected]1b4c7472014-05-15 18:32:2363#include "ash/shell_init_params.h"
James Cookb0bf8e82017-04-09 17:01:4464#include "ash/shell_observer.h"
sky11cf8db92017-04-10 23:38:0865#include "ash/shell_port.h"
James Cookb0bf8e82017-04-09 17:01:4466#include "ash/shutdown_controller.h"
jamescook01bf23e72017-01-09 19:58:1567#include "ash/sticky_keys/sticky_keys_controller.h"
James Cooka35a1e22017-04-08 02:33:0868#include "ash/system/bluetooth/bluetooth_notification_controller.h"
69#include "ash/system/bluetooth/tray_bluetooth_helper.h"
70#include "ash/system/brightness/brightness_controller_chromeos.h"
James Cookb0bf8e82017-04-09 17:01:4471#include "ash/system/brightness_control_delegate.h"
72#include "ash/system/keyboard_brightness_control_delegate.h"
James Cooka35a1e22017-04-08 02:33:0873#include "ash/system/keyboard_brightness_controller.h"
James Cookb0bf8e82017-04-09 17:01:4474#include "ash/system/locale/locale_notification_controller.h"
James Cooka35a1e22017-04-08 02:33:0875#include "ash/system/network/sms_observer.h"
76#include "ash/system/network/vpn_list.h"
77#include "ash/system/power/power_event_observer.h"
78#include "ash/system/power/power_status.h"
79#include "ash/system/power/video_activity_notifier.h"
80#include "ash/system/screen_layout_observer.h"
81#include "ash/system/session/logout_confirmation_controller.h"
James Cookb0bf8e82017-04-09 17:01:4482#include "ash/system/status_area_widget.h"
83#include "ash/system/toast/toast_manager.h"
84#include "ash/system/tray/system_tray_controller.h"
85#include "ash/system/tray/system_tray_delegate.h"
86#include "ash/system/tray/system_tray_notifier.h"
kylechar55f0eaf22017-01-11 22:57:3787#include "ash/touch/ash_touch_transform_controller.h"
oshima5a296e82016-04-29 01:32:2788#include "ash/utility/screenshot_controller.h"
jamescook01bf23e72017-01-09 19:58:1589#include "ash/virtual_keyboard_controller.h"
James Cookb0bf8e82017-04-09 17:01:4490#include "ash/wallpaper/wallpaper_controller.h"
91#include "ash/wallpaper/wallpaper_delegate.h"
[email protected]39718b52012-12-03 17:24:5692#include "ash/wm/ash_focus_rules.h"
[email protected]c0ff0342013-02-27 00:41:2993#include "ash/wm/ash_native_cursor_manager.h"
James Cookb0bf8e82017-04-09 17:01:4494#include "ash/wm/container_finder.h"
[email protected]262f8bd2012-03-23 19:30:2795#include "ash/wm/event_client_impl.h"
James Cookb0bf8e82017-04-09 17:01:4496#include "ash/wm/immersive_context_ash.h"
skyb7b54092016-08-19 16:00:0997#include "ash/wm/immersive_handler_factory_ash.h"
[email protected]ab4f8c92013-05-30 19:07:4798#include "ash/wm/lock_state_controller.h"
James Cookb0bf8e82017-04-09 17:01:4499#include "ash/wm/maximize_mode/maximize_mode_controller.h"
100#include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
101#include "ash/wm/mru_window_tracker.h"
[email protected]9ae32df2012-07-26 03:25:18102#include "ash/wm/overlay_event_filter.h"
sky6624a7af2016-05-27 18:47:49103#include "ash/wm/overview/scoped_overview_animation_settings_factory_aura.h"
James Cookb0bf8e82017-04-09 17:01:44104#include "ash/wm/overview/window_selector_controller.h"
[email protected]e0d22e82012-01-04 00:46:57105#include "ash/wm/power_button_controller.h"
[email protected]e4a181cc2012-03-17 02:20:57106#include "ash/wm/resize_shadow_controller.h"
James Cookb0bf8e82017-04-09 17:01:44107#include "ash/wm/root_window_finder.h"
hidehiko6821ca42016-06-18 11:12:23108#include "ash/wm/screen_pinning_controller.h"
[email protected]435b212e2012-04-05 19:43:37109#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:27110#include "ash/wm/system_modal_container_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44111#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]3537d472014-01-15 05:45:31112#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:58113#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:02114#include "ash/wm/window_animations.h"
James Cookb0bf8e82017-04-09 17:01:44115#include "ash/wm/window_cycle_controller.h"
116#include "ash/wm/window_positioner.h"
[email protected]f059c6942012-07-21 14:27:57117#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:59118#include "ash/wm/window_util.h"
James Cookb0bf8e82017-04-09 17:01:44119#include "ash/wm/workspace_controller.h"
James Cookb0bf8e82017-04-09 17:01:44120#include "ash/wm_window.h"
[email protected]f296be72011-10-11 15:40:00121#include "base/bind.h"
jamescook01bf23e72017-01-09 19:58:15122#include "base/bind_helpers.h"
jamescookfda159002016-10-21 18:48:57123#include "base/command_line.h"
dchenga94547472016-04-08 08:41:11124#include "base/memory/ptr_util.h"
jamescook01bf23e72017-01-09 19:58:15125#include "base/sys_info.h"
tzik0dd58d42017-02-15 08:26:52126#include "base/threading/sequenced_worker_pool.h"
primiano7182d7b2015-01-30 18:02:03127#include "base/trace_event/trace_event.h"
jamescook01bf23e72017-01-09 19:58:15128#include "chromeos/audio/audio_a11y_controller.h"
129#include "chromeos/chromeos_switches.h"
130#include "chromeos/dbus/dbus_thread_manager.h"
reveman24158982017-01-10 05:58:45131#include "chromeos/system/devicemode.h"
tibellb93c729b2017-03-30 00:45:09132#include "components/prefs/pref_registry_simple.h"
133#include "components/prefs/pref_service.h"
sky07a24d42017-03-09 23:57:30134#include "components/ui_devtools/devtools_server.h"
tibellb93c729b2017-03-30 00:45:09135#include "services/preferences/public/cpp/pref_service_factory.h"
skyb073203a2017-03-13 16:59:16136#include "services/preferences/public/interfaces/preferences.mojom.h"
derat94887a22017-01-20 18:17:25137#include "services/service_manager/public/cpp/connector.h"
138#include "services/ui/public/interfaces/constants.mojom.h"
sky7db5ccf2017-03-14 21:52:29139#include "ui/app_list/presenter/app_list.h"
[email protected]2c456102011-12-26 06:26:34140#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:44141#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:58142#include "ui/aura/layout_manager.h"
derat94887a22017-01-20 18:17:25143#include "ui/aura/mus/user_activity_forwarder.h"
[email protected]87b0d82e2011-10-07 21:02:59144#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:26145#include "ui/aura/window_event_dispatcher.h"
[email protected]2d4817742012-12-17 20:16:18146#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:17147#include "ui/base/user_activity/user_activity_detector.h"
jamescook01bf23e72017-01-09 19:58:15148#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]116302fc2012-05-05 21:45:41149#include "ui/compositor/layer.h"
150#include "ui/compositor/layer_animator.h"
oshimaf84b0da722016-04-27 19:47:19151#include "ui/display/display.h"
jamescook01bf23e72017-01-09 19:58:15152#include "ui/display/manager/chromeos/display_change_observer.h"
153#include "ui/display/manager/chromeos/display_configurator.h"
rjkroege72f8154f2016-10-29 00:49:02154#include "ui/display/manager/display_manager.h"
oshimaf84b0da722016-04-27 19:47:19155#include "ui/display/screen.h"
[email protected]3e670aa2013-12-02 19:04:32156#include "ui/events/event_target_iterator.h"
sky4ec2be82017-01-06 17:38:32157#include "ui/gfx/geometry/insets.h"
[email protected]9ec0f452012-05-31 15:58:53158#include "ui/gfx/image/image_skia.h"
[email protected]b6ba05d902013-10-04 21:38:45159#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28160#include "ui/keyboard/keyboard_switches.h"
[email protected]f1d5c3a2013-04-23 17:42:56161#include "ui/keyboard/keyboard_util.h"
[email protected]d7f30a72013-10-05 05:09:41162#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04163#include "ui/views/corewm/tooltip_controller.h"
sky07a24d42017-03-09 23:57:30164#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:58165#include "ui/views/widget/native_widget_aura.h"
166#include "ui/views/widget/widget.h"
[email protected]60d677d2014-05-30 13:07:02167#include "ui/wm/core/accelerator_filter.h"
[email protected]ee3ed10772014-03-11 22:02:01168#include "ui/wm/core/compound_event_filter.h"
169#include "ui/wm/core/focus_controller.h"
[email protected]ee3ed10772014-03-11 22:02:01170#include "ui/wm/core/shadow_controller.h"
171#include "ui/wm/core/visibility_controller.h"
172#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59173
oshimae001c8c2016-04-13 23:49:04174#if defined(USE_X11)
kylechar731f85f92016-12-01 20:50:46175#include "ui/display/manager/chromeos/x11/native_display_delegate_x11.h"
jamescook01bf23e72017-01-09 19:58:15176#include "ui/gfx/x/x11_types.h" // nogncheck
oshimae001c8c2016-04-13 23:49:04177#endif
178
179#if defined(USE_OZONE)
180#include "ui/display/types/native_display_delegate.h"
181#include "ui/ozone/public/ozone_platform.h"
182#endif
[email protected]70b3e7d52012-06-02 22:12:25183
[email protected]55f593352011-12-24 05:42:46184namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59185
186namespace {
[email protected]671a2ae2011-10-13 21:53:23187
[email protected]615922f2012-02-07 02:41:15188using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45189using views::Widget;
190
[email protected]b5756e22012-11-30 01:32:02191// A Corewm VisibilityController subclass that calls the Ash animation routine
192// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14193class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02194 public:
195 AshVisibilityController() {}
dcheng1f4538e2014-10-27 23:57:05196 ~AshVisibilityController() override {}
[email protected]b5756e22012-11-30 01:32:02197
198 private:
[email protected]e319c7e2014-03-14 19:56:14199 // Overridden from ::wm::VisibilityController:
dcheng1f4538e2014-10-27 23:57:05200 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
201 bool visible) override {
[email protected]b5756e22012-11-30 01:32:02202 return AnimateOnChildWindowVisibilityChanged(window, visible);
203 }
204
205 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
206};
207
[email protected]87b0d82e2011-10-07 21:02:59208} // namespace
209
[email protected]cac10fc62011-10-07 23:22:56210// static
achuith287b26e2015-09-03 17:49:18211Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13212// static
sky00f98a372017-01-11 06:03:49213aura::WindowTreeClient* Shell::window_tree_client_ = nullptr;
214// static
skya8b222f2017-01-12 15:47:13215aura::WindowManagerClient* Shell::window_manager_client_ = nullptr;
216// static
[email protected]9488d4d2012-02-29 18:32:37217bool Shell::initially_hide_cursor_ = false;
[email protected]2b4cd302012-02-24 20:21:13218
219////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56220// Shell, public:
221
[email protected]cac10fc62011-10-07 23:22:56222// static
[email protected]1b4c7472014-05-15 18:32:23223Shell* Shell::CreateInstance(const ShellInitParams& init_params) {
[email protected]3266c2b92011-11-14 00:06:08224 CHECK(!instance_);
sky11cf8db92017-04-10 23:38:08225 ShellPort* shell_port = init_params.shell_port;
226 if (!shell_port)
227 shell_port = new ShellPortClassic();
skyb073203a2017-03-13 16:59:16228 instance_ = new Shell(base::WrapUnique<ShellDelegate>(init_params.delegate),
sky11cf8db92017-04-10 23:38:08229 base::WrapUnique<ShellPort>(shell_port));
[email protected]1b4c7472014-05-15 18:32:23230 instance_->Init(init_params);
[email protected]3266c2b92011-11-14 00:06:08231 return instance_;
232}
233
234// static
skyb073203a2017-03-13 16:59:16235Shell* Shell::Get() {
oshima9eea82da2014-09-13 01:11:07236 CHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56237 return instance_;
238}
239
[email protected]6377a002011-11-10 20:26:47240// static
[email protected]b3b7bcd2012-03-06 19:35:45241bool Shell::HasInstance() {
242 return !!instance_;
243}
244
245// static
[email protected]ef589af2011-12-03 01:07:15246void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47247 delete instance_;
[email protected]6377a002011-11-10 20:26:47248}
249
[email protected]e73bd7802012-02-17 20:10:34250// static
[email protected]093b8d642014-04-03 20:59:28251RootWindowController* Shell::GetPrimaryRootWindowController() {
oshima9eea82da2014-09-13 01:11:07252 CHECK(HasInstance());
[email protected]093b8d642014-04-03 20:59:28253 return GetRootWindowController(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23254}
255
256// static
257Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
oshima9eea82da2014-09-13 01:11:07258 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34259 RootWindowControllerList root_window_controllers;
sky11cf8db92017-04-10 23:38:08260 for (WmWindow* root_window : instance_->shell_port_->GetAllRootWindows())
skyabcae812017-01-18 17:01:34261 root_window_controllers.push_back(root_window->GetRootWindowController());
262 return root_window_controllers;
[email protected]d90b8392012-06-13 09:34:56263}
264
265// static
thanhphc90f49ca2017-03-03 17:48:53266RootWindowController* Shell::GetRootWindowControllerWithDisplayId(
267 int64_t display_id) {
268 CHECK(HasInstance());
269 WmWindow* root_window =
sky11cf8db92017-04-10 23:38:08270 instance_->shell_port_->GetRootWindowForDisplayId(display_id);
thanhphc90f49ca2017-03-03 17:48:53271 return root_window ? root_window->GetRootWindowController() : nullptr;
272}
273
274// static
[email protected]bf9cdb362013-10-25 19:22:45275aura::Window* Shell::GetPrimaryRootWindow() {
oshima9eea82da2014-09-13 01:11:07276 CHECK(HasInstance());
sky11cf8db92017-04-10 23:38:08277 return instance_->shell_port_->GetPrimaryRootWindow()->aura_window();
[email protected]e73bd7802012-02-17 20:10:34278}
279
[email protected]7b0f7502012-06-11 00:12:39280// static
sky27344382017-03-08 21:30:32281aura::Window* Shell::GetRootWindowForNewWindows() {
282 CHECK(Shell::HasInstance());
283 return WmWindow::GetAuraWindow(Shell::GetWmRootWindowForNewWindows());
[email protected]a857dbe2012-05-30 22:10:14284}
285
[email protected]7b0f7502012-06-11 00:12:39286// static
sky27344382017-03-08 21:30:32287WmWindow* Shell::GetWmRootWindowForNewWindows() {
288 CHECK(Shell::HasInstance());
skycb4be5b2017-04-06 17:52:45289 Shell* shell = Shell::Get();
sky27344382017-03-08 21:30:32290 if (shell->scoped_root_window_for_new_windows_)
291 return shell->scoped_root_window_for_new_windows_;
292 return shell->root_window_for_new_windows_;
mfomitcheva1a8aa62016-05-03 16:23:26293}
294
295// static
[email protected]c9390bd2013-11-08 20:33:13296aura::Window::Windows Shell::GetAllRootWindows() {
oshima9eea82da2014-09-13 01:11:07297 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34298 aura::Window::Windows windows;
sky11cf8db92017-04-10 23:38:08299 for (WmWindow* window : instance_->shell_port_->GetAllRootWindows())
skyabcae812017-01-18 17:01:34300 windows.push_back(window->aura_window());
301 return windows;
[email protected]be65be362012-06-15 07:38:23302}
303
304// static
jamescookb8dcef522016-06-25 14:42:55305aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) {
[email protected]7b0f7502012-06-11 00:12:39306 return root_window->GetChildById(container_id);
307}
308
309// static
[email protected]bf9cdb362013-10-25 19:22:45310const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38311 int container_id) {
312 return root_window->GetChildById(container_id);
313}
314
sky494c6cbd2017-03-27 20:57:48315// static
jamescook0dfe5632017-04-05 18:49:02316Config Shell::GetAshConfig() {
sky11cf8db92017-04-10 23:38:08317 return Get()->shell_port_->GetAshConfig();
sky494c6cbd2017-03-27 20:57:48318}
319
[email protected]57b8bb352012-01-11 05:11:46320views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
321 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04322 // Use translucent-style window frames for dialogs.
[email protected]85501fe2013-10-18 10:15:27323 return new CustomFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46324}
325
[email protected]2e236a52012-06-27 22:21:47326void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44327 const gfx::Insets& insets) {
sky11cf8db92017-04-10 23:38:08328 shell_port_->SetDisplayWorkAreaInsets(WmWindow::Get(contains), insets);
[email protected]1a2145b2012-03-13 21:09:17329}
330
[email protected]82d3954ae2012-04-20 09:02:22331void Shell::OnAppTerminating() {
sky00c813f2017-03-08 22:48:55332 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18333 observer.OnAppTerminating();
[email protected]82d3954ae2012-04-20 09:02:22334}
335
[email protected]58868abf2014-01-17 23:45:33336void Shell::OnCastingSessionStartedOrStopped(bool started) {
sky00c813f2017-03-08 22:48:55337 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18338 observer.OnCastingSessionStartedOrStopped(started);
[email protected]58868abf2014-01-17 23:45:33339}
340
sky80556bc42016-06-07 22:46:13341void Shell::OnRootWindowAdded(WmWindow* root_window) {
sky00c813f2017-03-08 22:48:55342 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18343 observer.OnRootWindowAdded(root_window);
[email protected]0e3e7cb2014-04-12 05:18:25344}
345
[email protected]51f438112013-11-18 19:32:50346void Shell::CreateKeyboard() {
[email protected]51f438112013-11-18 19:32:50347 InitKeyboard();
jamescookb8dcef522016-06-25 14:42:55348 GetPrimaryRootWindowController()->ActivateKeyboard(
349 keyboard::KeyboardController::GetInstance());
[email protected]51f438112013-11-18 19:32:50350}
351
[email protected]e1b299b2014-01-29 23:53:41352void Shell::DeactivateKeyboard() {
sky11cf8db92017-04-10 23:38:08353 // TODO(jamescook): Move keyboard create and hide into ShellPort.
sky79fa34712017-03-20 23:46:47354 keyboard_ui_->Hide();
[email protected]a0b3fb882014-04-07 19:26:03355 if (keyboard::KeyboardController::GetInstance()) {
[email protected]e1b299b2014-01-29 23:53:41356 RootWindowControllerList controllers = GetAllRootWindowControllers();
357 for (RootWindowControllerList::iterator iter = controllers.begin();
jamescookb8dcef522016-06-25 14:42:55358 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:03359 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]e1b299b2014-01-29 23:53:41360 }
361 }
achuith287b26e2015-09-03 17:49:18362 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]e1b299b2014-01-29 23:53:41363}
364
[email protected]da285852014-05-27 19:53:43365bool Shell::ShouldSaveDisplaySettings() {
skye5fd1222017-04-12 18:43:23366 DCHECK(GetAshConfig() != Config::MASH);
jamescookb8dcef522016-06-25 14:42:55367 return !(
368 screen_orientation_controller_->ignore_display_configuration_updates() ||
369 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43370}
[email protected]da285852014-05-27 19:53:43371
sky5ad143a2017-03-22 04:31:23372ShelfModel* Shell::shelf_model() {
373 return shelf_controller_->model();
374}
375
sky27344382017-03-08 21:30:32376aura::client::ActivationClient* Shell::activation_client() {
377 return focus_controller_.get();
378}
379
[email protected]c758fbf2012-03-25 22:53:59380void Shell::UpdateShelfVisibility() {
sky11cf8db92017-04-10 23:38:08381 for (WmWindow* root : shell_port_->GetAllRootWindows())
jamescookb551aba2016-09-01 01:00:16382 root->GetRootWindowController()->GetShelf()->UpdateVisibilityState();
[email protected]c758fbf2012-03-25 22:53:59383}
384
[email protected]88d71122012-10-18 07:11:01385WebNotificationTray* Shell::GetWebNotificationTray() {
jamescook612205f2016-05-26 06:02:11386 return GetPrimaryRootWindowController()
jamescookb551aba2016-09-01 01:00:16387 ->GetStatusAreaWidget()
jamescook612205f2016-05-26 06:02:11388 ->web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28389}
390
[email protected]a0afeb12012-12-10 22:57:09391bool Shell::HasPrimaryStatusArea() {
jamescookb551aba2016-09-01 01:00:16392 return !!GetPrimaryRootWindowController()->GetStatusAreaWidget();
[email protected]31f19e32012-10-30 22:31:23393}
394
[email protected]a0afeb12012-12-10 22:57:09395SystemTray* Shell::GetPrimarySystemTray() {
396 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42397}
398
[email protected]2b8a9bb2013-07-01 22:43:40399void Shell::SetTouchHudProjectionEnabled(bool enabled) {
400 if (is_touch_hud_projection_enabled_ == enabled)
401 return;
402
[email protected]2b8a9bb2013-07-01 22:43:40403 is_touch_hud_projection_enabled_ = enabled;
sky00c813f2017-03-08 22:48:55404 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18405 observer.OnTouchHudProjectionToggled(enabled);
[email protected]2b8a9bb2013-07-01 22:43:40406}
407
mswa7e8a5f2016-03-01 04:15:06408FirstRunHelper* Shell::CreateFirstRunHelper() {
409 return new FirstRunHelperImpl;
[email protected]59ccade2013-10-17 17:56:40410}
[email protected]87ec2202014-02-06 06:24:27411
sky5ad143a2017-03-22 04:31:23412void Shell::CreateShelfView() {
413 // Must occur after SessionController creation and user login.
414 DCHECK(session_controller());
415 DCHECK_GT(session_controller()->NumberOfLoggedInUsers(), 0);
416 CreateShelfDelegate();
417
sky11cf8db92017-04-10 23:38:08418 for (WmWindow* root_window : shell_port_->GetAllRootWindows())
sky5ad143a2017-03-22 04:31:23419 root_window->GetRootWindowController()->CreateShelfView();
420}
421
yawanodc5533b32017-02-23 11:04:38422void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
423 window_tree_host_manager_->cursor_window_controller()
424 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
425}
426
[email protected]87ec2202014-02-06 06:24:27427void Shell::SetCursorCompositingEnabled(bool enabled) {
jamescook0dfe5632017-04-05 18:49:02428 if (GetAshConfig() == Config::CLASSIC) {
sky494c6cbd2017-03-27 20:57:48429 // TODO: needs to work in mus. http://crbug.com/705592.
430 window_tree_host_manager_->cursor_window_controller()
431 ->SetCursorCompositingEnabled(enabled);
432 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
433 }
[email protected]87ec2202014-02-06 06:24:27434}
[email protected]59ccade2013-10-17 17:56:40435
[email protected]f9466702012-09-17 16:35:27436void Shell::DoInitialWorkspaceAnimation() {
jamescookb8dcef522016-06-25 14:42:55437 return GetPrimaryRootWindowController()
438 ->workspace_controller()
439 ->DoInitialAnimation();
[email protected]f9466702012-09-17 16:35:27440}
441
sky00c813f2017-03-08 22:48:55442void Shell::AddShellObserver(ShellObserver* observer) {
443 shell_observers_.AddObserver(observer);
444}
445
446void Shell::RemoveShellObserver(ShellObserver* observer) {
447 shell_observers_.RemoveObserver(observer);
448}
449
sky7db5ccf2017-03-14 21:52:29450void Shell::ShowAppList() {
451 // Show the app list on the default display for new windows.
452 app_list_->Show(
453 GetWmRootWindowForNewWindows()->GetDisplayNearestWindow().id());
454}
455
456void Shell::DismissAppList() {
457 app_list_->Dismiss();
458}
459
460void Shell::ToggleAppList() {
461 // Toggle the app list on the default display for new windows.
462 app_list_->ToggleAppList(
463 GetWmRootWindowForNewWindows()->GetDisplayNearestWindow().id());
464}
465
466bool Shell::IsAppListVisible() const {
467 return app_list_->IsVisible();
468}
469
470bool Shell::GetAppListTargetVisibility() const {
471 return app_list_->GetTargetVisibility();
472}
473
sky5ad143a2017-03-22 04:31:23474void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
sky11cf8db92017-04-10 23:38:08475 for (WmWindow* root_window : shell_port_->GetAllRootWindows()) {
sky5ad143a2017-03-22 04:31:23476 root_window->GetRootWindowController()->UpdateAfterLoginStatusChange(
477 status);
478 }
479}
480
sky00c813f2017-03-08 22:48:55481void Shell::NotifyMaximizeModeStarted() {
482 for (auto& observer : shell_observers_)
483 observer.OnMaximizeModeStarted();
484}
485
486void Shell::NotifyMaximizeModeEnding() {
487 for (auto& observer : shell_observers_)
488 observer.OnMaximizeModeEnding();
489}
490
491void Shell::NotifyMaximizeModeEnded() {
492 for (auto& observer : shell_observers_)
493 observer.OnMaximizeModeEnded();
494}
495
496void Shell::NotifyOverviewModeStarting() {
497 for (auto& observer : shell_observers_)
498 observer.OnOverviewModeStarting();
499}
500
501void Shell::NotifyOverviewModeEnded() {
502 for (auto& observer : shell_observers_)
503 observer.OnOverviewModeEnded();
504}
505
506void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
507 WmWindow* root_window) {
508 for (auto& observer : shell_observers_)
509 observer.OnFullscreenStateChanged(is_fullscreen, root_window);
510}
511
512void Shell::NotifyPinnedStateChanged(WmWindow* pinned_window) {
513 for (auto& observer : shell_observers_)
514 observer.OnPinnedStateChanged(pinned_window);
515}
516
xiyuan38160182017-03-14 22:50:13517void Shell::NotifyVirtualKeyboardActivated(bool activated,
518 WmWindow* root_window) {
sky00c813f2017-03-08 22:48:55519 for (auto& observer : shell_observers_)
xiyuan38160182017-03-14 22:50:13520 observer.OnVirtualKeyboardStateChanged(activated, root_window);
sky00c813f2017-03-08 22:48:55521}
522
523void Shell::NotifyShelfCreatedForRootWindow(WmWindow* root_window) {
524 for (auto& observer : shell_observers_)
525 observer.OnShelfCreatedForRootWindow(root_window);
526}
527
528void Shell::NotifyShelfAlignmentChanged(WmWindow* root_window) {
529 for (auto& observer : shell_observers_)
530 observer.OnShelfAlignmentChanged(root_window);
531}
532
533void Shell::NotifyShelfAutoHideBehaviorChanged(WmWindow* root_window) {
534 for (auto& observer : shell_observers_)
535 observer.OnShelfAutoHideBehaviorChanged(root_window);
536}
537
[email protected]b6ba05d902013-10-04 21:38:45538////////////////////////////////////////////////////////////////////////////////
539// Shell, private:
540
skyb073203a2017-03-13 16:59:16541Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
sky11cf8db92017-04-10 23:38:08542 std::unique_ptr<ShellPort> shell_port)
543 : shell_port_(std::move(shell_port)),
sky79fa34712017-03-20 23:46:47544 brightness_control_delegate_(
545 base::MakeUnique<system::BrightnessControllerChromeos>()),
546 cast_config_(base::MakeUnique<CastConfigController>()),
547 focus_cycler_(base::MakeUnique<FocusCycler>()),
sky5ab16472017-03-21 19:35:08548 immersive_context_(base::MakeUnique<ImmersiveContextAsh>()),
sky79fa34712017-03-20 23:46:47549 keyboard_brightness_control_delegate_(
550 base::MakeUnique<KeyboardBrightnessController>()),
551 locale_notification_controller_(
552 base::MakeUnique<LocaleNotificationController>()),
sky5ab16472017-03-21 19:35:08553 media_controller_(base::MakeUnique<MediaController>()),
554 new_window_controller_(base::MakeUnique<NewWindowController>()),
sky5ad143a2017-03-22 04:31:23555 session_controller_(base::MakeUnique<SessionController>()),
556 shelf_controller_(base::MakeUnique<ShelfController>()),
skyb073203a2017-03-13 16:59:16557 shell_delegate_(std::move(shell_delegate)),
sky5b45ed82017-03-27 02:54:23558 shutdown_controller_(base::MakeUnique<ShutdownController>()),
sky79fa34712017-03-20 23:46:47559 system_tray_controller_(base::MakeUnique<SystemTrayController>()),
sky5b45ed82017-03-27 02:54:23560 system_tray_notifier_(base::MakeUnique<SystemTrayNotifier>()),
561 vpn_list_(base::MakeUnique<VpnList>()),
562 window_cycle_controller_(base::MakeUnique<WindowCycleController>()),
563 window_selector_controller_(base::MakeUnique<WindowSelectorController>()),
sky7db5ccf2017-03-14 21:52:29564 app_list_(base::MakeUnique<app_list::AppList>()),
yusukes1168eda2016-04-27 07:52:08565 link_handler_model_factory_(nullptr),
jamescookac6724332017-03-21 02:54:43566 tray_bluetooth_helper_(base::MakeUnique<TrayBluetoothHelper>()),
kylechar7a067ec2017-01-07 01:16:28567 display_configurator_(new display::DisplayConfigurator()),
sadrul7a8785e2016-02-12 21:54:35568 native_cursor_manager_(nullptr),
[email protected]b6ba05d902013-10-04 21:38:45569 simulate_modal_window_open_for_testing_(false),
msw3f439af2016-09-08 22:35:26570 is_touch_hud_projection_enabled_(false) {
skyabcae812017-01-18 17:01:34571 // TODO(sky): better refactor cash/mash dependencies. Perhaps put all cash
sky11cf8db92017-04-10 23:38:08572 // state on ShellPortClassic. http://crbug.com/671246.
skyabcae812017-01-18 17:01:34573
skye5fd1222017-04-12 18:43:23574 // Don't use Shell::GetAshConfig() as |instance_| has not yet been set.
575 if (shell_port_->GetAshConfig() != Config::MASH) {
skyb073203a2017-03-13 16:59:16576 gpu_support_.reset(shell_delegate_->CreateGPUSupport());
skyabcae812017-01-18 17:01:34577 display_manager_.reset(ScreenAsh::CreateDisplayManager());
578 window_tree_host_manager_.reset(new WindowTreeHostManager);
579 user_metrics_recorder_.reset(new UserMetricsRecorder);
580 }
[email protected]b6ba05d902013-10-04 21:38:45581
[email protected]093b8d642014-04-03 20:59:28582 PowerStatus::Initialize();
sky5ad143a2017-03-22 04:31:23583
584 session_controller_->AddSessionStateObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45585}
586
587Shell::~Shell() {
588 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
589
sky11cf8db92017-04-10 23:38:08590 const Config config = shell_port_->GetAshConfig();
skyabcae812017-01-18 17:01:34591
skyb5e13442017-04-06 02:11:23592 if (config != Config::MASH)
skyabcae812017-01-18 17:01:34593 user_metrics_recorder_->OnShellShuttingDown();
bruthigc24d11f2015-06-09 21:30:03594
skyb073203a2017-03-13 16:59:16595 shell_delegate_->PreShutdown();
[email protected]050e77182014-03-25 15:29:16596
[email protected]b6ba05d902013-10-04 21:38:45597 // Remove the focus from any window. This will prevent overhead and side
598 // effects (e.g. crashes) from changing focus during shutdown.
599 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18600 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45601
602 // Please keep in same order as in Init() because it's easy to miss one.
603 if (window_modality_controller_)
604 window_modality_controller_.reset();
skyb5e13442017-04-06 02:11:23605 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:34606 RemovePreTargetHandler(
607 window_tree_host_manager_->input_method_event_handler());
608 }
jamescook01bf23e72017-01-09 19:58:15609
[email protected]e4ea52362014-02-15 03:21:06610 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
611 magnifier_key_scroll_handler_.reset();
612
613 RemovePreTargetHandler(speech_feedback_handler_.get());
614 speech_feedback_handler_.reset();
jamescook01bf23e72017-01-09 19:58:15615
[email protected]b6ba05d902013-10-04 21:38:45616 RemovePreTargetHandler(overlay_filter_.get());
[email protected]3537d472014-01-15 05:45:31617 RemovePreTargetHandler(accelerator_filter_.get());
618 RemovePreTargetHandler(event_transformation_handler_.get());
619 RemovePreTargetHandler(toplevel_window_event_handler_.get());
620 RemovePostTargetHandler(toplevel_window_event_handler_.get());
skyb5e13442017-04-06 02:11:23621 if (config != Config::MASH)
skyabcae812017-01-18 17:01:34622 RemovePreTargetHandler(system_gesture_filter_.get());
skyb5e13442017-04-06 02:11:23623 if (config == Config::CLASSIC)
skyabcae812017-01-18 17:01:34624 RemovePreTargetHandler(mouse_cursor_filter_.get());
hariank0dd03dd2016-07-14 23:47:33625 RemovePreTargetHandler(modality_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45626
627 // TooltipController is deleted with the Shell so removing its references.
628 RemovePreTargetHandler(tooltip_controller_.get());
629
jonross0af45212015-01-13 18:55:46630 screen_orientation_controller_.reset();
yiyixa68ade512016-09-01 17:38:13631 screen_layout_observer_.reset();
jonross0af45212015-01-13 18:55:46632
jamescook01bf23e72017-01-09 19:58:15633 // Destroy the virtual keyboard controller before the maximize mode controller
634 // since the latters destructor triggers events that the former is listening
635 // to but no longer cares about.
rsadambbaf2c82015-01-07 17:54:13636 virtual_keyboard_controller_.reset();
jonross0af45212015-01-13 18:55:46637
[email protected]2a57beb52014-06-09 20:02:26638 // Destroy maximize mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57639 // need to be removed.
sky5ab16472017-03-21 19:35:08640 maximize_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57641
jdufault551152e2016-01-27 19:48:43642 // Destroy the keyboard before closing the shelf, since it will invoke a shelf
643 // layout.
644 DeactivateKeyboard();
645
sky07a24d42017-03-09 23:57:30646 toast_manager_.reset();
yoshiki32f51632016-03-24 01:24:43647
jdufault551152e2016-01-27 19:48:43648 // Destroy SystemTrayDelegate before destroying the status area(s). Make sure
649 // to deinitialize the shelf first, as it is initialized after the delegate.
sky11cf8db92017-04-10 23:38:08650 for (WmWindow* root : shell_port_->GetAllRootWindows())
jamescookb551aba2016-09-01 01:00:16651 root->GetRootWindowController()->GetShelf()->ShutdownShelfWidget();
jamescookac6724332017-03-21 02:54:43652 tray_bluetooth_helper_.reset();
sky79fa34712017-03-20 23:46:47653 DeleteSystemTrayDelegate();
[email protected]b6ba05d902013-10-04 21:38:45654
[email protected]b6ba05d902013-10-04 21:38:45655 // Drag-and-drop must be canceled prior to close all windows.
656 drag_drop_controller_.reset();
657
jamescookb8dcef522016-06-25 14:42:55658// Controllers who have WindowObserver added must be deleted
659// before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03660
[email protected]8c9d12a2013-12-06 18:39:03661 // VideoActivityNotifier must be deleted before |video_detector_| is
662 // deleted because it's observing video activity through
derat83b761392016-07-11 16:44:44663 // VideoDetector::Observer interface.
[email protected]8c9d12a2013-12-06 18:39:03664 video_activity_notifier_.reset();
[email protected]8c9d12a2013-12-06 18:39:03665 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25666 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03667
668 shadow_controller_.reset();
669 resize_shadow_controller_.reset();
670
sky37f0dd12016-07-19 18:00:59671 // Has to happen before ~MruWindowTracker.
sky5b45ed82017-03-27 02:54:23672 window_cycle_controller_.reset();
673 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03674
skyabcae812017-01-18 17:01:34675 CloseAllRootWindowChildWindows();
676
afakhry58159392015-05-22 02:45:52677 // MruWindowTracker must be destroyed after all windows have been deleted to
678 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
679 // path. (crbug.com/485438).
sky5ab16472017-03-21 19:35:08680 mru_window_tracker_.reset();
[email protected]b6ba05d902013-10-04 21:38:45681
[email protected]b6ba05d902013-10-04 21:38:45682 // These need a valid Shell instance to clean up properly, so explicitly
683 // delete them before invalidating the instance.
684 // Alphabetical. TODO(oshima): sort.
685 magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45686 tooltip_controller_.reset();
687 event_client_.reset();
[email protected]3537d472014-01-15 05:45:31688 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45689 visibility_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45690
691 power_button_controller_.reset();
692 lock_state_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45693
hidehiko6821ca42016-06-18 11:12:23694 screen_pinning_controller_.reset();
695
[email protected]b6ba05d902013-10-04 21:38:45696 resolution_notification_controller_.reset();
oshima5a296e82016-04-29 01:32:27697 screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49698 mouse_cursor_filter_.reset();
hariank0dd03dd2016-07-14 23:47:33699 modality_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45700
[email protected]03122891a2014-05-13 23:56:49701 touch_transformer_controller_.reset();
warx533c8f62016-04-12 01:19:43702 audio_a11y_controller_.reset();
sammiequon203ae022016-09-18 17:23:42703 laser_pointer_controller_.reset();
704 partial_magnification_controller_.reset();
warx533c8f62016-04-12 01:19:43705
[email protected]b6ba05d902013-10-04 21:38:45706 // This also deletes all RootWindows. Note that we invoke Shutdown() on
oshimae2818922015-07-28 01:18:52707 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
708 // destruction
[email protected]b6ba05d902013-10-04 21:38:45709 // of its owned RootWindowControllers relies on the value.
rjkroege2c9305402016-09-07 00:21:45710 ScreenAsh::CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12711 display_configuration_controller_.reset();
dtseng4ae0a882016-04-15 21:39:27712
sky15ef0aa2017-01-20 18:55:59713 // AppListDelegateImpl depends upon AppList.
714 app_list_delegate_impl_.reset();
715
sky07a24d42017-03-09 23:57:30716 // These members access Shell in their destructors.
717 wallpaper_controller_.reset();
718 accessibility_delegate_.reset();
719
720 // Balances the Install() in Initialize().
721 views::FocusManagerFactory::Install(nullptr);
722
sky5ad143a2017-03-22 04:31:23723 // ShelfWindowWatcher has window observers and a pointer to the shelf model.
724 shelf_window_watcher_.reset();
725
726 // ShelfItemDelegate subclasses it owns have complex cleanup to run (e.g. ARC
727 // shelf items in Chrome) so explicitly shutdown early.
728 shelf_model()->DestroyItemDelegates();
729
730 // Must be destroyed before FocusController.
731 shelf_delegate_.reset();
732
tibellb93c729b2017-03-30 00:45:09733 // Removes itself as an observer of |pref_service_|.
sky5ad143a2017-03-22 04:31:23734 shelf_controller_.reset();
735
sky11cf8db92017-04-10 23:38:08736 shell_port_->Shutdown();
sky5ad143a2017-03-22 04:31:23737
sky27344382017-03-08 21:30:32738 // Depends on |focus_controller_|, so must be destroyed before.
oshimae2818922015-07-28 01:18:52739 window_tree_host_manager_.reset();
sky27344382017-03-08 21:30:32740 focus_controller_->RemoveObserver(this);
741 focus_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45742 screen_position_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45743
robert.bradfordab052492015-05-06 11:09:56744 display_color_manager_.reset();
[email protected]7bc49bd2014-01-22 09:30:34745 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11746 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45747 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11748 display_configurator_->RemoveObserver(display_error_observer_.get());
jdufault88fb76652015-04-30 22:36:43749 if (projecting_observer_) {
[email protected]1e31cbd2014-04-07 20:06:11750 display_configurator_->RemoveObserver(projecting_observer_.get());
sky00c813f2017-03-08 22:48:55751 RemoveShellObserver(projecting_observer_.get());
jdufault88fb76652015-04-30 22:36:43752 }
[email protected]b6ba05d902013-10-04 21:38:45753 display_change_observer_.reset();
kylechar98748a52016-12-03 01:33:22754 shutdown_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45755
[email protected]093b8d642014-04-03 20:59:28756 PowerStatus::Shutdown();
pneubeck8be1f5422014-10-09 16:46:18757
758 // Ensure that DBusThreadManager outlives this Shell.
759 DCHECK(chromeos::DBusThreadManager::IsInitialized());
[email protected]b6ba05d902013-10-04 21:38:45760
sky88bd4be62016-06-09 17:34:41761 // Needs to happen right before |instance_| is reset.
sky11cf8db92017-04-10 23:38:08762 shell_port_.reset();
sky5ad143a2017-03-22 04:31:23763 session_controller_->RemoveSessionStateObserver(this);
skyb073203a2017-03-13 16:59:16764 wallpaper_delegate_.reset();
tibellb93c729b2017-03-30 00:45:09765 pref_service_ = nullptr;
skyb073203a2017-03-13 16:59:16766 shell_delegate_.reset();
sky88bd4be62016-06-09 17:34:41767
[email protected]b6ba05d902013-10-04 21:38:45768 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18769 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45770}
771
[email protected]1b4c7472014-05-15 18:32:23772void Shell::Init(const ShellInitParams& init_params) {
sky11cf8db92017-04-10 23:38:08773 const Config config = shell_port_->GetAshConfig();
skyabcae812017-01-18 17:01:34774
sky07a24d42017-03-09 23:57:30775 blocking_pool_ = init_params.blocking_pool;
776
skyb073203a2017-03-13 16:59:16777 wallpaper_delegate_ = shell_delegate_->CreateWallpaperDelegate();
778
779 // Can be null in tests.
skye5fd1222017-04-12 18:43:23780 if (config == Config::MASH && shell_delegate_->GetShellConnector()) {
tibellb93c729b2017-03-30 00:45:09781 prefs::ConnectToPrefService(
782 shell_delegate_->GetShellConnector(),
783 make_scoped_refptr(new PrefRegistrySimple()),
tibell2961ff42017-04-06 05:31:16784 std::vector<PrefValueStore::PrefStoreType>(),
tibellb93c729b2017-03-30 00:45:09785 base::Bind(&Shell::OnPrefServiceInitialized, base::Unretained(this)),
786 prefs::mojom::kForwarderServiceName);
jonrossc4ba10602017-04-07 20:51:05787 }
skyb073203a2017-03-13 16:59:16788
sky11cf8db92017-04-10 23:38:08789 // Some delegates access ShellPort during their construction. Create them here
790 // instead of the ShellPort constructor.
skyb073203a2017-03-13 16:59:16791 accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate());
792 palette_delegate_ = shell_delegate_->CreatePaletteDelegate();
sky07a24d42017-03-09 23:57:30793 toast_manager_ = base::MakeUnique<ToastManager>();
794
sky07a24d42017-03-09 23:57:30795 // Install the custom factory early on so that views::FocusManagers for Tray,
796 // Shelf, and WallPaper could be created by the factory.
797 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
798
799 wallpaper_controller_ = base::MakeUnique<WallpaperController>(blocking_pool_);
800
801 // Start devtools server
802 devtools_server_ = ui::devtools::UiDevToolsServer::Create(nullptr);
803 if (devtools_server_) {
804 auto dom_backend = base::MakeUnique<devtools::AshDevToolsDOMAgent>();
805 auto css_backend =
806 base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_backend.get());
807 auto devtools_client = base::MakeUnique<ui::devtools::UiDevToolsClient>(
808 "Ash", devtools_server_.get());
809 devtools_client->AddAgent(std::move(dom_backend));
810 devtools_client->AddAgent(std::move(css_backend));
811 devtools_server_->AttachClient(std::move(devtools_client));
812 }
jamescook3daef412016-07-14 23:53:30813
skye5fd1222017-04-12 18:43:23814 if (config == Config::MASH)
sky15ef0aa2017-01-20 18:55:59815 app_list_delegate_impl_ = base::MakeUnique<AppListDelegateImpl>();
816
sky11cf8db92017-04-10 23:38:08817 // TODO(sky): move creation to ShellPort.
skye5fd1222017-04-12 18:43:23818 if (config != Config::MASH)
skyabcae812017-01-18 17:01:34819 immersive_handler_factory_ = base::MakeUnique<ImmersiveHandlerFactoryAsh>();
skyb7b54092016-08-19 16:00:09820
sky6624a7af2016-05-27 18:47:49821 scoped_overview_animation_settings_factory_.reset(
822 new ScopedOverviewAnimationSettingsFactoryAura);
sky5ab16472017-03-21 19:35:08823 window_positioner_ = base::MakeUnique<WindowPositioner>();
sky984c1892016-04-20 00:00:34824
sky494c6cbd2017-03-27 20:57:48825 if (config == Config::CLASSIC) {
826 // TODO: needs to work in mus. http://crbug.com/705592.
skyabcae812017-01-18 17:01:34827 native_cursor_manager_ = new AshNativeCursorManager;
828 cursor_manager_.reset(
829 new CursorManager(base::WrapUnique(native_cursor_manager_)));
830 }
skyfee520c2016-02-11 19:57:46831
skyb073203a2017-03-13 16:59:16832 shell_delegate_->PreInit();
skyabcae812017-01-18 17:01:34833 bool display_initialized = true;
sky494c6cbd2017-03-27 20:57:48834 if (config == Config::CLASSIC) {
835 // TODO: decide if this needs to be made to work in Config::MUS.
836 // http://crbug.com/705595.
skyabcae812017-01-18 17:01:34837 display_initialized = display_manager_->InitFromCommandLine();
stevenjb537c5c3f2016-01-20 23:38:12838
skyabcae812017-01-18 17:01:34839 display_configuration_controller_.reset(new DisplayConfigurationController(
840 display_manager_.get(), window_tree_host_manager_.get()));
stevenjb537c5c3f2016-01-20 23:38:12841
oshimae001c8c2016-04-13 23:49:04842#if defined(USE_OZONE)
skyabcae812017-01-18 17:01:34843 display_configurator_->Init(
844 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(),
845 !gpu_support_->IsPanelFittingDisabled());
oshimae001c8c2016-04-13 23:49:04846#elif defined(USE_X11)
skyabcae812017-01-18 17:01:34847 display_configurator_->Init(
848 base::MakeUnique<display::NativeDisplayDelegateX11>(),
849 !gpu_support_->IsPanelFittingDisabled());
oshimae001c8c2016-04-13 23:49:04850#endif
skyabcae812017-01-18 17:01:34851 }
[email protected]0249a6532013-10-31 06:53:34852
pneubeck8be1f5422014-10-09 16:46:18853 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell.
854 chromeos::DBusThreadManager* dbus_thread_manager =
855 chromeos::DBusThreadManager::Get();
856 projecting_observer_.reset(
857 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient()));
[email protected]1e31cbd2014-04-07 20:06:11858 display_configurator_->AddObserver(projecting_observer_.get());
sky00c813f2017-03-08 22:48:55859 AddShellObserver(projecting_observer_.get());
[email protected]72bce522014-02-10 21:11:26860
reveman24158982017-01-10 05:58:45861 if (!display_initialized && chromeos::IsRunningAsSystemCompositor()) {
kylecharf2e4e412016-12-04 04:21:35862 display_change_observer_ = base::MakeUnique<display::DisplayChangeObserver>(
kylechar98748a52016-12-03 01:33:22863 display_configurator_.get(), display_manager_.get());
864
865 shutdown_observer_ =
866 base::MakeUnique<ShutdownObserver>(display_configurator_.get());
867
[email protected]b6ba05d902013-10-04 21:38:45868 // Register |display_change_observer_| first so that the rest of
869 // observer gets invoked after the root windows are configured.
[email protected]1e31cbd2014-04-07 20:06:11870 display_configurator_->AddObserver(display_change_observer_.get());
[email protected]093b8d642014-04-03 20:59:28871 display_error_observer_.reset(new DisplayErrorObserver());
[email protected]1e31cbd2014-04-07 20:06:11872 display_configurator_->AddObserver(display_error_observer_.get());
873 display_configurator_->set_state_controller(display_change_observer_.get());
874 display_configurator_->set_mirroring_controller(display_manager_.get());
875 display_configurator_->ForceInitialConfigure(
jamescookfda159002016-10-21 18:48:57876 base::CommandLine::ForCurrentProcess()->HasSwitch(
877 chromeos::switches::kFirstExecAfterBoot)
878 ? kChromeOsBootColor
879 : 0);
[email protected]b6ba05d902013-10-04 21:38:45880 display_initialized = true;
881 }
msw3f439af2016-09-08 22:35:26882 display_color_manager_.reset(new DisplayColorManager(
883 display_configurator_.get(), init_params.blocking_pool));
stevenjb537c5c3f2016-01-20 23:38:12884
[email protected]b6ba05d902013-10-04 21:38:45885 if (!display_initialized)
[email protected]0249a6532013-10-31 06:53:34886 display_manager_->InitDefaultDisplay();
[email protected]b6ba05d902013-10-04 21:38:45887
skyb5e13442017-04-06 02:11:23888 if (config == Config::CLASSIC) {
skyabcae812017-01-18 17:01:34889 display_manager_->RefreshFontParams();
[email protected]68d6080e2014-08-21 23:06:32890
skyabcae812017-01-18 17:01:34891 aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
892 aura::Env::GetInstance()->set_context_factory_private(
893 init_params.context_factory_private);
894 }
[email protected]ecca62b2013-10-09 16:18:53895
[email protected]b6ba05d902013-10-04 21:38:45896 // The WindowModalityController needs to be at the front of the input event
897 // pretarget handler list to ensure that it processes input events when modal
898 // windows are active.
jamescookb8dcef522016-06-25 14:42:55899 window_modality_controller_.reset(new ::wm::WindowModalityController(this));
[email protected]b6ba05d902013-10-04 21:38:45900
[email protected]e319c7e2014-03-14 19:56:14901 env_filter_.reset(new ::wm::CompoundEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45902 AddPreTargetHandler(env_filter_.get());
903
sky27344382017-03-08 21:30:32904 // FocusController takes ownership of AshFocusRules.
905 focus_controller_ =
906 base::MakeUnique<::wm::FocusController>(new wm::AshFocusRules());
907 focus_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45908
[email protected]093b8d642014-04-03 20:59:28909 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:45910
sky11cf8db92017-04-10 23:38:08911 shell_port_->CreatePrimaryHost();
sky27344382017-03-08 21:30:32912 root_window_for_new_windows_ = WmWindow::Get(GetPrimaryRootWindow());
[email protected]b6ba05d902013-10-04 21:38:45913
skye5fd1222017-04-12 18:43:23914 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:34915 resolution_notification_controller_.reset(
916 new ResolutionNotificationController);
917 }
[email protected]b6ba05d902013-10-04 21:38:45918
deratc6250a02017-01-25 05:51:53919 if (cursor_manager_) {
oshimaf84b0da722016-04-27 19:47:19920 cursor_manager_->SetDisplay(
921 display::Screen::GetScreen()->GetPrimaryDisplay());
deratc6250a02017-01-25 05:51:53922 }
[email protected]b6ba05d902013-10-04 21:38:45923
sky11cf8db92017-04-10 23:38:08924 accelerator_controller_ = shell_port_->CreateAcceleratorController();
sky5ab16472017-03-21 19:35:08925 maximize_mode_controller_ = base::MakeUnique<MaximizeModeController>();
[email protected]b6ba05d902013-10-04 21:38:45926
sky494c6cbd2017-03-27 20:57:48927 if (config == Config::CLASSIC) {
928 // Not applicable to mus/mash as events are already routed to InputMethod
929 // first.
skyabcae812017-01-18 17:01:34930 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
sky11cf8db92017-04-10 23:38:08957 toplevel_window_event_handler_ =
958 base::MakeUnique<ToplevelWindowEventHandler>();
[email protected]3537d472014-01-15 05:45:31959
skye5fd1222017-04-12 18:43:23960 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:34961 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);
sky13857152017-03-29 15:46:04966 screen_pinning_controller_ = base::MakeUnique<ScreenPinningController>();
[email protected]354520b2014-06-21 04:31:01967
jamescookd9f152f2016-11-15 00:53:08968 lock_state_controller_ =
sky5b45ed82017-03-27 02:54:23969 base::MakeUnique<LockStateController>(shutdown_controller_.get());
jamescookb8dcef522016-06-25 14:42:55970 power_button_controller_.reset(
971 new PowerButtonController(lock_state_controller_.get()));
[email protected]685442f32014-02-28 10:40:06972 // Pass the initial display state to PowerButtonController.
973 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:09974 display_configurator_->cached_displays());
jamescook01bf23e72017-01-09 19:58:15975
sky00c813f2017-03-08 22:48:55976 AddShellObserver(lock_state_controller_.get());
[email protected]b6ba05d902013-10-04 21:38:45977
derat94887a22017-01-20 18:17:25978 // The connector is unavailable in some tests.
skye5fd1222017-04-12 18:43:23979 if (config == Config::MASH && shell_delegate_->GetShellConnector()) {
derat94887a22017-01-20 18:17:25980 ui::mojom::UserActivityMonitorPtr user_activity_monitor;
skyb073203a2017-03-13 16:59:16981 shell_delegate_->GetShellConnector()->BindInterface(ui::mojom::kServiceName,
982 &user_activity_monitor);
derat94887a22017-01-20 18:17:25983 user_activity_forwarder_ = base::MakeUnique<aura::UserActivityForwarder>(
984 std::move(user_activity_monitor), user_activity_detector_.get());
985 }
986
[email protected]093b8d642014-04-03 20:59:28987 drag_drop_controller_.reset(new DragDropController);
oshima5a296e82016-04-29 01:32:27988 // |screenshot_controller_| needs to be created (and prepended as a
mukai19274bdd2015-02-24 22:37:48989 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
oshima5a296e82016-04-29 01:32:27990 // process mouse events prior to screenshot session.
mukai19274bdd2015-02-24 22:37:48991 // See http://crbug.com/459214
oshima5a296e82016-04-29 01:32:27992 screenshot_controller_.reset(new ScreenshotController());
skyb5e13442017-04-06 02:11:23993 // TODO: evaluate if MouseCursorEventFilter needs to work for mus/mash.
994 // http://crbug.com/706474.
995 if (config == Config::CLASSIC) {
skyabcae812017-01-18 17:01:34996 mouse_cursor_filter_.reset(new MouseCursorEventFilter());
997 PrependPreTargetHandler(mouse_cursor_filter_.get());
998 }
[email protected]b6ba05d902013-10-04 21:38:45999
1000 // Create Controllers that may need root window.
1001 // TODO(oshima): Move as many controllers before creating
1002 // RootWindowController as possible.
1003 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:451004
sammiequon203ae022016-09-18 17:23:421005 laser_pointer_controller_.reset(new LaserPointerController());
1006 partial_magnification_controller_.reset(new PartialMagnificationController());
sammiequon203ae022016-09-18 17:23:421007
jamescookb8dcef522016-06-25 14:42:551008 magnification_controller_.reset(MagnificationController::CreateInstance());
sky5ab16472017-03-21 19:35:081009 mru_window_tracker_ = base::MakeUnique<MruWindowTracker>();
[email protected]b6ba05d902013-10-04 21:38:451010
[email protected]55398d22013-10-10 19:49:201011 autoclick_controller_.reset(AutoclickController::CreateInstance());
1012
[email protected]b6ba05d902013-10-04 21:38:451013 high_contrast_controller_.reset(new HighContrastController);
1014 video_detector_.reset(new VideoDetector);
[email protected]b6ba05d902013-10-04 21:38:451015
oshimaebbe63772015-02-19 18:41:321016 tooltip_controller_.reset(new views::corewm::TooltipController(
dchenga94547472016-04-08 08:41:111017 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451018 AddPreTargetHandler(tooltip_controller_.get());
1019
hariank0dd03dd2016-07-14 23:47:331020 modality_filter_.reset(new SystemModalContainerEventFilter(this));
1021 AddPreTargetHandler(modality_filter_.get());
1022
[email protected]093b8d642014-04-03 20:59:281023 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451024
skyb073203a2017-03-13 16:59:161025 session_state_delegate_.reset(shell_delegate_->CreateSessionStateDelegate());
skyabcae812017-01-18 17:01:341026 // Must occur after Shell has installed its early pre-target handlers (for
1027 // example, WindowModalityController).
sky11cf8db92017-04-10 23:38:081028 shell_port_->CreatePointerWatcherAdapter();
[email protected]b6ba05d902013-10-04 21:38:451029
[email protected]093b8d642014-04-03 20:59:281030 resize_shadow_controller_.reset(new ResizeShadowController());
sky27344382017-03-08 21:30:321031 shadow_controller_.reset(new ::wm::ShadowController(focus_controller_.get()));
[email protected]b6ba05d902013-10-04 21:38:451032
sky79fa34712017-03-20 23:46:471033 SetSystemTrayDelegate(
skyb073203a2017-03-13 16:59:161034 base::WrapUnique(shell_delegate_->CreateSystemTrayDelegate()));
[email protected]b6ba05d902013-10-04 21:38:451035
jamescookac6724332017-03-21 02:54:431036 // May trigger initialization of the Bluetooth adapter.
1037 tray_bluetooth_helper_->Initialize();
1038
kylechar55f0eaf22017-01-11 22:57:371039 // Create AshTouchTransformController before
oshimae2818922015-07-28 01:18:521040 // WindowTreeHostManager::InitDisplays()
kylechar55f0eaf22017-01-11 22:57:371041 // since AshTouchTransformController listens on
oshimae2818922015-07-28 01:18:521042 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
skye5fd1222017-04-12 18:43:231043 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:341044 touch_transformer_controller_.reset(new AshTouchTransformController(
1045 display_configurator_.get(), display_manager_.get()));
1046 }
[email protected]03122891a2014-05-13 23:56:491047
sky11cf8db92017-04-10 23:38:081048 keyboard_ui_ = shell_port_->CreateKeyboardUI();
skyfee520c2016-02-11 19:57:461049
sky11cf8db92017-04-10 23:38:081050 shell_port_->InitHosts(init_params);
[email protected]b6ba05d902013-10-04 21:38:451051
rsadam9172bc8a2014-10-29 23:37:381052 // Needs to be created after InitDisplays() since it may cause the virtual
1053 // keyboard to be deployed.
skye5fd1222017-04-12 18:43:231054 if (config != Config::MASH)
skyabcae812017-01-18 17:01:341055 virtual_keyboard_controller_.reset(new VirtualKeyboardController);
rsadam9172bc8a2014-10-29 23:37:381056
warx533c8f62016-04-12 01:19:431057 audio_a11y_controller_.reset(new chromeos::AudioA11yController);
warx533c8f62016-04-12 01:19:431058
msw0e91d932016-08-25 22:34:091059 // Initialize the wallpaper after the RootWindowController has been created,
1060 // otherwise the widget will not paint when restoring after a browser crash.
1061 // Also, initialize after display initialization to ensure correct sizing.
skyb073203a2017-03-13 16:59:161062 wallpaper_delegate_->InitializeWallpaper();
[email protected]b6ba05d902013-10-04 21:38:451063
sadrul7a8785e2016-02-12 21:54:351064 if (cursor_manager_) {
1065 if (initially_hide_cursor_)
1066 cursor_manager_->HideCursor();
1067 cursor_manager_->SetCursor(ui::kCursorPointer);
1068 }
[email protected]b6ba05d902013-10-04 21:38:451069
[email protected]093b8d642014-04-03 20:59:281070 power_event_observer_.reset(new PowerEventObserver());
[email protected]ded58fd2013-10-09 07:56:551071 user_activity_notifier_.reset(
[email protected]b0fa7012014-04-16 12:50:571072 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
[email protected]ded58fd2013-10-09 07:56:551073 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281074 new VideoActivityNotifier(video_detector_.get()));
1075 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
skye5fd1222017-04-12 18:43:231076 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:341077 screen_orientation_controller_.reset(new ScreenOrientationController());
1078 screen_layout_observer_.reset(new ScreenLayoutObserver());
1079 }
yiyix90cfee22017-02-16 05:38:181080 sms_observer_.reset(new SmsObserver());
jamescook01bf23e72017-01-09 19:58:151081
[email protected]b6ba05d902013-10-04 21:38:451082 // The compositor thread and main message loop have to be running in
1083 // order to create mirror window. Run it after the main message loop
1084 // is started.
skye5fd1222017-04-12 18:43:231085 if (config != Config::MASH)
skyabcae812017-01-18 17:01:341086 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031087
sky00c813f2017-03-08 22:48:551088 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:181089 observer.OnShellInitialized();
phweiss0bf64c52015-11-17 12:56:181090
skye5fd1222017-04-12 18:43:231091 if (config != Config::MASH)
skyabcae812017-01-18 17:01:341092 user_metrics_recorder_->OnShellInitialized();
[email protected]b6ba05d902013-10-04 21:38:451093}
1094
[email protected]51f438112013-11-18 19:32:501095void Shell::InitKeyboard() {
[email protected]b6ba05d902013-10-04 21:38:451096 if (keyboard::IsKeyboardEnabled()) {
[email protected]a0b3fb882014-04-07 19:26:031097 if (keyboard::KeyboardController::GetInstance()) {
[email protected]b6ba05d902013-10-04 21:38:451098 RootWindowControllerList controllers = GetAllRootWindowControllers();
1099 for (RootWindowControllerList::iterator iter = controllers.begin();
1100 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:031101 (*iter)->DeactivateKeyboard(
1102 keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:451103 }
1104 }
[email protected]a0b3fb882014-04-07 19:26:031105 keyboard::KeyboardController::ResetInstance(
skyb073203a2017-03-13 16:59:161106 new keyboard::KeyboardController(shell_delegate_->CreateKeyboardUI(),
1107 virtual_keyboard_controller_.get()));
[email protected]b6ba05d902013-10-04 21:38:451108 }
1109}
1110
[email protected]41baaed2013-11-09 04:18:261111void Shell::InitRootWindow(aura::Window* root_window) {
sky27344382017-03-08 21:30:321112 DCHECK(focus_controller_);
[email protected]d90b8392012-06-13 09:34:561113 DCHECK(visibility_controller_.get());
1114 DCHECK(drag_drop_controller_.get());
[email protected]d90b8392012-06-13 09:34:561115
sky27344382017-03-08 21:30:321116 aura::client::SetFocusClient(root_window, focus_controller_.get());
1117 aura::client::SetActivationClient(root_window, focus_controller_.get());
1118 root_window->AddPreTargetHandler(focus_controller_.get());
[email protected]d90b8392012-06-13 09:34:561119 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
1120 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]8d625fb2012-07-18 16:40:061121 aura::client::SetScreenPositionClient(root_window,
1122 screen_position_controller_.get());
sadrul7a8785e2016-02-12 21:54:351123 aura::client::SetCursorClient(root_window, cursor_manager_.get());
[email protected]54a37cdc2012-07-25 19:16:011124 aura::client::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381125 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561126
[email protected]3537d472014-01-15 05:45:311127 aura::client::SetWindowMoveClient(root_window,
jamescookb8dcef522016-06-25 14:42:551128 toplevel_window_event_handler_.get());
[email protected]3537d472014-01-15 05:45:311129 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1130 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
[email protected]d90b8392012-06-13 09:34:561131}
1132
sky79fa34712017-03-20 23:46:471133void Shell::SetSystemTrayDelegate(
1134 std::unique_ptr<SystemTrayDelegate> delegate) {
1135 DCHECK(delegate);
1136 system_tray_delegate_ = std::move(delegate);
1137 system_tray_delegate_->Initialize();
sky11cf8db92017-04-10 23:38:081138 // Accesses ShellPort in its constructor.
sky79fa34712017-03-20 23:46:471139 logout_confirmation_controller_.reset(new LogoutConfirmationController(
1140 base::Bind(&SystemTrayController::SignOut,
1141 base::Unretained(system_tray_controller_.get()))));
1142}
1143
1144void Shell::DeleteSystemTrayDelegate() {
1145 DCHECK(system_tray_delegate_);
sky11cf8db92017-04-10 23:38:081146 // Accesses ShellPort in its destructor.
sky79fa34712017-03-20 23:46:471147 logout_confirmation_controller_.reset();
1148 system_tray_delegate_.reset();
1149}
1150
skyabcae812017-01-18 17:01:341151void Shell::CloseAllRootWindowChildWindows() {
sky11cf8db92017-04-10 23:38:081152 for (WmWindow* wm_root_window : shell_port_->GetAllRootWindows()) {
skyabcae812017-01-18 17:01:341153 aura::Window* root_window = wm_root_window->aura_window();
1154 RootWindowController* controller = GetRootWindowController(root_window);
1155 if (controller) {
1156 controller->CloseChildWindows();
1157 } else {
1158 while (!root_window->children().empty()) {
1159 aura::Window* child = root_window->children()[0];
1160 delete child;
1161 }
1162 }
1163 }
1164}
1165
sky5ad143a2017-03-22 04:31:231166void Shell::CreateShelfDelegate() {
1167 // May be called multiple times as shelves are created and destroyed.
1168 if (shelf_delegate_)
1169 return;
1170 // Must occur after SessionController creation and user login because
1171 // Chrome's implementation of ShelfDelegate assumes it can get information
1172 // about multi-profile login state.
1173 DCHECK(session_controller());
1174 DCHECK_GT(session_controller()->NumberOfLoggedInUsers(), 0);
1175 shelf_delegate_.reset(shell_delegate_->CreateShelfDelegate(shelf_model()));
1176 shelf_window_watcher_ = base::MakeUnique<ShelfWindowWatcher>(shelf_model());
1177}
1178
[email protected]c0ce80e2012-10-05 23:28:271179bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1180 RootWindowControllerList controllers = GetAllRootWindowControllers();
oshima9a61ecf2016-06-18 10:43:051181 for (RootWindowController* controller : controllers) {
1182 if (controller->CanWindowReceiveEvents(window))
[email protected]602022b2014-03-31 17:07:311183 return true;
[email protected]c0ce80e2012-10-05 23:28:271184 }
1185 return false;
1186}
1187
[email protected]049cf34b2012-12-07 17:15:481188////////////////////////////////////////////////////////////////////////////////
1189// Shell, ui::EventTarget overrides:
1190
[email protected]869f6352012-12-06 20:47:171191bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411192 return true;
1193}
1194
1195ui::EventTarget* Shell::GetParentTarget() {
[email protected]ff0278852013-11-05 22:35:481196 return aura::Env::GetInstance();
[email protected]5097e692012-10-30 22:08:411197}
1198
dchenga94547472016-04-08 08:41:111199std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1200 return std::unique_ptr<ui::EventTargetIterator>();
[email protected]3e670aa2013-12-02 19:04:321201}
1202
1203ui::EventTargeter* Shell::GetEventTargeter() {
1204 NOTREACHED();
achuith287b26e2015-09-03 17:49:181205 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321206}
1207
sky27344382017-03-08 21:30:321208void Shell::OnWindowActivated(
1209 aura::client::ActivationChangeObserver::ActivationReason reason,
1210 aura::Window* gained_active,
1211 aura::Window* lost_active) {
1212 WmWindow* gained_active_wm = WmWindow::Get(gained_active);
1213 if (gained_active_wm)
1214 root_window_for_new_windows_ = gained_active_wm->GetRootWindow();
1215}
1216
Xiyuan Xiab64fd0a2017-04-13 17:53:141217void Shell::OnSessionStateChanged(session_manager::SessionState state) {
sky5ad143a2017-03-22 04:31:231218 // Create the shelf when a session becomes active. It's safe to do this
1219 // multiple times (e.g. initial login vs. multiprofile add session).
1220 if (state == session_manager::SessionState::ACTIVE) {
1221 CreateShelfView();
1222
skye5fd1222017-04-12 18:43:231223 if (GetAshConfig() != Config::MASH) {
sky5ad143a2017-03-22 04:31:231224 // Recreate the keyboard after initial login and after multiprofile login.
1225 CreateKeyboard();
1226 }
1227 }
xiyuan233f4e72017-04-06 06:59:561228}
sky5ad143a2017-03-22 04:31:231229
Xiyuan Xiab64fd0a2017-04-13 17:53:141230void Shell::OnLoginStatusChanged(LoginStatus login_status) {
xiyuan233f4e72017-04-06 06:59:561231 UpdateAfterLoginStatusChange(login_status);
1232
1233 // TODO(xiyuan): Update OnLoginStateChanged -> OnLoginStatusChanged.
1234 for (auto& observer : shell_observers_)
1235 observer.OnLoginStateChanged(login_status);
sky5ad143a2017-03-22 04:31:231236}
1237
Xiyuan Xiab64fd0a2017-04-13 17:53:141238void Shell::OnLockStateChanged(bool locked) {
xiyuan7ebbf7f2017-04-10 16:49:101239 // TODO(xiyuan): Convert OnLockStateChanged() ShellObservers to
1240 // SessionStateObservers.
1241 for (auto& observer : shell_observers_)
1242 observer.OnLockStateChanged(locked);
1243#ifndef NDEBUG
1244 // Make sure that there is no system modal in Lock layer when unlocked.
1245 if (!locked) {
1246 aura::Window::Windows containers = wm::GetContainersFromAllRootWindows(
1247 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
1248 for (aura::Window* container : containers)
1249 DCHECK(container->children().empty());
1250 }
1251#endif
1252}
1253
tibellb93c729b2017-03-30 00:45:091254void Shell::OnPrefServiceInitialized(
1255 std::unique_ptr<::PrefService> pref_service) {
1256 if (!instance_)
1257 return;
sky7bd582ae2017-04-12 21:43:331258 // |pref_service_| is null if can't connect to Chrome (as happens when
1259 // running mash outside of chrome --mash and chrome isn't built).
tibellb93c729b2017-03-30 00:45:091260 pref_service_ = std::move(pref_service);
1261}
1262
[email protected]55f593352011-12-24 05:42:461263} // namespace ash