blob: 8773c1ab338c89faa4210b15bc944cd3a28cc2f1 [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>
Mitsuru Oshima04b54d02017-10-09 14:22:458#include <memory>
[email protected]0039db92012-05-09 04:11:459#include <string>
dchengcbf0d9d2015-12-27 22:49:2310#include <utility>
[email protected]f7eb89c2011-12-13 09:48:5411
James Cookb0bf8e82017-04-09 17:01:4412#include "ash/accelerators/accelerator_controller.h"
[email protected]60d677d2014-05-30 13:07:0213#include "ash/accelerators/accelerator_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4414#include "ash/accelerators/ash_focus_manager_factory.h"
jamescook01bf23e72017-01-09 19:58:1515#include "ash/accelerators/magnifier_key_scroller.h"
16#include "ash/accelerators/spoken_feedback_toggler.h"
James Cookec144952017-09-01 00:05:1617#include "ash/accessibility/accessibility_controller.h"
James Cook37b7d102017-10-06 04:35:1918#include "ash/accessibility/accessibility_delegate.h"
Qiang Xua9591002018-03-15 22:29:3119#include "ash/accessibility/accessibility_focus_ring_controller.h"
David Tseng6792dc82018-05-04 19:18:4120#include "ash/accessibility/key_accessibility_enabler.h"
Jiaquan He4b48f912018-03-01 03:59:3921#include "ash/app_list/app_list_controller_impl.h"
David Black00fdce32018-05-10 20:59:1422#include "ash/assistant/assistant_controller.h"
[email protected]55398d22013-10-10 19:49:2023#include "ash/autoclick/autoclick_controller.h"
James Cookb0bf8e82017-04-09 17:01:4424#include "ash/cast_config_controller.h"
Evan Stadef3c89c602018-06-14 04:44:1225#include "ash/client_image_registry.h"
James Cooka9384092018-05-23 02:54:2626#include "ash/components/tap_visualizer/public/mojom/constants.mojom.h"
Jeffrey Kardatzkef108f022018-04-17 17:52:3527#include "ash/dbus/ash_dbus_services.h"
Toni Barzicd6238312018-03-02 18:26:1328#include "ash/detachable_base/detachable_base_handler.h"
Toni Barzic550419f2018-03-08 03:56:2129#include "ash/detachable_base/detachable_base_notification_controller.h"
Scott Violetd64dac12017-06-02 21:50:0830#include "ash/display/ash_display_controller.h"
Steven Bennetts2a9b4382018-04-26 23:41:1931#include "ash/display/cros_display_config.h"
[email protected]87ec2202014-02-06 06:24:2732#include "ash/display/cursor_window_controller.h"
Mitsuru Oshimaf51c8b42018-03-17 01:41:3233#include "ash/display/display_color_manager.h"
stevenjb537c5c3f2016-01-20 23:38:1234#include "ash/display/display_configuration_controller.h"
Steven Bennetts9b21fa32018-04-13 23:45:5535#include "ash/display/display_configuration_observer.h"
Mitsuru Oshimaf51c8b42018-03-17 01:41:3236#include "ash/display/display_error_observer.h"
Scott Violetbed23cb2018-08-22 19:56:1237#include "ash/display/display_output_protection.h"
Steven Bennetts3688c6032018-04-13 01:14:2338#include "ash/display/display_prefs.h"
Steven Bennetts7683e342018-01-02 21:29:5239#include "ash/display/display_shutdown_observer.h"
[email protected]682990f2013-01-10 06:49:1140#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2741#include "ash/display/mouse_cursor_event_filter.h"
Qiang Xud77a90c2018-02-20 19:43:2942#include "ash/display/persistent_window_controller.h"
Mitsuru Oshimaf51c8b42018-03-17 01:41:3243#include "ash/display/projecting_observer.h"
jamescook01bf23e72017-01-09 19:58:1544#include "ash/display/resolution_notification_controller.h"
rjkroege2c9305402016-09-07 00:21:4545#include "ash/display/screen_ash.h"
Mitsuru Oshimaddfde3552018-03-22 09:12:1346#include "ash/display/screen_orientation_controller.h"
[email protected]8d625fb2012-07-18 16:40:0647#include "ash/display/screen_position_controller.h"
oshimae2818922015-07-28 01:18:5248#include "ash/display/window_tree_host_manager.h"
[email protected]f4c92b382012-08-28 00:59:5949#include "ash/drag_drop/drag_drop_controller.h"
Mike Wasserman5623bac22018-04-30 17:24:3250#include "ash/events/event_rewriter_controller.h"
James Cookf5398842018-04-16 20:15:2451#include "ash/first_run/first_run_helper.h"
James Cookb0bf8e82017-04-09 17:01:4452#include "ash/focus_cycler.h"
Evan Stade5f09e6572018-08-10 17:48:1553#include "ash/frame/non_client_frame_view_ash.h"
[email protected]f4c92b382012-08-28 00:59:5954#include "ash/high_contrast/high_contrast_controller.h"
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:3255#include "ash/highlighter/highlighter_controller.h"
Scott Violet596bb46342017-06-21 14:43:1356#include "ash/host/ash_window_tree_host_init_params.h"
James Cookbb026732017-06-09 23:01:5557#include "ash/ime/ime_controller.h"
Xiyuan Xia5f1046e2018-06-01 16:04:4458#include "ash/ime/ime_focus_handler.h"
James Cook8d912522018-06-19 02:18:4759#include "ash/keyboard/virtual_keyboard_controller.h"
sammiequon203ae022016-09-18 17:23:4260#include "ash/laser/laser_pointer_controller.h"
Jacob Dufaultffd9b0d2017-11-15 23:07:1661#include "ash/login/login_screen_controller.h"
James Cookb0bf8e82017-04-09 17:01:4462#include "ash/login_status.h"
Ahmed Fakhry4bf3f742018-02-06 17:33:3663#include "ash/magnifier/docked_magnifier_controller.h"
[email protected]f4c92b382012-08-28 00:59:5964#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5465#include "ash/magnifier/partial_magnification_controller.h"
James Cookb0bf8e82017-04-09 17:01:4466#include "ash/media_controller.h"
Evan Stadee9974e22017-09-23 00:02:2667#include "ash/message_center/message_center_controller.h"
Scott Violet3c554ae2017-12-13 02:25:4168#include "ash/metrics/time_to_first_present_recorder.h"
Kyle Horimoto9fc84fc22018-04-27 19:45:1569#include "ash/multi_device_setup/multi_device_notification_presenter.h"
James Cookb0bf8e82017-04-09 17:01:4470#include "ash/new_window_controller.h"
Vladislav Kaznacheev92edf62e2017-10-13 22:08:0171#include "ash/note_taking_controller.h"
James Cook31bb3252018-08-08 20:06:4472#include "ash/pointer_watcher_adapter.h"
Qiang Xud8e897e2018-05-24 20:07:5773#include "ash/policy/policy_recommendation_restorer.h"
Steven Bennetts93d3e5b12018-05-05 01:14:5074#include "ash/public/cpp/ash_constants.h"
Ahmed Fakhry4af48e42018-02-28 17:45:3875#include "ash/public/cpp/ash_features.h"
Evan Stade7d0e8232017-10-04 02:01:3676#include "ash/public/cpp/ash_switches.h"
msw109806d2017-06-02 20:11:5777#include "ash/public/cpp/shelf_model.h"
jamescook8800b8232016-10-19 12:46:2778#include "ash/public/cpp/shell_window_ids.h"
[email protected]d90b8392012-06-13 09:34:5679#include "ash/root_window_controller.h"
James Cook5e9d3402017-11-01 00:20:1280#include "ash/screenshot_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4481#include "ash/session/session_controller.h"
James Cook840177e2017-05-25 02:20:0182#include "ash/shelf/shelf.h"
James Cookb0bf8e82017-04-09 17:01:4483#include "ash/shelf/shelf_controller.h"
James Cookb0bf8e82017-04-09 17:01:4484#include "ash/shelf/shelf_window_watcher.h"
James Cookb0bf8e82017-04-09 17:01:4485#include "ash/shell_delegate.h"
[email protected]1b4c7472014-05-15 18:32:2386#include "ash/shell_init_params.h"
James Cookb0bf8e82017-04-09 17:01:4487#include "ash/shell_observer.h"
James Cook40f7d752018-05-25 18:21:5888#include "ash/shell_state.h"
James Cookb0bf8e82017-04-09 17:01:4489#include "ash/shutdown_controller.h"
jamescook01bf23e72017-01-09 19:58:1590#include "ash/sticky_keys/sticky_keys_controller.h"
Tetsui Ohkubo01421b32018-05-30 16:54:5991#include "ash/system/audio/display_speaker_controller.h"
James Cooka35a1e22017-04-08 02:33:0892#include "ash/system/bluetooth/bluetooth_notification_controller.h"
Sonny Sasaka55f69fc2017-08-28 21:29:3793#include "ash/system/bluetooth/bluetooth_power_controller.h"
James Cooka35a1e22017-04-08 02:33:0894#include "ash/system/bluetooth/tray_bluetooth_helper.h"
95#include "ash/system/brightness/brightness_controller_chromeos.h"
James Cookb0bf8e82017-04-09 17:01:4496#include "ash/system/brightness_control_delegate.h"
Tetsui Ohkubo5e2499532018-04-04 02:01:3997#include "ash/system/caps_lock_notification_controller.h"
Lann Martinb9991402017-06-23 22:25:0898#include "ash/system/keyboard_brightness/keyboard_brightness_controller.h"
James Cookb0bf8e82017-04-09 17:01:4499#include "ash/system/keyboard_brightness_control_delegate.h"
James Cookb0bf8e82017-04-09 17:01:44100#include "ash/system/locale/locale_notification_controller.h"
Tetsui Ohkubo21722932018-03-02 02:56:56101#include "ash/system/model/system_tray_model.h"
James Cooka35a1e22017-04-08 02:33:08102#include "ash/system/network/sms_observer.h"
103#include "ash/system/network/vpn_list.h"
afakhrye4fae852017-05-09 18:49:06104#include "ash/system/night_light/night_light_controller.h"
Sammie Quon4d7dba62017-08-03 23:18:17105#include "ash/system/palette/palette_tray.h"
Sammie Quon6c4e2b1f2017-10-13 16:54:18106#include "ash/system/palette/palette_welcome_bubble.h"
Toni Barzic9d0c82f42017-12-06 00:53:52107#include "ash/system/power/backlights_forced_off_setter.h"
Sammie Quon95c6a1c2017-09-12 19:16:55108#include "ash/system/power/peripheral_battery_notifier.h"
Qiang Xu0a86020f2017-10-12 08:34:54109#include "ash/system/power/power_button_controller.h"
James Cooka35a1e22017-04-08 02:33:08110#include "ash/system/power/power_event_observer.h"
Qiang Xu36234e532018-04-11 04:54:02111#include "ash/system/power/power_prefs.h"
James Cooka35a1e22017-04-08 02:33:08112#include "ash/system/power/power_status.h"
113#include "ash/system/power/video_activity_notifier.h"
114#include "ash/system/screen_layout_observer.h"
Tetsui Ohkubo54d50222018-05-10 01:58:11115#include "ash/system/screen_security/screen_switch_check_controller.h"
James Cookdc041122017-08-01 14:03:22116#include "ash/system/session/logout_button_tray.h"
James Cooka35a1e22017-04-08 02:33:08117#include "ash/system/session/logout_confirmation_controller.h"
James Cookb0bf8e82017-04-09 17:01:44118#include "ash/system/status_area_widget.h"
Tetsui Ohkubo269b5792018-04-26 01:06:32119#include "ash/system/system_notification_controller.h"
James Cookb0bf8e82017-04-09 17:01:44120#include "ash/system/toast/toast_manager.h"
James Cookb0bf8e82017-04-09 17:01:44121#include "ash/system/tray/system_tray_notifier.h"
kylechar55f0eaf22017-01-11 22:57:37122#include "ash/touch/ash_touch_transform_controller.h"
Qiang Xuf1400a362017-09-14 02:28:30123#include "ash/touch/touch_devices_controller.h"
tbarzicc78da1ff92017-05-08 20:46:15124#include "ash/tray_action/tray_action.h"
oshima5a296e82016-04-29 01:32:27125#include "ash/utility/screenshot_controller.h"
Yue Lia33960a2017-11-01 22:06:07126#include "ash/voice_interaction/voice_interaction_controller.h"
James Cookb0bf8e82017-04-09 17:01:44127#include "ash/wallpaper/wallpaper_controller.h"
Scott Violet737fb752018-04-11 15:35:22128#include "ash/wayland/wayland_server_controller.h"
[email protected]39718b52012-12-03 17:24:56129#include "ash/wm/ash_focus_rules.h"
James Cookb0bf8e82017-04-09 17:01:44130#include "ash/wm/container_finder.h"
James Cook698fc3662018-07-27 16:05:01131#include "ash/wm/cursor_manager_chromeos.h"
[email protected]262f8bd2012-03-23 19:30:27132#include "ash/wm/event_client_impl.h"
James Cookb0bf8e82017-04-09 17:01:44133#include "ash/wm/immersive_context_ash.h"
skyb7b54092016-08-19 16:00:09134#include "ash/wm/immersive_handler_factory_ash.h"
[email protected]ab4f8c92013-05-30 19:07:47135#include "ash/wm/lock_state_controller.h"
James Cookb0bf8e82017-04-09 17:01:44136#include "ash/wm/mru_window_tracker.h"
James Cookbc2758b42018-09-07 16:20:37137#include "ash/wm/native_cursor_manager_ash.h"
Scott Violetac410622018-08-11 18:33:22138#include "ash/wm/non_client_frame_controller.h"
[email protected]9ae32df2012-07-26 03:25:18139#include "ash/wm/overlay_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44140#include "ash/wm/overview/window_selector_controller.h"
[email protected]e4a181cc2012-03-17 02:20:57141#include "ash/wm/resize_shadow_controller.h"
James Cookb0bf8e82017-04-09 17:01:44142#include "ash/wm/root_window_finder.h"
hidehiko6821ca42016-06-18 11:12:23143#include "ash/wm/screen_pinning_controller.h"
xdaid4913762017-07-06 00:17:22144#include "ash/wm/splitview/split_view_controller.h"
[email protected]435b212e2012-04-05 19:43:37145#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:27146#include "ash/wm/system_modal_container_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44147#include "ash/wm/system_modal_container_layout_manager.h"
Mitsuru Oshima0e9b7a62017-07-19 18:23:03148#include "ash/wm/tablet_mode/tablet_mode_controller.h"
149#include "ash/wm/tablet_mode/tablet_mode_window_manager.h"
[email protected]3537d472014-01-15 05:45:31150#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:58151#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:02152#include "ash/wm/window_animations.h"
James Cookb0bf8e82017-04-09 17:01:44153#include "ash/wm/window_cycle_controller.h"
154#include "ash/wm/window_positioner.h"
[email protected]f059c6942012-07-21 14:27:57155#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:59156#include "ash/wm/window_util.h"
Sammie Quon557418662018-04-25 18:45:51157#include "ash/wm/wm_shadow_controller_delegate.h"
James Cookb0bf8e82017-04-09 17:01:44158#include "ash/wm/workspace_controller.h"
Scott Violetb7f4df22018-05-17 04:43:12159#include "ash/ws/window_service_owner.h"
[email protected]f296be72011-10-11 15:40:00160#include "base/bind.h"
jamescook01bf23e72017-01-09 19:58:15161#include "base/bind_helpers.h"
jamescookfda159002016-10-21 18:48:57162#include "base/command_line.h"
dchenga94547472016-04-08 08:41:11163#include "base/memory/ptr_util.h"
jamescook01bf23e72017-01-09 19:58:15164#include "base/sys_info.h"
primiano7182d7b2015-01-30 18:02:03165#include "base/trace_event/trace_event.h"
Kyle Horimoto9fc84fc22018-04-27 19:45:15166#include "chromeos/chromeos_features.h"
Toni Barzic85c9e0802018-03-30 02:46:01167#include "chromeos/dbus/dbus_thread_manager.h"
Qiang Xu36234e532018-04-11 04:54:02168#include "chromeos/dbus/power_policy_controller.h"
reveman24158982017-01-10 05:58:45169#include "chromeos/system/devicemode.h"
Scott Violet737fb752018-04-11 15:35:22170#include "components/exo/file_helper.h"
tibellb93c729b2017-03-30 00:45:09171#include "components/prefs/pref_registry_simple.h"
172#include "components/prefs/pref_service.h"
Saman Sami3fb310d2017-11-09 16:51:54173#include "components/viz/host/host_frame_sink_manager.h"
Ken Rockot388ba4fc2018-02-10 17:23:41174#include "mash/public/mojom/launchable.mojom.h"
tibellb93c729b2017-03-30 00:45:09175#include "services/preferences/public/cpp/pref_service_factory.h"
Ken Rockotf7f533e2018-02-11 02:21:33176#include "services/preferences/public/mojom/preferences.mojom.h"
derat94887a22017-01-20 18:17:25177#include "services/service_manager/public/cpp/connector.h"
Scott Violet9f984252018-08-27 19:02:13178#include "services/ws/gpu_interface_provider.h"
179#include "services/ws/window_service.h"
[email protected]2c456102011-12-26 06:26:34180#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:44181#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:58182#include "ui/aura/layout_manager.h"
[email protected]87b0d82e2011-10-07 21:02:59183#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:26184#include "ui/aura/window_event_dispatcher.h"
Scott Violet6c0eb6962018-06-20 01:31:26185#include "ui/base/ui_base_features.h"
[email protected]2d4817742012-12-17 20:16:18186#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:17187#include "ui/base/user_activity/user_activity_detector.h"
jamescook01bf23e72017-01-09 19:58:15188#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]116302fc2012-05-05 21:45:41189#include "ui/compositor/layer.h"
190#include "ui/compositor/layer_animator.h"
oshimaf84b0da722016-04-27 19:47:19191#include "ui/display/display.h"
Joone Hurd3ae8732018-04-17 18:05:09192#include "ui/display/manager/default_touch_transform_setter.h"
193#include "ui/display/manager/display_change_observer.h"
194#include "ui/display/manager/display_configurator.h"
rjkroege72f8154f2016-10-29 00:49:02195#include "ui/display/manager/display_manager.h"
Joone Hurd3ae8732018-04-17 18:05:09196#include "ui/display/manager/touch_transform_setter.h"
oshimaf84b0da722016-04-27 19:47:19197#include "ui/display/screen.h"
skycfaad892017-04-28 20:52:58198#include "ui/display/types/native_display_delegate.h"
[email protected]3e670aa2013-12-02 19:04:32199#include "ui/events/event_target_iterator.h"
sky4ec2be82017-01-06 17:38:32200#include "ui/gfx/geometry/insets.h"
[email protected]9ec0f452012-05-31 15:58:53201#include "ui/gfx/image/image_skia.h"
[email protected]b6ba05d902013-10-04 21:38:45202#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28203#include "ui/keyboard/keyboard_switches.h"
yhanada8909a542017-07-11 10:06:19204#include "ui/keyboard/keyboard_ui.h"
[email protected]f1d5c3a2013-04-23 17:42:56205#include "ui/keyboard/keyboard_util.h"
James Cook9db56d72018-08-01 03:21:31206#include "ui/ozone/public/ozone_platform.h"
[email protected]d7f30a72013-10-05 05:09:41207#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04208#include "ui/views/corewm/tooltip_controller.h"
sky07a24d42017-03-09 23:57:30209#include "ui/views/focus/focus_manager_factory.h"
Scott Violetac410622018-08-11 18:33:22210#include "ui/views/mus/window_manager_frame_values.h"
[email protected]c13be0d2011-11-22 02:09:58211#include "ui/views/widget/native_widget_aura.h"
212#include "ui/views/widget/widget.h"
[email protected]60d677d2014-05-30 13:07:02213#include "ui/wm/core/accelerator_filter.h"
[email protected]ee3ed10772014-03-11 22:02:01214#include "ui/wm/core/compound_event_filter.h"
215#include "ui/wm/core/focus_controller.h"
[email protected]ee3ed10772014-03-11 22:02:01216#include "ui/wm/core/shadow_controller.h"
217#include "ui/wm/core/visibility_controller.h"
218#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59219
[email protected]55f593352011-12-24 05:42:46220namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59221
222namespace {
[email protected]671a2ae2011-10-13 21:53:23223
[email protected]615922f2012-02-07 02:41:15224using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45225using views::Widget;
226
jamescook518dccbd2017-05-18 04:57:07227bool g_is_browser_process_with_mash = false;
228
[email protected]b5756e22012-11-30 01:32:02229// A Corewm VisibilityController subclass that calls the Ash animation routine
230// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14231class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02232 public:
Chris Watkinsc24daf62017-11-28 03:43:09233 AshVisibilityController() = default;
234 ~AshVisibilityController() override = default;
[email protected]b5756e22012-11-30 01:32:02235
236 private:
[email protected]e319c7e2014-03-14 19:56:14237 // Overridden from ::wm::VisibilityController:
dcheng1f4538e2014-10-27 23:57:05238 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
239 bool visible) override {
[email protected]b5756e22012-11-30 01:32:02240 return AnimateOnChildWindowVisibilityChanged(window, visible);
241 }
242
243 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
244};
245
Qiang Xu36234e532018-04-11 04:54:02246// Registers prefs whose default values are same in user and signin prefs.
247void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) {
248 AccessibilityController::RegisterProfilePrefs(registry, for_test);
249 BluetoothPowerController::RegisterProfilePrefs(registry);
Qiang Xudcf11e32018-04-25 17:10:17250 DockedMagnifierController::RegisterProfilePrefs(registry, for_test);
Qiang Xu36234e532018-04-11 04:54:02251 LoginScreenController::RegisterProfilePrefs(registry, for_test);
252 LogoutButtonTray::RegisterProfilePrefs(registry);
yoshiki iguchi71623722018-08-10 19:44:45253 MessageCenterController::RegisterProfilePrefs(registry);
Qiang Xu36234e532018-04-11 04:54:02254 NightLightController::RegisterProfilePrefs(registry);
255 PaletteTray::RegisterProfilePrefs(registry);
256 PaletteWelcomeBubble::RegisterProfilePrefs(registry);
257 ShelfController::RegisterProfilePrefs(registry);
Michael Giuffridac997aa72018-08-31 23:38:59258 TouchDevicesController::RegisterProfilePrefs(registry);
Qiang Xu36234e532018-04-11 04:54:02259 CapsLockNotificationController::RegisterProfilePrefs(registry, for_test);
260}
261
[email protected]87b0d82e2011-10-07 21:02:59262} // namespace
263
[email protected]cac10fc62011-10-07 23:22:56264// static
achuith287b26e2015-09-03 17:49:18265Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13266
267////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56268// Shell, public:
269
[email protected]cac10fc62011-10-07 23:22:56270// static
Scott Violetc8a1c6c2017-11-29 23:17:36271Shell* Shell::CreateInstance(ShellInitParams init_params) {
[email protected]3266c2b92011-11-14 00:06:08272 CHECK(!instance_);
James Cookfa4838e2018-08-08 16:30:15273 instance_ = new Shell(std::move(init_params.delegate), init_params.connector);
Scott Violete5c79f52018-07-31 00:10:17274 instance_->Init(init_params.context_factory,
275 init_params.context_factory_private,
276 std::move(init_params.initial_display_prefs),
277 std::move(init_params.gpu_interface_provider));
[email protected]3266c2b92011-11-14 00:06:08278 return instance_;
279}
280
281// static
skyb073203a2017-03-13 16:59:16282Shell* Shell::Get() {
jamescook518dccbd2017-05-18 04:57:07283 CHECK(!g_is_browser_process_with_mash) // Implies null |instance_|.
284 << "Ash is running in its own process so Shell::Get() will return null. "
285 "The browser process must use the mojo interfaces in //ash/public to "
286 "access ash. See ash/README.md for details.";
oshima9eea82da2014-09-13 01:11:07287 CHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56288 return instance_;
289}
290
[email protected]6377a002011-11-10 20:26:47291// static
[email protected]b3b7bcd2012-03-06 19:35:45292bool Shell::HasInstance() {
293 return !!instance_;
294}
295
296// static
[email protected]ef589af2011-12-03 01:07:15297void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47298 delete instance_;
[email protected]6377a002011-11-10 20:26:47299}
300
[email protected]e73bd7802012-02-17 20:10:34301// static
[email protected]093b8d642014-04-03 20:59:28302RootWindowController* Shell::GetPrimaryRootWindowController() {
oshima9eea82da2014-09-13 01:11:07303 CHECK(HasInstance());
msw257a6a232017-06-01 01:46:30304 return RootWindowController::ForWindow(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23305}
306
307// static
308Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
oshima9eea82da2014-09-13 01:11:07309 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34310 RootWindowControllerList root_window_controllers;
msw257a6a232017-06-01 01:46:30311 for (aura::Window* root : GetAllRootWindows())
312 root_window_controllers.push_back(RootWindowController::ForWindow(root));
skyabcae812017-01-18 17:01:34313 return root_window_controllers;
[email protected]d90b8392012-06-13 09:34:56314}
315
316// static
thanhphc90f49ca2017-03-03 17:48:53317RootWindowController* Shell::GetRootWindowControllerWithDisplayId(
318 int64_t display_id) {
319 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13320 aura::Window* root = GetRootWindowForDisplayId(display_id);
msw257a6a232017-06-01 01:46:30321 return root ? RootWindowController::ForWindow(root) : nullptr;
thanhphc90f49ca2017-03-03 17:48:53322}
323
324// static
Scott Violet596bb46342017-06-21 14:43:13325aura::Window* Shell::GetRootWindowForDisplayId(int64_t display_id) {
326 CHECK(HasInstance());
327 return instance_->window_tree_host_manager_->GetRootWindowForDisplayId(
328 display_id);
329}
330
331// static
[email protected]bf9cdb362013-10-25 19:22:45332aura::Window* Shell::GetPrimaryRootWindow() {
oshima9eea82da2014-09-13 01:11:07333 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13334 return instance_->window_tree_host_manager_->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34335}
336
[email protected]7b0f7502012-06-11 00:12:39337// static
sky27344382017-03-08 21:30:32338aura::Window* Shell::GetRootWindowForNewWindows() {
James Cook40f7d752018-05-25 18:21:58339 return Shell::Get()->shell_state_->GetRootWindowForNewWindows();
mfomitcheva1a8aa62016-05-03 16:23:26340}
341
342// static
[email protected]c9390bd2013-11-08 20:33:13343aura::Window::Windows Shell::GetAllRootWindows() {
oshima9eea82da2014-09-13 01:11:07344 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13345 return instance_->window_tree_host_manager_->GetAllRootWindows();
[email protected]be65be362012-06-15 07:38:23346}
347
348// static
jamescookb8dcef522016-06-25 14:42:55349aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) {
[email protected]7b0f7502012-06-11 00:12:39350 return root_window->GetChildById(container_id);
351}
352
353// static
[email protected]bf9cdb362013-10-25 19:22:45354const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38355 int container_id) {
356 return root_window->GetChildById(container_id);
357}
358
sky494c6cbd2017-03-27 20:57:48359// static
James Cook7b7c6a52018-01-04 23:40:03360int Shell::GetOpenSystemModalWindowContainerId() {
361 // The test boolean is not static to avoid leaking state between tests.
362 if (Get()->simulate_modal_window_open_for_test_)
363 return kShellWindowId_SystemModalContainer;
364
365 // Traverse all system modal containers, and find its direct child window
366 // with "SystemModal" setting, and visible.
James Cook7b7c6a52018-01-04 23:40:03367 for (aura::Window* root : Shell::GetAllRootWindows()) {
Xiyuan Xia40b3fb1f2018-08-22 22:18:20368 for (int modal_window_id : kSystemModalContainerIds) {
James Cook7b7c6a52018-01-04 23:40:03369 aura::Window* system_modal = root->GetChildById(modal_window_id);
370 if (!system_modal)
371 continue;
372 for (const aura::Window* child : system_modal->children()) {
373 if (child->GetProperty(aura::client::kModalKey) ==
374 ui::MODAL_TYPE_SYSTEM &&
375 child->layer()->GetTargetVisibility()) {
376 return modal_window_id;
377 }
378 }
379 }
380 }
381 return -1;
382}
383
384// static
385bool Shell::IsSystemModalWindowOpen() {
386 return GetOpenSystemModalWindowContainerId() >= 0;
387}
388
389// static
James Cooka6066972018-07-31 19:34:07390bool Shell::HasRemoteClient(aura::Window* window) {
Scott Violet7e33efc2018-08-29 22:30:15391 return ws::WindowService::HasRemoteClient(window);
James Cooka6066972018-07-31 19:34:07392}
393
394// static
Steven Bennettsca108512018-05-02 11:05:03395void Shell::RegisterLocalStatePrefs(PrefRegistrySimple* registry,
396 bool for_test) {
Sammie Quon4d7dba62017-08-03 23:18:17397 PaletteTray::RegisterLocalStatePrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34398 WallpaperController::RegisterLocalStatePrefs(registry);
Sonny Sasaka55f69fc2017-08-28 21:29:37399 BluetoothPowerController::RegisterLocalStatePrefs(registry);
Toni Barzicd6238312018-03-02 18:26:13400 DetachableBaseHandler::RegisterPrefs(registry);
Steven Bennettsca108512018-05-02 11:05:03401 // Note: DisplayPrefs are registered in chrome in AshShellInit::RegisterPrefs
402 // (see comment there for details).
403 if (for_test)
404 DisplayPrefs::RegisterLocalStatePrefs(registry);
405 else
406 DisplayPrefs::RegisterForeignPrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34407}
408
409// static
Qiang Xu36234e532018-04-11 04:54:02410void Shell::RegisterSigninProfilePrefs(PrefRegistrySimple* registry,
411 bool for_test) {
412 RegisterProfilePrefs(registry, for_test);
413 PowerPrefs::RegisterSigninProfilePrefs(registry, for_test);
414}
415
416// static
417void Shell::RegisterUserProfilePrefs(PrefRegistrySimple* registry,
418 bool for_test) {
419 RegisterProfilePrefs(registry, for_test);
420 PowerPrefs::RegisterUserProfilePrefs(registry, for_test);
afakhrye4fae852017-05-09 18:49:06421}
422
Xiyuan Xia36197372018-04-25 00:45:17423void Shell::InitWaylandServer(std::unique_ptr<exo::FileHelper> file_helper) {
Scott Violetac410622018-08-11 18:33:22424 wayland_server_controller_ = WaylandServerController::CreateIfNecessary(
425 std::move(file_helper), aura_env_);
Scott Violet737fb752018-04-11 15:35:22426}
427
428void Shell::DestroyWaylandServer() {
429 wayland_server_controller_.reset();
430}
431
[email protected]57b8bb352012-01-11 05:11:46432views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
433 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04434 // Use translucent-style window frames for dialogs.
Evan Stade5f09e6572018-08-10 17:48:15435 return new NonClientFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46436}
437
[email protected]2e236a52012-06-27 22:21:47438void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44439 const gfx::Insets& insets) {
Scott Violet596bb46342017-06-21 14:43:13440 window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow(contains,
441 insets);
[email protected]1a2145b2012-03-13 21:09:17442}
443
[email protected]58868abf2014-01-17 23:45:33444void Shell::OnCastingSessionStartedOrStopped(bool started) {
sky00c813f2017-03-08 22:48:55445 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18446 observer.OnCastingSessionStartedOrStopped(started);
[email protected]58868abf2014-01-17 23:45:33447}
448
varkhac71444e52017-05-25 22:51:34449void Shell::OnRootWindowAdded(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55450 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18451 observer.OnRootWindowAdded(root_window);
[email protected]0e3e7cb2014-04-12 05:18:25452}
453
Zach Helfinsteinbbb6bad2018-05-02 18:21:51454void Shell::OnDictationStarted() {
455 for (auto& observer : shell_observers_)
456 observer.OnDictationStarted();
457}
458
459void Shell::OnDictationEnded() {
460 for (auto& observer : shell_observers_)
461 observer.OnDictationEnded();
462}
463
Darren Shenf62db77a2018-06-07 06:22:44464void Shell::EnableKeyboard() {
Darren Shena314c212018-05-22 00:53:17465 if (!keyboard::IsKeyboardEnabled())
466 return;
467
Darren Shenf62db77a2018-06-07 06:22:44468 if (keyboard_controller_->enabled()) {
469 // Disable and re-enable the keyboard, as some callers expect the keyboard
470 // to be reloaded.
471 // TODO(https://crbug.com/731537): Add a separate function for reloading the
472 // keyboard.
473 for (auto* const controller : GetAllRootWindowControllers())
474 controller->DeactivateKeyboard(keyboard_controller_.get());
Keigo Okae82281a2017-06-14 13:59:14475 }
Mike Wassermancebe67682018-06-28 23:01:35476
James Cook8160d0332018-08-21 16:02:32477 // TODO(crbug.com/646565): The keyboard UI uses a WebContents that is
478 // created by chrome code but parented to an ash-created container window.
479 // See ChromeKeyboardUI and keyboard::KeyboardController. This needs to be
480 // fixed for both SingleProcessMash and MultiProcessMash.
481 if (::features::IsUsingWindowService())
Mike Wassermancebe67682018-06-28 23:01:35482 return;
483
James Cook8160d0332018-08-21 16:02:32484 auto keyboard_ui = shell_delegate_->CreateKeyboardUI();
485 DCHECK(keyboard_ui);
Mike Wassermancebe67682018-06-28 23:01:35486 keyboard_controller_->EnableKeyboard(std::move(keyboard_ui),
Darren Shenad5dc722018-05-28 00:14:45487 virtual_keyboard_controller_.get());
Darren Shena314c212018-05-22 00:53:17488 for (auto& observer : shell_observers_)
489 observer.OnKeyboardControllerCreated();
jamescookb8dcef522016-06-25 14:42:55490 GetPrimaryRootWindowController()->ActivateKeyboard(
Darren Shenf62db77a2018-06-07 06:22:44491 keyboard_controller_.get());
[email protected]51f438112013-11-18 19:32:50492}
493
Darren Shenf62db77a2018-06-07 06:22:44494void Shell::DisableKeyboard() {
Darren Shenf62db77a2018-06-07 06:22:44495 if (keyboard_controller_->enabled()) {
496 for (auto* const controller : GetAllRootWindowControllers())
497 controller->DeactivateKeyboard(keyboard_controller_.get());
[email protected]e1b299b2014-01-29 23:53:41498 }
Darren Shenf62db77a2018-06-07 06:22:44499
Darren Shenad5dc722018-05-28 00:14:45500 keyboard_controller_->DisableKeyboard();
[email protected]e1b299b2014-01-29 23:53:41501}
502
[email protected]da285852014-05-27 19:53:43503bool Shell::ShouldSaveDisplaySettings() {
jamescookb8dcef522016-06-25 14:42:55504 return !(
505 screen_orientation_controller_->ignore_display_configuration_updates() ||
506 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43507}
[email protected]da285852014-05-27 19:53:43508
Ahmed Fakhry4bf3f742018-02-06 17:33:36509DockedMagnifierController* Shell::docked_magnifier_controller() {
Ahmed Fakhry4af48e42018-02-28 17:45:38510 DCHECK(features::IsDockedMagnifierEnabled());
Ahmed Fakhry4bf3f742018-02-06 17:33:36511 return docked_magnifier_controller_.get();
512}
513
afakhry9e0a18b32017-06-05 19:23:14514NightLightController* Shell::night_light_controller() {
Ahmed Fakhryb9ace242018-06-06 18:49:31515 DCHECK(features::IsNightLightEnabled());
afakhry9e0a18b32017-06-05 19:23:14516 return night_light_controller_.get();
517}
518
sky5ad143a2017-03-22 04:31:23519ShelfModel* Shell::shelf_model() {
520 return shelf_controller_->model();
521}
522
Thiago Farina3b086a02017-05-30 22:32:50523::wm::ActivationClient* Shell::activation_client() {
sky27344382017-03-08 21:30:32524 return focus_controller_.get();
525}
526
[email protected]c758fbf2012-03-25 22:53:59527void Shell::UpdateShelfVisibility() {
msw257a6a232017-06-01 01:46:30528 for (aura::Window* root : GetAllRootWindows())
529 Shelf::ForWindow(root)->UpdateVisibilityState();
[email protected]c758fbf2012-03-25 22:53:59530}
531
Xiyuan Xia522710a2018-05-08 16:35:42532NotificationTray* Shell::GetNotificationTray() {
jamescook612205f2016-05-26 06:02:11533 return GetPrimaryRootWindowController()
jamescookb551aba2016-09-01 01:00:16534 ->GetStatusAreaWidget()
Xiyuan Xia522710a2018-05-08 16:35:42535 ->notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28536}
537
[email protected]a0afeb12012-12-10 22:57:09538bool Shell::HasPrimaryStatusArea() {
jamescookb551aba2016-09-01 01:00:16539 return !!GetPrimaryRootWindowController()->GetStatusAreaWidget();
[email protected]31f19e32012-10-30 22:31:23540}
541
[email protected]a0afeb12012-12-10 22:57:09542SystemTray* Shell::GetPrimarySystemTray() {
543 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42544}
545
yawanodc5533b32017-02-23 11:04:38546void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
547 window_tree_host_manager_->cursor_window_controller()
548 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
549}
550
Weidong Guod07448f2017-10-18 03:35:18551void Shell::UpdateCursorCompositingEnabled() {
552 SetCursorCompositingEnabled(
553 window_tree_host_manager_->cursor_window_controller()
554 ->ShouldEnableCursorCompositing());
555}
556
[email protected]87ec2202014-02-06 06:24:27557void Shell::SetCursorCompositingEnabled(bool enabled) {
James Cookf2920df2018-09-04 19:55:01558 CursorWindowController* cursor_window_controller =
559 window_tree_host_manager_->cursor_window_controller();
Weidong Guo7dfd1482017-11-08 05:56:28560
James Cookf2920df2018-09-04 19:55:01561 if (cursor_window_controller->is_cursor_compositing_enabled() == enabled)
562 return;
563 cursor_window_controller->SetCursorCompositingEnabled(enabled);
564 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
[email protected]87ec2202014-02-06 06:24:27565}
[email protected]59ccade2013-10-17 17:56:40566
[email protected]f9466702012-09-17 16:35:27567void Shell::DoInitialWorkspaceAnimation() {
jamescookb8dcef522016-06-25 14:42:55568 return GetPrimaryRootWindowController()
569 ->workspace_controller()
570 ->DoInitialAnimation();
[email protected]f9466702012-09-17 16:35:27571}
572
xdaid4913762017-07-06 00:17:22573bool Shell::IsSplitViewModeActive() const {
Xiaoqian Daibf3771f2018-03-13 18:21:46574 return split_view_controller_.get() &&
575 split_view_controller_->IsSplitViewModeActive();
xdaid4913762017-07-06 00:17:22576}
577
James Cookfa4838e2018-08-08 16:30:15578void Shell::ShowContextMenu(const gfx::Point& location_in_screen,
579 ui::MenuSourceType source_type) {
580 // Bail with no active user session, in the lock screen, or in app/kiosk mode.
581 if (session_controller_->NumberOfLoggedInUsers() < 1 ||
582 session_controller_->IsScreenLocked() ||
583 session_controller_->IsRunningInAppMode()) {
584 return;
585 }
586
587 aura::Window* root = wm::GetRootWindowAt(location_in_screen);
588 RootWindowController::ForWindow(root)->ShowContextMenu(location_in_screen,
589 source_type);
590}
591
592void Shell::AddPointerWatcher(views::PointerWatcher* watcher,
593 views::PointerWatcherEventTypes events) {
594 pointer_watcher_adapter_->AddPointerWatcher(watcher, events);
595}
596
597void Shell::RemovePointerWatcher(views::PointerWatcher* watcher) {
598 pointer_watcher_adapter_->RemovePointerWatcher(watcher);
599}
600
sky00c813f2017-03-08 22:48:55601void Shell::AddShellObserver(ShellObserver* observer) {
602 shell_observers_.AddObserver(observer);
603}
604
605void Shell::RemoveShellObserver(ShellObserver* observer) {
606 shell_observers_.RemoveObserver(observer);
607}
608
sky5ad143a2017-03-22 04:31:23609void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
varkha59679632017-06-01 00:42:05610 for (auto* root_window_controller : GetAllRootWindowControllers())
611 root_window_controller->UpdateAfterLoginStatusChange(status);
sky5ad143a2017-03-22 04:31:23612}
613
sky00c813f2017-03-08 22:48:55614void Shell::NotifyOverviewModeStarting() {
615 for (auto& observer : shell_observers_)
616 observer.OnOverviewModeStarting();
617}
618
Xiaoqian Daifb4698ed2018-02-23 20:11:06619void Shell::NotifyOverviewModeEnding() {
620 for (auto& observer : shell_observers_)
621 observer.OnOverviewModeEnding();
622}
623
sky00c813f2017-03-08 22:48:55624void Shell::NotifyOverviewModeEnded() {
625 for (auto& observer : shell_observers_)
626 observer.OnOverviewModeEnded();
627}
628
Sammie Quon317deb52018-09-06 16:36:28629void Shell::NotifyOverviewModeEndingAnimationComplete() {
630 for (auto& observer : shell_observers_)
631 observer.OnOverviewModeEndingAnimationComplete();
632}
633
xdaid4913762017-07-06 00:17:22634void Shell::NotifySplitViewModeStarting() {
635 for (auto& observer : shell_observers_)
636 observer.OnSplitViewModeStarting();
637}
638
Xiaoqian Daibf3771f2018-03-13 18:21:46639void Shell::NotifySplitViewModeStarted() {
640 for (auto& observer : shell_observers_)
641 observer.OnSplitViewModeStarted();
642}
643
xdaid4913762017-07-06 00:17:22644void Shell::NotifySplitViewModeEnded() {
645 for (auto& observer : shell_observers_)
646 observer.OnSplitViewModeEnded();
647}
648
sky00c813f2017-03-08 22:48:55649void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
varkhac71444e52017-05-25 22:51:34650 aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55651 for (auto& observer : shell_observers_)
652 observer.OnFullscreenStateChanged(is_fullscreen, root_window);
653}
654
varkha19d7e6c52017-05-25 21:15:30655void Shell::NotifyPinnedStateChanged(aura::Window* pinned_window) {
sky00c813f2017-03-08 22:48:55656 for (auto& observer : shell_observers_)
657 observer.OnPinnedStateChanged(pinned_window);
658}
659
varkha6b016b0f2017-05-26 16:14:18660void Shell::NotifyShelfAlignmentChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55661 for (auto& observer : shell_observers_)
662 observer.OnShelfAlignmentChanged(root_window);
663}
664
varkha6b016b0f2017-05-26 16:14:18665void Shell::NotifyShelfAutoHideBehaviorChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55666 for (auto& observer : shell_observers_)
667 observer.OnShelfAutoHideBehaviorChanged(root_window);
668}
669
jamescook518dccbd2017-05-18 04:57:07670// static
671void Shell::SetIsBrowserProcessWithMash() {
672 g_is_browser_process_with_mash = true;
673}
674
muyuanlid766f2e2017-06-26 20:17:19675void Shell::NotifyAppListVisibilityChanged(bool visible,
676 aura::Window* root_window) {
newcomer2febb9832017-06-12 17:00:23677 for (auto& observer : shell_observers_)
678 observer.OnAppListVisibilityChanged(visible, root_window);
679}
680
[email protected]b6ba05d902013-10-04 21:38:45681////////////////////////////////////////////////////////////////////////////////
682// Shell, private:
683
skyb073203a2017-03-13 16:59:16684Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
Scott Violete5c79f52018-07-31 00:10:17685 service_manager::Connector* connector)
Scott Violetac410622018-08-11 18:33:22686 : owned_aura_env_(::features::IsSingleProcessMash()
687 ? aura::Env::CreateLocalInstanceForInProcess()
688 : nullptr),
689 aura_env_(owned_aura_env_.get() ? owned_aura_env_.get()
690 : aura::Env::GetInstance()),
691 ash_display_controller_(std::make_unique<AshDisplayController>()),
sky79fa34712017-03-20 23:46:47692 brightness_control_delegate_(
Mitsuru Oshima04b54d02017-10-09 14:22:45693 std::make_unique<system::BrightnessControllerChromeos>()),
694 cast_config_(std::make_unique<CastConfigController>()),
Scott Violete5c79f52018-07-31 00:10:17695 connector_(connector),
James Cookf5398842018-04-16 20:15:24696 first_run_helper_(std::make_unique<FirstRunHelper>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45697 focus_cycler_(std::make_unique<FocusCycler>()),
698 ime_controller_(std::make_unique<ImeController>()),
699 immersive_context_(std::make_unique<ImmersiveContextAsh>()),
sky79fa34712017-03-20 23:46:47700 keyboard_brightness_control_delegate_(
Mitsuru Oshima04b54d02017-10-09 14:22:45701 std::make_unique<KeyboardBrightnessController>()),
Darren Shenad5dc722018-05-28 00:14:45702 keyboard_controller_(std::make_unique<keyboard::KeyboardController>()),
sky79fa34712017-03-20 23:46:47703 locale_notification_controller_(
Mitsuru Oshima04b54d02017-10-09 14:22:45704 std::make_unique<LocaleNotificationController>()),
Jacob Dufaultffd9b0d2017-11-15 23:07:16705 login_screen_controller_(std::make_unique<LoginScreenController>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45706 media_controller_(std::make_unique<MediaController>()),
707 new_window_controller_(std::make_unique<NewWindowController>()),
Scott Violete5c79f52018-07-31 00:10:17708 session_controller_(std::make_unique<SessionController>(connector)),
Vladislav Kaznacheev92edf62e2017-10-13 22:08:01709 note_taking_controller_(std::make_unique<NoteTakingController>()),
skyb073203a2017-03-13 16:59:16710 shell_delegate_(std::move(shell_delegate)),
James Cook40f7d752018-05-25 18:21:58711 shell_state_(std::make_unique<ShellState>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45712 shutdown_controller_(std::make_unique<ShutdownController>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45713 system_tray_notifier_(std::make_unique<SystemTrayNotifier>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45714 vpn_list_(std::make_unique<VpnList>()),
715 window_cycle_controller_(std::make_unique<WindowCycleController>()),
716 window_selector_controller_(std::make_unique<WindowSelectorController>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45717 tray_bluetooth_helper_(std::make_unique<TrayBluetoothHelper>()),
Scott Violetbed23cb2018-08-22 19:56:12718 display_configurator_(std::make_unique<display::DisplayConfigurator>()),
719 display_output_protection_(std::make_unique<DisplayOutputProtection>(
720 display_configurator_.get())),
sadrul7a8785e2016-02-12 21:54:35721 native_cursor_manager_(nullptr),
Sam McNallye36abbc2017-07-20 01:04:28722 weak_factory_(this) {
Scott Violet596bb46342017-06-21 14:43:13723 display_manager_.reset(ScreenAsh::CreateDisplayManager());
Mitsuru Oshima04b54d02017-10-09 14:22:45724 window_tree_host_manager_ = std::make_unique<WindowTreeHostManager>();
725 user_metrics_recorder_ = std::make_unique<UserMetricsRecorder>();
[email protected]b6ba05d902013-10-04 21:38:45726
[email protected]093b8d642014-04-03 20:59:28727 PowerStatus::Initialize();
sky5ad143a2017-03-22 04:31:23728
Xiyuan Xia22b1a6c2017-04-18 22:46:01729 session_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45730}
731
732Shell::~Shell() {
733 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
734
Scott Violet737fb752018-04-11 15:35:22735 // Wayland depends upon some ash specific objects. Destroy it early on.
736 wayland_server_controller_.reset();
737
Scott Violet41562d1c2017-06-26 15:15:48738 user_metrics_recorder_->OnShellShuttingDown();
bruthigc24d11f2015-06-09 21:30:03739
Steven Bennetts2a9b4382018-04-26 23:41:19740 cros_display_config_.reset();
Steven Bennetts9b21fa32018-04-13 23:45:55741 display_configuration_observer_.reset();
Steven Bennetts3688c6032018-04-13 01:14:23742 display_prefs_.reset();
[email protected]050e77182014-03-25 15:29:16743
[email protected]b6ba05d902013-10-04 21:38:45744 // Remove the focus from any window. This will prevent overhead and side
745 // effects (e.g. crashes) from changing focus during shutdown.
746 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18747 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45748
xdaid4913762017-07-06 00:17:22749 // Please keep in reverse order as in Init() because it's easy to miss one.
[email protected]b6ba05d902013-10-04 21:38:45750 if (window_modality_controller_)
751 window_modality_controller_.reset();
jamescook01bf23e72017-01-09 19:58:15752
[email protected]e4ea52362014-02-15 03:21:06753 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
754 magnifier_key_scroll_handler_.reset();
755
756 RemovePreTargetHandler(speech_feedback_handler_.get());
757 speech_feedback_handler_.reset();
jamescook01bf23e72017-01-09 19:58:15758
[email protected]b6ba05d902013-10-04 21:38:45759 RemovePreTargetHandler(overlay_filter_.get());
Xiyuan Xia22b1a6c2017-04-18 22:46:01760 overlay_filter_.reset();
761
[email protected]3537d472014-01-15 05:45:31762 RemovePreTargetHandler(accelerator_filter_.get());
763 RemovePreTargetHandler(event_transformation_handler_.get());
764 RemovePreTargetHandler(toplevel_window_event_handler_.get());
765 RemovePostTargetHandler(toplevel_window_event_handler_.get());
Scott Violet596bb46342017-06-21 14:43:13766 RemovePreTargetHandler(system_gesture_filter_.get());
767 RemovePreTargetHandler(mouse_cursor_filter_.get());
hariank0dd03dd2016-07-14 23:47:33768 RemovePreTargetHandler(modality_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45769 RemovePreTargetHandler(tooltip_controller_.get());
770
Mike Wassermanefbf3402018-04-26 00:41:32771 event_rewriter_controller_.reset();
772
jonross0af45212015-01-13 18:55:46773 screen_orientation_controller_.reset();
yiyixa68ade512016-09-01 17:38:13774 screen_layout_observer_.reset();
jonross0af45212015-01-13 18:55:46775
Mitsuru Oshima0e9b7a62017-07-19 18:23:03776 // Destroy the virtual keyboard controller before the tablet mode controller
jamescook01bf23e72017-01-09 19:58:15777 // since the latters destructor triggers events that the former is listening
778 // to but no longer cares about.
rsadambbaf2c82015-01-07 17:54:13779 virtual_keyboard_controller_.reset();
jonross0af45212015-01-13 18:55:46780
James Cookd2495fe2018-03-19 19:53:10781 // Depends on |tablet_mode_controller_|.
782 shelf_controller_->Shutdown();
783
Weidong Guo268c7992018-04-13 21:06:07784 // Destroy |app_list_controller_| early than |tablet_mode_controller_| since
785 // the former may use the latter before destruction.
786 app_list_controller_.reset();
787
David Blackc153e3172018-08-21 18:17:58788 // Destroy |assistant_controller_| earlier than |tablet_mode_controller_| so
789 // that the former will destroy the Assistant view hierarchy which has a
790 // dependency on the latter.
Muyuan Li628f6a62018-08-15 20:39:58791 if (chromeos::switches::IsAssistantEnabled())
David Blackc153e3172018-08-21 18:17:58792 assistant_controller_.reset();
Muyuan Li628f6a62018-08-15 20:39:58793
Mitsuru Oshima0e9b7a62017-07-19 18:23:03794 // Destroy tablet mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57795 // need to be removed.
Mitsuru Oshima0e9b7a62017-07-19 18:23:03796 tablet_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57797
jdufault551152e2016-01-27 19:48:43798 // Destroy the keyboard before closing the shelf, since it will invoke a shelf
799 // layout.
Darren Shenf62db77a2018-06-07 06:22:44800 DisableKeyboard();
jdufault551152e2016-01-27 19:48:43801
sky07a24d42017-03-09 23:57:30802 toast_manager_.reset();
yoshiki32f51632016-03-24 01:24:43803
jamescookac6724332017-03-21 02:54:43804 tray_bluetooth_helper_.reset();
James Cookb50959e22017-08-10 20:24:38805
806 // Accesses root window containers.
807 logout_confirmation_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45808
[email protected]b6ba05d902013-10-04 21:38:45809 // Drag-and-drop must be canceled prior to close all windows.
James Cook1e0f3ff2018-03-06 22:52:45810 for (aura::Window* root : GetAllRootWindows())
811 aura::client::SetDragDropClient(root, nullptr);
[email protected]b6ba05d902013-10-04 21:38:45812 drag_drop_controller_.reset();
813
Xiyuan Xia22b1a6c2017-04-18 22:46:01814 // Controllers who have WindowObserver added must be deleted
815 // before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03816
Qiang Xud77a90c2018-02-20 19:43:29817 persistent_window_controller_.reset();
818
[email protected]8c9d12a2013-12-06 18:39:03819 // VideoActivityNotifier must be deleted before |video_detector_| is
820 // deleted because it's observing video activity through
derat83b761392016-07-11 16:44:44821 // VideoDetector::Observer interface.
[email protected]8c9d12a2013-12-06 18:39:03822 video_activity_notifier_.reset();
[email protected]8c9d12a2013-12-06 18:39:03823 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25824 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03825
826 shadow_controller_.reset();
827 resize_shadow_controller_.reset();
828
sky37f0dd12016-07-19 18:00:59829 // Has to happen before ~MruWindowTracker.
sky5b45ed82017-03-27 02:54:23830 window_cycle_controller_.reset();
831 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03832
xdai7a8867cd2017-08-25 23:10:16833 // |split_view_controller_| needs to be deleted after
834 // |window_selector_controller_|.
835 split_view_controller_.reset();
836
James Cook43097132018-08-18 23:31:54837 // Stop dispatching events (e.g. synthesized mouse exits from window close).
838 // https://crbug.com/874156
839 for (RootWindowController* rwc : GetAllRootWindowControllers())
840 rwc->GetHost()->dispatcher()->Shutdown();
841
James Cookee2daef2018-03-10 01:48:10842 // Close all widgets (including the shelf) and destroy all window containers.
skyabcae812017-01-18 17:01:34843 CloseAllRootWindowChildWindows();
844
Tetsui Ohkubo269b5792018-04-26 01:06:32845 system_notification_controller_.reset();
846 // Should be destroyed after Shelf and |system_notification_controller_|.
847 system_tray_model_.reset();
848
afakhry58159392015-05-22 02:45:52849 // MruWindowTracker must be destroyed after all windows have been deleted to
850 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
851 // path. (crbug.com/485438).
sky5ab16472017-03-21 19:35:08852 mru_window_tracker_.reset();
[email protected]b6ba05d902013-10-04 21:38:45853
[email protected]b6ba05d902013-10-04 21:38:45854 // These need a valid Shell instance to clean up properly, so explicitly
855 // delete them before invalidating the instance.
856 // Alphabetical. TODO(oshima): sort.
857 magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45858 tooltip_controller_.reset();
859 event_client_.reset();
[email protected]3537d472014-01-15 05:45:31860 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45861 visibility_controller_.reset();
Qiang Xu36234e532018-04-11 04:54:02862 power_prefs_.reset();
[email protected]b6ba05d902013-10-04 21:38:45863
Toni Barzic85ae39e2017-12-07 05:50:18864 tray_action_.reset();
865
[email protected]b6ba05d902013-10-04 21:38:45866 power_button_controller_.reset();
867 lock_state_controller_.reset();
Toni Barzic9d0c82f42017-12-06 00:53:52868 backlights_forced_off_setter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45869
hidehiko6821ca42016-06-18 11:12:23870 screen_pinning_controller_.reset();
871
Kyle Horimoto9fc84fc22018-04-27 19:45:15872 multidevice_notification_presenter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45873 resolution_notification_controller_.reset();
oshima5a296e82016-04-29 01:32:27874 screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49875 mouse_cursor_filter_.reset();
hariank0dd03dd2016-07-14 23:47:33876 modality_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45877
[email protected]03122891a2014-05-13 23:56:49878 touch_transformer_controller_.reset();
sammiequon203ae022016-09-18 17:23:42879 laser_pointer_controller_.reset();
880 partial_magnification_controller_.reset();
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:32881 highlighter_controller_.reset();
Yue Lia33960a2017-11-01 22:06:07882 voice_interaction_controller_.reset();
David Tseng6792dc82018-05-04 19:18:41883 key_accessibility_enabler_.reset();
warx533c8f62016-04-12 01:19:43884
Tetsui Ohkubo01421b32018-05-30 16:54:59885 display_speaker_controller_.reset();
Tetsui Ohkubo54d50222018-05-10 01:58:11886 screen_switch_check_controller_.reset();
887
rjkroege2c9305402016-09-07 00:21:45888 ScreenAsh::CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12889 display_configuration_controller_.reset();
dtseng4ae0a882016-04-15 21:39:27890
sky07a24d42017-03-09 23:57:30891 // These members access Shell in their destructors.
892 wallpaper_controller_.reset();
James Cookec144952017-09-01 00:05:16893 accessibility_controller_.reset();
sky07a24d42017-03-09 23:57:30894 accessibility_delegate_.reset();
Qiang Xua9591002018-03-15 22:29:31895 accessibility_focus_ring_controller_.reset();
Qiang Xud8e897e2018-05-24 20:07:57896 policy_recommendation_restorer_.reset();
sky07a24d42017-03-09 23:57:30897
898 // Balances the Install() in Initialize().
899 views::FocusManagerFactory::Install(nullptr);
900
sky5ad143a2017-03-22 04:31:23901 // ShelfWindowWatcher has window observers and a pointer to the shelf model.
902 shelf_window_watcher_.reset();
903
tibellb93c729b2017-03-30 00:45:09904 // Removes itself as an observer of |pref_service_|.
sky5ad143a2017-03-22 04:31:23905 shelf_controller_.reset();
906
Ahmed Fakhrye96051f2017-12-12 17:42:17907 // NightLightController depends on the PrefService as well as the window tree
908 // host manager, and must be destructed before them. crbug.com/724231.
909 night_light_controller_ = nullptr;
Ahmed Fakhry4bf3f742018-02-06 17:33:36910 // Similarly for DockedMagnifierController.
911 docked_magnifier_controller_ = nullptr;
Ahmed Fakhrye96051f2017-12-12 17:42:17912
Scott Violetb7f4df22018-05-17 04:43:12913 // May own windows and other objects that have indirect hooks into
914 // WindowTreeHostManager.
915 window_service_owner_.reset();
916
Xiyuan Xia5f1046e2018-06-01 16:04:44917 // Must be released before |focus_controller_|.
918 ime_focus_handler_.reset();
919
James Cookfa4838e2018-08-08 16:30:15920 pointer_watcher_adapter_.reset();
James Cook05b3a3f2018-08-07 00:38:55921
922 // Stop observing window activation changes before closing all windows.
923 focus_controller_->RemoveObserver(this);
924
925 // This also deletes all RootWindows. Note that we invoke Shutdown() on
926 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
927 // destruction of its owned RootWindowControllers relies on the value.
Scott Violet596bb46342017-06-21 14:43:13928 window_tree_host_manager_->Shutdown();
sky5ad143a2017-03-22 04:31:23929
sky27344382017-03-08 21:30:32930 // Depends on |focus_controller_|, so must be destroyed before.
oshimae2818922015-07-28 01:18:52931 window_tree_host_manager_.reset();
sky27344382017-03-08 21:30:32932 focus_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45933 screen_position_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45934
robert.bradfordab052492015-05-06 11:09:56935 display_color_manager_.reset();
Steven Bennetts7683e342018-01-02 21:29:52936 projecting_observer_.reset();
937
[email protected]7bc49bd2014-01-22 09:30:34938 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11939 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45940 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11941 display_configurator_->RemoveObserver(display_error_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45942 display_change_observer_.reset();
Steven Bennetts7683e342018-01-02 21:29:52943 display_shutdown_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45944
[email protected]093b8d642014-04-03 20:59:28945 PowerStatus::Shutdown();
James Cook934ba812018-04-20 14:17:35946 // Depends on SessionController.
947 power_event_observer_.reset();
pneubeck8be1f5422014-10-09 16:46:18948
Xiyuan Xia22b1a6c2017-04-18 22:46:01949 session_controller_->RemoveObserver(this);
Sonny Sasaka55f69fc2017-08-28 21:29:37950 // BluetoothPowerController depends on the PrefService and must be destructed
951 // before it.
952 bluetooth_power_controller_ = nullptr;
Qiang Xuf1400a362017-09-14 02:28:30953 // TouchDevicesController depends on the PrefService and must be destructed
954 // before it.
955 touch_devices_controller_ = nullptr;
Toni Barzic550419f2018-03-08 03:56:21956 // DetachableBaseNotificationController depends on DetachableBaseHandler, and
957 // has to be destructed before it.
958 detachable_base_notification_controller_.reset();
Toni Barzicd6238312018-03-02 18:26:13959 // DetachableBaseHandler depends on the PrefService and must be destructed
960 // before it.
961 detachable_base_handler_.reset();
Ahmed Fakhrye96051f2017-12-12 17:42:17962
Evan Stade196ec042018-03-13 19:44:36963 // Destroys the MessageCenter singleton, so must happen late.
964 message_center_controller_.reset();
965
Sam McNallya853cd82017-08-30 01:55:10966 local_state_.reset();
skyb073203a2017-03-13 16:59:16967 shell_delegate_.reset();
sky88bd4be62016-06-09 17:34:41968
Scott Violet17a61722017-06-19 17:54:31969 for (auto& observer : shell_observers_)
970 observer.OnShellDestroyed();
971
[email protected]b6ba05d902013-10-04 21:38:45972 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18973 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45974}
975
Scott Violetae4c25d2018-06-19 15:50:15976void Shell::Init(
977 ui::ContextFactory* context_factory,
978 ui::ContextFactoryPrivate* context_factory_private,
979 std::unique_ptr<base::Value> initial_display_prefs,
Scott Violet7e33efc2018-08-29 22:30:15980 std::unique_ptr<ws::GpuInterfaceProvider> gpu_interface_provider) {
Scott Violetac410622018-08-11 18:33:22981 if (::features::IsSingleProcessMash()) {
982 // In SingleProcessMash mode ScreenMus is not created, which means Ash needs
983 // to set the WindowManagerFrameValues.
984 views::WindowManagerFrameValues frame_values;
985 frame_values.normal_insets = frame_values.maximized_insets =
986 NonClientFrameController::GetPreferredClientAreaInsets();
987 frame_values.max_title_bar_button_width =
988 NonClientFrameController::GetMaxTitleBarButtonWidth();
989 views::WindowManagerFrameValues::SetInstance(frame_values);
990 }
991
Evan Stade196ec042018-03-13 19:44:36992 // This creates the MessageCenter object which is used by some other objects
993 // initialized here, so it needs to come early.
994 message_center_controller_ = std::make_unique<MessageCenterController>();
995
James Cookbd0b7792017-11-17 03:24:26996 // These controllers call Shell::Get() in their constructors, so they cannot
997 // be in the member initialization list.
Qiang Xuf1400a362017-09-14 02:28:30998 touch_devices_controller_ = std::make_unique<TouchDevicesController>();
Mitsuru Oshima04b54d02017-10-09 14:22:45999 bluetooth_power_controller_ = std::make_unique<BluetoothPowerController>();
Toni Barzicd6238312018-03-02 18:26:131000 detachable_base_handler_ = std::make_unique<DetachableBaseHandler>(this);
Toni Barzic550419f2018-03-08 03:56:211001 detachable_base_notification_controller_ =
1002 std::make_unique<DetachableBaseNotificationController>(
1003 detachable_base_handler_.get());
Tetsui Ohkubo01421b32018-05-30 16:54:591004 display_speaker_controller_ = std::make_unique<DisplaySpeakerController>();
Qiang Xud8e897e2018-05-24 20:07:571005 policy_recommendation_restorer_ =
1006 std::make_unique<PolicyRecommendationRestorer>();
Tetsui Ohkubo54d50222018-05-10 01:58:111007 screen_switch_check_controller_ =
1008 std::make_unique<ScreenSwitchCheckController>();
Kyle Horimoto9fc84fc22018-04-27 19:45:151009 // Connector can be null in tests.
Scott Violete5c79f52018-07-31 00:10:171010 if (connector_ && base::FeatureList::IsEnabled(
1011 chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
Kyle Horimoto9fc84fc22018-04-27 19:45:151012 multidevice_notification_presenter_ =
1013 std::make_unique<MultiDeviceNotificationPresenter>(
Scott Violete5c79f52018-07-31 00:10:171014 message_center::MessageCenter::Get(), connector_);
Kyle Horimoto9fc84fc22018-04-27 19:45:151015 }
Sonny Sasaka55f69fc2017-08-28 21:29:371016
James Cook8532dbc2017-07-31 21:54:511017 // Connector can be null in tests.
Scott Violete5c79f52018-07-31 00:10:171018 if (connector_) {
James Cook8532dbc2017-07-31 21:54:511019 // Connect to local state prefs now, but wait for an active user before
1020 // connecting to the profile pref service. The login screen has a temporary
1021 // user profile that is not associated with a real user.
Taiju Tsuiki36c517d2017-05-18 06:45:431022 auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
Steven Bennettsca108512018-05-02 11:05:031023 RegisterLocalStatePrefs(pref_registry.get(), false);
tibellb93c729b2017-03-30 00:45:091024 prefs::ConnectToPrefService(
Scott Violete5c79f52018-07-31 00:10:171025 connector_, std::move(pref_registry),
Sam McNallye36abbc2017-07-20 01:04:281026 base::Bind(&Shell::OnLocalStatePrefServiceInitialized,
1027 weak_factory_.GetWeakPtr()),
1028 prefs::mojom::kLocalStateServiceName);
jonrossc4ba10602017-04-07 20:51:051029 }
skyb073203a2017-03-13 16:59:161030
David Tseng562a9c12018-07-18 03:35:051031 tablet_mode_controller_ = std::make_unique<TabletModeController>();
1032
Qiang Xua9591002018-03-15 22:29:311033 accessibility_focus_ring_controller_ =
1034 std::make_unique<AccessibilityFocusRingController>();
skyb073203a2017-03-13 16:59:161035 accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate());
James Cookaa6aaad2018-08-24 01:00:061036 accessibility_controller_ = std::make_unique<AccessibilityController>();
Mitsuru Oshima04b54d02017-10-09 14:22:451037 toast_manager_ = std::make_unique<ToastManager>();
sky07a24d42017-03-09 23:57:301038
sky07a24d42017-03-09 23:57:301039 // Install the custom factory early on so that views::FocusManagers for Tray,
1040 // Shelf, and WallPaper could be created by the factory.
1041 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
1042
Mitsuru Oshima04b54d02017-10-09 14:22:451043 wallpaper_controller_ = std::make_unique<WallpaperController>();
sky07a24d42017-03-09 23:57:301044
Scott Violet97a7b9d2018-08-06 22:31:131045 immersive_handler_factory_ = std::make_unique<ImmersiveHandlerFactoryAsh>();
skyb7b54092016-08-19 16:00:091046
Mitsuru Oshima04b54d02017-10-09 14:22:451047 window_positioner_ = std::make_unique<WindowPositioner>();
sky984c1892016-04-20 00:00:341048
James Cook79e1ed62018-09-07 15:40:421049 native_cursor_manager_ = new NativeCursorManagerAsh;
James Cook698fc3662018-07-27 16:05:011050 cursor_manager_ =
1051 std::make_unique<CursorManager>(base::WrapUnique(native_cursor_manager_));
skyfee520c2016-02-11 19:57:461052
Steven Bennettsca108512018-05-02 11:05:031053 // In CLASSIC mode, |initial_display_prefs| contains the synchronously
1054 // loaded display pref values. Otherwise |initial_display_prefs| is null and
1055 // the pref values will be loaded once |local_state_| is available. (Any store
1056 // requests in the meanwhile will be queued).
1057 display_prefs_ =
1058 std::make_unique<DisplayPrefs>(std::move(initial_display_prefs));
1059
Steven Bennetts7683e342018-01-02 21:29:521060 InitializeDisplayManager();
[email protected]b6ba05d902013-10-04 21:38:451061
James Cook602164e2018-08-07 20:39:421062 // This will initialize aura::Env which requires |display_manager_| to
1063 // be initialized first.
1064 if (context_factory)
Scott Violetac410622018-08-11 18:33:221065 aura_env_->set_context_factory(context_factory);
1066 if (context_factory_private)
1067 aura_env_->set_context_factory_private(context_factory_private);
[email protected]ecca62b2013-10-09 16:18:531068
Ahmed Fakhry46357342018-04-27 00:46:111069 // Night Light depends on the display manager, the display color manager, and
1070 // aura::Env, so initialize it after all have been initialized.
Ahmed Fakhryb9ace242018-06-06 18:49:311071 if (features::IsNightLightEnabled())
Ahmed Fakhry46357342018-04-27 00:46:111072 night_light_controller_ = std::make_unique<NightLightController>();
1073
[email protected]b6ba05d902013-10-04 21:38:451074 // The WindowModalityController needs to be at the front of the input event
1075 // pretarget handler list to ensure that it processes input events when modal
1076 // windows are active.
Scott Violetac410622018-08-11 18:33:221077 window_modality_controller_ =
1078 std::make_unique<::wm::WindowModalityController>(this, aura_env_);
[email protected]b6ba05d902013-10-04 21:38:451079
Mike Wassermanefbf3402018-04-26 00:41:321080 event_rewriter_controller_ = std::make_unique<EventRewriterController>();
1081
Scott Violetac410622018-08-11 18:33:221082 env_filter_ = std::make_unique<::wm::CompoundEventFilter>();
[email protected]b6ba05d902013-10-04 21:38:451083 AddPreTargetHandler(env_filter_.get());
1084
sky27344382017-03-08 21:30:321085 // FocusController takes ownership of AshFocusRules.
1086 focus_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451087 std::make_unique<::wm::FocusController>(new wm::AshFocusRules());
sky27344382017-03-08 21:30:321088 focus_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:451089
[email protected]093b8d642014-04-03 20:59:281090 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:451091
Scott Violet596bb46342017-06-21 14:43:131092 window_tree_host_manager_->Start();
1093 AshWindowTreeHostInitParams ash_init_params;
1094 window_tree_host_manager_->CreatePrimaryHost(ash_init_params);
1095
Scott Violet3c554ae2017-12-13 02:25:411096 time_to_first_present_recorder_ =
1097 std::make_unique<TimeToFirstPresentRecorder>(GetPrimaryRootWindow());
1098
James Cook40f7d752018-05-25 18:21:581099 shell_state_->SetRootWindowForNewWindows(GetPrimaryRootWindow());
[email protected]b6ba05d902013-10-04 21:38:451100
Scott Violet596bb46342017-06-21 14:43:131101 resolution_notification_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451102 std::make_unique<ResolutionNotificationController>();
[email protected]b6ba05d902013-10-04 21:38:451103
James Cook698fc3662018-07-27 16:05:011104 cursor_manager_->SetDisplay(
1105 display::Screen::GetScreen()->GetPrimaryDisplay());
[email protected]b6ba05d902013-10-04 21:38:451106
James Cook9db56d72018-08-01 03:21:311107 accelerator_controller_ = std::make_unique<AcceleratorController>(nullptr);
Xiaohui Chend68ffc12018-08-16 01:56:411108 voice_interaction_controller_ =
1109 std::make_unique<VoiceInteractionController>();
Weidong Guo268c7992018-04-13 21:06:071110
Scott Violete5c3f5b2018-08-22 21:56:451111 window_service_owner_ =
1112 std::make_unique<WindowServiceOwner>(std::move(gpu_interface_provider));
1113
Weidong Guo268c7992018-04-13 21:06:071114 // |app_list_controller_| is put after |tablet_mode_controller_| as the former
1115 // uses the latter in constructor.
Scott Violete5c3f5b2018-08-22 21:56:451116 app_list_controller_ = std::make_unique<AppListControllerImpl>(
1117 window_service_owner_->window_service());
Mitsuru Oshima04b54d02017-10-09 14:22:451118 shelf_controller_ = std::make_unique<ShelfController>();
[email protected]b6ba05d902013-10-04 21:38:451119
spange9b51272014-12-11 01:20:101120 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:061121 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
spange9b51272014-12-11 01:20:101122 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:061123 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:391124
[email protected]b6ba05d902013-10-04 21:38:451125 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:451126
derat2d4e62d2015-01-09 16:09:171127 // ui::UserActivityDetector passes events to observers, so let them get
Michael Wasserman07466432018-04-11 03:56:481128 // rewritten first.
1129 user_activity_detector_.reset(new ui::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:451130
[email protected]093b8d642014-04-03 20:59:281131 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:451132 AddPreTargetHandler(overlay_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:451133
[email protected]60d677d2014-05-30 13:07:021134 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
dchenga94547472016-04-08 08:41:111135 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
sky81a2d792017-03-17 19:14:391136 accelerator_controller_->accelerator_history()));
[email protected]b6ba05d902013-10-04 21:38:451137 AddPreTargetHandler(accelerator_filter_.get());
1138
[email protected]093b8d642014-04-03 20:59:281139 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:451140 AddPreTargetHandler(event_transformation_handler_.get());
1141
sky11cf8db92017-04-10 23:38:081142 toplevel_window_event_handler_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451143 std::make_unique<ToplevelWindowEventHandler>();
[email protected]3537d472014-01-15 05:45:311144
Ryan Cuieb5b84e32018-07-19 01:36:021145 system_gesture_filter_ = std::make_unique<SystemGestureEventFilter>();
1146 AddPreTargetHandler(system_gesture_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:451147
[email protected]354520b2014-06-21 04:31:011148 sticky_keys_controller_.reset(new StickyKeysController);
Mitsuru Oshima04b54d02017-10-09 14:22:451149 screen_pinning_controller_ = std::make_unique<ScreenPinningController>();
[email protected]354520b2014-06-21 04:31:011150
Qiang Xu36234e532018-04-11 04:54:021151 power_prefs_ = std::make_unique<PowerPrefs>(
1152 chromeos::PowerPolicyController::Get(),
1153 chromeos::DBusThreadManager::Get()->GetPowerManagerClient());
1154
Toni Barzic9d0c82f42017-12-06 00:53:521155 backlights_forced_off_setter_ = std::make_unique<BacklightsForcedOffSetter>();
1156
Toni Barzic85ae39e2017-12-07 05:50:181157 tray_action_ =
1158 std::make_unique<TrayAction>(backlights_forced_off_setter_.get());
1159
jamescookd9f152f2016-11-15 00:53:081160 lock_state_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451161 std::make_unique<LockStateController>(shutdown_controller_.get());
Toni Barzic9d0c82f42017-12-06 00:53:521162 power_button_controller_ = std::make_unique<PowerButtonController>(
1163 backlights_forced_off_setter_.get());
[email protected]685442f32014-02-28 10:40:061164 // Pass the initial display state to PowerButtonController.
1165 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:091166 display_configurator_->cached_displays());
jamescook01bf23e72017-01-09 19:58:151167
Scott Violet49d2db62018-08-16 19:28:081168 if (::features::IsUsingWindowService())
Evan Stadef3c89c602018-06-14 04:44:121169 client_image_registry_ = std::make_unique<ClientImageRegistry>();
1170
James Cook93614f02018-07-11 21:37:351171 drag_drop_controller_ = std::make_unique<DragDropController>();
Scott Violet361833fb2017-06-21 22:25:201172
oshima5a296e82016-04-29 01:32:271173 // |screenshot_controller_| needs to be created (and prepended as a
mukai19274bdd2015-02-24 22:37:481174 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
oshima5a296e82016-04-29 01:32:271175 // process mouse events prior to screenshot session.
mukai19274bdd2015-02-24 22:37:481176 // See http://crbug.com/459214
James Cook5e9d3402017-11-01 00:20:121177 screenshot_controller_ = std::make_unique<ScreenshotController>(
1178 shell_delegate_->CreateScreenshotDelegate());
Mitsuru Oshima04b54d02017-10-09 14:22:451179 mouse_cursor_filter_ = std::make_unique<MouseCursorEventFilter>();
Katie Db68a5522018-03-30 18:47:361180 AddPreTargetHandler(mouse_cursor_filter_.get(),
1181 ui::EventTarget::Priority::kAccessibility);
[email protected]b6ba05d902013-10-04 21:38:451182
1183 // Create Controllers that may need root window.
1184 // TODO(oshima): Move as many controllers before creating
1185 // RootWindowController as possible.
1186 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:451187
sammiequon203ae022016-09-18 17:23:421188 laser_pointer_controller_.reset(new LaserPointerController());
1189 partial_magnification_controller_.reset(new PartialMagnificationController());
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:321190 highlighter_controller_.reset(new HighlighterController());
sammiequon203ae022016-09-18 17:23:421191
David Black00fdce32018-05-10 20:59:141192 assistant_controller_ = chromeos::switches::IsAssistantEnabled()
1193 ? std::make_unique<AssistantController>()
1194 : nullptr;
Qiang Xubd6d84e72018-05-09 01:31:511195
Qiang Xu2657abf2018-03-21 18:01:451196 magnification_controller_ = std::make_unique<MagnificationController>();
Mitsuru Oshima04b54d02017-10-09 14:22:451197 mru_window_tracker_ = std::make_unique<MruWindowTracker>();
[email protected]b6ba05d902013-10-04 21:38:451198
[email protected]55398d22013-10-10 19:49:201199 autoclick_controller_.reset(AutoclickController::CreateInstance());
1200
[email protected]b6ba05d902013-10-04 21:38:451201 high_contrast_controller_.reset(new HighContrastController);
Saman Sami3fb310d2017-11-09 16:51:541202
Ahmed Fakhry4af48e42018-02-28 17:45:381203 if (features::IsDockedMagnifierEnabled()) {
Ahmed Fakhry4bf3f742018-02-06 17:33:361204 docked_magnifier_controller_ =
1205 std::make_unique<DockedMagnifierController>();
1206 }
1207
Saman Sami3fb310d2017-11-09 16:51:541208 viz::mojom::VideoDetectorObserverPtr observer;
1209 video_detector_ =
1210 std::make_unique<VideoDetector>(mojo::MakeRequest(&observer));
Scott Violetac410622018-08-11 18:33:221211 aura_env_->context_factory_private()
James Cook602164e2018-08-07 20:39:421212 ->GetHostFrameSinkManager()
1213 ->AddVideoDetectorObserver(std::move(observer));
[email protected]b6ba05d902013-10-04 21:38:451214
oshimaebbe63772015-02-19 18:41:321215 tooltip_controller_.reset(new views::corewm::TooltipController(
dchenga94547472016-04-08 08:41:111216 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451217 AddPreTargetHandler(tooltip_controller_.get());
1218
hariank0dd03dd2016-07-14 23:47:331219 modality_filter_.reset(new SystemModalContainerEventFilter(this));
1220 AddPreTargetHandler(modality_filter_.get());
1221
[email protected]093b8d642014-04-03 20:59:281222 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451223
skyabcae812017-01-18 17:01:341224 // Must occur after Shell has installed its early pre-target handlers (for
1225 // example, WindowModalityController).
James Cook31bb3252018-08-08 20:06:441226 pointer_watcher_adapter_ = std::make_unique<PointerWatcherAdapter>();
[email protected]b6ba05d902013-10-04 21:38:451227
[email protected]093b8d642014-04-03 20:59:281228 resize_shadow_controller_.reset(new ResizeShadowController());
Scott Violetac410622018-08-11 18:33:221229 shadow_controller_ = std::make_unique<::wm::ShadowController>(
1230 focus_controller_.get(), std::make_unique<WmShadowControllerDelegate>(),
1231 aura_env_);
[email protected]b6ba05d902013-10-04 21:38:451232
James Cookb50959e22017-08-10 20:24:381233 logout_confirmation_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451234 std::make_unique<LogoutConfirmationController>();
[email protected]b6ba05d902013-10-04 21:38:451235
jamescookac6724332017-03-21 02:54:431236 // May trigger initialization of the Bluetooth adapter.
1237 tray_bluetooth_helper_->Initialize();
1238
kylechar55f0eaf22017-01-11 22:57:371239 // Create AshTouchTransformController before
oshimae2818922015-07-28 01:18:521240 // WindowTreeHostManager::InitDisplays()
kylechar55f0eaf22017-01-11 22:57:371241 // since AshTouchTransformController listens on
oshimae2818922015-07-28 01:18:521242 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
Mitsuru Oshima04b54d02017-10-09 14:22:451243 touch_transformer_controller_ = std::make_unique<AshTouchTransformController>(
Scott Violet596bb46342017-06-21 14:43:131244 display_configurator_.get(), display_manager_.get(),
James Cook9db56d72018-08-01 03:21:311245 std::make_unique<display::DefaultTouchTransformSetter>());
[email protected]03122891a2014-05-13 23:56:491246
Tetsui Ohkubo269b5792018-04-26 01:06:321247 // |system_tray_model_| should be available before
1248 // |system_notification_controller_| is initialized and Shelf is created by
1249 // WindowTreeHostManager::InitHosts.
1250 system_tray_model_ = std::make_unique<SystemTrayModel>();
1251 system_notification_controller_ =
1252 std::make_unique<SystemNotificationController>();
1253
Scott Violet596bb46342017-06-21 14:43:131254 window_tree_host_manager_->InitHosts();
[email protected]b6ba05d902013-10-04 21:38:451255
rsadam9172bc8a2014-10-29 23:37:381256 // Needs to be created after InitDisplays() since it may cause the virtual
1257 // keyboard to be deployed.
James Cook602164e2018-08-07 20:39:421258 virtual_keyboard_controller_ = std::make_unique<VirtualKeyboardController>();
rsadam9172bc8a2014-10-29 23:37:381259
James Cook698fc3662018-07-27 16:05:011260 cursor_manager_->HideCursor(); // Hide the mouse cursor on startup.
1261 cursor_manager_->SetCursor(ui::CursorType::kPointer);
[email protected]b6ba05d902013-10-04 21:38:451262
Mitsuru Oshima04b54d02017-10-09 14:22:451263 peripheral_battery_notifier_ = std::make_unique<PeripheralBatteryNotifier>();
[email protected]093b8d642014-04-03 20:59:281264 power_event_observer_.reset(new PowerEventObserver());
[email protected]ded58fd2013-10-09 07:56:551265 user_activity_notifier_.reset(
[email protected]b0fa7012014-04-16 12:50:571266 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
[email protected]ded58fd2013-10-09 07:56:551267 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281268 new VideoActivityNotifier(video_detector_.get()));
1269 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
Scott Violet596bb46342017-06-21 14:43:131270 screen_orientation_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451271 std::make_unique<ScreenOrientationController>();
Scott Violet596bb46342017-06-21 14:43:131272 screen_layout_observer_.reset(new ScreenLayoutObserver());
yiyix90cfee22017-02-16 05:38:181273 sms_observer_.reset(new SmsObserver());
jamescook01bf23e72017-01-09 19:58:151274
xdaid4913762017-07-06 00:17:221275 split_view_controller_.reset(new SplitViewController());
1276
David Tseng6792dc82018-05-04 19:18:411277 key_accessibility_enabler_ = std::make_unique<KeyAccessibilityEnabler>();
1278
[email protected]b6ba05d902013-10-04 21:38:451279 // The compositor thread and main message loop have to be running in
1280 // order to create mirror window. Run it after the main message loop
1281 // is started.
Scott Violet596bb46342017-06-21 14:43:131282 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031283
Scott Violete5c79f52018-07-31 00:10:171284 // |connector_| is null in unit tests.
Scott Violete5c79f52018-07-31 00:10:171285 if (connector_ &&
James Cook08ebee42018-08-07 04:06:421286 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowTaps)) {
1287 // The show taps feature is a separate mojo app.
1288 // TODO(jamescook): Make this work in ash_shell_with_content.
Scott Violete5c79f52018-07-31 00:10:171289 connector_->StartService(tap_visualizer::mojom::kServiceName);
James Cook0ba192bf2017-12-01 20:53:111290 }
1291
James Cook7e6a7ae2018-08-24 23:00:471292 if (!::features::IsMultiProcessMash()) {
James Cookc9d6a542018-07-27 21:00:561293 ime_focus_handler_ = std::make_unique<ImeFocusHandler>(
1294 focus_controller(), window_tree_host_manager_->input_method());
Scott Violetb7f4df22018-05-17 04:43:121295 }
1296
sky00c813f2017-03-08 22:48:551297 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:181298 observer.OnShellInitialized();
phweiss0bf64c52015-11-17 12:56:181299
Scott Violet41562d1c2017-06-26 15:15:481300 user_metrics_recorder_->OnShellInitialized();
Toni Barzic85c9e0802018-03-30 02:46:011301
Jeffrey Kardatzkef108f022018-04-17 17:52:351302 // Initialize the D-Bus thread and services for ash.
1303 ash_dbus_services_ = std::make_unique<AshDBusServices>();
Toni Barzic85c9e0802018-03-30 02:46:011304 // By this point ash shell should have initialized its D-Bus signal
1305 // listeners, so emit ash-initialized upstart signal to start Chrome OS tasks
1306 // that expect that ash is listening to D-Bus signals they emit. For example,
1307 // hammerd, which handles detachable base state, communicates the base state
1308 // purely by emitting D-Bus signals, and thus has to be run whenever ash is
1309 // started so ash (DetachableBaseHandler in particular) gets the proper view
1310 // of the current detachable base state.
Jeffrey Kardatzkef108f022018-04-17 17:52:351311 // TODO(stevenjb): Move this and other D-Bus dependencies to AshDBusServices.
1312 ash_dbus_services_->EmitAshInitialized();
[email protected]b6ba05d902013-10-04 21:38:451313}
1314
Steven Bennetts7683e342018-01-02 21:29:521315void Shell::InitializeDisplayManager() {
Steven Bennetts7683e342018-01-02 21:29:521316 bool display_initialized = display_manager_->InitFromCommandLine();
1317
Steven Bennetts7683e342018-01-02 21:29:521318 display_configuration_controller_ =
1319 std::make_unique<DisplayConfigurationController>(
1320 display_manager_.get(), window_tree_host_manager_.get());
James Cook9db56d72018-08-01 03:21:311321 display_configurator_->Init(
1322 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(), false);
Steven Bennetts9b21fa32018-04-13 23:45:551323 display_configuration_observer_ =
1324 std::make_unique<DisplayConfigurationObserver>();
1325
Steven Bennetts2a9b4382018-04-26 23:41:191326 cros_display_config_ = std::make_unique<CrosDisplayConfig>();
1327
Qiang Xud77a90c2018-02-20 19:43:291328 persistent_window_controller_ =
1329 std::make_unique<PersistentWindowController>();
Steven Bennetts7683e342018-01-02 21:29:521330
1331 projecting_observer_ =
1332 std::make_unique<ProjectingObserver>(display_configurator_.get());
1333
1334 if (!display_initialized) {
Scott Violet97a7b9d2018-08-06 22:31:131335 if (chromeos::IsRunningAsSystemCompositor()) {
Steven Bennetts7683e342018-01-02 21:29:521336 display_change_observer_ =
1337 std::make_unique<display::DisplayChangeObserver>(
1338 display_configurator_.get(), display_manager_.get());
1339
1340 display_shutdown_observer_ = std::make_unique<DisplayShutdownObserver>(
1341 display_configurator_.get());
1342
1343 // Register |display_change_observer_| first so that the rest of
1344 // observer gets invoked after the root windows are configured.
1345 display_configurator_->AddObserver(display_change_observer_.get());
1346 display_error_observer_.reset(new DisplayErrorObserver());
1347 display_configurator_->AddObserver(display_error_observer_.get());
1348 display_configurator_->set_state_controller(
1349 display_change_observer_.get());
1350 display_configurator_->set_mirroring_controller(display_manager_.get());
1351 display_configurator_->ForceInitialConfigure();
1352 display_initialized = true;
1353 }
1354 }
1355
Ahmed Fakhry1ad4bd42018-04-18 19:31:371356 display_color_manager_ = std::make_unique<DisplayColorManager>(
1357 display_configurator_.get(), display::Screen::GetScreen());
Steven Bennetts7683e342018-01-02 21:29:521358
1359 if (!display_initialized)
1360 display_manager_->InitDefaultDisplay();
1361
Scott Violet97a7b9d2018-08-06 22:31:131362 display_manager_->RefreshFontParams();
Steven Bennetts7683e342018-01-02 21:29:521363}
1364
[email protected]41baaed2013-11-09 04:18:261365void Shell::InitRootWindow(aura::Window* root_window) {
sky27344382017-03-08 21:30:321366 DCHECK(focus_controller_);
[email protected]d90b8392012-06-13 09:34:561367 DCHECK(visibility_controller_.get());
[email protected]d90b8392012-06-13 09:34:561368
sky27344382017-03-08 21:30:321369 aura::client::SetFocusClient(root_window, focus_controller_.get());
Thiago Farina3b086a02017-05-30 22:32:501370 ::wm::SetActivationClient(root_window, focus_controller_.get());
sky27344382017-03-08 21:30:321371 root_window->AddPreTargetHandler(focus_controller_.get());
[email protected]d90b8392012-06-13 09:34:561372 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
James Cook93614f02018-07-11 21:37:351373 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]8d625fb2012-07-18 16:40:061374 aura::client::SetScreenPositionClient(root_window,
1375 screen_position_controller_.get());
sadrul7a8785e2016-02-12 21:54:351376 aura::client::SetCursorClient(root_window, cursor_manager_.get());
Thiago Farina3b086a02017-05-30 22:32:501377 ::wm::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381378 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561379
Thiago Farina3b086a02017-05-30 22:32:501380 ::wm::SetWindowMoveClient(root_window, toplevel_window_event_handler_.get());
[email protected]3537d472014-01-15 05:45:311381 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1382 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
[email protected]d90b8392012-06-13 09:34:561383}
1384
skyabcae812017-01-18 17:01:341385void Shell::CloseAllRootWindowChildWindows() {
msw257a6a232017-06-01 01:46:301386 for (aura::Window* root : GetAllRootWindows()) {
1387 RootWindowController* controller = RootWindowController::ForWindow(root);
skyabcae812017-01-18 17:01:341388 if (controller) {
1389 controller->CloseChildWindows();
1390 } else {
msw257a6a232017-06-01 01:46:301391 while (!root->children().empty()) {
1392 aura::Window* child = root->children()[0];
skyabcae812017-01-18 17:01:341393 delete child;
1394 }
1395 }
1396 }
1397}
1398
[email protected]c0ce80e2012-10-05 23:28:271399bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1400 RootWindowControllerList controllers = GetAllRootWindowControllers();
oshima9a61ecf2016-06-18 10:43:051401 for (RootWindowController* controller : controllers) {
1402 if (controller->CanWindowReceiveEvents(window))
[email protected]602022b2014-03-31 17:07:311403 return true;
[email protected]c0ce80e2012-10-05 23:28:271404 }
1405 return false;
1406}
1407
[email protected]049cf34b2012-12-07 17:15:481408////////////////////////////////////////////////////////////////////////////////
1409// Shell, ui::EventTarget overrides:
1410
[email protected]869f6352012-12-06 20:47:171411bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411412 return true;
1413}
1414
1415ui::EventTarget* Shell::GetParentTarget() {
Scott Violetac410622018-08-11 18:33:221416 return aura_env_;
[email protected]5097e692012-10-30 22:08:411417}
1418
dchenga94547472016-04-08 08:41:111419std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1420 return std::unique_ptr<ui::EventTargetIterator>();
[email protected]3e670aa2013-12-02 19:04:321421}
1422
1423ui::EventTargeter* Shell::GetEventTargeter() {
1424 NOTREACHED();
achuith287b26e2015-09-03 17:49:181425 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321426}
1427
sky27344382017-03-08 21:30:321428void Shell::OnWindowActivated(
Thiago Farina3b086a02017-05-30 22:32:501429 ::wm::ActivationChangeObserver::ActivationReason reason,
sky27344382017-03-08 21:30:321430 aura::Window* gained_active,
1431 aura::Window* lost_active) {
James Cook40f7d752018-05-25 18:21:581432 if (!gained_active)
1433 return;
1434
1435 shell_state_->SetRootWindowForNewWindows(gained_active->GetRootWindow());
sky27344382017-03-08 21:30:321436}
1437
Steven Bennettsbadc3092018-05-24 21:26:011438void Shell::OnFirstSessionStarted() {
1439 // Enable magnifier scroll keys as there may be no mouse cursor in kiosk mode.
1440 MagnifierKeyScroller::SetEnabled(session_controller_->IsRunningInAppMode());
1441
1442 // Enable long press action to toggle spoken feedback with hotrod remote
1443 // which can't handle shortcuts.
1444 SpokenFeedbackToggler::SetEnabled(session_controller_->IsRunningInAppMode());
1445}
1446
Xiyuan Xiab64fd0a2017-04-13 17:53:141447void Shell::OnSessionStateChanged(session_manager::SessionState state) {
Aga Wronskae195ad22017-12-20 01:38:111448 // Initialize the |shelf_window_watcher_| when a session becomes active.
1449 // Shelf itself is initialized in RootWindowController.
sky5ad143a2017-03-22 04:31:231450 if (state == session_manager::SessionState::ACTIVE) {
Steven Bennettsbadc3092018-05-24 21:26:011451 if (!shelf_window_watcher_) {
Aga Wronskae195ad22017-12-20 01:38:111452 shelf_window_watcher_ =
1453 std::make_unique<ShelfWindowWatcher>(shelf_model());
Steven Bennettsbadc3092018-05-24 21:26:011454 }
okac21941d2017-06-20 17:54:441455 }
Steven Bennetts43b3c212018-01-08 16:39:581456
Steven Bennetts9fd12ad2017-11-09 23:36:271457 // NOTE: keyboard::IsKeyboardEnabled() is false in mash, but may not be in
1458 // unit tests. crbug.com/646565.
Steven Bennetts43b3c212018-01-08 16:39:581459 if (keyboard::IsKeyboardEnabled()) {
1460 switch (state) {
1461 case session_manager::SessionState::OOBE:
1462 case session_manager::SessionState::LOGIN_PRIMARY:
1463 // Ensure that the keyboard controller is activated for the primary
1464 // window.
1465 GetPrimaryRootWindowController()->ActivateKeyboard(
Darren Shenf62db77a2018-06-07 06:22:441466 keyboard_controller_.get());
Steven Bennetts43b3c212018-01-08 16:39:581467 break;
1468 case session_manager::SessionState::LOGGED_IN_NOT_ACTIVE:
1469 case session_manager::SessionState::ACTIVE:
Darren Shen0219ebe2018-04-29 22:52:541470 // Reload the keyboard on user profile change to refresh keyboard
Steven Bennetts43b3c212018-01-08 16:39:581471 // extensions with the new profile and ensure the extensions call the
1472 // proper IME. |LOGGED_IN_NOT_ACTIVE| is needed so that the virtual
1473 // keyboard works on supervised user creation, http://crbug.com/712873.
1474 // |ACTIVE| is also needed for guest user workflow.
Darren Shenf62db77a2018-06-07 06:22:441475 EnableKeyboard();
Steven Bennetts43b3c212018-01-08 16:39:581476 break;
1477 default:
1478 break;
1479 }
sky5ad143a2017-03-22 04:31:231480 }
xiyuan233f4e72017-04-06 06:59:561481}
sky5ad143a2017-03-22 04:31:231482
Xiyuan Xiab64fd0a2017-04-13 17:53:141483void Shell::OnLoginStatusChanged(LoginStatus login_status) {
xiyuan233f4e72017-04-06 06:59:561484 UpdateAfterLoginStatusChange(login_status);
sky5ad143a2017-03-22 04:31:231485}
1486
Xiyuan Xiab64fd0a2017-04-13 17:53:141487void Shell::OnLockStateChanged(bool locked) {
xiyuan7ebbf7f2017-04-10 16:49:101488#ifndef NDEBUG
1489 // Make sure that there is no system modal in Lock layer when unlocked.
1490 if (!locked) {
1491 aura::Window::Windows containers = wm::GetContainersFromAllRootWindows(
1492 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
1493 for (aura::Window* container : containers)
1494 DCHECK(container->children().empty());
1495 }
1496#endif
1497}
1498
Sam McNallye36abbc2017-07-20 01:04:281499void Shell::OnLocalStatePrefServiceInitialized(
1500 std::unique_ptr<::PrefService> pref_service) {
Sam McNallya853cd82017-08-30 01:55:101501 DCHECK(!local_state_);
James Cook8532dbc2017-07-31 21:54:511502 // |pref_service| is null if can't connect to Chrome (as happens when
Scott Violet8ff9c302018-02-22 22:28:351503 // running mash outside of chrome --enable-features=Mash and chrome isn't
1504 // built).
Sam McNallya853cd82017-08-30 01:55:101505 if (!pref_service)
1506 return;
1507
1508 local_state_ = std::move(pref_service);
James Cookbbe5cb12017-08-08 18:32:211509
1510 for (auto& observer : shell_observers_)
Sam McNallya853cd82017-08-30 01:55:101511 observer.OnLocalStatePrefServiceInitialized(local_state_.get());
Sam McNallye36abbc2017-07-20 01:04:281512}
1513
[email protected]55f593352011-12-24 05:42:461514} // namespace ash