blob: 7b57fe4e1714a329c9248bb649ac0309959c0d84 [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"
James Cookb0bf8e82017-04-09 17:01:4413#include "ash/accelerators/ash_focus_manager_factory.h"
jamescook01bf23e72017-01-09 19:58:1514#include "ash/accelerators/magnifier_key_scroller.h"
Scott Violetf5db2502018-10-05 15:19:3915#include "ash/accelerators/pre_target_accelerator_handler.h"
jamescook01bf23e72017-01-09 19:58:1516#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"
James Cooka9384092018-05-23 02:54:2625#include "ash/components/tap_visualizer/public/mojom/constants.mojom.h"
Jeffrey Kardatzkef108f022018-04-17 17:52:3526#include "ash/dbus/ash_dbus_services.h"
Toni Barzicd6238312018-03-02 18:26:1327#include "ash/detachable_base/detachable_base_handler.h"
Toni Barzic550419f2018-03-08 03:56:2128#include "ash/detachable_base/detachable_base_notification_controller.h"
Scott Violetd64dac12017-06-02 21:50:0829#include "ash/display/ash_display_controller.h"
Steven Bennetts2a9b4382018-04-26 23:41:1930#include "ash/display/cros_display_config.h"
[email protected]87ec2202014-02-06 06:24:2731#include "ash/display/cursor_window_controller.h"
Mitsuru Oshimaf51c8b42018-03-17 01:41:3232#include "ash/display/display_color_manager.h"
stevenjb537c5c3f2016-01-20 23:38:1233#include "ash/display/display_configuration_controller.h"
Steven Bennetts9b21fa32018-04-13 23:45:5534#include "ash/display/display_configuration_observer.h"
Mitsuru Oshimaf51c8b42018-03-17 01:41:3235#include "ash/display/display_error_observer.h"
Scott Violetbed23cb2018-08-22 19:56:1236#include "ash/display/display_output_protection.h"
Steven Bennetts3688c6032018-04-13 01:14:2337#include "ash/display/display_prefs.h"
Steven Bennetts7683e342018-01-02 21:29:5238#include "ash/display/display_shutdown_observer.h"
[email protected]682990f2013-01-10 06:49:1139#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2740#include "ash/display/mouse_cursor_event_filter.h"
Qiang Xud77a90c2018-02-20 19:43:2941#include "ash/display/persistent_window_controller.h"
Mitsuru Oshimaf51c8b42018-03-17 01:41:3242#include "ash/display/projecting_observer.h"
jamescook01bf23e72017-01-09 19:58:1543#include "ash/display/resolution_notification_controller.h"
rjkroege2c9305402016-09-07 00:21:4544#include "ash/display/screen_ash.h"
Mitsuru Oshimaddfde3552018-03-22 09:12:1345#include "ash/display/screen_orientation_controller.h"
[email protected]8d625fb2012-07-18 16:40:0646#include "ash/display/screen_position_controller.h"
oshimae2818922015-07-28 01:18:5247#include "ash/display/window_tree_host_manager.h"
[email protected]f4c92b382012-08-28 00:59:5948#include "ash/drag_drop/drag_drop_controller.h"
Mike Wasserman5623bac22018-04-30 17:24:3249#include "ash/events/event_rewriter_controller.h"
James Cookf5398842018-04-16 20:15:2450#include "ash/first_run/first_run_helper.h"
James Cookb0bf8e82017-04-09 17:01:4451#include "ash/focus_cycler.h"
Evan Stade5f09e6572018-08-10 17:48:1552#include "ash/frame/non_client_frame_view_ash.h"
[email protected]f4c92b382012-08-28 00:59:5953#include "ash/high_contrast/high_contrast_controller.h"
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:3254#include "ash/highlighter/highlighter_controller.h"
Scott Violet596bb46342017-06-21 14:43:1355#include "ash/host/ash_window_tree_host_init_params.h"
James Cookbb026732017-06-09 23:01:5556#include "ash/ime/ime_controller.h"
Xiyuan Xia5f1046e2018-06-01 16:04:4457#include "ash/ime/ime_focus_handler.h"
James Cook8d912522018-06-19 02:18:4758#include "ash/keyboard/virtual_keyboard_controller.h"
sammiequon203ae022016-09-18 17:23:4259#include "ash/laser/laser_pointer_controller.h"
Jacob Dufaultffd9b0d2017-11-15 23:07:1660#include "ash/login/login_screen_controller.h"
James Cookb0bf8e82017-04-09 17:01:4461#include "ash/login_status.h"
Ahmed Fakhry4bf3f742018-02-06 17:33:3662#include "ash/magnifier/docked_magnifier_controller.h"
[email protected]f4c92b382012-08-28 00:59:5963#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5464#include "ash/magnifier/partial_magnification_controller.h"
James Cookb0bf8e82017-04-09 17:01:4465#include "ash/media_controller.h"
Evan Stadee9974e22017-09-23 00:02:2666#include "ash/message_center/message_center_controller.h"
Scott Violet3c554ae2017-12-13 02:25:4167#include "ash/metrics/time_to_first_present_recorder.h"
Kyle Horimoto9fc84fc22018-04-27 19:45:1568#include "ash/multi_device_setup/multi_device_notification_presenter.h"
James Cookb0bf8e82017-04-09 17:01:4469#include "ash/new_window_controller.h"
Vladislav Kaznacheev92edf62e2017-10-13 22:08:0170#include "ash/note_taking_controller.h"
James Cook31bb3252018-08-08 20:06:4471#include "ash/pointer_watcher_adapter.h"
Qiang Xud8e897e2018-05-24 20:07:5772#include "ash/policy/policy_recommendation_restorer.h"
Steven Bennetts93d3e5b12018-05-05 01:14:5073#include "ash/public/cpp/ash_constants.h"
Ahmed Fakhry4af48e42018-02-28 17:45:3874#include "ash/public/cpp/ash_features.h"
Evan Stade7d0e8232017-10-04 02:01:3675#include "ash/public/cpp/ash_switches.h"
msw109806d2017-06-02 20:11:5776#include "ash/public/cpp/shelf_model.h"
jamescook8800b8232016-10-19 12:46:2777#include "ash/public/cpp/shell_window_ids.h"
[email protected]d90b8392012-06-13 09:34:5678#include "ash/root_window_controller.h"
James Cook5e9d3402017-11-01 00:20:1279#include "ash/screenshot_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4480#include "ash/session/session_controller.h"
James Cook840177e2017-05-25 02:20:0181#include "ash/shelf/shelf.h"
James Cookb0bf8e82017-04-09 17:01:4482#include "ash/shelf/shelf_controller.h"
James Cookb0bf8e82017-04-09 17:01:4483#include "ash/shelf/shelf_window_watcher.h"
James Cookb0bf8e82017-04-09 17:01:4484#include "ash/shell_delegate.h"
[email protected]1b4c7472014-05-15 18:32:2385#include "ash/shell_init_params.h"
James Cookb0bf8e82017-04-09 17:01:4486#include "ash/shell_observer.h"
James Cook40f7d752018-05-25 18:21:5887#include "ash/shell_state.h"
James Cookb0bf8e82017-04-09 17:01:4488#include "ash/shutdown_controller.h"
jamescook01bf23e72017-01-09 19:58:1589#include "ash/sticky_keys/sticky_keys_controller.h"
Tetsui Ohkubo01421b32018-05-30 16:54:5990#include "ash/system/audio/display_speaker_controller.h"
James Cooka35a1e22017-04-08 02:33:0891#include "ash/system/bluetooth/bluetooth_notification_controller.h"
Sonny Sasaka55f69fc2017-08-28 21:29:3792#include "ash/system/bluetooth/bluetooth_power_controller.h"
Giovanni Ortuño Urquidi55aa5d8f2018-10-10 05:33:3493#include "ash/system/bluetooth/tray_bluetooth_helper_experimental.h"
94#include "ash/system/bluetooth/tray_bluetooth_helper_legacy.h"
James Cooka35a1e22017-04-08 02:33:0895#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"
tibellb93c729b2017-03-30 00:45:09174#include "services/preferences/public/cpp/pref_service_factory.h"
Ken Rockotf7f533e2018-02-11 02:21:33175#include "services/preferences/public/mojom/preferences.mojom.h"
derat94887a22017-01-20 18:17:25176#include "services/service_manager/public/cpp/connector.h"
Xiyuan Xiaebf96b72018-09-07 21:04:34177#include "services/ws/public/cpp/host/gpu_interface_provider.h"
Scott Violet9f984252018-08-27 19:02:13178#include "services/ws/window_service.h"
[email protected]2c456102011-12-26 06:26:34179#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:44180#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:58181#include "ui/aura/layout_manager.h"
[email protected]87b0d82e2011-10-07 21:02:59182#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:26183#include "ui/aura/window_event_dispatcher.h"
Scott Violet6c0eb6962018-06-20 01:31:26184#include "ui/base/ui_base_features.h"
[email protected]2d4817742012-12-17 20:16:18185#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:17186#include "ui/base/user_activity/user_activity_detector.h"
jamescook01bf23e72017-01-09 19:58:15187#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]116302fc2012-05-05 21:45:41188#include "ui/compositor/layer.h"
189#include "ui/compositor/layer_animator.h"
oshimaf84b0da722016-04-27 19:47:19190#include "ui/display/display.h"
Joone Hurd3ae8732018-04-17 18:05:09191#include "ui/display/manager/default_touch_transform_setter.h"
192#include "ui/display/manager/display_change_observer.h"
193#include "ui/display/manager/display_configurator.h"
rjkroege72f8154f2016-10-29 00:49:02194#include "ui/display/manager/display_manager.h"
Joone Hurd3ae8732018-04-17 18:05:09195#include "ui/display/manager/touch_transform_setter.h"
oshimaf84b0da722016-04-27 19:47:19196#include "ui/display/screen.h"
skycfaad892017-04-28 20:52:58197#include "ui/display/types/native_display_delegate.h"
[email protected]3e670aa2013-12-02 19:04:32198#include "ui/events/event_target_iterator.h"
sky4ec2be82017-01-06 17:38:32199#include "ui/gfx/geometry/insets.h"
[email protected]9ec0f452012-05-31 15:58:53200#include "ui/gfx/image/image_skia.h"
[email protected]b6ba05d902013-10-04 21:38:45201#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28202#include "ui/keyboard/keyboard_switches.h"
yhanada8909a542017-07-11 10:06:19203#include "ui/keyboard/keyboard_ui.h"
[email protected]f1d5c3a2013-04-23 17:42:56204#include "ui/keyboard/keyboard_util.h"
James Cook9db56d72018-08-01 03:21:31205#include "ui/ozone/public/ozone_platform.h"
[email protected]d7f30a72013-10-05 05:09:41206#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04207#include "ui/views/corewm/tooltip_controller.h"
sky07a24d42017-03-09 23:57:30208#include "ui/views/focus/focus_manager_factory.h"
Scott Violetac410622018-08-11 18:33:22209#include "ui/views/mus/window_manager_frame_values.h"
[email protected]c13be0d2011-11-22 02:09:58210#include "ui/views/widget/native_widget_aura.h"
211#include "ui/views/widget/widget.h"
[email protected]60d677d2014-05-30 13:07:02212#include "ui/wm/core/accelerator_filter.h"
[email protected]ee3ed10772014-03-11 22:02:01213#include "ui/wm/core/compound_event_filter.h"
214#include "ui/wm/core/focus_controller.h"
[email protected]ee3ed10772014-03-11 22:02:01215#include "ui/wm/core/shadow_controller.h"
216#include "ui/wm/core/visibility_controller.h"
217#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59218
[email protected]55f593352011-12-24 05:42:46219namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59220
221namespace {
[email protected]671a2ae2011-10-13 21:53:23222
[email protected]615922f2012-02-07 02:41:15223using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45224using views::Widget;
225
jamescook518dccbd2017-05-18 04:57:07226bool g_is_browser_process_with_mash = false;
227
[email protected]b5756e22012-11-30 01:32:02228// A Corewm VisibilityController subclass that calls the Ash animation routine
229// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14230class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02231 public:
Chris Watkinsc24daf62017-11-28 03:43:09232 AshVisibilityController() = default;
233 ~AshVisibilityController() override = default;
[email protected]b5756e22012-11-30 01:32:02234
235 private:
[email protected]e319c7e2014-03-14 19:56:14236 // Overridden from ::wm::VisibilityController:
dcheng1f4538e2014-10-27 23:57:05237 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
238 bool visible) override {
[email protected]b5756e22012-11-30 01:32:02239 return AnimateOnChildWindowVisibilityChanged(window, visible);
240 }
241
242 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
243};
244
Qiang Xu36234e532018-04-11 04:54:02245// Registers prefs whose default values are same in user and signin prefs.
246void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) {
247 AccessibilityController::RegisterProfilePrefs(registry, for_test);
248 BluetoothPowerController::RegisterProfilePrefs(registry);
Qiang Xudcf11e32018-04-25 17:10:17249 DockedMagnifierController::RegisterProfilePrefs(registry, for_test);
Qiang Xu36234e532018-04-11 04:54:02250 LoginScreenController::RegisterProfilePrefs(registry, for_test);
251 LogoutButtonTray::RegisterProfilePrefs(registry);
yoshiki iguchi71623722018-08-10 19:44:45252 MessageCenterController::RegisterProfilePrefs(registry);
Qiang Xu36234e532018-04-11 04:54:02253 NightLightController::RegisterProfilePrefs(registry);
254 PaletteTray::RegisterProfilePrefs(registry);
255 PaletteWelcomeBubble::RegisterProfilePrefs(registry);
256 ShelfController::RegisterProfilePrefs(registry);
Michael Giuffridac997aa72018-08-31 23:38:59257 TouchDevicesController::RegisterProfilePrefs(registry);
Qiang Xu36234e532018-04-11 04:54:02258 CapsLockNotificationController::RegisterProfilePrefs(registry, for_test);
259}
260
[email protected]87b0d82e2011-10-07 21:02:59261} // namespace
262
[email protected]cac10fc62011-10-07 23:22:56263// static
achuith287b26e2015-09-03 17:49:18264Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13265
266////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56267// Shell, public:
268
[email protected]cac10fc62011-10-07 23:22:56269// static
Scott Violetc8a1c6c2017-11-29 23:17:36270Shell* Shell::CreateInstance(ShellInitParams init_params) {
[email protected]3266c2b92011-11-14 00:06:08271 CHECK(!instance_);
James Cookfa4838e2018-08-08 16:30:15272 instance_ = new Shell(std::move(init_params.delegate), init_params.connector);
Scott Violete5c79f52018-07-31 00:10:17273 instance_->Init(init_params.context_factory,
274 init_params.context_factory_private,
275 std::move(init_params.initial_display_prefs),
276 std::move(init_params.gpu_interface_provider));
[email protected]3266c2b92011-11-14 00:06:08277 return instance_;
278}
279
280// static
skyb073203a2017-03-13 16:59:16281Shell* Shell::Get() {
jamescook518dccbd2017-05-18 04:57:07282 CHECK(!g_is_browser_process_with_mash) // Implies null |instance_|.
283 << "Ash is running in its own process so Shell::Get() will return null. "
284 "The browser process must use the mojo interfaces in //ash/public to "
285 "access ash. See ash/README.md for details.";
oshima9eea82da2014-09-13 01:11:07286 CHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56287 return instance_;
288}
289
[email protected]6377a002011-11-10 20:26:47290// static
[email protected]b3b7bcd2012-03-06 19:35:45291bool Shell::HasInstance() {
292 return !!instance_;
293}
294
295// static
[email protected]ef589af2011-12-03 01:07:15296void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47297 delete instance_;
[email protected]6377a002011-11-10 20:26:47298}
299
[email protected]e73bd7802012-02-17 20:10:34300// static
[email protected]093b8d642014-04-03 20:59:28301RootWindowController* Shell::GetPrimaryRootWindowController() {
oshima9eea82da2014-09-13 01:11:07302 CHECK(HasInstance());
msw257a6a232017-06-01 01:46:30303 return RootWindowController::ForWindow(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23304}
305
306// static
307Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
oshima9eea82da2014-09-13 01:11:07308 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34309 RootWindowControllerList root_window_controllers;
msw257a6a232017-06-01 01:46:30310 for (aura::Window* root : GetAllRootWindows())
311 root_window_controllers.push_back(RootWindowController::ForWindow(root));
skyabcae812017-01-18 17:01:34312 return root_window_controllers;
[email protected]d90b8392012-06-13 09:34:56313}
314
315// static
thanhphc90f49ca2017-03-03 17:48:53316RootWindowController* Shell::GetRootWindowControllerWithDisplayId(
317 int64_t display_id) {
318 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13319 aura::Window* root = GetRootWindowForDisplayId(display_id);
msw257a6a232017-06-01 01:46:30320 return root ? RootWindowController::ForWindow(root) : nullptr;
thanhphc90f49ca2017-03-03 17:48:53321}
322
323// static
Scott Violet596bb46342017-06-21 14:43:13324aura::Window* Shell::GetRootWindowForDisplayId(int64_t display_id) {
325 CHECK(HasInstance());
326 return instance_->window_tree_host_manager_->GetRootWindowForDisplayId(
327 display_id);
328}
329
330// static
[email protected]bf9cdb362013-10-25 19:22:45331aura::Window* Shell::GetPrimaryRootWindow() {
oshima9eea82da2014-09-13 01:11:07332 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13333 return instance_->window_tree_host_manager_->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34334}
335
[email protected]7b0f7502012-06-11 00:12:39336// static
sky27344382017-03-08 21:30:32337aura::Window* Shell::GetRootWindowForNewWindows() {
James Cook40f7d752018-05-25 18:21:58338 return Shell::Get()->shell_state_->GetRootWindowForNewWindows();
mfomitcheva1a8aa62016-05-03 16:23:26339}
340
341// static
[email protected]c9390bd2013-11-08 20:33:13342aura::Window::Windows Shell::GetAllRootWindows() {
oshima9eea82da2014-09-13 01:11:07343 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13344 return instance_->window_tree_host_manager_->GetAllRootWindows();
[email protected]be65be362012-06-15 07:38:23345}
346
347// static
jamescookb8dcef522016-06-25 14:42:55348aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) {
[email protected]7b0f7502012-06-11 00:12:39349 return root_window->GetChildById(container_id);
350}
351
352// static
[email protected]bf9cdb362013-10-25 19:22:45353const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38354 int container_id) {
355 return root_window->GetChildById(container_id);
356}
357
sky494c6cbd2017-03-27 20:57:48358// static
James Cook7b7c6a52018-01-04 23:40:03359int Shell::GetOpenSystemModalWindowContainerId() {
360 // The test boolean is not static to avoid leaking state between tests.
361 if (Get()->simulate_modal_window_open_for_test_)
362 return kShellWindowId_SystemModalContainer;
363
364 // Traverse all system modal containers, and find its direct child window
365 // with "SystemModal" setting, and visible.
James Cook7b7c6a52018-01-04 23:40:03366 for (aura::Window* root : Shell::GetAllRootWindows()) {
Xiyuan Xia40b3fb1f2018-08-22 22:18:20367 for (int modal_window_id : kSystemModalContainerIds) {
James Cook7b7c6a52018-01-04 23:40:03368 aura::Window* system_modal = root->GetChildById(modal_window_id);
369 if (!system_modal)
370 continue;
371 for (const aura::Window* child : system_modal->children()) {
372 if (child->GetProperty(aura::client::kModalKey) ==
373 ui::MODAL_TYPE_SYSTEM &&
374 child->layer()->GetTargetVisibility()) {
375 return modal_window_id;
376 }
377 }
378 }
379 }
380 return -1;
381}
382
383// static
384bool Shell::IsSystemModalWindowOpen() {
385 return GetOpenSystemModalWindowContainerId() >= 0;
386}
387
388// static
James Cooka6066972018-07-31 19:34:07389bool Shell::HasRemoteClient(aura::Window* window) {
Scott Violet7e33efc2018-08-29 22:30:15390 return ws::WindowService::HasRemoteClient(window);
James Cooka6066972018-07-31 19:34:07391}
392
393// static
Steven Bennettsca108512018-05-02 11:05:03394void Shell::RegisterLocalStatePrefs(PrefRegistrySimple* registry,
395 bool for_test) {
Sammie Quon4d7dba62017-08-03 23:18:17396 PaletteTray::RegisterLocalStatePrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34397 WallpaperController::RegisterLocalStatePrefs(registry);
Sonny Sasaka55f69fc2017-08-28 21:29:37398 BluetoothPowerController::RegisterLocalStatePrefs(registry);
Toni Barzicd6238312018-03-02 18:26:13399 DetachableBaseHandler::RegisterPrefs(registry);
Steven Bennettsca108512018-05-02 11:05:03400 // Note: DisplayPrefs are registered in chrome in AshShellInit::RegisterPrefs
401 // (see comment there for details).
402 if (for_test)
403 DisplayPrefs::RegisterLocalStatePrefs(registry);
404 else
405 DisplayPrefs::RegisterForeignPrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34406}
407
408// static
Qiang Xu36234e532018-04-11 04:54:02409void Shell::RegisterSigninProfilePrefs(PrefRegistrySimple* registry,
410 bool for_test) {
411 RegisterProfilePrefs(registry, for_test);
412 PowerPrefs::RegisterSigninProfilePrefs(registry, for_test);
413}
414
415// static
416void Shell::RegisterUserProfilePrefs(PrefRegistrySimple* registry,
417 bool for_test) {
418 RegisterProfilePrefs(registry, for_test);
419 PowerPrefs::RegisterUserProfilePrefs(registry, for_test);
afakhrye4fae852017-05-09 18:49:06420}
421
Xiyuan Xia36197372018-04-25 00:45:17422void Shell::InitWaylandServer(std::unique_ptr<exo::FileHelper> file_helper) {
Scott Violetac410622018-08-11 18:33:22423 wayland_server_controller_ = WaylandServerController::CreateIfNecessary(
424 std::move(file_helper), aura_env_);
Tetsui Ohkubo852abe642018-10-03 02:52:27425 if (wayland_server_controller_) {
426 system_tray_model()
427 ->virtual_keyboard()
428 ->SetInputMethodSurfaceManagerObserver(
429 wayland_server_controller_->arc_input_method_surface_manager());
430 }
Scott Violet737fb752018-04-11 15:35:22431}
432
433void Shell::DestroyWaylandServer() {
Tetsui Ohkubo852abe642018-10-03 02:52:27434 if (wayland_server_controller_) {
435 system_tray_model()
436 ->virtual_keyboard()
437 ->RemoveInputMethodSurfaceManagerObserver(
438 wayland_server_controller_->arc_input_method_surface_manager());
439 }
Scott Violet737fb752018-04-11 15:35:22440 wayland_server_controller_.reset();
441}
442
[email protected]57b8bb352012-01-11 05:11:46443views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
444 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04445 // Use translucent-style window frames for dialogs.
Evan Stade5f09e6572018-08-10 17:48:15446 return new NonClientFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46447}
448
[email protected]2e236a52012-06-27 22:21:47449void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44450 const gfx::Insets& insets) {
Scott Violet596bb46342017-06-21 14:43:13451 window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow(contains,
452 insets);
[email protected]1a2145b2012-03-13 21:09:17453}
454
[email protected]58868abf2014-01-17 23:45:33455void Shell::OnCastingSessionStartedOrStopped(bool started) {
sky00c813f2017-03-08 22:48:55456 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18457 observer.OnCastingSessionStartedOrStopped(started);
[email protected]58868abf2014-01-17 23:45:33458}
459
varkhac71444e52017-05-25 22:51:34460void Shell::OnRootWindowAdded(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55461 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18462 observer.OnRootWindowAdded(root_window);
[email protected]0e3e7cb2014-04-12 05:18:25463}
464
Zach Helfinsteinbbb6bad2018-05-02 18:21:51465void Shell::OnDictationStarted() {
466 for (auto& observer : shell_observers_)
467 observer.OnDictationStarted();
468}
469
470void Shell::OnDictationEnded() {
471 for (auto& observer : shell_observers_)
472 observer.OnDictationEnded();
473}
474
Darren Shenf62db77a2018-06-07 06:22:44475void Shell::EnableKeyboard() {
Darren Shena314c212018-05-22 00:53:17476 if (!keyboard::IsKeyboardEnabled())
477 return;
478
Darren Shenf62db77a2018-06-07 06:22:44479 if (keyboard_controller_->enabled()) {
480 // Disable and re-enable the keyboard, as some callers expect the keyboard
481 // to be reloaded.
482 // TODO(https://crbug.com/731537): Add a separate function for reloading the
483 // keyboard.
484 for (auto* const controller : GetAllRootWindowControllers())
485 controller->DeactivateKeyboard(keyboard_controller_.get());
Keigo Okae82281a2017-06-14 13:59:14486 }
Mike Wassermancebe67682018-06-28 23:01:35487
James Cook8160d0332018-08-21 16:02:32488 // TODO(crbug.com/646565): The keyboard UI uses a WebContents that is
489 // created by chrome code but parented to an ash-created container window.
490 // See ChromeKeyboardUI and keyboard::KeyboardController. This needs to be
491 // fixed for both SingleProcessMash and MultiProcessMash.
492 if (::features::IsUsingWindowService())
Mike Wassermancebe67682018-06-28 23:01:35493 return;
494
James Cook8160d0332018-08-21 16:02:32495 auto keyboard_ui = shell_delegate_->CreateKeyboardUI();
496 DCHECK(keyboard_ui);
Mike Wassermancebe67682018-06-28 23:01:35497 keyboard_controller_->EnableKeyboard(std::move(keyboard_ui),
Darren Shenad5dc722018-05-28 00:14:45498 virtual_keyboard_controller_.get());
Darren Shena314c212018-05-22 00:53:17499 for (auto& observer : shell_observers_)
500 observer.OnKeyboardControllerCreated();
jamescookb8dcef522016-06-25 14:42:55501 GetPrimaryRootWindowController()->ActivateKeyboard(
Darren Shenf62db77a2018-06-07 06:22:44502 keyboard_controller_.get());
[email protected]51f438112013-11-18 19:32:50503}
504
Darren Shenf62db77a2018-06-07 06:22:44505void Shell::DisableKeyboard() {
Darren Shenf62db77a2018-06-07 06:22:44506 if (keyboard_controller_->enabled()) {
507 for (auto* const controller : GetAllRootWindowControllers())
508 controller->DeactivateKeyboard(keyboard_controller_.get());
[email protected]e1b299b2014-01-29 23:53:41509 }
Darren Shenf62db77a2018-06-07 06:22:44510
Darren Shenad5dc722018-05-28 00:14:45511 keyboard_controller_->DisableKeyboard();
[email protected]e1b299b2014-01-29 23:53:41512}
513
[email protected]da285852014-05-27 19:53:43514bool Shell::ShouldSaveDisplaySettings() {
jamescookb8dcef522016-06-25 14:42:55515 return !(
516 screen_orientation_controller_->ignore_display_configuration_updates() ||
517 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43518}
[email protected]da285852014-05-27 19:53:43519
Ahmed Fakhry4bf3f742018-02-06 17:33:36520DockedMagnifierController* Shell::docked_magnifier_controller() {
Ahmed Fakhry4af48e42018-02-28 17:45:38521 DCHECK(features::IsDockedMagnifierEnabled());
Ahmed Fakhry4bf3f742018-02-06 17:33:36522 return docked_magnifier_controller_.get();
523}
524
afakhry9e0a18b32017-06-05 19:23:14525NightLightController* Shell::night_light_controller() {
Ahmed Fakhryb9ace242018-06-06 18:49:31526 DCHECK(features::IsNightLightEnabled());
afakhry9e0a18b32017-06-05 19:23:14527 return night_light_controller_.get();
528}
529
sky5ad143a2017-03-22 04:31:23530ShelfModel* Shell::shelf_model() {
531 return shelf_controller_->model();
532}
533
Thiago Farina3b086a02017-05-30 22:32:50534::wm::ActivationClient* Shell::activation_client() {
sky27344382017-03-08 21:30:32535 return focus_controller_.get();
536}
537
[email protected]c758fbf2012-03-25 22:53:59538void Shell::UpdateShelfVisibility() {
msw257a6a232017-06-01 01:46:30539 for (aura::Window* root : GetAllRootWindows())
540 Shelf::ForWindow(root)->UpdateVisibilityState();
[email protected]c758fbf2012-03-25 22:53:59541}
542
Xiyuan Xia522710a2018-05-08 16:35:42543NotificationTray* Shell::GetNotificationTray() {
jamescook612205f2016-05-26 06:02:11544 return GetPrimaryRootWindowController()
jamescookb551aba2016-09-01 01:00:16545 ->GetStatusAreaWidget()
Xiyuan Xia522710a2018-05-08 16:35:42546 ->notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28547}
548
[email protected]a0afeb12012-12-10 22:57:09549bool Shell::HasPrimaryStatusArea() {
jamescookb551aba2016-09-01 01:00:16550 return !!GetPrimaryRootWindowController()->GetStatusAreaWidget();
[email protected]31f19e32012-10-30 22:31:23551}
552
[email protected]a0afeb12012-12-10 22:57:09553SystemTray* Shell::GetPrimarySystemTray() {
554 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42555}
556
yawanodc5533b32017-02-23 11:04:38557void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
558 window_tree_host_manager_->cursor_window_controller()
559 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
560}
561
Weidong Guod07448f2017-10-18 03:35:18562void Shell::UpdateCursorCompositingEnabled() {
563 SetCursorCompositingEnabled(
564 window_tree_host_manager_->cursor_window_controller()
565 ->ShouldEnableCursorCompositing());
566}
567
[email protected]87ec2202014-02-06 06:24:27568void Shell::SetCursorCompositingEnabled(bool enabled) {
James Cookf2920df2018-09-04 19:55:01569 CursorWindowController* cursor_window_controller =
570 window_tree_host_manager_->cursor_window_controller();
Weidong Guo7dfd1482017-11-08 05:56:28571
James Cookf2920df2018-09-04 19:55:01572 if (cursor_window_controller->is_cursor_compositing_enabled() == enabled)
573 return;
574 cursor_window_controller->SetCursorCompositingEnabled(enabled);
575 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
[email protected]87ec2202014-02-06 06:24:27576}
[email protected]59ccade2013-10-17 17:56:40577
[email protected]f9466702012-09-17 16:35:27578void Shell::DoInitialWorkspaceAnimation() {
jamescookb8dcef522016-06-25 14:42:55579 return GetPrimaryRootWindowController()
580 ->workspace_controller()
581 ->DoInitialAnimation();
[email protected]f9466702012-09-17 16:35:27582}
583
xdaid4913762017-07-06 00:17:22584bool Shell::IsSplitViewModeActive() const {
Xiaoqian Daibf3771f2018-03-13 18:21:46585 return split_view_controller_.get() &&
586 split_view_controller_->IsSplitViewModeActive();
xdaid4913762017-07-06 00:17:22587}
588
James Cookfa4838e2018-08-08 16:30:15589void Shell::ShowContextMenu(const gfx::Point& location_in_screen,
590 ui::MenuSourceType source_type) {
591 // Bail with no active user session, in the lock screen, or in app/kiosk mode.
592 if (session_controller_->NumberOfLoggedInUsers() < 1 ||
593 session_controller_->IsScreenLocked() ||
594 session_controller_->IsRunningInAppMode()) {
595 return;
596 }
597
598 aura::Window* root = wm::GetRootWindowAt(location_in_screen);
599 RootWindowController::ForWindow(root)->ShowContextMenu(location_in_screen,
600 source_type);
601}
602
603void Shell::AddPointerWatcher(views::PointerWatcher* watcher,
604 views::PointerWatcherEventTypes events) {
605 pointer_watcher_adapter_->AddPointerWatcher(watcher, events);
606}
607
608void Shell::RemovePointerWatcher(views::PointerWatcher* watcher) {
609 pointer_watcher_adapter_->RemovePointerWatcher(watcher);
610}
611
sky00c813f2017-03-08 22:48:55612void Shell::AddShellObserver(ShellObserver* observer) {
613 shell_observers_.AddObserver(observer);
614}
615
616void Shell::RemoveShellObserver(ShellObserver* observer) {
617 shell_observers_.RemoveObserver(observer);
618}
619
sky5ad143a2017-03-22 04:31:23620void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
varkha59679632017-06-01 00:42:05621 for (auto* root_window_controller : GetAllRootWindowControllers())
622 root_window_controller->UpdateAfterLoginStatusChange(status);
sky5ad143a2017-03-22 04:31:23623}
624
sky00c813f2017-03-08 22:48:55625void Shell::NotifyOverviewModeStarting() {
626 for (auto& observer : shell_observers_)
627 observer.OnOverviewModeStarting();
628}
629
Xiaoqian Daifb4698ed2018-02-23 20:11:06630void Shell::NotifyOverviewModeEnding() {
631 for (auto& observer : shell_observers_)
632 observer.OnOverviewModeEnding();
633}
634
sky00c813f2017-03-08 22:48:55635void Shell::NotifyOverviewModeEnded() {
636 for (auto& observer : shell_observers_)
637 observer.OnOverviewModeEnded();
638}
639
Sammie Quon317deb52018-09-06 16:36:28640void Shell::NotifyOverviewModeEndingAnimationComplete() {
641 for (auto& observer : shell_observers_)
642 observer.OnOverviewModeEndingAnimationComplete();
643}
644
xdaid4913762017-07-06 00:17:22645void Shell::NotifySplitViewModeStarting() {
646 for (auto& observer : shell_observers_)
647 observer.OnSplitViewModeStarting();
648}
649
Xiaoqian Daibf3771f2018-03-13 18:21:46650void Shell::NotifySplitViewModeStarted() {
651 for (auto& observer : shell_observers_)
652 observer.OnSplitViewModeStarted();
653}
654
xdaid4913762017-07-06 00:17:22655void Shell::NotifySplitViewModeEnded() {
656 for (auto& observer : shell_observers_)
657 observer.OnSplitViewModeEnded();
658}
659
sky00c813f2017-03-08 22:48:55660void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
varkhac71444e52017-05-25 22:51:34661 aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55662 for (auto& observer : shell_observers_)
663 observer.OnFullscreenStateChanged(is_fullscreen, root_window);
664}
665
varkha19d7e6c52017-05-25 21:15:30666void Shell::NotifyPinnedStateChanged(aura::Window* pinned_window) {
sky00c813f2017-03-08 22:48:55667 for (auto& observer : shell_observers_)
668 observer.OnPinnedStateChanged(pinned_window);
669}
670
varkha6b016b0f2017-05-26 16:14:18671void Shell::NotifyShelfAlignmentChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55672 for (auto& observer : shell_observers_)
673 observer.OnShelfAlignmentChanged(root_window);
674}
675
varkha6b016b0f2017-05-26 16:14:18676void Shell::NotifyShelfAutoHideBehaviorChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55677 for (auto& observer : shell_observers_)
678 observer.OnShelfAutoHideBehaviorChanged(root_window);
679}
680
jamescook518dccbd2017-05-18 04:57:07681// static
682void Shell::SetIsBrowserProcessWithMash() {
683 g_is_browser_process_with_mash = true;
684}
685
muyuanlid766f2e2017-06-26 20:17:19686void Shell::NotifyAppListVisibilityChanged(bool visible,
687 aura::Window* root_window) {
newcomer2febb9832017-06-12 17:00:23688 for (auto& observer : shell_observers_)
689 observer.OnAppListVisibilityChanged(visible, root_window);
690}
691
[email protected]b6ba05d902013-10-04 21:38:45692////////////////////////////////////////////////////////////////////////////////
693// Shell, private:
694
skyb073203a2017-03-13 16:59:16695Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
Scott Violete5c79f52018-07-31 00:10:17696 service_manager::Connector* connector)
Scott Violetac410622018-08-11 18:33:22697 : owned_aura_env_(::features::IsSingleProcessMash()
698 ? aura::Env::CreateLocalInstanceForInProcess()
699 : nullptr),
700 aura_env_(owned_aura_env_.get() ? owned_aura_env_.get()
701 : aura::Env::GetInstance()),
702 ash_display_controller_(std::make_unique<AshDisplayController>()),
sky79fa34712017-03-20 23:46:47703 brightness_control_delegate_(
Mitsuru Oshima04b54d02017-10-09 14:22:45704 std::make_unique<system::BrightnessControllerChromeos>()),
705 cast_config_(std::make_unique<CastConfigController>()),
Scott Violete5c79f52018-07-31 00:10:17706 connector_(connector),
James Cookf5398842018-04-16 20:15:24707 first_run_helper_(std::make_unique<FirstRunHelper>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45708 focus_cycler_(std::make_unique<FocusCycler>()),
709 ime_controller_(std::make_unique<ImeController>()),
710 immersive_context_(std::make_unique<ImmersiveContextAsh>()),
sky79fa34712017-03-20 23:46:47711 keyboard_brightness_control_delegate_(
Mitsuru Oshima04b54d02017-10-09 14:22:45712 std::make_unique<KeyboardBrightnessController>()),
Darren Shenad5dc722018-05-28 00:14:45713 keyboard_controller_(std::make_unique<keyboard::KeyboardController>()),
sky79fa34712017-03-20 23:46:47714 locale_notification_controller_(
Mitsuru Oshima04b54d02017-10-09 14:22:45715 std::make_unique<LocaleNotificationController>()),
Jacob Dufaultffd9b0d2017-11-15 23:07:16716 login_screen_controller_(std::make_unique<LoginScreenController>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45717 media_controller_(std::make_unique<MediaController>()),
718 new_window_controller_(std::make_unique<NewWindowController>()),
Scott Violete5c79f52018-07-31 00:10:17719 session_controller_(std::make_unique<SessionController>(connector)),
Vladislav Kaznacheev92edf62e2017-10-13 22:08:01720 note_taking_controller_(std::make_unique<NoteTakingController>()),
skyb073203a2017-03-13 16:59:16721 shell_delegate_(std::move(shell_delegate)),
James Cook40f7d752018-05-25 18:21:58722 shell_state_(std::make_unique<ShellState>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45723 shutdown_controller_(std::make_unique<ShutdownController>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45724 system_tray_notifier_(std::make_unique<SystemTrayNotifier>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45725 vpn_list_(std::make_unique<VpnList>()),
726 window_cycle_controller_(std::make_unique<WindowCycleController>()),
727 window_selector_controller_(std::make_unique<WindowSelectorController>()),
Scott Violetbed23cb2018-08-22 19:56:12728 display_configurator_(std::make_unique<display::DisplayConfigurator>()),
729 display_output_protection_(std::make_unique<DisplayOutputProtection>(
730 display_configurator_.get())),
sadrul7a8785e2016-02-12 21:54:35731 native_cursor_manager_(nullptr),
Sam McNallye36abbc2017-07-20 01:04:28732 weak_factory_(this) {
Scott Violet596bb46342017-06-21 14:43:13733 display_manager_.reset(ScreenAsh::CreateDisplayManager());
Mitsuru Oshima04b54d02017-10-09 14:22:45734 window_tree_host_manager_ = std::make_unique<WindowTreeHostManager>();
735 user_metrics_recorder_ = std::make_unique<UserMetricsRecorder>();
[email protected]b6ba05d902013-10-04 21:38:45736
Giovanni Ortuño Urquidi55aa5d8f2018-10-10 05:33:34737 if (base::FeatureList::IsEnabled(features::kUseBluetoothSystemInAsh)) {
738 tray_bluetooth_helper_ =
739 std::make_unique<TrayBluetoothHelperExperimental>();
740 } else {
741 tray_bluetooth_helper_ = std::make_unique<TrayBluetoothHelperLegacy>();
742 }
743
[email protected]093b8d642014-04-03 20:59:28744 PowerStatus::Initialize();
sky5ad143a2017-03-22 04:31:23745
Xiyuan Xia22b1a6c2017-04-18 22:46:01746 session_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45747}
748
749Shell::~Shell() {
750 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
751
Scott Violet737fb752018-04-11 15:35:22752 // Wayland depends upon some ash specific objects. Destroy it early on.
753 wayland_server_controller_.reset();
754
Scott Violet41562d1c2017-06-26 15:15:48755 user_metrics_recorder_->OnShellShuttingDown();
bruthigc24d11f2015-06-09 21:30:03756
Steven Bennetts2a9b4382018-04-26 23:41:19757 cros_display_config_.reset();
Steven Bennetts9b21fa32018-04-13 23:45:55758 display_configuration_observer_.reset();
Steven Bennetts3688c6032018-04-13 01:14:23759 display_prefs_.reset();
[email protected]050e77182014-03-25 15:29:16760
[email protected]b6ba05d902013-10-04 21:38:45761 // Remove the focus from any window. This will prevent overhead and side
762 // effects (e.g. crashes) from changing focus during shutdown.
763 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18764 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45765
xdaid4913762017-07-06 00:17:22766 // Please keep in reverse order as in Init() because it's easy to miss one.
[email protected]b6ba05d902013-10-04 21:38:45767 if (window_modality_controller_)
768 window_modality_controller_.reset();
jamescook01bf23e72017-01-09 19:58:15769
[email protected]e4ea52362014-02-15 03:21:06770 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
771 magnifier_key_scroll_handler_.reset();
772
773 RemovePreTargetHandler(speech_feedback_handler_.get());
774 speech_feedback_handler_.reset();
jamescook01bf23e72017-01-09 19:58:15775
[email protected]b6ba05d902013-10-04 21:38:45776 RemovePreTargetHandler(overlay_filter_.get());
Xiyuan Xia22b1a6c2017-04-18 22:46:01777 overlay_filter_.reset();
778
[email protected]3537d472014-01-15 05:45:31779 RemovePreTargetHandler(accelerator_filter_.get());
780 RemovePreTargetHandler(event_transformation_handler_.get());
781 RemovePreTargetHandler(toplevel_window_event_handler_.get());
782 RemovePostTargetHandler(toplevel_window_event_handler_.get());
Scott Violet596bb46342017-06-21 14:43:13783 RemovePreTargetHandler(system_gesture_filter_.get());
784 RemovePreTargetHandler(mouse_cursor_filter_.get());
hariank0dd03dd2016-07-14 23:47:33785 RemovePreTargetHandler(modality_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45786 RemovePreTargetHandler(tooltip_controller_.get());
787
Mike Wassermanefbf3402018-04-26 00:41:32788 event_rewriter_controller_.reset();
789
jonross0af45212015-01-13 18:55:46790 screen_orientation_controller_.reset();
yiyixa68ade512016-09-01 17:38:13791 screen_layout_observer_.reset();
jonross0af45212015-01-13 18:55:46792
Mitsuru Oshima0e9b7a62017-07-19 18:23:03793 // Destroy the virtual keyboard controller before the tablet mode controller
jamescook01bf23e72017-01-09 19:58:15794 // since the latters destructor triggers events that the former is listening
795 // to but no longer cares about.
rsadambbaf2c82015-01-07 17:54:13796 virtual_keyboard_controller_.reset();
jonross0af45212015-01-13 18:55:46797
James Cookd2495fe2018-03-19 19:53:10798 // Depends on |tablet_mode_controller_|.
799 shelf_controller_->Shutdown();
800
Weidong Guo268c7992018-04-13 21:06:07801 // Destroy |app_list_controller_| early than |tablet_mode_controller_| since
802 // the former may use the latter before destruction.
803 app_list_controller_.reset();
804
David Blackc153e3172018-08-21 18:17:58805 // Destroy |assistant_controller_| earlier than |tablet_mode_controller_| so
806 // that the former will destroy the Assistant view hierarchy which has a
807 // dependency on the latter.
Muyuan Li628f6a62018-08-15 20:39:58808 if (chromeos::switches::IsAssistantEnabled())
David Blackc153e3172018-08-21 18:17:58809 assistant_controller_.reset();
Muyuan Li628f6a62018-08-15 20:39:58810
Mitsuru Oshima0e9b7a62017-07-19 18:23:03811 // Destroy tablet mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57812 // need to be removed.
Mitsuru Oshima0e9b7a62017-07-19 18:23:03813 tablet_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57814
jdufault551152e2016-01-27 19:48:43815 // Destroy the keyboard before closing the shelf, since it will invoke a shelf
816 // layout.
Darren Shenf62db77a2018-06-07 06:22:44817 DisableKeyboard();
jdufault551152e2016-01-27 19:48:43818
sky07a24d42017-03-09 23:57:30819 toast_manager_.reset();
yoshiki32f51632016-03-24 01:24:43820
jamescookac6724332017-03-21 02:54:43821 tray_bluetooth_helper_.reset();
James Cookb50959e22017-08-10 20:24:38822
823 // Accesses root window containers.
824 logout_confirmation_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45825
[email protected]b6ba05d902013-10-04 21:38:45826 // Drag-and-drop must be canceled prior to close all windows.
James Cook1e0f3ff2018-03-06 22:52:45827 for (aura::Window* root : GetAllRootWindows())
828 aura::client::SetDragDropClient(root, nullptr);
[email protected]b6ba05d902013-10-04 21:38:45829 drag_drop_controller_.reset();
830
Xiyuan Xia22b1a6c2017-04-18 22:46:01831 // Controllers who have WindowObserver added must be deleted
832 // before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03833
Qiang Xud77a90c2018-02-20 19:43:29834 persistent_window_controller_.reset();
835
[email protected]8c9d12a2013-12-06 18:39:03836 // VideoActivityNotifier must be deleted before |video_detector_| is
837 // deleted because it's observing video activity through
derat83b761392016-07-11 16:44:44838 // VideoDetector::Observer interface.
[email protected]8c9d12a2013-12-06 18:39:03839 video_activity_notifier_.reset();
[email protected]8c9d12a2013-12-06 18:39:03840 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25841 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03842
843 shadow_controller_.reset();
844 resize_shadow_controller_.reset();
845
sky37f0dd12016-07-19 18:00:59846 // Has to happen before ~MruWindowTracker.
sky5b45ed82017-03-27 02:54:23847 window_cycle_controller_.reset();
848 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03849
xdai7a8867cd2017-08-25 23:10:16850 // |split_view_controller_| needs to be deleted after
851 // |window_selector_controller_|.
852 split_view_controller_.reset();
853
James Cook43097132018-08-18 23:31:54854 // Stop dispatching events (e.g. synthesized mouse exits from window close).
855 // https://crbug.com/874156
856 for (RootWindowController* rwc : GetAllRootWindowControllers())
857 rwc->GetHost()->dispatcher()->Shutdown();
858
James Cookee2daef2018-03-10 01:48:10859 // Close all widgets (including the shelf) and destroy all window containers.
skyabcae812017-01-18 17:01:34860 CloseAllRootWindowChildWindows();
861
Tetsui Ohkubo269b5792018-04-26 01:06:32862 system_notification_controller_.reset();
863 // Should be destroyed after Shelf and |system_notification_controller_|.
864 system_tray_model_.reset();
865
afakhry58159392015-05-22 02:45:52866 // MruWindowTracker must be destroyed after all windows have been deleted to
867 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
868 // path. (crbug.com/485438).
sky5ab16472017-03-21 19:35:08869 mru_window_tracker_.reset();
[email protected]b6ba05d902013-10-04 21:38:45870
[email protected]b6ba05d902013-10-04 21:38:45871 // These need a valid Shell instance to clean up properly, so explicitly
872 // delete them before invalidating the instance.
873 // Alphabetical. TODO(oshima): sort.
874 magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45875 tooltip_controller_.reset();
876 event_client_.reset();
[email protected]3537d472014-01-15 05:45:31877 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45878 visibility_controller_.reset();
Qiang Xu36234e532018-04-11 04:54:02879 power_prefs_.reset();
[email protected]b6ba05d902013-10-04 21:38:45880
Toni Barzic85ae39e2017-12-07 05:50:18881 tray_action_.reset();
882
[email protected]b6ba05d902013-10-04 21:38:45883 power_button_controller_.reset();
884 lock_state_controller_.reset();
Toni Barzic9d0c82f42017-12-06 00:53:52885 backlights_forced_off_setter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45886
hidehiko6821ca42016-06-18 11:12:23887 screen_pinning_controller_.reset();
888
Kyle Horimoto9fc84fc22018-04-27 19:45:15889 multidevice_notification_presenter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45890 resolution_notification_controller_.reset();
oshima5a296e82016-04-29 01:32:27891 screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49892 mouse_cursor_filter_.reset();
hariank0dd03dd2016-07-14 23:47:33893 modality_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45894
[email protected]03122891a2014-05-13 23:56:49895 touch_transformer_controller_.reset();
sammiequon203ae022016-09-18 17:23:42896 laser_pointer_controller_.reset();
897 partial_magnification_controller_.reset();
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:32898 highlighter_controller_.reset();
Yue Lia33960a2017-11-01 22:06:07899 voice_interaction_controller_.reset();
David Tseng6792dc82018-05-04 19:18:41900 key_accessibility_enabler_.reset();
warx533c8f62016-04-12 01:19:43901
Tetsui Ohkubo01421b32018-05-30 16:54:59902 display_speaker_controller_.reset();
Tetsui Ohkubo54d50222018-05-10 01:58:11903 screen_switch_check_controller_.reset();
904
rjkroege2c9305402016-09-07 00:21:45905 ScreenAsh::CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12906 display_configuration_controller_.reset();
dtseng4ae0a882016-04-15 21:39:27907
sky07a24d42017-03-09 23:57:30908 // These members access Shell in their destructors.
909 wallpaper_controller_.reset();
James Cookec144952017-09-01 00:05:16910 accessibility_controller_.reset();
sky07a24d42017-03-09 23:57:30911 accessibility_delegate_.reset();
Qiang Xua9591002018-03-15 22:29:31912 accessibility_focus_ring_controller_.reset();
Qiang Xud8e897e2018-05-24 20:07:57913 policy_recommendation_restorer_.reset();
sky07a24d42017-03-09 23:57:30914
915 // Balances the Install() in Initialize().
916 views::FocusManagerFactory::Install(nullptr);
917
sky5ad143a2017-03-22 04:31:23918 // ShelfWindowWatcher has window observers and a pointer to the shelf model.
919 shelf_window_watcher_.reset();
920
tibellb93c729b2017-03-30 00:45:09921 // Removes itself as an observer of |pref_service_|.
sky5ad143a2017-03-22 04:31:23922 shelf_controller_.reset();
923
Ahmed Fakhrye96051f2017-12-12 17:42:17924 // NightLightController depends on the PrefService as well as the window tree
925 // host manager, and must be destructed before them. crbug.com/724231.
926 night_light_controller_ = nullptr;
Ahmed Fakhry4bf3f742018-02-06 17:33:36927 // Similarly for DockedMagnifierController.
928 docked_magnifier_controller_ = nullptr;
Ahmed Fakhrye96051f2017-12-12 17:42:17929
Scott Violetb7f4df22018-05-17 04:43:12930 // May own windows and other objects that have indirect hooks into
931 // WindowTreeHostManager.
932 window_service_owner_.reset();
933
Xiyuan Xia5f1046e2018-06-01 16:04:44934 // Must be released before |focus_controller_|.
935 ime_focus_handler_.reset();
936
James Cookfa4838e2018-08-08 16:30:15937 pointer_watcher_adapter_.reset();
James Cook05b3a3f2018-08-07 00:38:55938
939 // Stop observing window activation changes before closing all windows.
940 focus_controller_->RemoveObserver(this);
941
942 // This also deletes all RootWindows. Note that we invoke Shutdown() on
943 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
944 // destruction of its owned RootWindowControllers relies on the value.
Scott Violet596bb46342017-06-21 14:43:13945 window_tree_host_manager_->Shutdown();
sky5ad143a2017-03-22 04:31:23946
sky27344382017-03-08 21:30:32947 // Depends on |focus_controller_|, so must be destroyed before.
oshimae2818922015-07-28 01:18:52948 window_tree_host_manager_.reset();
sky27344382017-03-08 21:30:32949 focus_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45950 screen_position_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45951
robert.bradfordab052492015-05-06 11:09:56952 display_color_manager_.reset();
Steven Bennetts7683e342018-01-02 21:29:52953 projecting_observer_.reset();
954
[email protected]7bc49bd2014-01-22 09:30:34955 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11956 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45957 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11958 display_configurator_->RemoveObserver(display_error_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45959 display_change_observer_.reset();
Steven Bennetts7683e342018-01-02 21:29:52960 display_shutdown_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45961
[email protected]093b8d642014-04-03 20:59:28962 PowerStatus::Shutdown();
James Cook934ba812018-04-20 14:17:35963 // Depends on SessionController.
964 power_event_observer_.reset();
pneubeck8be1f5422014-10-09 16:46:18965
Xiyuan Xia22b1a6c2017-04-18 22:46:01966 session_controller_->RemoveObserver(this);
Sonny Sasaka55f69fc2017-08-28 21:29:37967 // BluetoothPowerController depends on the PrefService and must be destructed
968 // before it.
969 bluetooth_power_controller_ = nullptr;
Qiang Xuf1400a362017-09-14 02:28:30970 // TouchDevicesController depends on the PrefService and must be destructed
971 // before it.
972 touch_devices_controller_ = nullptr;
Toni Barzic550419f2018-03-08 03:56:21973 // DetachableBaseNotificationController depends on DetachableBaseHandler, and
974 // has to be destructed before it.
975 detachable_base_notification_controller_.reset();
Toni Barzicd6238312018-03-02 18:26:13976 // DetachableBaseHandler depends on the PrefService and must be destructed
977 // before it.
978 detachable_base_handler_.reset();
Ahmed Fakhrye96051f2017-12-12 17:42:17979
Evan Stade196ec042018-03-13 19:44:36980 // Destroys the MessageCenter singleton, so must happen late.
981 message_center_controller_.reset();
982
Sam McNallya853cd82017-08-30 01:55:10983 local_state_.reset();
skyb073203a2017-03-13 16:59:16984 shell_delegate_.reset();
sky88bd4be62016-06-09 17:34:41985
Scott Violet17a61722017-06-19 17:54:31986 for (auto& observer : shell_observers_)
987 observer.OnShellDestroyed();
988
[email protected]b6ba05d902013-10-04 21:38:45989 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18990 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45991}
992
Scott Violetae4c25d2018-06-19 15:50:15993void Shell::Init(
994 ui::ContextFactory* context_factory,
995 ui::ContextFactoryPrivate* context_factory_private,
996 std::unique_ptr<base::Value> initial_display_prefs,
Scott Violet7e33efc2018-08-29 22:30:15997 std::unique_ptr<ws::GpuInterfaceProvider> gpu_interface_provider) {
Scott Violetac410622018-08-11 18:33:22998 if (::features::IsSingleProcessMash()) {
999 // In SingleProcessMash mode ScreenMus is not created, which means Ash needs
1000 // to set the WindowManagerFrameValues.
1001 views::WindowManagerFrameValues frame_values;
1002 frame_values.normal_insets = frame_values.maximized_insets =
1003 NonClientFrameController::GetPreferredClientAreaInsets();
1004 frame_values.max_title_bar_button_width =
1005 NonClientFrameController::GetMaxTitleBarButtonWidth();
1006 views::WindowManagerFrameValues::SetInstance(frame_values);
1007 }
1008
Evan Stade196ec042018-03-13 19:44:361009 // This creates the MessageCenter object which is used by some other objects
1010 // initialized here, so it needs to come early.
1011 message_center_controller_ = std::make_unique<MessageCenterController>();
1012
James Cookbd0b7792017-11-17 03:24:261013 // These controllers call Shell::Get() in their constructors, so they cannot
1014 // be in the member initialization list.
Qiang Xuf1400a362017-09-14 02:28:301015 touch_devices_controller_ = std::make_unique<TouchDevicesController>();
Mitsuru Oshima04b54d02017-10-09 14:22:451016 bluetooth_power_controller_ = std::make_unique<BluetoothPowerController>();
Toni Barzicd6238312018-03-02 18:26:131017 detachable_base_handler_ = std::make_unique<DetachableBaseHandler>(this);
Toni Barzic550419f2018-03-08 03:56:211018 detachable_base_notification_controller_ =
1019 std::make_unique<DetachableBaseNotificationController>(
1020 detachable_base_handler_.get());
Tetsui Ohkubo01421b32018-05-30 16:54:591021 display_speaker_controller_ = std::make_unique<DisplaySpeakerController>();
Qiang Xud8e897e2018-05-24 20:07:571022 policy_recommendation_restorer_ =
1023 std::make_unique<PolicyRecommendationRestorer>();
Tetsui Ohkubo54d50222018-05-10 01:58:111024 screen_switch_check_controller_ =
1025 std::make_unique<ScreenSwitchCheckController>();
Kyle Horimoto9fc84fc22018-04-27 19:45:151026 // Connector can be null in tests.
Scott Violete5c79f52018-07-31 00:10:171027 if (connector_ && base::FeatureList::IsEnabled(
1028 chromeos::features::kEnableUnifiedMultiDeviceSetup)) {
Kyle Horimoto9fc84fc22018-04-27 19:45:151029 multidevice_notification_presenter_ =
1030 std::make_unique<MultiDeviceNotificationPresenter>(
Scott Violete5c79f52018-07-31 00:10:171031 message_center::MessageCenter::Get(), connector_);
Kyle Horimoto9fc84fc22018-04-27 19:45:151032 }
Sonny Sasaka55f69fc2017-08-28 21:29:371033
James Cook8532dbc2017-07-31 21:54:511034 // Connector can be null in tests.
Scott Violete5c79f52018-07-31 00:10:171035 if (connector_) {
James Cook8532dbc2017-07-31 21:54:511036 // Connect to local state prefs now, but wait for an active user before
1037 // connecting to the profile pref service. The login screen has a temporary
1038 // user profile that is not associated with a real user.
Taiju Tsuiki36c517d2017-05-18 06:45:431039 auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
Steven Bennettsca108512018-05-02 11:05:031040 RegisterLocalStatePrefs(pref_registry.get(), false);
tibellb93c729b2017-03-30 00:45:091041 prefs::ConnectToPrefService(
Scott Violete5c79f52018-07-31 00:10:171042 connector_, std::move(pref_registry),
Sam McNallye36abbc2017-07-20 01:04:281043 base::Bind(&Shell::OnLocalStatePrefServiceInitialized,
1044 weak_factory_.GetWeakPtr()),
1045 prefs::mojom::kLocalStateServiceName);
jonrossc4ba10602017-04-07 20:51:051046 }
skyb073203a2017-03-13 16:59:161047
David Tseng562a9c12018-07-18 03:35:051048 tablet_mode_controller_ = std::make_unique<TabletModeController>();
1049
Qiang Xua9591002018-03-15 22:29:311050 accessibility_focus_ring_controller_ =
1051 std::make_unique<AccessibilityFocusRingController>();
skyb073203a2017-03-13 16:59:161052 accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate());
James Cookaa6aaad2018-08-24 01:00:061053 accessibility_controller_ = std::make_unique<AccessibilityController>();
Mitsuru Oshima04b54d02017-10-09 14:22:451054 toast_manager_ = std::make_unique<ToastManager>();
sky07a24d42017-03-09 23:57:301055
sky07a24d42017-03-09 23:57:301056 // Install the custom factory early on so that views::FocusManagers for Tray,
1057 // Shelf, and WallPaper could be created by the factory.
1058 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
1059
Mitsuru Oshima04b54d02017-10-09 14:22:451060 wallpaper_controller_ = std::make_unique<WallpaperController>();
sky07a24d42017-03-09 23:57:301061
Scott Violet97a7b9d2018-08-06 22:31:131062 immersive_handler_factory_ = std::make_unique<ImmersiveHandlerFactoryAsh>();
skyb7b54092016-08-19 16:00:091063
Mitsuru Oshima04b54d02017-10-09 14:22:451064 window_positioner_ = std::make_unique<WindowPositioner>();
sky984c1892016-04-20 00:00:341065
James Cook79e1ed62018-09-07 15:40:421066 native_cursor_manager_ = new NativeCursorManagerAsh;
James Cook698fc3662018-07-27 16:05:011067 cursor_manager_ =
1068 std::make_unique<CursorManager>(base::WrapUnique(native_cursor_manager_));
skyfee520c2016-02-11 19:57:461069
Steven Bennettsca108512018-05-02 11:05:031070 // In CLASSIC mode, |initial_display_prefs| contains the synchronously
1071 // loaded display pref values. Otherwise |initial_display_prefs| is null and
1072 // the pref values will be loaded once |local_state_| is available. (Any store
1073 // requests in the meanwhile will be queued).
1074 display_prefs_ =
1075 std::make_unique<DisplayPrefs>(std::move(initial_display_prefs));
1076
Steven Bennetts7683e342018-01-02 21:29:521077 InitializeDisplayManager();
[email protected]b6ba05d902013-10-04 21:38:451078
James Cook602164e2018-08-07 20:39:421079 // This will initialize aura::Env which requires |display_manager_| to
1080 // be initialized first.
1081 if (context_factory)
Scott Violetac410622018-08-11 18:33:221082 aura_env_->set_context_factory(context_factory);
1083 if (context_factory_private)
1084 aura_env_->set_context_factory_private(context_factory_private);
[email protected]ecca62b2013-10-09 16:18:531085
Ahmed Fakhry46357342018-04-27 00:46:111086 // Night Light depends on the display manager, the display color manager, and
1087 // aura::Env, so initialize it after all have been initialized.
Ahmed Fakhryb9ace242018-06-06 18:49:311088 if (features::IsNightLightEnabled())
Ahmed Fakhry46357342018-04-27 00:46:111089 night_light_controller_ = std::make_unique<NightLightController>();
1090
[email protected]b6ba05d902013-10-04 21:38:451091 // The WindowModalityController needs to be at the front of the input event
1092 // pretarget handler list to ensure that it processes input events when modal
1093 // windows are active.
Scott Violetac410622018-08-11 18:33:221094 window_modality_controller_ =
1095 std::make_unique<::wm::WindowModalityController>(this, aura_env_);
[email protected]b6ba05d902013-10-04 21:38:451096
Mike Wassermanefbf3402018-04-26 00:41:321097 event_rewriter_controller_ = std::make_unique<EventRewriterController>();
1098
Scott Violetac410622018-08-11 18:33:221099 env_filter_ = std::make_unique<::wm::CompoundEventFilter>();
[email protected]b6ba05d902013-10-04 21:38:451100 AddPreTargetHandler(env_filter_.get());
1101
sky27344382017-03-08 21:30:321102 // FocusController takes ownership of AshFocusRules.
1103 focus_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451104 std::make_unique<::wm::FocusController>(new wm::AshFocusRules());
sky27344382017-03-08 21:30:321105 focus_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:451106
[email protected]093b8d642014-04-03 20:59:281107 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:451108
Scott Violet596bb46342017-06-21 14:43:131109 window_tree_host_manager_->Start();
1110 AshWindowTreeHostInitParams ash_init_params;
1111 window_tree_host_manager_->CreatePrimaryHost(ash_init_params);
1112
Scott Violet3c554ae2017-12-13 02:25:411113 time_to_first_present_recorder_ =
1114 std::make_unique<TimeToFirstPresentRecorder>(GetPrimaryRootWindow());
1115
James Cook40f7d752018-05-25 18:21:581116 shell_state_->SetRootWindowForNewWindows(GetPrimaryRootWindow());
[email protected]b6ba05d902013-10-04 21:38:451117
Scott Violet596bb46342017-06-21 14:43:131118 resolution_notification_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451119 std::make_unique<ResolutionNotificationController>();
[email protected]b6ba05d902013-10-04 21:38:451120
James Cook698fc3662018-07-27 16:05:011121 cursor_manager_->SetDisplay(
1122 display::Screen::GetScreen()->GetPrimaryDisplay());
[email protected]b6ba05d902013-10-04 21:38:451123
James Cookdafb54f2018-09-14 16:36:151124 accelerator_controller_ = std::make_unique<AcceleratorController>();
Xiaohui Chend68ffc12018-08-16 01:56:411125 voice_interaction_controller_ =
1126 std::make_unique<VoiceInteractionController>();
Weidong Guo268c7992018-04-13 21:06:071127
Scott Violete5c3f5b2018-08-22 21:56:451128 window_service_owner_ =
1129 std::make_unique<WindowServiceOwner>(std::move(gpu_interface_provider));
1130
Weidong Guo268c7992018-04-13 21:06:071131 // |app_list_controller_| is put after |tablet_mode_controller_| as the former
1132 // uses the latter in constructor.
Scott Violete5c3f5b2018-08-22 21:56:451133 app_list_controller_ = std::make_unique<AppListControllerImpl>(
1134 window_service_owner_->window_service());
Mitsuru Oshima04b54d02017-10-09 14:22:451135 shelf_controller_ = std::make_unique<ShelfController>();
[email protected]b6ba05d902013-10-04 21:38:451136
spange9b51272014-12-11 01:20:101137 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:061138 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
spange9b51272014-12-11 01:20:101139 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:061140 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:391141
[email protected]b6ba05d902013-10-04 21:38:451142 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:451143
derat2d4e62d2015-01-09 16:09:171144 // ui::UserActivityDetector passes events to observers, so let them get
Michael Wasserman07466432018-04-11 03:56:481145 // rewritten first.
1146 user_activity_detector_.reset(new ui::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:451147
[email protected]093b8d642014-04-03 20:59:281148 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:451149 AddPreTargetHandler(overlay_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:451150
[email protected]60d677d2014-05-30 13:07:021151 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
Scott Violetf5db2502018-10-05 15:19:391152 std::make_unique<PreTargetAcceleratorHandler>(),
sky81a2d792017-03-17 19:14:391153 accelerator_controller_->accelerator_history()));
[email protected]b6ba05d902013-10-04 21:38:451154 AddPreTargetHandler(accelerator_filter_.get());
1155
[email protected]093b8d642014-04-03 20:59:281156 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:451157 AddPreTargetHandler(event_transformation_handler_.get());
1158
sky11cf8db92017-04-10 23:38:081159 toplevel_window_event_handler_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451160 std::make_unique<ToplevelWindowEventHandler>();
[email protected]3537d472014-01-15 05:45:311161
Ryan Cuieb5b84e32018-07-19 01:36:021162 system_gesture_filter_ = std::make_unique<SystemGestureEventFilter>();
1163 AddPreTargetHandler(system_gesture_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:451164
[email protected]354520b2014-06-21 04:31:011165 sticky_keys_controller_.reset(new StickyKeysController);
Mitsuru Oshima04b54d02017-10-09 14:22:451166 screen_pinning_controller_ = std::make_unique<ScreenPinningController>();
[email protected]354520b2014-06-21 04:31:011167
Qiang Xu36234e532018-04-11 04:54:021168 power_prefs_ = std::make_unique<PowerPrefs>(
1169 chromeos::PowerPolicyController::Get(),
1170 chromeos::DBusThreadManager::Get()->GetPowerManagerClient());
1171
Toni Barzic9d0c82f42017-12-06 00:53:521172 backlights_forced_off_setter_ = std::make_unique<BacklightsForcedOffSetter>();
1173
Toni Barzic85ae39e2017-12-07 05:50:181174 tray_action_ =
1175 std::make_unique<TrayAction>(backlights_forced_off_setter_.get());
1176
jamescookd9f152f2016-11-15 00:53:081177 lock_state_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451178 std::make_unique<LockStateController>(shutdown_controller_.get());
Toni Barzic9d0c82f42017-12-06 00:53:521179 power_button_controller_ = std::make_unique<PowerButtonController>(
1180 backlights_forced_off_setter_.get());
[email protected]685442f32014-02-28 10:40:061181 // Pass the initial display state to PowerButtonController.
1182 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:091183 display_configurator_->cached_displays());
jamescook01bf23e72017-01-09 19:58:151184
James Cook93614f02018-07-11 21:37:351185 drag_drop_controller_ = std::make_unique<DragDropController>();
Scott Violet361833fb2017-06-21 22:25:201186
oshima5a296e82016-04-29 01:32:271187 // |screenshot_controller_| needs to be created (and prepended as a
mukai19274bdd2015-02-24 22:37:481188 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
oshima5a296e82016-04-29 01:32:271189 // process mouse events prior to screenshot session.
mukai19274bdd2015-02-24 22:37:481190 // See http://crbug.com/459214
James Cook5e9d3402017-11-01 00:20:121191 screenshot_controller_ = std::make_unique<ScreenshotController>(
1192 shell_delegate_->CreateScreenshotDelegate());
Mitsuru Oshima04b54d02017-10-09 14:22:451193 mouse_cursor_filter_ = std::make_unique<MouseCursorEventFilter>();
Katie Db68a5522018-03-30 18:47:361194 AddPreTargetHandler(mouse_cursor_filter_.get(),
1195 ui::EventTarget::Priority::kAccessibility);
[email protected]b6ba05d902013-10-04 21:38:451196
1197 // Create Controllers that may need root window.
1198 // TODO(oshima): Move as many controllers before creating
1199 // RootWindowController as possible.
1200 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:451201
sammiequon203ae022016-09-18 17:23:421202 laser_pointer_controller_.reset(new LaserPointerController());
1203 partial_magnification_controller_.reset(new PartialMagnificationController());
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:321204 highlighter_controller_.reset(new HighlighterController());
sammiequon203ae022016-09-18 17:23:421205
Qiang Xu2657abf2018-03-21 18:01:451206 magnification_controller_ = std::make_unique<MagnificationController>();
Mitsuru Oshima04b54d02017-10-09 14:22:451207 mru_window_tracker_ = std::make_unique<MruWindowTracker>();
[email protected]b6ba05d902013-10-04 21:38:451208
[email protected]55398d22013-10-10 19:49:201209 autoclick_controller_.reset(AutoclickController::CreateInstance());
1210
[email protected]b6ba05d902013-10-04 21:38:451211 high_contrast_controller_.reset(new HighContrastController);
Saman Sami3fb310d2017-11-09 16:51:541212
Ahmed Fakhry4af48e42018-02-28 17:45:381213 if (features::IsDockedMagnifierEnabled()) {
Ahmed Fakhry4bf3f742018-02-06 17:33:361214 docked_magnifier_controller_ =
1215 std::make_unique<DockedMagnifierController>();
1216 }
1217
Saman Sami3fb310d2017-11-09 16:51:541218 viz::mojom::VideoDetectorObserverPtr observer;
1219 video_detector_ =
1220 std::make_unique<VideoDetector>(mojo::MakeRequest(&observer));
Scott Violetac410622018-08-11 18:33:221221 aura_env_->context_factory_private()
James Cook602164e2018-08-07 20:39:421222 ->GetHostFrameSinkManager()
1223 ->AddVideoDetectorObserver(std::move(observer));
[email protected]b6ba05d902013-10-04 21:38:451224
oshimaebbe63772015-02-19 18:41:321225 tooltip_controller_.reset(new views::corewm::TooltipController(
dchenga94547472016-04-08 08:41:111226 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451227 AddPreTargetHandler(tooltip_controller_.get());
1228
hariank0dd03dd2016-07-14 23:47:331229 modality_filter_.reset(new SystemModalContainerEventFilter(this));
1230 AddPreTargetHandler(modality_filter_.get());
1231
[email protected]093b8d642014-04-03 20:59:281232 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451233
skyabcae812017-01-18 17:01:341234 // Must occur after Shell has installed its early pre-target handlers (for
1235 // example, WindowModalityController).
James Cook31bb3252018-08-08 20:06:441236 pointer_watcher_adapter_ = std::make_unique<PointerWatcherAdapter>();
[email protected]b6ba05d902013-10-04 21:38:451237
[email protected]093b8d642014-04-03 20:59:281238 resize_shadow_controller_.reset(new ResizeShadowController());
Scott Violetac410622018-08-11 18:33:221239 shadow_controller_ = std::make_unique<::wm::ShadowController>(
1240 focus_controller_.get(), std::make_unique<WmShadowControllerDelegate>(),
1241 aura_env_);
[email protected]b6ba05d902013-10-04 21:38:451242
James Cookb50959e22017-08-10 20:24:381243 logout_confirmation_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451244 std::make_unique<LogoutConfirmationController>();
[email protected]b6ba05d902013-10-04 21:38:451245
jamescookac6724332017-03-21 02:54:431246 // May trigger initialization of the Bluetooth adapter.
1247 tray_bluetooth_helper_->Initialize();
1248
kylechar55f0eaf22017-01-11 22:57:371249 // Create AshTouchTransformController before
oshimae2818922015-07-28 01:18:521250 // WindowTreeHostManager::InitDisplays()
kylechar55f0eaf22017-01-11 22:57:371251 // since AshTouchTransformController listens on
oshimae2818922015-07-28 01:18:521252 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
Mitsuru Oshima04b54d02017-10-09 14:22:451253 touch_transformer_controller_ = std::make_unique<AshTouchTransformController>(
Scott Violet596bb46342017-06-21 14:43:131254 display_configurator_.get(), display_manager_.get(),
James Cook9db56d72018-08-01 03:21:311255 std::make_unique<display::DefaultTouchTransformSetter>());
[email protected]03122891a2014-05-13 23:56:491256
Tetsui Ohkubo269b5792018-04-26 01:06:321257 // |system_tray_model_| should be available before
1258 // |system_notification_controller_| is initialized and Shelf is created by
1259 // WindowTreeHostManager::InitHosts.
1260 system_tray_model_ = std::make_unique<SystemTrayModel>();
1261 system_notification_controller_ =
1262 std::make_unique<SystemNotificationController>();
1263
Scott Violet596bb46342017-06-21 14:43:131264 window_tree_host_manager_->InitHosts();
[email protected]b6ba05d902013-10-04 21:38:451265
Meilin Wang3a4ac8e2018-09-27 19:03:431266 // |assistant_controller_| needs to be created after InitHosts() since its
1267 // keyboard observer function result has dependency on workspace change.
1268 assistant_controller_ = chromeos::switches::IsAssistantEnabled()
1269 ? std::make_unique<AssistantController>()
1270 : nullptr;
1271
rsadam9172bc8a2014-10-29 23:37:381272 // Needs to be created after InitDisplays() since it may cause the virtual
1273 // keyboard to be deployed.
James Cook602164e2018-08-07 20:39:421274 virtual_keyboard_controller_ = std::make_unique<VirtualKeyboardController>();
rsadam9172bc8a2014-10-29 23:37:381275
James Cook698fc3662018-07-27 16:05:011276 cursor_manager_->HideCursor(); // Hide the mouse cursor on startup.
1277 cursor_manager_->SetCursor(ui::CursorType::kPointer);
[email protected]b6ba05d902013-10-04 21:38:451278
Mitsuru Oshima04b54d02017-10-09 14:22:451279 peripheral_battery_notifier_ = std::make_unique<PeripheralBatteryNotifier>();
[email protected]093b8d642014-04-03 20:59:281280 power_event_observer_.reset(new PowerEventObserver());
Sarah Hu8ce89c332018-09-24 18:23:141281 user_activity_notifier_ =
1282 std::make_unique<ui::UserActivityPowerManagerNotifier>(
1283 user_activity_detector_.get(), connector_);
[email protected]ded58fd2013-10-09 07:56:551284 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281285 new VideoActivityNotifier(video_detector_.get()));
1286 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
Scott Violet596bb46342017-06-21 14:43:131287 screen_orientation_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451288 std::make_unique<ScreenOrientationController>();
Scott Violet596bb46342017-06-21 14:43:131289 screen_layout_observer_.reset(new ScreenLayoutObserver());
yiyix90cfee22017-02-16 05:38:181290 sms_observer_.reset(new SmsObserver());
jamescook01bf23e72017-01-09 19:58:151291
xdaid4913762017-07-06 00:17:221292 split_view_controller_.reset(new SplitViewController());
1293
David Tseng6792dc82018-05-04 19:18:411294 key_accessibility_enabler_ = std::make_unique<KeyAccessibilityEnabler>();
1295
[email protected]b6ba05d902013-10-04 21:38:451296 // The compositor thread and main message loop have to be running in
1297 // order to create mirror window. Run it after the main message loop
1298 // is started.
Scott Violet596bb46342017-06-21 14:43:131299 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031300
Scott Violete5c79f52018-07-31 00:10:171301 // |connector_| is null in unit tests.
Scott Violete5c79f52018-07-31 00:10:171302 if (connector_ &&
James Cook08ebee42018-08-07 04:06:421303 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowTaps)) {
1304 // The show taps feature is a separate mojo app.
1305 // TODO(jamescook): Make this work in ash_shell_with_content.
Scott Violete5c79f52018-07-31 00:10:171306 connector_->StartService(tap_visualizer::mojom::kServiceName);
James Cook0ba192bf2017-12-01 20:53:111307 }
1308
James Cook7e6a7ae2018-08-24 23:00:471309 if (!::features::IsMultiProcessMash()) {
James Cookc9d6a542018-07-27 21:00:561310 ime_focus_handler_ = std::make_unique<ImeFocusHandler>(
1311 focus_controller(), window_tree_host_manager_->input_method());
Scott Violetb7f4df22018-05-17 04:43:121312 }
1313
sky00c813f2017-03-08 22:48:551314 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:181315 observer.OnShellInitialized();
phweiss0bf64c52015-11-17 12:56:181316
Scott Violet41562d1c2017-06-26 15:15:481317 user_metrics_recorder_->OnShellInitialized();
Toni Barzic85c9e0802018-03-30 02:46:011318
Jeffrey Kardatzkef108f022018-04-17 17:52:351319 // Initialize the D-Bus thread and services for ash.
1320 ash_dbus_services_ = std::make_unique<AshDBusServices>();
Toni Barzic85c9e0802018-03-30 02:46:011321 // By this point ash shell should have initialized its D-Bus signal
1322 // listeners, so emit ash-initialized upstart signal to start Chrome OS tasks
1323 // that expect that ash is listening to D-Bus signals they emit. For example,
1324 // hammerd, which handles detachable base state, communicates the base state
1325 // purely by emitting D-Bus signals, and thus has to be run whenever ash is
1326 // started so ash (DetachableBaseHandler in particular) gets the proper view
1327 // of the current detachable base state.
Jeffrey Kardatzkef108f022018-04-17 17:52:351328 // TODO(stevenjb): Move this and other D-Bus dependencies to AshDBusServices.
1329 ash_dbus_services_->EmitAshInitialized();
[email protected]b6ba05d902013-10-04 21:38:451330}
1331
Steven Bennetts7683e342018-01-02 21:29:521332void Shell::InitializeDisplayManager() {
Steven Bennetts7683e342018-01-02 21:29:521333 bool display_initialized = display_manager_->InitFromCommandLine();
1334
Steven Bennetts7683e342018-01-02 21:29:521335 display_configuration_controller_ =
1336 std::make_unique<DisplayConfigurationController>(
1337 display_manager_.get(), window_tree_host_manager_.get());
James Cook9db56d72018-08-01 03:21:311338 display_configurator_->Init(
1339 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(), false);
Steven Bennetts9b21fa32018-04-13 23:45:551340 display_configuration_observer_ =
1341 std::make_unique<DisplayConfigurationObserver>();
1342
Steven Bennetts2a9b4382018-04-26 23:41:191343 cros_display_config_ = std::make_unique<CrosDisplayConfig>();
1344
Qiang Xud77a90c2018-02-20 19:43:291345 persistent_window_controller_ =
1346 std::make_unique<PersistentWindowController>();
Steven Bennetts7683e342018-01-02 21:29:521347
1348 projecting_observer_ =
1349 std::make_unique<ProjectingObserver>(display_configurator_.get());
1350
1351 if (!display_initialized) {
Scott Violet97a7b9d2018-08-06 22:31:131352 if (chromeos::IsRunningAsSystemCompositor()) {
Steven Bennetts7683e342018-01-02 21:29:521353 display_change_observer_ =
1354 std::make_unique<display::DisplayChangeObserver>(
1355 display_configurator_.get(), display_manager_.get());
1356
1357 display_shutdown_observer_ = std::make_unique<DisplayShutdownObserver>(
1358 display_configurator_.get());
1359
1360 // Register |display_change_observer_| first so that the rest of
1361 // observer gets invoked after the root windows are configured.
1362 display_configurator_->AddObserver(display_change_observer_.get());
1363 display_error_observer_.reset(new DisplayErrorObserver());
1364 display_configurator_->AddObserver(display_error_observer_.get());
1365 display_configurator_->set_state_controller(
1366 display_change_observer_.get());
1367 display_configurator_->set_mirroring_controller(display_manager_.get());
1368 display_configurator_->ForceInitialConfigure();
1369 display_initialized = true;
1370 }
1371 }
1372
Ahmed Fakhry1ad4bd42018-04-18 19:31:371373 display_color_manager_ = std::make_unique<DisplayColorManager>(
1374 display_configurator_.get(), display::Screen::GetScreen());
Steven Bennetts7683e342018-01-02 21:29:521375
1376 if (!display_initialized)
1377 display_manager_->InitDefaultDisplay();
1378
Scott Violet97a7b9d2018-08-06 22:31:131379 display_manager_->RefreshFontParams();
Steven Bennetts7683e342018-01-02 21:29:521380}
1381
[email protected]41baaed2013-11-09 04:18:261382void Shell::InitRootWindow(aura::Window* root_window) {
sky27344382017-03-08 21:30:321383 DCHECK(focus_controller_);
[email protected]d90b8392012-06-13 09:34:561384 DCHECK(visibility_controller_.get());
[email protected]d90b8392012-06-13 09:34:561385
sky27344382017-03-08 21:30:321386 aura::client::SetFocusClient(root_window, focus_controller_.get());
Thiago Farina3b086a02017-05-30 22:32:501387 ::wm::SetActivationClient(root_window, focus_controller_.get());
sky27344382017-03-08 21:30:321388 root_window->AddPreTargetHandler(focus_controller_.get());
[email protected]d90b8392012-06-13 09:34:561389 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
James Cook93614f02018-07-11 21:37:351390 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]8d625fb2012-07-18 16:40:061391 aura::client::SetScreenPositionClient(root_window,
1392 screen_position_controller_.get());
sadrul7a8785e2016-02-12 21:54:351393 aura::client::SetCursorClient(root_window, cursor_manager_.get());
Thiago Farina3b086a02017-05-30 22:32:501394 ::wm::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381395 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561396
Thiago Farina3b086a02017-05-30 22:32:501397 ::wm::SetWindowMoveClient(root_window, toplevel_window_event_handler_.get());
[email protected]3537d472014-01-15 05:45:311398 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1399 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
[email protected]d90b8392012-06-13 09:34:561400}
1401
skyabcae812017-01-18 17:01:341402void Shell::CloseAllRootWindowChildWindows() {
msw257a6a232017-06-01 01:46:301403 for (aura::Window* root : GetAllRootWindows()) {
1404 RootWindowController* controller = RootWindowController::ForWindow(root);
skyabcae812017-01-18 17:01:341405 if (controller) {
1406 controller->CloseChildWindows();
1407 } else {
msw257a6a232017-06-01 01:46:301408 while (!root->children().empty()) {
1409 aura::Window* child = root->children()[0];
skyabcae812017-01-18 17:01:341410 delete child;
1411 }
1412 }
1413 }
1414}
1415
[email protected]c0ce80e2012-10-05 23:28:271416bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1417 RootWindowControllerList controllers = GetAllRootWindowControllers();
oshima9a61ecf2016-06-18 10:43:051418 for (RootWindowController* controller : controllers) {
1419 if (controller->CanWindowReceiveEvents(window))
[email protected]602022b2014-03-31 17:07:311420 return true;
[email protected]c0ce80e2012-10-05 23:28:271421 }
1422 return false;
1423}
1424
[email protected]049cf34b2012-12-07 17:15:481425////////////////////////////////////////////////////////////////////////////////
1426// Shell, ui::EventTarget overrides:
1427
[email protected]869f6352012-12-06 20:47:171428bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411429 return true;
1430}
1431
1432ui::EventTarget* Shell::GetParentTarget() {
Scott Violetac410622018-08-11 18:33:221433 return aura_env_;
[email protected]5097e692012-10-30 22:08:411434}
1435
dchenga94547472016-04-08 08:41:111436std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1437 return std::unique_ptr<ui::EventTargetIterator>();
[email protected]3e670aa2013-12-02 19:04:321438}
1439
1440ui::EventTargeter* Shell::GetEventTargeter() {
1441 NOTREACHED();
achuith287b26e2015-09-03 17:49:181442 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321443}
1444
sky27344382017-03-08 21:30:321445void Shell::OnWindowActivated(
Thiago Farina3b086a02017-05-30 22:32:501446 ::wm::ActivationChangeObserver::ActivationReason reason,
sky27344382017-03-08 21:30:321447 aura::Window* gained_active,
1448 aura::Window* lost_active) {
James Cook40f7d752018-05-25 18:21:581449 if (!gained_active)
1450 return;
1451
1452 shell_state_->SetRootWindowForNewWindows(gained_active->GetRootWindow());
sky27344382017-03-08 21:30:321453}
1454
Steven Bennettsbadc3092018-05-24 21:26:011455void Shell::OnFirstSessionStarted() {
1456 // Enable magnifier scroll keys as there may be no mouse cursor in kiosk mode.
1457 MagnifierKeyScroller::SetEnabled(session_controller_->IsRunningInAppMode());
1458
1459 // Enable long press action to toggle spoken feedback with hotrod remote
1460 // which can't handle shortcuts.
1461 SpokenFeedbackToggler::SetEnabled(session_controller_->IsRunningInAppMode());
1462}
1463
Xiyuan Xiab64fd0a2017-04-13 17:53:141464void Shell::OnSessionStateChanged(session_manager::SessionState state) {
James Cookeb426b52018-09-17 16:45:121465 const bool is_session_active = state == session_manager::SessionState::ACTIVE;
Aga Wronskae195ad22017-12-20 01:38:111466 // Initialize the |shelf_window_watcher_| when a session becomes active.
1467 // Shelf itself is initialized in RootWindowController.
James Cookeb426b52018-09-17 16:45:121468 if (is_session_active && !shelf_window_watcher_)
1469 shelf_window_watcher_ = std::make_unique<ShelfWindowWatcher>(shelf_model());
1470
1471 // Disable drag-and-drop during OOBE and GAIA login screens by only enabling
1472 // the controller when the session is active. https://crbug.com/464118
1473 drag_drop_controller_->set_enabled(is_session_active);
Steven Bennetts43b3c212018-01-08 16:39:581474
Steven Bennetts9fd12ad2017-11-09 23:36:271475 // NOTE: keyboard::IsKeyboardEnabled() is false in mash, but may not be in
1476 // unit tests. crbug.com/646565.
Steven Bennetts43b3c212018-01-08 16:39:581477 if (keyboard::IsKeyboardEnabled()) {
1478 switch (state) {
1479 case session_manager::SessionState::OOBE:
1480 case session_manager::SessionState::LOGIN_PRIMARY:
1481 // Ensure that the keyboard controller is activated for the primary
1482 // window.
1483 GetPrimaryRootWindowController()->ActivateKeyboard(
Darren Shenf62db77a2018-06-07 06:22:441484 keyboard_controller_.get());
Steven Bennetts43b3c212018-01-08 16:39:581485 break;
1486 case session_manager::SessionState::LOGGED_IN_NOT_ACTIVE:
1487 case session_manager::SessionState::ACTIVE:
Darren Shen0219ebe2018-04-29 22:52:541488 // Reload the keyboard on user profile change to refresh keyboard
Steven Bennetts43b3c212018-01-08 16:39:581489 // extensions with the new profile and ensure the extensions call the
1490 // proper IME. |LOGGED_IN_NOT_ACTIVE| is needed so that the virtual
1491 // keyboard works on supervised user creation, http://crbug.com/712873.
1492 // |ACTIVE| is also needed for guest user workflow.
Darren Shenf62db77a2018-06-07 06:22:441493 EnableKeyboard();
Steven Bennetts43b3c212018-01-08 16:39:581494 break;
1495 default:
1496 break;
1497 }
sky5ad143a2017-03-22 04:31:231498 }
xiyuan233f4e72017-04-06 06:59:561499}
sky5ad143a2017-03-22 04:31:231500
Xiyuan Xiab64fd0a2017-04-13 17:53:141501void Shell::OnLoginStatusChanged(LoginStatus login_status) {
xiyuan233f4e72017-04-06 06:59:561502 UpdateAfterLoginStatusChange(login_status);
sky5ad143a2017-03-22 04:31:231503}
1504
Xiyuan Xiab64fd0a2017-04-13 17:53:141505void Shell::OnLockStateChanged(bool locked) {
xiyuan7ebbf7f2017-04-10 16:49:101506#ifndef NDEBUG
1507 // Make sure that there is no system modal in Lock layer when unlocked.
1508 if (!locked) {
1509 aura::Window::Windows containers = wm::GetContainersFromAllRootWindows(
1510 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
1511 for (aura::Window* container : containers)
1512 DCHECK(container->children().empty());
1513 }
1514#endif
1515}
1516
Sam McNallye36abbc2017-07-20 01:04:281517void Shell::OnLocalStatePrefServiceInitialized(
1518 std::unique_ptr<::PrefService> pref_service) {
Sam McNallya853cd82017-08-30 01:55:101519 DCHECK(!local_state_);
James Cook8532dbc2017-07-31 21:54:511520 // |pref_service| is null if can't connect to Chrome (as happens when
Scott Violet8ff9c302018-02-22 22:28:351521 // running mash outside of chrome --enable-features=Mash and chrome isn't
1522 // built).
Sam McNallya853cd82017-08-30 01:55:101523 if (!pref_service)
1524 return;
1525
1526 local_state_ = std::move(pref_service);
James Cookbbe5cb12017-08-08 18:32:211527
1528 for (auto& observer : shell_observers_)
Sam McNallya853cd82017-08-30 01:55:101529 observer.OnLocalStatePrefServiceInitialized(local_state_.get());
Sam McNallye36abbc2017-07-20 01:04:281530}
1531
[email protected]55f593352011-12-24 05:42:461532} // namespace ash