blob: e3a79268080b539fad0e67710a0d282fb3e73a0c [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"
Evan Stade7d0e8232017-10-04 02:01:3658#include "ash/public/cpp/ash_switches.h"
sky494c6cbd2017-03-27 20:57:4859#include "ash/public/cpp/config.h"
msw109806d2017-06-02 20:11:5760#include "ash/public/cpp/shelf_model.h"
jamescook8800b8232016-10-19 12:46:2761#include "ash/public/cpp/shell_window_ids.h"
[email protected]d90b8392012-06-13 09:34:5662#include "ash/root_window_controller.h"
James Cook5e9d3402017-11-01 00:20:1263#include "ash/screenshot_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4464#include "ash/session/session_controller.h"
James Cook840177e2017-05-25 02:20:0165#include "ash/shelf/shelf.h"
James Cookb0bf8e82017-04-09 17:01:4466#include "ash/shelf/shelf_controller.h"
James Cookb0bf8e82017-04-09 17:01:4467#include "ash/shelf/shelf_window_watcher.h"
James Cookb0bf8e82017-04-09 17:01:4468#include "ash/shell_delegate.h"
[email protected]1b4c7472014-05-15 18:32:2369#include "ash/shell_init_params.h"
James Cookb0bf8e82017-04-09 17:01:4470#include "ash/shell_observer.h"
sky11cf8db92017-04-10 23:38:0871#include "ash/shell_port.h"
Scott Violet22a7b9212017-07-20 19:05:1972#include "ash/shell_port_classic.h"
James Cookb0bf8e82017-04-09 17:01:4473#include "ash/shutdown_controller.h"
jamescook01bf23e72017-01-09 19:58:1574#include "ash/sticky_keys/sticky_keys_controller.h"
James Cooka35a1e22017-04-08 02:33:0875#include "ash/system/bluetooth/bluetooth_notification_controller.h"
Sonny Sasaka55f69fc2017-08-28 21:29:3776#include "ash/system/bluetooth/bluetooth_power_controller.h"
James Cooka35a1e22017-04-08 02:33:0877#include "ash/system/bluetooth/tray_bluetooth_helper.h"
78#include "ash/system/brightness/brightness_controller_chromeos.h"
James Cookb0bf8e82017-04-09 17:01:4479#include "ash/system/brightness_control_delegate.h"
Lann Martinb9991402017-06-23 22:25:0880#include "ash/system/keyboard_brightness/keyboard_brightness_controller.h"
James Cookb0bf8e82017-04-09 17:01:4481#include "ash/system/keyboard_brightness_control_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4482#include "ash/system/locale/locale_notification_controller.h"
James Cooka35a1e22017-04-08 02:33:0883#include "ash/system/network/sms_observer.h"
84#include "ash/system/network/vpn_list.h"
afakhrye4fae852017-05-09 18:49:0685#include "ash/system/night_light/night_light_controller.h"
Sammie Quon4d7dba62017-08-03 23:18:1786#include "ash/system/palette/palette_tray.h"
Sammie Quon6c4e2b1f2017-10-13 16:54:1887#include "ash/system/palette/palette_welcome_bubble.h"
Toni Barzic9d0c82f42017-12-06 00:53:5288#include "ash/system/power/backlights_forced_off_setter.h"
Sammie Quon95c6a1c2017-09-12 19:16:5589#include "ash/system/power/peripheral_battery_notifier.h"
Qiang Xu0a86020f2017-10-12 08:34:5490#include "ash/system/power/power_button_controller.h"
James Cooka35a1e22017-04-08 02:33:0891#include "ash/system/power/power_event_observer.h"
92#include "ash/system/power/power_status.h"
93#include "ash/system/power/video_activity_notifier.h"
94#include "ash/system/screen_layout_observer.h"
James Cookdc041122017-08-01 14:03:2295#include "ash/system/session/logout_button_tray.h"
James Cooka35a1e22017-04-08 02:33:0896#include "ash/system/session/logout_confirmation_controller.h"
James Cookb0bf8e82017-04-09 17:01:4497#include "ash/system/status_area_widget.h"
98#include "ash/system/toast/toast_manager.h"
99#include "ash/system/tray/system_tray_controller.h"
James Cookb0bf8e82017-04-09 17:01:44100#include "ash/system/tray/system_tray_notifier.h"
James Cook98072352017-08-07 18:00:07101#include "ash/system/tray_caps_lock.h"
kylechar55f0eaf22017-01-11 22:57:37102#include "ash/touch/ash_touch_transform_controller.h"
Qiang Xuf1400a362017-09-14 02:28:30103#include "ash/touch/touch_devices_controller.h"
tbarzicc78da1ff92017-05-08 20:46:15104#include "ash/tray_action/tray_action.h"
oshima5a296e82016-04-29 01:32:27105#include "ash/utility/screenshot_controller.h"
jamescook01bf23e72017-01-09 19:58:15106#include "ash/virtual_keyboard_controller.h"
Yue Lia33960a2017-11-01 22:06:07107#include "ash/voice_interaction/voice_interaction_controller.h"
James Cookb0bf8e82017-04-09 17:01:44108#include "ash/wallpaper/wallpaper_controller.h"
[email protected]39718b52012-12-03 17:24:56109#include "ash/wm/ash_focus_rules.h"
James Cookb0bf8e82017-04-09 17:01:44110#include "ash/wm/container_finder.h"
[email protected]262f8bd2012-03-23 19:30:27111#include "ash/wm/event_client_impl.h"
James Cookb0bf8e82017-04-09 17:01:44112#include "ash/wm/immersive_context_ash.h"
skyb7b54092016-08-19 16:00:09113#include "ash/wm/immersive_handler_factory_ash.h"
[email protected]ab4f8c92013-05-30 19:07:47114#include "ash/wm/lock_state_controller.h"
James Cookb0bf8e82017-04-09 17:01:44115#include "ash/wm/mru_window_tracker.h"
erg36cfb952017-06-21 19:41:45116#include "ash/wm/native_cursor_manager_ash_classic.h"
117#include "ash/wm/native_cursor_manager_ash_mus.h"
[email protected]9ae32df2012-07-26 03:25:18118#include "ash/wm/overlay_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44119#include "ash/wm/overview/window_selector_controller.h"
[email protected]e4a181cc2012-03-17 02:20:57120#include "ash/wm/resize_shadow_controller.h"
James Cookb0bf8e82017-04-09 17:01:44121#include "ash/wm/root_window_finder.h"
hidehiko6821ca42016-06-18 11:12:23122#include "ash/wm/screen_pinning_controller.h"
xdaid4913762017-07-06 00:17:22123#include "ash/wm/splitview/split_view_controller.h"
[email protected]435b212e2012-04-05 19:43:37124#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:27125#include "ash/wm/system_modal_container_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44126#include "ash/wm/system_modal_container_layout_manager.h"
Mitsuru Oshima0e9b7a62017-07-19 18:23:03127#include "ash/wm/tablet_mode/tablet_mode_controller.h"
128#include "ash/wm/tablet_mode/tablet_mode_window_manager.h"
[email protected]3537d472014-01-15 05:45:31129#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:58130#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:02131#include "ash/wm/window_animations.h"
James Cookb0bf8e82017-04-09 17:01:44132#include "ash/wm/window_cycle_controller.h"
133#include "ash/wm/window_positioner.h"
[email protected]f059c6942012-07-21 14:27:57134#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:59135#include "ash/wm/window_util.h"
James Cookb0bf8e82017-04-09 17:01:44136#include "ash/wm/workspace_controller.h"
[email protected]f296be72011-10-11 15:40:00137#include "base/bind.h"
jamescook01bf23e72017-01-09 19:58:15138#include "base/bind_helpers.h"
jamescookfda159002016-10-21 18:48:57139#include "base/command_line.h"
dchenga94547472016-04-08 08:41:11140#include "base/memory/ptr_util.h"
jamescook01bf23e72017-01-09 19:58:15141#include "base/sys_info.h"
primiano7182d7b2015-01-30 18:02:03142#include "base/trace_event/trace_event.h"
jamescook01bf23e72017-01-09 19:58:15143#include "chromeos/chromeos_switches.h"
reveman24158982017-01-10 05:58:45144#include "chromeos/system/devicemode.h"
tibellb93c729b2017-03-30 00:45:09145#include "components/prefs/pref_registry_simple.h"
146#include "components/prefs/pref_service.h"
Saman Sami3fb310d2017-11-09 16:51:54147#include "components/viz/host/host_frame_sink_manager.h"
Ken Rockot388ba4fc2018-02-10 17:23:41148#include "mash/public/mojom/launchable.mojom.h"
tibellb93c729b2017-03-30 00:45:09149#include "services/preferences/public/cpp/pref_service_factory.h"
Ken Rockotf7f533e2018-02-11 02:21:33150#include "services/preferences/public/mojom/preferences.mojom.h"
derat94887a22017-01-20 18:17:25151#include "services/service_manager/public/cpp/connector.h"
152#include "services/ui/public/interfaces/constants.mojom.h"
sky7db5ccf2017-03-14 21:52:29153#include "ui/app_list/presenter/app_list.h"
[email protected]2c456102011-12-26 06:26:34154#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:44155#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:58156#include "ui/aura/layout_manager.h"
sky68612712017-04-27 04:45:04157#include "ui/aura/mus/focus_synchronizer.h"
derat94887a22017-01-20 18:17:25158#include "ui/aura/mus/user_activity_forwarder.h"
sky68612712017-04-27 04:45:04159#include "ui/aura/mus/window_tree_client.h"
[email protected]87b0d82e2011-10-07 21:02:59160#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:26161#include "ui/aura/window_event_dispatcher.h"
[email protected]2d4817742012-12-17 20:16:18162#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:17163#include "ui/base/user_activity/user_activity_detector.h"
jamescook01bf23e72017-01-09 19:58:15164#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]116302fc2012-05-05 21:45:41165#include "ui/compositor/layer.h"
166#include "ui/compositor/layer_animator.h"
oshimaf84b0da722016-04-27 19:47:19167#include "ui/display/display.h"
sky2f68b6f2017-05-21 16:08:39168#include "ui/display/manager/chromeos/default_touch_transform_setter.h"
jamescook01bf23e72017-01-09 19:58:15169#include "ui/display/manager/chromeos/display_change_observer.h"
170#include "ui/display/manager/chromeos/display_configurator.h"
sky7265b1cc2017-05-22 23:11:03171#include "ui/display/manager/chromeos/touch_transform_setter.h"
rjkroege72f8154f2016-10-29 00:49:02172#include "ui/display/manager/display_manager.h"
kylechar7e4f46f2017-10-31 23:26:57173#include "ui/display/mojo/dev_display_controller.mojom.h"
oshimaf84b0da722016-04-27 19:47:19174#include "ui/display/screen.h"
skycfaad892017-04-28 20:52:58175#include "ui/display/types/native_display_delegate.h"
[email protected]3e670aa2013-12-02 19:04:32176#include "ui/events/event_target_iterator.h"
sky4ec2be82017-01-06 17:38:32177#include "ui/gfx/geometry/insets.h"
[email protected]9ec0f452012-05-31 15:58:53178#include "ui/gfx/image/image_skia.h"
[email protected]b6ba05d902013-10-04 21:38:45179#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28180#include "ui/keyboard/keyboard_switches.h"
yhanada8909a542017-07-11 10:06:19181#include "ui/keyboard/keyboard_ui.h"
[email protected]f1d5c3a2013-04-23 17:42:56182#include "ui/keyboard/keyboard_util.h"
[email protected]d7f30a72013-10-05 05:09:41183#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04184#include "ui/views/corewm/tooltip_controller.h"
sky07a24d42017-03-09 23:57:30185#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:58186#include "ui/views/widget/native_widget_aura.h"
187#include "ui/views/widget/widget.h"
[email protected]60d677d2014-05-30 13:07:02188#include "ui/wm/core/accelerator_filter.h"
[email protected]ee3ed10772014-03-11 22:02:01189#include "ui/wm/core/compound_event_filter.h"
190#include "ui/wm/core/focus_controller.h"
[email protected]ee3ed10772014-03-11 22:02:01191#include "ui/wm/core/shadow_controller.h"
192#include "ui/wm/core/visibility_controller.h"
193#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59194
[email protected]55f593352011-12-24 05:42:46195namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59196
197namespace {
[email protected]671a2ae2011-10-13 21:53:23198
[email protected]615922f2012-02-07 02:41:15199using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45200using views::Widget;
201
jamescook518dccbd2017-05-18 04:57:07202bool g_is_browser_process_with_mash = false;
203
[email protected]b5756e22012-11-30 01:32:02204// A Corewm VisibilityController subclass that calls the Ash animation routine
205// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14206class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02207 public:
Chris Watkinsc24daf62017-11-28 03:43:09208 AshVisibilityController() = default;
209 ~AshVisibilityController() override = default;
[email protected]b5756e22012-11-30 01:32:02210
211 private:
[email protected]e319c7e2014-03-14 19:56:14212 // Overridden from ::wm::VisibilityController:
dcheng1f4538e2014-10-27 23:57:05213 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
214 bool visible) override {
[email protected]b5756e22012-11-30 01:32:02215 return AnimateOnChildWindowVisibilityChanged(window, visible);
216 }
217
218 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
219};
220
[email protected]87b0d82e2011-10-07 21:02:59221} // namespace
222
[email protected]cac10fc62011-10-07 23:22:56223// static
achuith287b26e2015-09-03 17:49:18224Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13225// static
sky00f98a372017-01-11 06:03:49226aura::WindowTreeClient* Shell::window_tree_client_ = nullptr;
227// static
skya8b222f2017-01-12 15:47:13228aura::WindowManagerClient* Shell::window_manager_client_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13229
230////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56231// Shell, public:
232
[email protected]cac10fc62011-10-07 23:22:56233// static
Scott Violetc8a1c6c2017-11-29 23:17:36234Shell* Shell::CreateInstance(ShellInitParams init_params) {
[email protected]3266c2b92011-11-14 00:06:08235 CHECK(!instance_);
Scott Violetc8a1c6c2017-11-29 23:17:36236 instance_ = new Shell(std::move(init_params.delegate),
237 std::move(init_params.shell_port));
238 instance_->Init(init_params.context_factory,
239 init_params.context_factory_private);
[email protected]3266c2b92011-11-14 00:06:08240 return instance_;
241}
242
243// static
skyb073203a2017-03-13 16:59:16244Shell* Shell::Get() {
jamescook518dccbd2017-05-18 04:57:07245 CHECK(!g_is_browser_process_with_mash) // Implies null |instance_|.
246 << "Ash is running in its own process so Shell::Get() will return null. "
247 "The browser process must use the mojo interfaces in //ash/public to "
248 "access ash. See ash/README.md for details.";
oshima9eea82da2014-09-13 01:11:07249 CHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56250 return instance_;
251}
252
[email protected]6377a002011-11-10 20:26:47253// static
[email protected]b3b7bcd2012-03-06 19:35:45254bool Shell::HasInstance() {
255 return !!instance_;
256}
257
258// static
[email protected]ef589af2011-12-03 01:07:15259void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47260 delete instance_;
[email protected]6377a002011-11-10 20:26:47261}
262
[email protected]e73bd7802012-02-17 20:10:34263// static
[email protected]093b8d642014-04-03 20:59:28264RootWindowController* Shell::GetPrimaryRootWindowController() {
oshima9eea82da2014-09-13 01:11:07265 CHECK(HasInstance());
msw257a6a232017-06-01 01:46:30266 return RootWindowController::ForWindow(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23267}
268
269// static
270Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
oshima9eea82da2014-09-13 01:11:07271 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34272 RootWindowControllerList root_window_controllers;
msw257a6a232017-06-01 01:46:30273 for (aura::Window* root : GetAllRootWindows())
274 root_window_controllers.push_back(RootWindowController::ForWindow(root));
skyabcae812017-01-18 17:01:34275 return root_window_controllers;
[email protected]d90b8392012-06-13 09:34:56276}
277
278// static
thanhphc90f49ca2017-03-03 17:48:53279RootWindowController* Shell::GetRootWindowControllerWithDisplayId(
280 int64_t display_id) {
281 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13282 aura::Window* root = GetRootWindowForDisplayId(display_id);
msw257a6a232017-06-01 01:46:30283 return root ? RootWindowController::ForWindow(root) : nullptr;
thanhphc90f49ca2017-03-03 17:48:53284}
285
286// static
Scott Violet596bb46342017-06-21 14:43:13287aura::Window* Shell::GetRootWindowForDisplayId(int64_t display_id) {
288 CHECK(HasInstance());
289 return instance_->window_tree_host_manager_->GetRootWindowForDisplayId(
290 display_id);
291}
292
293// static
[email protected]bf9cdb362013-10-25 19:22:45294aura::Window* Shell::GetPrimaryRootWindow() {
oshima9eea82da2014-09-13 01:11:07295 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13296 return instance_->window_tree_host_manager_->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34297}
298
[email protected]7b0f7502012-06-11 00:12:39299// static
sky27344382017-03-08 21:30:32300aura::Window* Shell::GetRootWindowForNewWindows() {
301 CHECK(Shell::HasInstance());
skycb4be5b2017-04-06 17:52:45302 Shell* shell = Shell::Get();
sky27344382017-03-08 21:30:32303 if (shell->scoped_root_window_for_new_windows_)
304 return shell->scoped_root_window_for_new_windows_;
305 return shell->root_window_for_new_windows_;
mfomitcheva1a8aa62016-05-03 16:23:26306}
307
308// static
[email protected]c9390bd2013-11-08 20:33:13309aura::Window::Windows Shell::GetAllRootWindows() {
oshima9eea82da2014-09-13 01:11:07310 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13311 return instance_->window_tree_host_manager_->GetAllRootWindows();
[email protected]be65be362012-06-15 07:38:23312}
313
314// static
jamescookb8dcef522016-06-25 14:42:55315aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) {
[email protected]7b0f7502012-06-11 00:12:39316 return root_window->GetChildById(container_id);
317}
318
319// static
[email protected]bf9cdb362013-10-25 19:22:45320const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38321 int container_id) {
322 return root_window->GetChildById(container_id);
323}
324
sky494c6cbd2017-03-27 20:57:48325// static
James Cook7b7c6a52018-01-04 23:40:03326int Shell::GetOpenSystemModalWindowContainerId() {
327 // The test boolean is not static to avoid leaking state between tests.
328 if (Get()->simulate_modal_window_open_for_test_)
329 return kShellWindowId_SystemModalContainer;
330
331 // Traverse all system modal containers, and find its direct child window
332 // with "SystemModal" setting, and visible.
333 // Note: LockSystemModalContainer is more restrictive, so make it preferable
334 // to SystemModalCotainer.
335 constexpr int modal_window_ids[] = {kShellWindowId_LockSystemModalContainer,
336 kShellWindowId_SystemModalContainer};
337 for (aura::Window* root : Shell::GetAllRootWindows()) {
338 for (int modal_window_id : modal_window_ids) {
339 aura::Window* system_modal = root->GetChildById(modal_window_id);
340 if (!system_modal)
341 continue;
342 for (const aura::Window* child : system_modal->children()) {
343 if (child->GetProperty(aura::client::kModalKey) ==
344 ui::MODAL_TYPE_SYSTEM &&
345 child->layer()->GetTargetVisibility()) {
346 return modal_window_id;
347 }
348 }
349 }
350 }
351 return -1;
352}
353
354// static
355bool Shell::IsSystemModalWindowOpen() {
356 return GetOpenSystemModalWindowContainerId() >= 0;
357}
358
359// static
jamescook0dfe5632017-04-05 18:49:02360Config Shell::GetAshConfig() {
sky11cf8db92017-04-10 23:38:08361 return Get()->shell_port_->GetAshConfig();
sky494c6cbd2017-03-27 20:57:48362}
363
moshayedic229a522017-05-05 18:14:26364// static
365bool Shell::ShouldUseIMEService() {
366 return Shell::GetAshConfig() == Config::MASH ||
367 (Shell::GetAshConfig() == Config::MUS &&
368 base::CommandLine::ForCurrentProcess()->HasSwitch(
369 switches::kUseIMEService));
370}
371
afakhrye4fae852017-05-09 18:49:06372// static
Wenzhao Zang56c292932017-08-02 04:58:34373void Shell::RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
Sammie Quon4d7dba62017-08-03 23:18:17374 PaletteTray::RegisterLocalStatePrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34375 WallpaperController::RegisterLocalStatePrefs(registry);
Sonny Sasaka55f69fc2017-08-28 21:29:37376 BluetoothPowerController::RegisterLocalStatePrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34377}
378
379// static
James Cookec144952017-09-01 00:05:16380void Shell::RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) {
381 AccessibilityController::RegisterProfilePrefs(registry, for_test);
Sonny Sasaka55f69fc2017-08-28 21:29:37382 BluetoothPowerController::RegisterProfilePrefs(registry);
Ahmed Fakhry4bf3f742018-02-06 17:33:36383 DockedMagnifierController::RegisterProfilePrefs(registry);
Jacob Dufaultffd9b0d2017-11-15 23:07:16384 LoginScreenController::RegisterProfilePrefs(registry, for_test);
Sammie Quon6c4e2b1f2017-10-13 16:54:18385 LogoutButtonTray::RegisterProfilePrefs(registry);
386 NightLightController::RegisterProfilePrefs(registry);
Vladislav Kaznacheevfefa6bd2017-10-14 00:25:24387 PaletteTray::RegisterProfilePrefs(registry);
Sammie Quon6c4e2b1f2017-10-13 16:54:18388 PaletteWelcomeBubble::RegisterProfilePrefs(registry);
389 ShelfController::RegisterProfilePrefs(registry);
Qiang Xuf1400a362017-09-14 02:28:30390 TouchDevicesController::RegisterProfilePrefs(registry);
Sammie Quon6c4e2b1f2017-10-13 16:54:18391 TrayCapsLock::RegisterProfilePrefs(registry, for_test);
afakhrye4fae852017-05-09 18:49:06392}
393
[email protected]57b8bb352012-01-11 05:11:46394views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
395 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04396 // Use translucent-style window frames for dialogs.
[email protected]85501fe2013-10-18 10:15:27397 return new CustomFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46398}
399
[email protected]2e236a52012-06-27 22:21:47400void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44401 const gfx::Insets& insets) {
Scott Violet596bb46342017-06-21 14:43:13402 window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow(contains,
403 insets);
[email protected]1a2145b2012-03-13 21:09:17404}
405
[email protected]58868abf2014-01-17 23:45:33406void Shell::OnCastingSessionStartedOrStopped(bool started) {
sky00c813f2017-03-08 22:48:55407 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18408 observer.OnCastingSessionStartedOrStopped(started);
[email protected]58868abf2014-01-17 23:45:33409}
410
varkhac71444e52017-05-25 22:51:34411void Shell::OnRootWindowAdded(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55412 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18413 observer.OnRootWindowAdded(root_window);
[email protected]0e3e7cb2014-04-12 05:18:25414}
415
[email protected]51f438112013-11-18 19:32:50416void Shell::CreateKeyboard() {
Keigo Okae82281a2017-06-14 13:59:14417 if (keyboard::IsKeyboardEnabled()) {
418 if (keyboard::KeyboardController::GetInstance()) {
419 RootWindowControllerList controllers = GetAllRootWindowControllers();
420 for (RootWindowControllerList::iterator iter = controllers.begin();
421 iter != controllers.end(); ++iter) {
422 (*iter)->DeactivateKeyboard(
423 keyboard::KeyboardController::GetInstance());
424 }
425 }
426 keyboard::KeyboardController::ResetInstance(
427 new keyboard::KeyboardController(shell_delegate_->CreateKeyboardUI(),
428 virtual_keyboard_controller_.get()));
429 for (auto& observer : shell_observers_)
430 observer.OnKeyboardControllerCreated();
431 }
432
jamescookb8dcef522016-06-25 14:42:55433 GetPrimaryRootWindowController()->ActivateKeyboard(
434 keyboard::KeyboardController::GetInstance());
[email protected]51f438112013-11-18 19:32:50435}
436
Keigo Okac7617a42017-06-14 11:33:24437void Shell::DestroyKeyboard() {
sky11cf8db92017-04-10 23:38:08438 // TODO(jamescook): Move keyboard create and hide into ShellPort.
sky79fa34712017-03-20 23:46:47439 keyboard_ui_->Hide();
[email protected]a0b3fb882014-04-07 19:26:03440 if (keyboard::KeyboardController::GetInstance()) {
[email protected]e1b299b2014-01-29 23:53:41441 RootWindowControllerList controllers = GetAllRootWindowControllers();
442 for (RootWindowControllerList::iterator iter = controllers.begin();
jamescookb8dcef522016-06-25 14:42:55443 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:03444 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]e1b299b2014-01-29 23:53:41445 }
446 }
achuith287b26e2015-09-03 17:49:18447 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]e1b299b2014-01-29 23:53:41448}
449
[email protected]da285852014-05-27 19:53:43450bool Shell::ShouldSaveDisplaySettings() {
Steven Bennetts7614ab52018-01-12 20:48:17451 // This function is only called from Chrome, hence the DCHECK for not-MASH.
452 DCHECK(GetAshConfig() != Config::MASH);
jamescookb8dcef522016-06-25 14:42:55453 return !(
454 screen_orientation_controller_->ignore_display_configuration_updates() ||
455 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43456}
[email protected]da285852014-05-27 19:53:43457
Ahmed Fakhry4bf3f742018-02-06 17:33:36458DockedMagnifierController* Shell::docked_magnifier_controller() {
459 DCHECK(switches::IsDockedMagnifierEnabled());
460 return docked_magnifier_controller_.get();
461}
462
afakhry9e0a18b32017-06-05 19:23:14463NightLightController* Shell::night_light_controller() {
Evan Stade48768f42017-10-10 05:23:30464 DCHECK(switches::IsNightLightEnabled());
afakhry9e0a18b32017-06-05 19:23:14465 return night_light_controller_.get();
466}
467
sky5ad143a2017-03-22 04:31:23468ShelfModel* Shell::shelf_model() {
469 return shelf_controller_->model();
470}
471
Thiago Farina3b086a02017-05-30 22:32:50472::wm::ActivationClient* Shell::activation_client() {
sky27344382017-03-08 21:30:32473 return focus_controller_.get();
474}
475
[email protected]c758fbf2012-03-25 22:53:59476void Shell::UpdateShelfVisibility() {
msw257a6a232017-06-01 01:46:30477 for (aura::Window* root : GetAllRootWindows())
478 Shelf::ForWindow(root)->UpdateVisibilityState();
[email protected]c758fbf2012-03-25 22:53:59479}
480
Wenzhao Zang44240fb2017-07-13 01:36:54481PrefService* Shell::GetLocalStatePrefService() const {
Sam McNallya853cd82017-08-30 01:55:10482 return local_state_.get();
Wenzhao Zang44240fb2017-07-13 01:36:54483}
484
[email protected]88d71122012-10-18 07:11:01485WebNotificationTray* Shell::GetWebNotificationTray() {
jamescook612205f2016-05-26 06:02:11486 return GetPrimaryRootWindowController()
jamescookb551aba2016-09-01 01:00:16487 ->GetStatusAreaWidget()
jamescook612205f2016-05-26 06:02:11488 ->web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28489}
490
[email protected]a0afeb12012-12-10 22:57:09491bool Shell::HasPrimaryStatusArea() {
jamescookb551aba2016-09-01 01:00:16492 return !!GetPrimaryRootWindowController()->GetStatusAreaWidget();
[email protected]31f19e32012-10-30 22:31:23493}
494
[email protected]a0afeb12012-12-10 22:57:09495SystemTray* Shell::GetPrimarySystemTray() {
496 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42497}
498
mswa7e8a5f2016-03-01 04:15:06499FirstRunHelper* Shell::CreateFirstRunHelper() {
500 return new FirstRunHelperImpl;
[email protected]59ccade2013-10-17 17:56:40501}
[email protected]87ec2202014-02-06 06:24:27502
yawanodc5533b32017-02-23 11:04:38503void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
504 window_tree_host_manager_->cursor_window_controller()
505 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
506}
507
Weidong Guod07448f2017-10-18 03:35:18508void Shell::UpdateCursorCompositingEnabled() {
509 SetCursorCompositingEnabled(
510 window_tree_host_manager_->cursor_window_controller()
511 ->ShouldEnableCursorCompositing());
512}
513
[email protected]87ec2202014-02-06 06:24:27514void Shell::SetCursorCompositingEnabled(bool enabled) {
erg36cfb952017-06-21 19:41:45515 if (GetAshConfig() != Config::MASH) {
516 // TODO: needs to work in mash. http://crbug.com/705592.
Weidong Guo7dfd1482017-11-08 05:56:28517 CursorWindowController* cursor_window_controller =
518 window_tree_host_manager_->cursor_window_controller();
519
520 if (cursor_window_controller->is_cursor_compositing_enabled() == enabled)
521 return;
522 cursor_window_controller->SetCursorCompositingEnabled(enabled);
sky494c6cbd2017-03-27 20:57:48523 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
524 }
[email protected]87ec2202014-02-06 06:24:27525}
[email protected]59ccade2013-10-17 17:56:40526
[email protected]f9466702012-09-17 16:35:27527void Shell::DoInitialWorkspaceAnimation() {
jamescookb8dcef522016-06-25 14:42:55528 return GetPrimaryRootWindowController()
529 ->workspace_controller()
530 ->DoInitialAnimation();
[email protected]f9466702012-09-17 16:35:27531}
532
xdaid4913762017-07-06 00:17:22533bool Shell::IsSplitViewModeActive() const {
534 return split_view_controller_->IsSplitViewModeActive();
535}
536
sky00c813f2017-03-08 22:48:55537void Shell::AddShellObserver(ShellObserver* observer) {
538 shell_observers_.AddObserver(observer);
539}
540
541void Shell::RemoveShellObserver(ShellObserver* observer) {
542 shell_observers_.RemoveObserver(observer);
543}
544
sky5ad143a2017-03-22 04:31:23545void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
varkha59679632017-06-01 00:42:05546 for (auto* root_window_controller : GetAllRootWindowControllers())
547 root_window_controller->UpdateAfterLoginStatusChange(status);
sky5ad143a2017-03-22 04:31:23548}
549
sky00c813f2017-03-08 22:48:55550void Shell::NotifyOverviewModeStarting() {
551 for (auto& observer : shell_observers_)
552 observer.OnOverviewModeStarting();
553}
554
Xiaoqian Daifb4698ed2018-02-23 20:11:06555void Shell::NotifyOverviewModeEnding() {
556 for (auto& observer : shell_observers_)
557 observer.OnOverviewModeEnding();
558}
559
sky00c813f2017-03-08 22:48:55560void Shell::NotifyOverviewModeEnded() {
561 for (auto& observer : shell_observers_)
562 observer.OnOverviewModeEnded();
563}
564
xdaid4913762017-07-06 00:17:22565void Shell::NotifySplitViewModeStarting() {
566 for (auto& observer : shell_observers_)
567 observer.OnSplitViewModeStarting();
568}
569
570void Shell::NotifySplitViewModeEnded() {
571 for (auto& observer : shell_observers_)
572 observer.OnSplitViewModeEnded();
573}
574
sky00c813f2017-03-08 22:48:55575void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
varkhac71444e52017-05-25 22:51:34576 aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55577 for (auto& observer : shell_observers_)
578 observer.OnFullscreenStateChanged(is_fullscreen, root_window);
579}
580
varkha19d7e6c52017-05-25 21:15:30581void Shell::NotifyPinnedStateChanged(aura::Window* pinned_window) {
sky00c813f2017-03-08 22:48:55582 for (auto& observer : shell_observers_)
583 observer.OnPinnedStateChanged(pinned_window);
584}
585
xiyuan38160182017-03-14 22:50:13586void Shell::NotifyVirtualKeyboardActivated(bool activated,
sky97f9a7432017-05-09 05:14:31587 aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55588 for (auto& observer : shell_observers_)
xiyuan38160182017-03-14 22:50:13589 observer.OnVirtualKeyboardStateChanged(activated, root_window);
sky00c813f2017-03-08 22:48:55590}
591
varkha6b016b0f2017-05-26 16:14:18592void Shell::NotifyShelfCreatedForRootWindow(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55593 for (auto& observer : shell_observers_)
594 observer.OnShelfCreatedForRootWindow(root_window);
595}
596
varkha6b016b0f2017-05-26 16:14:18597void Shell::NotifyShelfAlignmentChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55598 for (auto& observer : shell_observers_)
599 observer.OnShelfAlignmentChanged(root_window);
600}
601
varkha6b016b0f2017-05-26 16:14:18602void Shell::NotifyShelfAutoHideBehaviorChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55603 for (auto& observer : shell_observers_)
604 observer.OnShelfAutoHideBehaviorChanged(root_window);
605}
606
jamescook518dccbd2017-05-18 04:57:07607// static
608void Shell::SetIsBrowserProcessWithMash() {
609 g_is_browser_process_with_mash = true;
610}
611
muyuanlid766f2e2017-06-26 20:17:19612void Shell::NotifyAppListVisibilityChanged(bool visible,
613 aura::Window* root_window) {
newcomer2febb9832017-06-12 17:00:23614 for (auto& observer : shell_observers_)
615 observer.OnAppListVisibilityChanged(visible, root_window);
616}
617
[email protected]b6ba05d902013-10-04 21:38:45618////////////////////////////////////////////////////////////////////////////////
619// Shell, private:
620
skyb073203a2017-03-13 16:59:16621Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
sky11cf8db92017-04-10 23:38:08622 std::unique_ptr<ShellPort> shell_port)
623 : shell_port_(std::move(shell_port)),
Mitsuru Oshima04b54d02017-10-09 14:22:45624 ash_display_controller_(std::make_unique<AshDisplayController>()),
sky79fa34712017-03-20 23:46:47625 brightness_control_delegate_(
Mitsuru Oshima04b54d02017-10-09 14:22:45626 std::make_unique<system::BrightnessControllerChromeos>()),
627 cast_config_(std::make_unique<CastConfigController>()),
628 focus_cycler_(std::make_unique<FocusCycler>()),
629 ime_controller_(std::make_unique<ImeController>()),
630 immersive_context_(std::make_unique<ImmersiveContextAsh>()),
sky79fa34712017-03-20 23:46:47631 keyboard_brightness_control_delegate_(
Mitsuru Oshima04b54d02017-10-09 14:22:45632 std::make_unique<KeyboardBrightnessController>()),
sky79fa34712017-03-20 23:46:47633 locale_notification_controller_(
Mitsuru Oshima04b54d02017-10-09 14:22:45634 std::make_unique<LocaleNotificationController>()),
Jacob Dufaultffd9b0d2017-11-15 23:07:16635 login_screen_controller_(std::make_unique<LoginScreenController>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45636 media_controller_(std::make_unique<MediaController>()),
637 new_window_controller_(std::make_unique<NewWindowController>()),
638 session_controller_(std::make_unique<SessionController>(
Sam McNallyf4dab612017-08-16 03:06:33639 shell_delegate->GetShellConnector())),
Vladislav Kaznacheev92edf62e2017-10-13 22:08:01640 note_taking_controller_(std::make_unique<NoteTakingController>()),
skyb073203a2017-03-13 16:59:16641 shell_delegate_(std::move(shell_delegate)),
Mitsuru Oshima04b54d02017-10-09 14:22:45642 shutdown_controller_(std::make_unique<ShutdownController>()),
643 system_tray_controller_(std::make_unique<SystemTrayController>()),
644 system_tray_notifier_(std::make_unique<SystemTrayNotifier>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45645 vpn_list_(std::make_unique<VpnList>()),
646 window_cycle_controller_(std::make_unique<WindowCycleController>()),
647 window_selector_controller_(std::make_unique<WindowSelectorController>()),
648 app_list_(std::make_unique<app_list::AppList>()),
649 tray_bluetooth_helper_(std::make_unique<TrayBluetoothHelper>()),
kylechar7a067ec2017-01-07 01:16:28650 display_configurator_(new display::DisplayConfigurator()),
sadrul7a8785e2016-02-12 21:54:35651 native_cursor_manager_(nullptr),
Sam McNallye36abbc2017-07-20 01:04:28652 weak_factory_(this) {
skyabcae812017-01-18 17:01:34653 // TODO(sky): better refactor cash/mash dependencies. Perhaps put all cash
sky11cf8db92017-04-10 23:38:08654 // state on ShellPortClassic. http://crbug.com/671246.
skyabcae812017-01-18 17:01:34655
Scott Violet596bb46342017-06-21 14:43:13656 display_manager_.reset(ScreenAsh::CreateDisplayManager());
Mitsuru Oshima04b54d02017-10-09 14:22:45657 window_tree_host_manager_ = std::make_unique<WindowTreeHostManager>();
658 user_metrics_recorder_ = std::make_unique<UserMetricsRecorder>();
[email protected]b6ba05d902013-10-04 21:38:45659
[email protected]093b8d642014-04-03 20:59:28660 PowerStatus::Initialize();
sky5ad143a2017-03-22 04:31:23661
Xiyuan Xia22b1a6c2017-04-18 22:46:01662 session_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45663}
664
665Shell::~Shell() {
666 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
667
sky11cf8db92017-04-10 23:38:08668 const Config config = shell_port_->GetAshConfig();
skyabcae812017-01-18 17:01:34669
Scott Violet41562d1c2017-06-26 15:15:48670 user_metrics_recorder_->OnShellShuttingDown();
bruthigc24d11f2015-06-09 21:30:03671
Steven Bennetts7614ab52018-01-12 20:48:17672 shell_delegate_->PreShutdown();
[email protected]050e77182014-03-25 15:29:16673
[email protected]b6ba05d902013-10-04 21:38:45674 // Remove the focus from any window. This will prevent overhead and side
675 // effects (e.g. crashes) from changing focus during shutdown.
676 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18677 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45678
xdaid4913762017-07-06 00:17:22679 // Please keep in reverse order as in Init() because it's easy to miss one.
[email protected]b6ba05d902013-10-04 21:38:45680 if (window_modality_controller_)
681 window_modality_controller_.reset();
jamescook01bf23e72017-01-09 19:58:15682
[email protected]e4ea52362014-02-15 03:21:06683 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
684 magnifier_key_scroll_handler_.reset();
685
686 RemovePreTargetHandler(speech_feedback_handler_.get());
687 speech_feedback_handler_.reset();
jamescook01bf23e72017-01-09 19:58:15688
[email protected]b6ba05d902013-10-04 21:38:45689 RemovePreTargetHandler(overlay_filter_.get());
Xiyuan Xia22b1a6c2017-04-18 22:46:01690 overlay_filter_.reset();
691
[email protected]3537d472014-01-15 05:45:31692 RemovePreTargetHandler(accelerator_filter_.get());
693 RemovePreTargetHandler(event_transformation_handler_.get());
694 RemovePreTargetHandler(toplevel_window_event_handler_.get());
695 RemovePostTargetHandler(toplevel_window_event_handler_.get());
Scott Violet596bb46342017-06-21 14:43:13696 RemovePreTargetHandler(system_gesture_filter_.get());
697 RemovePreTargetHandler(mouse_cursor_filter_.get());
hariank0dd03dd2016-07-14 23:47:33698 RemovePreTargetHandler(modality_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45699
700 // TooltipController is deleted with the Shell so removing its references.
701 RemovePreTargetHandler(tooltip_controller_.get());
702
jonross0af45212015-01-13 18:55:46703 screen_orientation_controller_.reset();
yiyixa68ade512016-09-01 17:38:13704 screen_layout_observer_.reset();
jonross0af45212015-01-13 18:55:46705
Mitsuru Oshima0e9b7a62017-07-19 18:23:03706 // Destroy the virtual keyboard controller before the tablet mode controller
jamescook01bf23e72017-01-09 19:58:15707 // since the latters destructor triggers events that the former is listening
708 // to but no longer cares about.
rsadambbaf2c82015-01-07 17:54:13709 virtual_keyboard_controller_.reset();
jonross0af45212015-01-13 18:55:46710
Mitsuru Oshima0e9b7a62017-07-19 18:23:03711 // Destroy tablet mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57712 // need to be removed.
Mitsuru Oshima0e9b7a62017-07-19 18:23:03713 tablet_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57714
jdufault551152e2016-01-27 19:48:43715 // Destroy the keyboard before closing the shelf, since it will invoke a shelf
716 // layout.
Keigo Okac7617a42017-06-14 11:33:24717 DestroyKeyboard();
jdufault551152e2016-01-27 19:48:43718
sky07a24d42017-03-09 23:57:30719 toast_manager_.reset();
yoshiki32f51632016-03-24 01:24:43720
msw257a6a232017-06-01 01:46:30721 for (aura::Window* root : GetAllRootWindows())
722 Shelf::ForWindow(root)->ShutdownShelfWidget();
jamescookac6724332017-03-21 02:54:43723 tray_bluetooth_helper_.reset();
James Cookb50959e22017-08-10 20:24:38724
725 // Accesses root window containers.
726 logout_confirmation_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45727
[email protected]b6ba05d902013-10-04 21:38:45728 // Drag-and-drop must be canceled prior to close all windows.
729 drag_drop_controller_.reset();
730
Xiyuan Xia22b1a6c2017-04-18 22:46:01731 // Controllers who have WindowObserver added must be deleted
732 // before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03733
Qiang Xud77a90c2018-02-20 19:43:29734 persistent_window_controller_.reset();
735
[email protected]8c9d12a2013-12-06 18:39:03736 // VideoActivityNotifier must be deleted before |video_detector_| is
737 // deleted because it's observing video activity through
derat83b761392016-07-11 16:44:44738 // VideoDetector::Observer interface.
[email protected]8c9d12a2013-12-06 18:39:03739 video_activity_notifier_.reset();
[email protected]8c9d12a2013-12-06 18:39:03740 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25741 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03742
743 shadow_controller_.reset();
744 resize_shadow_controller_.reset();
745
sky37f0dd12016-07-19 18:00:59746 // Has to happen before ~MruWindowTracker.
sky5b45ed82017-03-27 02:54:23747 window_cycle_controller_.reset();
748 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03749
xdai7a8867cd2017-08-25 23:10:16750 // |split_view_controller_| needs to be deleted after
751 // |window_selector_controller_|.
752 split_view_controller_.reset();
753
skyabcae812017-01-18 17:01:34754 CloseAllRootWindowChildWindows();
755
afakhry58159392015-05-22 02:45:52756 // MruWindowTracker must be destroyed after all windows have been deleted to
757 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
758 // path. (crbug.com/485438).
sky5ab16472017-03-21 19:35:08759 mru_window_tracker_.reset();
[email protected]b6ba05d902013-10-04 21:38:45760
[email protected]b6ba05d902013-10-04 21:38:45761 // These need a valid Shell instance to clean up properly, so explicitly
762 // delete them before invalidating the instance.
763 // Alphabetical. TODO(oshima): sort.
764 magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45765 tooltip_controller_.reset();
766 event_client_.reset();
[email protected]3537d472014-01-15 05:45:31767 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45768 visibility_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45769
Toni Barzic85ae39e2017-12-07 05:50:18770 tray_action_.reset();
771
[email protected]b6ba05d902013-10-04 21:38:45772 power_button_controller_.reset();
773 lock_state_controller_.reset();
Toni Barzic9d0c82f42017-12-06 00:53:52774 backlights_forced_off_setter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45775
hidehiko6821ca42016-06-18 11:12:23776 screen_pinning_controller_.reset();
777
[email protected]b6ba05d902013-10-04 21:38:45778 resolution_notification_controller_.reset();
oshima5a296e82016-04-29 01:32:27779 screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49780 mouse_cursor_filter_.reset();
hariank0dd03dd2016-07-14 23:47:33781 modality_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45782
[email protected]03122891a2014-05-13 23:56:49783 touch_transformer_controller_.reset();
sammiequon203ae022016-09-18 17:23:42784 laser_pointer_controller_.reset();
785 partial_magnification_controller_.reset();
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:32786 highlighter_controller_.reset();
Yue Lia33960a2017-11-01 22:06:07787 voice_interaction_controller_.reset();
warx533c8f62016-04-12 01:19:43788
[email protected]b6ba05d902013-10-04 21:38:45789 // This also deletes all RootWindows. Note that we invoke Shutdown() on
oshimae2818922015-07-28 01:18:52790 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
msw257a6a232017-06-01 01:46:30791 // destruction of its owned RootWindowControllers relies on the value.
rjkroege2c9305402016-09-07 00:21:45792 ScreenAsh::CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12793 display_configuration_controller_.reset();
dtseng4ae0a882016-04-15 21:39:27794
sky15ef0aa2017-01-20 18:55:59795 // AppListDelegateImpl depends upon AppList.
796 app_list_delegate_impl_.reset();
797
sky07a24d42017-03-09 23:57:30798 // These members access Shell in their destructors.
799 wallpaper_controller_.reset();
James Cookec144952017-09-01 00:05:16800 accessibility_controller_.reset();
sky07a24d42017-03-09 23:57:30801 accessibility_delegate_.reset();
Evan Stade4d07c422017-09-01 21:51:51802 message_center_controller_.reset();
sky07a24d42017-03-09 23:57:30803
804 // Balances the Install() in Initialize().
805 views::FocusManagerFactory::Install(nullptr);
806
sky5ad143a2017-03-22 04:31:23807 // ShelfWindowWatcher has window observers and a pointer to the shelf model.
808 shelf_window_watcher_.reset();
809
tibellb93c729b2017-03-30 00:45:09810 // Removes itself as an observer of |pref_service_|.
sky5ad143a2017-03-22 04:31:23811 shelf_controller_.reset();
812
Ahmed Fakhrye96051f2017-12-12 17:42:17813 // NightLightController depends on the PrefService as well as the window tree
814 // host manager, and must be destructed before them. crbug.com/724231.
815 night_light_controller_ = nullptr;
Ahmed Fakhry4bf3f742018-02-06 17:33:36816 // Similarly for DockedMagnifierController.
817 docked_magnifier_controller_ = nullptr;
Ahmed Fakhrye96051f2017-12-12 17:42:17818
sky11cf8db92017-04-10 23:38:08819 shell_port_->Shutdown();
Scott Violet596bb46342017-06-21 14:43:13820 window_tree_host_manager_->Shutdown();
sky5ad143a2017-03-22 04:31:23821
sky27344382017-03-08 21:30:32822 // Depends on |focus_controller_|, so must be destroyed before.
oshimae2818922015-07-28 01:18:52823 window_tree_host_manager_.reset();
sky27344382017-03-08 21:30:32824 focus_controller_->RemoveObserver(this);
sky68612712017-04-27 04:45:04825 if (config != Config::CLASSIC &&
826 window_tree_client_->focus_synchronizer()->active_focus_client() ==
827 focus_controller_.get()) {
828 window_tree_client_->focus_synchronizer()->SetSingletonFocusClient(nullptr);
829 }
sky27344382017-03-08 21:30:32830 focus_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45831 screen_position_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45832
robert.bradfordab052492015-05-06 11:09:56833 display_color_manager_.reset();
Steven Bennetts7683e342018-01-02 21:29:52834 projecting_observer_.reset();
835
[email protected]7bc49bd2014-01-22 09:30:34836 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11837 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45838 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11839 display_configurator_->RemoveObserver(display_error_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45840 display_change_observer_.reset();
Steven Bennetts7683e342018-01-02 21:29:52841 display_shutdown_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45842
[email protected]093b8d642014-04-03 20:59:28843 PowerStatus::Shutdown();
pneubeck8be1f5422014-10-09 16:46:18844
sky88bd4be62016-06-09 17:34:41845 // Needs to happen right before |instance_| is reset.
sky11cf8db92017-04-10 23:38:08846 shell_port_.reset();
Xiyuan Xia22b1a6c2017-04-18 22:46:01847 session_controller_->RemoveObserver(this);
Sonny Sasaka55f69fc2017-08-28 21:29:37848 // BluetoothPowerController depends on the PrefService and must be destructed
849 // before it.
850 bluetooth_power_controller_ = nullptr;
Qiang Xuf1400a362017-09-14 02:28:30851 // TouchDevicesController depends on the PrefService and must be destructed
852 // before it.
853 touch_devices_controller_ = nullptr;
Ahmed Fakhrye96051f2017-12-12 17:42:17854
Sam McNallya853cd82017-08-30 01:55:10855 local_state_.reset();
skyb073203a2017-03-13 16:59:16856 shell_delegate_.reset();
sky88bd4be62016-06-09 17:34:41857
Scott Violet17a61722017-06-19 17:54:31858 for (auto& observer : shell_observers_)
859 observer.OnShellDestroyed();
860
[email protected]b6ba05d902013-10-04 21:38:45861 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18862 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45863}
864
Scott Violetc8a1c6c2017-11-29 23:17:36865void Shell::Init(ui::ContextFactory* context_factory,
866 ui::ContextFactoryPrivate* context_factory_private) {
sky11cf8db92017-04-10 23:38:08867 const Config config = shell_port_->GetAshConfig();
skyabcae812017-01-18 17:01:34868
James Cookbd0b7792017-11-17 03:24:26869 // These controllers call Shell::Get() in their constructors, so they cannot
870 // be in the member initialization list.
Evan Stade48768f42017-10-10 05:23:30871 if (switches::IsNightLightEnabled())
Mitsuru Oshima04b54d02017-10-09 14:22:45872 night_light_controller_ = std::make_unique<NightLightController>();
Qiang Xuf1400a362017-09-14 02:28:30873 touch_devices_controller_ = std::make_unique<TouchDevicesController>();
Mitsuru Oshima04b54d02017-10-09 14:22:45874 bluetooth_power_controller_ = std::make_unique<BluetoothPowerController>();
Sonny Sasaka55f69fc2017-08-28 21:29:37875
James Cook8532dbc2017-07-31 21:54:51876 // Connector can be null in tests.
Sam McNallya853cd82017-08-30 01:55:10877 if (shell_delegate_->GetShellConnector()) {
James Cook8532dbc2017-07-31 21:54:51878 // Connect to local state prefs now, but wait for an active user before
879 // connecting to the profile pref service. The login screen has a temporary
880 // user profile that is not associated with a real user.
Taiju Tsuiki36c517d2017-05-18 06:45:43881 auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
Wenzhao Zang56c292932017-08-02 04:58:34882 RegisterLocalStatePrefs(pref_registry.get());
tibellb93c729b2017-03-30 00:45:09883 prefs::ConnectToPrefService(
Sam McNally538fca1e2017-07-14 03:10:43884 shell_delegate_->GetShellConnector(), std::move(pref_registry),
Sam McNallye36abbc2017-07-20 01:04:28885 base::Bind(&Shell::OnLocalStatePrefServiceInitialized,
886 weak_factory_.GetWeakPtr()),
887 prefs::mojom::kLocalStateServiceName);
jonrossc4ba10602017-04-07 20:51:05888 }
skyb073203a2017-03-13 16:59:16889
sky11cf8db92017-04-10 23:38:08890 // Some delegates access ShellPort during their construction. Create them here
891 // instead of the ShellPort constructor.
skyb073203a2017-03-13 16:59:16892 accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate());
Mitsuru Oshima04b54d02017-10-09 14:22:45893 accessibility_controller_ = std::make_unique<AccessibilityController>(
James Cook5fbdccb2017-09-01 21:17:55894 shell_delegate_->GetShellConnector());
Mitsuru Oshima04b54d02017-10-09 14:22:45895 toast_manager_ = std::make_unique<ToastManager>();
sky07a24d42017-03-09 23:57:30896
sky07a24d42017-03-09 23:57:30897 // Install the custom factory early on so that views::FocusManagers for Tray,
898 // Shelf, and WallPaper could be created by the factory.
899 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
900
Mitsuru Oshima04b54d02017-10-09 14:22:45901 wallpaper_controller_ = std::make_unique<WallpaperController>();
sky07a24d42017-03-09 23:57:30902
Mitsuru Oshima04b54d02017-10-09 14:22:45903 app_list_delegate_impl_ = std::make_unique<AppListDelegateImpl>();
sky15ef0aa2017-01-20 18:55:59904
sky11cf8db92017-04-10 23:38:08905 // TODO(sky): move creation to ShellPort.
skye5fd1222017-04-12 18:43:23906 if (config != Config::MASH)
Mitsuru Oshima04b54d02017-10-09 14:22:45907 immersive_handler_factory_ = std::make_unique<ImmersiveHandlerFactoryAsh>();
skyb7b54092016-08-19 16:00:09908
Mitsuru Oshima04b54d02017-10-09 14:22:45909 window_positioner_ = std::make_unique<WindowPositioner>();
sky984c1892016-04-20 00:00:34910
sky494c6cbd2017-03-27 20:57:48911 if (config == Config::CLASSIC) {
erg36cfb952017-06-21 19:41:45912 native_cursor_manager_ = new NativeCursorManagerAshClassic;
Mitsuru Oshima04b54d02017-10-09 14:22:45913 cursor_manager_ = std::make_unique<CursorManager>(
erg36cfb952017-06-21 19:41:45914 base::WrapUnique(native_cursor_manager_));
915 } else if (config == Config::MUS) {
916 native_cursor_manager_ = new NativeCursorManagerAshMus;
Mitsuru Oshima04b54d02017-10-09 14:22:45917 cursor_manager_ = std::make_unique<CursorManager>(
erg36cfb952017-06-21 19:41:45918 base::WrapUnique(native_cursor_manager_));
skyabcae812017-01-18 17:01:34919 }
skyfee520c2016-02-11 19:57:46920
Steven Bennettscce939192018-01-12 22:57:12921 // TODO(stevenjb): ChromeShellDelegate::PreInit currently handles
922 // DisplayPreference initialization, required for InitializeDisplayManager.
923 // Before we can move that code into ash/display where it belongs, we need to
924 // wait for |lcoal_state_| to be set in OnLocalStatePrefServiceInitialized
925 // before initializing DisplayPreferences (and therefore DisplayManager).
926 // http://crbug.com/678949.
skyb073203a2017-03-13 16:59:16927 shell_delegate_->PreInit();
[email protected]0249a6532013-10-31 06:53:34928
Steven Bennetts7683e342018-01-02 21:29:52929 InitializeDisplayManager();
[email protected]b6ba05d902013-10-04 21:38:45930
newcomer2febb9832017-06-12 17:00:23931 if (config == Config::CLASSIC) {
Steven Bennetts7683e342018-01-02 21:29:52932 // This will initialize aura::Env which requires |display_manager_| to
933 // be initialized first.
Scott Violetc8a1c6c2017-11-29 23:17:36934 aura::Env::GetInstance()->set_context_factory(context_factory);
skyabcae812017-01-18 17:01:34935 aura::Env::GetInstance()->set_context_factory_private(
Scott Violetc8a1c6c2017-11-29 23:17:36936 context_factory_private);
skyabcae812017-01-18 17:01:34937 }
[email protected]ecca62b2013-10-09 16:18:53938
[email protected]b6ba05d902013-10-04 21:38:45939 // The WindowModalityController needs to be at the front of the input event
940 // pretarget handler list to ensure that it processes input events when modal
941 // windows are active.
jamescookb8dcef522016-06-25 14:42:55942 window_modality_controller_.reset(new ::wm::WindowModalityController(this));
[email protected]b6ba05d902013-10-04 21:38:45943
[email protected]e319c7e2014-03-14 19:56:14944 env_filter_.reset(new ::wm::CompoundEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45945 AddPreTargetHandler(env_filter_.get());
946
sky27344382017-03-08 21:30:32947 // FocusController takes ownership of AshFocusRules.
948 focus_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:45949 std::make_unique<::wm::FocusController>(new wm::AshFocusRules());
sky27344382017-03-08 21:30:32950 focus_controller_->AddObserver(this);
sky68612712017-04-27 04:45:04951 if (config != Config::CLASSIC) {
952 window_tree_client_->focus_synchronizer()->SetSingletonFocusClient(
953 focus_controller_.get());
954 }
[email protected]b6ba05d902013-10-04 21:38:45955
[email protected]093b8d642014-04-03 20:59:28956 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:45957
Scott Violet596bb46342017-06-21 14:43:13958 window_tree_host_manager_->Start();
959 AshWindowTreeHostInitParams ash_init_params;
960 window_tree_host_manager_->CreatePrimaryHost(ash_init_params);
961
Scott Violet3c554ae2017-12-13 02:25:41962 time_to_first_present_recorder_ =
963 std::make_unique<TimeToFirstPresentRecorder>(GetPrimaryRootWindow());
964
mswad3d9552017-05-18 21:23:36965 root_window_for_new_windows_ = GetPrimaryRootWindow();
[email protected]b6ba05d902013-10-04 21:38:45966
Scott Violet596bb46342017-06-21 14:43:13967 resolution_notification_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:45968 std::make_unique<ResolutionNotificationController>();
[email protected]b6ba05d902013-10-04 21:38:45969
deratc6250a02017-01-25 05:51:53970 if (cursor_manager_) {
oshimaf84b0da722016-04-27 19:47:19971 cursor_manager_->SetDisplay(
972 display::Screen::GetScreen()->GetPrimaryDisplay());
deratc6250a02017-01-25 05:51:53973 }
[email protected]b6ba05d902013-10-04 21:38:45974
sky11cf8db92017-04-10 23:38:08975 accelerator_controller_ = shell_port_->CreateAcceleratorController();
Mitsuru Oshima04b54d02017-10-09 14:22:45976 tablet_mode_controller_ = std::make_unique<TabletModeController>();
977 shelf_controller_ = std::make_unique<ShelfController>();
[email protected]b6ba05d902013-10-04 21:38:45978
spange9b51272014-12-11 01:20:10979 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06980 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
spange9b51272014-12-11 01:20:10981 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06982 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:39983
[email protected]b6ba05d902013-10-04 21:38:45984 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:45985
derat2d4e62d2015-01-09 16:09:17986 // ui::UserActivityDetector passes events to observers, so let them get
[email protected]b6ba05d902013-10-04 21:38:45987 // rewritten first.
derat2d4e62d2015-01-09 16:09:17988 user_activity_detector_.reset(new ui::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:45989
[email protected]093b8d642014-04-03 20:59:28990 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45991 AddPreTargetHandler(overlay_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45992
[email protected]60d677d2014-05-30 13:07:02993 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
dchenga94547472016-04-08 08:41:11994 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
sky81a2d792017-03-17 19:14:39995 accelerator_controller_->accelerator_history()));
[email protected]b6ba05d902013-10-04 21:38:45996 AddPreTargetHandler(accelerator_filter_.get());
997
[email protected]093b8d642014-04-03 20:59:28998 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:45999 AddPreTargetHandler(event_transformation_handler_.get());
1000
sky11cf8db92017-04-10 23:38:081001 toplevel_window_event_handler_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451002 std::make_unique<ToplevelWindowEventHandler>();
[email protected]3537d472014-01-15 05:45:311003
sky83b1bb12017-04-24 20:29:281004 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:341005 system_gesture_filter_.reset(new SystemGestureEventFilter);
1006 AddPreTargetHandler(system_gesture_filter_.get());
1007 }
[email protected]b6ba05d902013-10-04 21:38:451008
[email protected]354520b2014-06-21 04:31:011009 sticky_keys_controller_.reset(new StickyKeysController);
Mitsuru Oshima04b54d02017-10-09 14:22:451010 screen_pinning_controller_ = std::make_unique<ScreenPinningController>();
[email protected]354520b2014-06-21 04:31:011011
Toni Barzic9d0c82f42017-12-06 00:53:521012 backlights_forced_off_setter_ = std::make_unique<BacklightsForcedOffSetter>();
1013
Toni Barzic85ae39e2017-12-07 05:50:181014 tray_action_ =
1015 std::make_unique<TrayAction>(backlights_forced_off_setter_.get());
1016
jamescookd9f152f2016-11-15 00:53:081017 lock_state_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451018 std::make_unique<LockStateController>(shutdown_controller_.get());
Toni Barzic9d0c82f42017-12-06 00:53:521019 power_button_controller_ = std::make_unique<PowerButtonController>(
1020 backlights_forced_off_setter_.get());
[email protected]685442f32014-02-28 10:40:061021 // Pass the initial display state to PowerButtonController.
1022 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:091023 display_configurator_->cached_displays());
jamescook01bf23e72017-01-09 19:58:151024
derat036f91b92017-05-05 00:33:181025 // Forward user activity from the window server to |user_activity_detector_|.
derat94887a22017-01-20 18:17:251026 // The connector is unavailable in some tests.
derat036f91b92017-05-05 00:33:181027 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS &&
1028 shell_delegate_->GetShellConnector()) {
derat94887a22017-01-20 18:17:251029 ui::mojom::UserActivityMonitorPtr user_activity_monitor;
skyb073203a2017-03-13 16:59:161030 shell_delegate_->GetShellConnector()->BindInterface(ui::mojom::kServiceName,
1031 &user_activity_monitor);
Mitsuru Oshima04b54d02017-10-09 14:22:451032 user_activity_forwarder_ = std::make_unique<aura::UserActivityForwarder>(
derat94887a22017-01-20 18:17:251033 std::move(user_activity_monitor), user_activity_detector_.get());
1034 }
1035
Scott Violet361833fb2017-06-21 22:25:201036 // In mash drag and drop is handled by mus.
1037 if (config != Config::MASH)
Mitsuru Oshima04b54d02017-10-09 14:22:451038 drag_drop_controller_ = std::make_unique<DragDropController>();
Scott Violet361833fb2017-06-21 22:25:201039
oshima5a296e82016-04-29 01:32:271040 // |screenshot_controller_| needs to be created (and prepended as a
mukai19274bdd2015-02-24 22:37:481041 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
oshima5a296e82016-04-29 01:32:271042 // process mouse events prior to screenshot session.
mukai19274bdd2015-02-24 22:37:481043 // See http://crbug.com/459214
James Cook5e9d3402017-11-01 00:20:121044 screenshot_controller_ = std::make_unique<ScreenshotController>(
1045 shell_delegate_->CreateScreenshotDelegate());
Mitsuru Oshima04b54d02017-10-09 14:22:451046 mouse_cursor_filter_ = std::make_unique<MouseCursorEventFilter>();
Scott Violet596bb46342017-06-21 14:43:131047 PrependPreTargetHandler(mouse_cursor_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:451048
1049 // Create Controllers that may need root window.
1050 // TODO(oshima): Move as many controllers before creating
1051 // RootWindowController as possible.
1052 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:451053
sammiequon203ae022016-09-18 17:23:421054 laser_pointer_controller_.reset(new LaserPointerController());
1055 partial_magnification_controller_.reset(new PartialMagnificationController());
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:321056 highlighter_controller_.reset(new HighlighterController());
Yue Lia33960a2017-11-01 22:06:071057 voice_interaction_controller_ =
1058 std::make_unique<VoiceInteractionController>();
sammiequon203ae022016-09-18 17:23:421059
jamescookb8dcef522016-06-25 14:42:551060 magnification_controller_.reset(MagnificationController::CreateInstance());
Mitsuru Oshima04b54d02017-10-09 14:22:451061 mru_window_tracker_ = std::make_unique<MruWindowTracker>();
[email protected]b6ba05d902013-10-04 21:38:451062
[email protected]55398d22013-10-10 19:49:201063 autoclick_controller_.reset(AutoclickController::CreateInstance());
1064
[email protected]b6ba05d902013-10-04 21:38:451065 high_contrast_controller_.reset(new HighContrastController);
Saman Sami3fb310d2017-11-09 16:51:541066
Ahmed Fakhry4bf3f742018-02-06 17:33:361067 if (switches::IsDockedMagnifierEnabled()) {
1068 docked_magnifier_controller_ =
1069 std::make_unique<DockedMagnifierController>();
1070 }
1071
Saman Sami3fb310d2017-11-09 16:51:541072 viz::mojom::VideoDetectorObserverPtr observer;
1073 video_detector_ =
1074 std::make_unique<VideoDetector>(mojo::MakeRequest(&observer));
1075 shell_port_->AddVideoDetectorObserver(std::move(observer));
[email protected]b6ba05d902013-10-04 21:38:451076
oshimaebbe63772015-02-19 18:41:321077 tooltip_controller_.reset(new views::corewm::TooltipController(
dchenga94547472016-04-08 08:41:111078 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451079 AddPreTargetHandler(tooltip_controller_.get());
1080
hariank0dd03dd2016-07-14 23:47:331081 modality_filter_.reset(new SystemModalContainerEventFilter(this));
1082 AddPreTargetHandler(modality_filter_.get());
1083
[email protected]093b8d642014-04-03 20:59:281084 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451085
skyabcae812017-01-18 17:01:341086 // Must occur after Shell has installed its early pre-target handlers (for
1087 // example, WindowModalityController).
sky11cf8db92017-04-10 23:38:081088 shell_port_->CreatePointerWatcherAdapter();
[email protected]b6ba05d902013-10-04 21:38:451089
[email protected]093b8d642014-04-03 20:59:281090 resize_shadow_controller_.reset(new ResizeShadowController());
sky27344382017-03-08 21:30:321091 shadow_controller_.reset(new ::wm::ShadowController(focus_controller_.get()));
[email protected]b6ba05d902013-10-04 21:38:451092
James Cookb50959e22017-08-10 20:24:381093 logout_confirmation_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451094 std::make_unique<LogoutConfirmationController>();
[email protected]b6ba05d902013-10-04 21:38:451095
jamescookac6724332017-03-21 02:54:431096 // May trigger initialization of the Bluetooth adapter.
1097 tray_bluetooth_helper_->Initialize();
1098
kylechar55f0eaf22017-01-11 22:57:371099 // Create AshTouchTransformController before
oshimae2818922015-07-28 01:18:521100 // WindowTreeHostManager::InitDisplays()
kylechar55f0eaf22017-01-11 22:57:371101 // since AshTouchTransformController listens on
oshimae2818922015-07-28 01:18:521102 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
Mitsuru Oshima04b54d02017-10-09 14:22:451103 touch_transformer_controller_ = std::make_unique<AshTouchTransformController>(
Scott Violet596bb46342017-06-21 14:43:131104 display_configurator_.get(), display_manager_.get(),
1105 shell_port_->CreateTouchTransformDelegate());
[email protected]03122891a2014-05-13 23:56:491106
sky11cf8db92017-04-10 23:38:081107 keyboard_ui_ = shell_port_->CreateKeyboardUI();
skyfee520c2016-02-11 19:57:461108
Scott Violet596bb46342017-06-21 14:43:131109 window_tree_host_manager_->InitHosts();
1110 shell_port_->OnHostsInitialized();
[email protected]b6ba05d902013-10-04 21:38:451111
rsadam9172bc8a2014-10-29 23:37:381112 // Needs to be created after InitDisplays() since it may cause the virtual
1113 // keyboard to be deployed.
sky83b1bb12017-04-24 20:29:281114 if (config != Config::MASH)
skyabcae812017-01-18 17:01:341115 virtual_keyboard_controller_.reset(new VirtualKeyboardController);
rsadam9172bc8a2014-10-29 23:37:381116
sadrul7a8785e2016-02-12 21:54:351117 if (cursor_manager_) {
Steven Bennetts6d12eb42018-01-09 16:49:081118 cursor_manager_->HideCursor(); // Hide the mouse cursor on startup.
ergeeba7c622017-04-25 18:06:161119 cursor_manager_->SetCursor(ui::CursorType::kPointer);
sadrul7a8785e2016-02-12 21:54:351120 }
[email protected]b6ba05d902013-10-04 21:38:451121
Mitsuru Oshima04b54d02017-10-09 14:22:451122 peripheral_battery_notifier_ = std::make_unique<PeripheralBatteryNotifier>();
[email protected]093b8d642014-04-03 20:59:281123 power_event_observer_.reset(new PowerEventObserver());
[email protected]ded58fd2013-10-09 07:56:551124 user_activity_notifier_.reset(
[email protected]b0fa7012014-04-16 12:50:571125 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
[email protected]ded58fd2013-10-09 07:56:551126 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281127 new VideoActivityNotifier(video_detector_.get()));
1128 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
Scott Violet596bb46342017-06-21 14:43:131129 screen_orientation_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451130 std::make_unique<ScreenOrientationController>();
Scott Violet596bb46342017-06-21 14:43:131131 screen_layout_observer_.reset(new ScreenLayoutObserver());
yiyix90cfee22017-02-16 05:38:181132 sms_observer_.reset(new SmsObserver());
jamescook01bf23e72017-01-09 19:58:151133
xdaid4913762017-07-06 00:17:221134 split_view_controller_.reset(new SplitViewController());
1135
[email protected]b6ba05d902013-10-04 21:38:451136 // The compositor thread and main message loop have to be running in
1137 // order to create mirror window. Run it after the main message loop
1138 // is started.
Scott Violet596bb46342017-06-21 14:43:131139 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031140
Mitsuru Oshima04b54d02017-10-09 14:22:451141 message_center_controller_ = std::make_unique<MessageCenterController>();
Evan Stade2c43a87b32017-08-31 17:53:101142
James Cook0ba192bf2017-12-01 20:53:111143 // Mash implements the show taps feature with a separate mojo app.
1144 // GetShellConnector() is null in unit tests.
1145 if (config == Config::MASH && shell_delegate_->GetShellConnector() &&
1146 base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowTaps)) {
1147 mash::mojom::LaunchablePtr launchable;
James Cook2268bef2018-02-27 01:12:161148 shell_delegate_->GetShellConnector()->BindInterface("touch_hud_app",
James Cook0ba192bf2017-12-01 20:53:111149 &launchable);
1150 launchable->Launch(mash::mojom::kWindow, mash::mojom::LaunchMode::DEFAULT);
1151 }
1152
sky00c813f2017-03-08 22:48:551153 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:181154 observer.OnShellInitialized();
phweiss0bf64c52015-11-17 12:56:181155
Scott Violet41562d1c2017-06-26 15:15:481156 user_metrics_recorder_->OnShellInitialized();
[email protected]b6ba05d902013-10-04 21:38:451157}
1158
Steven Bennetts7683e342018-01-02 21:29:521159void Shell::InitializeDisplayManager() {
1160 const Config config = shell_port_->GetAshConfig();
1161 bool display_initialized = display_manager_->InitFromCommandLine();
1162
1163 if (!display_initialized && config != Config::CLASSIC) {
1164 // Run display configuration off device in mus mode.
1165 display_manager_->set_configure_displays(true);
1166 display_configurator_->set_configure_display(true);
1167 }
1168 display_configuration_controller_ =
1169 std::make_unique<DisplayConfigurationController>(
1170 display_manager_.get(), window_tree_host_manager_.get());
1171 display_configurator_->Init(shell_port_->CreateNativeDisplayDelegate(),
1172 false);
Qiang Xud77a90c2018-02-20 19:43:291173 persistent_window_controller_ =
1174 std::make_unique<PersistentWindowController>();
Steven Bennetts7683e342018-01-02 21:29:521175
1176 projecting_observer_ =
1177 std::make_unique<ProjectingObserver>(display_configurator_.get());
1178
1179 if (!display_initialized) {
1180 if (config != Config::CLASSIC && !chromeos::IsRunningAsSystemCompositor()) {
1181 display::mojom::DevDisplayControllerPtr controller;
1182 shell_delegate_->GetShellConnector()->BindInterface(
1183 ui::mojom::kServiceName, &controller);
1184 display_manager_->SetDevDisplayController(std::move(controller));
1185 }
1186
1187 if (config != Config::CLASSIC || chromeos::IsRunningAsSystemCompositor()) {
1188 display_change_observer_ =
1189 std::make_unique<display::DisplayChangeObserver>(
1190 display_configurator_.get(), display_manager_.get());
1191
1192 display_shutdown_observer_ = std::make_unique<DisplayShutdownObserver>(
1193 display_configurator_.get());
1194
1195 // Register |display_change_observer_| first so that the rest of
1196 // observer gets invoked after the root windows are configured.
1197 display_configurator_->AddObserver(display_change_observer_.get());
1198 display_error_observer_.reset(new DisplayErrorObserver());
1199 display_configurator_->AddObserver(display_error_observer_.get());
1200 display_configurator_->set_state_controller(
1201 display_change_observer_.get());
1202 display_configurator_->set_mirroring_controller(display_manager_.get());
1203 display_configurator_->ForceInitialConfigure();
1204 display_initialized = true;
1205 }
1206 }
1207
1208 display_color_manager_ =
1209 std::make_unique<DisplayColorManager>(display_configurator_.get());
1210
1211 if (!display_initialized)
1212 display_manager_->InitDefaultDisplay();
1213
1214 if (config == Config::CLASSIC)
1215 display_manager_->RefreshFontParams();
1216}
1217
[email protected]41baaed2013-11-09 04:18:261218void Shell::InitRootWindow(aura::Window* root_window) {
sky27344382017-03-08 21:30:321219 DCHECK(focus_controller_);
[email protected]d90b8392012-06-13 09:34:561220 DCHECK(visibility_controller_.get());
[email protected]d90b8392012-06-13 09:34:561221
sky27344382017-03-08 21:30:321222 aura::client::SetFocusClient(root_window, focus_controller_.get());
Thiago Farina3b086a02017-05-30 22:32:501223 ::wm::SetActivationClient(root_window, focus_controller_.get());
sky27344382017-03-08 21:30:321224 root_window->AddPreTargetHandler(focus_controller_.get());
[email protected]d90b8392012-06-13 09:34:561225 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
Scott Violet361833fb2017-06-21 22:25:201226 if (drag_drop_controller_) {
1227 DCHECK_NE(Config::MASH, GetAshConfig());
1228 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
1229 } else {
1230 DCHECK_EQ(Config::MASH, GetAshConfig());
1231 }
[email protected]8d625fb2012-07-18 16:40:061232 aura::client::SetScreenPositionClient(root_window,
1233 screen_position_controller_.get());
sadrul7a8785e2016-02-12 21:54:351234 aura::client::SetCursorClient(root_window, cursor_manager_.get());
Thiago Farina3b086a02017-05-30 22:32:501235 ::wm::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381236 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561237
Thiago Farina3b086a02017-05-30 22:32:501238 ::wm::SetWindowMoveClient(root_window, toplevel_window_event_handler_.get());
[email protected]3537d472014-01-15 05:45:311239 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1240 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
[email protected]d90b8392012-06-13 09:34:561241}
1242
skyabcae812017-01-18 17:01:341243void Shell::CloseAllRootWindowChildWindows() {
msw257a6a232017-06-01 01:46:301244 for (aura::Window* root : GetAllRootWindows()) {
1245 RootWindowController* controller = RootWindowController::ForWindow(root);
skyabcae812017-01-18 17:01:341246 if (controller) {
1247 controller->CloseChildWindows();
1248 } else {
msw257a6a232017-06-01 01:46:301249 while (!root->children().empty()) {
1250 aura::Window* child = root->children()[0];
skyabcae812017-01-18 17:01:341251 delete child;
1252 }
1253 }
1254 }
1255}
1256
[email protected]c0ce80e2012-10-05 23:28:271257bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1258 RootWindowControllerList controllers = GetAllRootWindowControllers();
oshima9a61ecf2016-06-18 10:43:051259 for (RootWindowController* controller : controllers) {
1260 if (controller->CanWindowReceiveEvents(window))
[email protected]602022b2014-03-31 17:07:311261 return true;
[email protected]c0ce80e2012-10-05 23:28:271262 }
1263 return false;
1264}
1265
[email protected]049cf34b2012-12-07 17:15:481266////////////////////////////////////////////////////////////////////////////////
1267// Shell, ui::EventTarget overrides:
1268
[email protected]869f6352012-12-06 20:47:171269bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411270 return true;
1271}
1272
1273ui::EventTarget* Shell::GetParentTarget() {
[email protected]ff0278852013-11-05 22:35:481274 return aura::Env::GetInstance();
[email protected]5097e692012-10-30 22:08:411275}
1276
dchenga94547472016-04-08 08:41:111277std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1278 return std::unique_ptr<ui::EventTargetIterator>();
[email protected]3e670aa2013-12-02 19:04:321279}
1280
1281ui::EventTargeter* Shell::GetEventTargeter() {
1282 NOTREACHED();
achuith287b26e2015-09-03 17:49:181283 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321284}
1285
sky27344382017-03-08 21:30:321286void Shell::OnWindowActivated(
Thiago Farina3b086a02017-05-30 22:32:501287 ::wm::ActivationChangeObserver::ActivationReason reason,
sky27344382017-03-08 21:30:321288 aura::Window* gained_active,
1289 aura::Window* lost_active) {
mswad3d9552017-05-18 21:23:361290 if (gained_active)
1291 root_window_for_new_windows_ = gained_active->GetRootWindow();
sky27344382017-03-08 21:30:321292}
1293
Xiyuan Xiab64fd0a2017-04-13 17:53:141294void Shell::OnSessionStateChanged(session_manager::SessionState state) {
Aga Wronskae195ad22017-12-20 01:38:111295 // Initialize the |shelf_window_watcher_| when a session becomes active.
1296 // Shelf itself is initialized in RootWindowController.
sky5ad143a2017-03-22 04:31:231297 if (state == session_manager::SessionState::ACTIVE) {
Aga Wronskae195ad22017-12-20 01:38:111298 if (!shelf_window_watcher_)
1299 shelf_window_watcher_ =
1300 std::make_unique<ShelfWindowWatcher>(shelf_model());
okac21941d2017-06-20 17:54:441301 }
Steven Bennetts43b3c212018-01-08 16:39:581302
Steven Bennetts9fd12ad2017-11-09 23:36:271303 // NOTE: keyboard::IsKeyboardEnabled() is false in mash, but may not be in
1304 // unit tests. crbug.com/646565.
Steven Bennetts43b3c212018-01-08 16:39:581305 if (keyboard::IsKeyboardEnabled()) {
1306 switch (state) {
1307 case session_manager::SessionState::OOBE:
1308 case session_manager::SessionState::LOGIN_PRIMARY:
1309 // Ensure that the keyboard controller is activated for the primary
1310 // window.
1311 GetPrimaryRootWindowController()->ActivateKeyboard(
1312 keyboard::KeyboardController::GetInstance());
1313 break;
1314 case session_manager::SessionState::LOGGED_IN_NOT_ACTIVE:
1315 case session_manager::SessionState::ACTIVE:
1316 // Recreate the keyboard on user profile change, to refresh keyboard
1317 // extensions with the new profile and ensure the extensions call the
1318 // proper IME. |LOGGED_IN_NOT_ACTIVE| is needed so that the virtual
1319 // keyboard works on supervised user creation, http://crbug.com/712873.
1320 // |ACTIVE| is also needed for guest user workflow.
1321 CreateKeyboard();
1322 break;
1323 default:
1324 break;
1325 }
sky5ad143a2017-03-22 04:31:231326 }
Scott Violet0c0dcde2017-08-04 21:48:181327
1328 shell_port_->UpdateSystemModalAndBlockingContainers();
xiyuan233f4e72017-04-06 06:59:561329}
sky5ad143a2017-03-22 04:31:231330
Xiyuan Xiab64fd0a2017-04-13 17:53:141331void Shell::OnLoginStatusChanged(LoginStatus login_status) {
xiyuan233f4e72017-04-06 06:59:561332 UpdateAfterLoginStatusChange(login_status);
sky5ad143a2017-03-22 04:31:231333}
1334
Xiyuan Xiab64fd0a2017-04-13 17:53:141335void Shell::OnLockStateChanged(bool locked) {
xiyuan7ebbf7f2017-04-10 16:49:101336#ifndef NDEBUG
1337 // Make sure that there is no system modal in Lock layer when unlocked.
1338 if (!locked) {
1339 aura::Window::Windows containers = wm::GetContainersFromAllRootWindows(
1340 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
1341 for (aura::Window* container : containers)
1342 DCHECK(container->children().empty());
1343 }
1344#endif
1345}
1346
Sam McNallye36abbc2017-07-20 01:04:281347void Shell::OnLocalStatePrefServiceInitialized(
1348 std::unique_ptr<::PrefService> pref_service) {
Sam McNallya853cd82017-08-30 01:55:101349 DCHECK(!local_state_);
James Cook8532dbc2017-07-31 21:54:511350 // |pref_service| is null if can't connect to Chrome (as happens when
Scott Violet8ff9c302018-02-22 22:28:351351 // running mash outside of chrome --enable-features=Mash and chrome isn't
1352 // built).
Sam McNallya853cd82017-08-30 01:55:101353 if (!pref_service)
1354 return;
1355
1356 local_state_ = std::move(pref_service);
James Cookbbe5cb12017-08-08 18:32:211357
1358 for (auto& observer : shell_observers_)
Sam McNallya853cd82017-08-30 01:55:101359 observer.OnLocalStatePrefServiceInitialized(local_state_.get());
Sam McNallye36abbc2017-07-20 01:04:281360}
1361
[email protected]55f593352011-12-24 05:42:461362} // namespace ash