blob: b23e515c04923c43e606ae7c0dfe78da6a51da98 [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"
[email protected]682990f2013-01-10 06:49:1128#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2729#include "ash/display/mouse_cursor_event_filter.h"
jamescook01bf23e72017-01-09 19:58:1530#include "ash/display/projecting_observer_chromeos.h"
31#include "ash/display/resolution_notification_controller.h"
rjkroege2c9305402016-09-07 00:21:4532#include "ash/display/screen_ash.h"
jamescook01bf23e72017-01-09 19:58:1533#include "ash/display/screen_orientation_controller_chromeos.h"
[email protected]8d625fb2012-07-18 16:40:0634#include "ash/display/screen_position_controller.h"
jamescook01bf23e72017-01-09 19:58:1535#include "ash/display/shutdown_observer_chromeos.h"
oshimae2818922015-07-28 01:18:5236#include "ash/display/window_tree_host_manager.h"
[email protected]f4c92b382012-08-28 00:59:5937#include "ash/drag_drop/drag_drop_controller.h"
[email protected]59ccade2013-10-17 17:56:4038#include "ash/first_run/first_run_helper_impl.h"
James Cookb0bf8e82017-04-09 17:01:4439#include "ash/focus_cycler.h"
40#include "ash/frame/custom_frame_view_ash.h"
[email protected]f4c92b382012-08-28 00:59:5941#include "ash/high_contrast/high_contrast_controller.h"
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:3242#include "ash/highlighter/highlighter_controller.h"
Scott Violet596bb46342017-06-21 14:43:1343#include "ash/host/ash_window_tree_host_init_params.h"
James Cookbb026732017-06-09 23:01:5544#include "ash/ime/ime_controller.h"
James Cookb0bf8e82017-04-09 17:01:4445#include "ash/keyboard/keyboard_ui.h"
sammiequon203ae022016-09-18 17:23:4246#include "ash/laser/laser_pointer_controller.h"
Jacob Dufaultffd9b0d2017-11-15 23:07:1647#include "ash/login/login_screen_controller.h"
James Cookb0bf8e82017-04-09 17:01:4448#include "ash/login_status.h"
[email protected]f4c92b382012-08-28 00:59:5949#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5450#include "ash/magnifier/partial_magnification_controller.h"
James Cookb0bf8e82017-04-09 17:01:4451#include "ash/media_controller.h"
Evan Stadee9974e22017-09-23 00:02:2652#include "ash/message_center/message_center_controller.h"
James Cookb0bf8e82017-04-09 17:01:4453#include "ash/new_window_controller.h"
Vladislav Kaznacheev92edf62e2017-10-13 22:08:0154#include "ash/note_taking_controller.h"
Evan Stade7d0e8232017-10-04 02:01:3655#include "ash/public/cpp/ash_switches.h"
sky494c6cbd2017-03-27 20:57:4856#include "ash/public/cpp/config.h"
msw109806d2017-06-02 20:11:5757#include "ash/public/cpp/shelf_model.h"
jamescook8800b8232016-10-19 12:46:2758#include "ash/public/cpp/shell_window_ids.h"
[email protected]d90b8392012-06-13 09:34:5659#include "ash/root_window_controller.h"
James Cook5e9d3402017-11-01 00:20:1260#include "ash/screenshot_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4461#include "ash/session/session_controller.h"
James Cook840177e2017-05-25 02:20:0162#include "ash/shelf/shelf.h"
James Cookb0bf8e82017-04-09 17:01:4463#include "ash/shelf/shelf_controller.h"
James Cookb0bf8e82017-04-09 17:01:4464#include "ash/shelf/shelf_window_watcher.h"
James Cookb0bf8e82017-04-09 17:01:4465#include "ash/shell_delegate.h"
[email protected]1b4c7472014-05-15 18:32:2366#include "ash/shell_init_params.h"
James Cookb0bf8e82017-04-09 17:01:4467#include "ash/shell_observer.h"
sky11cf8db92017-04-10 23:38:0868#include "ash/shell_port.h"
Scott Violet22a7b9212017-07-20 19:05:1969#include "ash/shell_port_classic.h"
James Cookb0bf8e82017-04-09 17:01:4470#include "ash/shutdown_controller.h"
jamescook01bf23e72017-01-09 19:58:1571#include "ash/sticky_keys/sticky_keys_controller.h"
James Cooka35a1e22017-04-08 02:33:0872#include "ash/system/bluetooth/bluetooth_notification_controller.h"
Sonny Sasaka55f69fc2017-08-28 21:29:3773#include "ash/system/bluetooth/bluetooth_power_controller.h"
James Cooka35a1e22017-04-08 02:33:0874#include "ash/system/bluetooth/tray_bluetooth_helper.h"
75#include "ash/system/brightness/brightness_controller_chromeos.h"
James Cookb0bf8e82017-04-09 17:01:4476#include "ash/system/brightness_control_delegate.h"
Lann Martinb9991402017-06-23 22:25:0877#include "ash/system/keyboard_brightness/keyboard_brightness_controller.h"
James Cookb0bf8e82017-04-09 17:01:4478#include "ash/system/keyboard_brightness_control_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4479#include "ash/system/locale/locale_notification_controller.h"
James Cooka35a1e22017-04-08 02:33:0880#include "ash/system/network/sms_observer.h"
81#include "ash/system/network/vpn_list.h"
afakhrye4fae852017-05-09 18:49:0682#include "ash/system/night_light/night_light_controller.h"
Sammie Quon4d7dba62017-08-03 23:18:1783#include "ash/system/palette/palette_tray.h"
Sammie Quon6c4e2b1f2017-10-13 16:54:1884#include "ash/system/palette/palette_welcome_bubble.h"
Sammie Quon95c6a1c2017-09-12 19:16:5585#include "ash/system/power/peripheral_battery_notifier.h"
Qiang Xu0a86020f2017-10-12 08:34:5486#include "ash/system/power/power_button_controller.h"
James Cooka35a1e22017-04-08 02:33:0887#include "ash/system/power/power_event_observer.h"
88#include "ash/system/power/power_status.h"
89#include "ash/system/power/video_activity_notifier.h"
90#include "ash/system/screen_layout_observer.h"
James Cookdc041122017-08-01 14:03:2291#include "ash/system/session/logout_button_tray.h"
James Cooka35a1e22017-04-08 02:33:0892#include "ash/system/session/logout_confirmation_controller.h"
James Cookb0bf8e82017-04-09 17:01:4493#include "ash/system/status_area_widget.h"
94#include "ash/system/toast/toast_manager.h"
95#include "ash/system/tray/system_tray_controller.h"
James Cookb0bf8e82017-04-09 17:01:4496#include "ash/system/tray/system_tray_notifier.h"
James Cook98072352017-08-07 18:00:0797#include "ash/system/tray_caps_lock.h"
kylechar55f0eaf22017-01-11 22:57:3798#include "ash/touch/ash_touch_transform_controller.h"
Qiang Xuf1400a362017-09-14 02:28:3099#include "ash/touch/touch_devices_controller.h"
tbarzicc78da1ff92017-05-08 20:46:15100#include "ash/tray_action/tray_action.h"
oshima5a296e82016-04-29 01:32:27101#include "ash/utility/screenshot_controller.h"
jamescook01bf23e72017-01-09 19:58:15102#include "ash/virtual_keyboard_controller.h"
Yue Lia33960a2017-11-01 22:06:07103#include "ash/voice_interaction/voice_interaction_controller.h"
James Cookb0bf8e82017-04-09 17:01:44104#include "ash/wallpaper/wallpaper_controller.h"
105#include "ash/wallpaper/wallpaper_delegate.h"
[email protected]39718b52012-12-03 17:24:56106#include "ash/wm/ash_focus_rules.h"
James Cookb0bf8e82017-04-09 17:01:44107#include "ash/wm/container_finder.h"
[email protected]262f8bd2012-03-23 19:30:27108#include "ash/wm/event_client_impl.h"
James Cookb0bf8e82017-04-09 17:01:44109#include "ash/wm/immersive_context_ash.h"
skyb7b54092016-08-19 16:00:09110#include "ash/wm/immersive_handler_factory_ash.h"
[email protected]ab4f8c92013-05-30 19:07:47111#include "ash/wm/lock_state_controller.h"
James Cookb0bf8e82017-04-09 17:01:44112#include "ash/wm/mru_window_tracker.h"
erg36cfb952017-06-21 19:41:45113#include "ash/wm/native_cursor_manager_ash_classic.h"
114#include "ash/wm/native_cursor_manager_ash_mus.h"
[email protected]9ae32df2012-07-26 03:25:18115#include "ash/wm/overlay_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44116#include "ash/wm/overview/window_selector_controller.h"
[email protected]e4a181cc2012-03-17 02:20:57117#include "ash/wm/resize_shadow_controller.h"
James Cookb0bf8e82017-04-09 17:01:44118#include "ash/wm/root_window_finder.h"
hidehiko6821ca42016-06-18 11:12:23119#include "ash/wm/screen_pinning_controller.h"
xdaid4913762017-07-06 00:17:22120#include "ash/wm/splitview/split_view_controller.h"
[email protected]435b212e2012-04-05 19:43:37121#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:27122#include "ash/wm/system_modal_container_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44123#include "ash/wm/system_modal_container_layout_manager.h"
Mitsuru Oshima0e9b7a62017-07-19 18:23:03124#include "ash/wm/tablet_mode/tablet_mode_controller.h"
125#include "ash/wm/tablet_mode/tablet_mode_window_manager.h"
[email protected]3537d472014-01-15 05:45:31126#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:58127#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:02128#include "ash/wm/window_animations.h"
James Cookb0bf8e82017-04-09 17:01:44129#include "ash/wm/window_cycle_controller.h"
130#include "ash/wm/window_positioner.h"
[email protected]f059c6942012-07-21 14:27:57131#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:59132#include "ash/wm/window_util.h"
James Cookb0bf8e82017-04-09 17:01:44133#include "ash/wm/workspace_controller.h"
[email protected]f296be72011-10-11 15:40:00134#include "base/bind.h"
jamescook01bf23e72017-01-09 19:58:15135#include "base/bind_helpers.h"
jamescookfda159002016-10-21 18:48:57136#include "base/command_line.h"
dchenga94547472016-04-08 08:41:11137#include "base/memory/ptr_util.h"
jamescook01bf23e72017-01-09 19:58:15138#include "base/sys_info.h"
tzik0dd58d42017-02-15 08:26:52139#include "base/threading/sequenced_worker_pool.h"
primiano7182d7b2015-01-30 18:02:03140#include "base/trace_event/trace_event.h"
jamescook01bf23e72017-01-09 19:58:15141#include "chromeos/chromeos_switches.h"
142#include "chromeos/dbus/dbus_thread_manager.h"
reveman24158982017-01-10 05:58:45143#include "chromeos/system/devicemode.h"
tibellb93c729b2017-03-30 00:45:09144#include "components/prefs/pref_registry_simple.h"
145#include "components/prefs/pref_service.h"
Saman Sami3fb310d2017-11-09 16:51:54146#include "components/viz/host/host_frame_sink_manager.h"
tibellb93c729b2017-03-30 00:45:09147#include "services/preferences/public/cpp/pref_service_factory.h"
skyb073203a2017-03-13 16:59:16148#include "services/preferences/public/interfaces/preferences.mojom.h"
derat94887a22017-01-20 18:17:25149#include "services/service_manager/public/cpp/connector.h"
150#include "services/ui/public/interfaces/constants.mojom.h"
sky7db5ccf2017-03-14 21:52:29151#include "ui/app_list/presenter/app_list.h"
[email protected]2c456102011-12-26 06:26:34152#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:44153#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:58154#include "ui/aura/layout_manager.h"
sky68612712017-04-27 04:45:04155#include "ui/aura/mus/focus_synchronizer.h"
derat94887a22017-01-20 18:17:25156#include "ui/aura/mus/user_activity_forwarder.h"
sky68612712017-04-27 04:45:04157#include "ui/aura/mus/window_tree_client.h"
[email protected]87b0d82e2011-10-07 21:02:59158#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:26159#include "ui/aura/window_event_dispatcher.h"
[email protected]2d4817742012-12-17 20:16:18160#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:17161#include "ui/base/user_activity/user_activity_detector.h"
jamescook01bf23e72017-01-09 19:58:15162#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]116302fc2012-05-05 21:45:41163#include "ui/compositor/layer.h"
164#include "ui/compositor/layer_animator.h"
oshimaf84b0da722016-04-27 19:47:19165#include "ui/display/display.h"
sky2f68b6f2017-05-21 16:08:39166#include "ui/display/manager/chromeos/default_touch_transform_setter.h"
jamescook01bf23e72017-01-09 19:58:15167#include "ui/display/manager/chromeos/display_change_observer.h"
168#include "ui/display/manager/chromeos/display_configurator.h"
sky7265b1cc2017-05-22 23:11:03169#include "ui/display/manager/chromeos/touch_transform_setter.h"
rjkroege72f8154f2016-10-29 00:49:02170#include "ui/display/manager/display_manager.h"
kylechar7e4f46f2017-10-31 23:26:57171#include "ui/display/mojo/dev_display_controller.mojom.h"
oshimaf84b0da722016-04-27 19:47:19172#include "ui/display/screen.h"
skycfaad892017-04-28 20:52:58173#include "ui/display/types/native_display_delegate.h"
[email protected]3e670aa2013-12-02 19:04:32174#include "ui/events/event_target_iterator.h"
sky4ec2be82017-01-06 17:38:32175#include "ui/gfx/geometry/insets.h"
[email protected]9ec0f452012-05-31 15:58:53176#include "ui/gfx/image/image_skia.h"
[email protected]b6ba05d902013-10-04 21:38:45177#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28178#include "ui/keyboard/keyboard_switches.h"
yhanada8909a542017-07-11 10:06:19179#include "ui/keyboard/keyboard_ui.h"
[email protected]f1d5c3a2013-04-23 17:42:56180#include "ui/keyboard/keyboard_util.h"
[email protected]d7f30a72013-10-05 05:09:41181#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04182#include "ui/views/corewm/tooltip_controller.h"
sky07a24d42017-03-09 23:57:30183#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:58184#include "ui/views/widget/native_widget_aura.h"
185#include "ui/views/widget/widget.h"
[email protected]60d677d2014-05-30 13:07:02186#include "ui/wm/core/accelerator_filter.h"
[email protected]ee3ed10772014-03-11 22:02:01187#include "ui/wm/core/compound_event_filter.h"
188#include "ui/wm/core/focus_controller.h"
[email protected]ee3ed10772014-03-11 22:02:01189#include "ui/wm/core/shadow_controller.h"
190#include "ui/wm/core/visibility_controller.h"
191#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59192
[email protected]55f593352011-12-24 05:42:46193namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59194
195namespace {
[email protected]671a2ae2011-10-13 21:53:23196
[email protected]615922f2012-02-07 02:41:15197using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45198using views::Widget;
199
jamescook518dccbd2017-05-18 04:57:07200bool g_is_browser_process_with_mash = false;
201
[email protected]b5756e22012-11-30 01:32:02202// A Corewm VisibilityController subclass that calls the Ash animation routine
203// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14204class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02205 public:
Chris Watkinsc24daf62017-11-28 03:43:09206 AshVisibilityController() = default;
207 ~AshVisibilityController() override = default;
[email protected]b5756e22012-11-30 01:32:02208
209 private:
[email protected]e319c7e2014-03-14 19:56:14210 // Overridden from ::wm::VisibilityController:
dcheng1f4538e2014-10-27 23:57:05211 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
212 bool visible) override {
[email protected]b5756e22012-11-30 01:32:02213 return AnimateOnChildWindowVisibilityChanged(window, visible);
214 }
215
216 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
217};
218
[email protected]87b0d82e2011-10-07 21:02:59219} // namespace
220
[email protected]cac10fc62011-10-07 23:22:56221// static
achuith287b26e2015-09-03 17:49:18222Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13223// static
sky00f98a372017-01-11 06:03:49224aura::WindowTreeClient* Shell::window_tree_client_ = nullptr;
225// static
skya8b222f2017-01-12 15:47:13226aura::WindowManagerClient* Shell::window_manager_client_ = nullptr;
227// static
[email protected]9488d4d2012-02-29 18:32:37228bool Shell::initially_hide_cursor_ = false;
[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
jamescook0dfe5632017-04-05 18:49:02326Config Shell::GetAshConfig() {
sky11cf8db92017-04-10 23:38:08327 return Get()->shell_port_->GetAshConfig();
sky494c6cbd2017-03-27 20:57:48328}
329
moshayedic229a522017-05-05 18:14:26330// static
331bool Shell::ShouldUseIMEService() {
332 return Shell::GetAshConfig() == Config::MASH ||
333 (Shell::GetAshConfig() == Config::MUS &&
334 base::CommandLine::ForCurrentProcess()->HasSwitch(
335 switches::kUseIMEService));
336}
337
afakhrye4fae852017-05-09 18:49:06338// static
Wenzhao Zang56c292932017-08-02 04:58:34339void Shell::RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
Sammie Quon4d7dba62017-08-03 23:18:17340 PaletteTray::RegisterLocalStatePrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34341 WallpaperController::RegisterLocalStatePrefs(registry);
Sonny Sasaka55f69fc2017-08-28 21:29:37342 BluetoothPowerController::RegisterLocalStatePrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34343}
344
345// static
James Cookec144952017-09-01 00:05:16346void Shell::RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) {
347 AccessibilityController::RegisterProfilePrefs(registry, for_test);
Sonny Sasaka55f69fc2017-08-28 21:29:37348 BluetoothPowerController::RegisterProfilePrefs(registry);
Jacob Dufaultffd9b0d2017-11-15 23:07:16349 LoginScreenController::RegisterProfilePrefs(registry, for_test);
Sammie Quon6c4e2b1f2017-10-13 16:54:18350 LogoutButtonTray::RegisterProfilePrefs(registry);
351 NightLightController::RegisterProfilePrefs(registry);
Vladislav Kaznacheevfefa6bd2017-10-14 00:25:24352 PaletteTray::RegisterProfilePrefs(registry);
Sammie Quon6c4e2b1f2017-10-13 16:54:18353 PaletteWelcomeBubble::RegisterProfilePrefs(registry);
354 ShelfController::RegisterProfilePrefs(registry);
Qiang Xuf1400a362017-09-14 02:28:30355 TouchDevicesController::RegisterProfilePrefs(registry);
Sammie Quon6c4e2b1f2017-10-13 16:54:18356 TrayCapsLock::RegisterProfilePrefs(registry, for_test);
afakhrye4fae852017-05-09 18:49:06357}
358
[email protected]57b8bb352012-01-11 05:11:46359views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
360 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04361 // Use translucent-style window frames for dialogs.
[email protected]85501fe2013-10-18 10:15:27362 return new CustomFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46363}
364
[email protected]2e236a52012-06-27 22:21:47365void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44366 const gfx::Insets& insets) {
Scott Violet596bb46342017-06-21 14:43:13367 window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow(contains,
368 insets);
[email protected]1a2145b2012-03-13 21:09:17369}
370
[email protected]58868abf2014-01-17 23:45:33371void Shell::OnCastingSessionStartedOrStopped(bool started) {
sky00c813f2017-03-08 22:48:55372 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18373 observer.OnCastingSessionStartedOrStopped(started);
[email protected]58868abf2014-01-17 23:45:33374}
375
varkhac71444e52017-05-25 22:51:34376void Shell::OnRootWindowAdded(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55377 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18378 observer.OnRootWindowAdded(root_window);
[email protected]0e3e7cb2014-04-12 05:18:25379}
380
[email protected]51f438112013-11-18 19:32:50381void Shell::CreateKeyboard() {
Keigo Okae82281a2017-06-14 13:59:14382 if (keyboard::IsKeyboardEnabled()) {
383 if (keyboard::KeyboardController::GetInstance()) {
384 RootWindowControllerList controllers = GetAllRootWindowControllers();
385 for (RootWindowControllerList::iterator iter = controllers.begin();
386 iter != controllers.end(); ++iter) {
387 (*iter)->DeactivateKeyboard(
388 keyboard::KeyboardController::GetInstance());
389 }
390 }
391 keyboard::KeyboardController::ResetInstance(
392 new keyboard::KeyboardController(shell_delegate_->CreateKeyboardUI(),
393 virtual_keyboard_controller_.get()));
394 for (auto& observer : shell_observers_)
395 observer.OnKeyboardControllerCreated();
396 }
397
jamescookb8dcef522016-06-25 14:42:55398 GetPrimaryRootWindowController()->ActivateKeyboard(
399 keyboard::KeyboardController::GetInstance());
[email protected]51f438112013-11-18 19:32:50400}
401
Keigo Okac7617a42017-06-14 11:33:24402void Shell::DestroyKeyboard() {
sky11cf8db92017-04-10 23:38:08403 // TODO(jamescook): Move keyboard create and hide into ShellPort.
sky79fa34712017-03-20 23:46:47404 keyboard_ui_->Hide();
[email protected]a0b3fb882014-04-07 19:26:03405 if (keyboard::KeyboardController::GetInstance()) {
[email protected]e1b299b2014-01-29 23:53:41406 RootWindowControllerList controllers = GetAllRootWindowControllers();
407 for (RootWindowControllerList::iterator iter = controllers.begin();
jamescookb8dcef522016-06-25 14:42:55408 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:03409 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]e1b299b2014-01-29 23:53:41410 }
411 }
achuith287b26e2015-09-03 17:49:18412 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]e1b299b2014-01-29 23:53:41413}
414
[email protected]da285852014-05-27 19:53:43415bool Shell::ShouldSaveDisplaySettings() {
sky2c5eae82017-06-06 01:46:58416 // This function is only called from Chrome, hence the DCHECK for not-MASH.
skye5fd1222017-04-12 18:43:23417 DCHECK(GetAshConfig() != Config::MASH);
jamescookb8dcef522016-06-25 14:42:55418 return !(
419 screen_orientation_controller_->ignore_display_configuration_updates() ||
420 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43421}
[email protected]da285852014-05-27 19:53:43422
afakhry9e0a18b32017-06-05 19:23:14423NightLightController* Shell::night_light_controller() {
Evan Stade48768f42017-10-10 05:23:30424 DCHECK(switches::IsNightLightEnabled());
afakhry9e0a18b32017-06-05 19:23:14425 return night_light_controller_.get();
426}
427
sky5ad143a2017-03-22 04:31:23428ShelfModel* Shell::shelf_model() {
429 return shelf_controller_->model();
430}
431
Thiago Farina3b086a02017-05-30 22:32:50432::wm::ActivationClient* Shell::activation_client() {
sky27344382017-03-08 21:30:32433 return focus_controller_.get();
434}
435
[email protected]c758fbf2012-03-25 22:53:59436void Shell::UpdateShelfVisibility() {
msw257a6a232017-06-01 01:46:30437 for (aura::Window* root : GetAllRootWindows())
438 Shelf::ForWindow(root)->UpdateVisibilityState();
[email protected]c758fbf2012-03-25 22:53:59439}
440
Wenzhao Zang44240fb2017-07-13 01:36:54441PrefService* Shell::GetLocalStatePrefService() const {
Sam McNallya853cd82017-08-30 01:55:10442 return local_state_.get();
Wenzhao Zang44240fb2017-07-13 01:36:54443}
444
[email protected]88d71122012-10-18 07:11:01445WebNotificationTray* Shell::GetWebNotificationTray() {
jamescook612205f2016-05-26 06:02:11446 return GetPrimaryRootWindowController()
jamescookb551aba2016-09-01 01:00:16447 ->GetStatusAreaWidget()
jamescook612205f2016-05-26 06:02:11448 ->web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28449}
450
[email protected]a0afeb12012-12-10 22:57:09451bool Shell::HasPrimaryStatusArea() {
jamescookb551aba2016-09-01 01:00:16452 return !!GetPrimaryRootWindowController()->GetStatusAreaWidget();
[email protected]31f19e32012-10-30 22:31:23453}
454
[email protected]a0afeb12012-12-10 22:57:09455SystemTray* Shell::GetPrimarySystemTray() {
456 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42457}
458
mswa7e8a5f2016-03-01 04:15:06459FirstRunHelper* Shell::CreateFirstRunHelper() {
460 return new FirstRunHelperImpl;
[email protected]59ccade2013-10-17 17:56:40461}
[email protected]87ec2202014-02-06 06:24:27462
yawanodc5533b32017-02-23 11:04:38463void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
464 window_tree_host_manager_->cursor_window_controller()
465 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
466}
467
Weidong Guod07448f2017-10-18 03:35:18468void Shell::UpdateCursorCompositingEnabled() {
469 SetCursorCompositingEnabled(
470 window_tree_host_manager_->cursor_window_controller()
471 ->ShouldEnableCursorCompositing());
472}
473
[email protected]87ec2202014-02-06 06:24:27474void Shell::SetCursorCompositingEnabled(bool enabled) {
erg36cfb952017-06-21 19:41:45475 if (GetAshConfig() != Config::MASH) {
476 // TODO: needs to work in mash. http://crbug.com/705592.
Weidong Guo7dfd1482017-11-08 05:56:28477 CursorWindowController* cursor_window_controller =
478 window_tree_host_manager_->cursor_window_controller();
479
480 if (cursor_window_controller->is_cursor_compositing_enabled() == enabled)
481 return;
482 cursor_window_controller->SetCursorCompositingEnabled(enabled);
sky494c6cbd2017-03-27 20:57:48483 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
484 }
[email protected]87ec2202014-02-06 06:24:27485}
[email protected]59ccade2013-10-17 17:56:40486
[email protected]f9466702012-09-17 16:35:27487void Shell::DoInitialWorkspaceAnimation() {
jamescookb8dcef522016-06-25 14:42:55488 return GetPrimaryRootWindowController()
489 ->workspace_controller()
490 ->DoInitialAnimation();
[email protected]f9466702012-09-17 16:35:27491}
492
xdaid4913762017-07-06 00:17:22493bool Shell::IsSplitViewModeActive() const {
494 return split_view_controller_->IsSplitViewModeActive();
495}
496
sky00c813f2017-03-08 22:48:55497void Shell::AddShellObserver(ShellObserver* observer) {
498 shell_observers_.AddObserver(observer);
499}
500
501void Shell::RemoveShellObserver(ShellObserver* observer) {
502 shell_observers_.RemoveObserver(observer);
503}
504
sky5ad143a2017-03-22 04:31:23505void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
varkha59679632017-06-01 00:42:05506 for (auto* root_window_controller : GetAllRootWindowControllers())
507 root_window_controller->UpdateAfterLoginStatusChange(status);
sky5ad143a2017-03-22 04:31:23508}
509
sky00c813f2017-03-08 22:48:55510void Shell::NotifyOverviewModeStarting() {
511 for (auto& observer : shell_observers_)
512 observer.OnOverviewModeStarting();
513}
514
515void Shell::NotifyOverviewModeEnded() {
516 for (auto& observer : shell_observers_)
517 observer.OnOverviewModeEnded();
518}
519
xdaid4913762017-07-06 00:17:22520void Shell::NotifySplitViewModeStarting() {
521 for (auto& observer : shell_observers_)
522 observer.OnSplitViewModeStarting();
523}
524
525void Shell::NotifySplitViewModeEnded() {
526 for (auto& observer : shell_observers_)
527 observer.OnSplitViewModeEnded();
528}
529
sky00c813f2017-03-08 22:48:55530void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
varkhac71444e52017-05-25 22:51:34531 aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55532 for (auto& observer : shell_observers_)
533 observer.OnFullscreenStateChanged(is_fullscreen, root_window);
534}
535
varkha19d7e6c52017-05-25 21:15:30536void Shell::NotifyPinnedStateChanged(aura::Window* pinned_window) {
sky00c813f2017-03-08 22:48:55537 for (auto& observer : shell_observers_)
538 observer.OnPinnedStateChanged(pinned_window);
539}
540
xiyuan38160182017-03-14 22:50:13541void Shell::NotifyVirtualKeyboardActivated(bool activated,
sky97f9a7432017-05-09 05:14:31542 aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55543 for (auto& observer : shell_observers_)
xiyuan38160182017-03-14 22:50:13544 observer.OnVirtualKeyboardStateChanged(activated, root_window);
sky00c813f2017-03-08 22:48:55545}
546
varkha6b016b0f2017-05-26 16:14:18547void Shell::NotifyShelfCreatedForRootWindow(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55548 for (auto& observer : shell_observers_)
549 observer.OnShelfCreatedForRootWindow(root_window);
550}
551
varkha6b016b0f2017-05-26 16:14:18552void Shell::NotifyShelfAlignmentChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55553 for (auto& observer : shell_observers_)
554 observer.OnShelfAlignmentChanged(root_window);
555}
556
varkha6b016b0f2017-05-26 16:14:18557void Shell::NotifyShelfAutoHideBehaviorChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55558 for (auto& observer : shell_observers_)
559 observer.OnShelfAutoHideBehaviorChanged(root_window);
560}
561
jamescook518dccbd2017-05-18 04:57:07562// static
563void Shell::SetIsBrowserProcessWithMash() {
564 g_is_browser_process_with_mash = true;
565}
566
muyuanlid766f2e2017-06-26 20:17:19567void Shell::NotifyAppListVisibilityChanged(bool visible,
568 aura::Window* root_window) {
newcomer2febb9832017-06-12 17:00:23569 for (auto& observer : shell_observers_)
570 observer.OnAppListVisibilityChanged(visible, root_window);
571}
572
[email protected]b6ba05d902013-10-04 21:38:45573////////////////////////////////////////////////////////////////////////////////
574// Shell, private:
575
skyb073203a2017-03-13 16:59:16576Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
sky11cf8db92017-04-10 23:38:08577 std::unique_ptr<ShellPort> shell_port)
578 : shell_port_(std::move(shell_port)),
Mitsuru Oshima04b54d02017-10-09 14:22:45579 ash_display_controller_(std::make_unique<AshDisplayController>()),
sky79fa34712017-03-20 23:46:47580 brightness_control_delegate_(
Mitsuru Oshima04b54d02017-10-09 14:22:45581 std::make_unique<system::BrightnessControllerChromeos>()),
582 cast_config_(std::make_unique<CastConfigController>()),
583 focus_cycler_(std::make_unique<FocusCycler>()),
584 ime_controller_(std::make_unique<ImeController>()),
585 immersive_context_(std::make_unique<ImmersiveContextAsh>()),
sky79fa34712017-03-20 23:46:47586 keyboard_brightness_control_delegate_(
Mitsuru Oshima04b54d02017-10-09 14:22:45587 std::make_unique<KeyboardBrightnessController>()),
sky79fa34712017-03-20 23:46:47588 locale_notification_controller_(
Mitsuru Oshima04b54d02017-10-09 14:22:45589 std::make_unique<LocaleNotificationController>()),
Jacob Dufaultffd9b0d2017-11-15 23:07:16590 login_screen_controller_(std::make_unique<LoginScreenController>()),
Mitsuru Oshima04b54d02017-10-09 14:22:45591 media_controller_(std::make_unique<MediaController>()),
592 new_window_controller_(std::make_unique<NewWindowController>()),
593 session_controller_(std::make_unique<SessionController>(
Sam McNallyf4dab612017-08-16 03:06:33594 shell_delegate->GetShellConnector())),
Vladislav Kaznacheev92edf62e2017-10-13 22:08:01595 note_taking_controller_(std::make_unique<NoteTakingController>()),
skyb073203a2017-03-13 16:59:16596 shell_delegate_(std::move(shell_delegate)),
Mitsuru Oshima04b54d02017-10-09 14:22:45597 shutdown_controller_(std::make_unique<ShutdownController>()),
598 system_tray_controller_(std::make_unique<SystemTrayController>()),
599 system_tray_notifier_(std::make_unique<SystemTrayNotifier>()),
600 tray_action_(std::make_unique<TrayAction>()),
601 vpn_list_(std::make_unique<VpnList>()),
602 window_cycle_controller_(std::make_unique<WindowCycleController>()),
603 window_selector_controller_(std::make_unique<WindowSelectorController>()),
604 app_list_(std::make_unique<app_list::AppList>()),
605 tray_bluetooth_helper_(std::make_unique<TrayBluetoothHelper>()),
kylechar7a067ec2017-01-07 01:16:28606 display_configurator_(new display::DisplayConfigurator()),
sadrul7a8785e2016-02-12 21:54:35607 native_cursor_manager_(nullptr),
[email protected]b6ba05d902013-10-04 21:38:45608 simulate_modal_window_open_for_testing_(false),
Sam McNallye36abbc2017-07-20 01:04:28609 weak_factory_(this) {
skyabcae812017-01-18 17:01:34610 // TODO(sky): better refactor cash/mash dependencies. Perhaps put all cash
sky11cf8db92017-04-10 23:38:08611 // state on ShellPortClassic. http://crbug.com/671246.
skyabcae812017-01-18 17:01:34612
Scott Violet596bb46342017-06-21 14:43:13613 display_manager_.reset(ScreenAsh::CreateDisplayManager());
Mitsuru Oshima04b54d02017-10-09 14:22:45614 window_tree_host_manager_ = std::make_unique<WindowTreeHostManager>();
615 user_metrics_recorder_ = std::make_unique<UserMetricsRecorder>();
[email protected]b6ba05d902013-10-04 21:38:45616
[email protected]093b8d642014-04-03 20:59:28617 PowerStatus::Initialize();
sky5ad143a2017-03-22 04:31:23618
Xiyuan Xia22b1a6c2017-04-18 22:46:01619 session_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45620}
621
622Shell::~Shell() {
623 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
624
sky11cf8db92017-04-10 23:38:08625 const Config config = shell_port_->GetAshConfig();
skyabcae812017-01-18 17:01:34626
Scott Violet41562d1c2017-06-26 15:15:48627 user_metrics_recorder_->OnShellShuttingDown();
bruthigc24d11f2015-06-09 21:30:03628
skyb073203a2017-03-13 16:59:16629 shell_delegate_->PreShutdown();
[email protected]050e77182014-03-25 15:29:16630
[email protected]b6ba05d902013-10-04 21:38:45631 // Remove the focus from any window. This will prevent overhead and side
632 // effects (e.g. crashes) from changing focus during shutdown.
633 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18634 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45635
xdaid4913762017-07-06 00:17:22636 // Please keep in reverse order as in Init() because it's easy to miss one.
[email protected]b6ba05d902013-10-04 21:38:45637 if (window_modality_controller_)
638 window_modality_controller_.reset();
jamescook01bf23e72017-01-09 19:58:15639
[email protected]e4ea52362014-02-15 03:21:06640 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
641 magnifier_key_scroll_handler_.reset();
642
643 RemovePreTargetHandler(speech_feedback_handler_.get());
644 speech_feedback_handler_.reset();
jamescook01bf23e72017-01-09 19:58:15645
[email protected]b6ba05d902013-10-04 21:38:45646 RemovePreTargetHandler(overlay_filter_.get());
Xiyuan Xia22b1a6c2017-04-18 22:46:01647 overlay_filter_.reset();
648
[email protected]3537d472014-01-15 05:45:31649 RemovePreTargetHandler(accelerator_filter_.get());
650 RemovePreTargetHandler(event_transformation_handler_.get());
651 RemovePreTargetHandler(toplevel_window_event_handler_.get());
652 RemovePostTargetHandler(toplevel_window_event_handler_.get());
Scott Violet596bb46342017-06-21 14:43:13653 RemovePreTargetHandler(system_gesture_filter_.get());
654 RemovePreTargetHandler(mouse_cursor_filter_.get());
hariank0dd03dd2016-07-14 23:47:33655 RemovePreTargetHandler(modality_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45656
657 // TooltipController is deleted with the Shell so removing its references.
658 RemovePreTargetHandler(tooltip_controller_.get());
659
jonross0af45212015-01-13 18:55:46660 screen_orientation_controller_.reset();
yiyixa68ade512016-09-01 17:38:13661 screen_layout_observer_.reset();
jonross0af45212015-01-13 18:55:46662
Mitsuru Oshima0e9b7a62017-07-19 18:23:03663 // Destroy the virtual keyboard controller before the tablet mode controller
jamescook01bf23e72017-01-09 19:58:15664 // since the latters destructor triggers events that the former is listening
665 // to but no longer cares about.
rsadambbaf2c82015-01-07 17:54:13666 virtual_keyboard_controller_.reset();
jonross0af45212015-01-13 18:55:46667
Mitsuru Oshima0e9b7a62017-07-19 18:23:03668 // Destroy tablet mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57669 // need to be removed.
Mitsuru Oshima0e9b7a62017-07-19 18:23:03670 tablet_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57671
jdufault551152e2016-01-27 19:48:43672 // Destroy the keyboard before closing the shelf, since it will invoke a shelf
673 // layout.
Keigo Okac7617a42017-06-14 11:33:24674 DestroyKeyboard();
jdufault551152e2016-01-27 19:48:43675
sky07a24d42017-03-09 23:57:30676 toast_manager_.reset();
yoshiki32f51632016-03-24 01:24:43677
msw257a6a232017-06-01 01:46:30678 for (aura::Window* root : GetAllRootWindows())
679 Shelf::ForWindow(root)->ShutdownShelfWidget();
jamescookac6724332017-03-21 02:54:43680 tray_bluetooth_helper_.reset();
James Cookb50959e22017-08-10 20:24:38681
682 // Accesses root window containers.
683 logout_confirmation_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45684
[email protected]b6ba05d902013-10-04 21:38:45685 // Drag-and-drop must be canceled prior to close all windows.
686 drag_drop_controller_.reset();
687
Xiyuan Xia22b1a6c2017-04-18 22:46:01688 // Controllers who have WindowObserver added must be deleted
689 // before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03690
[email protected]8c9d12a2013-12-06 18:39:03691 // VideoActivityNotifier must be deleted before |video_detector_| is
692 // deleted because it's observing video activity through
derat83b761392016-07-11 16:44:44693 // VideoDetector::Observer interface.
[email protected]8c9d12a2013-12-06 18:39:03694 video_activity_notifier_.reset();
[email protected]8c9d12a2013-12-06 18:39:03695 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25696 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03697
698 shadow_controller_.reset();
699 resize_shadow_controller_.reset();
700
sky37f0dd12016-07-19 18:00:59701 // Has to happen before ~MruWindowTracker.
sky5b45ed82017-03-27 02:54:23702 window_cycle_controller_.reset();
703 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03704
xdai7a8867cd2017-08-25 23:10:16705 // |split_view_controller_| needs to be deleted after
706 // |window_selector_controller_|.
707 split_view_controller_.reset();
708
skyabcae812017-01-18 17:01:34709 CloseAllRootWindowChildWindows();
710
afakhry58159392015-05-22 02:45:52711 // MruWindowTracker must be destroyed after all windows have been deleted to
712 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
713 // path. (crbug.com/485438).
sky5ab16472017-03-21 19:35:08714 mru_window_tracker_.reset();
[email protected]b6ba05d902013-10-04 21:38:45715
[email protected]b6ba05d902013-10-04 21:38:45716 // These need a valid Shell instance to clean up properly, so explicitly
717 // delete them before invalidating the instance.
718 // Alphabetical. TODO(oshima): sort.
719 magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45720 tooltip_controller_.reset();
721 event_client_.reset();
[email protected]3537d472014-01-15 05:45:31722 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45723 visibility_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45724
725 power_button_controller_.reset();
726 lock_state_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45727
hidehiko6821ca42016-06-18 11:12:23728 screen_pinning_controller_.reset();
729
[email protected]b6ba05d902013-10-04 21:38:45730 resolution_notification_controller_.reset();
oshima5a296e82016-04-29 01:32:27731 screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49732 mouse_cursor_filter_.reset();
hariank0dd03dd2016-07-14 23:47:33733 modality_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45734
[email protected]03122891a2014-05-13 23:56:49735 touch_transformer_controller_.reset();
sammiequon203ae022016-09-18 17:23:42736 laser_pointer_controller_.reset();
737 partial_magnification_controller_.reset();
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:32738 highlighter_controller_.reset();
Yue Lia33960a2017-11-01 22:06:07739 voice_interaction_controller_.reset();
warx533c8f62016-04-12 01:19:43740
[email protected]b6ba05d902013-10-04 21:38:45741 // This also deletes all RootWindows. Note that we invoke Shutdown() on
oshimae2818922015-07-28 01:18:52742 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
msw257a6a232017-06-01 01:46:30743 // destruction of its owned RootWindowControllers relies on the value.
rjkroege2c9305402016-09-07 00:21:45744 ScreenAsh::CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12745 display_configuration_controller_.reset();
dtseng4ae0a882016-04-15 21:39:27746
sky15ef0aa2017-01-20 18:55:59747 // AppListDelegateImpl depends upon AppList.
748 app_list_delegate_impl_.reset();
749
sky07a24d42017-03-09 23:57:30750 // These members access Shell in their destructors.
751 wallpaper_controller_.reset();
James Cookec144952017-09-01 00:05:16752 accessibility_controller_.reset();
sky07a24d42017-03-09 23:57:30753 accessibility_delegate_.reset();
Evan Stade4d07c422017-09-01 21:51:51754 message_center_controller_.reset();
sky07a24d42017-03-09 23:57:30755
756 // Balances the Install() in Initialize().
757 views::FocusManagerFactory::Install(nullptr);
758
sky5ad143a2017-03-22 04:31:23759 // ShelfWindowWatcher has window observers and a pointer to the shelf model.
760 shelf_window_watcher_.reset();
761
tibellb93c729b2017-03-30 00:45:09762 // Removes itself as an observer of |pref_service_|.
sky5ad143a2017-03-22 04:31:23763 shelf_controller_.reset();
764
sky11cf8db92017-04-10 23:38:08765 shell_port_->Shutdown();
Scott Violet596bb46342017-06-21 14:43:13766 window_tree_host_manager_->Shutdown();
sky5ad143a2017-03-22 04:31:23767
sky27344382017-03-08 21:30:32768 // Depends on |focus_controller_|, so must be destroyed before.
oshimae2818922015-07-28 01:18:52769 window_tree_host_manager_.reset();
sky27344382017-03-08 21:30:32770 focus_controller_->RemoveObserver(this);
sky68612712017-04-27 04:45:04771 if (config != Config::CLASSIC &&
772 window_tree_client_->focus_synchronizer()->active_focus_client() ==
773 focus_controller_.get()) {
774 window_tree_client_->focus_synchronizer()->SetSingletonFocusClient(nullptr);
775 }
sky27344382017-03-08 21:30:32776 focus_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45777 screen_position_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45778
robert.bradfordab052492015-05-06 11:09:56779 display_color_manager_.reset();
[email protected]7bc49bd2014-01-22 09:30:34780 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11781 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45782 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11783 display_configurator_->RemoveObserver(display_error_observer_.get());
jdufault88fb76652015-04-30 22:36:43784 if (projecting_observer_) {
[email protected]1e31cbd2014-04-07 20:06:11785 display_configurator_->RemoveObserver(projecting_observer_.get());
sky00c813f2017-03-08 22:48:55786 RemoveShellObserver(projecting_observer_.get());
jdufault88fb76652015-04-30 22:36:43787 }
[email protected]b6ba05d902013-10-04 21:38:45788 display_change_observer_.reset();
kylechar98748a52016-12-03 01:33:22789 shutdown_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45790
[email protected]093b8d642014-04-03 20:59:28791 PowerStatus::Shutdown();
pneubeck8be1f5422014-10-09 16:46:18792
793 // Ensure that DBusThreadManager outlives this Shell.
794 DCHECK(chromeos::DBusThreadManager::IsInitialized());
[email protected]b6ba05d902013-10-04 21:38:45795
sky88bd4be62016-06-09 17:34:41796 // Needs to happen right before |instance_| is reset.
sky11cf8db92017-04-10 23:38:08797 shell_port_.reset();
Xiyuan Xia22b1a6c2017-04-18 22:46:01798 session_controller_->RemoveObserver(this);
skyb073203a2017-03-13 16:59:16799 wallpaper_delegate_.reset();
Sonny Sasaka55f69fc2017-08-28 21:29:37800 // BluetoothPowerController depends on the PrefService and must be destructed
801 // before it.
802 bluetooth_power_controller_ = nullptr;
Qiang Xuf1400a362017-09-14 02:28:30803 // TouchDevicesController depends on the PrefService and must be destructed
804 // before it.
805 touch_devices_controller_ = nullptr;
afakhry21501562017-05-19 22:52:40806 // NightLightController depeneds on the PrefService and must be destructed
807 // before it. crbug.com/724231.
808 night_light_controller_ = nullptr;
Sam McNallya853cd82017-08-30 01:55:10809 local_state_.reset();
skyb073203a2017-03-13 16:59:16810 shell_delegate_.reset();
sky88bd4be62016-06-09 17:34:41811
Scott Violet17a61722017-06-19 17:54:31812 for (auto& observer : shell_observers_)
813 observer.OnShellDestroyed();
814
[email protected]b6ba05d902013-10-04 21:38:45815 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18816 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45817}
818
Scott Violetc8a1c6c2017-11-29 23:17:36819void Shell::Init(ui::ContextFactory* context_factory,
820 ui::ContextFactoryPrivate* context_factory_private) {
sky11cf8db92017-04-10 23:38:08821 const Config config = shell_port_->GetAshConfig();
skyabcae812017-01-18 17:01:34822
James Cookbd0b7792017-11-17 03:24:26823 // These controllers call Shell::Get() in their constructors, so they cannot
824 // be in the member initialization list.
Evan Stade48768f42017-10-10 05:23:30825 if (switches::IsNightLightEnabled())
Mitsuru Oshima04b54d02017-10-09 14:22:45826 night_light_controller_ = std::make_unique<NightLightController>();
Qiang Xuf1400a362017-09-14 02:28:30827 touch_devices_controller_ = std::make_unique<TouchDevicesController>();
Mitsuru Oshima04b54d02017-10-09 14:22:45828 bluetooth_power_controller_ = std::make_unique<BluetoothPowerController>();
Sonny Sasaka55f69fc2017-08-28 21:29:37829
skyb073203a2017-03-13 16:59:16830 wallpaper_delegate_ = shell_delegate_->CreateWallpaperDelegate();
831
James Cook8532dbc2017-07-31 21:54:51832 // Connector can be null in tests.
Sam McNallya853cd82017-08-30 01:55:10833 if (shell_delegate_->GetShellConnector()) {
James Cook8532dbc2017-07-31 21:54:51834 // Connect to local state prefs now, but wait for an active user before
835 // connecting to the profile pref service. The login screen has a temporary
836 // user profile that is not associated with a real user.
Taiju Tsuiki36c517d2017-05-18 06:45:43837 auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
Wenzhao Zang56c292932017-08-02 04:58:34838 RegisterLocalStatePrefs(pref_registry.get());
tibellb93c729b2017-03-30 00:45:09839 prefs::ConnectToPrefService(
Sam McNally538fca1e2017-07-14 03:10:43840 shell_delegate_->GetShellConnector(), std::move(pref_registry),
Sam McNallye36abbc2017-07-20 01:04:28841 base::Bind(&Shell::OnLocalStatePrefServiceInitialized,
842 weak_factory_.GetWeakPtr()),
843 prefs::mojom::kLocalStateServiceName);
jonrossc4ba10602017-04-07 20:51:05844 }
skyb073203a2017-03-13 16:59:16845
sky11cf8db92017-04-10 23:38:08846 // Some delegates access ShellPort during their construction. Create them here
847 // instead of the ShellPort constructor.
skyb073203a2017-03-13 16:59:16848 accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate());
Mitsuru Oshima04b54d02017-10-09 14:22:45849 accessibility_controller_ = std::make_unique<AccessibilityController>(
James Cook5fbdccb2017-09-01 21:17:55850 shell_delegate_->GetShellConnector());
Mitsuru Oshima04b54d02017-10-09 14:22:45851 toast_manager_ = std::make_unique<ToastManager>();
sky07a24d42017-03-09 23:57:30852
sky07a24d42017-03-09 23:57:30853 // Install the custom factory early on so that views::FocusManagers for Tray,
854 // Shelf, and WallPaper could be created by the factory.
855 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
856
Mitsuru Oshima04b54d02017-10-09 14:22:45857 wallpaper_controller_ = std::make_unique<WallpaperController>();
sky07a24d42017-03-09 23:57:30858
Mitsuru Oshima04b54d02017-10-09 14:22:45859 app_list_delegate_impl_ = std::make_unique<AppListDelegateImpl>();
sky15ef0aa2017-01-20 18:55:59860
sky11cf8db92017-04-10 23:38:08861 // TODO(sky): move creation to ShellPort.
skye5fd1222017-04-12 18:43:23862 if (config != Config::MASH)
Mitsuru Oshima04b54d02017-10-09 14:22:45863 immersive_handler_factory_ = std::make_unique<ImmersiveHandlerFactoryAsh>();
skyb7b54092016-08-19 16:00:09864
Mitsuru Oshima04b54d02017-10-09 14:22:45865 window_positioner_ = std::make_unique<WindowPositioner>();
sky984c1892016-04-20 00:00:34866
sky494c6cbd2017-03-27 20:57:48867 if (config == Config::CLASSIC) {
erg36cfb952017-06-21 19:41:45868 native_cursor_manager_ = new NativeCursorManagerAshClassic;
Mitsuru Oshima04b54d02017-10-09 14:22:45869 cursor_manager_ = std::make_unique<CursorManager>(
erg36cfb952017-06-21 19:41:45870 base::WrapUnique(native_cursor_manager_));
871 } else if (config == Config::MUS) {
872 native_cursor_manager_ = new NativeCursorManagerAshMus;
Mitsuru Oshima04b54d02017-10-09 14:22:45873 cursor_manager_ = std::make_unique<CursorManager>(
erg36cfb952017-06-21 19:41:45874 base::WrapUnique(native_cursor_manager_));
skyabcae812017-01-18 17:01:34875 }
skyfee520c2016-02-11 19:57:46876
skyb073203a2017-03-13 16:59:16877 shell_delegate_->PreInit();
Scott Violet596bb46342017-06-21 14:43:13878 bool display_initialized = display_manager_->InitFromCommandLine();
879 if (!display_initialized && config != Config::CLASSIC) {
skycfaad892017-04-28 20:52:58880 // Run display configuration off device in mus mode.
881 display_manager_->set_configure_displays(true);
882 display_configurator_->set_configure_display(true);
883 }
Scott Violet596bb46342017-06-21 14:43:13884 display_configuration_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:45885 std::make_unique<DisplayConfigurationController>(
Scott Violet596bb46342017-06-21 14:43:13886 display_manager_.get(), window_tree_host_manager_.get());
887 display_configurator_->Init(shell_port_->CreateNativeDisplayDelegate(),
Zhenyao Mo472b4c42017-11-07 17:53:21888 false);
[email protected]0249a6532013-10-31 06:53:34889
pneubeck8be1f5422014-10-09 16:46:18890 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell.
891 chromeos::DBusThreadManager* dbus_thread_manager =
892 chromeos::DBusThreadManager::Get();
893 projecting_observer_.reset(
894 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient()));
[email protected]1e31cbd2014-04-07 20:06:11895 display_configurator_->AddObserver(projecting_observer_.get());
sky00c813f2017-03-08 22:48:55896 AddShellObserver(projecting_observer_.get());
[email protected]72bce522014-02-10 21:11:26897
kylechar7e4f46f2017-10-31 23:26:57898 if (!display_initialized) {
899 if (config != Config::CLASSIC && !chromeos::IsRunningAsSystemCompositor()) {
900 display::mojom::DevDisplayControllerPtr controller;
901 shell_delegate_->GetShellConnector()->BindInterface(
902 ui::mojom::kServiceName, &controller);
903 display_manager_->SetDevDisplayController(std::move(controller));
904 }
kylechar98748a52016-12-03 01:33:22905
kylechar7e4f46f2017-10-31 23:26:57906 if (config != Config::CLASSIC || chromeos::IsRunningAsSystemCompositor()) {
907 display_change_observer_ =
908 std::make_unique<display::DisplayChangeObserver>(
909 display_configurator_.get(), display_manager_.get());
kylechar98748a52016-12-03 01:33:22910
kylechar7e4f46f2017-10-31 23:26:57911 shutdown_observer_ =
912 std::make_unique<ShutdownObserver>(display_configurator_.get());
913
914 // Register |display_change_observer_| first so that the rest of
915 // observer gets invoked after the root windows are configured.
916 display_configurator_->AddObserver(display_change_observer_.get());
917 display_error_observer_.reset(new DisplayErrorObserver());
918 display_configurator_->AddObserver(display_error_observer_.get());
919 display_configurator_->set_state_controller(
920 display_change_observer_.get());
921 display_configurator_->set_mirroring_controller(display_manager_.get());
922 display_configurator_->ForceInitialConfigure();
923 display_initialized = true;
924 }
[email protected]b6ba05d902013-10-04 21:38:45925 }
kylechar7e4f46f2017-10-31 23:26:57926
James Cook8ba362c2017-06-16 16:39:16927 display_color_manager_ =
Mitsuru Oshima04b54d02017-10-09 14:22:45928 std::make_unique<DisplayColorManager>(display_configurator_.get());
stevenjb537c5c3f2016-01-20 23:38:12929
[email protected]b6ba05d902013-10-04 21:38:45930 if (!display_initialized)
[email protected]0249a6532013-10-31 06:53:34931 display_manager_->InitDefaultDisplay();
[email protected]b6ba05d902013-10-04 21:38:45932
newcomer2febb9832017-06-12 17:00:23933 if (config == Config::CLASSIC) {
skyabcae812017-01-18 17:01:34934 display_manager_->RefreshFontParams();
[email protected]68d6080e2014-08-21 23:06:32935
Scott Violetc8a1c6c2017-11-29 23:17:36936 aura::Env::GetInstance()->set_context_factory(context_factory);
skyabcae812017-01-18 17:01:34937 aura::Env::GetInstance()->set_context_factory_private(
Scott Violetc8a1c6c2017-11-29 23:17:36938 context_factory_private);
skyabcae812017-01-18 17:01:34939 }
[email protected]ecca62b2013-10-09 16:18:53940
[email protected]b6ba05d902013-10-04 21:38:45941 // The WindowModalityController needs to be at the front of the input event
942 // pretarget handler list to ensure that it processes input events when modal
943 // windows are active.
jamescookb8dcef522016-06-25 14:42:55944 window_modality_controller_.reset(new ::wm::WindowModalityController(this));
[email protected]b6ba05d902013-10-04 21:38:45945
[email protected]e319c7e2014-03-14 19:56:14946 env_filter_.reset(new ::wm::CompoundEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45947 AddPreTargetHandler(env_filter_.get());
948
sky27344382017-03-08 21:30:32949 // FocusController takes ownership of AshFocusRules.
950 focus_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:45951 std::make_unique<::wm::FocusController>(new wm::AshFocusRules());
sky27344382017-03-08 21:30:32952 focus_controller_->AddObserver(this);
sky68612712017-04-27 04:45:04953 if (config != Config::CLASSIC) {
954 window_tree_client_->focus_synchronizer()->SetSingletonFocusClient(
955 focus_controller_.get());
956 }
[email protected]b6ba05d902013-10-04 21:38:45957
[email protected]093b8d642014-04-03 20:59:28958 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:45959
Scott Violet596bb46342017-06-21 14:43:13960 window_tree_host_manager_->Start();
961 AshWindowTreeHostInitParams ash_init_params;
962 window_tree_host_manager_->CreatePrimaryHost(ash_init_params);
963
mswad3d9552017-05-18 21:23:36964 root_window_for_new_windows_ = GetPrimaryRootWindow();
[email protected]b6ba05d902013-10-04 21:38:45965
Scott Violet596bb46342017-06-21 14:43:13966 resolution_notification_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:45967 std::make_unique<ResolutionNotificationController>();
[email protected]b6ba05d902013-10-04 21:38:45968
deratc6250a02017-01-25 05:51:53969 if (cursor_manager_) {
oshimaf84b0da722016-04-27 19:47:19970 cursor_manager_->SetDisplay(
971 display::Screen::GetScreen()->GetPrimaryDisplay());
deratc6250a02017-01-25 05:51:53972 }
[email protected]b6ba05d902013-10-04 21:38:45973
sky11cf8db92017-04-10 23:38:08974 accelerator_controller_ = shell_port_->CreateAcceleratorController();
Mitsuru Oshima04b54d02017-10-09 14:22:45975 tablet_mode_controller_ = std::make_unique<TabletModeController>();
976 shelf_controller_ = std::make_unique<ShelfController>();
[email protected]b6ba05d902013-10-04 21:38:45977
spange9b51272014-12-11 01:20:10978 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06979 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
spange9b51272014-12-11 01:20:10980 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06981 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:39982
[email protected]b6ba05d902013-10-04 21:38:45983 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:45984
derat2d4e62d2015-01-09 16:09:17985 // ui::UserActivityDetector passes events to observers, so let them get
[email protected]b6ba05d902013-10-04 21:38:45986 // rewritten first.
derat2d4e62d2015-01-09 16:09:17987 user_activity_detector_.reset(new ui::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:45988
[email protected]093b8d642014-04-03 20:59:28989 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45990 AddPreTargetHandler(overlay_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45991
[email protected]60d677d2014-05-30 13:07:02992 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
dchenga94547472016-04-08 08:41:11993 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
sky81a2d792017-03-17 19:14:39994 accelerator_controller_->accelerator_history()));
[email protected]b6ba05d902013-10-04 21:38:45995 AddPreTargetHandler(accelerator_filter_.get());
996
[email protected]093b8d642014-04-03 20:59:28997 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:45998 AddPreTargetHandler(event_transformation_handler_.get());
999
sky11cf8db92017-04-10 23:38:081000 toplevel_window_event_handler_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451001 std::make_unique<ToplevelWindowEventHandler>();
[email protected]3537d472014-01-15 05:45:311002
sky83b1bb12017-04-24 20:29:281003 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:341004 system_gesture_filter_.reset(new SystemGestureEventFilter);
1005 AddPreTargetHandler(system_gesture_filter_.get());
1006 }
[email protected]b6ba05d902013-10-04 21:38:451007
[email protected]354520b2014-06-21 04:31:011008 sticky_keys_controller_.reset(new StickyKeysController);
Mitsuru Oshima04b54d02017-10-09 14:22:451009 screen_pinning_controller_ = std::make_unique<ScreenPinningController>();
[email protected]354520b2014-06-21 04:31:011010
jamescookd9f152f2016-11-15 00:53:081011 lock_state_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451012 std::make_unique<LockStateController>(shutdown_controller_.get());
Qiang Xu3fbcbf52017-09-09 01:18:011013 power_button_controller_ = std::make_unique<PowerButtonController>();
[email protected]685442f32014-02-28 10:40:061014 // Pass the initial display state to PowerButtonController.
1015 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:091016 display_configurator_->cached_displays());
jamescook01bf23e72017-01-09 19:58:151017
derat036f91b92017-05-05 00:33:181018 // Forward user activity from the window server to |user_activity_detector_|.
derat94887a22017-01-20 18:17:251019 // The connector is unavailable in some tests.
derat036f91b92017-05-05 00:33:181020 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS &&
1021 shell_delegate_->GetShellConnector()) {
derat94887a22017-01-20 18:17:251022 ui::mojom::UserActivityMonitorPtr user_activity_monitor;
skyb073203a2017-03-13 16:59:161023 shell_delegate_->GetShellConnector()->BindInterface(ui::mojom::kServiceName,
1024 &user_activity_monitor);
Mitsuru Oshima04b54d02017-10-09 14:22:451025 user_activity_forwarder_ = std::make_unique<aura::UserActivityForwarder>(
derat94887a22017-01-20 18:17:251026 std::move(user_activity_monitor), user_activity_detector_.get());
1027 }
1028
Scott Violet361833fb2017-06-21 22:25:201029 // In mash drag and drop is handled by mus.
1030 if (config != Config::MASH)
Mitsuru Oshima04b54d02017-10-09 14:22:451031 drag_drop_controller_ = std::make_unique<DragDropController>();
Scott Violet361833fb2017-06-21 22:25:201032
oshima5a296e82016-04-29 01:32:271033 // |screenshot_controller_| needs to be created (and prepended as a
mukai19274bdd2015-02-24 22:37:481034 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
oshima5a296e82016-04-29 01:32:271035 // process mouse events prior to screenshot session.
mukai19274bdd2015-02-24 22:37:481036 // See http://crbug.com/459214
James Cook5e9d3402017-11-01 00:20:121037 screenshot_controller_ = std::make_unique<ScreenshotController>(
1038 shell_delegate_->CreateScreenshotDelegate());
Mitsuru Oshima04b54d02017-10-09 14:22:451039 mouse_cursor_filter_ = std::make_unique<MouseCursorEventFilter>();
Scott Violet596bb46342017-06-21 14:43:131040 PrependPreTargetHandler(mouse_cursor_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:451041
1042 // Create Controllers that may need root window.
1043 // TODO(oshima): Move as many controllers before creating
1044 // RootWindowController as possible.
1045 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:451046
sammiequon203ae022016-09-18 17:23:421047 laser_pointer_controller_.reset(new LaserPointerController());
1048 partial_magnification_controller_.reset(new PartialMagnificationController());
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:321049 highlighter_controller_.reset(new HighlighterController());
Yue Lia33960a2017-11-01 22:06:071050 voice_interaction_controller_ =
1051 std::make_unique<VoiceInteractionController>();
sammiequon203ae022016-09-18 17:23:421052
jamescookb8dcef522016-06-25 14:42:551053 magnification_controller_.reset(MagnificationController::CreateInstance());
Mitsuru Oshima04b54d02017-10-09 14:22:451054 mru_window_tracker_ = std::make_unique<MruWindowTracker>();
[email protected]b6ba05d902013-10-04 21:38:451055
[email protected]55398d22013-10-10 19:49:201056 autoclick_controller_.reset(AutoclickController::CreateInstance());
1057
[email protected]b6ba05d902013-10-04 21:38:451058 high_contrast_controller_.reset(new HighContrastController);
Saman Sami3fb310d2017-11-09 16:51:541059
1060 viz::mojom::VideoDetectorObserverPtr observer;
1061 video_detector_ =
1062 std::make_unique<VideoDetector>(mojo::MakeRequest(&observer));
1063 shell_port_->AddVideoDetectorObserver(std::move(observer));
[email protected]b6ba05d902013-10-04 21:38:451064
oshimaebbe63772015-02-19 18:41:321065 tooltip_controller_.reset(new views::corewm::TooltipController(
dchenga94547472016-04-08 08:41:111066 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451067 AddPreTargetHandler(tooltip_controller_.get());
1068
hariank0dd03dd2016-07-14 23:47:331069 modality_filter_.reset(new SystemModalContainerEventFilter(this));
1070 AddPreTargetHandler(modality_filter_.get());
1071
[email protected]093b8d642014-04-03 20:59:281072 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451073
skyabcae812017-01-18 17:01:341074 // Must occur after Shell has installed its early pre-target handlers (for
1075 // example, WindowModalityController).
sky11cf8db92017-04-10 23:38:081076 shell_port_->CreatePointerWatcherAdapter();
[email protected]b6ba05d902013-10-04 21:38:451077
[email protected]093b8d642014-04-03 20:59:281078 resize_shadow_controller_.reset(new ResizeShadowController());
sky27344382017-03-08 21:30:321079 shadow_controller_.reset(new ::wm::ShadowController(focus_controller_.get()));
[email protected]b6ba05d902013-10-04 21:38:451080
James Cookb50959e22017-08-10 20:24:381081 logout_confirmation_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451082 std::make_unique<LogoutConfirmationController>();
[email protected]b6ba05d902013-10-04 21:38:451083
jamescookac6724332017-03-21 02:54:431084 // May trigger initialization of the Bluetooth adapter.
1085 tray_bluetooth_helper_->Initialize();
1086
kylechar55f0eaf22017-01-11 22:57:371087 // Create AshTouchTransformController before
oshimae2818922015-07-28 01:18:521088 // WindowTreeHostManager::InitDisplays()
kylechar55f0eaf22017-01-11 22:57:371089 // since AshTouchTransformController listens on
oshimae2818922015-07-28 01:18:521090 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
Mitsuru Oshima04b54d02017-10-09 14:22:451091 touch_transformer_controller_ = std::make_unique<AshTouchTransformController>(
Scott Violet596bb46342017-06-21 14:43:131092 display_configurator_.get(), display_manager_.get(),
1093 shell_port_->CreateTouchTransformDelegate());
[email protected]03122891a2014-05-13 23:56:491094
sky11cf8db92017-04-10 23:38:081095 keyboard_ui_ = shell_port_->CreateKeyboardUI();
skyfee520c2016-02-11 19:57:461096
Scott Violet596bb46342017-06-21 14:43:131097 window_tree_host_manager_->InitHosts();
1098 shell_port_->OnHostsInitialized();
[email protected]b6ba05d902013-10-04 21:38:451099
rsadam9172bc8a2014-10-29 23:37:381100 // Needs to be created after InitDisplays() since it may cause the virtual
1101 // keyboard to be deployed.
sky83b1bb12017-04-24 20:29:281102 if (config != Config::MASH)
skyabcae812017-01-18 17:01:341103 virtual_keyboard_controller_.reset(new VirtualKeyboardController);
rsadam9172bc8a2014-10-29 23:37:381104
msw0e91d932016-08-25 22:34:091105 // Initialize the wallpaper after the RootWindowController has been created,
1106 // otherwise the widget will not paint when restoring after a browser crash.
1107 // Also, initialize after display initialization to ensure correct sizing.
skyb073203a2017-03-13 16:59:161108 wallpaper_delegate_->InitializeWallpaper();
[email protected]b6ba05d902013-10-04 21:38:451109
sadrul7a8785e2016-02-12 21:54:351110 if (cursor_manager_) {
1111 if (initially_hide_cursor_)
1112 cursor_manager_->HideCursor();
ergeeba7c622017-04-25 18:06:161113 cursor_manager_->SetCursor(ui::CursorType::kPointer);
sadrul7a8785e2016-02-12 21:54:351114 }
[email protected]b6ba05d902013-10-04 21:38:451115
Mitsuru Oshima04b54d02017-10-09 14:22:451116 peripheral_battery_notifier_ = std::make_unique<PeripheralBatteryNotifier>();
[email protected]093b8d642014-04-03 20:59:281117 power_event_observer_.reset(new PowerEventObserver());
[email protected]ded58fd2013-10-09 07:56:551118 user_activity_notifier_.reset(
[email protected]b0fa7012014-04-16 12:50:571119 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
[email protected]ded58fd2013-10-09 07:56:551120 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281121 new VideoActivityNotifier(video_detector_.get()));
1122 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
Scott Violet596bb46342017-06-21 14:43:131123 screen_orientation_controller_ =
Mitsuru Oshima04b54d02017-10-09 14:22:451124 std::make_unique<ScreenOrientationController>();
Scott Violet596bb46342017-06-21 14:43:131125 screen_layout_observer_.reset(new ScreenLayoutObserver());
yiyix90cfee22017-02-16 05:38:181126 sms_observer_.reset(new SmsObserver());
jamescook01bf23e72017-01-09 19:58:151127
xdaid4913762017-07-06 00:17:221128 split_view_controller_.reset(new SplitViewController());
1129
[email protected]b6ba05d902013-10-04 21:38:451130 // The compositor thread and main message loop have to be running in
1131 // order to create mirror window. Run it after the main message loop
1132 // is started.
Scott Violet596bb46342017-06-21 14:43:131133 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031134
Mitsuru Oshima04b54d02017-10-09 14:22:451135 message_center_controller_ = std::make_unique<MessageCenterController>();
Evan Stade2c43a87b32017-08-31 17:53:101136
sky00c813f2017-03-08 22:48:551137 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:181138 observer.OnShellInitialized();
phweiss0bf64c52015-11-17 12:56:181139
Scott Violet41562d1c2017-06-26 15:15:481140 user_metrics_recorder_->OnShellInitialized();
[email protected]b6ba05d902013-10-04 21:38:451141}
1142
[email protected]41baaed2013-11-09 04:18:261143void Shell::InitRootWindow(aura::Window* root_window) {
sky27344382017-03-08 21:30:321144 DCHECK(focus_controller_);
[email protected]d90b8392012-06-13 09:34:561145 DCHECK(visibility_controller_.get());
[email protected]d90b8392012-06-13 09:34:561146
sky27344382017-03-08 21:30:321147 aura::client::SetFocusClient(root_window, focus_controller_.get());
Thiago Farina3b086a02017-05-30 22:32:501148 ::wm::SetActivationClient(root_window, focus_controller_.get());
sky27344382017-03-08 21:30:321149 root_window->AddPreTargetHandler(focus_controller_.get());
[email protected]d90b8392012-06-13 09:34:561150 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
Scott Violet361833fb2017-06-21 22:25:201151 if (drag_drop_controller_) {
1152 DCHECK_NE(Config::MASH, GetAshConfig());
1153 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
1154 } else {
1155 DCHECK_EQ(Config::MASH, GetAshConfig());
1156 }
[email protected]8d625fb2012-07-18 16:40:061157 aura::client::SetScreenPositionClient(root_window,
1158 screen_position_controller_.get());
sadrul7a8785e2016-02-12 21:54:351159 aura::client::SetCursorClient(root_window, cursor_manager_.get());
Thiago Farina3b086a02017-05-30 22:32:501160 ::wm::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381161 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561162
Thiago Farina3b086a02017-05-30 22:32:501163 ::wm::SetWindowMoveClient(root_window, toplevel_window_event_handler_.get());
[email protected]3537d472014-01-15 05:45:311164 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1165 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
[email protected]d90b8392012-06-13 09:34:561166}
1167
skyabcae812017-01-18 17:01:341168void Shell::CloseAllRootWindowChildWindows() {
msw257a6a232017-06-01 01:46:301169 for (aura::Window* root : GetAllRootWindows()) {
1170 RootWindowController* controller = RootWindowController::ForWindow(root);
skyabcae812017-01-18 17:01:341171 if (controller) {
1172 controller->CloseChildWindows();
1173 } else {
msw257a6a232017-06-01 01:46:301174 while (!root->children().empty()) {
1175 aura::Window* child = root->children()[0];
skyabcae812017-01-18 17:01:341176 delete child;
1177 }
1178 }
1179 }
1180}
1181
[email protected]c0ce80e2012-10-05 23:28:271182bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1183 RootWindowControllerList controllers = GetAllRootWindowControllers();
oshima9a61ecf2016-06-18 10:43:051184 for (RootWindowController* controller : controllers) {
1185 if (controller->CanWindowReceiveEvents(window))
[email protected]602022b2014-03-31 17:07:311186 return true;
[email protected]c0ce80e2012-10-05 23:28:271187 }
1188 return false;
1189}
1190
[email protected]049cf34b2012-12-07 17:15:481191////////////////////////////////////////////////////////////////////////////////
1192// Shell, ui::EventTarget overrides:
1193
[email protected]869f6352012-12-06 20:47:171194bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411195 return true;
1196}
1197
1198ui::EventTarget* Shell::GetParentTarget() {
[email protected]ff0278852013-11-05 22:35:481199 return aura::Env::GetInstance();
[email protected]5097e692012-10-30 22:08:411200}
1201
dchenga94547472016-04-08 08:41:111202std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1203 return std::unique_ptr<ui::EventTargetIterator>();
[email protected]3e670aa2013-12-02 19:04:321204}
1205
1206ui::EventTargeter* Shell::GetEventTargeter() {
1207 NOTREACHED();
achuith287b26e2015-09-03 17:49:181208 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321209}
1210
sky27344382017-03-08 21:30:321211void Shell::OnWindowActivated(
Thiago Farina3b086a02017-05-30 22:32:501212 ::wm::ActivationChangeObserver::ActivationReason reason,
sky27344382017-03-08 21:30:321213 aura::Window* gained_active,
1214 aura::Window* lost_active) {
mswad3d9552017-05-18 21:23:361215 if (gained_active)
1216 root_window_for_new_windows_ = gained_active->GetRootWindow();
sky27344382017-03-08 21:30:321217}
1218
Xiyuan Xiab64fd0a2017-04-13 17:53:141219void Shell::OnSessionStateChanged(session_manager::SessionState state) {
jamescook788b4fc2017-05-18 16:16:061220 // Initialize the shelf when a session becomes active. It's safe to do this
sky5ad143a2017-03-22 04:31:231221 // multiple times (e.g. initial login vs. multiprofile add session).
1222 if (state == session_manager::SessionState::ACTIVE) {
jamescook788b4fc2017-05-18 16:16:061223 InitializeShelf();
okac21941d2017-06-20 17:54:441224 }
1225 // Recreates keyboard on user profile change, to refresh keyboard
1226 // extensions with the new profile and the extensions call proper IME.
1227 // |LOGGED_IN_NOT_ACTIVE| is needed so that the virtual keyboard works on
1228 // supervised user creation. crbug.com/712873
1229 // |ACTIVE| is also needed for guest user workflow.
Steven Bennetts9fd12ad2017-11-09 23:36:271230 // NOTE: keyboard::IsKeyboardEnabled() is false in mash, but may not be in
1231 // unit tests. crbug.com/646565.
okac21941d2017-06-20 17:54:441232 if ((state == session_manager::SessionState::LOGGED_IN_NOT_ACTIVE ||
1233 state == session_manager::SessionState::ACTIVE) &&
1234 keyboard::IsKeyboardEnabled()) {
Steven Bennetts9fd12ad2017-11-09 23:36:271235 // Recreate the keyboard after initial login and after multiprofile login.
1236 CreateKeyboard();
sky5ad143a2017-03-22 04:31:231237 }
Scott Violet0c0dcde2017-08-04 21:48:181238
1239 shell_port_->UpdateSystemModalAndBlockingContainers();
xiyuan233f4e72017-04-06 06:59:561240}
sky5ad143a2017-03-22 04:31:231241
Xiyuan Xiab64fd0a2017-04-13 17:53:141242void Shell::OnLoginStatusChanged(LoginStatus login_status) {
xiyuan233f4e72017-04-06 06:59:561243 UpdateAfterLoginStatusChange(login_status);
sky5ad143a2017-03-22 04:31:231244}
1245
Xiyuan Xiab64fd0a2017-04-13 17:53:141246void Shell::OnLockStateChanged(bool locked) {
xiyuan7ebbf7f2017-04-10 16:49:101247#ifndef NDEBUG
1248 // Make sure that there is no system modal in Lock layer when unlocked.
1249 if (!locked) {
1250 aura::Window::Windows containers = wm::GetContainersFromAllRootWindows(
1251 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
1252 for (aura::Window* container : containers)
1253 DCHECK(container->children().empty());
1254 }
1255#endif
1256}
1257
jamescook788b4fc2017-05-18 16:16:061258void Shell::InitializeShelf() {
1259 // Must occur after SessionController creation and user login.
1260 DCHECK(session_controller());
1261 DCHECK_GT(session_controller()->NumberOfLoggedInUsers(), 0);
1262
jamescook788b4fc2017-05-18 16:16:061263 if (!shelf_window_watcher_)
Mitsuru Oshima04b54d02017-10-09 14:22:451264 shelf_window_watcher_ = std::make_unique<ShelfWindowWatcher>(shelf_model());
jamescook788b4fc2017-05-18 16:16:061265
1266 for (RootWindowController* root : GetAllRootWindowControllers())
1267 root->InitializeShelf();
1268}
1269
Sam McNallye36abbc2017-07-20 01:04:281270void Shell::OnLocalStatePrefServiceInitialized(
1271 std::unique_ptr<::PrefService> pref_service) {
Sam McNallya853cd82017-08-30 01:55:101272 DCHECK(!local_state_);
James Cook8532dbc2017-07-31 21:54:511273 // |pref_service| is null if can't connect to Chrome (as happens when
Sam McNallye36abbc2017-07-20 01:04:281274 // running mash outside of chrome --mash and chrome isn't built).
Sam McNallya853cd82017-08-30 01:55:101275 if (!pref_service)
1276 return;
1277
1278 local_state_ = std::move(pref_service);
James Cookbbe5cb12017-08-08 18:32:211279
1280 for (auto& observer : shell_observers_)
Sam McNallya853cd82017-08-30 01:55:101281 observer.OnLocalStatePrefServiceInitialized(local_state_.get());
Sam McNallye36abbc2017-07-20 01:04:281282}
1283
[email protected]55f593352011-12-24 05:42:461284} // namespace ash