blob: 9b151c25e32939612baaa6c70ad3a2cb6f22db73 [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>
[email protected]0039db92012-05-09 04:11:458#include <string>
dchengcbf0d9d2015-12-27 22:49:239#include <utility>
[email protected]f7eb89c2011-12-13 09:48:5410
James Cookb0bf8e82017-04-09 17:01:4411#include "ash/accelerators/accelerator_controller.h"
[email protected]60d677d2014-05-30 13:07:0212#include "ash/accelerators/accelerator_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4413#include "ash/accelerators/ash_focus_manager_factory.h"
jamescook01bf23e72017-01-09 19:58:1514#include "ash/accelerators/magnifier_key_scroller.h"
15#include "ash/accelerators/spoken_feedback_toggler.h"
James Cookb0bf8e82017-04-09 17:01:4416#include "ash/accessibility_delegate.h"
sky15ef0aa2017-01-20 18:55:5917#include "ash/app_list/app_list_delegate_impl.h"
James Cookb0bf8e82017-04-09 17:01:4418#include "ash/ash_constants.h"
moshayedic229a522017-05-05 18:14:2619#include "ash/ash_switches.h"
[email protected]55398d22013-10-10 19:49:2020#include "ash/autoclick/autoclick_controller.h"
James Cookb0bf8e82017-04-09 17:01:4421#include "ash/cast_config_controller.h"
Scott Violetd64dac12017-06-02 21:50:0822#include "ash/display/ash_display_controller.h"
[email protected]87ec2202014-02-06 06:24:2723#include "ash/display/cursor_window_controller.h"
jamescook01bf23e72017-01-09 19:58:1524#include "ash/display/display_color_manager_chromeos.h"
stevenjb537c5c3f2016-01-20 23:38:1225#include "ash/display/display_configuration_controller.h"
jamescook01bf23e72017-01-09 19:58:1526#include "ash/display/display_error_observer_chromeos.h"
[email protected]682990f2013-01-10 06:49:1127#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2728#include "ash/display/mouse_cursor_event_filter.h"
jamescook01bf23e72017-01-09 19:58:1529#include "ash/display/projecting_observer_chromeos.h"
30#include "ash/display/resolution_notification_controller.h"
rjkroege2c9305402016-09-07 00:21:4531#include "ash/display/screen_ash.h"
jamescook01bf23e72017-01-09 19:58:1532#include "ash/display/screen_orientation_controller_chromeos.h"
[email protected]8d625fb2012-07-18 16:40:0633#include "ash/display/screen_position_controller.h"
jamescook01bf23e72017-01-09 19:58:1534#include "ash/display/shutdown_observer_chromeos.h"
oshimae2818922015-07-28 01:18:5235#include "ash/display/window_tree_host_manager.h"
[email protected]f4c92b382012-08-28 00:59:5936#include "ash/drag_drop/drag_drop_controller.h"
[email protected]59ccade2013-10-17 17:56:4037#include "ash/first_run/first_run_helper_impl.h"
James Cookb0bf8e82017-04-09 17:01:4438#include "ash/focus_cycler.h"
39#include "ash/frame/custom_frame_view_ash.h"
40#include "ash/gpu_support.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"
xiaoyinh2bbdd102017-05-18 23:29:4247#include "ash/login/lock_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"
52#include "ash/new_window_controller.h"
53#include "ash/palette_delegate.h"
sky494c6cbd2017-03-27 20:57:4854#include "ash/public/cpp/config.h"
msw109806d2017-06-02 20:11:5755#include "ash/public/cpp/shelf_model.h"
jamescook8800b8232016-10-19 12:46:2756#include "ash/public/cpp/shell_window_ids.h"
[email protected]d90b8392012-06-13 09:34:5657#include "ash/root_window_controller.h"
James Cookb0bf8e82017-04-09 17:01:4458#include "ash/session/session_controller.h"
James Cook840177e2017-05-25 02:20:0159#include "ash/shelf/shelf.h"
James Cookb0bf8e82017-04-09 17:01:4460#include "ash/shelf/shelf_controller.h"
James Cookb0bf8e82017-04-09 17:01:4461#include "ash/shelf/shelf_window_watcher.h"
James Cookb0bf8e82017-04-09 17:01:4462#include "ash/shell_delegate.h"
[email protected]1b4c7472014-05-15 18:32:2363#include "ash/shell_init_params.h"
James Cookb0bf8e82017-04-09 17:01:4464#include "ash/shell_observer.h"
sky11cf8db92017-04-10 23:38:0865#include "ash/shell_port.h"
Scott Violet22a7b9212017-07-20 19:05:1966#include "ash/shell_port_classic.h"
James Cookb0bf8e82017-04-09 17:01:4467#include "ash/shutdown_controller.h"
jamescook01bf23e72017-01-09 19:58:1568#include "ash/sticky_keys/sticky_keys_controller.h"
James Cooka35a1e22017-04-08 02:33:0869#include "ash/system/bluetooth/bluetooth_notification_controller.h"
70#include "ash/system/bluetooth/tray_bluetooth_helper.h"
71#include "ash/system/brightness/brightness_controller_chromeos.h"
James Cookb0bf8e82017-04-09 17:01:4472#include "ash/system/brightness_control_delegate.h"
Lann Martinb9991402017-06-23 22:25:0873#include "ash/system/keyboard_brightness/keyboard_brightness_controller.h"
James Cookb0bf8e82017-04-09 17:01:4474#include "ash/system/keyboard_brightness_control_delegate.h"
James Cookb0bf8e82017-04-09 17:01:4475#include "ash/system/locale/locale_notification_controller.h"
James Cooka35a1e22017-04-08 02:33:0876#include "ash/system/network/sms_observer.h"
77#include "ash/system/network/vpn_list.h"
afakhrye4fae852017-05-09 18:49:0678#include "ash/system/night_light/night_light_controller.h"
Sammie Quon4d7dba62017-08-03 23:18:1779#include "ash/system/palette/palette_tray.h"
James Cooka35a1e22017-04-08 02:33:0880#include "ash/system/power/power_event_observer.h"
81#include "ash/system/power/power_status.h"
82#include "ash/system/power/video_activity_notifier.h"
83#include "ash/system/screen_layout_observer.h"
James Cookdc041122017-08-01 14:03:2284#include "ash/system/session/logout_button_tray.h"
James Cooka35a1e22017-04-08 02:33:0885#include "ash/system/session/logout_confirmation_controller.h"
James Cookb0bf8e82017-04-09 17:01:4486#include "ash/system/status_area_widget.h"
87#include "ash/system/toast/toast_manager.h"
88#include "ash/system/tray/system_tray_controller.h"
89#include "ash/system/tray/system_tray_delegate.h"
90#include "ash/system/tray/system_tray_notifier.h"
James Cook98072352017-08-07 18:00:0791#include "ash/system/tray_caps_lock.h"
kylechar55f0eaf22017-01-11 22:57:3792#include "ash/touch/ash_touch_transform_controller.h"
tbarzicc78da1ff92017-05-08 20:46:1593#include "ash/tray_action/tray_action.h"
oshima5a296e82016-04-29 01:32:2794#include "ash/utility/screenshot_controller.h"
jamescook01bf23e72017-01-09 19:58:1595#include "ash/virtual_keyboard_controller.h"
James Cookb0bf8e82017-04-09 17:01:4496#include "ash/wallpaper/wallpaper_controller.h"
97#include "ash/wallpaper/wallpaper_delegate.h"
[email protected]39718b52012-12-03 17:24:5698#include "ash/wm/ash_focus_rules.h"
James Cookb0bf8e82017-04-09 17:01:4499#include "ash/wm/container_finder.h"
[email protected]262f8bd2012-03-23 19:30:27100#include "ash/wm/event_client_impl.h"
James Cookb0bf8e82017-04-09 17:01:44101#include "ash/wm/immersive_context_ash.h"
skyb7b54092016-08-19 16:00:09102#include "ash/wm/immersive_handler_factory_ash.h"
[email protected]ab4f8c92013-05-30 19:07:47103#include "ash/wm/lock_state_controller.h"
James Cookb0bf8e82017-04-09 17:01:44104#include "ash/wm/mru_window_tracker.h"
erg36cfb952017-06-21 19:41:45105#include "ash/wm/native_cursor_manager_ash_classic.h"
106#include "ash/wm/native_cursor_manager_ash_mus.h"
[email protected]9ae32df2012-07-26 03:25:18107#include "ash/wm/overlay_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44108#include "ash/wm/overview/window_selector_controller.h"
[email protected]e0d22e82012-01-04 00:46:57109#include "ash/wm/power_button_controller.h"
[email protected]e4a181cc2012-03-17 02:20:57110#include "ash/wm/resize_shadow_controller.h"
James Cookb0bf8e82017-04-09 17:01:44111#include "ash/wm/root_window_finder.h"
hidehiko6821ca42016-06-18 11:12:23112#include "ash/wm/screen_pinning_controller.h"
xdaid4913762017-07-06 00:17:22113#include "ash/wm/splitview/split_view_controller.h"
[email protected]435b212e2012-04-05 19:43:37114#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:27115#include "ash/wm/system_modal_container_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44116#include "ash/wm/system_modal_container_layout_manager.h"
Mitsuru Oshima0e9b7a62017-07-19 18:23:03117#include "ash/wm/tablet_mode/tablet_mode_controller.h"
118#include "ash/wm/tablet_mode/tablet_mode_window_manager.h"
[email protected]3537d472014-01-15 05:45:31119#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:58120#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:02121#include "ash/wm/window_animations.h"
James Cookb0bf8e82017-04-09 17:01:44122#include "ash/wm/window_cycle_controller.h"
123#include "ash/wm/window_positioner.h"
[email protected]f059c6942012-07-21 14:27:57124#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:59125#include "ash/wm/window_util.h"
James Cookb0bf8e82017-04-09 17:01:44126#include "ash/wm/workspace_controller.h"
[email protected]f296be72011-10-11 15:40:00127#include "base/bind.h"
jamescook01bf23e72017-01-09 19:58:15128#include "base/bind_helpers.h"
jamescookfda159002016-10-21 18:48:57129#include "base/command_line.h"
dchenga94547472016-04-08 08:41:11130#include "base/memory/ptr_util.h"
Alex Newcomer8fdcb9342017-08-08 18:48:44131#include "base/metrics/histogram_macros.h"
jamescook01bf23e72017-01-09 19:58:15132#include "base/sys_info.h"
tzik0dd58d42017-02-15 08:26:52133#include "base/threading/sequenced_worker_pool.h"
primiano7182d7b2015-01-30 18:02:03134#include "base/trace_event/trace_event.h"
jamescook01bf23e72017-01-09 19:58:15135#include "chromeos/audio/audio_a11y_controller.h"
136#include "chromeos/chromeos_switches.h"
137#include "chromeos/dbus/dbus_thread_manager.h"
reveman24158982017-01-10 05:58:45138#include "chromeos/system/devicemode.h"
tibellb93c729b2017-03-30 00:45:09139#include "components/prefs/pref_registry_simple.h"
140#include "components/prefs/pref_service.h"
tibellb93c729b2017-03-30 00:45:09141#include "services/preferences/public/cpp/pref_service_factory.h"
skyb073203a2017-03-13 16:59:16142#include "services/preferences/public/interfaces/preferences.mojom.h"
derat94887a22017-01-20 18:17:25143#include "services/service_manager/public/cpp/connector.h"
144#include "services/ui/public/interfaces/constants.mojom.h"
sky7db5ccf2017-03-14 21:52:29145#include "ui/app_list/presenter/app_list.h"
[email protected]2c456102011-12-26 06:26:34146#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:44147#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:58148#include "ui/aura/layout_manager.h"
sky68612712017-04-27 04:45:04149#include "ui/aura/mus/focus_synchronizer.h"
derat94887a22017-01-20 18:17:25150#include "ui/aura/mus/user_activity_forwarder.h"
sky68612712017-04-27 04:45:04151#include "ui/aura/mus/window_tree_client.h"
[email protected]87b0d82e2011-10-07 21:02:59152#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:26153#include "ui/aura/window_event_dispatcher.h"
[email protected]2d4817742012-12-17 20:16:18154#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:17155#include "ui/base/user_activity/user_activity_detector.h"
jamescook01bf23e72017-01-09 19:58:15156#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]116302fc2012-05-05 21:45:41157#include "ui/compositor/layer.h"
158#include "ui/compositor/layer_animator.h"
oshimaf84b0da722016-04-27 19:47:19159#include "ui/display/display.h"
sky2f68b6f2017-05-21 16:08:39160#include "ui/display/manager/chromeos/default_touch_transform_setter.h"
jamescook01bf23e72017-01-09 19:58:15161#include "ui/display/manager/chromeos/display_change_observer.h"
162#include "ui/display/manager/chromeos/display_configurator.h"
sky7265b1cc2017-05-22 23:11:03163#include "ui/display/manager/chromeos/touch_transform_setter.h"
rjkroege72f8154f2016-10-29 00:49:02164#include "ui/display/manager/display_manager.h"
oshimaf84b0da722016-04-27 19:47:19165#include "ui/display/screen.h"
skycfaad892017-04-28 20:52:58166#include "ui/display/types/native_display_delegate.h"
[email protected]3e670aa2013-12-02 19:04:32167#include "ui/events/event_target_iterator.h"
sky4ec2be82017-01-06 17:38:32168#include "ui/gfx/geometry/insets.h"
[email protected]9ec0f452012-05-31 15:58:53169#include "ui/gfx/image/image_skia.h"
[email protected]b6ba05d902013-10-04 21:38:45170#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28171#include "ui/keyboard/keyboard_switches.h"
yhanada8909a542017-07-11 10:06:19172#include "ui/keyboard/keyboard_ui.h"
[email protected]f1d5c3a2013-04-23 17:42:56173#include "ui/keyboard/keyboard_util.h"
[email protected]d7f30a72013-10-05 05:09:41174#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04175#include "ui/views/corewm/tooltip_controller.h"
sky07a24d42017-03-09 23:57:30176#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:58177#include "ui/views/widget/native_widget_aura.h"
178#include "ui/views/widget/widget.h"
[email protected]60d677d2014-05-30 13:07:02179#include "ui/wm/core/accelerator_filter.h"
[email protected]ee3ed10772014-03-11 22:02:01180#include "ui/wm/core/compound_event_filter.h"
181#include "ui/wm/core/focus_controller.h"
[email protected]ee3ed10772014-03-11 22:02:01182#include "ui/wm/core/shadow_controller.h"
183#include "ui/wm/core/visibility_controller.h"
184#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59185
[email protected]55f593352011-12-24 05:42:46186namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59187
188namespace {
[email protected]671a2ae2011-10-13 21:53:23189
[email protected]615922f2012-02-07 02:41:15190using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45191using views::Widget;
192
jamescook518dccbd2017-05-18 04:57:07193bool g_is_browser_process_with_mash = false;
194
[email protected]b5756e22012-11-30 01:32:02195// A Corewm VisibilityController subclass that calls the Ash animation routine
196// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14197class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02198 public:
199 AshVisibilityController() {}
dcheng1f4538e2014-10-27 23:57:05200 ~AshVisibilityController() override {}
[email protected]b5756e22012-11-30 01:32:02201
202 private:
[email protected]e319c7e2014-03-14 19:56:14203 // Overridden from ::wm::VisibilityController:
dcheng1f4538e2014-10-27 23:57:05204 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
205 bool visible) override {
[email protected]b5756e22012-11-30 01:32:02206 return AnimateOnChildWindowVisibilityChanged(window, visible);
207 }
208
209 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
210};
211
[email protected]87b0d82e2011-10-07 21:02:59212} // namespace
213
[email protected]cac10fc62011-10-07 23:22:56214// static
achuith287b26e2015-09-03 17:49:18215Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13216// static
sky00f98a372017-01-11 06:03:49217aura::WindowTreeClient* Shell::window_tree_client_ = nullptr;
218// static
skya8b222f2017-01-12 15:47:13219aura::WindowManagerClient* Shell::window_manager_client_ = nullptr;
220// static
[email protected]9488d4d2012-02-29 18:32:37221bool Shell::initially_hide_cursor_ = false;
[email protected]2b4cd302012-02-24 20:21:13222
223////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56224// Shell, public:
225
[email protected]cac10fc62011-10-07 23:22:56226// static
[email protected]1b4c7472014-05-15 18:32:23227Shell* Shell::CreateInstance(const ShellInitParams& init_params) {
[email protected]3266c2b92011-11-14 00:06:08228 CHECK(!instance_);
sky11cf8db92017-04-10 23:38:08229 ShellPort* shell_port = init_params.shell_port;
230 if (!shell_port)
231 shell_port = new ShellPortClassic();
skyb073203a2017-03-13 16:59:16232 instance_ = new Shell(base::WrapUnique<ShellDelegate>(init_params.delegate),
sky11cf8db92017-04-10 23:38:08233 base::WrapUnique<ShellPort>(shell_port));
[email protected]1b4c7472014-05-15 18:32:23234 instance_->Init(init_params);
[email protected]3266c2b92011-11-14 00:06:08235 return instance_;
236}
237
238// static
skyb073203a2017-03-13 16:59:16239Shell* Shell::Get() {
jamescook518dccbd2017-05-18 04:57:07240 CHECK(!g_is_browser_process_with_mash) // Implies null |instance_|.
241 << "Ash is running in its own process so Shell::Get() will return null. "
242 "The browser process must use the mojo interfaces in //ash/public to "
243 "access ash. See ash/README.md for details.";
oshima9eea82da2014-09-13 01:11:07244 CHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56245 return instance_;
246}
247
[email protected]6377a002011-11-10 20:26:47248// static
[email protected]b3b7bcd2012-03-06 19:35:45249bool Shell::HasInstance() {
250 return !!instance_;
251}
252
253// static
[email protected]ef589af2011-12-03 01:07:15254void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47255 delete instance_;
[email protected]6377a002011-11-10 20:26:47256}
257
[email protected]e73bd7802012-02-17 20:10:34258// static
[email protected]093b8d642014-04-03 20:59:28259RootWindowController* Shell::GetPrimaryRootWindowController() {
oshima9eea82da2014-09-13 01:11:07260 CHECK(HasInstance());
msw257a6a232017-06-01 01:46:30261 return RootWindowController::ForWindow(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23262}
263
264// static
265Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
oshima9eea82da2014-09-13 01:11:07266 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34267 RootWindowControllerList root_window_controllers;
msw257a6a232017-06-01 01:46:30268 for (aura::Window* root : GetAllRootWindows())
269 root_window_controllers.push_back(RootWindowController::ForWindow(root));
skyabcae812017-01-18 17:01:34270 return root_window_controllers;
[email protected]d90b8392012-06-13 09:34:56271}
272
273// static
thanhphc90f49ca2017-03-03 17:48:53274RootWindowController* Shell::GetRootWindowControllerWithDisplayId(
275 int64_t display_id) {
276 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13277 aura::Window* root = GetRootWindowForDisplayId(display_id);
msw257a6a232017-06-01 01:46:30278 return root ? RootWindowController::ForWindow(root) : nullptr;
thanhphc90f49ca2017-03-03 17:48:53279}
280
281// static
Scott Violet596bb46342017-06-21 14:43:13282aura::Window* Shell::GetRootWindowForDisplayId(int64_t display_id) {
283 CHECK(HasInstance());
284 return instance_->window_tree_host_manager_->GetRootWindowForDisplayId(
285 display_id);
286}
287
288// static
[email protected]bf9cdb362013-10-25 19:22:45289aura::Window* Shell::GetPrimaryRootWindow() {
oshima9eea82da2014-09-13 01:11:07290 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13291 return instance_->window_tree_host_manager_->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34292}
293
[email protected]7b0f7502012-06-11 00:12:39294// static
sky27344382017-03-08 21:30:32295aura::Window* Shell::GetRootWindowForNewWindows() {
296 CHECK(Shell::HasInstance());
skycb4be5b2017-04-06 17:52:45297 Shell* shell = Shell::Get();
sky27344382017-03-08 21:30:32298 if (shell->scoped_root_window_for_new_windows_)
299 return shell->scoped_root_window_for_new_windows_;
300 return shell->root_window_for_new_windows_;
mfomitcheva1a8aa62016-05-03 16:23:26301}
302
303// static
[email protected]c9390bd2013-11-08 20:33:13304aura::Window::Windows Shell::GetAllRootWindows() {
oshima9eea82da2014-09-13 01:11:07305 CHECK(HasInstance());
Scott Violet596bb46342017-06-21 14:43:13306 return instance_->window_tree_host_manager_->GetAllRootWindows();
[email protected]be65be362012-06-15 07:38:23307}
308
309// static
jamescookb8dcef522016-06-25 14:42:55310aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) {
[email protected]7b0f7502012-06-11 00:12:39311 return root_window->GetChildById(container_id);
312}
313
314// static
[email protected]bf9cdb362013-10-25 19:22:45315const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38316 int container_id) {
317 return root_window->GetChildById(container_id);
318}
319
sky494c6cbd2017-03-27 20:57:48320// static
jamescook0dfe5632017-04-05 18:49:02321Config Shell::GetAshConfig() {
sky11cf8db92017-04-10 23:38:08322 return Get()->shell_port_->GetAshConfig();
sky494c6cbd2017-03-27 20:57:48323}
324
moshayedic229a522017-05-05 18:14:26325// static
326bool Shell::ShouldUseIMEService() {
327 return Shell::GetAshConfig() == Config::MASH ||
328 (Shell::GetAshConfig() == Config::MUS &&
329 base::CommandLine::ForCurrentProcess()->HasSwitch(
330 switches::kUseIMEService));
331}
332
afakhrye4fae852017-05-09 18:49:06333// static
Wenzhao Zang56c292932017-08-02 04:58:34334void Shell::RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
Sammie Quon4d7dba62017-08-03 23:18:17335 PaletteTray::RegisterLocalStatePrefs(registry);
Wenzhao Zang56c292932017-08-02 04:58:34336 WallpaperController::RegisterLocalStatePrefs(registry);
337}
338
339// static
James Cook8532dbc2017-07-31 21:54:51340void Shell::RegisterProfilePrefs(PrefRegistrySimple* registry) {
James Cookdc041122017-08-01 14:03:22341 LogoutButtonTray::RegisterProfilePrefs(registry);
James Cook8532dbc2017-07-31 21:54:51342 NightLightController::RegisterProfilePrefs(registry);
afakhrye4fae852017-05-09 18:49:06343}
344
[email protected]57b8bb352012-01-11 05:11:46345views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
346 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04347 // Use translucent-style window frames for dialogs.
[email protected]85501fe2013-10-18 10:15:27348 return new CustomFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46349}
350
[email protected]2e236a52012-06-27 22:21:47351void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44352 const gfx::Insets& insets) {
Scott Violet596bb46342017-06-21 14:43:13353 window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow(contains,
354 insets);
[email protected]1a2145b2012-03-13 21:09:17355}
356
[email protected]58868abf2014-01-17 23:45:33357void Shell::OnCastingSessionStartedOrStopped(bool started) {
sky00c813f2017-03-08 22:48:55358 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18359 observer.OnCastingSessionStartedOrStopped(started);
[email protected]58868abf2014-01-17 23:45:33360}
361
varkhac71444e52017-05-25 22:51:34362void Shell::OnRootWindowAdded(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55363 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18364 observer.OnRootWindowAdded(root_window);
[email protected]0e3e7cb2014-04-12 05:18:25365}
366
[email protected]51f438112013-11-18 19:32:50367void Shell::CreateKeyboard() {
Keigo Okae82281a2017-06-14 13:59:14368 if (keyboard::IsKeyboardEnabled()) {
369 if (keyboard::KeyboardController::GetInstance()) {
370 RootWindowControllerList controllers = GetAllRootWindowControllers();
371 for (RootWindowControllerList::iterator iter = controllers.begin();
372 iter != controllers.end(); ++iter) {
373 (*iter)->DeactivateKeyboard(
374 keyboard::KeyboardController::GetInstance());
375 }
376 }
377 keyboard::KeyboardController::ResetInstance(
378 new keyboard::KeyboardController(shell_delegate_->CreateKeyboardUI(),
379 virtual_keyboard_controller_.get()));
380 for (auto& observer : shell_observers_)
381 observer.OnKeyboardControllerCreated();
382 }
383
jamescookb8dcef522016-06-25 14:42:55384 GetPrimaryRootWindowController()->ActivateKeyboard(
385 keyboard::KeyboardController::GetInstance());
[email protected]51f438112013-11-18 19:32:50386}
387
Keigo Okac7617a42017-06-14 11:33:24388void Shell::DestroyKeyboard() {
sky11cf8db92017-04-10 23:38:08389 // TODO(jamescook): Move keyboard create and hide into ShellPort.
sky79fa34712017-03-20 23:46:47390 keyboard_ui_->Hide();
[email protected]a0b3fb882014-04-07 19:26:03391 if (keyboard::KeyboardController::GetInstance()) {
[email protected]e1b299b2014-01-29 23:53:41392 RootWindowControllerList controllers = GetAllRootWindowControllers();
393 for (RootWindowControllerList::iterator iter = controllers.begin();
jamescookb8dcef522016-06-25 14:42:55394 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:03395 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]e1b299b2014-01-29 23:53:41396 }
397 }
achuith287b26e2015-09-03 17:49:18398 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]e1b299b2014-01-29 23:53:41399}
400
[email protected]da285852014-05-27 19:53:43401bool Shell::ShouldSaveDisplaySettings() {
sky2c5eae82017-06-06 01:46:58402 // This function is only called from Chrome, hence the DCHECK for not-MASH.
skye5fd1222017-04-12 18:43:23403 DCHECK(GetAshConfig() != Config::MASH);
jamescookb8dcef522016-06-25 14:42:55404 return !(
405 screen_orientation_controller_->ignore_display_configuration_updates() ||
406 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43407}
[email protected]da285852014-05-27 19:53:43408
afakhry9e0a18b32017-06-05 19:23:14409NightLightController* Shell::night_light_controller() {
410 DCHECK(NightLightController::IsFeatureEnabled());
411 return night_light_controller_.get();
412}
413
sky5ad143a2017-03-22 04:31:23414ShelfModel* Shell::shelf_model() {
415 return shelf_controller_->model();
416}
417
Thiago Farina3b086a02017-05-30 22:32:50418::wm::ActivationClient* Shell::activation_client() {
sky27344382017-03-08 21:30:32419 return focus_controller_.get();
420}
421
[email protected]c758fbf2012-03-25 22:53:59422void Shell::UpdateShelfVisibility() {
msw257a6a232017-06-01 01:46:30423 for (aura::Window* root : GetAllRootWindows())
424 Shelf::ForWindow(root)->UpdateVisibilityState();
[email protected]c758fbf2012-03-25 22:53:59425}
426
James Cook6d51c9182017-08-04 01:31:00427PrefService* Shell::GetActiveUserPrefService() const {
428 if (shell_port_->GetAshConfig() == Config::MASH)
James Cookbbe5cb12017-08-08 18:32:21429 return profile_pref_service_mash_.get();
James Cook6d51c9182017-08-04 01:31:00430
431 return shell_delegate_->GetActiveUserPrefService();
432}
433
Wenzhao Zang44240fb2017-07-13 01:36:54434PrefService* Shell::GetLocalStatePrefService() const {
Sam McNallye36abbc2017-07-20 01:04:28435 if (shell_port_->GetAshConfig() == Config::MASH)
James Cookbbe5cb12017-08-08 18:32:21436 return local_state_mash_.get();
Sam McNallye36abbc2017-07-20 01:04:28437
James Cookbbe5cb12017-08-08 18:32:21438 return local_state_non_mash_;
Wenzhao Zang44240fb2017-07-13 01:36:54439}
440
[email protected]88d71122012-10-18 07:11:01441WebNotificationTray* Shell::GetWebNotificationTray() {
jamescook612205f2016-05-26 06:02:11442 return GetPrimaryRootWindowController()
jamescookb551aba2016-09-01 01:00:16443 ->GetStatusAreaWidget()
jamescook612205f2016-05-26 06:02:11444 ->web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28445}
446
[email protected]a0afeb12012-12-10 22:57:09447bool Shell::HasPrimaryStatusArea() {
jamescookb551aba2016-09-01 01:00:16448 return !!GetPrimaryRootWindowController()->GetStatusAreaWidget();
[email protected]31f19e32012-10-30 22:31:23449}
450
[email protected]a0afeb12012-12-10 22:57:09451SystemTray* Shell::GetPrimarySystemTray() {
452 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42453}
454
[email protected]2b8a9bb2013-07-01 22:43:40455void Shell::SetTouchHudProjectionEnabled(bool enabled) {
456 if (is_touch_hud_projection_enabled_ == enabled)
457 return;
458
[email protected]2b8a9bb2013-07-01 22:43:40459 is_touch_hud_projection_enabled_ = enabled;
sky00c813f2017-03-08 22:48:55460 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18461 observer.OnTouchHudProjectionToggled(enabled);
[email protected]2b8a9bb2013-07-01 22:43:40462}
463
mswa7e8a5f2016-03-01 04:15:06464FirstRunHelper* Shell::CreateFirstRunHelper() {
465 return new FirstRunHelperImpl;
[email protected]59ccade2013-10-17 17:56:40466}
[email protected]87ec2202014-02-06 06:24:27467
yawanodc5533b32017-02-23 11:04:38468void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
469 window_tree_host_manager_->cursor_window_controller()
470 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
471}
472
[email protected]87ec2202014-02-06 06:24:27473void Shell::SetCursorCompositingEnabled(bool enabled) {
erg36cfb952017-06-21 19:41:45474 if (GetAshConfig() != Config::MASH) {
475 // TODO: needs to work in mash. http://crbug.com/705592.
sky494c6cbd2017-03-27 20:57:48476 window_tree_host_manager_->cursor_window_controller()
477 ->SetCursorCompositingEnabled(enabled);
478 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
479 }
[email protected]87ec2202014-02-06 06:24:27480}
[email protected]59ccade2013-10-17 17:56:40481
[email protected]f9466702012-09-17 16:35:27482void Shell::DoInitialWorkspaceAnimation() {
jamescookb8dcef522016-06-25 14:42:55483 return GetPrimaryRootWindowController()
484 ->workspace_controller()
485 ->DoInitialAnimation();
[email protected]f9466702012-09-17 16:35:27486}
487
xdaid4913762017-07-06 00:17:22488bool Shell::IsSplitViewModeActive() const {
489 return split_view_controller_->IsSplitViewModeActive();
490}
491
sky00c813f2017-03-08 22:48:55492void Shell::AddShellObserver(ShellObserver* observer) {
493 shell_observers_.AddObserver(observer);
494}
495
496void Shell::RemoveShellObserver(ShellObserver* observer) {
497 shell_observers_.RemoveObserver(observer);
498}
499
Alex Newcomer8fdcb9342017-08-08 18:48:44500void Shell::ShowAppList(app_list::AppListShowSource toggle_method) {
501 if (IsAppListVisible()) {
502 UMA_HISTOGRAM_ENUMERATION(app_list::kAppListToggleMethodHistogram,
503 toggle_method, app_list::kMaxAppListToggleMethod);
504 }
sky7db5ccf2017-03-14 21:52:29505 // Show the app list on the default display for new windows.
mswad3d9552017-05-18 21:23:36506 app_list_->Show(display::Screen::GetScreen()
507 ->GetDisplayNearestWindow(GetRootWindowForNewWindows())
508 .id());
sky7db5ccf2017-03-14 21:52:29509}
510
MinCheneafaa52e2017-07-31 18:32:52511void Shell::UpdateAppListYPositionAndOpacity(int y_position_in_screen,
512 float app_list_background_opacity,
513 bool is_end_gesture) {
514 app_list_->UpdateYPositionAndOpacity(
515 y_position_in_screen, app_list_background_opacity, is_end_gesture);
MinChend646ae02017-07-21 23:07:17516}
517
sky7db5ccf2017-03-14 21:52:29518void Shell::DismissAppList() {
519 app_list_->Dismiss();
520}
521
Alex Newcomer8fdcb9342017-08-08 18:48:44522void Shell::ToggleAppList(app_list::AppListShowSource toggle_method) {
523 if (IsAppListVisible()) {
524 UMA_HISTOGRAM_ENUMERATION(app_list::kAppListToggleMethodHistogram,
525 toggle_method, app_list::kMaxAppListToggleMethod);
526 }
sky7db5ccf2017-03-14 21:52:29527 // Toggle the app list on the default display for new windows.
528 app_list_->ToggleAppList(
mswad3d9552017-05-18 21:23:36529 display::Screen::GetScreen()
530 ->GetDisplayNearestWindow(GetRootWindowForNewWindows())
531 .id());
sky7db5ccf2017-03-14 21:52:29532}
533
534bool Shell::IsAppListVisible() const {
535 return app_list_->IsVisible();
536}
537
538bool Shell::GetAppListTargetVisibility() const {
539 return app_list_->GetTargetVisibility();
540}
541
sky5ad143a2017-03-22 04:31:23542void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
varkha59679632017-06-01 00:42:05543 for (auto* root_window_controller : GetAllRootWindowControllers())
544 root_window_controller->UpdateAfterLoginStatusChange(status);
sky5ad143a2017-03-22 04:31:23545}
546
sky00c813f2017-03-08 22:48:55547void Shell::NotifyOverviewModeStarting() {
548 for (auto& observer : shell_observers_)
549 observer.OnOverviewModeStarting();
550}
551
552void Shell::NotifyOverviewModeEnded() {
553 for (auto& observer : shell_observers_)
554 observer.OnOverviewModeEnded();
555}
556
xdaid4913762017-07-06 00:17:22557void Shell::NotifySplitViewModeStarting() {
558 for (auto& observer : shell_observers_)
559 observer.OnSplitViewModeStarting();
560}
561
562void Shell::NotifySplitViewModeEnded() {
563 for (auto& observer : shell_observers_)
564 observer.OnSplitViewModeEnded();
565}
566
sky00c813f2017-03-08 22:48:55567void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
varkhac71444e52017-05-25 22:51:34568 aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55569 for (auto& observer : shell_observers_)
570 observer.OnFullscreenStateChanged(is_fullscreen, root_window);
571}
572
varkha19d7e6c52017-05-25 21:15:30573void Shell::NotifyPinnedStateChanged(aura::Window* pinned_window) {
sky00c813f2017-03-08 22:48:55574 for (auto& observer : shell_observers_)
575 observer.OnPinnedStateChanged(pinned_window);
576}
577
xiyuan38160182017-03-14 22:50:13578void Shell::NotifyVirtualKeyboardActivated(bool activated,
sky97f9a7432017-05-09 05:14:31579 aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55580 for (auto& observer : shell_observers_)
xiyuan38160182017-03-14 22:50:13581 observer.OnVirtualKeyboardStateChanged(activated, root_window);
sky00c813f2017-03-08 22:48:55582}
583
varkha6b016b0f2017-05-26 16:14:18584void Shell::NotifyShelfCreatedForRootWindow(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55585 for (auto& observer : shell_observers_)
586 observer.OnShelfCreatedForRootWindow(root_window);
587}
588
varkha6b016b0f2017-05-26 16:14:18589void Shell::NotifyShelfAlignmentChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55590 for (auto& observer : shell_observers_)
591 observer.OnShelfAlignmentChanged(root_window);
592}
593
varkha6b016b0f2017-05-26 16:14:18594void Shell::NotifyShelfAutoHideBehaviorChanged(aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55595 for (auto& observer : shell_observers_)
596 observer.OnShelfAutoHideBehaviorChanged(root_window);
597}
598
jamescook518dccbd2017-05-18 04:57:07599// static
600void Shell::SetIsBrowserProcessWithMash() {
601 g_is_browser_process_with_mash = true;
602}
603
James Cookbbe5cb12017-08-08 18:32:21604void Shell::SetLocalStatePrefService(PrefService* local_state) {
605 DCHECK(GetAshConfig() != Config::MASH);
606 DCHECK(local_state);
607 local_state_non_mash_ = local_state;
608
609 for (auto& observer : shell_observers_)
610 observer.OnLocalStatePrefServiceInitialized(local_state_non_mash_);
611}
612
muyuanlid766f2e2017-06-26 20:17:19613void Shell::NotifyAppListVisibilityChanged(bool visible,
614 aura::Window* root_window) {
newcomer2febb9832017-06-12 17:00:23615 for (auto& observer : shell_observers_)
616 observer.OnAppListVisibilityChanged(visible, root_window);
617}
618
muyuanlid766f2e2017-06-26 20:17:19619void Shell::NotifyVoiceInteractionStatusChanged(bool running) {
620 for (auto& observer : shell_observers_)
621 observer.OnVoiceInteractionStatusChanged(running);
622}
623
[email protected]b6ba05d902013-10-04 21:38:45624////////////////////////////////////////////////////////////////////////////////
625// Shell, private:
626
skyb073203a2017-03-13 16:59:16627Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
sky11cf8db92017-04-10 23:38:08628 std::unique_ptr<ShellPort> shell_port)
629 : shell_port_(std::move(shell_port)),
Scott Violetd64dac12017-06-02 21:50:08630 ash_display_controller_(base::MakeUnique<AshDisplayController>()),
sky79fa34712017-03-20 23:46:47631 brightness_control_delegate_(
632 base::MakeUnique<system::BrightnessControllerChromeos>()),
633 cast_config_(base::MakeUnique<CastConfigController>()),
634 focus_cycler_(base::MakeUnique<FocusCycler>()),
James Cookf0c78fc2017-06-15 14:42:55635 ime_controller_(base::MakeUnique<ImeController>()),
sky5ab16472017-03-21 19:35:08636 immersive_context_(base::MakeUnique<ImmersiveContextAsh>()),
sky79fa34712017-03-20 23:46:47637 keyboard_brightness_control_delegate_(
638 base::MakeUnique<KeyboardBrightnessController>()),
639 locale_notification_controller_(
640 base::MakeUnique<LocaleNotificationController>()),
xiaoyinh2bbdd102017-05-18 23:29:42641 lock_screen_controller_(base::MakeUnique<LockScreenController>()),
sky5ab16472017-03-21 19:35:08642 media_controller_(base::MakeUnique<MediaController>()),
643 new_window_controller_(base::MakeUnique<NewWindowController>()),
sky5ad143a2017-03-22 04:31:23644 session_controller_(base::MakeUnique<SessionController>()),
645 shelf_controller_(base::MakeUnique<ShelfController>()),
skyb073203a2017-03-13 16:59:16646 shell_delegate_(std::move(shell_delegate)),
sky5b45ed82017-03-27 02:54:23647 shutdown_controller_(base::MakeUnique<ShutdownController>()),
sky79fa34712017-03-20 23:46:47648 system_tray_controller_(base::MakeUnique<SystemTrayController>()),
sky5b45ed82017-03-27 02:54:23649 system_tray_notifier_(base::MakeUnique<SystemTrayNotifier>()),
tbarzicc78da1ff92017-05-08 20:46:15650 tray_action_(base::MakeUnique<TrayAction>()),
sky5b45ed82017-03-27 02:54:23651 vpn_list_(base::MakeUnique<VpnList>()),
652 window_cycle_controller_(base::MakeUnique<WindowCycleController>()),
653 window_selector_controller_(base::MakeUnique<WindowSelectorController>()),
sky7db5ccf2017-03-14 21:52:29654 app_list_(base::MakeUnique<app_list::AppList>()),
yusukes1168eda2016-04-27 07:52:08655 link_handler_model_factory_(nullptr),
jamescookac6724332017-03-21 02:54:43656 tray_bluetooth_helper_(base::MakeUnique<TrayBluetoothHelper>()),
kylechar7a067ec2017-01-07 01:16:28657 display_configurator_(new display::DisplayConfigurator()),
sadrul7a8785e2016-02-12 21:54:35658 native_cursor_manager_(nullptr),
[email protected]b6ba05d902013-10-04 21:38:45659 simulate_modal_window_open_for_testing_(false),
Sam McNallye36abbc2017-07-20 01:04:28660 is_touch_hud_projection_enabled_(false),
661 weak_factory_(this) {
skyabcae812017-01-18 17:01:34662 // TODO(sky): better refactor cash/mash dependencies. Perhaps put all cash
sky11cf8db92017-04-10 23:38:08663 // state on ShellPortClassic. http://crbug.com/671246.
skyabcae812017-01-18 17:01:34664
skycfaad892017-04-28 20:52:58665 gpu_support_.reset(shell_delegate_->CreateGPUSupport());
666
Scott Violet596bb46342017-06-21 14:43:13667 display_manager_.reset(ScreenAsh::CreateDisplayManager());
668 window_tree_host_manager_ = base::MakeUnique<WindowTreeHostManager>();
669 user_metrics_recorder_ = base::MakeUnique<UserMetricsRecorder>();
[email protected]b6ba05d902013-10-04 21:38:45670
[email protected]093b8d642014-04-03 20:59:28671 PowerStatus::Initialize();
sky5ad143a2017-03-22 04:31:23672
Xiyuan Xia22b1a6c2017-04-18 22:46:01673 session_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45674}
675
676Shell::~Shell() {
677 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
678
sky11cf8db92017-04-10 23:38:08679 const Config config = shell_port_->GetAshConfig();
skyabcae812017-01-18 17:01:34680
Scott Violet41562d1c2017-06-26 15:15:48681 user_metrics_recorder_->OnShellShuttingDown();
bruthigc24d11f2015-06-09 21:30:03682
skyb073203a2017-03-13 16:59:16683 shell_delegate_->PreShutdown();
[email protected]050e77182014-03-25 15:29:16684
[email protected]b6ba05d902013-10-04 21:38:45685 // Remove the focus from any window. This will prevent overhead and side
686 // effects (e.g. crashes) from changing focus during shutdown.
687 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18688 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45689
xdaid4913762017-07-06 00:17:22690 // Please keep in reverse order as in Init() because it's easy to miss one.
691 split_view_controller_.reset();
692
[email protected]b6ba05d902013-10-04 21:38:45693 if (window_modality_controller_)
694 window_modality_controller_.reset();
jamescook01bf23e72017-01-09 19:58:15695
[email protected]e4ea52362014-02-15 03:21:06696 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
697 magnifier_key_scroll_handler_.reset();
698
699 RemovePreTargetHandler(speech_feedback_handler_.get());
700 speech_feedback_handler_.reset();
jamescook01bf23e72017-01-09 19:58:15701
[email protected]b6ba05d902013-10-04 21:38:45702 RemovePreTargetHandler(overlay_filter_.get());
Xiyuan Xia22b1a6c2017-04-18 22:46:01703 overlay_filter_.reset();
704
[email protected]3537d472014-01-15 05:45:31705 RemovePreTargetHandler(accelerator_filter_.get());
706 RemovePreTargetHandler(event_transformation_handler_.get());
707 RemovePreTargetHandler(toplevel_window_event_handler_.get());
708 RemovePostTargetHandler(toplevel_window_event_handler_.get());
Scott Violet596bb46342017-06-21 14:43:13709 RemovePreTargetHandler(system_gesture_filter_.get());
710 RemovePreTargetHandler(mouse_cursor_filter_.get());
hariank0dd03dd2016-07-14 23:47:33711 RemovePreTargetHandler(modality_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45712
713 // TooltipController is deleted with the Shell so removing its references.
714 RemovePreTargetHandler(tooltip_controller_.get());
715
jonross0af45212015-01-13 18:55:46716 screen_orientation_controller_.reset();
yiyixa68ade512016-09-01 17:38:13717 screen_layout_observer_.reset();
jonross0af45212015-01-13 18:55:46718
Mitsuru Oshima0e9b7a62017-07-19 18:23:03719 // Destroy the virtual keyboard controller before the tablet mode controller
jamescook01bf23e72017-01-09 19:58:15720 // since the latters destructor triggers events that the former is listening
721 // to but no longer cares about.
rsadambbaf2c82015-01-07 17:54:13722 virtual_keyboard_controller_.reset();
jonross0af45212015-01-13 18:55:46723
Mitsuru Oshima0e9b7a62017-07-19 18:23:03724 // Destroy tablet mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57725 // need to be removed.
Mitsuru Oshima0e9b7a62017-07-19 18:23:03726 tablet_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57727
jdufault551152e2016-01-27 19:48:43728 // Destroy the keyboard before closing the shelf, since it will invoke a shelf
729 // layout.
Keigo Okac7617a42017-06-14 11:33:24730 DestroyKeyboard();
jdufault551152e2016-01-27 19:48:43731
sky07a24d42017-03-09 23:57:30732 toast_manager_.reset();
yoshiki32f51632016-03-24 01:24:43733
jdufault551152e2016-01-27 19:48:43734 // Destroy SystemTrayDelegate before destroying the status area(s). Make sure
735 // to deinitialize the shelf first, as it is initialized after the delegate.
msw257a6a232017-06-01 01:46:30736 for (aura::Window* root : GetAllRootWindows())
737 Shelf::ForWindow(root)->ShutdownShelfWidget();
jamescookac6724332017-03-21 02:54:43738 tray_bluetooth_helper_.reset();
sky79fa34712017-03-20 23:46:47739 DeleteSystemTrayDelegate();
[email protected]b6ba05d902013-10-04 21:38:45740
[email protected]b6ba05d902013-10-04 21:38:45741 // Drag-and-drop must be canceled prior to close all windows.
742 drag_drop_controller_.reset();
743
Xiyuan Xia22b1a6c2017-04-18 22:46:01744 // Controllers who have WindowObserver added must be deleted
745 // before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03746
[email protected]8c9d12a2013-12-06 18:39:03747 // VideoActivityNotifier must be deleted before |video_detector_| is
748 // deleted because it's observing video activity through
derat83b761392016-07-11 16:44:44749 // VideoDetector::Observer interface.
[email protected]8c9d12a2013-12-06 18:39:03750 video_activity_notifier_.reset();
[email protected]8c9d12a2013-12-06 18:39:03751 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25752 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03753
754 shadow_controller_.reset();
755 resize_shadow_controller_.reset();
756
sky37f0dd12016-07-19 18:00:59757 // Has to happen before ~MruWindowTracker.
sky5b45ed82017-03-27 02:54:23758 window_cycle_controller_.reset();
759 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03760
skyabcae812017-01-18 17:01:34761 CloseAllRootWindowChildWindows();
762
afakhry58159392015-05-22 02:45:52763 // MruWindowTracker must be destroyed after all windows have been deleted to
764 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
765 // path. (crbug.com/485438).
sky5ab16472017-03-21 19:35:08766 mru_window_tracker_.reset();
[email protected]b6ba05d902013-10-04 21:38:45767
[email protected]b6ba05d902013-10-04 21:38:45768 // These need a valid Shell instance to clean up properly, so explicitly
769 // delete them before invalidating the instance.
770 // Alphabetical. TODO(oshima): sort.
771 magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45772 tooltip_controller_.reset();
773 event_client_.reset();
[email protected]3537d472014-01-15 05:45:31774 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45775 visibility_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45776
777 power_button_controller_.reset();
778 lock_state_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45779
hidehiko6821ca42016-06-18 11:12:23780 screen_pinning_controller_.reset();
781
[email protected]b6ba05d902013-10-04 21:38:45782 resolution_notification_controller_.reset();
oshima5a296e82016-04-29 01:32:27783 screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49784 mouse_cursor_filter_.reset();
hariank0dd03dd2016-07-14 23:47:33785 modality_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45786
[email protected]03122891a2014-05-13 23:56:49787 touch_transformer_controller_.reset();
warx533c8f62016-04-12 01:19:43788 audio_a11y_controller_.reset();
sammiequon203ae022016-09-18 17:23:42789 laser_pointer_controller_.reset();
790 partial_magnification_controller_.reset();
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:32791 highlighter_controller_.reset();
warx533c8f62016-04-12 01:19:43792
[email protected]b6ba05d902013-10-04 21:38:45793 // This also deletes all RootWindows. Note that we invoke Shutdown() on
oshimae2818922015-07-28 01:18:52794 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
msw257a6a232017-06-01 01:46:30795 // destruction of its owned RootWindowControllers relies on the value.
rjkroege2c9305402016-09-07 00:21:45796 ScreenAsh::CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12797 display_configuration_controller_.reset();
dtseng4ae0a882016-04-15 21:39:27798
sky15ef0aa2017-01-20 18:55:59799 // AppListDelegateImpl depends upon AppList.
800 app_list_delegate_impl_.reset();
801
sky07a24d42017-03-09 23:57:30802 // These members access Shell in their destructors.
803 wallpaper_controller_.reset();
804 accessibility_delegate_.reset();
805
806 // Balances the Install() in Initialize().
807 views::FocusManagerFactory::Install(nullptr);
808
sky5ad143a2017-03-22 04:31:23809 // ShelfWindowWatcher has window observers and a pointer to the shelf model.
810 shelf_window_watcher_.reset();
811
812 // ShelfItemDelegate subclasses it owns have complex cleanup to run (e.g. ARC
813 // shelf items in Chrome) so explicitly shutdown early.
814 shelf_model()->DestroyItemDelegates();
815
msw5138f3d2017-04-20 00:22:07816 // Notify the ShellDelegate that the shelf is shutting down.
msw5c06364c2017-04-27 02:49:06817 // TODO(msw): Refine ChromeLauncherController lifetime management.
msw5138f3d2017-04-20 00:22:07818 shell_delegate_->ShelfShutdown();
sky5ad143a2017-03-22 04:31:23819
tibellb93c729b2017-03-30 00:45:09820 // Removes itself as an observer of |pref_service_|.
sky5ad143a2017-03-22 04:31:23821 shelf_controller_.reset();
822
sky11cf8db92017-04-10 23:38:08823 shell_port_->Shutdown();
Scott Violet596bb46342017-06-21 14:43:13824 window_tree_host_manager_->Shutdown();
sky5ad143a2017-03-22 04:31:23825
sky27344382017-03-08 21:30:32826 // Depends on |focus_controller_|, so must be destroyed before.
oshimae2818922015-07-28 01:18:52827 window_tree_host_manager_.reset();
sky27344382017-03-08 21:30:32828 focus_controller_->RemoveObserver(this);
sky68612712017-04-27 04:45:04829 if (config != Config::CLASSIC &&
830 window_tree_client_->focus_synchronizer()->active_focus_client() ==
831 focus_controller_.get()) {
832 window_tree_client_->focus_synchronizer()->SetSingletonFocusClient(nullptr);
833 }
sky27344382017-03-08 21:30:32834 focus_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45835 screen_position_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45836
robert.bradfordab052492015-05-06 11:09:56837 display_color_manager_.reset();
[email protected]7bc49bd2014-01-22 09:30:34838 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11839 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45840 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11841 display_configurator_->RemoveObserver(display_error_observer_.get());
jdufault88fb76652015-04-30 22:36:43842 if (projecting_observer_) {
[email protected]1e31cbd2014-04-07 20:06:11843 display_configurator_->RemoveObserver(projecting_observer_.get());
sky00c813f2017-03-08 22:48:55844 RemoveShellObserver(projecting_observer_.get());
jdufault88fb76652015-04-30 22:36:43845 }
[email protected]b6ba05d902013-10-04 21:38:45846 display_change_observer_.reset();
kylechar98748a52016-12-03 01:33:22847 shutdown_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45848
[email protected]093b8d642014-04-03 20:59:28849 PowerStatus::Shutdown();
pneubeck8be1f5422014-10-09 16:46:18850
851 // Ensure that DBusThreadManager outlives this Shell.
852 DCHECK(chromeos::DBusThreadManager::IsInitialized());
[email protected]b6ba05d902013-10-04 21:38:45853
sky88bd4be62016-06-09 17:34:41854 // Needs to happen right before |instance_| is reset.
sky11cf8db92017-04-10 23:38:08855 shell_port_.reset();
Xiyuan Xia22b1a6c2017-04-18 22:46:01856 session_controller_->RemoveObserver(this);
skyb073203a2017-03-13 16:59:16857 wallpaper_delegate_.reset();
afakhry21501562017-05-19 22:52:40858 // NightLightController depeneds on the PrefService and must be destructed
859 // before it. crbug.com/724231.
860 night_light_controller_ = nullptr;
James Cookbbe5cb12017-08-08 18:32:21861 profile_pref_service_mash_.reset();
862 local_state_mash_.reset();
863 local_state_non_mash_ = nullptr;
skyb073203a2017-03-13 16:59:16864 shell_delegate_.reset();
sky88bd4be62016-06-09 17:34:41865
Scott Violet17a61722017-06-19 17:54:31866 for (auto& observer : shell_observers_)
867 observer.OnShellDestroyed();
868
[email protected]b6ba05d902013-10-04 21:38:45869 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18870 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45871}
872
[email protected]1b4c7472014-05-15 18:32:23873void Shell::Init(const ShellInitParams& init_params) {
sky11cf8db92017-04-10 23:38:08874 const Config config = shell_port_->GetAshConfig();
skyabcae812017-01-18 17:01:34875
James Cook8532dbc2017-07-31 21:54:51876 if (NightLightController::IsFeatureEnabled())
877 night_light_controller_ = base::MakeUnique<NightLightController>();
afakhry9e0a18b32017-06-05 19:23:14878
skyb073203a2017-03-13 16:59:16879 wallpaper_delegate_ = shell_delegate_->CreateWallpaperDelegate();
880
James Cook8532dbc2017-07-31 21:54:51881 // Connector can be null in tests.
skye5fd1222017-04-12 18:43:23882 if (config == Config::MASH && shell_delegate_->GetShellConnector()) {
James Cook8532dbc2017-07-31 21:54:51883 // Connect to local state prefs now, but wait for an active user before
884 // connecting to the profile pref service. The login screen has a temporary
885 // user profile that is not associated with a real user.
Taiju Tsuiki36c517d2017-05-18 06:45:43886 auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
Wenzhao Zang56c292932017-08-02 04:58:34887 RegisterLocalStatePrefs(pref_registry.get());
tibellb93c729b2017-03-30 00:45:09888 prefs::ConnectToPrefService(
Sam McNally538fca1e2017-07-14 03:10:43889 shell_delegate_->GetShellConnector(), std::move(pref_registry),
Sam McNallye36abbc2017-07-20 01:04:28890 base::Bind(&Shell::OnLocalStatePrefServiceInitialized,
891 weak_factory_.GetWeakPtr()),
892 prefs::mojom::kLocalStateServiceName);
jonrossc4ba10602017-04-07 20:51:05893 }
skyb073203a2017-03-13 16:59:16894
sky11cf8db92017-04-10 23:38:08895 // Some delegates access ShellPort during their construction. Create them here
896 // instead of the ShellPort constructor.
skyb073203a2017-03-13 16:59:16897 accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate());
898 palette_delegate_ = shell_delegate_->CreatePaletteDelegate();
sky07a24d42017-03-09 23:57:30899 toast_manager_ = base::MakeUnique<ToastManager>();
900
sky07a24d42017-03-09 23:57:30901 // Install the custom factory early on so that views::FocusManagers for Tray,
902 // Shelf, and WallPaper could be created by the factory.
903 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
904
James Cook08fc8ce22017-06-15 18:28:41905 wallpaper_controller_ = base::MakeUnique<WallpaperController>();
sky07a24d42017-03-09 23:57:30906
skye5fd1222017-04-12 18:43:23907 if (config == Config::MASH)
sky15ef0aa2017-01-20 18:55:59908 app_list_delegate_impl_ = base::MakeUnique<AppListDelegateImpl>();
909
sky11cf8db92017-04-10 23:38:08910 // TODO(sky): move creation to ShellPort.
skye5fd1222017-04-12 18:43:23911 if (config != Config::MASH)
skyabcae812017-01-18 17:01:34912 immersive_handler_factory_ = base::MakeUnique<ImmersiveHandlerFactoryAsh>();
skyb7b54092016-08-19 16:00:09913
sky5ab16472017-03-21 19:35:08914 window_positioner_ = base::MakeUnique<WindowPositioner>();
sky984c1892016-04-20 00:00:34915
sky494c6cbd2017-03-27 20:57:48916 if (config == Config::CLASSIC) {
erg36cfb952017-06-21 19:41:45917 native_cursor_manager_ = new NativeCursorManagerAshClassic;
918 cursor_manager_ = base::MakeUnique<CursorManager>(
919 base::WrapUnique(native_cursor_manager_));
920 } else if (config == Config::MUS) {
921 native_cursor_manager_ = new NativeCursorManagerAshMus;
922 cursor_manager_ = base::MakeUnique<CursorManager>(
923 base::WrapUnique(native_cursor_manager_));
skyabcae812017-01-18 17:01:34924 }
skyfee520c2016-02-11 19:57:46925
skyb073203a2017-03-13 16:59:16926 shell_delegate_->PreInit();
Scott Violet596bb46342017-06-21 14:43:13927 bool display_initialized = display_manager_->InitFromCommandLine();
928 if (!display_initialized && config != Config::CLASSIC) {
skycfaad892017-04-28 20:52:58929 // Run display configuration off device in mus mode.
930 display_manager_->set_configure_displays(true);
931 display_configurator_->set_configure_display(true);
932 }
Scott Violet596bb46342017-06-21 14:43:13933 display_configuration_controller_ =
934 base::MakeUnique<DisplayConfigurationController>(
935 display_manager_.get(), window_tree_host_manager_.get());
936 display_configurator_->Init(shell_port_->CreateNativeDisplayDelegate(),
937 !gpu_support_->IsPanelFittingDisabled());
[email protected]0249a6532013-10-31 06:53:34938
pneubeck8be1f5422014-10-09 16:46:18939 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell.
940 chromeos::DBusThreadManager* dbus_thread_manager =
941 chromeos::DBusThreadManager::Get();
942 projecting_observer_.reset(
943 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient()));
[email protected]1e31cbd2014-04-07 20:06:11944 display_configurator_->AddObserver(projecting_observer_.get());
sky00c813f2017-03-08 22:48:55945 AddShellObserver(projecting_observer_.get());
[email protected]72bce522014-02-10 21:11:26946
Scott Violet596bb46342017-06-21 14:43:13947 if (!display_initialized &&
948 (config != Config::CLASSIC || chromeos::IsRunningAsSystemCompositor())) {
kylecharf2e4e412016-12-04 04:21:35949 display_change_observer_ = base::MakeUnique<display::DisplayChangeObserver>(
kylechar98748a52016-12-03 01:33:22950 display_configurator_.get(), display_manager_.get());
951
952 shutdown_observer_ =
953 base::MakeUnique<ShutdownObserver>(display_configurator_.get());
954
[email protected]b6ba05d902013-10-04 21:38:45955 // Register |display_change_observer_| first so that the rest of
956 // observer gets invoked after the root windows are configured.
[email protected]1e31cbd2014-04-07 20:06:11957 display_configurator_->AddObserver(display_change_observer_.get());
[email protected]093b8d642014-04-03 20:59:28958 display_error_observer_.reset(new DisplayErrorObserver());
[email protected]1e31cbd2014-04-07 20:06:11959 display_configurator_->AddObserver(display_error_observer_.get());
960 display_configurator_->set_state_controller(display_change_observer_.get());
961 display_configurator_->set_mirroring_controller(display_manager_.get());
962 display_configurator_->ForceInitialConfigure(
jamescookfda159002016-10-21 18:48:57963 base::CommandLine::ForCurrentProcess()->HasSwitch(
964 chromeos::switches::kFirstExecAfterBoot)
965 ? kChromeOsBootColor
966 : 0);
[email protected]b6ba05d902013-10-04 21:38:45967 display_initialized = true;
968 }
James Cook8ba362c2017-06-16 16:39:16969 display_color_manager_ =
970 base::MakeUnique<DisplayColorManager>(display_configurator_.get());
stevenjb537c5c3f2016-01-20 23:38:12971
[email protected]b6ba05d902013-10-04 21:38:45972 if (!display_initialized)
[email protected]0249a6532013-10-31 06:53:34973 display_manager_->InitDefaultDisplay();
[email protected]b6ba05d902013-10-04 21:38:45974
newcomer2febb9832017-06-12 17:00:23975 if (config == Config::CLASSIC) {
skyabcae812017-01-18 17:01:34976 display_manager_->RefreshFontParams();
[email protected]68d6080e2014-08-21 23:06:32977
skyabcae812017-01-18 17:01:34978 aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
979 aura::Env::GetInstance()->set_context_factory_private(
980 init_params.context_factory_private);
981 }
[email protected]ecca62b2013-10-09 16:18:53982
[email protected]b6ba05d902013-10-04 21:38:45983 // The WindowModalityController needs to be at the front of the input event
984 // pretarget handler list to ensure that it processes input events when modal
985 // windows are active.
jamescookb8dcef522016-06-25 14:42:55986 window_modality_controller_.reset(new ::wm::WindowModalityController(this));
[email protected]b6ba05d902013-10-04 21:38:45987
[email protected]e319c7e2014-03-14 19:56:14988 env_filter_.reset(new ::wm::CompoundEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45989 AddPreTargetHandler(env_filter_.get());
990
sky27344382017-03-08 21:30:32991 // FocusController takes ownership of AshFocusRules.
992 focus_controller_ =
993 base::MakeUnique<::wm::FocusController>(new wm::AshFocusRules());
994 focus_controller_->AddObserver(this);
sky68612712017-04-27 04:45:04995 if (config != Config::CLASSIC) {
996 window_tree_client_->focus_synchronizer()->SetSingletonFocusClient(
997 focus_controller_.get());
998 }
[email protected]b6ba05d902013-10-04 21:38:45999
[email protected]093b8d642014-04-03 20:59:281000 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:451001
Scott Violet596bb46342017-06-21 14:43:131002 window_tree_host_manager_->Start();
1003 AshWindowTreeHostInitParams ash_init_params;
1004 window_tree_host_manager_->CreatePrimaryHost(ash_init_params);
1005
mswad3d9552017-05-18 21:23:361006 root_window_for_new_windows_ = GetPrimaryRootWindow();
[email protected]b6ba05d902013-10-04 21:38:451007
Scott Violet596bb46342017-06-21 14:43:131008 resolution_notification_controller_ =
1009 base::MakeUnique<ResolutionNotificationController>();
[email protected]b6ba05d902013-10-04 21:38:451010
deratc6250a02017-01-25 05:51:531011 if (cursor_manager_) {
oshimaf84b0da722016-04-27 19:47:191012 cursor_manager_->SetDisplay(
1013 display::Screen::GetScreen()->GetPrimaryDisplay());
deratc6250a02017-01-25 05:51:531014 }
[email protected]b6ba05d902013-10-04 21:38:451015
sky11cf8db92017-04-10 23:38:081016 accelerator_controller_ = shell_port_->CreateAcceleratorController();
Mitsuru Oshima0e9b7a62017-07-19 18:23:031017 tablet_mode_controller_ = base::MakeUnique<TabletModeController>();
[email protected]b6ba05d902013-10-04 21:38:451018
spange9b51272014-12-11 01:20:101019 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:061020 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
spange9b51272014-12-11 01:20:101021 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:061022 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:391023
[email protected]b6ba05d902013-10-04 21:38:451024 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:451025
derat2d4e62d2015-01-09 16:09:171026 // ui::UserActivityDetector passes events to observers, so let them get
[email protected]b6ba05d902013-10-04 21:38:451027 // rewritten first.
derat2d4e62d2015-01-09 16:09:171028 user_activity_detector_.reset(new ui::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:451029
[email protected]093b8d642014-04-03 20:59:281030 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:451031 AddPreTargetHandler(overlay_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:451032
[email protected]60d677d2014-05-30 13:07:021033 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
dchenga94547472016-04-08 08:41:111034 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
sky81a2d792017-03-17 19:14:391035 accelerator_controller_->accelerator_history()));
[email protected]b6ba05d902013-10-04 21:38:451036 AddPreTargetHandler(accelerator_filter_.get());
1037
[email protected]093b8d642014-04-03 20:59:281038 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:451039 AddPreTargetHandler(event_transformation_handler_.get());
1040
sky11cf8db92017-04-10 23:38:081041 toplevel_window_event_handler_ =
1042 base::MakeUnique<ToplevelWindowEventHandler>();
[email protected]3537d472014-01-15 05:45:311043
sky83b1bb12017-04-24 20:29:281044 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:341045 system_gesture_filter_.reset(new SystemGestureEventFilter);
1046 AddPreTargetHandler(system_gesture_filter_.get());
1047 }
[email protected]b6ba05d902013-10-04 21:38:451048
[email protected]354520b2014-06-21 04:31:011049 sticky_keys_controller_.reset(new StickyKeysController);
sky13857152017-03-29 15:46:041050 screen_pinning_controller_ = base::MakeUnique<ScreenPinningController>();
[email protected]354520b2014-06-21 04:31:011051
jamescookd9f152f2016-11-15 00:53:081052 lock_state_controller_ =
sky5b45ed82017-03-27 02:54:231053 base::MakeUnique<LockStateController>(shutdown_controller_.get());
jamescookb8dcef522016-06-25 14:42:551054 power_button_controller_.reset(
1055 new PowerButtonController(lock_state_controller_.get()));
[email protected]685442f32014-02-28 10:40:061056 // Pass the initial display state to PowerButtonController.
1057 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:091058 display_configurator_->cached_displays());
jamescook01bf23e72017-01-09 19:58:151059
derat036f91b92017-05-05 00:33:181060 // Forward user activity from the window server to |user_activity_detector_|.
derat94887a22017-01-20 18:17:251061 // The connector is unavailable in some tests.
derat036f91b92017-05-05 00:33:181062 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS &&
1063 shell_delegate_->GetShellConnector()) {
derat94887a22017-01-20 18:17:251064 ui::mojom::UserActivityMonitorPtr user_activity_monitor;
skyb073203a2017-03-13 16:59:161065 shell_delegate_->GetShellConnector()->BindInterface(ui::mojom::kServiceName,
1066 &user_activity_monitor);
derat94887a22017-01-20 18:17:251067 user_activity_forwarder_ = base::MakeUnique<aura::UserActivityForwarder>(
1068 std::move(user_activity_monitor), user_activity_detector_.get());
1069 }
1070
Scott Violet361833fb2017-06-21 22:25:201071 // In mash drag and drop is handled by mus.
1072 if (config != Config::MASH)
1073 drag_drop_controller_ = base::MakeUnique<DragDropController>();
1074
oshima5a296e82016-04-29 01:32:271075 // |screenshot_controller_| needs to be created (and prepended as a
mukai19274bdd2015-02-24 22:37:481076 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
oshima5a296e82016-04-29 01:32:271077 // process mouse events prior to screenshot session.
mukai19274bdd2015-02-24 22:37:481078 // See http://crbug.com/459214
oshima5a296e82016-04-29 01:32:271079 screenshot_controller_.reset(new ScreenshotController());
Scott Violet596bb46342017-06-21 14:43:131080 mouse_cursor_filter_ = base::MakeUnique<MouseCursorEventFilter>();
1081 PrependPreTargetHandler(mouse_cursor_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:451082
1083 // Create Controllers that may need root window.
1084 // TODO(oshima): Move as many controllers before creating
1085 // RootWindowController as possible.
1086 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:451087
sammiequon203ae022016-09-18 17:23:421088 laser_pointer_controller_.reset(new LaserPointerController());
1089 partial_magnification_controller_.reset(new PartialMagnificationController());
Vladislav Kaznacheev6d6aaff2017-07-22 04:06:321090 highlighter_controller_.reset(new HighlighterController());
sammiequon203ae022016-09-18 17:23:421091
jamescookb8dcef522016-06-25 14:42:551092 magnification_controller_.reset(MagnificationController::CreateInstance());
sky5ab16472017-03-21 19:35:081093 mru_window_tracker_ = base::MakeUnique<MruWindowTracker>();
[email protected]b6ba05d902013-10-04 21:38:451094
[email protected]55398d22013-10-10 19:49:201095 autoclick_controller_.reset(AutoclickController::CreateInstance());
1096
[email protected]b6ba05d902013-10-04 21:38:451097 high_contrast_controller_.reset(new HighContrastController);
1098 video_detector_.reset(new VideoDetector);
[email protected]b6ba05d902013-10-04 21:38:451099
oshimaebbe63772015-02-19 18:41:321100 tooltip_controller_.reset(new views::corewm::TooltipController(
dchenga94547472016-04-08 08:41:111101 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451102 AddPreTargetHandler(tooltip_controller_.get());
1103
hariank0dd03dd2016-07-14 23:47:331104 modality_filter_.reset(new SystemModalContainerEventFilter(this));
1105 AddPreTargetHandler(modality_filter_.get());
1106
[email protected]093b8d642014-04-03 20:59:281107 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451108
skyabcae812017-01-18 17:01:341109 // Must occur after Shell has installed its early pre-target handlers (for
1110 // example, WindowModalityController).
sky11cf8db92017-04-10 23:38:081111 shell_port_->CreatePointerWatcherAdapter();
[email protected]b6ba05d902013-10-04 21:38:451112
[email protected]093b8d642014-04-03 20:59:281113 resize_shadow_controller_.reset(new ResizeShadowController());
sky27344382017-03-08 21:30:321114 shadow_controller_.reset(new ::wm::ShadowController(focus_controller_.get()));
[email protected]b6ba05d902013-10-04 21:38:451115
sky79fa34712017-03-20 23:46:471116 SetSystemTrayDelegate(
skyb073203a2017-03-13 16:59:161117 base::WrapUnique(shell_delegate_->CreateSystemTrayDelegate()));
[email protected]b6ba05d902013-10-04 21:38:451118
jamescookac6724332017-03-21 02:54:431119 // May trigger initialization of the Bluetooth adapter.
1120 tray_bluetooth_helper_->Initialize();
1121
kylechar55f0eaf22017-01-11 22:57:371122 // Create AshTouchTransformController before
oshimae2818922015-07-28 01:18:521123 // WindowTreeHostManager::InitDisplays()
kylechar55f0eaf22017-01-11 22:57:371124 // since AshTouchTransformController listens on
oshimae2818922015-07-28 01:18:521125 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
Scott Violet596bb46342017-06-21 14:43:131126 touch_transformer_controller_ = base::MakeUnique<AshTouchTransformController>(
1127 display_configurator_.get(), display_manager_.get(),
1128 shell_port_->CreateTouchTransformDelegate());
[email protected]03122891a2014-05-13 23:56:491129
sky11cf8db92017-04-10 23:38:081130 keyboard_ui_ = shell_port_->CreateKeyboardUI();
skyfee520c2016-02-11 19:57:461131
Scott Violet596bb46342017-06-21 14:43:131132 window_tree_host_manager_->InitHosts();
1133 shell_port_->OnHostsInitialized();
[email protected]b6ba05d902013-10-04 21:38:451134
rsadam9172bc8a2014-10-29 23:37:381135 // Needs to be created after InitDisplays() since it may cause the virtual
1136 // keyboard to be deployed.
sky83b1bb12017-04-24 20:29:281137 if (config != Config::MASH)
skyabcae812017-01-18 17:01:341138 virtual_keyboard_controller_.reset(new VirtualKeyboardController);
rsadam9172bc8a2014-10-29 23:37:381139
warx533c8f62016-04-12 01:19:431140 audio_a11y_controller_.reset(new chromeos::AudioA11yController);
warx533c8f62016-04-12 01:19:431141
msw0e91d932016-08-25 22:34:091142 // Initialize the wallpaper after the RootWindowController has been created,
1143 // otherwise the widget will not paint when restoring after a browser crash.
1144 // Also, initialize after display initialization to ensure correct sizing.
skyb073203a2017-03-13 16:59:161145 wallpaper_delegate_->InitializeWallpaper();
[email protected]b6ba05d902013-10-04 21:38:451146
sadrul7a8785e2016-02-12 21:54:351147 if (cursor_manager_) {
1148 if (initially_hide_cursor_)
1149 cursor_manager_->HideCursor();
ergeeba7c622017-04-25 18:06:161150 cursor_manager_->SetCursor(ui::CursorType::kPointer);
sadrul7a8785e2016-02-12 21:54:351151 }
[email protected]b6ba05d902013-10-04 21:38:451152
[email protected]093b8d642014-04-03 20:59:281153 power_event_observer_.reset(new PowerEventObserver());
[email protected]ded58fd2013-10-09 07:56:551154 user_activity_notifier_.reset(
[email protected]b0fa7012014-04-16 12:50:571155 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
[email protected]ded58fd2013-10-09 07:56:551156 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281157 new VideoActivityNotifier(video_detector_.get()));
1158 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
Scott Violet596bb46342017-06-21 14:43:131159 screen_orientation_controller_ =
1160 base::MakeUnique<ScreenOrientationController>();
1161 screen_layout_observer_.reset(new ScreenLayoutObserver());
yiyix90cfee22017-02-16 05:38:181162 sms_observer_.reset(new SmsObserver());
jamescook01bf23e72017-01-09 19:58:151163
xdaid4913762017-07-06 00:17:221164 split_view_controller_.reset(new SplitViewController());
1165
[email protected]b6ba05d902013-10-04 21:38:451166 // The compositor thread and main message loop have to be running in
1167 // order to create mirror window. Run it after the main message loop
1168 // is started.
Scott Violet596bb46342017-06-21 14:43:131169 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031170
sky00c813f2017-03-08 22:48:551171 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:181172 observer.OnShellInitialized();
phweiss0bf64c52015-11-17 12:56:181173
Scott Violet41562d1c2017-06-26 15:15:481174 user_metrics_recorder_->OnShellInitialized();
[email protected]b6ba05d902013-10-04 21:38:451175}
1176
[email protected]41baaed2013-11-09 04:18:261177void Shell::InitRootWindow(aura::Window* root_window) {
sky27344382017-03-08 21:30:321178 DCHECK(focus_controller_);
[email protected]d90b8392012-06-13 09:34:561179 DCHECK(visibility_controller_.get());
[email protected]d90b8392012-06-13 09:34:561180
sky27344382017-03-08 21:30:321181 aura::client::SetFocusClient(root_window, focus_controller_.get());
Thiago Farina3b086a02017-05-30 22:32:501182 ::wm::SetActivationClient(root_window, focus_controller_.get());
sky27344382017-03-08 21:30:321183 root_window->AddPreTargetHandler(focus_controller_.get());
[email protected]d90b8392012-06-13 09:34:561184 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
Scott Violet361833fb2017-06-21 22:25:201185 if (drag_drop_controller_) {
1186 DCHECK_NE(Config::MASH, GetAshConfig());
1187 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
1188 } else {
1189 DCHECK_EQ(Config::MASH, GetAshConfig());
1190 }
[email protected]8d625fb2012-07-18 16:40:061191 aura::client::SetScreenPositionClient(root_window,
1192 screen_position_controller_.get());
sadrul7a8785e2016-02-12 21:54:351193 aura::client::SetCursorClient(root_window, cursor_manager_.get());
Thiago Farina3b086a02017-05-30 22:32:501194 ::wm::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381195 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561196
Thiago Farina3b086a02017-05-30 22:32:501197 ::wm::SetWindowMoveClient(root_window, toplevel_window_event_handler_.get());
[email protected]3537d472014-01-15 05:45:311198 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1199 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
[email protected]d90b8392012-06-13 09:34:561200}
1201
sky79fa34712017-03-20 23:46:471202void Shell::SetSystemTrayDelegate(
1203 std::unique_ptr<SystemTrayDelegate> delegate) {
1204 DCHECK(delegate);
1205 system_tray_delegate_ = std::move(delegate);
1206 system_tray_delegate_->Initialize();
sky11cf8db92017-04-10 23:38:081207 // Accesses ShellPort in its constructor.
sky79fa34712017-03-20 23:46:471208 logout_confirmation_controller_.reset(new LogoutConfirmationController(
1209 base::Bind(&SystemTrayController::SignOut,
1210 base::Unretained(system_tray_controller_.get()))));
1211}
1212
1213void Shell::DeleteSystemTrayDelegate() {
1214 DCHECK(system_tray_delegate_);
sky11cf8db92017-04-10 23:38:081215 // Accesses ShellPort in its destructor.
sky79fa34712017-03-20 23:46:471216 logout_confirmation_controller_.reset();
1217 system_tray_delegate_.reset();
1218}
1219
skyabcae812017-01-18 17:01:341220void Shell::CloseAllRootWindowChildWindows() {
msw257a6a232017-06-01 01:46:301221 for (aura::Window* root : GetAllRootWindows()) {
1222 RootWindowController* controller = RootWindowController::ForWindow(root);
skyabcae812017-01-18 17:01:341223 if (controller) {
1224 controller->CloseChildWindows();
1225 } else {
msw257a6a232017-06-01 01:46:301226 while (!root->children().empty()) {
1227 aura::Window* child = root->children()[0];
skyabcae812017-01-18 17:01:341228 delete child;
1229 }
1230 }
1231 }
1232}
1233
[email protected]c0ce80e2012-10-05 23:28:271234bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1235 RootWindowControllerList controllers = GetAllRootWindowControllers();
oshima9a61ecf2016-06-18 10:43:051236 for (RootWindowController* controller : controllers) {
1237 if (controller->CanWindowReceiveEvents(window))
[email protected]602022b2014-03-31 17:07:311238 return true;
[email protected]c0ce80e2012-10-05 23:28:271239 }
1240 return false;
1241}
1242
[email protected]049cf34b2012-12-07 17:15:481243////////////////////////////////////////////////////////////////////////////////
1244// Shell, ui::EventTarget overrides:
1245
[email protected]869f6352012-12-06 20:47:171246bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411247 return true;
1248}
1249
1250ui::EventTarget* Shell::GetParentTarget() {
[email protected]ff0278852013-11-05 22:35:481251 return aura::Env::GetInstance();
[email protected]5097e692012-10-30 22:08:411252}
1253
dchenga94547472016-04-08 08:41:111254std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1255 return std::unique_ptr<ui::EventTargetIterator>();
[email protected]3e670aa2013-12-02 19:04:321256}
1257
1258ui::EventTargeter* Shell::GetEventTargeter() {
1259 NOTREACHED();
achuith287b26e2015-09-03 17:49:181260 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321261}
1262
sky27344382017-03-08 21:30:321263void Shell::OnWindowActivated(
Thiago Farina3b086a02017-05-30 22:32:501264 ::wm::ActivationChangeObserver::ActivationReason reason,
sky27344382017-03-08 21:30:321265 aura::Window* gained_active,
1266 aura::Window* lost_active) {
mswad3d9552017-05-18 21:23:361267 if (gained_active)
1268 root_window_for_new_windows_ = gained_active->GetRootWindow();
sky27344382017-03-08 21:30:321269}
1270
James Cook8532dbc2017-07-31 21:54:511271void Shell::OnActiveUserSessionChanged(const AccountId& account_id) {
1272 if (GetAshConfig() == Config::MASH && shell_delegate_->GetShellConnector()) {
James Cook6d51c9182017-08-04 01:31:001273 // NOTE: |profile_pref_service_| will point to the previous user's profile
1274 // while the connection is being made.
James Cook8532dbc2017-07-31 21:54:511275 auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
1276 RegisterProfilePrefs(pref_registry.get());
James Cook98072352017-08-07 18:00:071277 RegisterForeignPrefs(pref_registry.get());
James Cook8532dbc2017-07-31 21:54:511278 prefs::ConnectToPrefService(
1279 shell_delegate_->GetShellConnector(), pref_registry,
1280 base::Bind(&Shell::OnProfilePrefServiceInitialized,
1281 weak_factory_.GetWeakPtr()),
1282 prefs::mojom::kForwarderServiceName);
1283 return;
1284 }
1285
1286 // On classic ash user profile prefs are available immediately after login.
1287 // The login screen temporary profile is never available.
1288 PrefService* profile_prefs = shell_delegate_->GetActiveUserPrefService();
1289 for (auto& observer : shell_observers_)
1290 observer.OnActiveUserPrefServiceChanged(profile_prefs);
1291}
1292
Xiyuan Xiab64fd0a2017-04-13 17:53:141293void Shell::OnSessionStateChanged(session_manager::SessionState state) {
jamescook788b4fc2017-05-18 16:16:061294 // Initialize the shelf when a session becomes active. It's safe to do this
sky5ad143a2017-03-22 04:31:231295 // multiple times (e.g. initial login vs. multiprofile add session).
1296 if (state == session_manager::SessionState::ACTIVE) {
jamescook788b4fc2017-05-18 16:16:061297 InitializeShelf();
okac21941d2017-06-20 17:54:441298 }
1299 // Recreates keyboard on user profile change, to refresh keyboard
1300 // extensions with the new profile and the extensions call proper IME.
1301 // |LOGGED_IN_NOT_ACTIVE| is needed so that the virtual keyboard works on
1302 // supervised user creation. crbug.com/712873
1303 // |ACTIVE| is also needed for guest user workflow.
1304 if ((state == session_manager::SessionState::LOGGED_IN_NOT_ACTIVE ||
1305 state == session_manager::SessionState::ACTIVE) &&
1306 keyboard::IsKeyboardEnabled()) {
skye5fd1222017-04-12 18:43:231307 if (GetAshConfig() != Config::MASH) {
sky5ad143a2017-03-22 04:31:231308 // Recreate the keyboard after initial login and after multiprofile login.
1309 CreateKeyboard();
1310 }
1311 }
Scott Violet0c0dcde2017-08-04 21:48:181312
1313 shell_port_->UpdateSystemModalAndBlockingContainers();
xiyuan233f4e72017-04-06 06:59:561314}
sky5ad143a2017-03-22 04:31:231315
Xiyuan Xiab64fd0a2017-04-13 17:53:141316void Shell::OnLoginStatusChanged(LoginStatus login_status) {
xiyuan233f4e72017-04-06 06:59:561317 UpdateAfterLoginStatusChange(login_status);
sky5ad143a2017-03-22 04:31:231318}
1319
Xiyuan Xiab64fd0a2017-04-13 17:53:141320void Shell::OnLockStateChanged(bool locked) {
xiyuan7ebbf7f2017-04-10 16:49:101321#ifndef NDEBUG
1322 // Make sure that there is no system modal in Lock layer when unlocked.
1323 if (!locked) {
1324 aura::Window::Windows containers = wm::GetContainersFromAllRootWindows(
1325 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
1326 for (aura::Window* container : containers)
1327 DCHECK(container->children().empty());
1328 }
1329#endif
1330}
1331
jamescook788b4fc2017-05-18 16:16:061332void Shell::InitializeShelf() {
1333 // Must occur after SessionController creation and user login.
1334 DCHECK(session_controller());
1335 DCHECK_GT(session_controller()->NumberOfLoggedInUsers(), 0);
1336
1337 // Notify the ShellDelegate that the shelf is being initialized.
1338 // TODO(msw): Refine ChromeLauncherController lifetime management.
1339 shell_delegate_->ShelfInit();
1340
1341 if (!shelf_window_watcher_)
1342 shelf_window_watcher_ = base::MakeUnique<ShelfWindowWatcher>(shelf_model());
1343
1344 for (RootWindowController* root : GetAllRootWindowControllers())
1345 root->InitializeShelf();
1346}
1347
James Cook98072352017-08-07 18:00:071348// static
1349void Shell::RegisterForeignPrefs(PrefRegistrySimple* registry) {
1350 DCHECK_EQ(GetAshConfig(), Config::MASH);
1351 // Request access to prefs used by ash but owned by chrome.
1352 // See //services/preferences/README.md
1353 TrayCapsLock::RegisterForeignPrefs(registry);
1354}
1355
James Cook8532dbc2017-07-31 21:54:511356void Shell::OnProfilePrefServiceInitialized(
James Cook0ff197f2017-08-07 17:26:381357 std::unique_ptr<PrefService> pref_service) {
James Cookbbe5cb12017-08-08 18:32:211358 DCHECK(GetAshConfig() == Config::MASH);
James Cook0ff197f2017-08-07 17:26:381359 // Keep the old PrefService object alive so OnActiveUserPrefServiceChanged()
1360 // clients can unregister pref observers on the old service.
James Cookbbe5cb12017-08-08 18:32:211361 std::unique_ptr<PrefService> old_service =
1362 std::move(profile_pref_service_mash_);
1363 profile_pref_service_mash_ = std::move(pref_service);
James Cook8532dbc2017-07-31 21:54:511364 // |pref_service| can be null if can't connect to Chrome (as happens when
sky7bd582ae2017-04-12 21:43:331365 // running mash outside of chrome --mash and chrome isn't built).
James Cook8532dbc2017-07-31 21:54:511366 for (auto& observer : shell_observers_)
James Cookbbe5cb12017-08-08 18:32:211367 observer.OnActiveUserPrefServiceChanged(profile_pref_service_mash_.get());
James Cook0ff197f2017-08-07 17:26:381368 // |old_service| is deleted.
tibellb93c729b2017-03-30 00:45:091369}
1370
Sam McNallye36abbc2017-07-20 01:04:281371void Shell::OnLocalStatePrefServiceInitialized(
1372 std::unique_ptr<::PrefService> pref_service) {
James Cookbbe5cb12017-08-08 18:32:211373 DCHECK(GetAshConfig() == Config::MASH);
James Cook8532dbc2017-07-31 21:54:511374 // |pref_service| is null if can't connect to Chrome (as happens when
Sam McNallye36abbc2017-07-20 01:04:281375 // running mash outside of chrome --mash and chrome isn't built).
James Cookbbe5cb12017-08-08 18:32:211376 local_state_mash_ = std::move(pref_service);
1377
1378 for (auto& observer : shell_observers_)
1379 observer.OnLocalStatePrefServiceInitialized(local_state_mash_.get());
Sam McNallye36abbc2017-07-20 01:04:281380}
1381
[email protected]55f593352011-12-24 05:42:461382} // namespace ash