blob: f2698ab6465cb1fa7e73b7cb354c1f368debd777 [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"
Steven Bennetts368a1c82019-01-11 20:45:2217#include "ash/accelerometer/accelerometer_reader.h"
James Cookec144952017-09-01 00:05:1618#include "ash/accessibility/accessibility_controller.h"
James Cook37b7d102017-10-06 04:35:1919#include "ash/accessibility/accessibility_delegate.h"
Qiang Xua9591002018-03-15 22:29:3120#include "ash/accessibility/accessibility_focus_ring_controller.h"
David Tseng6792dc82018-05-04 19:18:4121#include "ash/accessibility/key_accessibility_enabler.h"
Jiaquan He4b48f912018-03-01 03:59:3922#include "ash/app_list/app_list_controller_impl.h"
David Black00fdce32018-05-10 20:59:1423#include "ash/assistant/assistant_controller.h"
[email protected]55398d22013-10-10 19:49:2024#include "ash/autoclick/autoclick_controller.h"
James Cookb0bf8e82017-04-09 17:01:4425#include "ash/cast_config_controller.h"
James Cook1d323b32019-01-02 19:42:2926#include "ash/components/tap_visualizer/public/mojom/tap_visualizer.mojom.h"
Quan Nguyenaf67b64d2018-11-29 19:21:4827#include "ash/contained_shell/contained_shell_controller.h"
Jeffrey Kardatzkef108f022018-04-17 17:52:3528#include "ash/dbus/ash_dbus_services.h"
Toni Barzicd6238312018-03-02 18:26:1329#include "ash/detachable_base/detachable_base_handler.h"
Toni Barzic550419f2018-03-08 03:56:2130#include "ash/detachable_base/detachable_base_notification_controller.h"
Scott Violetd64dac12017-06-02 21:50:0831#include "ash/display/ash_display_controller.h"
Steven Bennetts2a9b4382018-04-26 23:41:1932#include "ash/display/cros_display_config.h"
[email protected]87ec2202014-02-06 06:24:2733#include "ash/display/cursor_window_controller.h"
Mitsuru Oshimaf51c8b42018-03-17 01:41:3234#include "ash/display/display_color_manager.h"
stevenjb537c5c3f2016-01-20 23:38:1235#include "ash/display/display_configuration_controller.h"
Steven Bennetts9b21fa32018-04-13 23:45:5536#include "ash/display/display_configuration_observer.h"
Mitsuru Oshimaf51c8b42018-03-17 01:41:3237#include "ash/display/display_error_observer.h"
Scott Violetbed23cb2018-08-22 19:56:1238#include "ash/display/display_output_protection.h"
Steven Bennetts3688c6032018-04-13 01:14:2339#include "ash/display/display_prefs.h"
Steven Bennetts7683e342018-01-02 21:29:5240#include "ash/display/display_shutdown_observer.h"
[email protected]682990f2013-01-10 06:49:1141#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2742#include "ash/display/mouse_cursor_event_filter.h"
Qiang Xud77a90c2018-02-20 19:43:2943#include "ash/display/persistent_window_controller.h"
Mitsuru Oshimaf51c8b42018-03-17 01:41:3244#include "ash/display/projecting_observer.h"
jamescook01bf23e72017-01-09 19:58:1545#include "ash/display/resolution_notification_controller.h"
rjkroege2c9305402016-09-07 00:21:4546#include "ash/display/screen_ash.h"
Mitsuru Oshimaddfde3552018-03-22 09:12:1347#include "ash/display/screen_orientation_controller.h"
[email protected]8d625fb2012-07-18 16:40:0648#include "ash/display/screen_position_controller.h"
oshimae2818922015-07-28 01:18:5249#include "ash/display/window_tree_host_manager.h"
[email protected]f4c92b382012-08-28 00:59:5950#include "ash/drag_drop/drag_drop_controller.h"
Mike Wasserman5623bac22018-04-30 17:24:3251#include "ash/events/event_rewriter_controller.h"
James Cookf5398842018-04-16 20:15:2452#include "ash/first_run/first_run_helper.h"
James Cookb0bf8e82017-04-09 17:01:4453#include "ash/focus_cycler.h"
Evan Stade5f09e6572018-08-10 17:48:1554#include "ash/frame/non_client_frame_view_ash.h"
[email protected]f4c92b382012-08-28 00:59:5955#include "ash/high_contrast/high_contrast_controller.h"
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:3256#include "ash/highlighter/highlighter_controller.h"
Scott Violet596bb46342017-06-21 14:43:1357#include "ash/host/ash_window_tree_host_init_params.h"
James Cookbb026732017-06-09 23:01:5558#include "ash/ime/ime_controller.h"
Xiyuan Xia5f1046e2018-06-01 16:04:4459#include "ash/ime/ime_focus_handler.h"
Steven Bennettsa0ea30942018-10-11 22:27:5160#include "ash/keyboard/ash_keyboard_controller.h"
sammiequon203ae022016-09-18 17:23:4261#include "ash/laser/laser_pointer_controller.h"
Jacob Dufaultffd9b0d2017-11-15 23:07:1662#include "ash/login/login_screen_controller.h"
James Cookb0bf8e82017-04-09 17:01:4463#include "ash/login_status.h"
Ahmed Fakhry4bf3f742018-02-06 17:33:3664#include "ash/magnifier/docked_magnifier_controller.h"
[email protected]f4c92b382012-08-28 00:59:5965#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5466#include "ash/magnifier/partial_magnification_controller.h"
Becca Hughes446aaccf2019-01-15 04:51:1767#include "ash/media/media_controller.h"
Becca Hughesc6a0a062018-10-25 16:54:1368#include "ash/media/media_notification_controller.h"
Scott Violet3c554ae2017-12-13 02:25:4169#include "ash/metrics/time_to_first_present_recorder.h"
Kyle Horimoto9fc84fc22018-04-27 19:45:1570#include "ash/multi_device_setup/multi_device_notification_presenter.h"
James Cookb0bf8e82017-04-09 17:01:4471#include "ash/new_window_controller.h"
Vladislav Kaznacheev92edf62e2017-10-13 22:08:0172#include "ash/note_taking_controller.h"
Qiang Xud8e897e2018-05-24 20:07:5773#include "ash/policy/policy_recommendation_restorer.h"
Steven Bennetts93d3e5b12018-05-05 01:14:5074#include "ash/public/cpp/ash_constants.h"
Ahmed Fakhry4af48e42018-02-28 17:45:3875#include "ash/public/cpp/ash_features.h"
Evan Stade7d0e8232017-10-04 02:01:3676#include "ash/public/cpp/ash_switches.h"
msw109806d2017-06-02 20:11:5777#include "ash/public/cpp/shelf_model.h"
jamescook8800b8232016-10-19 12:46:2778#include "ash/public/cpp/shell_window_ids.h"
[email protected]d90b8392012-06-13 09:34:5679#include "ash/root_window_controller.h"
James Cook5e9d3402017-11-01 00:20:1280#include "ash/screenshot_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4481#include "ash/session/session_controller.h"
James Cook840177e2017-05-25 02:20:0182#include "ash/shelf/shelf.h"
James Cookb0bf8e82017-04-09 17:01:4483#include "ash/shelf/shelf_controller.h"
James Cookb0bf8e82017-04-09 17:01:4484#include "ash/shelf/shelf_window_watcher.h"
James Cookb0bf8e82017-04-09 17:01:4485#include "ash/shell_delegate.h"
[email protected]1b4c7472014-05-15 18:32:2386#include "ash/shell_init_params.h"
James Cookb0bf8e82017-04-09 17:01:4487#include "ash/shell_observer.h"
James Cook40f7d752018-05-25 18:21:5888#include "ash/shell_state.h"
James Cookb0bf8e82017-04-09 17:01:4489#include "ash/shutdown_controller.h"
jamescook01bf23e72017-01-09 19:58:1590#include "ash/sticky_keys/sticky_keys_controller.h"
Tetsui Ohkubo01421b32018-05-30 16:54:5991#include "ash/system/audio/display_speaker_controller.h"
James Cooka35a1e22017-04-08 02:33:0892#include "ash/system/bluetooth/bluetooth_notification_controller.h"
Sonny Sasaka55f69fc2017-08-28 21:29:3793#include "ash/system/bluetooth/bluetooth_power_controller.h"
Giovanni Ortuño Urquidi55aa5d8f2018-10-10 05:33:3494#include "ash/system/bluetooth/tray_bluetooth_helper_experimental.h"
95#include "ash/system/bluetooth/tray_bluetooth_helper_legacy.h"
James Cooka35a1e22017-04-08 02:33:0896#include "ash/system/brightness/brightness_controller_chromeos.h"
James Cookb0bf8e82017-04-09 17:01:4497#include "ash/system/brightness_control_delegate.h"
Tetsui Ohkubo5e2499532018-04-04 02:01:3998#include "ash/system/caps_lock_notification_controller.h"
Lann Martinb9991402017-06-23 22:25:0899#include "ash/system/keyboard_brightness/keyboard_brightness_controller.h"
James Cookb0bf8e82017-04-09 17:01:44100#include "ash/system/keyboard_brightness_control_delegate.h"
Tatsuhisa Yamaguchi440e2d2e2018-12-05 09:16:31101#include "ash/system/locale/locale_update_controller.h"
Tetsui Ohkubo8d354c32018-10-11 01:23:28102#include "ash/system/message_center/message_center_controller.h"
Tetsui Ohkubo21722932018-03-02 02:56:56103#include "ash/system/model/system_tray_model.h"
James Cooka35a1e22017-04-08 02:33:08104#include "ash/system/network/sms_observer.h"
105#include "ash/system/network/vpn_list.h"
afakhrye4fae852017-05-09 18:49:06106#include "ash/system/night_light/night_light_controller.h"
Sammie Quon4d7dba62017-08-03 23:18:17107#include "ash/system/palette/palette_tray.h"
Sammie Quon6c4e2b1f2017-10-13 16:54:18108#include "ash/system/palette/palette_welcome_bubble.h"
Toni Barzic9d0c82f42017-12-06 00:53:52109#include "ash/system/power/backlights_forced_off_setter.h"
Sammie Quon95c6a1c2017-09-12 19:16:55110#include "ash/system/power/peripheral_battery_notifier.h"
Qiang Xu0a86020f2017-10-12 08:34:54111#include "ash/system/power/power_button_controller.h"
James Cooka35a1e22017-04-08 02:33:08112#include "ash/system/power/power_event_observer.h"
Qiang Xu36234e532018-04-11 04:54:02113#include "ash/system/power/power_prefs.h"
James Cooka35a1e22017-04-08 02:33:08114#include "ash/system/power/power_status.h"
115#include "ash/system/power/video_activity_notifier.h"
116#include "ash/system/screen_layout_observer.h"
Tetsui Ohkubo54d50222018-05-10 01:58:11117#include "ash/system/screen_security/screen_switch_check_controller.h"
James Cookdc041122017-08-01 14:03:22118#include "ash/system/session/logout_button_tray.h"
James Cooka35a1e22017-04-08 02:33:08119#include "ash/system/session/logout_confirmation_controller.h"
James Cookb0bf8e82017-04-09 17:01:44120#include "ash/system/status_area_widget.h"
Tetsui Ohkubo269b5792018-04-26 01:06:32121#include "ash/system/system_notification_controller.h"
James Cookb0bf8e82017-04-09 17:01:44122#include "ash/system/toast/toast_manager.h"
James Cookb0bf8e82017-04-09 17:01:44123#include "ash/system/tray/system_tray_notifier.h"
kylechar55f0eaf22017-01-11 22:57:37124#include "ash/touch/ash_touch_transform_controller.h"
Qiang Xuf1400a362017-09-14 02:28:30125#include "ash/touch/touch_devices_controller.h"
tbarzicc78da1ff92017-05-08 20:46:15126#include "ash/tray_action/tray_action.h"
oshima5a296e82016-04-29 01:32:27127#include "ash/utility/screenshot_controller.h"
Yue Lia33960a2017-11-01 22:06:07128#include "ash/voice_interaction/voice_interaction_controller.h"
James Cookb0bf8e82017-04-09 17:01:44129#include "ash/wallpaper/wallpaper_controller.h"
Scott Violet737fb752018-04-11 15:35:22130#include "ash/wayland/wayland_server_controller.h"
[email protected]39718b52012-12-03 17:24:56131#include "ash/wm/ash_focus_rules.h"
James Cookb0bf8e82017-04-09 17:01:44132#include "ash/wm/container_finder.h"
James Cook698fc3662018-07-27 16:05:01133#include "ash/wm/cursor_manager_chromeos.h"
[email protected]262f8bd2012-03-23 19:30:27134#include "ash/wm/event_client_impl.h"
James Cookb0bf8e82017-04-09 17:01:44135#include "ash/wm/immersive_context_ash.h"
[email protected]ab4f8c92013-05-30 19:07:47136#include "ash/wm/lock_state_controller.h"
James Cookb0bf8e82017-04-09 17:01:44137#include "ash/wm/mru_window_tracker.h"
James Cookbc2758b42018-09-07 16:20:37138#include "ash/wm/native_cursor_manager_ash.h"
Scott Violetac410622018-08-11 18:33:22139#include "ash/wm/non_client_frame_controller.h"
[email protected]9ae32df2012-07-26 03:25:18140#include "ash/wm/overlay_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44141#include "ash/wm/overview/window_selector_controller.h"
[email protected]e4a181cc2012-03-17 02:20:57142#include "ash/wm/resize_shadow_controller.h"
James Cookb0bf8e82017-04-09 17:01:44143#include "ash/wm/root_window_finder.h"
hidehiko6821ca42016-06-18 11:12:23144#include "ash/wm/screen_pinning_controller.h"
xdaid4913762017-07-06 00:17:22145#include "ash/wm/splitview/split_view_controller.h"
[email protected]435b212e2012-04-05 19:43:37146#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:27147#include "ash/wm/system_modal_container_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44148#include "ash/wm/system_modal_container_layout_manager.h"
Mitsuru Oshima0e9b7a62017-07-19 18:23:03149#include "ash/wm/tablet_mode/tablet_mode_controller.h"
150#include "ash/wm/tablet_mode/tablet_mode_window_manager.h"
[email protected]3537d472014-01-15 05:45:31151#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:58152#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:02153#include "ash/wm/window_animations.h"
James Cookb0bf8e82017-04-09 17:01:44154#include "ash/wm/window_cycle_controller.h"
155#include "ash/wm/window_positioner.h"
[email protected]f059c6942012-07-21 14:27:57156#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:59157#include "ash/wm/window_util.h"
Sammie Quon557418662018-04-25 18:45:51158#include "ash/wm/wm_shadow_controller_delegate.h"
James Cookb0bf8e82017-04-09 17:01:44159#include "ash/wm/workspace_controller.h"
James Cookcc2d1702018-12-13 21:20:08160#include "ash/ws/ax_ash_window_utils.h"
Scott Violetb7f4df22018-05-17 04:43:12161#include "ash/ws/window_service_owner.h"
[email protected]f296be72011-10-11 15:40:00162#include "base/bind.h"
jamescook01bf23e72017-01-09 19:58:15163#include "base/bind_helpers.h"
jamescookfda159002016-10-21 18:48:57164#include "base/command_line.h"
dchenga94547472016-04-08 08:41:11165#include "base/memory/ptr_util.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:03166#include "base/system/sys_info.h"
Steven Bennetts368a1c82019-01-11 20:45:22167#include "base/task/post_task.h"
168#include "base/task/task_traits.h"
primiano7182d7b2015-01-30 18:02:03169#include "base/trace_event/trace_event.h"
Toni Barzic85c9e0802018-03-30 02:46:01170#include "chromeos/dbus/dbus_thread_manager.h"
Qiang Xu36234e532018-04-11 04:54:02171#include "chromeos/dbus/power_policy_controller.h"
reveman24158982017-01-10 05:58:45172#include "chromeos/system/devicemode.h"
Scott Violet737fb752018-04-11 15:35:22173#include "components/exo/file_helper.h"
tibellb93c729b2017-03-30 00:45:09174#include "components/prefs/pref_registry_simple.h"
175#include "components/prefs/pref_service.h"
Saman Sami3fb310d2017-11-09 16:51:54176#include "components/viz/host/host_frame_sink_manager.h"
tibellb93c729b2017-03-30 00:45:09177#include "services/preferences/public/cpp/pref_service_factory.h"
Ken Rockotf7f533e2018-02-11 02:21:33178#include "services/preferences/public/mojom/preferences.mojom.h"
derat94887a22017-01-20 18:17:25179#include "services/service_manager/public/cpp/connector.h"
Xiyuan Xiaebf96b72018-09-07 21:04:34180#include "services/ws/public/cpp/host/gpu_interface_provider.h"
Scott Violet9f984252018-08-27 19:02:13181#include "services/ws/window_service.h"
[email protected]2c456102011-12-26 06:26:34182#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:44183#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:58184#include "ui/aura/layout_manager.h"
[email protected]87b0d82e2011-10-07 21:02:59185#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:26186#include "ui/aura/window_event_dispatcher.h"
Scott Violet6c0eb6962018-06-20 01:31:26187#include "ui/base/ui_base_features.h"
[email protected]2d4817742012-12-17 20:16:18188#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:17189#include "ui/base/user_activity/user_activity_detector.h"
jamescook01bf23e72017-01-09 19:58:15190#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]116302fc2012-05-05 21:45:41191#include "ui/compositor/layer.h"
192#include "ui/compositor/layer_animator.h"
oshimaf84b0da722016-04-27 19:47:19193#include "ui/display/display.h"
Joone Hurd3ae8732018-04-17 18:05:09194#include "ui/display/manager/default_touch_transform_setter.h"
195#include "ui/display/manager/display_change_observer.h"
196#include "ui/display/manager/display_configurator.h"
rjkroege72f8154f2016-10-29 00:49:02197#include "ui/display/manager/display_manager.h"
Joone Hurd3ae8732018-04-17 18:05:09198#include "ui/display/manager/touch_transform_setter.h"
oshimaf84b0da722016-04-27 19:47:19199#include "ui/display/screen.h"
skycfaad892017-04-28 20:52:58200#include "ui/display/types/native_display_delegate.h"
[email protected]3e670aa2013-12-02 19:04:32201#include "ui/events/event_target_iterator.h"
sky4ec2be82017-01-06 17:38:32202#include "ui/gfx/geometry/insets.h"
[email protected]9ec0f452012-05-31 15:58:53203#include "ui/gfx/image/image_skia.h"
Jun Mukaif2357792018-12-20 19:58:00204#include "ui/keyboard/keyboard_ui_factory.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);
yileilib394a2072018-12-07 18:33:28248 AssistantController::RegisterProfilePrefs(registry);
Qiang Xu36234e532018-04-11 04:54:02249 BluetoothPowerController::RegisterProfilePrefs(registry);
Qiang Xudcf11e32018-04-25 17:10:17250 DockedMagnifierController::RegisterProfilePrefs(registry, for_test);
Qiang Xu36234e532018-04-11 04:54:02251 LoginScreenController::RegisterProfilePrefs(registry, for_test);
252 LogoutButtonTray::RegisterProfilePrefs(registry);
yoshiki iguchi71623722018-08-10 19:44:45253 MessageCenterController::RegisterProfilePrefs(registry);
Qiang Xu36234e532018-04-11 04:54:02254 NightLightController::RegisterProfilePrefs(registry);
255 PaletteTray::RegisterProfilePrefs(registry);
256 PaletteWelcomeBubble::RegisterProfilePrefs(registry);
257 ShelfController::RegisterProfilePrefs(registry);
Michael Giuffridac997aa72018-08-31 23:38:59258 TouchDevicesController::RegisterProfilePrefs(registry);
Qiang Xu36234e532018-04-11 04:54:02259 CapsLockNotificationController::RegisterProfilePrefs(registry, for_test);
260}
261
[email protected]87b0d82e2011-10-07 21:02:59262} // namespace
263
[email protected]cac10fc62011-10-07 23:22:56264// static
achuith287b26e2015-09-03 17:49:18265Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13266
267////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56268// Shell, public:
269
[email protected]cac10fc62011-10-07 23:22:56270// static
Scott Violetc8a1c6c2017-11-29 23:17:36271Shell* Shell::CreateInstance(ShellInitParams init_params) {
[email protected]3266c2b92011-11-14 00:06:08272 CHECK(!instance_);
James Cookfa4838e2018-08-08 16:30:15273 instance_ = new Shell(std::move(init_params.delegate), init_params.connector);
Scott Violete5c79f52018-07-31 00:10:17274 instance_->Init(init_params.context_factory,
275 init_params.context_factory_private,
276 std::move(init_params.initial_display_prefs),
Jun Mukaif2357792018-12-20 19:58:00277 std::move(init_params.gpu_interface_provider),
278 std::move(init_params.keyboard_ui_factory));
[email protected]3266c2b92011-11-14 00:06:08279 return instance_;
280}
281
282// static
skyb073203a2017-03-13 16:59:16283Shell* Shell::Get() {
jamescook518dccbd2017-05-18 04:57:07284 CHECK(!g_is_browser_process_with_mash) // Implies null |instance_|.
285 << "Ash is running in its own process so Shell::Get() will return null. "
286 "The browser process must use the mojo interfaces in //ash/public to "
287 "access ash. See ash/README.md for details.";
oshima9eea82da2014-09-13 01:11:07288 CHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56289 return instance_;
290}
291
[email protected]6377a002011-11-10 20:26:47292// static
[email protected]b3b7bcd2012-03-06 19:35:45293bool Shell::HasInstance() {
294 return !!instance_;
295}
296
297// static
[email protected]ef589af2011-12-03 01:07:15298void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47299 delete instance_;
[email protected]6377a002011-11-10 20:26:47300}
301
[email protected]e73bd7802012-02-17 20:10:34302// static
[email protected]093b8d642014-04-03 20:59:28303RootWindowController* Shell::GetPrimaryRootWindowController() {
oshima9eea82da2014-09-13 01:11:07304 CHECK(HasInstance());
msw257a6a232017-06-01 01:46:30305 return RootWindowController::ForWindow(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23306}
307
308// static
309Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
oshima9eea82da2014-09-13 01:11:07310 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34311 RootWindowControllerList root_window_controllers;
msw257a6a232017-06-01 01:46:30312 for (aura::Window* root : GetAllRootWindows())
313 root_window_controllers.push_back(RootWindowController::ForWindow(root));
skyabcae812017-01-18 17:01:34314 return root_window_controllers;
[email protected]d90b8392012-06-13 09:34:56315}
316
317// static
thanhphc90f49ca2017-03-03 17:48:53318RootWindowController* Shell::GetRootWindowControllerWithDisplayId(
319 int64_t display_id) {
320 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13321 aura::Window* root = GetRootWindowForDisplayId(display_id);
msw257a6a232017-06-01 01:46:30322 return root ? RootWindowController::ForWindow(root) : nullptr;
thanhphc90f49ca2017-03-03 17:48:53323}
324
325// static
Scott Violet596bb46342017-06-21 14:43:13326aura::Window* Shell::GetRootWindowForDisplayId(int64_t display_id) {
327 CHECK(HasInstance());
328 return instance_->window_tree_host_manager_->GetRootWindowForDisplayId(
329 display_id);
330}
331
332// static
[email protected]bf9cdb362013-10-25 19:22:45333aura::Window* Shell::GetPrimaryRootWindow() {
oshima9eea82da2014-09-13 01:11:07334 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13335 return instance_->window_tree_host_manager_->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34336}
337
[email protected]7b0f7502012-06-11 00:12:39338// static
sky27344382017-03-08 21:30:32339aura::Window* Shell::GetRootWindowForNewWindows() {
James Cook40f7d752018-05-25 18:21:58340 return Shell::Get()->shell_state_->GetRootWindowForNewWindows();
mfomitcheva1a8aa62016-05-03 16:23:26341}
342
343// static
[email protected]c9390bd2013-11-08 20:33:13344aura::Window::Windows Shell::GetAllRootWindows() {
oshima9eea82da2014-09-13 01:11:07345 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13346 return instance_->window_tree_host_manager_->GetAllRootWindows();
[email protected]be65be362012-06-15 07:38:23347}
348
349// static
jamescookb8dcef522016-06-25 14:42:55350aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) {
[email protected]7b0f7502012-06-11 00:12:39351 return root_window->GetChildById(container_id);
352}
353
354// static
[email protected]bf9cdb362013-10-25 19:22:45355const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38356 int container_id) {
357 return root_window->GetChildById(container_id);
358}
359
sky494c6cbd2017-03-27 20:57:48360// static
James Cook7b7c6a52018-01-04 23:40:03361int Shell::GetOpenSystemModalWindowContainerId() {
362 // The test boolean is not static to avoid leaking state between tests.
363 if (Get()->simulate_modal_window_open_for_test_)
364 return kShellWindowId_SystemModalContainer;
365
366 // Traverse all system modal containers, and find its direct child window
367 // with "SystemModal" setting, and visible.
James Cook7b7c6a52018-01-04 23:40:03368 for (aura::Window* root : Shell::GetAllRootWindows()) {
Xiyuan Xia40b3fb1f2018-08-22 22:18:20369 for (int modal_window_id : kSystemModalContainerIds) {
James Cook7b7c6a52018-01-04 23:40:03370 aura::Window* system_modal = root->GetChildById(modal_window_id);
371 if (!system_modal)
372 continue;
373 for (const aura::Window* child : system_modal->children()) {
374 if (child->GetProperty(aura::client::kModalKey) ==
375 ui::MODAL_TYPE_SYSTEM &&
376 child->layer()->GetTargetVisibility()) {
377 return modal_window_id;
378 }
379 }
380 }
381 }
382 return -1;
383}
384
385// static
386bool Shell::IsSystemModalWindowOpen() {
387 return GetOpenSystemModalWindowContainerId() >= 0;
388}
389
390// static
Scott Violet25848c12018-12-14 18:29:15391bool Shell::IsProxyWindow(aura::Window* window) {
392 return ws::WindowService::IsProxyWindow(window);
James Cooka6066972018-07-31 19:34:07393}
394
395// static
Steven Bennettsca108512018-05-02 11:05:03396void Shell::RegisterLocalStatePrefs(PrefRegistrySimple* registry,
397 bool for_test) {
Sammie Quon4d7dba62017-08-03 23:18:17398 PaletteTray::RegisterLocalStatePrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34399 WallpaperController::RegisterLocalStatePrefs(registry);
Sonny Sasaka55f69fc2017-08-28 21:29:37400 BluetoothPowerController::RegisterLocalStatePrefs(registry);
Toni Barzicd6238312018-03-02 18:26:13401 DetachableBaseHandler::RegisterPrefs(registry);
Steven Bennettsca108512018-05-02 11:05:03402 // Note: DisplayPrefs are registered in chrome in AshShellInit::RegisterPrefs
403 // (see comment there for details).
404 if (for_test)
405 DisplayPrefs::RegisterLocalStatePrefs(registry);
406 else
407 DisplayPrefs::RegisterForeignPrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34408}
409
410// static
Qiang Xu36234e532018-04-11 04:54:02411void Shell::RegisterSigninProfilePrefs(PrefRegistrySimple* registry,
412 bool for_test) {
413 RegisterProfilePrefs(registry, for_test);
414 PowerPrefs::RegisterSigninProfilePrefs(registry, for_test);
415}
416
417// static
418void Shell::RegisterUserProfilePrefs(PrefRegistrySimple* registry,
419 bool for_test) {
420 RegisterProfilePrefs(registry, for_test);
421 PowerPrefs::RegisterUserProfilePrefs(registry, for_test);
afakhrye4fae852017-05-09 18:49:06422}
423
Xiyuan Xia36197372018-04-25 00:45:17424void Shell::InitWaylandServer(std::unique_ptr<exo::FileHelper> file_helper) {
Scott Violetac410622018-08-11 18:33:22425 wayland_server_controller_ = WaylandServerController::CreateIfNecessary(
426 std::move(file_helper), aura_env_);
Tetsui Ohkubo852abe642018-10-03 02:52:27427 if (wayland_server_controller_) {
428 system_tray_model()
429 ->virtual_keyboard()
430 ->SetInputMethodSurfaceManagerObserver(
431 wayland_server_controller_->arc_input_method_surface_manager());
432 }
Scott Violet737fb752018-04-11 15:35:22433}
434
435void Shell::DestroyWaylandServer() {
Tetsui Ohkubo852abe642018-10-03 02:52:27436 if (wayland_server_controller_) {
437 system_tray_model()
438 ->virtual_keyboard()
439 ->RemoveInputMethodSurfaceManagerObserver(
440 wayland_server_controller_->arc_input_method_surface_manager());
441 }
Scott Violet737fb752018-04-11 15:35:22442 wayland_server_controller_.reset();
443}
444
[email protected]57b8bb352012-01-11 05:11:46445views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
446 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04447 // Use translucent-style window frames for dialogs.
Evan Stade5f09e6572018-08-10 17:48:15448 return new NonClientFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46449}
450
[email protected]2e236a52012-06-27 22:21:47451void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44452 const gfx::Insets& insets) {
Scott Violet596bb46342017-06-21 14:43:13453 window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow(contains,
454 insets);
[email protected]1a2145b2012-03-13 21:09:17455}
456
[email protected]58868abf2014-01-17 23:45:33457void Shell::OnCastingSessionStartedOrStopped(bool started) {
sky00c813f2017-03-08 22:48:55458 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18459 observer.OnCastingSessionStartedOrStopped(started);
[email protected]58868abf2014-01-17 23:45:33460}
461
varkhac71444e52017-05-25 22:51:34462void Shell::OnRootWindowAdded(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55463 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18464 observer.OnRootWindowAdded(root_window);
[email protected]0e3e7cb2014-04-12 05:18:25465}
466
Zach Helfinsteinbbb6bad2018-05-02 18:21:51467void Shell::OnDictationStarted() {
468 for (auto& observer : shell_observers_)
469 observer.OnDictationStarted();
470}
471
472void Shell::OnDictationEnded() {
473 for (auto& observer : shell_observers_)
474 observer.OnDictationEnded();
475}
476
Darren Shenf62db77a2018-06-07 06:22:44477void Shell::EnableKeyboard() {
Steven Bennettsa0ea30942018-10-11 22:27:51478 // The keyboard controller is persistent; this will create or recreate the
479 // keyboard window as necessary.
480 ash_keyboard_controller_->EnableKeyboard();
[email protected]51f438112013-11-18 19:32:50481}
482
Darren Shenf62db77a2018-06-07 06:22:44483void Shell::DisableKeyboard() {
Steven Bennettsa0ea30942018-10-11 22:27:51484 ash_keyboard_controller_->DisableKeyboard();
[email protected]e1b299b2014-01-29 23:53:41485}
486
[email protected]da285852014-05-27 19:53:43487bool Shell::ShouldSaveDisplaySettings() {
jamescookb8dcef522016-06-25 14:42:55488 return !(
489 screen_orientation_controller_->ignore_display_configuration_updates() ||
490 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43491}
[email protected]da285852014-05-27 19:53:43492
Ahmed Fakhry4bf3f742018-02-06 17:33:36493DockedMagnifierController* Shell::docked_magnifier_controller() {
Ahmed Fakhry4af48e42018-02-28 17:45:38494 DCHECK(features::IsDockedMagnifierEnabled());
Ahmed Fakhry4bf3f742018-02-06 17:33:36495 return docked_magnifier_controller_.get();
496}
497
afakhry9e0a18b32017-06-05 19:23:14498NightLightController* Shell::night_light_controller() {
Ahmed Fakhryb9ace242018-06-06 18:49:31499 DCHECK(features::IsNightLightEnabled());
afakhry9e0a18b32017-06-05 19:23:14500 return night_light_controller_.get();
501}
502
sky5ad143a2017-03-22 04:31:23503ShelfModel* Shell::shelf_model() {
504 return shelf_controller_->model();
505}
506
Thiago Farina3b086a02017-05-30 22:32:50507::wm::ActivationClient* Shell::activation_client() {
sky27344382017-03-08 21:30:32508 return focus_controller_.get();
509}
510
[email protected]c758fbf2012-03-25 22:53:59511void Shell::UpdateShelfVisibility() {
msw257a6a232017-06-01 01:46:30512 for (aura::Window* root : GetAllRootWindows())
513 Shelf::ForWindow(root)->UpdateVisibilityState();
[email protected]c758fbf2012-03-25 22:53:59514}
515
[email protected]a0afeb12012-12-10 22:57:09516bool Shell::HasPrimaryStatusArea() {
jamescookb551aba2016-09-01 01:00:16517 return !!GetPrimaryRootWindowController()->GetStatusAreaWidget();
[email protected]31f19e32012-10-30 22:31:23518}
519
yawanodc5533b32017-02-23 11:04:38520void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
521 window_tree_host_manager_->cursor_window_controller()
522 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
523}
524
Weidong Guod07448f2017-10-18 03:35:18525void Shell::UpdateCursorCompositingEnabled() {
526 SetCursorCompositingEnabled(
527 window_tree_host_manager_->cursor_window_controller()
528 ->ShouldEnableCursorCompositing());
529}
530
[email protected]87ec2202014-02-06 06:24:27531void Shell::SetCursorCompositingEnabled(bool enabled) {
James Cookf2920df2018-09-04 19:55:01532 CursorWindowController* cursor_window_controller =
533 window_tree_host_manager_->cursor_window_controller();
Weidong Guo7dfd1482017-11-08 05:56:28534
James Cookf2920df2018-09-04 19:55:01535 if (cursor_window_controller->is_cursor_compositing_enabled() == enabled)
536 return;
537 cursor_window_controller->SetCursorCompositingEnabled(enabled);
538 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
[email protected]87ec2202014-02-06 06:24:27539}
[email protected]59ccade2013-10-17 17:56:40540
[email protected]f9466702012-09-17 16:35:27541void Shell::DoInitialWorkspaceAnimation() {
jamescookb8dcef522016-06-25 14:42:55542 return GetPrimaryRootWindowController()
543 ->workspace_controller()
544 ->DoInitialAnimation();
[email protected]f9466702012-09-17 16:35:27545}
546
xdaid4913762017-07-06 00:17:22547bool Shell::IsSplitViewModeActive() const {
Xiaoqian Daibf3771f2018-03-13 18:21:46548 return split_view_controller_.get() &&
549 split_view_controller_->IsSplitViewModeActive();
xdaid4913762017-07-06 00:17:22550}
551
James Cookfa4838e2018-08-08 16:30:15552void Shell::ShowContextMenu(const gfx::Point& location_in_screen,
553 ui::MenuSourceType source_type) {
554 // Bail with no active user session, in the lock screen, or in app/kiosk mode.
555 if (session_controller_->NumberOfLoggedInUsers() < 1 ||
556 session_controller_->IsScreenLocked() ||
557 session_controller_->IsRunningInAppMode()) {
558 return;
559 }
560
561 aura::Window* root = wm::GetRootWindowAt(location_in_screen);
562 RootWindowController::ForWindow(root)->ShowContextMenu(location_in_screen,
563 source_type);
564}
565
sky00c813f2017-03-08 22:48:55566void Shell::AddShellObserver(ShellObserver* observer) {
567 shell_observers_.AddObserver(observer);
568}
569
570void Shell::RemoveShellObserver(ShellObserver* observer) {
571 shell_observers_.RemoveObserver(observer);
572}
573
sky5ad143a2017-03-22 04:31:23574void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
varkha59679632017-06-01 00:42:05575 for (auto* root_window_controller : GetAllRootWindowControllers())
576 root_window_controller->UpdateAfterLoginStatusChange(status);
sky5ad143a2017-03-22 04:31:23577}
578
sky00c813f2017-03-08 22:48:55579void Shell::NotifyOverviewModeStarting() {
580 for (auto& observer : shell_observers_)
581 observer.OnOverviewModeStarting();
582}
583
Sammie Quonbe186062018-10-26 06:40:34584void Shell::NotifyOverviewModeStartingAnimationComplete(bool canceled) {
585 for (auto& observer : shell_observers_)
586 observer.OnOverviewModeStartingAnimationComplete(canceled);
587}
588
Xiaoqian Daifb4698ed2018-02-23 20:11:06589void Shell::NotifyOverviewModeEnding() {
590 for (auto& observer : shell_observers_)
591 observer.OnOverviewModeEnding();
592}
593
sky00c813f2017-03-08 22:48:55594void Shell::NotifyOverviewModeEnded() {
595 for (auto& observer : shell_observers_)
596 observer.OnOverviewModeEnded();
597}
598
Sammie Quonbe186062018-10-26 06:40:34599void Shell::NotifyOverviewModeEndingAnimationComplete(bool canceled) {
Sammie Quon317deb52018-09-06 16:36:28600 for (auto& observer : shell_observers_)
Sammie Quonbe186062018-10-26 06:40:34601 observer.OnOverviewModeEndingAnimationComplete(canceled);
Sammie Quon317deb52018-09-06 16:36:28602}
603
xdaid4913762017-07-06 00:17:22604void Shell::NotifySplitViewModeStarting() {
605 for (auto& observer : shell_observers_)
606 observer.OnSplitViewModeStarting();
607}
608
Xiaoqian Daibf3771f2018-03-13 18:21:46609void Shell::NotifySplitViewModeStarted() {
610 for (auto& observer : shell_observers_)
611 observer.OnSplitViewModeStarted();
612}
613
xdaid4913762017-07-06 00:17:22614void Shell::NotifySplitViewModeEnded() {
615 for (auto& observer : shell_observers_)
616 observer.OnSplitViewModeEnded();
617}
618
sky00c813f2017-03-08 22:48:55619void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
varkhac71444e52017-05-25 22:51:34620 aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55621 for (auto& observer : shell_observers_)
622 observer.OnFullscreenStateChanged(is_fullscreen, root_window);
623}
624
varkha19d7e6c52017-05-25 21:15:30625void Shell::NotifyPinnedStateChanged(aura::Window* pinned_window) {
sky00c813f2017-03-08 22:48:55626 for (auto& observer : shell_observers_)
627 observer.OnPinnedStateChanged(pinned_window);
628}
629
varkha6b016b0f2017-05-26 16:14:18630void Shell::NotifyShelfAlignmentChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55631 for (auto& observer : shell_observers_)
632 observer.OnShelfAlignmentChanged(root_window);
633}
634
varkha6b016b0f2017-05-26 16:14:18635void Shell::NotifyShelfAutoHideBehaviorChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55636 for (auto& observer : shell_observers_)
637 observer.OnShelfAutoHideBehaviorChanged(root_window);
638}
639
jamescook518dccbd2017-05-18 04:57:07640// static
641void Shell::SetIsBrowserProcessWithMash() {
642 g_is_browser_process_with_mash = true;
643}
644
muyuanlid766f2e2017-06-26 20:17:19645void Shell::NotifyAppListVisibilityChanged(bool visible,
646 aura::Window* root_window) {
newcomer2febb9832017-06-12 17:00:23647 for (auto& observer : shell_observers_)
648 observer.OnAppListVisibilityChanged(visible, root_window);
649}
650
[email protected]b6ba05d902013-10-04 21:38:45651////////////////////////////////////////////////////////////////////////////////
652// Shell, private:
653
skyb073203a2017-03-13 16:59:16654Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
Scott Violete5c79f52018-07-31 00:10:17655 service_manager::Connector* connector)
Scott Violetac410622018-08-11 18:33:22656 : owned_aura_env_(::features::IsSingleProcessMash()
657 ? aura::Env::CreateLocalInstanceForInProcess()
658 : nullptr),
659 aura_env_(owned_aura_env_.get() ? owned_aura_env_.get()
660 : aura::Env::GetInstance()),
661 ash_display_controller_(std::make_unique<AshDisplayController>()),
sky79fa34712017-03-20 23:46:47662 brightness_control_delegate_(
Mitsuru Oshima04b54d02017-10-09 14:22:45663 std::make_unique<system::BrightnessControllerChromeos>()),
664 cast_config_(std::make_unique<CastConfigController>()),
Scott Violete5c79f52018-07-31 00:10:17665 connector_(connector),
Quan Nguyenaf67b64d2018-11-29 19:21:48666 contained_shell_controller_(std::make_unique<ContainedShellController>()),
James Cookf5398842018-04-16 20:15:24667 first_run_helper_(std::make_unique<FirstRunHelper>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45668 focus_cycler_(std::make_unique<FocusCycler>()),
669 ime_controller_(std::make_unique<ImeController>()),
670 immersive_context_(std::make_unique<ImmersiveContextAsh>()),
sky79fa34712017-03-20 23:46:47671 keyboard_brightness_control_delegate_(
Mitsuru Oshima04b54d02017-10-09 14:22:45672 std::make_unique<KeyboardBrightnessController>()),
Tatsuhisa Yamaguchi440e2d2e2018-12-05 09:16:31673 locale_update_controller_(std::make_unique<LocaleUpdateController>()),
Becca Hughes253f1bbf32018-10-18 18:38:31674 media_controller_(std::make_unique<MediaController>(connector)),
Mitsuru Oshima04b54d02017-10-09 14:22:45675 new_window_controller_(std::make_unique<NewWindowController>()),
Scott Violete5c79f52018-07-31 00:10:17676 session_controller_(std::make_unique<SessionController>(connector)),
Vladislav Kaznacheev92edf62e2017-10-13 22:08:01677 note_taking_controller_(std::make_unique<NoteTakingController>()),
skyb073203a2017-03-13 16:59:16678 shell_delegate_(std::move(shell_delegate)),
James Cook40f7d752018-05-25 18:21:58679 shell_state_(std::make_unique<ShellState>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45680 shutdown_controller_(std::make_unique<ShutdownController>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45681 system_tray_notifier_(std::make_unique<SystemTrayNotifier>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45682 vpn_list_(std::make_unique<VpnList>()),
683 window_cycle_controller_(std::make_unique<WindowCycleController>()),
Scott Violetbed23cb2018-08-22 19:56:12684 display_configurator_(std::make_unique<display::DisplayConfigurator>()),
685 display_output_protection_(std::make_unique<DisplayOutputProtection>(
686 display_configurator_.get())),
sadrul7a8785e2016-02-12 21:54:35687 native_cursor_manager_(nullptr),
Sam McNallye36abbc2017-07-20 01:04:28688 weak_factory_(this) {
Scott Violetc354dd12018-10-17 00:12:35689 // Ash doesn't properly remove pre-target-handlers.
690 ui::EventHandler::DisableCheckTargets();
691
Steven Bennetts368a1c82019-01-11 20:45:22692 AccelerometerReader::GetInstance()->Initialize(
693 base::CreateSequencedTaskRunnerWithTraits(
694 {base::MayBlock(), base::TaskPriority::BEST_EFFORT,
695 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}));
696
Jun Mukai5c7b5b42018-11-30 00:08:50697 login_screen_controller_ =
698 std::make_unique<LoginScreenController>(system_tray_notifier_.get());
Scott Violet596bb46342017-06-21 14:43:13699 display_manager_.reset(ScreenAsh::CreateDisplayManager());
Mitsuru Oshima04b54d02017-10-09 14:22:45700 window_tree_host_manager_ = std::make_unique<WindowTreeHostManager>();
701 user_metrics_recorder_ = std::make_unique<UserMetricsRecorder>();
Steven Bennettsa0ea30942018-10-11 22:27:51702 ash_keyboard_controller_ =
703 std::make_unique<AshKeyboardController>(session_controller_.get());
[email protected]b6ba05d902013-10-04 21:38:45704
Giovanni Ortuño Urquidi55aa5d8f2018-10-10 05:33:34705 if (base::FeatureList::IsEnabled(features::kUseBluetoothSystemInAsh)) {
706 tray_bluetooth_helper_ =
Giovanni Ortuño Urquidic87b6f342018-10-16 04:44:41707 std::make_unique<TrayBluetoothHelperExperimental>(connector_);
Giovanni Ortuño Urquidi55aa5d8f2018-10-10 05:33:34708 } else {
709 tray_bluetooth_helper_ = std::make_unique<TrayBluetoothHelperLegacy>();
710 }
711
[email protected]093b8d642014-04-03 20:59:28712 PowerStatus::Initialize();
sky5ad143a2017-03-22 04:31:23713
Xiyuan Xia22b1a6c2017-04-18 22:46:01714 session_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45715}
716
717Shell::~Shell() {
718 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
719
Scott Violet737fb752018-04-11 15:35:22720 // Wayland depends upon some ash specific objects. Destroy it early on.
721 wayland_server_controller_.reset();
722
Scott Violet41562d1c2017-06-26 15:15:48723 user_metrics_recorder_->OnShellShuttingDown();
bruthigc24d11f2015-06-09 21:30:03724
Steven Bennetts2a9b4382018-04-26 23:41:19725 cros_display_config_.reset();
Steven Bennetts9b21fa32018-04-13 23:45:55726 display_configuration_observer_.reset();
Steven Bennetts3688c6032018-04-13 01:14:23727 display_prefs_.reset();
[email protected]050e77182014-03-25 15:29:16728
[email protected]b6ba05d902013-10-04 21:38:45729 // Remove the focus from any window. This will prevent overhead and side
730 // effects (e.g. crashes) from changing focus during shutdown.
731 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18732 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45733
xdaid4913762017-07-06 00:17:22734 // Please keep in reverse order as in Init() because it's easy to miss one.
[email protected]b6ba05d902013-10-04 21:38:45735 if (window_modality_controller_)
736 window_modality_controller_.reset();
jamescook01bf23e72017-01-09 19:58:15737
[email protected]e4ea52362014-02-15 03:21:06738 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
739 magnifier_key_scroll_handler_.reset();
740
741 RemovePreTargetHandler(speech_feedback_handler_.get());
742 speech_feedback_handler_.reset();
jamescook01bf23e72017-01-09 19:58:15743
[email protected]b6ba05d902013-10-04 21:38:45744 RemovePreTargetHandler(overlay_filter_.get());
Xiyuan Xia22b1a6c2017-04-18 22:46:01745 overlay_filter_.reset();
746
[email protected]3537d472014-01-15 05:45:31747 RemovePreTargetHandler(accelerator_filter_.get());
748 RemovePreTargetHandler(event_transformation_handler_.get());
749 RemovePreTargetHandler(toplevel_window_event_handler_.get());
750 RemovePostTargetHandler(toplevel_window_event_handler_.get());
Scott Violet596bb46342017-06-21 14:43:13751 RemovePreTargetHandler(system_gesture_filter_.get());
752 RemovePreTargetHandler(mouse_cursor_filter_.get());
hariank0dd03dd2016-07-14 23:47:33753 RemovePreTargetHandler(modality_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45754 RemovePreTargetHandler(tooltip_controller_.get());
755
Mike Wassermanefbf3402018-04-26 00:41:32756 event_rewriter_controller_.reset();
757
jonross0af45212015-01-13 18:55:46758 screen_orientation_controller_.reset();
yiyixa68ade512016-09-01 17:38:13759 screen_layout_observer_.reset();
jonross0af45212015-01-13 18:55:46760
Mitsuru Oshima0e9b7a62017-07-19 18:23:03761 // Destroy the virtual keyboard controller before the tablet mode controller
jamescook01bf23e72017-01-09 19:58:15762 // since the latters destructor triggers events that the former is listening
763 // to but no longer cares about.
Steven Bennettsedb5fa392018-10-18 17:47:52764 ash_keyboard_controller_->DestroyVirtualKeyboard();
jonross0af45212015-01-13 18:55:46765
James Cookd2495fe2018-03-19 19:53:10766 // Depends on |tablet_mode_controller_|.
767 shelf_controller_->Shutdown();
768
Weidong Guo268c7992018-04-13 21:06:07769 // Destroy |app_list_controller_| early than |tablet_mode_controller_| since
770 // the former may use the latter before destruction.
771 app_list_controller_.reset();
772
David Blackc153e3172018-08-21 18:17:58773 // Destroy |assistant_controller_| earlier than |tablet_mode_controller_| so
774 // that the former will destroy the Assistant view hierarchy which has a
775 // dependency on the latter.
Muyuan Li628f6a62018-08-15 20:39:58776 if (chromeos::switches::IsAssistantEnabled())
David Blackc153e3172018-08-21 18:17:58777 assistant_controller_.reset();
Muyuan Li628f6a62018-08-15 20:39:58778
Mitsuru Oshima0e9b7a62017-07-19 18:23:03779 // Destroy tablet mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57780 // need to be removed.
Mitsuru Oshima0e9b7a62017-07-19 18:23:03781 tablet_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57782
jdufault551152e2016-01-27 19:48:43783 // Destroy the keyboard before closing the shelf, since it will invoke a shelf
784 // layout.
Darren Shenf62db77a2018-06-07 06:22:44785 DisableKeyboard();
jdufault551152e2016-01-27 19:48:43786
sky07a24d42017-03-09 23:57:30787 toast_manager_.reset();
yoshiki32f51632016-03-24 01:24:43788
jamescookac6724332017-03-21 02:54:43789 tray_bluetooth_helper_.reset();
James Cookb50959e22017-08-10 20:24:38790
791 // Accesses root window containers.
792 logout_confirmation_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45793
[email protected]b6ba05d902013-10-04 21:38:45794 // Drag-and-drop must be canceled prior to close all windows.
James Cook1e0f3ff2018-03-06 22:52:45795 for (aura::Window* root : GetAllRootWindows())
796 aura::client::SetDragDropClient(root, nullptr);
[email protected]b6ba05d902013-10-04 21:38:45797 drag_drop_controller_.reset();
798
Xiyuan Xia22b1a6c2017-04-18 22:46:01799 // Controllers who have WindowObserver added must be deleted
800 // before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03801
Qiang Xud77a90c2018-02-20 19:43:29802 persistent_window_controller_.reset();
803
[email protected]8c9d12a2013-12-06 18:39:03804 // VideoActivityNotifier must be deleted before |video_detector_| is
805 // deleted because it's observing video activity through
derat83b761392016-07-11 16:44:44806 // VideoDetector::Observer interface.
[email protected]8c9d12a2013-12-06 18:39:03807 video_activity_notifier_.reset();
[email protected]8c9d12a2013-12-06 18:39:03808 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25809 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03810
811 shadow_controller_.reset();
812 resize_shadow_controller_.reset();
813
sky37f0dd12016-07-19 18:00:59814 // Has to happen before ~MruWindowTracker.
sky5b45ed82017-03-27 02:54:23815 window_cycle_controller_.reset();
816 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03817
xdai7a8867cd2017-08-25 23:10:16818 // |split_view_controller_| needs to be deleted after
819 // |window_selector_controller_|.
820 split_view_controller_.reset();
821
James Cook43097132018-08-18 23:31:54822 // Stop dispatching events (e.g. synthesized mouse exits from window close).
823 // https://crbug.com/874156
824 for (RootWindowController* rwc : GetAllRootWindowControllers())
825 rwc->GetHost()->dispatcher()->Shutdown();
826
James Cookee2daef2018-03-10 01:48:10827 // Close all widgets (including the shelf) and destroy all window containers.
skyabcae812017-01-18 17:01:34828 CloseAllRootWindowChildWindows();
829
Jun Mukai5c7b5b42018-11-30 00:08:50830 login_screen_controller_.reset();
Tetsui Ohkubo269b5792018-04-26 01:06:32831 system_notification_controller_.reset();
832 // Should be destroyed after Shelf and |system_notification_controller_|.
833 system_tray_model_.reset();
834
afakhry58159392015-05-22 02:45:52835 // MruWindowTracker must be destroyed after all windows have been deleted to
836 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
837 // path. (crbug.com/485438).
sky5ab16472017-03-21 19:35:08838 mru_window_tracker_.reset();
[email protected]b6ba05d902013-10-04 21:38:45839
[email protected]b6ba05d902013-10-04 21:38:45840 // These need a valid Shell instance to clean up properly, so explicitly
841 // delete them before invalidating the instance.
842 // Alphabetical. TODO(oshima): sort.
Katie Dcf8d55932018-10-24 23:01:22843 autoclick_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45844 magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45845 tooltip_controller_.reset();
846 event_client_.reset();
[email protected]3537d472014-01-15 05:45:31847 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45848 visibility_controller_.reset();
Qiang Xu36234e532018-04-11 04:54:02849 power_prefs_.reset();
[email protected]b6ba05d902013-10-04 21:38:45850
Toni Barzic85ae39e2017-12-07 05:50:18851 tray_action_.reset();
852
[email protected]b6ba05d902013-10-04 21:38:45853 power_button_controller_.reset();
854 lock_state_controller_.reset();
Toni Barzic9d0c82f42017-12-06 00:53:52855 backlights_forced_off_setter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45856
hidehiko6821ca42016-06-18 11:12:23857 screen_pinning_controller_.reset();
858
Kyle Horimoto9fc84fc22018-04-27 19:45:15859 multidevice_notification_presenter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45860 resolution_notification_controller_.reset();
oshima5a296e82016-04-29 01:32:27861 screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49862 mouse_cursor_filter_.reset();
hariank0dd03dd2016-07-14 23:47:33863 modality_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45864
[email protected]03122891a2014-05-13 23:56:49865 touch_transformer_controller_.reset();
sammiequon203ae022016-09-18 17:23:42866 laser_pointer_controller_.reset();
867 partial_magnification_controller_.reset();
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:32868 highlighter_controller_.reset();
Yue Lia33960a2017-11-01 22:06:07869 voice_interaction_controller_.reset();
David Tseng6792dc82018-05-04 19:18:41870 key_accessibility_enabler_.reset();
warx533c8f62016-04-12 01:19:43871
Tetsui Ohkubo01421b32018-05-30 16:54:59872 display_speaker_controller_.reset();
Tetsui Ohkubo54d50222018-05-10 01:58:11873 screen_switch_check_controller_.reset();
874
rjkroege2c9305402016-09-07 00:21:45875 ScreenAsh::CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12876 display_configuration_controller_.reset();
dtseng4ae0a882016-04-15 21:39:27877
sky07a24d42017-03-09 23:57:30878 // These members access Shell in their destructors.
879 wallpaper_controller_.reset();
James Cookec144952017-09-01 00:05:16880 accessibility_controller_.reset();
sky07a24d42017-03-09 23:57:30881 accessibility_delegate_.reset();
Qiang Xua9591002018-03-15 22:29:31882 accessibility_focus_ring_controller_.reset();
Qiang Xud8e897e2018-05-24 20:07:57883 policy_recommendation_restorer_.reset();
Shu Chen39277d22018-12-10 04:22:51884 ime_controller_.reset();
sky07a24d42017-03-09 23:57:30885
886 // Balances the Install() in Initialize().
887 views::FocusManagerFactory::Install(nullptr);
888
sky5ad143a2017-03-22 04:31:23889 // ShelfWindowWatcher has window observers and a pointer to the shelf model.
890 shelf_window_watcher_.reset();
891
tibellb93c729b2017-03-30 00:45:09892 // Removes itself as an observer of |pref_service_|.
sky5ad143a2017-03-22 04:31:23893 shelf_controller_.reset();
894
Ahmed Fakhrye96051f2017-12-12 17:42:17895 // NightLightController depends on the PrefService as well as the window tree
896 // host manager, and must be destructed before them. crbug.com/724231.
897 night_light_controller_ = nullptr;
Ahmed Fakhry4bf3f742018-02-06 17:33:36898 // Similarly for DockedMagnifierController.
899 docked_magnifier_controller_ = nullptr;
Ahmed Fakhrye96051f2017-12-12 17:42:17900
Scott Violetb7f4df22018-05-17 04:43:12901 // May own windows and other objects that have indirect hooks into
902 // WindowTreeHostManager.
903 window_service_owner_.reset();
904
Xiyuan Xia5f1046e2018-06-01 16:04:44905 // Must be released before |focus_controller_|.
906 ime_focus_handler_.reset();
907
James Cook05b3a3f2018-08-07 00:38:55908 // Stop observing window activation changes before closing all windows.
909 focus_controller_->RemoveObserver(this);
910
911 // This also deletes all RootWindows. Note that we invoke Shutdown() on
912 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
913 // destruction of its owned RootWindowControllers relies on the value.
Scott Violet596bb46342017-06-21 14:43:13914 window_tree_host_manager_->Shutdown();
sky5ad143a2017-03-22 04:31:23915
sky27344382017-03-08 21:30:32916 // Depends on |focus_controller_|, so must be destroyed before.
oshimae2818922015-07-28 01:18:52917 window_tree_host_manager_.reset();
Scott Violet7dbdaeb2018-12-11 22:39:02918 focus_rules_ = nullptr;
sky27344382017-03-08 21:30:32919 focus_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45920 screen_position_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45921
robert.bradfordab052492015-05-06 11:09:56922 display_color_manager_.reset();
Steven Bennetts7683e342018-01-02 21:29:52923 projecting_observer_.reset();
924
[email protected]7bc49bd2014-01-22 09:30:34925 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11926 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45927 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11928 display_configurator_->RemoveObserver(display_error_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45929 display_change_observer_.reset();
Steven Bennetts7683e342018-01-02 21:29:52930 display_shutdown_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45931
Steven Bennettsa0ea30942018-10-11 22:27:51932 ash_keyboard_controller_.reset();
933
[email protected]093b8d642014-04-03 20:59:28934 PowerStatus::Shutdown();
James Cook934ba812018-04-20 14:17:35935 // Depends on SessionController.
936 power_event_observer_.reset();
pneubeck8be1f5422014-10-09 16:46:18937
Xiyuan Xia22b1a6c2017-04-18 22:46:01938 session_controller_->RemoveObserver(this);
Sonny Sasaka55f69fc2017-08-28 21:29:37939 // BluetoothPowerController depends on the PrefService and must be destructed
940 // before it.
941 bluetooth_power_controller_ = nullptr;
Qiang Xuf1400a362017-09-14 02:28:30942 // TouchDevicesController depends on the PrefService and must be destructed
943 // before it.
944 touch_devices_controller_ = nullptr;
Toni Barzic550419f2018-03-08 03:56:21945 // DetachableBaseNotificationController depends on DetachableBaseHandler, and
946 // has to be destructed before it.
947 detachable_base_notification_controller_.reset();
Toni Barzicd6238312018-03-02 18:26:13948 // DetachableBaseHandler depends on the PrefService and must be destructed
949 // before it.
950 detachable_base_handler_.reset();
Ahmed Fakhrye96051f2017-12-12 17:42:17951
Becca Hughesc6a0a062018-10-25 16:54:13952 // MediaNotificationController depends on MessageCenter and must be destructed
953 // before it.
954 media_notification_controller_.reset();
955
Evan Stade196ec042018-03-13 19:44:36956 // Destroys the MessageCenter singleton, so must happen late.
957 message_center_controller_.reset();
958
Sam McNallya853cd82017-08-30 01:55:10959 local_state_.reset();
skyb073203a2017-03-13 16:59:16960 shell_delegate_.reset();
sky88bd4be62016-06-09 17:34:41961
Scott Violet17a61722017-06-19 17:54:31962 for (auto& observer : shell_observers_)
963 observer.OnShellDestroyed();
964
[email protected]b6ba05d902013-10-04 21:38:45965 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18966 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45967}
968
Scott Violetae4c25d2018-06-19 15:50:15969void Shell::Init(
970 ui::ContextFactory* context_factory,
971 ui::ContextFactoryPrivate* context_factory_private,
972 std::unique_ptr<base::Value> initial_display_prefs,
Jun Mukaif2357792018-12-20 19:58:00973 std::unique_ptr<ws::GpuInterfaceProvider> gpu_interface_provider,
974 std::unique_ptr<keyboard::KeyboardUIFactory> keyboard_ui_factory) {
Scott Violetac410622018-08-11 18:33:22975 if (::features::IsSingleProcessMash()) {
976 // In SingleProcessMash mode ScreenMus is not created, which means Ash needs
977 // to set the WindowManagerFrameValues.
978 views::WindowManagerFrameValues frame_values;
979 frame_values.normal_insets = frame_values.maximized_insets =
980 NonClientFrameController::GetPreferredClientAreaInsets();
981 frame_values.max_title_bar_button_width =
982 NonClientFrameController::GetMaxTitleBarButtonWidth();
983 views::WindowManagerFrameValues::SetInstance(frame_values);
James Cookcc2d1702018-12-13 21:20:08984
985 // Accessibility node tree serialization needs to "jump the fence" and
986 // convert between ash proxy and mus client windows.
987 views::AXAuraWindowUtils::Set(std::make_unique<AXAshWindowUtils>());
Scott Violetac410622018-08-11 18:33:22988 }
989
Evan Stade196ec042018-03-13 19:44:36990 // This creates the MessageCenter object which is used by some other objects
991 // initialized here, so it needs to come early.
992 message_center_controller_ = std::make_unique<MessageCenterController>();
993
James Cookbd0b7792017-11-17 03:24:26994 // These controllers call Shell::Get() in their constructors, so they cannot
995 // be in the member initialization list.
Qiang Xuf1400a362017-09-14 02:28:30996 touch_devices_controller_ = std::make_unique<TouchDevicesController>();
Mitsuru Oshima04b54d02017-10-09 14:22:45997 bluetooth_power_controller_ = std::make_unique<BluetoothPowerController>();
Toni Barzicd6238312018-03-02 18:26:13998 detachable_base_handler_ = std::make_unique<DetachableBaseHandler>(this);
Toni Barzic550419f2018-03-08 03:56:21999 detachable_base_notification_controller_ =
1000 std::make_unique<DetachableBaseNotificationController>(
1001 detachable_base_handler_.get());
Tetsui Ohkubo01421b32018-05-30 16:54:591002 display_speaker_controller_ = std::make_unique<DisplaySpeakerController>();
Qiang Xud8e897e2018-05-24 20:07:571003 policy_recommendation_restorer_ =
1004 std::make_unique<PolicyRecommendationRestorer>();
Tetsui Ohkubo54d50222018-05-10 01:58:111005 screen_switch_check_controller_ =
1006 std::make_unique<ScreenSwitchCheckController>();
Kyle Horimoto9fc84fc22018-04-27 19:45:151007 // Connector can be null in tests.
Kyle Horimoto3cdb1d02018-12-18 00:18:061008 if (connector_) {
Kyle Horimoto9fc84fc22018-04-27 19:45:151009 multidevice_notification_presenter_ =
1010 std::make_unique<MultiDeviceNotificationPresenter>(
Scott Violete5c79f52018-07-31 00:10:171011 message_center::MessageCenter::Get(), connector_);
Sonny Sasaka55f69fc2017-08-28 21:29:371012
James Cook8532dbc2017-07-31 21:54:511013 // Connect to local state prefs now, but wait for an active user before
1014 // connecting to the profile pref service. The login screen has a temporary
1015 // user profile that is not associated with a real user.
Taiju Tsuiki36c517d2017-05-18 06:45:431016 auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
Steven Bennettsca108512018-05-02 11:05:031017 RegisterLocalStatePrefs(pref_registry.get(), false);
tibellb93c729b2017-03-30 00:45:091018 prefs::ConnectToPrefService(
Scott Violete5c79f52018-07-31 00:10:171019 connector_, std::move(pref_registry),
Sam McNallye36abbc2017-07-20 01:04:281020 base::Bind(&Shell::OnLocalStatePrefServiceInitialized,
1021 weak_factory_.GetWeakPtr()),
1022 prefs::mojom::kLocalStateServiceName);
jonrossc4ba10602017-04-07 20:51:051023 }
skyb073203a2017-03-13 16:59:161024
David Tseng562a9c12018-07-18 03:35:051025 tablet_mode_controller_ = std::make_unique<TabletModeController>();
1026
Qiang Xua9591002018-03-15 22:29:311027 accessibility_focus_ring_controller_ =
1028 std::make_unique<AccessibilityFocusRingController>();
skyb073203a2017-03-13 16:59:161029 accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate());
James Cookaa6aaad2018-08-24 01:00:061030 accessibility_controller_ = std::make_unique<AccessibilityController>();
Mitsuru Oshima04b54d02017-10-09 14:22:451031 toast_manager_ = std::make_unique<ToastManager>();
sky07a24d42017-03-09 23:57:301032
sky07a24d42017-03-09 23:57:301033 // Install the custom factory early on so that views::FocusManagers for Tray,
1034 // Shelf, and WallPaper could be created by the factory.
1035 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
1036
Mitsuru Oshima04b54d02017-10-09 14:22:451037 wallpaper_controller_ = std::make_unique<WallpaperController>();
sky07a24d42017-03-09 23:57:301038
Mitsuru Oshima04b54d02017-10-09 14:22:451039 window_positioner_ = std::make_unique<WindowPositioner>();
sky984c1892016-04-20 00:00:341040
James Cook79e1ed62018-09-07 15:40:421041 native_cursor_manager_ = new NativeCursorManagerAsh;
James Cook698fc3662018-07-27 16:05:011042 cursor_manager_ =
1043 std::make_unique<CursorManager>(base::WrapUnique(native_cursor_manager_));
skyfee520c2016-02-11 19:57:461044
Steven Bennettsca108512018-05-02 11:05:031045 // In CLASSIC mode, |initial_display_prefs| contains the synchronously
1046 // loaded display pref values. Otherwise |initial_display_prefs| is null and
1047 // the pref values will be loaded once |local_state_| is available. (Any store
1048 // requests in the meanwhile will be queued).
1049 display_prefs_ =
1050 std::make_unique<DisplayPrefs>(std::move(initial_display_prefs));
1051
Steven Bennetts7683e342018-01-02 21:29:521052 InitializeDisplayManager();
[email protected]b6ba05d902013-10-04 21:38:451053
James Cook602164e2018-08-07 20:39:421054 // This will initialize aura::Env which requires |display_manager_| to
1055 // be initialized first.
1056 if (context_factory)
Scott Violetac410622018-08-11 18:33:221057 aura_env_->set_context_factory(context_factory);
1058 if (context_factory_private)
1059 aura_env_->set_context_factory_private(context_factory_private);
[email protected]ecca62b2013-10-09 16:18:531060
Ahmed Fakhry46357342018-04-27 00:46:111061 // Night Light depends on the display manager, the display color manager, and
1062 // aura::Env, so initialize it after all have been initialized.
Ahmed Fakhryb9ace242018-06-06 18:49:311063 if (features::IsNightLightEnabled())
Ahmed Fakhry46357342018-04-27 00:46:111064 night_light_controller_ = std::make_unique<NightLightController>();
1065
[email protected]b6ba05d902013-10-04 21:38:451066 // The WindowModalityController needs to be at the front of the input event
1067 // pretarget handler list to ensure that it processes input events when modal
1068 // windows are active.
Scott Violetac410622018-08-11 18:33:221069 window_modality_controller_ =
1070 std::make_unique<::wm::WindowModalityController>(this, aura_env_);
[email protected]b6ba05d902013-10-04 21:38:451071
Mike Wassermanefbf3402018-04-26 00:41:321072 event_rewriter_controller_ = std::make_unique<EventRewriterController>();
1073
Scott Violetac410622018-08-11 18:33:221074 env_filter_ = std::make_unique<::wm::CompoundEventFilter>();
[email protected]b6ba05d902013-10-04 21:38:451075 AddPreTargetHandler(env_filter_.get());
1076
sky27344382017-03-08 21:30:321077 // FocusController takes ownership of AshFocusRules.
Scott Violet7dbdaeb2018-12-11 22:39:021078 focus_rules_ = new wm::AshFocusRules();
1079 focus_controller_ = std::make_unique<::wm::FocusController>(focus_rules_);
sky27344382017-03-08 21:30:321080 focus_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:451081
Mitsuru Oshimae6c35092018-11-16 20:51:251082 window_selector_controller_ = std::make_unique<WindowSelectorController>();
1083
1084 screen_position_controller_ = std::make_unique<ScreenPositionController>();
[email protected]b6ba05d902013-10-04 21:38:451085
Scott Violet5e500372018-10-23 20:00:131086 // Must be before CreatePrimaryHost().
1087 window_service_owner_ =
1088 std::make_unique<WindowServiceOwner>(std::move(gpu_interface_provider));
1089
Scott Violet596bb46342017-06-21 14:43:131090 window_tree_host_manager_->Start();
1091 AshWindowTreeHostInitParams ash_init_params;
1092 window_tree_host_manager_->CreatePrimaryHost(ash_init_params);
1093
Scott Violet3c554ae2017-12-13 02:25:411094 time_to_first_present_recorder_ =
1095 std::make_unique<TimeToFirstPresentRecorder>(GetPrimaryRootWindow());
1096
James Cook40f7d752018-05-25 18:21:581097 shell_state_->SetRootWindowForNewWindows(GetPrimaryRootWindow());
[email protected]b6ba05d902013-10-04 21:38:451098
Scott Violet596bb46342017-06-21 14:43:131099 resolution_notification_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451100 std::make_unique<ResolutionNotificationController>();
[email protected]b6ba05d902013-10-04 21:38:451101
James Cook698fc3662018-07-27 16:05:011102 cursor_manager_->SetDisplay(
1103 display::Screen::GetScreen()->GetPrimaryDisplay());
[email protected]b6ba05d902013-10-04 21:38:451104
James Cookdafb54f2018-09-14 16:36:151105 accelerator_controller_ = std::make_unique<AcceleratorController>();
Xiaohui Chend68ffc12018-08-16 01:56:411106 voice_interaction_controller_ =
1107 std::make_unique<VoiceInteractionController>();
Weidong Guo268c7992018-04-13 21:06:071108
1109 // |app_list_controller_| is put after |tablet_mode_controller_| as the former
1110 // uses the latter in constructor.
Ken Rockot68c021ec2018-11-03 08:51:531111 app_list_controller_ = std::make_unique<AppListControllerImpl>();
Mitsuru Oshima04b54d02017-10-09 14:22:451112 shelf_controller_ = std::make_unique<ShelfController>();
[email protected]b6ba05d902013-10-04 21:38:451113
spange9b51272014-12-11 01:20:101114 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:061115 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
spange9b51272014-12-11 01:20:101116 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:061117 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:391118
[email protected]b6ba05d902013-10-04 21:38:451119 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:451120
derat2d4e62d2015-01-09 16:09:171121 // ui::UserActivityDetector passes events to observers, so let them get
Michael Wasserman07466432018-04-11 03:56:481122 // rewritten first.
1123 user_activity_detector_.reset(new ui::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:451124
[email protected]093b8d642014-04-03 20:59:281125 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:451126 AddPreTargetHandler(overlay_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:451127
[email protected]60d677d2014-05-30 13:07:021128 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
Scott Violetf5db2502018-10-05 15:19:391129 std::make_unique<PreTargetAcceleratorHandler>(),
sky81a2d792017-03-17 19:14:391130 accelerator_controller_->accelerator_history()));
[email protected]b6ba05d902013-10-04 21:38:451131 AddPreTargetHandler(accelerator_filter_.get());
1132
[email protected]093b8d642014-04-03 20:59:281133 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:451134 AddPreTargetHandler(event_transformation_handler_.get());
1135
sky11cf8db92017-04-10 23:38:081136 toplevel_window_event_handler_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451137 std::make_unique<ToplevelWindowEventHandler>();
[email protected]3537d472014-01-15 05:45:311138
Ryan Cuieb5b84e32018-07-19 01:36:021139 system_gesture_filter_ = std::make_unique<SystemGestureEventFilter>();
1140 AddPreTargetHandler(system_gesture_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:451141
[email protected]354520b2014-06-21 04:31:011142 sticky_keys_controller_.reset(new StickyKeysController);
Mitsuru Oshima04b54d02017-10-09 14:22:451143 screen_pinning_controller_ = std::make_unique<ScreenPinningController>();
[email protected]354520b2014-06-21 04:31:011144
Qiang Xu36234e532018-04-11 04:54:021145 power_prefs_ = std::make_unique<PowerPrefs>(
1146 chromeos::PowerPolicyController::Get(),
1147 chromeos::DBusThreadManager::Get()->GetPowerManagerClient());
1148
Toni Barzic9d0c82f42017-12-06 00:53:521149 backlights_forced_off_setter_ = std::make_unique<BacklightsForcedOffSetter>();
1150
Toni Barzic85ae39e2017-12-07 05:50:181151 tray_action_ =
1152 std::make_unique<TrayAction>(backlights_forced_off_setter_.get());
1153
jamescookd9f152f2016-11-15 00:53:081154 lock_state_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451155 std::make_unique<LockStateController>(shutdown_controller_.get());
Toni Barzic9d0c82f42017-12-06 00:53:521156 power_button_controller_ = std::make_unique<PowerButtonController>(
1157 backlights_forced_off_setter_.get());
[email protected]685442f32014-02-28 10:40:061158 // Pass the initial display state to PowerButtonController.
1159 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:091160 display_configurator_->cached_displays());
jamescook01bf23e72017-01-09 19:58:151161
James Cook93614f02018-07-11 21:37:351162 drag_drop_controller_ = std::make_unique<DragDropController>();
Scott Violet361833fb2017-06-21 22:25:201163
oshima5a296e82016-04-29 01:32:271164 // |screenshot_controller_| needs to be created (and prepended as a
mukai19274bdd2015-02-24 22:37:481165 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
oshima5a296e82016-04-29 01:32:271166 // process mouse events prior to screenshot session.
mukai19274bdd2015-02-24 22:37:481167 // See http://crbug.com/459214
James Cook5e9d3402017-11-01 00:20:121168 screenshot_controller_ = std::make_unique<ScreenshotController>(
1169 shell_delegate_->CreateScreenshotDelegate());
Mitsuru Oshima04b54d02017-10-09 14:22:451170 mouse_cursor_filter_ = std::make_unique<MouseCursorEventFilter>();
Katie Db68a5522018-03-30 18:47:361171 AddPreTargetHandler(mouse_cursor_filter_.get(),
1172 ui::EventTarget::Priority::kAccessibility);
[email protected]b6ba05d902013-10-04 21:38:451173
1174 // Create Controllers that may need root window.
1175 // TODO(oshima): Move as many controllers before creating
1176 // RootWindowController as possible.
1177 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:451178
sammiequon203ae022016-09-18 17:23:421179 laser_pointer_controller_.reset(new LaserPointerController());
1180 partial_magnification_controller_.reset(new PartialMagnificationController());
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:321181 highlighter_controller_.reset(new HighlighterController());
sammiequon203ae022016-09-18 17:23:421182
Qiang Xu2657abf2018-03-21 18:01:451183 magnification_controller_ = std::make_unique<MagnificationController>();
Mitsuru Oshima04b54d02017-10-09 14:22:451184 mru_window_tracker_ = std::make_unique<MruWindowTracker>();
[email protected]b6ba05d902013-10-04 21:38:451185
Katie Dab4edf572018-10-12 16:53:551186 autoclick_controller_ = std::make_unique<AutoclickController>();
[email protected]55398d22013-10-10 19:49:201187
[email protected]b6ba05d902013-10-04 21:38:451188 high_contrast_controller_.reset(new HighContrastController);
Saman Sami3fb310d2017-11-09 16:51:541189
Ahmed Fakhry4af48e42018-02-28 17:45:381190 if (features::IsDockedMagnifierEnabled()) {
Ahmed Fakhry4bf3f742018-02-06 17:33:361191 docked_magnifier_controller_ =
1192 std::make_unique<DockedMagnifierController>();
1193 }
1194
Saman Samia1d88aa2018-11-16 22:55:421195 video_detector_ = std::make_unique<VideoDetector>();
[email protected]b6ba05d902013-10-04 21:38:451196
oshimaebbe63772015-02-19 18:41:321197 tooltip_controller_.reset(new views::corewm::TooltipController(
dchenga94547472016-04-08 08:41:111198 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451199 AddPreTargetHandler(tooltip_controller_.get());
1200
hariank0dd03dd2016-07-14 23:47:331201 modality_filter_.reset(new SystemModalContainerEventFilter(this));
1202 AddPreTargetHandler(modality_filter_.get());
1203
[email protected]093b8d642014-04-03 20:59:281204 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451205
[email protected]093b8d642014-04-03 20:59:281206 resize_shadow_controller_.reset(new ResizeShadowController());
Scott Violetac410622018-08-11 18:33:221207 shadow_controller_ = std::make_unique<::wm::ShadowController>(
1208 focus_controller_.get(), std::make_unique<WmShadowControllerDelegate>(),
1209 aura_env_);
[email protected]b6ba05d902013-10-04 21:38:451210
James Cookb50959e22017-08-10 20:24:381211 logout_confirmation_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451212 std::make_unique<LogoutConfirmationController>();
[email protected]b6ba05d902013-10-04 21:38:451213
jamescookac6724332017-03-21 02:54:431214 // May trigger initialization of the Bluetooth adapter.
1215 tray_bluetooth_helper_->Initialize();
1216
kylechar55f0eaf22017-01-11 22:57:371217 // Create AshTouchTransformController before
oshimae2818922015-07-28 01:18:521218 // WindowTreeHostManager::InitDisplays()
kylechar55f0eaf22017-01-11 22:57:371219 // since AshTouchTransformController listens on
oshimae2818922015-07-28 01:18:521220 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
Mitsuru Oshima04b54d02017-10-09 14:22:451221 touch_transformer_controller_ = std::make_unique<AshTouchTransformController>(
Scott Violet596bb46342017-06-21 14:43:131222 display_configurator_.get(), display_manager_.get(),
James Cook9db56d72018-08-01 03:21:311223 std::make_unique<display::DefaultTouchTransformSetter>());
[email protected]03122891a2014-05-13 23:56:491224
Tetsui Ohkubo269b5792018-04-26 01:06:321225 // |system_tray_model_| should be available before
1226 // |system_notification_controller_| is initialized and Shelf is created by
1227 // WindowTreeHostManager::InitHosts.
1228 system_tray_model_ = std::make_unique<SystemTrayModel>();
1229 system_notification_controller_ =
1230 std::make_unique<SystemNotificationController>();
1231
Jun Mukaif2357792018-12-20 19:58:001232 ash_keyboard_controller_->CreateVirtualKeyboard(
1233 std::move(keyboard_ui_factory));
1234
Scott Violet596bb46342017-06-21 14:43:131235 window_tree_host_manager_->InitHosts();
[email protected]b6ba05d902013-10-04 21:38:451236
Meilin Wang3a4ac8e2018-09-27 19:03:431237 // |assistant_controller_| needs to be created after InitHosts() since its
1238 // keyboard observer function result has dependency on workspace change.
1239 assistant_controller_ = chromeos::switches::IsAssistantEnabled()
1240 ? std::make_unique<AssistantController>()
1241 : nullptr;
1242
James Cook698fc3662018-07-27 16:05:011243 cursor_manager_->HideCursor(); // Hide the mouse cursor on startup.
1244 cursor_manager_->SetCursor(ui::CursorType::kPointer);
[email protected]b6ba05d902013-10-04 21:38:451245
Mitsuru Oshima04b54d02017-10-09 14:22:451246 peripheral_battery_notifier_ = std::make_unique<PeripheralBatteryNotifier>();
[email protected]093b8d642014-04-03 20:59:281247 power_event_observer_.reset(new PowerEventObserver());
Sarah Hu8ce89c332018-09-24 18:23:141248 user_activity_notifier_ =
1249 std::make_unique<ui::UserActivityPowerManagerNotifier>(
1250 user_activity_detector_.get(), connector_);
[email protected]ded58fd2013-10-09 07:56:551251 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281252 new VideoActivityNotifier(video_detector_.get()));
1253 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
Scott Violet596bb46342017-06-21 14:43:131254 screen_orientation_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451255 std::make_unique<ScreenOrientationController>();
Scott Violet596bb46342017-06-21 14:43:131256 screen_layout_observer_.reset(new ScreenLayoutObserver());
yiyix90cfee22017-02-16 05:38:181257 sms_observer_.reset(new SmsObserver());
jamescook01bf23e72017-01-09 19:58:151258
xdaid4913762017-07-06 00:17:221259 split_view_controller_.reset(new SplitViewController());
1260
David Tseng6792dc82018-05-04 19:18:411261 key_accessibility_enabler_ = std::make_unique<KeyAccessibilityEnabler>();
1262
[email protected]b6ba05d902013-10-04 21:38:451263 // The compositor thread and main message loop have to be running in
1264 // order to create mirror window. Run it after the main message loop
1265 // is started.
Scott Violet596bb46342017-06-21 14:43:131266 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031267
Scott Violete5c79f52018-07-31 00:10:171268 // |connector_| is null in unit tests.
Scott Violete5c79f52018-07-31 00:10:171269 if (connector_ &&
James Cook08ebee42018-08-07 04:06:421270 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowTaps)) {
Ken Rockota86fa542018-11-13 21:47:131271 // The show taps feature is a separate service.
James Cook08ebee42018-08-07 04:06:421272 // TODO(jamescook): Make this work in ash_shell_with_content.
James Cook1d323b32019-01-02 19:42:291273 tap_visualizer::mojom::TapVisualizerPtr tap_visualizer_ptr;
1274 connector_->BindInterface(service_manager::ServiceFilter::ByName(
1275 tap_visualizer::mojom::kServiceName),
1276 mojo::MakeRequest(&tap_visualizer_ptr));
1277 tap_visualizer_ptr->Show();
James Cook0ba192bf2017-12-01 20:53:111278 }
1279
James Cook7e6a7ae2018-08-24 23:00:471280 if (!::features::IsMultiProcessMash()) {
James Cookc9d6a542018-07-27 21:00:561281 ime_focus_handler_ = std::make_unique<ImeFocusHandler>(
1282 focus_controller(), window_tree_host_manager_->input_method());
Scott Violetb7f4df22018-05-17 04:43:121283 }
1284
Becca Hughesc6a0a062018-10-25 16:54:131285 if (base::FeatureList::IsEnabled(features::kMediaSessionNotification)) {
1286 media_notification_controller_ =
1287 std::make_unique<MediaNotificationController>(connector_);
1288 }
1289
sky00c813f2017-03-08 22:48:551290 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:181291 observer.OnShellInitialized();
phweiss0bf64c52015-11-17 12:56:181292
Scott Violet41562d1c2017-06-26 15:15:481293 user_metrics_recorder_->OnShellInitialized();
Toni Barzic85c9e0802018-03-30 02:46:011294
Jeffrey Kardatzkef108f022018-04-17 17:52:351295 // Initialize the D-Bus thread and services for ash.
1296 ash_dbus_services_ = std::make_unique<AshDBusServices>();
Toni Barzic85c9e0802018-03-30 02:46:011297 // By this point ash shell should have initialized its D-Bus signal
1298 // listeners, so emit ash-initialized upstart signal to start Chrome OS tasks
1299 // that expect that ash is listening to D-Bus signals they emit. For example,
1300 // hammerd, which handles detachable base state, communicates the base state
1301 // purely by emitting D-Bus signals, and thus has to be run whenever ash is
1302 // started so ash (DetachableBaseHandler in particular) gets the proper view
1303 // of the current detachable base state.
Jeffrey Kardatzkef108f022018-04-17 17:52:351304 // TODO(stevenjb): Move this and other D-Bus dependencies to AshDBusServices.
1305 ash_dbus_services_->EmitAshInitialized();
[email protected]b6ba05d902013-10-04 21:38:451306}
1307
Steven Bennetts7683e342018-01-02 21:29:521308void Shell::InitializeDisplayManager() {
Steven Bennetts7683e342018-01-02 21:29:521309 bool display_initialized = display_manager_->InitFromCommandLine();
1310
Steven Bennetts7683e342018-01-02 21:29:521311 display_configuration_controller_ =
1312 std::make_unique<DisplayConfigurationController>(
1313 display_manager_.get(), window_tree_host_manager_.get());
James Cook9db56d72018-08-01 03:21:311314 display_configurator_->Init(
1315 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(), false);
Steven Bennetts9b21fa32018-04-13 23:45:551316 display_configuration_observer_ =
1317 std::make_unique<DisplayConfigurationObserver>();
1318
Steven Bennetts2a9b4382018-04-26 23:41:191319 cros_display_config_ = std::make_unique<CrosDisplayConfig>();
1320
Qiang Xud77a90c2018-02-20 19:43:291321 persistent_window_controller_ =
1322 std::make_unique<PersistentWindowController>();
Steven Bennetts7683e342018-01-02 21:29:521323
1324 projecting_observer_ =
1325 std::make_unique<ProjectingObserver>(display_configurator_.get());
1326
1327 if (!display_initialized) {
Scott Violet97a7b9d2018-08-06 22:31:131328 if (chromeos::IsRunningAsSystemCompositor()) {
Steven Bennetts7683e342018-01-02 21:29:521329 display_change_observer_ =
1330 std::make_unique<display::DisplayChangeObserver>(
1331 display_configurator_.get(), display_manager_.get());
1332
1333 display_shutdown_observer_ = std::make_unique<DisplayShutdownObserver>(
1334 display_configurator_.get());
1335
1336 // Register |display_change_observer_| first so that the rest of
1337 // observer gets invoked after the root windows are configured.
1338 display_configurator_->AddObserver(display_change_observer_.get());
1339 display_error_observer_.reset(new DisplayErrorObserver());
1340 display_configurator_->AddObserver(display_error_observer_.get());
1341 display_configurator_->set_state_controller(
1342 display_change_observer_.get());
1343 display_configurator_->set_mirroring_controller(display_manager_.get());
1344 display_configurator_->ForceInitialConfigure();
1345 display_initialized = true;
1346 }
1347 }
1348
Ahmed Fakhry1ad4bd42018-04-18 19:31:371349 display_color_manager_ = std::make_unique<DisplayColorManager>(
1350 display_configurator_.get(), display::Screen::GetScreen());
Steven Bennetts7683e342018-01-02 21:29:521351
1352 if (!display_initialized)
1353 display_manager_->InitDefaultDisplay();
1354
Scott Violet97a7b9d2018-08-06 22:31:131355 display_manager_->RefreshFontParams();
Steven Bennetts7683e342018-01-02 21:29:521356}
1357
[email protected]41baaed2013-11-09 04:18:261358void Shell::InitRootWindow(aura::Window* root_window) {
sky27344382017-03-08 21:30:321359 DCHECK(focus_controller_);
[email protected]d90b8392012-06-13 09:34:561360 DCHECK(visibility_controller_.get());
[email protected]d90b8392012-06-13 09:34:561361
sky27344382017-03-08 21:30:321362 aura::client::SetFocusClient(root_window, focus_controller_.get());
Thiago Farina3b086a02017-05-30 22:32:501363 ::wm::SetActivationClient(root_window, focus_controller_.get());
sky27344382017-03-08 21:30:321364 root_window->AddPreTargetHandler(focus_controller_.get());
[email protected]d90b8392012-06-13 09:34:561365 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
James Cook93614f02018-07-11 21:37:351366 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]8d625fb2012-07-18 16:40:061367 aura::client::SetScreenPositionClient(root_window,
1368 screen_position_controller_.get());
sadrul7a8785e2016-02-12 21:54:351369 aura::client::SetCursorClient(root_window, cursor_manager_.get());
Thiago Farina3b086a02017-05-30 22:32:501370 ::wm::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381371 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561372
Thiago Farina3b086a02017-05-30 22:32:501373 ::wm::SetWindowMoveClient(root_window, toplevel_window_event_handler_.get());
[email protected]3537d472014-01-15 05:45:311374 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1375 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
[email protected]d90b8392012-06-13 09:34:561376}
1377
skyabcae812017-01-18 17:01:341378void Shell::CloseAllRootWindowChildWindows() {
msw257a6a232017-06-01 01:46:301379 for (aura::Window* root : GetAllRootWindows()) {
1380 RootWindowController* controller = RootWindowController::ForWindow(root);
skyabcae812017-01-18 17:01:341381 if (controller) {
1382 controller->CloseChildWindows();
1383 } else {
msw257a6a232017-06-01 01:46:301384 while (!root->children().empty()) {
1385 aura::Window* child = root->children()[0];
skyabcae812017-01-18 17:01:341386 delete child;
1387 }
1388 }
1389 }
1390}
1391
[email protected]c0ce80e2012-10-05 23:28:271392bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1393 RootWindowControllerList controllers = GetAllRootWindowControllers();
oshima9a61ecf2016-06-18 10:43:051394 for (RootWindowController* controller : controllers) {
1395 if (controller->CanWindowReceiveEvents(window))
[email protected]602022b2014-03-31 17:07:311396 return true;
[email protected]c0ce80e2012-10-05 23:28:271397 }
1398 return false;
1399}
1400
[email protected]049cf34b2012-12-07 17:15:481401////////////////////////////////////////////////////////////////////////////////
1402// Shell, ui::EventTarget overrides:
1403
[email protected]869f6352012-12-06 20:47:171404bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411405 return true;
1406}
1407
1408ui::EventTarget* Shell::GetParentTarget() {
Scott Violetac410622018-08-11 18:33:221409 return aura_env_;
[email protected]5097e692012-10-30 22:08:411410}
1411
dchenga94547472016-04-08 08:41:111412std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1413 return std::unique_ptr<ui::EventTargetIterator>();
[email protected]3e670aa2013-12-02 19:04:321414}
1415
1416ui::EventTargeter* Shell::GetEventTargeter() {
1417 NOTREACHED();
achuith287b26e2015-09-03 17:49:181418 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321419}
1420
sky27344382017-03-08 21:30:321421void Shell::OnWindowActivated(
Thiago Farina3b086a02017-05-30 22:32:501422 ::wm::ActivationChangeObserver::ActivationReason reason,
sky27344382017-03-08 21:30:321423 aura::Window* gained_active,
1424 aura::Window* lost_active) {
James Cook40f7d752018-05-25 18:21:581425 if (!gained_active)
1426 return;
1427
1428 shell_state_->SetRootWindowForNewWindows(gained_active->GetRootWindow());
sky27344382017-03-08 21:30:321429}
1430
Steven Bennettsbadc3092018-05-24 21:26:011431void Shell::OnFirstSessionStarted() {
1432 // Enable magnifier scroll keys as there may be no mouse cursor in kiosk mode.
1433 MagnifierKeyScroller::SetEnabled(session_controller_->IsRunningInAppMode());
1434
1435 // Enable long press action to toggle spoken feedback with hotrod remote
1436 // which can't handle shortcuts.
1437 SpokenFeedbackToggler::SetEnabled(session_controller_->IsRunningInAppMode());
1438}
1439
Xiyuan Xiab64fd0a2017-04-13 17:53:141440void Shell::OnSessionStateChanged(session_manager::SessionState state) {
James Cookeb426b52018-09-17 16:45:121441 const bool is_session_active = state == session_manager::SessionState::ACTIVE;
Aga Wronskae195ad22017-12-20 01:38:111442 // Initialize the |shelf_window_watcher_| when a session becomes active.
1443 // Shelf itself is initialized in RootWindowController.
James Cookeb426b52018-09-17 16:45:121444 if (is_session_active && !shelf_window_watcher_)
1445 shelf_window_watcher_ = std::make_unique<ShelfWindowWatcher>(shelf_model());
1446
1447 // Disable drag-and-drop during OOBE and GAIA login screens by only enabling
1448 // the controller when the session is active. https://crbug.com/464118
1449 drag_drop_controller_->set_enabled(is_session_active);
Quan Nguyenaf67b64d2018-11-29 19:21:481450
1451 if (base::FeatureList::IsEnabled(features::kContainedShell) &&
1452 is_session_active) {
1453 contained_shell_controller_->LaunchContainedShell();
1454 }
xiyuan233f4e72017-04-06 06:59:561455}
sky5ad143a2017-03-22 04:31:231456
Xiyuan Xiab64fd0a2017-04-13 17:53:141457void Shell::OnLoginStatusChanged(LoginStatus login_status) {
xiyuan233f4e72017-04-06 06:59:561458 UpdateAfterLoginStatusChange(login_status);
sky5ad143a2017-03-22 04:31:231459}
1460
Xiyuan Xiab64fd0a2017-04-13 17:53:141461void Shell::OnLockStateChanged(bool locked) {
xiyuan7ebbf7f2017-04-10 16:49:101462#ifndef NDEBUG
1463 // Make sure that there is no system modal in Lock layer when unlocked.
1464 if (!locked) {
1465 aura::Window::Windows containers = wm::GetContainersFromAllRootWindows(
1466 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
1467 for (aura::Window* container : containers)
1468 DCHECK(container->children().empty());
1469 }
1470#endif
1471}
1472
Sam McNallye36abbc2017-07-20 01:04:281473void Shell::OnLocalStatePrefServiceInitialized(
1474 std::unique_ptr<::PrefService> pref_service) {
Sam McNallya853cd82017-08-30 01:55:101475 DCHECK(!local_state_);
James Cook8532dbc2017-07-31 21:54:511476 // |pref_service| is null if can't connect to Chrome (as happens when
Scott Violet8ff9c302018-02-22 22:28:351477 // running mash outside of chrome --enable-features=Mash and chrome isn't
1478 // built).
Sam McNallya853cd82017-08-30 01:55:101479 if (!pref_service)
1480 return;
1481
1482 local_state_ = std::move(pref_service);
James Cookbbe5cb12017-08-08 18:32:211483
1484 for (auto& observer : shell_observers_)
Sam McNallya853cd82017-08-30 01:55:101485 observer.OnLocalStatePrefServiceInitialized(local_state_.get());
Sam McNallye36abbc2017-07-20 01:04:281486}
1487
[email protected]55f593352011-12-24 05:42:461488} // namespace ash