blob: 6907eda3bb1066e888f0d7d3c8a599430dc08d58 [file] [log] [blame]
[email protected]e0d22e82012-01-04 00:46:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]87b0d82e2011-10-07 21:02:592// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]b65bdda2011-12-23 23:35:315#include "ash/shell.h"
[email protected]87b0d82e2011-10-07 21:02:596
[email protected]f7eb89c2011-12-13 09:48:547#include <algorithm>
Mitsuru Oshima04b54d02017-10-09 14:22:458#include <memory>
[email protected]0039db92012-05-09 04:11:459#include <string>
dchengcbf0d9d2015-12-27 22:49:2310#include <utility>
[email protected]f7eb89c2011-12-13 09:48:5411
James Cookb0bf8e82017-04-09 17:01:4412#include "ash/accelerators/accelerator_controller.h"
[email protected]60d677d2014-05-30 13:07:0213#include "ash/accelerators/accelerator_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4414#include "ash/accelerators/ash_focus_manager_factory.h"
jamescook01bf23e72017-01-09 19:58:1515#include "ash/accelerators/magnifier_key_scroller.h"
16#include "ash/accelerators/spoken_feedback_toggler.h"
James Cookec144952017-09-01 00:05:1617#include "ash/accessibility/accessibility_controller.h"
James Cook37b7d102017-10-06 04:35:1918#include "ash/accessibility/accessibility_delegate.h"
sky15ef0aa2017-01-20 18:55:5919#include "ash/app_list/app_list_delegate_impl.h"
James Cookb0bf8e82017-04-09 17:01:4420#include "ash/ash_constants.h"
[email protected]55398d22013-10-10 19:49:2021#include "ash/autoclick/autoclick_controller.h"
James Cookb0bf8e82017-04-09 17:01:4422#include "ash/cast_config_controller.h"
Scott Violetd64dac12017-06-02 21:50:0823#include "ash/display/ash_display_controller.h"
[email protected]87ec2202014-02-06 06:24:2724#include "ash/display/cursor_window_controller.h"
jamescook01bf23e72017-01-09 19:58:1525#include "ash/display/display_color_manager_chromeos.h"
stevenjb537c5c3f2016-01-20 23:38:1226#include "ash/display/display_configuration_controller.h"
jamescook01bf23e72017-01-09 19:58:1527#include "ash/display/display_error_observer_chromeos.h"
Steven Bennetts7683e342018-01-02 21:29:5228#include "ash/display/display_shutdown_observer.h"
[email protected]682990f2013-01-10 06:49:1129#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2730#include "ash/display/mouse_cursor_event_filter.h"
Qiang Xud77a90c2018-02-20 19:43:2931#include "ash/display/persistent_window_controller.h"
jamescook01bf23e72017-01-09 19:58:1532#include "ash/display/projecting_observer_chromeos.h"
33#include "ash/display/resolution_notification_controller.h"
rjkroege2c9305402016-09-07 00:21:4534#include "ash/display/screen_ash.h"
jamescook01bf23e72017-01-09 19:58:1535#include "ash/display/screen_orientation_controller_chromeos.h"
[email protected]8d625fb2012-07-18 16:40:0636#include "ash/display/screen_position_controller.h"
oshimae2818922015-07-28 01:18:5237#include "ash/display/window_tree_host_manager.h"
[email protected]f4c92b382012-08-28 00:59:5938#include "ash/drag_drop/drag_drop_controller.h"
[email protected]59ccade2013-10-17 17:56:4039#include "ash/first_run/first_run_helper_impl.h"
James Cookb0bf8e82017-04-09 17:01:4440#include "ash/focus_cycler.h"
41#include "ash/frame/custom_frame_view_ash.h"
[email protected]f4c92b382012-08-28 00:59:5942#include "ash/high_contrast/high_contrast_controller.h"
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:3243#include "ash/highlighter/highlighter_controller.h"
Scott Violet596bb46342017-06-21 14:43:1344#include "ash/host/ash_window_tree_host_init_params.h"
James Cookbb026732017-06-09 23:01:5545#include "ash/ime/ime_controller.h"
James Cookb0bf8e82017-04-09 17:01:4446#include "ash/keyboard/keyboard_ui.h"
sammiequon203ae022016-09-18 17:23:4247#include "ash/laser/laser_pointer_controller.h"
Jacob Dufaultffd9b0d2017-11-15 23:07:1648#include "ash/login/login_screen_controller.h"
James Cookb0bf8e82017-04-09 17:01:4449#include "ash/login_status.h"
Ahmed Fakhry4bf3f742018-02-06 17:33:3650#include "ash/magnifier/docked_magnifier_controller.h"
[email protected]f4c92b382012-08-28 00:59:5951#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5452#include "ash/magnifier/partial_magnification_controller.h"
James Cookb0bf8e82017-04-09 17:01:4453#include "ash/media_controller.h"
Evan Stadee9974e22017-09-23 00:02:2654#include "ash/message_center/message_center_controller.h"
Scott Violet3c554ae2017-12-13 02:25:4155#include "ash/metrics/time_to_first_present_recorder.h"
James Cookb0bf8e82017-04-09 17:01:4456#include "ash/new_window_controller.h"
Vladislav Kaznacheev92edf62e2017-10-13 22:08:0157#include "ash/note_taking_controller.h"
Ahmed Fakhry4af48e42018-02-28 17:45:3858#include "ash/public/cpp/ash_features.h"
Evan Stade7d0e8232017-10-04 02:01:3659#include "ash/public/cpp/ash_switches.h"
sky494c6cbd2017-03-27 20:57:4860#include "ash/public/cpp/config.h"
msw109806d2017-06-02 20:11:5761#include "ash/public/cpp/shelf_model.h"
jamescook8800b8232016-10-19 12:46:2762#include "ash/public/cpp/shell_window_ids.h"
[email protected]d90b8392012-06-13 09:34:5663#include "ash/root_window_controller.h"
James Cook5e9d3402017-11-01 00:20:1264#include "ash/screenshot_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4465#include "ash/session/session_controller.h"
James Cook840177e2017-05-25 02:20:0166#include "ash/shelf/shelf.h"
James Cookb0bf8e82017-04-09 17:01:4467#include "ash/shelf/shelf_controller.h"
James Cookb0bf8e82017-04-09 17:01:4468#include "ash/shelf/shelf_window_watcher.h"
James Cookb0bf8e82017-04-09 17:01:4469#include "ash/shell_delegate.h"
[email protected]1b4c7472014-05-15 18:32:2370#include "ash/shell_init_params.h"
James Cookb0bf8e82017-04-09 17:01:4471#include "ash/shell_observer.h"
sky11cf8db92017-04-10 23:38:0872#include "ash/shell_port.h"
Scott Violet22a7b9212017-07-20 19:05:1973#include "ash/shell_port_classic.h"
James Cookb0bf8e82017-04-09 17:01:4474#include "ash/shutdown_controller.h"
jamescook01bf23e72017-01-09 19:58:1575#include "ash/sticky_keys/sticky_keys_controller.h"
James Cooka35a1e22017-04-08 02:33:0876#include "ash/system/bluetooth/bluetooth_notification_controller.h"
Sonny Sasaka55f69fc2017-08-28 21:29:3777#include "ash/system/bluetooth/bluetooth_power_controller.h"
James Cooka35a1e22017-04-08 02:33:0878#include "ash/system/bluetooth/tray_bluetooth_helper.h"
79#include "ash/system/brightness/brightness_controller_chromeos.h"
James Cookb0bf8e82017-04-09 17:01:4480#include "ash/system/brightness_control_delegate.h"
Lann Martinb9991402017-06-23 22:25:0881#include "ash/system/keyboard_brightness/keyboard_brightness_controller.h"
James Cookb0bf8e82017-04-09 17:01:4482#include "ash/system/keyboard_brightness_control_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4483#include "ash/system/locale/locale_notification_controller.h"
James Cooka35a1e22017-04-08 02:33:0884#include "ash/system/network/sms_observer.h"
85#include "ash/system/network/vpn_list.h"
afakhrye4fae852017-05-09 18:49:0686#include "ash/system/night_light/night_light_controller.h"
Sammie Quon4d7dba62017-08-03 23:18:1787#include "ash/system/palette/palette_tray.h"
Sammie Quon6c4e2b1f2017-10-13 16:54:1888#include "ash/system/palette/palette_welcome_bubble.h"
Toni Barzic9d0c82f42017-12-06 00:53:5289#include "ash/system/power/backlights_forced_off_setter.h"
Sammie Quon95c6a1c2017-09-12 19:16:5590#include "ash/system/power/peripheral_battery_notifier.h"
Qiang Xu0a86020f2017-10-12 08:34:5491#include "ash/system/power/power_button_controller.h"
James Cooka35a1e22017-04-08 02:33:0892#include "ash/system/power/power_event_observer.h"
93#include "ash/system/power/power_status.h"
94#include "ash/system/power/video_activity_notifier.h"
95#include "ash/system/screen_layout_observer.h"
James Cookdc041122017-08-01 14:03:2296#include "ash/system/session/logout_button_tray.h"
James Cooka35a1e22017-04-08 02:33:0897#include "ash/system/session/logout_confirmation_controller.h"
James Cookb0bf8e82017-04-09 17:01:4498#include "ash/system/status_area_widget.h"
99#include "ash/system/toast/toast_manager.h"
100#include "ash/system/tray/system_tray_controller.h"
James Cookb0bf8e82017-04-09 17:01:44101#include "ash/system/tray/system_tray_notifier.h"
James Cook98072352017-08-07 18:00:07102#include "ash/system/tray_caps_lock.h"
kylechar55f0eaf22017-01-11 22:57:37103#include "ash/touch/ash_touch_transform_controller.h"
Qiang Xuf1400a362017-09-14 02:28:30104#include "ash/touch/touch_devices_controller.h"
tbarzicc78da1ff92017-05-08 20:46:15105#include "ash/tray_action/tray_action.h"
oshima5a296e82016-04-29 01:32:27106#include "ash/utility/screenshot_controller.h"
jamescook01bf23e72017-01-09 19:58:15107#include "ash/virtual_keyboard_controller.h"
Yue Lia33960a2017-11-01 22:06:07108#include "ash/voice_interaction/voice_interaction_controller.h"
James Cookb0bf8e82017-04-09 17:01:44109#include "ash/wallpaper/wallpaper_controller.h"
[email protected]39718b52012-12-03 17:24:56110#include "ash/wm/ash_focus_rules.h"
James Cookb0bf8e82017-04-09 17:01:44111#include "ash/wm/container_finder.h"
[email protected]262f8bd2012-03-23 19:30:27112#include "ash/wm/event_client_impl.h"
James Cookb0bf8e82017-04-09 17:01:44113#include "ash/wm/immersive_context_ash.h"
skyb7b54092016-08-19 16:00:09114#include "ash/wm/immersive_handler_factory_ash.h"
[email protected]ab4f8c92013-05-30 19:07:47115#include "ash/wm/lock_state_controller.h"
James Cookb0bf8e82017-04-09 17:01:44116#include "ash/wm/mru_window_tracker.h"
erg36cfb952017-06-21 19:41:45117#include "ash/wm/native_cursor_manager_ash_classic.h"
118#include "ash/wm/native_cursor_manager_ash_mus.h"
[email protected]9ae32df2012-07-26 03:25:18119#include "ash/wm/overlay_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44120#include "ash/wm/overview/window_selector_controller.h"
[email protected]e4a181cc2012-03-17 02:20:57121#include "ash/wm/resize_shadow_controller.h"
James Cookb0bf8e82017-04-09 17:01:44122#include "ash/wm/root_window_finder.h"
hidehiko6821ca42016-06-18 11:12:23123#include "ash/wm/screen_pinning_controller.h"
xdaid4913762017-07-06 00:17:22124#include "ash/wm/splitview/split_view_controller.h"
[email protected]435b212e2012-04-05 19:43:37125#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:27126#include "ash/wm/system_modal_container_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44127#include "ash/wm/system_modal_container_layout_manager.h"
Mitsuru Oshima0e9b7a62017-07-19 18:23:03128#include "ash/wm/tablet_mode/tablet_mode_controller.h"
129#include "ash/wm/tablet_mode/tablet_mode_window_manager.h"
[email protected]3537d472014-01-15 05:45:31130#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:58131#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:02132#include "ash/wm/window_animations.h"
James Cookb0bf8e82017-04-09 17:01:44133#include "ash/wm/window_cycle_controller.h"
134#include "ash/wm/window_positioner.h"
[email protected]f059c6942012-07-21 14:27:57135#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:59136#include "ash/wm/window_util.h"
James Cookb0bf8e82017-04-09 17:01:44137#include "ash/wm/workspace_controller.h"
[email protected]f296be72011-10-11 15:40:00138#include "base/bind.h"
jamescook01bf23e72017-01-09 19:58:15139#include "base/bind_helpers.h"
jamescookfda159002016-10-21 18:48:57140#include "base/command_line.h"
dchenga94547472016-04-08 08:41:11141#include "base/memory/ptr_util.h"
jamescook01bf23e72017-01-09 19:58:15142#include "base/sys_info.h"
primiano7182d7b2015-01-30 18:02:03143#include "base/trace_event/trace_event.h"
jamescook01bf23e72017-01-09 19:58:15144#include "chromeos/chromeos_switches.h"
reveman24158982017-01-10 05:58:45145#include "chromeos/system/devicemode.h"
tibellb93c729b2017-03-30 00:45:09146#include "components/prefs/pref_registry_simple.h"
147#include "components/prefs/pref_service.h"
Saman Sami3fb310d2017-11-09 16:51:54148#include "components/viz/host/host_frame_sink_manager.h"
Ken Rockot388ba4fc2018-02-10 17:23:41149#include "mash/public/mojom/launchable.mojom.h"
tibellb93c729b2017-03-30 00:45:09150#include "services/preferences/public/cpp/pref_service_factory.h"
Ken Rockotf7f533e2018-02-11 02:21:33151#include "services/preferences/public/mojom/preferences.mojom.h"
derat94887a22017-01-20 18:17:25152#include "services/service_manager/public/cpp/connector.h"
153#include "services/ui/public/interfaces/constants.mojom.h"
sky7db5ccf2017-03-14 21:52:29154#include "ui/app_list/presenter/app_list.h"
[email protected]2c456102011-12-26 06:26:34155#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:44156#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:58157#include "ui/aura/layout_manager.h"
sky68612712017-04-27 04:45:04158#include "ui/aura/mus/focus_synchronizer.h"
derat94887a22017-01-20 18:17:25159#include "ui/aura/mus/user_activity_forwarder.h"
sky68612712017-04-27 04:45:04160#include "ui/aura/mus/window_tree_client.h"
[email protected]87b0d82e2011-10-07 21:02:59161#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:26162#include "ui/aura/window_event_dispatcher.h"
[email protected]2d4817742012-12-17 20:16:18163#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:17164#include "ui/base/user_activity/user_activity_detector.h"
jamescook01bf23e72017-01-09 19:58:15165#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]116302fc2012-05-05 21:45:41166#include "ui/compositor/layer.h"
167#include "ui/compositor/layer_animator.h"
oshimaf84b0da722016-04-27 19:47:19168#include "ui/display/display.h"
sky2f68b6f2017-05-21 16:08:39169#include "ui/display/manager/chromeos/default_touch_transform_setter.h"
jamescook01bf23e72017-01-09 19:58:15170#include "ui/display/manager/chromeos/display_change_observer.h"
171#include "ui/display/manager/chromeos/display_configurator.h"
sky7265b1cc2017-05-22 23:11:03172#include "ui/display/manager/chromeos/touch_transform_setter.h"
rjkroege72f8154f2016-10-29 00:49:02173#include "ui/display/manager/display_manager.h"
kylechar7e4f46f2017-10-31 23:26:57174#include "ui/display/mojo/dev_display_controller.mojom.h"
oshimaf84b0da722016-04-27 19:47:19175#include "ui/display/screen.h"
skycfaad892017-04-28 20:52:58176#include "ui/display/types/native_display_delegate.h"
[email protected]3e670aa2013-12-02 19:04:32177#include "ui/events/event_target_iterator.h"
sky4ec2be82017-01-06 17:38:32178#include "ui/gfx/geometry/insets.h"
[email protected]9ec0f452012-05-31 15:58:53179#include "ui/gfx/image/image_skia.h"
[email protected]b6ba05d902013-10-04 21:38:45180#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28181#include "ui/keyboard/keyboard_switches.h"
yhanada8909a542017-07-11 10:06:19182#include "ui/keyboard/keyboard_ui.h"
[email protected]f1d5c3a2013-04-23 17:42:56183#include "ui/keyboard/keyboard_util.h"
[email protected]d7f30a72013-10-05 05:09:41184#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04185#include "ui/views/corewm/tooltip_controller.h"
sky07a24d42017-03-09 23:57:30186#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:58187#include "ui/views/widget/native_widget_aura.h"
188#include "ui/views/widget/widget.h"
[email protected]60d677d2014-05-30 13:07:02189#include "ui/wm/core/accelerator_filter.h"
[email protected]ee3ed10772014-03-11 22:02:01190#include "ui/wm/core/compound_event_filter.h"
191#include "ui/wm/core/focus_controller.h"
[email protected]ee3ed10772014-03-11 22:02:01192#include "ui/wm/core/shadow_controller.h"
193#include "ui/wm/core/visibility_controller.h"
194#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59195
[email protected]55f593352011-12-24 05:42:46196namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59197
198namespace {
[email protected]671a2ae2011-10-13 21:53:23199
[email protected]615922f2012-02-07 02:41:15200using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45201using views::Widget;
202
jamescook518dccbd2017-05-18 04:57:07203bool g_is_browser_process_with_mash = false;
204
[email protected]b5756e22012-11-30 01:32:02205// A Corewm VisibilityController subclass that calls the Ash animation routine
206// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14207class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02208 public:
Chris Watkinsc24daf62017-11-28 03:43:09209 AshVisibilityController() = default;
210 ~AshVisibilityController() override = default;
[email protected]b5756e22012-11-30 01:32:02211
212 private:
[email protected]e319c7e2014-03-14 19:56:14213 // Overridden from ::wm::VisibilityController:
dcheng1f4538e2014-10-27 23:57:05214 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
215 bool visible) override {
[email protected]b5756e22012-11-30 01:32:02216 return AnimateOnChildWindowVisibilityChanged(window, visible);
217 }
218
219 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
220};
221
[email protected]87b0d82e2011-10-07 21:02:59222} // namespace
223
[email protected]cac10fc62011-10-07 23:22:56224// static
achuith287b26e2015-09-03 17:49:18225Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13226// static
sky00f98a372017-01-11 06:03:49227aura::WindowTreeClient* Shell::window_tree_client_ = nullptr;
228// static
skya8b222f2017-01-12 15:47:13229aura::WindowManagerClient* Shell::window_manager_client_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13230
231////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56232// Shell, public:
233
[email protected]cac10fc62011-10-07 23:22:56234// static
Scott Violetc8a1c6c2017-11-29 23:17:36235Shell* Shell::CreateInstance(ShellInitParams init_params) {
[email protected]3266c2b92011-11-14 00:06:08236 CHECK(!instance_);
Scott Violetc8a1c6c2017-11-29 23:17:36237 instance_ = new Shell(std::move(init_params.delegate),
238 std::move(init_params.shell_port));
239 instance_->Init(init_params.context_factory,
240 init_params.context_factory_private);
[email protected]3266c2b92011-11-14 00:06:08241 return instance_;
242}
243
244// static
skyb073203a2017-03-13 16:59:16245Shell* Shell::Get() {
jamescook518dccbd2017-05-18 04:57:07246 CHECK(!g_is_browser_process_with_mash) // Implies null |instance_|.
247 << "Ash is running in its own process so Shell::Get() will return null. "
248 "The browser process must use the mojo interfaces in //ash/public to "
249 "access ash. See ash/README.md for details.";
oshima9eea82da2014-09-13 01:11:07250 CHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56251 return instance_;
252}
253
[email protected]6377a002011-11-10 20:26:47254// static
[email protected]b3b7bcd2012-03-06 19:35:45255bool Shell::HasInstance() {
256 return !!instance_;
257}
258
259// static
[email protected]ef589af2011-12-03 01:07:15260void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47261 delete instance_;
[email protected]6377a002011-11-10 20:26:47262}
263
[email protected]e73bd7802012-02-17 20:10:34264// static
[email protected]093b8d642014-04-03 20:59:28265RootWindowController* Shell::GetPrimaryRootWindowController() {
oshima9eea82da2014-09-13 01:11:07266 CHECK(HasInstance());
msw257a6a232017-06-01 01:46:30267 return RootWindowController::ForWindow(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23268}
269
270// static
271Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
oshima9eea82da2014-09-13 01:11:07272 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34273 RootWindowControllerList root_window_controllers;
msw257a6a232017-06-01 01:46:30274 for (aura::Window* root : GetAllRootWindows())
275 root_window_controllers.push_back(RootWindowController::ForWindow(root));
skyabcae812017-01-18 17:01:34276 return root_window_controllers;
[email protected]d90b8392012-06-13 09:34:56277}
278
279// static
thanhphc90f49ca2017-03-03 17:48:53280RootWindowController* Shell::GetRootWindowControllerWithDisplayId(
281 int64_t display_id) {
282 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13283 aura::Window* root = GetRootWindowForDisplayId(display_id);
msw257a6a232017-06-01 01:46:30284 return root ? RootWindowController::ForWindow(root) : nullptr;
thanhphc90f49ca2017-03-03 17:48:53285}
286
287// static
Scott Violet596bb46342017-06-21 14:43:13288aura::Window* Shell::GetRootWindowForDisplayId(int64_t display_id) {
289 CHECK(HasInstance());
290 return instance_->window_tree_host_manager_->GetRootWindowForDisplayId(
291 display_id);
292}
293
294// static
[email protected]bf9cdb362013-10-25 19:22:45295aura::Window* Shell::GetPrimaryRootWindow() {
oshima9eea82da2014-09-13 01:11:07296 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13297 return instance_->window_tree_host_manager_->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34298}
299
[email protected]7b0f7502012-06-11 00:12:39300// static
sky27344382017-03-08 21:30:32301aura::Window* Shell::GetRootWindowForNewWindows() {
302 CHECK(Shell::HasInstance());
skycb4be5b2017-04-06 17:52:45303 Shell* shell = Shell::Get();
sky27344382017-03-08 21:30:32304 if (shell->scoped_root_window_for_new_windows_)
305 return shell->scoped_root_window_for_new_windows_;
306 return shell->root_window_for_new_windows_;
mfomitcheva1a8aa62016-05-03 16:23:26307}
308
309// static
[email protected]c9390bd2013-11-08 20:33:13310aura::Window::Windows Shell::GetAllRootWindows() {
oshima9eea82da2014-09-13 01:11:07311 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13312 return instance_->window_tree_host_manager_->GetAllRootWindows();
[email protected]be65be362012-06-15 07:38:23313}
314
315// static
jamescookb8dcef522016-06-25 14:42:55316aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) {
[email protected]7b0f7502012-06-11 00:12:39317 return root_window->GetChildById(container_id);
318}
319
320// static
[email protected]bf9cdb362013-10-25 19:22:45321const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38322 int container_id) {
323 return root_window->GetChildById(container_id);
324}
325
sky494c6cbd2017-03-27 20:57:48326// static
James Cook7b7c6a52018-01-04 23:40:03327int Shell::GetOpenSystemModalWindowContainerId() {
328 // The test boolean is not static to avoid leaking state between tests.
329 if (Get()->simulate_modal_window_open_for_test_)
330 return kShellWindowId_SystemModalContainer;
331
332 // Traverse all system modal containers, and find its direct child window
333 // with "SystemModal" setting, and visible.
334 // Note: LockSystemModalContainer is more restrictive, so make it preferable
335 // to SystemModalCotainer.
336 constexpr int modal_window_ids[] = {kShellWindowId_LockSystemModalContainer,
337 kShellWindowId_SystemModalContainer};
338 for (aura::Window* root : Shell::GetAllRootWindows()) {
339 for (int modal_window_id : modal_window_ids) {
340 aura::Window* system_modal = root->GetChildById(modal_window_id);
341 if (!system_modal)
342 continue;
343 for (const aura::Window* child : system_modal->children()) {
344 if (child->GetProperty(aura::client::kModalKey) ==
345 ui::MODAL_TYPE_SYSTEM &&
346 child->layer()->GetTargetVisibility()) {
347 return modal_window_id;
348 }
349 }
350 }
351 }
352 return -1;
353}
354
355// static
356bool Shell::IsSystemModalWindowOpen() {
357 return GetOpenSystemModalWindowContainerId() >= 0;
358}
359
360// static
jamescook0dfe5632017-04-05 18:49:02361Config Shell::GetAshConfig() {
sky11cf8db92017-04-10 23:38:08362 return Get()->shell_port_->GetAshConfig();
sky494c6cbd2017-03-27 20:57:48363}
364
moshayedic229a522017-05-05 18:14:26365// static
366bool Shell::ShouldUseIMEService() {
367 return Shell::GetAshConfig() == Config::MASH ||
368 (Shell::GetAshConfig() == Config::MUS &&
369 base::CommandLine::ForCurrentProcess()->HasSwitch(
370 switches::kUseIMEService));
371}
372
afakhrye4fae852017-05-09 18:49:06373// static
Wenzhao Zang56c292932017-08-02 04:58:34374void Shell::RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
Sammie Quon4d7dba62017-08-03 23:18:17375 PaletteTray::RegisterLocalStatePrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34376 WallpaperController::RegisterLocalStatePrefs(registry);
Sonny Sasaka55f69fc2017-08-28 21:29:37377 BluetoothPowerController::RegisterLocalStatePrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34378}
379
380// static
James Cookec144952017-09-01 00:05:16381void Shell::RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) {
382 AccessibilityController::RegisterProfilePrefs(registry, for_test);
Sonny Sasaka55f69fc2017-08-28 21:29:37383 BluetoothPowerController::RegisterProfilePrefs(registry);
Ahmed Fakhry4bf3f742018-02-06 17:33:36384 DockedMagnifierController::RegisterProfilePrefs(registry);
Jacob Dufaultffd9b0d2017-11-15 23:07:16385 LoginScreenController::RegisterProfilePrefs(registry, for_test);
Sammie Quon6c4e2b1f2017-10-13 16:54:18386 LogoutButtonTray::RegisterProfilePrefs(registry);
387 NightLightController::RegisterProfilePrefs(registry);
Vladislav Kaznacheevfefa6bd2017-10-14 00:25:24388 PaletteTray::RegisterProfilePrefs(registry);
Sammie Quon6c4e2b1f2017-10-13 16:54:18389 PaletteWelcomeBubble::RegisterProfilePrefs(registry);
390 ShelfController::RegisterProfilePrefs(registry);
Qiang Xuf1400a362017-09-14 02:28:30391 TouchDevicesController::RegisterProfilePrefs(registry);
Sammie Quon6c4e2b1f2017-10-13 16:54:18392 TrayCapsLock::RegisterProfilePrefs(registry, for_test);
afakhrye4fae852017-05-09 18:49:06393}
394
[email protected]57b8bb352012-01-11 05:11:46395views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
396 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04397 // Use translucent-style window frames for dialogs.
[email protected]85501fe2013-10-18 10:15:27398 return new CustomFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46399}
400
[email protected]2e236a52012-06-27 22:21:47401void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44402 const gfx::Insets& insets) {
Scott Violet596bb46342017-06-21 14:43:13403 window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow(contains,
404 insets);
[email protected]1a2145b2012-03-13 21:09:17405}
406
[email protected]58868abf2014-01-17 23:45:33407void Shell::OnCastingSessionStartedOrStopped(bool started) {
sky00c813f2017-03-08 22:48:55408 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18409 observer.OnCastingSessionStartedOrStopped(started);
[email protected]58868abf2014-01-17 23:45:33410}
411
varkhac71444e52017-05-25 22:51:34412void Shell::OnRootWindowAdded(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55413 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18414 observer.OnRootWindowAdded(root_window);
[email protected]0e3e7cb2014-04-12 05:18:25415}
416
[email protected]51f438112013-11-18 19:32:50417void Shell::CreateKeyboard() {
Keigo Okae82281a2017-06-14 13:59:14418 if (keyboard::IsKeyboardEnabled()) {
419 if (keyboard::KeyboardController::GetInstance()) {
420 RootWindowControllerList controllers = GetAllRootWindowControllers();
421 for (RootWindowControllerList::iterator iter = controllers.begin();
422 iter != controllers.end(); ++iter) {
423 (*iter)->DeactivateKeyboard(
424 keyboard::KeyboardController::GetInstance());
425 }
426 }
427 keyboard::KeyboardController::ResetInstance(
428 new keyboard::KeyboardController(shell_delegate_->CreateKeyboardUI(),
429 virtual_keyboard_controller_.get()));
430 for (auto& observer : shell_observers_)
431 observer.OnKeyboardControllerCreated();
432 }
433
jamescookb8dcef522016-06-25 14:42:55434 GetPrimaryRootWindowController()->ActivateKeyboard(
435 keyboard::KeyboardController::GetInstance());
[email protected]51f438112013-11-18 19:32:50436}
437
Keigo Okac7617a42017-06-14 11:33:24438void Shell::DestroyKeyboard() {
sky11cf8db92017-04-10 23:38:08439 // TODO(jamescook): Move keyboard create and hide into ShellPort.
sky79fa34712017-03-20 23:46:47440 keyboard_ui_->Hide();
[email protected]a0b3fb882014-04-07 19:26:03441 if (keyboard::KeyboardController::GetInstance()) {
[email protected]e1b299b2014-01-29 23:53:41442 RootWindowControllerList controllers = GetAllRootWindowControllers();
443 for (RootWindowControllerList::iterator iter = controllers.begin();
jamescookb8dcef522016-06-25 14:42:55444 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:03445 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]e1b299b2014-01-29 23:53:41446 }
447 }
achuith287b26e2015-09-03 17:49:18448 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]e1b299b2014-01-29 23:53:41449}
450
[email protected]da285852014-05-27 19:53:43451bool Shell::ShouldSaveDisplaySettings() {
Steven Bennetts7614ab52018-01-12 20:48:17452 // This function is only called from Chrome, hence the DCHECK for not-MASH.
453 DCHECK(GetAshConfig() != Config::MASH);
jamescookb8dcef522016-06-25 14:42:55454 return !(
455 screen_orientation_controller_->ignore_display_configuration_updates() ||
456 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43457}
[email protected]da285852014-05-27 19:53:43458
Ahmed Fakhry4bf3f742018-02-06 17:33:36459DockedMagnifierController* Shell::docked_magnifier_controller() {
Ahmed Fakhry4af48e42018-02-28 17:45:38460 DCHECK(features::IsDockedMagnifierEnabled());
Ahmed Fakhry4bf3f742018-02-06 17:33:36461 return docked_magnifier_controller_.get();
462}
463
afakhry9e0a18b32017-06-05 19:23:14464NightLightController* Shell::night_light_controller() {
Evan Stade48768f42017-10-10 05:23:30465 DCHECK(switches::IsNightLightEnabled());
afakhry9e0a18b32017-06-05 19:23:14466 return night_light_controller_.get();
467}
468
sky5ad143a2017-03-22 04:31:23469ShelfModel* Shell::shelf_model() {
470 return shelf_controller_->model();
471}
472
Thiago Farina3b086a02017-05-30 22:32:50473::wm::ActivationClient* Shell::activation_client() {
sky27344382017-03-08 21:30:32474 return focus_controller_.get();
475}
476
[email protected]c758fbf2012-03-25 22:53:59477void Shell::UpdateShelfVisibility() {
msw257a6a232017-06-01 01:46:30478 for (aura::Window* root : GetAllRootWindows())
479 Shelf::ForWindow(root)->UpdateVisibilityState();
[email protected]c758fbf2012-03-25 22:53:59480}
481
Wenzhao Zang44240fb2017-07-13 01:36:54482PrefService* Shell::GetLocalStatePrefService() const {
Sam McNallya853cd82017-08-30 01:55:10483 return local_state_.get();
Wenzhao Zang44240fb2017-07-13 01:36:54484}
485
[email protected]88d71122012-10-18 07:11:01486WebNotificationTray* Shell::GetWebNotificationTray() {
jamescook612205f2016-05-26 06:02:11487 return GetPrimaryRootWindowController()
jamescookb551aba2016-09-01 01:00:16488 ->GetStatusAreaWidget()
jamescook612205f2016-05-26 06:02:11489 ->web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28490}
491
[email protected]a0afeb12012-12-10 22:57:09492bool Shell::HasPrimaryStatusArea() {
jamescookb551aba2016-09-01 01:00:16493 return !!GetPrimaryRootWindowController()->GetStatusAreaWidget();
[email protected]31f19e32012-10-30 22:31:23494}
495
[email protected]a0afeb12012-12-10 22:57:09496SystemTray* Shell::GetPrimarySystemTray() {
497 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42498}
499
mswa7e8a5f2016-03-01 04:15:06500FirstRunHelper* Shell::CreateFirstRunHelper() {
501 return new FirstRunHelperImpl;
[email protected]59ccade2013-10-17 17:56:40502}
[email protected]87ec2202014-02-06 06:24:27503
yawanodc5533b32017-02-23 11:04:38504void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
505 window_tree_host_manager_->cursor_window_controller()
506 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
507}
508
Weidong Guod07448f2017-10-18 03:35:18509void Shell::UpdateCursorCompositingEnabled() {
510 SetCursorCompositingEnabled(
511 window_tree_host_manager_->cursor_window_controller()
512 ->ShouldEnableCursorCompositing());
513}
514
[email protected]87ec2202014-02-06 06:24:27515void Shell::SetCursorCompositingEnabled(bool enabled) {
erg36cfb952017-06-21 19:41:45516 if (GetAshConfig() != Config::MASH) {
517 // TODO: needs to work in mash. http://crbug.com/705592.
Weidong Guo7dfd1482017-11-08 05:56:28518 CursorWindowController* cursor_window_controller =
519 window_tree_host_manager_->cursor_window_controller();
520
521 if (cursor_window_controller->is_cursor_compositing_enabled() == enabled)
522 return;
523 cursor_window_controller->SetCursorCompositingEnabled(enabled);
sky494c6cbd2017-03-27 20:57:48524 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
525 }
[email protected]87ec2202014-02-06 06:24:27526}
[email protected]59ccade2013-10-17 17:56:40527
[email protected]f9466702012-09-17 16:35:27528void Shell::DoInitialWorkspaceAnimation() {
jamescookb8dcef522016-06-25 14:42:55529 return GetPrimaryRootWindowController()
530 ->workspace_controller()
531 ->DoInitialAnimation();
[email protected]f9466702012-09-17 16:35:27532}
533
xdaid4913762017-07-06 00:17:22534bool Shell::IsSplitViewModeActive() const {
535 return split_view_controller_->IsSplitViewModeActive();
536}
537
sky00c813f2017-03-08 22:48:55538void Shell::AddShellObserver(ShellObserver* observer) {
539 shell_observers_.AddObserver(observer);
540}
541
542void Shell::RemoveShellObserver(ShellObserver* observer) {
543 shell_observers_.RemoveObserver(observer);
544}
545
sky5ad143a2017-03-22 04:31:23546void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
varkha59679632017-06-01 00:42:05547 for (auto* root_window_controller : GetAllRootWindowControllers())
548 root_window_controller->UpdateAfterLoginStatusChange(status);
sky5ad143a2017-03-22 04:31:23549}
550
sky00c813f2017-03-08 22:48:55551void Shell::NotifyOverviewModeStarting() {
552 for (auto& observer : shell_observers_)
553 observer.OnOverviewModeStarting();
554}
555
Xiaoqian Daifb4698ed2018-02-23 20:11:06556void Shell::NotifyOverviewModeEnding() {
557 for (auto& observer : shell_observers_)
558 observer.OnOverviewModeEnding();
559}
560
sky00c813f2017-03-08 22:48:55561void Shell::NotifyOverviewModeEnded() {
562 for (auto& observer : shell_observers_)
563 observer.OnOverviewModeEnded();
564}
565
xdaid4913762017-07-06 00:17:22566void Shell::NotifySplitViewModeStarting() {
567 for (auto& observer : shell_observers_)
568 observer.OnSplitViewModeStarting();
569}
570
571void Shell::NotifySplitViewModeEnded() {
572 for (auto& observer : shell_observers_)
573 observer.OnSplitViewModeEnded();
574}
575
sky00c813f2017-03-08 22:48:55576void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
varkhac71444e52017-05-25 22:51:34577 aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55578 for (auto& observer : shell_observers_)
579 observer.OnFullscreenStateChanged(is_fullscreen, root_window);
580}
581
varkha19d7e6c52017-05-25 21:15:30582void Shell::NotifyPinnedStateChanged(aura::Window* pinned_window) {
sky00c813f2017-03-08 22:48:55583 for (auto& observer : shell_observers_)
584 observer.OnPinnedStateChanged(pinned_window);
585}
586
xiyuan38160182017-03-14 22:50:13587void Shell::NotifyVirtualKeyboardActivated(bool activated,
sky97f9a7432017-05-09 05:14:31588 aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55589 for (auto& observer : shell_observers_)
xiyuan38160182017-03-14 22:50:13590 observer.OnVirtualKeyboardStateChanged(activated, root_window);
sky00c813f2017-03-08 22:48:55591}
592
varkha6b016b0f2017-05-26 16:14:18593void Shell::NotifyShelfCreatedForRootWindow(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55594 for (auto& observer : shell_observers_)
595 observer.OnShelfCreatedForRootWindow(root_window);
596}
597
varkha6b016b0f2017-05-26 16:14:18598void Shell::NotifyShelfAlignmentChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55599 for (auto& observer : shell_observers_)
600 observer.OnShelfAlignmentChanged(root_window);
601}
602
varkha6b016b0f2017-05-26 16:14:18603void Shell::NotifyShelfAutoHideBehaviorChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55604 for (auto& observer : shell_observers_)
605 observer.OnShelfAutoHideBehaviorChanged(root_window);
606}
607
jamescook518dccbd2017-05-18 04:57:07608// static
609void Shell::SetIsBrowserProcessWithMash() {
610 g_is_browser_process_with_mash = true;
611}
612
muyuanlid766f2e2017-06-26 20:17:19613void Shell::NotifyAppListVisibilityChanged(bool visible,
614 aura::Window* root_window) {
newcomer2febb9832017-06-12 17:00:23615 for (auto& observer : shell_observers_)
616 observer.OnAppListVisibilityChanged(visible, root_window);
617}
618
[email protected]b6ba05d902013-10-04 21:38:45619////////////////////////////////////////////////////////////////////////////////
620// Shell, private:
621
skyb073203a2017-03-13 16:59:16622Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
sky11cf8db92017-04-10 23:38:08623 std::unique_ptr<ShellPort> shell_port)
624 : shell_port_(std::move(shell_port)),
Mitsuru Oshima04b54d02017-10-09 14:22:45625 ash_display_controller_(std::make_unique<AshDisplayController>()),
sky79fa34712017-03-20 23:46:47626 brightness_control_delegate_(
Mitsuru Oshima04b54d02017-10-09 14:22:45627 std::make_unique<system::BrightnessControllerChromeos>()),
628 cast_config_(std::make_unique<CastConfigController>()),
629 focus_cycler_(std::make_unique<FocusCycler>()),
630 ime_controller_(std::make_unique<ImeController>()),
631 immersive_context_(std::make_unique<ImmersiveContextAsh>()),
sky79fa34712017-03-20 23:46:47632 keyboard_brightness_control_delegate_(
Mitsuru Oshima04b54d02017-10-09 14:22:45633 std::make_unique<KeyboardBrightnessController>()),
sky79fa34712017-03-20 23:46:47634 locale_notification_controller_(
Mitsuru Oshima04b54d02017-10-09 14:22:45635 std::make_unique<LocaleNotificationController>()),
Jacob Dufaultffd9b0d2017-11-15 23:07:16636 login_screen_controller_(std::make_unique<LoginScreenController>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45637 media_controller_(std::make_unique<MediaController>()),
638 new_window_controller_(std::make_unique<NewWindowController>()),
639 session_controller_(std::make_unique<SessionController>(
Sam McNallyf4dab612017-08-16 03:06:33640 shell_delegate->GetShellConnector())),
Vladislav Kaznacheev92edf62e2017-10-13 22:08:01641 note_taking_controller_(std::make_unique<NoteTakingController>()),
skyb073203a2017-03-13 16:59:16642 shell_delegate_(std::move(shell_delegate)),
Mitsuru Oshima04b54d02017-10-09 14:22:45643 shutdown_controller_(std::make_unique<ShutdownController>()),
644 system_tray_controller_(std::make_unique<SystemTrayController>()),
645 system_tray_notifier_(std::make_unique<SystemTrayNotifier>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45646 vpn_list_(std::make_unique<VpnList>()),
647 window_cycle_controller_(std::make_unique<WindowCycleController>()),
648 window_selector_controller_(std::make_unique<WindowSelectorController>()),
649 app_list_(std::make_unique<app_list::AppList>()),
650 tray_bluetooth_helper_(std::make_unique<TrayBluetoothHelper>()),
kylechar7a067ec2017-01-07 01:16:28651 display_configurator_(new display::DisplayConfigurator()),
sadrul7a8785e2016-02-12 21:54:35652 native_cursor_manager_(nullptr),
Sam McNallye36abbc2017-07-20 01:04:28653 weak_factory_(this) {
skyabcae812017-01-18 17:01:34654 // TODO(sky): better refactor cash/mash dependencies. Perhaps put all cash
sky11cf8db92017-04-10 23:38:08655 // state on ShellPortClassic. http://crbug.com/671246.
skyabcae812017-01-18 17:01:34656
Scott Violet596bb46342017-06-21 14:43:13657 display_manager_.reset(ScreenAsh::CreateDisplayManager());
Mitsuru Oshima04b54d02017-10-09 14:22:45658 window_tree_host_manager_ = std::make_unique<WindowTreeHostManager>();
659 user_metrics_recorder_ = std::make_unique<UserMetricsRecorder>();
[email protected]b6ba05d902013-10-04 21:38:45660
[email protected]093b8d642014-04-03 20:59:28661 PowerStatus::Initialize();
sky5ad143a2017-03-22 04:31:23662
Xiyuan Xia22b1a6c2017-04-18 22:46:01663 session_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45664}
665
666Shell::~Shell() {
667 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
668
sky11cf8db92017-04-10 23:38:08669 const Config config = shell_port_->GetAshConfig();
skyabcae812017-01-18 17:01:34670
Scott Violet41562d1c2017-06-26 15:15:48671 user_metrics_recorder_->OnShellShuttingDown();
bruthigc24d11f2015-06-09 21:30:03672
Steven Bennetts7614ab52018-01-12 20:48:17673 shell_delegate_->PreShutdown();
[email protected]050e77182014-03-25 15:29:16674
[email protected]b6ba05d902013-10-04 21:38:45675 // Remove the focus from any window. This will prevent overhead and side
676 // effects (e.g. crashes) from changing focus during shutdown.
677 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18678 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45679
xdaid4913762017-07-06 00:17:22680 // Please keep in reverse order as in Init() because it's easy to miss one.
[email protected]b6ba05d902013-10-04 21:38:45681 if (window_modality_controller_)
682 window_modality_controller_.reset();
jamescook01bf23e72017-01-09 19:58:15683
[email protected]e4ea52362014-02-15 03:21:06684 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
685 magnifier_key_scroll_handler_.reset();
686
687 RemovePreTargetHandler(speech_feedback_handler_.get());
688 speech_feedback_handler_.reset();
jamescook01bf23e72017-01-09 19:58:15689
[email protected]b6ba05d902013-10-04 21:38:45690 RemovePreTargetHandler(overlay_filter_.get());
Xiyuan Xia22b1a6c2017-04-18 22:46:01691 overlay_filter_.reset();
692
[email protected]3537d472014-01-15 05:45:31693 RemovePreTargetHandler(accelerator_filter_.get());
694 RemovePreTargetHandler(event_transformation_handler_.get());
695 RemovePreTargetHandler(toplevel_window_event_handler_.get());
696 RemovePostTargetHandler(toplevel_window_event_handler_.get());
Scott Violet596bb46342017-06-21 14:43:13697 RemovePreTargetHandler(system_gesture_filter_.get());
698 RemovePreTargetHandler(mouse_cursor_filter_.get());
hariank0dd03dd2016-07-14 23:47:33699 RemovePreTargetHandler(modality_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45700
701 // TooltipController is deleted with the Shell so removing its references.
702 RemovePreTargetHandler(tooltip_controller_.get());
703
jonross0af45212015-01-13 18:55:46704 screen_orientation_controller_.reset();
yiyixa68ade512016-09-01 17:38:13705 screen_layout_observer_.reset();
jonross0af45212015-01-13 18:55:46706
Mitsuru Oshima0e9b7a62017-07-19 18:23:03707 // Destroy the virtual keyboard controller before the tablet mode controller
jamescook01bf23e72017-01-09 19:58:15708 // since the latters destructor triggers events that the former is listening
709 // to but no longer cares about.
rsadambbaf2c82015-01-07 17:54:13710 virtual_keyboard_controller_.reset();
jonross0af45212015-01-13 18:55:46711
Mitsuru Oshima0e9b7a62017-07-19 18:23:03712 // Destroy tablet mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57713 // need to be removed.
Mitsuru Oshima0e9b7a62017-07-19 18:23:03714 tablet_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57715
jdufault551152e2016-01-27 19:48:43716 // Destroy the keyboard before closing the shelf, since it will invoke a shelf
717 // layout.
Keigo Okac7617a42017-06-14 11:33:24718 DestroyKeyboard();
jdufault551152e2016-01-27 19:48:43719
sky07a24d42017-03-09 23:57:30720 toast_manager_.reset();
yoshiki32f51632016-03-24 01:24:43721
msw257a6a232017-06-01 01:46:30722 for (aura::Window* root : GetAllRootWindows())
723 Shelf::ForWindow(root)->ShutdownShelfWidget();
jamescookac6724332017-03-21 02:54:43724 tray_bluetooth_helper_.reset();
James Cookb50959e22017-08-10 20:24:38725
726 // Accesses root window containers.
727 logout_confirmation_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45728
[email protected]b6ba05d902013-10-04 21:38:45729 // Drag-and-drop must be canceled prior to close all windows.
730 drag_drop_controller_.reset();
731
Xiyuan Xia22b1a6c2017-04-18 22:46:01732 // Controllers who have WindowObserver added must be deleted
733 // before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03734
Qiang Xud77a90c2018-02-20 19:43:29735 persistent_window_controller_.reset();
736
[email protected]8c9d12a2013-12-06 18:39:03737 // VideoActivityNotifier must be deleted before |video_detector_| is
738 // deleted because it's observing video activity through
derat83b761392016-07-11 16:44:44739 // VideoDetector::Observer interface.
[email protected]8c9d12a2013-12-06 18:39:03740 video_activity_notifier_.reset();
[email protected]8c9d12a2013-12-06 18:39:03741 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25742 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03743
744 shadow_controller_.reset();
745 resize_shadow_controller_.reset();
746
sky37f0dd12016-07-19 18:00:59747 // Has to happen before ~MruWindowTracker.
sky5b45ed82017-03-27 02:54:23748 window_cycle_controller_.reset();
749 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03750
xdai7a8867cd2017-08-25 23:10:16751 // |split_view_controller_| needs to be deleted after
752 // |window_selector_controller_|.
753 split_view_controller_.reset();
754
skyabcae812017-01-18 17:01:34755 CloseAllRootWindowChildWindows();
756
afakhry58159392015-05-22 02:45:52757 // MruWindowTracker must be destroyed after all windows have been deleted to
758 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
759 // path. (crbug.com/485438).
sky5ab16472017-03-21 19:35:08760 mru_window_tracker_.reset();
[email protected]b6ba05d902013-10-04 21:38:45761
[email protected]b6ba05d902013-10-04 21:38:45762 // These need a valid Shell instance to clean up properly, so explicitly
763 // delete them before invalidating the instance.
764 // Alphabetical. TODO(oshima): sort.
765 magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45766 tooltip_controller_.reset();
767 event_client_.reset();
[email protected]3537d472014-01-15 05:45:31768 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45769 visibility_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45770
Toni Barzic85ae39e2017-12-07 05:50:18771 tray_action_.reset();
772
[email protected]b6ba05d902013-10-04 21:38:45773 power_button_controller_.reset();
774 lock_state_controller_.reset();
Toni Barzic9d0c82f42017-12-06 00:53:52775 backlights_forced_off_setter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45776
hidehiko6821ca42016-06-18 11:12:23777 screen_pinning_controller_.reset();
778
[email protected]b6ba05d902013-10-04 21:38:45779 resolution_notification_controller_.reset();
oshima5a296e82016-04-29 01:32:27780 screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49781 mouse_cursor_filter_.reset();
hariank0dd03dd2016-07-14 23:47:33782 modality_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45783
[email protected]03122891a2014-05-13 23:56:49784 touch_transformer_controller_.reset();
sammiequon203ae022016-09-18 17:23:42785 laser_pointer_controller_.reset();
786 partial_magnification_controller_.reset();
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:32787 highlighter_controller_.reset();
Yue Lia33960a2017-11-01 22:06:07788 voice_interaction_controller_.reset();
warx533c8f62016-04-12 01:19:43789
[email protected]b6ba05d902013-10-04 21:38:45790 // This also deletes all RootWindows. Note that we invoke Shutdown() on
oshimae2818922015-07-28 01:18:52791 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
msw257a6a232017-06-01 01:46:30792 // destruction of its owned RootWindowControllers relies on the value.
rjkroege2c9305402016-09-07 00:21:45793 ScreenAsh::CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12794 display_configuration_controller_.reset();
dtseng4ae0a882016-04-15 21:39:27795
sky15ef0aa2017-01-20 18:55:59796 // AppListDelegateImpl depends upon AppList.
797 app_list_delegate_impl_.reset();
798
sky07a24d42017-03-09 23:57:30799 // These members access Shell in their destructors.
800 wallpaper_controller_.reset();
James Cookec144952017-09-01 00:05:16801 accessibility_controller_.reset();
sky07a24d42017-03-09 23:57:30802 accessibility_delegate_.reset();
Evan Stade4d07c422017-09-01 21:51:51803 message_center_controller_.reset();
sky07a24d42017-03-09 23:57:30804
805 // Balances the Install() in Initialize().
806 views::FocusManagerFactory::Install(nullptr);
807
sky5ad143a2017-03-22 04:31:23808 // ShelfWindowWatcher has window observers and a pointer to the shelf model.
809 shelf_window_watcher_.reset();
810
tibellb93c729b2017-03-30 00:45:09811 // Removes itself as an observer of |pref_service_|.
sky5ad143a2017-03-22 04:31:23812 shelf_controller_.reset();
813
Ahmed Fakhrye96051f2017-12-12 17:42:17814 // NightLightController depends on the PrefService as well as the window tree
815 // host manager, and must be destructed before them. crbug.com/724231.
816 night_light_controller_ = nullptr;
Ahmed Fakhry4bf3f742018-02-06 17:33:36817 // Similarly for DockedMagnifierController.
818 docked_magnifier_controller_ = nullptr;
Ahmed Fakhrye96051f2017-12-12 17:42:17819
sky11cf8db92017-04-10 23:38:08820 shell_port_->Shutdown();
Scott Violet596bb46342017-06-21 14:43:13821 window_tree_host_manager_->Shutdown();
sky5ad143a2017-03-22 04:31:23822
sky27344382017-03-08 21:30:32823 // Depends on |focus_controller_|, so must be destroyed before.
oshimae2818922015-07-28 01:18:52824 window_tree_host_manager_.reset();
sky27344382017-03-08 21:30:32825 focus_controller_->RemoveObserver(this);
sky68612712017-04-27 04:45:04826 if (config != Config::CLASSIC &&
827 window_tree_client_->focus_synchronizer()->active_focus_client() ==
828 focus_controller_.get()) {
829 window_tree_client_->focus_synchronizer()->SetSingletonFocusClient(nullptr);
830 }
sky27344382017-03-08 21:30:32831 focus_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45832 screen_position_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45833
robert.bradfordab052492015-05-06 11:09:56834 display_color_manager_.reset();
Steven Bennetts7683e342018-01-02 21:29:52835 projecting_observer_.reset();
836
[email protected]7bc49bd2014-01-22 09:30:34837 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11838 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45839 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11840 display_configurator_->RemoveObserver(display_error_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45841 display_change_observer_.reset();
Steven Bennetts7683e342018-01-02 21:29:52842 display_shutdown_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45843
[email protected]093b8d642014-04-03 20:59:28844 PowerStatus::Shutdown();
pneubeck8be1f5422014-10-09 16:46:18845
sky88bd4be62016-06-09 17:34:41846 // Needs to happen right before |instance_| is reset.
sky11cf8db92017-04-10 23:38:08847 shell_port_.reset();
Xiyuan Xia22b1a6c2017-04-18 22:46:01848 session_controller_->RemoveObserver(this);
Sonny Sasaka55f69fc2017-08-28 21:29:37849 // BluetoothPowerController depends on the PrefService and must be destructed
850 // before it.
851 bluetooth_power_controller_ = nullptr;
Qiang Xuf1400a362017-09-14 02:28:30852 // TouchDevicesController depends on the PrefService and must be destructed
853 // before it.
854 touch_devices_controller_ = nullptr;
Ahmed Fakhrye96051f2017-12-12 17:42:17855
Sam McNallya853cd82017-08-30 01:55:10856 local_state_.reset();
skyb073203a2017-03-13 16:59:16857 shell_delegate_.reset();
sky88bd4be62016-06-09 17:34:41858
Scott Violet17a61722017-06-19 17:54:31859 for (auto& observer : shell_observers_)
860 observer.OnShellDestroyed();
861
[email protected]b6ba05d902013-10-04 21:38:45862 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18863 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45864}
865
Scott Violetc8a1c6c2017-11-29 23:17:36866void Shell::Init(ui::ContextFactory* context_factory,
867 ui::ContextFactoryPrivate* context_factory_private) {
sky11cf8db92017-04-10 23:38:08868 const Config config = shell_port_->GetAshConfig();
skyabcae812017-01-18 17:01:34869
James Cookbd0b7792017-11-17 03:24:26870 // These controllers call Shell::Get() in their constructors, so they cannot
871 // be in the member initialization list.
Evan Stade48768f42017-10-10 05:23:30872 if (switches::IsNightLightEnabled())
Mitsuru Oshima04b54d02017-10-09 14:22:45873 night_light_controller_ = std::make_unique<NightLightController>();
Qiang Xuf1400a362017-09-14 02:28:30874 touch_devices_controller_ = std::make_unique<TouchDevicesController>();
Mitsuru Oshima04b54d02017-10-09 14:22:45875 bluetooth_power_controller_ = std::make_unique<BluetoothPowerController>();
Sonny Sasaka55f69fc2017-08-28 21:29:37876
James Cook8532dbc2017-07-31 21:54:51877 // Connector can be null in tests.
Sam McNallya853cd82017-08-30 01:55:10878 if (shell_delegate_->GetShellConnector()) {
James Cook8532dbc2017-07-31 21:54:51879 // Connect to local state prefs now, but wait for an active user before
880 // connecting to the profile pref service. The login screen has a temporary
881 // user profile that is not associated with a real user.
Taiju Tsuiki36c517d2017-05-18 06:45:43882 auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
Wenzhao Zang56c292932017-08-02 04:58:34883 RegisterLocalStatePrefs(pref_registry.get());
tibellb93c729b2017-03-30 00:45:09884 prefs::ConnectToPrefService(
Sam McNally538fca1e2017-07-14 03:10:43885 shell_delegate_->GetShellConnector(), std::move(pref_registry),
Sam McNallye36abbc2017-07-20 01:04:28886 base::Bind(&Shell::OnLocalStatePrefServiceInitialized,
887 weak_factory_.GetWeakPtr()),
888 prefs::mojom::kLocalStateServiceName);
jonrossc4ba10602017-04-07 20:51:05889 }
skyb073203a2017-03-13 16:59:16890
sky11cf8db92017-04-10 23:38:08891 // Some delegates access ShellPort during their construction. Create them here
892 // instead of the ShellPort constructor.
skyb073203a2017-03-13 16:59:16893 accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate());
Mitsuru Oshima04b54d02017-10-09 14:22:45894 accessibility_controller_ = std::make_unique<AccessibilityController>(
James Cook5fbdccb2017-09-01 21:17:55895 shell_delegate_->GetShellConnector());
Mitsuru Oshima04b54d02017-10-09 14:22:45896 toast_manager_ = std::make_unique<ToastManager>();
sky07a24d42017-03-09 23:57:30897
sky07a24d42017-03-09 23:57:30898 // Install the custom factory early on so that views::FocusManagers for Tray,
899 // Shelf, and WallPaper could be created by the factory.
900 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
901
Mitsuru Oshima04b54d02017-10-09 14:22:45902 wallpaper_controller_ = std::make_unique<WallpaperController>();
sky07a24d42017-03-09 23:57:30903
Mitsuru Oshima04b54d02017-10-09 14:22:45904 app_list_delegate_impl_ = std::make_unique<AppListDelegateImpl>();
sky15ef0aa2017-01-20 18:55:59905
sky11cf8db92017-04-10 23:38:08906 // TODO(sky): move creation to ShellPort.
skye5fd1222017-04-12 18:43:23907 if (config != Config::MASH)
Mitsuru Oshima04b54d02017-10-09 14:22:45908 immersive_handler_factory_ = std::make_unique<ImmersiveHandlerFactoryAsh>();
skyb7b54092016-08-19 16:00:09909
Mitsuru Oshima04b54d02017-10-09 14:22:45910 window_positioner_ = std::make_unique<WindowPositioner>();
sky984c1892016-04-20 00:00:34911
sky494c6cbd2017-03-27 20:57:48912 if (config == Config::CLASSIC) {
erg36cfb952017-06-21 19:41:45913 native_cursor_manager_ = new NativeCursorManagerAshClassic;
Mitsuru Oshima04b54d02017-10-09 14:22:45914 cursor_manager_ = std::make_unique<CursorManager>(
erg36cfb952017-06-21 19:41:45915 base::WrapUnique(native_cursor_manager_));
916 } else if (config == Config::MUS) {
917 native_cursor_manager_ = new NativeCursorManagerAshMus;
Mitsuru Oshima04b54d02017-10-09 14:22:45918 cursor_manager_ = std::make_unique<CursorManager>(
erg36cfb952017-06-21 19:41:45919 base::WrapUnique(native_cursor_manager_));
skyabcae812017-01-18 17:01:34920 }
skyfee520c2016-02-11 19:57:46921
Steven Bennettscce939192018-01-12 22:57:12922 // TODO(stevenjb): ChromeShellDelegate::PreInit currently handles
923 // DisplayPreference initialization, required for InitializeDisplayManager.
924 // Before we can move that code into ash/display where it belongs, we need to
925 // wait for |lcoal_state_| to be set in OnLocalStatePrefServiceInitialized
926 // before initializing DisplayPreferences (and therefore DisplayManager).
927 // http://crbug.com/678949.
skyb073203a2017-03-13 16:59:16928 shell_delegate_->PreInit();
[email protected]0249a6532013-10-31 06:53:34929
Steven Bennetts7683e342018-01-02 21:29:52930 InitializeDisplayManager();
[email protected]b6ba05d902013-10-04 21:38:45931
newcomer2febb9832017-06-12 17:00:23932 if (config == Config::CLASSIC) {
Steven Bennetts7683e342018-01-02 21:29:52933 // This will initialize aura::Env which requires |display_manager_| to
934 // be initialized first.
Scott Violetc8a1c6c2017-11-29 23:17:36935 aura::Env::GetInstance()->set_context_factory(context_factory);
skyabcae812017-01-18 17:01:34936 aura::Env::GetInstance()->set_context_factory_private(
Scott Violetc8a1c6c2017-11-29 23:17:36937 context_factory_private);
skyabcae812017-01-18 17:01:34938 }
[email protected]ecca62b2013-10-09 16:18:53939
[email protected]b6ba05d902013-10-04 21:38:45940 // The WindowModalityController needs to be at the front of the input event
941 // pretarget handler list to ensure that it processes input events when modal
942 // windows are active.
jamescookb8dcef522016-06-25 14:42:55943 window_modality_controller_.reset(new ::wm::WindowModalityController(this));
[email protected]b6ba05d902013-10-04 21:38:45944
[email protected]e319c7e2014-03-14 19:56:14945 env_filter_.reset(new ::wm::CompoundEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45946 AddPreTargetHandler(env_filter_.get());
947
sky27344382017-03-08 21:30:32948 // FocusController takes ownership of AshFocusRules.
949 focus_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:45950 std::make_unique<::wm::FocusController>(new wm::AshFocusRules());
sky27344382017-03-08 21:30:32951 focus_controller_->AddObserver(this);
sky68612712017-04-27 04:45:04952 if (config != Config::CLASSIC) {
953 window_tree_client_->focus_synchronizer()->SetSingletonFocusClient(
954 focus_controller_.get());
955 }
[email protected]b6ba05d902013-10-04 21:38:45956
[email protected]093b8d642014-04-03 20:59:28957 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:45958
Scott Violet596bb46342017-06-21 14:43:13959 window_tree_host_manager_->Start();
960 AshWindowTreeHostInitParams ash_init_params;
961 window_tree_host_manager_->CreatePrimaryHost(ash_init_params);
962
Scott Violet3c554ae2017-12-13 02:25:41963 time_to_first_present_recorder_ =
964 std::make_unique<TimeToFirstPresentRecorder>(GetPrimaryRootWindow());
965
mswad3d9552017-05-18 21:23:36966 root_window_for_new_windows_ = GetPrimaryRootWindow();
[email protected]b6ba05d902013-10-04 21:38:45967
Scott Violet596bb46342017-06-21 14:43:13968 resolution_notification_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:45969 std::make_unique<ResolutionNotificationController>();
[email protected]b6ba05d902013-10-04 21:38:45970
deratc6250a02017-01-25 05:51:53971 if (cursor_manager_) {
oshimaf84b0da722016-04-27 19:47:19972 cursor_manager_->SetDisplay(
973 display::Screen::GetScreen()->GetPrimaryDisplay());
deratc6250a02017-01-25 05:51:53974 }
[email protected]b6ba05d902013-10-04 21:38:45975
sky11cf8db92017-04-10 23:38:08976 accelerator_controller_ = shell_port_->CreateAcceleratorController();
Mitsuru Oshima04b54d02017-10-09 14:22:45977 tablet_mode_controller_ = std::make_unique<TabletModeController>();
978 shelf_controller_ = std::make_unique<ShelfController>();
[email protected]b6ba05d902013-10-04 21:38:45979
spange9b51272014-12-11 01:20:10980 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06981 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
spange9b51272014-12-11 01:20:10982 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06983 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:39984
[email protected]b6ba05d902013-10-04 21:38:45985 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:45986
derat2d4e62d2015-01-09 16:09:17987 // ui::UserActivityDetector passes events to observers, so let them get
[email protected]b6ba05d902013-10-04 21:38:45988 // rewritten first.
derat2d4e62d2015-01-09 16:09:17989 user_activity_detector_.reset(new ui::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:45990
[email protected]093b8d642014-04-03 20:59:28991 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45992 AddPreTargetHandler(overlay_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45993
[email protected]60d677d2014-05-30 13:07:02994 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
dchenga94547472016-04-08 08:41:11995 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
sky81a2d792017-03-17 19:14:39996 accelerator_controller_->accelerator_history()));
[email protected]b6ba05d902013-10-04 21:38:45997 AddPreTargetHandler(accelerator_filter_.get());
998
[email protected]093b8d642014-04-03 20:59:28999 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:451000 AddPreTargetHandler(event_transformation_handler_.get());
1001
sky11cf8db92017-04-10 23:38:081002 toplevel_window_event_handler_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451003 std::make_unique<ToplevelWindowEventHandler>();
[email protected]3537d472014-01-15 05:45:311004
sky83b1bb12017-04-24 20:29:281005 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:341006 system_gesture_filter_.reset(new SystemGestureEventFilter);
1007 AddPreTargetHandler(system_gesture_filter_.get());
1008 }
[email protected]b6ba05d902013-10-04 21:38:451009
[email protected]354520b2014-06-21 04:31:011010 sticky_keys_controller_.reset(new StickyKeysController);
Mitsuru Oshima04b54d02017-10-09 14:22:451011 screen_pinning_controller_ = std::make_unique<ScreenPinningController>();
[email protected]354520b2014-06-21 04:31:011012
Toni Barzic9d0c82f42017-12-06 00:53:521013 backlights_forced_off_setter_ = std::make_unique<BacklightsForcedOffSetter>();
1014
Toni Barzic85ae39e2017-12-07 05:50:181015 tray_action_ =
1016 std::make_unique<TrayAction>(backlights_forced_off_setter_.get());
1017
jamescookd9f152f2016-11-15 00:53:081018 lock_state_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451019 std::make_unique<LockStateController>(shutdown_controller_.get());
Toni Barzic9d0c82f42017-12-06 00:53:521020 power_button_controller_ = std::make_unique<PowerButtonController>(
1021 backlights_forced_off_setter_.get());
[email protected]685442f32014-02-28 10:40:061022 // Pass the initial display state to PowerButtonController.
1023 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:091024 display_configurator_->cached_displays());
jamescook01bf23e72017-01-09 19:58:151025
derat036f91b92017-05-05 00:33:181026 // Forward user activity from the window server to |user_activity_detector_|.
derat94887a22017-01-20 18:17:251027 // The connector is unavailable in some tests.
derat036f91b92017-05-05 00:33:181028 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS &&
1029 shell_delegate_->GetShellConnector()) {
derat94887a22017-01-20 18:17:251030 ui::mojom::UserActivityMonitorPtr user_activity_monitor;
skyb073203a2017-03-13 16:59:161031 shell_delegate_->GetShellConnector()->BindInterface(ui::mojom::kServiceName,
1032 &user_activity_monitor);
Mitsuru Oshima04b54d02017-10-09 14:22:451033 user_activity_forwarder_ = std::make_unique<aura::UserActivityForwarder>(
derat94887a22017-01-20 18:17:251034 std::move(user_activity_monitor), user_activity_detector_.get());
1035 }
1036
Scott Violet361833fb2017-06-21 22:25:201037 // In mash drag and drop is handled by mus.
1038 if (config != Config::MASH)
Mitsuru Oshima04b54d02017-10-09 14:22:451039 drag_drop_controller_ = std::make_unique<DragDropController>();
Scott Violet361833fb2017-06-21 22:25:201040
oshima5a296e82016-04-29 01:32:271041 // |screenshot_controller_| needs to be created (and prepended as a
mukai19274bdd2015-02-24 22:37:481042 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
oshima5a296e82016-04-29 01:32:271043 // process mouse events prior to screenshot session.
mukai19274bdd2015-02-24 22:37:481044 // See http://crbug.com/459214
James Cook5e9d3402017-11-01 00:20:121045 screenshot_controller_ = std::make_unique<ScreenshotController>(
1046 shell_delegate_->CreateScreenshotDelegate());
Mitsuru Oshima04b54d02017-10-09 14:22:451047 mouse_cursor_filter_ = std::make_unique<MouseCursorEventFilter>();
Scott Violet596bb46342017-06-21 14:43:131048 PrependPreTargetHandler(mouse_cursor_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:451049
1050 // Create Controllers that may need root window.
1051 // TODO(oshima): Move as many controllers before creating
1052 // RootWindowController as possible.
1053 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:451054
sammiequon203ae022016-09-18 17:23:421055 laser_pointer_controller_.reset(new LaserPointerController());
1056 partial_magnification_controller_.reset(new PartialMagnificationController());
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:321057 highlighter_controller_.reset(new HighlighterController());
Yue Lia33960a2017-11-01 22:06:071058 voice_interaction_controller_ =
1059 std::make_unique<VoiceInteractionController>();
sammiequon203ae022016-09-18 17:23:421060
jamescookb8dcef522016-06-25 14:42:551061 magnification_controller_.reset(MagnificationController::CreateInstance());
Mitsuru Oshima04b54d02017-10-09 14:22:451062 mru_window_tracker_ = std::make_unique<MruWindowTracker>();
[email protected]b6ba05d902013-10-04 21:38:451063
[email protected]55398d22013-10-10 19:49:201064 autoclick_controller_.reset(AutoclickController::CreateInstance());
1065
[email protected]b6ba05d902013-10-04 21:38:451066 high_contrast_controller_.reset(new HighContrastController);
Saman Sami3fb310d2017-11-09 16:51:541067
Ahmed Fakhry4af48e42018-02-28 17:45:381068 if (features::IsDockedMagnifierEnabled()) {
Ahmed Fakhry4bf3f742018-02-06 17:33:361069 docked_magnifier_controller_ =
1070 std::make_unique<DockedMagnifierController>();
1071 }
1072
Saman Sami3fb310d2017-11-09 16:51:541073 viz::mojom::VideoDetectorObserverPtr observer;
1074 video_detector_ =
1075 std::make_unique<VideoDetector>(mojo::MakeRequest(&observer));
1076 shell_port_->AddVideoDetectorObserver(std::move(observer));
[email protected]b6ba05d902013-10-04 21:38:451077
oshimaebbe63772015-02-19 18:41:321078 tooltip_controller_.reset(new views::corewm::TooltipController(
dchenga94547472016-04-08 08:41:111079 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451080 AddPreTargetHandler(tooltip_controller_.get());
1081
hariank0dd03dd2016-07-14 23:47:331082 modality_filter_.reset(new SystemModalContainerEventFilter(this));
1083 AddPreTargetHandler(modality_filter_.get());
1084
[email protected]093b8d642014-04-03 20:59:281085 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451086
skyabcae812017-01-18 17:01:341087 // Must occur after Shell has installed its early pre-target handlers (for
1088 // example, WindowModalityController).
sky11cf8db92017-04-10 23:38:081089 shell_port_->CreatePointerWatcherAdapter();
[email protected]b6ba05d902013-10-04 21:38:451090
[email protected]093b8d642014-04-03 20:59:281091 resize_shadow_controller_.reset(new ResizeShadowController());
sky27344382017-03-08 21:30:321092 shadow_controller_.reset(new ::wm::ShadowController(focus_controller_.get()));
[email protected]b6ba05d902013-10-04 21:38:451093
James Cookb50959e22017-08-10 20:24:381094 logout_confirmation_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451095 std::make_unique<LogoutConfirmationController>();
[email protected]b6ba05d902013-10-04 21:38:451096
jamescookac6724332017-03-21 02:54:431097 // May trigger initialization of the Bluetooth adapter.
1098 tray_bluetooth_helper_->Initialize();
1099
kylechar55f0eaf22017-01-11 22:57:371100 // Create AshTouchTransformController before
oshimae2818922015-07-28 01:18:521101 // WindowTreeHostManager::InitDisplays()
kylechar55f0eaf22017-01-11 22:57:371102 // since AshTouchTransformController listens on
oshimae2818922015-07-28 01:18:521103 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
Mitsuru Oshima04b54d02017-10-09 14:22:451104 touch_transformer_controller_ = std::make_unique<AshTouchTransformController>(
Scott Violet596bb46342017-06-21 14:43:131105 display_configurator_.get(), display_manager_.get(),
1106 shell_port_->CreateTouchTransformDelegate());
[email protected]03122891a2014-05-13 23:56:491107
sky11cf8db92017-04-10 23:38:081108 keyboard_ui_ = shell_port_->CreateKeyboardUI();
skyfee520c2016-02-11 19:57:461109
Scott Violet596bb46342017-06-21 14:43:131110 window_tree_host_manager_->InitHosts();
1111 shell_port_->OnHostsInitialized();
[email protected]b6ba05d902013-10-04 21:38:451112
rsadam9172bc8a2014-10-29 23:37:381113 // Needs to be created after InitDisplays() since it may cause the virtual
1114 // keyboard to be deployed.
sky83b1bb12017-04-24 20:29:281115 if (config != Config::MASH)
skyabcae812017-01-18 17:01:341116 virtual_keyboard_controller_.reset(new VirtualKeyboardController);
rsadam9172bc8a2014-10-29 23:37:381117
sadrul7a8785e2016-02-12 21:54:351118 if (cursor_manager_) {
Steven Bennetts6d12eb42018-01-09 16:49:081119 cursor_manager_->HideCursor(); // Hide the mouse cursor on startup.
ergeeba7c622017-04-25 18:06:161120 cursor_manager_->SetCursor(ui::CursorType::kPointer);
sadrul7a8785e2016-02-12 21:54:351121 }
[email protected]b6ba05d902013-10-04 21:38:451122
Mitsuru Oshima04b54d02017-10-09 14:22:451123 peripheral_battery_notifier_ = std::make_unique<PeripheralBatteryNotifier>();
[email protected]093b8d642014-04-03 20:59:281124 power_event_observer_.reset(new PowerEventObserver());
[email protected]ded58fd2013-10-09 07:56:551125 user_activity_notifier_.reset(
[email protected]b0fa7012014-04-16 12:50:571126 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
[email protected]ded58fd2013-10-09 07:56:551127 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281128 new VideoActivityNotifier(video_detector_.get()));
1129 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
Scott Violet596bb46342017-06-21 14:43:131130 screen_orientation_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451131 std::make_unique<ScreenOrientationController>();
Scott Violet596bb46342017-06-21 14:43:131132 screen_layout_observer_.reset(new ScreenLayoutObserver());
yiyix90cfee22017-02-16 05:38:181133 sms_observer_.reset(new SmsObserver());
jamescook01bf23e72017-01-09 19:58:151134
xdaid4913762017-07-06 00:17:221135 split_view_controller_.reset(new SplitViewController());
1136
[email protected]b6ba05d902013-10-04 21:38:451137 // The compositor thread and main message loop have to be running in
1138 // order to create mirror window. Run it after the main message loop
1139 // is started.
Scott Violet596bb46342017-06-21 14:43:131140 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031141
Mitsuru Oshima04b54d02017-10-09 14:22:451142 message_center_controller_ = std::make_unique<MessageCenterController>();
Evan Stade2c43a87b32017-08-31 17:53:101143
James Cook0ba192bf2017-12-01 20:53:111144 // Mash implements the show taps feature with a separate mojo app.
1145 // GetShellConnector() is null in unit tests.
1146 if (config == Config::MASH && shell_delegate_->GetShellConnector() &&
1147 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowTaps)) {
1148 mash::mojom::LaunchablePtr launchable;
James Cook2268bef2018-02-27 01:12:161149 shell_delegate_->GetShellConnector()->BindInterface("touch_hud_app",
James Cook0ba192bf2017-12-01 20:53:111150 &launchable);
1151 launchable->Launch(mash::mojom::kWindow, mash::mojom::LaunchMode::DEFAULT);
1152 }
1153
sky00c813f2017-03-08 22:48:551154 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:181155 observer.OnShellInitialized();
phweiss0bf64c52015-11-17 12:56:181156
Scott Violet41562d1c2017-06-26 15:15:481157 user_metrics_recorder_->OnShellInitialized();
[email protected]b6ba05d902013-10-04 21:38:451158}
1159
Steven Bennetts7683e342018-01-02 21:29:521160void Shell::InitializeDisplayManager() {
1161 const Config config = shell_port_->GetAshConfig();
1162 bool display_initialized = display_manager_->InitFromCommandLine();
1163
1164 if (!display_initialized && config != Config::CLASSIC) {
1165 // Run display configuration off device in mus mode.
1166 display_manager_->set_configure_displays(true);
1167 display_configurator_->set_configure_display(true);
1168 }
1169 display_configuration_controller_ =
1170 std::make_unique<DisplayConfigurationController>(
1171 display_manager_.get(), window_tree_host_manager_.get());
1172 display_configurator_->Init(shell_port_->CreateNativeDisplayDelegate(),
1173 false);
Qiang Xud77a90c2018-02-20 19:43:291174 persistent_window_controller_ =
1175 std::make_unique<PersistentWindowController>();
Steven Bennetts7683e342018-01-02 21:29:521176
1177 projecting_observer_ =
1178 std::make_unique<ProjectingObserver>(display_configurator_.get());
1179
1180 if (!display_initialized) {
1181 if (config != Config::CLASSIC && !chromeos::IsRunningAsSystemCompositor()) {
1182 display::mojom::DevDisplayControllerPtr controller;
1183 shell_delegate_->GetShellConnector()->BindInterface(
1184 ui::mojom::kServiceName, &controller);
1185 display_manager_->SetDevDisplayController(std::move(controller));
1186 }
1187
1188 if (config != Config::CLASSIC || chromeos::IsRunningAsSystemCompositor()) {
1189 display_change_observer_ =
1190 std::make_unique<display::DisplayChangeObserver>(
1191 display_configurator_.get(), display_manager_.get());
1192
1193 display_shutdown_observer_ = std::make_unique<DisplayShutdownObserver>(
1194 display_configurator_.get());
1195
1196 // Register |display_change_observer_| first so that the rest of
1197 // observer gets invoked after the root windows are configured.
1198 display_configurator_->AddObserver(display_change_observer_.get());
1199 display_error_observer_.reset(new DisplayErrorObserver());
1200 display_configurator_->AddObserver(display_error_observer_.get());
1201 display_configurator_->set_state_controller(
1202 display_change_observer_.get());
1203 display_configurator_->set_mirroring_controller(display_manager_.get());
1204 display_configurator_->ForceInitialConfigure();
1205 display_initialized = true;
1206 }
1207 }
1208
1209 display_color_manager_ =
1210 std::make_unique<DisplayColorManager>(display_configurator_.get());
1211
1212 if (!display_initialized)
1213 display_manager_->InitDefaultDisplay();
1214
1215 if (config == Config::CLASSIC)
1216 display_manager_->RefreshFontParams();
1217}
1218
[email protected]41baaed2013-11-09 04:18:261219void Shell::InitRootWindow(aura::Window* root_window) {
sky27344382017-03-08 21:30:321220 DCHECK(focus_controller_);
[email protected]d90b8392012-06-13 09:34:561221 DCHECK(visibility_controller_.get());
[email protected]d90b8392012-06-13 09:34:561222
sky27344382017-03-08 21:30:321223 aura::client::SetFocusClient(root_window, focus_controller_.get());
Thiago Farina3b086a02017-05-30 22:32:501224 ::wm::SetActivationClient(root_window, focus_controller_.get());
sky27344382017-03-08 21:30:321225 root_window->AddPreTargetHandler(focus_controller_.get());
[email protected]d90b8392012-06-13 09:34:561226 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
Scott Violet361833fb2017-06-21 22:25:201227 if (drag_drop_controller_) {
1228 DCHECK_NE(Config::MASH, GetAshConfig());
1229 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
1230 } else {
1231 DCHECK_EQ(Config::MASH, GetAshConfig());
1232 }
[email protected]8d625fb2012-07-18 16:40:061233 aura::client::SetScreenPositionClient(root_window,
1234 screen_position_controller_.get());
sadrul7a8785e2016-02-12 21:54:351235 aura::client::SetCursorClient(root_window, cursor_manager_.get());
Thiago Farina3b086a02017-05-30 22:32:501236 ::wm::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381237 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561238
Thiago Farina3b086a02017-05-30 22:32:501239 ::wm::SetWindowMoveClient(root_window, toplevel_window_event_handler_.get());
[email protected]3537d472014-01-15 05:45:311240 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1241 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
[email protected]d90b8392012-06-13 09:34:561242}
1243
skyabcae812017-01-18 17:01:341244void Shell::CloseAllRootWindowChildWindows() {
msw257a6a232017-06-01 01:46:301245 for (aura::Window* root : GetAllRootWindows()) {
1246 RootWindowController* controller = RootWindowController::ForWindow(root);
skyabcae812017-01-18 17:01:341247 if (controller) {
1248 controller->CloseChildWindows();
1249 } else {
msw257a6a232017-06-01 01:46:301250 while (!root->children().empty()) {
1251 aura::Window* child = root->children()[0];
skyabcae812017-01-18 17:01:341252 delete child;
1253 }
1254 }
1255 }
1256}
1257
[email protected]c0ce80e2012-10-05 23:28:271258bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1259 RootWindowControllerList controllers = GetAllRootWindowControllers();
oshima9a61ecf2016-06-18 10:43:051260 for (RootWindowController* controller : controllers) {
1261 if (controller->CanWindowReceiveEvents(window))
[email protected]602022b2014-03-31 17:07:311262 return true;
[email protected]c0ce80e2012-10-05 23:28:271263 }
1264 return false;
1265}
1266
[email protected]049cf34b2012-12-07 17:15:481267////////////////////////////////////////////////////////////////////////////////
1268// Shell, ui::EventTarget overrides:
1269
[email protected]869f6352012-12-06 20:47:171270bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411271 return true;
1272}
1273
1274ui::EventTarget* Shell::GetParentTarget() {
[email protected]ff0278852013-11-05 22:35:481275 return aura::Env::GetInstance();
[email protected]5097e692012-10-30 22:08:411276}
1277
dchenga94547472016-04-08 08:41:111278std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1279 return std::unique_ptr<ui::EventTargetIterator>();
[email protected]3e670aa2013-12-02 19:04:321280}
1281
1282ui::EventTargeter* Shell::GetEventTargeter() {
1283 NOTREACHED();
achuith287b26e2015-09-03 17:49:181284 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321285}
1286
sky27344382017-03-08 21:30:321287void Shell::OnWindowActivated(
Thiago Farina3b086a02017-05-30 22:32:501288 ::wm::ActivationChangeObserver::ActivationReason reason,
sky27344382017-03-08 21:30:321289 aura::Window* gained_active,
1290 aura::Window* lost_active) {
mswad3d9552017-05-18 21:23:361291 if (gained_active)
1292 root_window_for_new_windows_ = gained_active->GetRootWindow();
sky27344382017-03-08 21:30:321293}
1294
Xiyuan Xiab64fd0a2017-04-13 17:53:141295void Shell::OnSessionStateChanged(session_manager::SessionState state) {
Aga Wronskae195ad22017-12-20 01:38:111296 // Initialize the |shelf_window_watcher_| when a session becomes active.
1297 // Shelf itself is initialized in RootWindowController.
sky5ad143a2017-03-22 04:31:231298 if (state == session_manager::SessionState::ACTIVE) {
Aga Wronskae195ad22017-12-20 01:38:111299 if (!shelf_window_watcher_)
1300 shelf_window_watcher_ =
1301 std::make_unique<ShelfWindowWatcher>(shelf_model());
okac21941d2017-06-20 17:54:441302 }
Steven Bennetts43b3c212018-01-08 16:39:581303
Steven Bennetts9fd12ad2017-11-09 23:36:271304 // NOTE: keyboard::IsKeyboardEnabled() is false in mash, but may not be in
1305 // unit tests. crbug.com/646565.
Steven Bennetts43b3c212018-01-08 16:39:581306 if (keyboard::IsKeyboardEnabled()) {
1307 switch (state) {
1308 case session_manager::SessionState::OOBE:
1309 case session_manager::SessionState::LOGIN_PRIMARY:
1310 // Ensure that the keyboard controller is activated for the primary
1311 // window.
1312 GetPrimaryRootWindowController()->ActivateKeyboard(
1313 keyboard::KeyboardController::GetInstance());
1314 break;
1315 case session_manager::SessionState::LOGGED_IN_NOT_ACTIVE:
1316 case session_manager::SessionState::ACTIVE:
1317 // Recreate the keyboard on user profile change, to refresh keyboard
1318 // extensions with the new profile and ensure the extensions call the
1319 // proper IME. |LOGGED_IN_NOT_ACTIVE| is needed so that the virtual
1320 // keyboard works on supervised user creation, http://crbug.com/712873.
1321 // |ACTIVE| is also needed for guest user workflow.
1322 CreateKeyboard();
1323 break;
1324 default:
1325 break;
1326 }
sky5ad143a2017-03-22 04:31:231327 }
Scott Violet0c0dcde2017-08-04 21:48:181328
1329 shell_port_->UpdateSystemModalAndBlockingContainers();
xiyuan233f4e72017-04-06 06:59:561330}
sky5ad143a2017-03-22 04:31:231331
Xiyuan Xiab64fd0a2017-04-13 17:53:141332void Shell::OnLoginStatusChanged(LoginStatus login_status) {
xiyuan233f4e72017-04-06 06:59:561333 UpdateAfterLoginStatusChange(login_status);
sky5ad143a2017-03-22 04:31:231334}
1335
Xiyuan Xiab64fd0a2017-04-13 17:53:141336void Shell::OnLockStateChanged(bool locked) {
xiyuan7ebbf7f2017-04-10 16:49:101337#ifndef NDEBUG
1338 // Make sure that there is no system modal in Lock layer when unlocked.
1339 if (!locked) {
1340 aura::Window::Windows containers = wm::GetContainersFromAllRootWindows(
1341 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
1342 for (aura::Window* container : containers)
1343 DCHECK(container->children().empty());
1344 }
1345#endif
1346}
1347
Sam McNallye36abbc2017-07-20 01:04:281348void Shell::OnLocalStatePrefServiceInitialized(
1349 std::unique_ptr<::PrefService> pref_service) {
Sam McNallya853cd82017-08-30 01:55:101350 DCHECK(!local_state_);
James Cook8532dbc2017-07-31 21:54:511351 // |pref_service| is null if can't connect to Chrome (as happens when
Scott Violet8ff9c302018-02-22 22:28:351352 // running mash outside of chrome --enable-features=Mash and chrome isn't
1353 // built).
Sam McNallya853cd82017-08-30 01:55:101354 if (!pref_service)
1355 return;
1356
1357 local_state_ = std::move(pref_service);
James Cookbbe5cb12017-08-08 18:32:211358
1359 for (auto& observer : shell_observers_)
Sam McNallya853cd82017-08-30 01:55:101360 observer.OnLocalStatePrefServiceInitialized(local_state_.get());
Sam McNallye36abbc2017-07-20 01:04:281361}
1362
[email protected]55f593352011-12-24 05:42:461363} // namespace ash