blob: 5d9abf02b9697376c2aa5d2c7a44b6b2028bc209 [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"
sky11cf8db92017-04-10 23:38:0820#include "ash/aura/shell_port_classic.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"
23#include "ash/devtools/ash_devtools_css_agent.h"
24#include "ash/devtools/ash_devtools_dom_agent.h"
[email protected]87ec2202014-02-06 06:24:2725#include "ash/display/cursor_window_controller.h"
jamescook01bf23e72017-01-09 19:58:1526#include "ash/display/display_color_manager_chromeos.h"
stevenjb537c5c3f2016-01-20 23:38:1227#include "ash/display/display_configuration_controller.h"
jamescook01bf23e72017-01-09 19:58:1528#include "ash/display/display_error_observer_chromeos.h"
[email protected]682990f2013-01-10 06:49:1129#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2730#include "ash/display/mouse_cursor_event_filter.h"
jamescook01bf23e72017-01-09 19:58:1531#include "ash/display/projecting_observer_chromeos.h"
32#include "ash/display/resolution_notification_controller.h"
rjkroege2c9305402016-09-07 00:21:4533#include "ash/display/screen_ash.h"
jamescook01bf23e72017-01-09 19:58:1534#include "ash/display/screen_orientation_controller_chromeos.h"
[email protected]8d625fb2012-07-18 16:40:0635#include "ash/display/screen_position_controller.h"
jamescook01bf23e72017-01-09 19:58:1536#include "ash/display/shutdown_observer_chromeos.h"
oshimae2818922015-07-28 01:18:5237#include "ash/display/window_tree_host_manager.h"
[email protected]f4c92b382012-08-28 00:59:5938#include "ash/drag_drop/drag_drop_controller.h"
[email protected]59ccade2013-10-17 17:56:4039#include "ash/first_run/first_run_helper_impl.h"
James Cookb0bf8e82017-04-09 17:01:4440#include "ash/focus_cycler.h"
41#include "ash/frame/custom_frame_view_ash.h"
42#include "ash/gpu_support.h"
[email protected]f4c92b382012-08-28 00:59:5943#include "ash/high_contrast/high_contrast_controller.h"
oshima5e0fff82015-06-27 01:31:3044#include "ash/ime/input_method_event_handler.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"
James Cookb0bf8e82017-04-09 17:01:4447#include "ash/login_status.h"
[email protected]f4c92b382012-08-28 00:59:5948#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5449#include "ash/magnifier/partial_magnification_controller.h"
James Cookb0bf8e82017-04-09 17:01:4450#include "ash/media_controller.h"
51#include "ash/new_window_controller.h"
52#include "ash/palette_delegate.h"
sky494c6cbd2017-03-27 20:57:4853#include "ash/public/cpp/config.h"
jamescook8800b8232016-10-19 12:46:2754#include "ash/public/cpp/shell_window_ids.h"
[email protected]d90b8392012-06-13 09:34:5655#include "ash/root_window_controller.h"
James Cookb0bf8e82017-04-09 17:01:4456#include "ash/session/session_controller.h"
57#include "ash/session/session_state_delegate.h"
58#include "ash/shelf/shelf_controller.h"
James Cookb0bf8e82017-04-09 17:01:4459#include "ash/shelf/shelf_model.h"
60#include "ash/shelf/shelf_window_watcher.h"
61#include "ash/shelf/wm_shelf.h"
62#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"
James Cookb0bf8e82017-04-09 17:01:4466#include "ash/shutdown_controller.h"
jamescook01bf23e72017-01-09 19:58:1567#include "ash/sticky_keys/sticky_keys_controller.h"
James Cooka35a1e22017-04-08 02:33:0868#include "ash/system/bluetooth/bluetooth_notification_controller.h"
69#include "ash/system/bluetooth/tray_bluetooth_helper.h"
70#include "ash/system/brightness/brightness_controller_chromeos.h"
James Cookb0bf8e82017-04-09 17:01:4471#include "ash/system/brightness_control_delegate.h"
72#include "ash/system/keyboard_brightness_control_delegate.h"
James Cooka35a1e22017-04-08 02:33:0873#include "ash/system/keyboard_brightness_controller.h"
James Cookb0bf8e82017-04-09 17:01:4474#include "ash/system/locale/locale_notification_controller.h"
James Cooka35a1e22017-04-08 02:33:0875#include "ash/system/network/sms_observer.h"
76#include "ash/system/network/vpn_list.h"
afakhrye4fae852017-05-09 18:49:0677#include "ash/system/night_light/night_light_controller.h"
James Cooka35a1e22017-04-08 02:33:0878#include "ash/system/power/power_event_observer.h"
79#include "ash/system/power/power_status.h"
80#include "ash/system/power/video_activity_notifier.h"
81#include "ash/system/screen_layout_observer.h"
82#include "ash/system/session/logout_confirmation_controller.h"
James Cookb0bf8e82017-04-09 17:01:4483#include "ash/system/status_area_widget.h"
84#include "ash/system/toast/toast_manager.h"
85#include "ash/system/tray/system_tray_controller.h"
86#include "ash/system/tray/system_tray_delegate.h"
87#include "ash/system/tray/system_tray_notifier.h"
kylechar55f0eaf22017-01-11 22:57:3788#include "ash/touch/ash_touch_transform_controller.h"
tbarzicc78da1ff92017-05-08 20:46:1589#include "ash/tray_action/tray_action.h"
oshima5a296e82016-04-29 01:32:2790#include "ash/utility/screenshot_controller.h"
jamescook01bf23e72017-01-09 19:58:1591#include "ash/virtual_keyboard_controller.h"
James Cookb0bf8e82017-04-09 17:01:4492#include "ash/wallpaper/wallpaper_controller.h"
93#include "ash/wallpaper/wallpaper_delegate.h"
[email protected]39718b52012-12-03 17:24:5694#include "ash/wm/ash_focus_rules.h"
[email protected]c0ff0342013-02-27 00:41:2995#include "ash/wm/ash_native_cursor_manager.h"
James Cookb0bf8e82017-04-09 17:01:4496#include "ash/wm/container_finder.h"
[email protected]262f8bd2012-03-23 19:30:2797#include "ash/wm/event_client_impl.h"
James Cookb0bf8e82017-04-09 17:01:4498#include "ash/wm/immersive_context_ash.h"
skyb7b54092016-08-19 16:00:0999#include "ash/wm/immersive_handler_factory_ash.h"
[email protected]ab4f8c92013-05-30 19:07:47100#include "ash/wm/lock_state_controller.h"
James Cookb0bf8e82017-04-09 17:01:44101#include "ash/wm/maximize_mode/maximize_mode_controller.h"
102#include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
103#include "ash/wm/mru_window_tracker.h"
[email protected]9ae32df2012-07-26 03:25:18104#include "ash/wm/overlay_event_filter.h"
sky6624a7af2016-05-27 18:47:49105#include "ash/wm/overview/scoped_overview_animation_settings_factory_aura.h"
James Cookb0bf8e82017-04-09 17:01:44106#include "ash/wm/overview/window_selector_controller.h"
[email protected]e0d22e82012-01-04 00:46:57107#include "ash/wm/power_button_controller.h"
[email protected]e4a181cc2012-03-17 02:20:57108#include "ash/wm/resize_shadow_controller.h"
James Cookb0bf8e82017-04-09 17:01:44109#include "ash/wm/root_window_finder.h"
hidehiko6821ca42016-06-18 11:12:23110#include "ash/wm/screen_pinning_controller.h"
[email protected]435b212e2012-04-05 19:43:37111#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:27112#include "ash/wm/system_modal_container_event_filter.h"
James Cookb0bf8e82017-04-09 17:01:44113#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]3537d472014-01-15 05:45:31114#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:58115#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:02116#include "ash/wm/window_animations.h"
James Cookb0bf8e82017-04-09 17:01:44117#include "ash/wm/window_cycle_controller.h"
118#include "ash/wm/window_positioner.h"
[email protected]f059c6942012-07-21 14:27:57119#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:59120#include "ash/wm/window_util.h"
James Cookb0bf8e82017-04-09 17:01:44121#include "ash/wm/workspace_controller.h"
James Cookb0bf8e82017-04-09 17:01:44122#include "ash/wm_window.h"
[email protected]f296be72011-10-11 15:40:00123#include "base/bind.h"
jamescook01bf23e72017-01-09 19:58:15124#include "base/bind_helpers.h"
jamescookfda159002016-10-21 18:48:57125#include "base/command_line.h"
dchenga94547472016-04-08 08:41:11126#include "base/memory/ptr_util.h"
jamescook01bf23e72017-01-09 19:58:15127#include "base/sys_info.h"
tzik0dd58d42017-02-15 08:26:52128#include "base/threading/sequenced_worker_pool.h"
primiano7182d7b2015-01-30 18:02:03129#include "base/trace_event/trace_event.h"
jamescook01bf23e72017-01-09 19:58:15130#include "chromeos/audio/audio_a11y_controller.h"
131#include "chromeos/chromeos_switches.h"
132#include "chromeos/dbus/dbus_thread_manager.h"
reveman24158982017-01-10 05:58:45133#include "chromeos/system/devicemode.h"
tibellb93c729b2017-03-30 00:45:09134#include "components/prefs/pref_registry_simple.h"
135#include "components/prefs/pref_service.h"
sky07a24d42017-03-09 23:57:30136#include "components/ui_devtools/devtools_server.h"
tibellb93c729b2017-03-30 00:45:09137#include "services/preferences/public/cpp/pref_service_factory.h"
skyb073203a2017-03-13 16:59:16138#include "services/preferences/public/interfaces/preferences.mojom.h"
derat94887a22017-01-20 18:17:25139#include "services/service_manager/public/cpp/connector.h"
140#include "services/ui/public/interfaces/constants.mojom.h"
sky7db5ccf2017-03-14 21:52:29141#include "ui/app_list/presenter/app_list.h"
[email protected]2c456102011-12-26 06:26:34142#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:44143#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:58144#include "ui/aura/layout_manager.h"
sky68612712017-04-27 04:45:04145#include "ui/aura/mus/focus_synchronizer.h"
derat94887a22017-01-20 18:17:25146#include "ui/aura/mus/user_activity_forwarder.h"
sky68612712017-04-27 04:45:04147#include "ui/aura/mus/window_tree_client.h"
[email protected]87b0d82e2011-10-07 21:02:59148#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:26149#include "ui/aura/window_event_dispatcher.h"
[email protected]2d4817742012-12-17 20:16:18150#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:17151#include "ui/base/user_activity/user_activity_detector.h"
jamescook01bf23e72017-01-09 19:58:15152#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]116302fc2012-05-05 21:45:41153#include "ui/compositor/layer.h"
154#include "ui/compositor/layer_animator.h"
oshimaf84b0da722016-04-27 19:47:19155#include "ui/display/display.h"
jamescook01bf23e72017-01-09 19:58:15156#include "ui/display/manager/chromeos/display_change_observer.h"
157#include "ui/display/manager/chromeos/display_configurator.h"
rjkroege72f8154f2016-10-29 00:49:02158#include "ui/display/manager/display_manager.h"
oshimaf84b0da722016-04-27 19:47:19159#include "ui/display/screen.h"
skycfaad892017-04-28 20:52:58160#include "ui/display/types/native_display_delegate.h"
[email protected]3e670aa2013-12-02 19:04:32161#include "ui/events/event_target_iterator.h"
sky4ec2be82017-01-06 17:38:32162#include "ui/gfx/geometry/insets.h"
[email protected]9ec0f452012-05-31 15:58:53163#include "ui/gfx/image/image_skia.h"
[email protected]b6ba05d902013-10-04 21:38:45164#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28165#include "ui/keyboard/keyboard_switches.h"
[email protected]f1d5c3a2013-04-23 17:42:56166#include "ui/keyboard/keyboard_util.h"
[email protected]d7f30a72013-10-05 05:09:41167#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04168#include "ui/views/corewm/tooltip_controller.h"
sky07a24d42017-03-09 23:57:30169#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:58170#include "ui/views/widget/native_widget_aura.h"
171#include "ui/views/widget/widget.h"
[email protected]60d677d2014-05-30 13:07:02172#include "ui/wm/core/accelerator_filter.h"
[email protected]ee3ed10772014-03-11 22:02:01173#include "ui/wm/core/compound_event_filter.h"
174#include "ui/wm/core/focus_controller.h"
[email protected]ee3ed10772014-03-11 22:02:01175#include "ui/wm/core/shadow_controller.h"
176#include "ui/wm/core/visibility_controller.h"
177#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59178
[email protected]55f593352011-12-24 05:42:46179namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59180
181namespace {
[email protected]671a2ae2011-10-13 21:53:23182
[email protected]615922f2012-02-07 02:41:15183using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45184using views::Widget;
185
jamescook518dccbd2017-05-18 04:57:07186bool g_is_browser_process_with_mash = false;
187
[email protected]b5756e22012-11-30 01:32:02188// A Corewm VisibilityController subclass that calls the Ash animation routine
189// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14190class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02191 public:
192 AshVisibilityController() {}
dcheng1f4538e2014-10-27 23:57:05193 ~AshVisibilityController() override {}
[email protected]b5756e22012-11-30 01:32:02194
195 private:
[email protected]e319c7e2014-03-14 19:56:14196 // Overridden from ::wm::VisibilityController:
dcheng1f4538e2014-10-27 23:57:05197 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
198 bool visible) override {
[email protected]b5756e22012-11-30 01:32:02199 return AnimateOnChildWindowVisibilityChanged(window, visible);
200 }
201
202 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
203};
204
[email protected]87b0d82e2011-10-07 21:02:59205} // namespace
206
[email protected]cac10fc62011-10-07 23:22:56207// static
achuith287b26e2015-09-03 17:49:18208Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13209// static
sky00f98a372017-01-11 06:03:49210aura::WindowTreeClient* Shell::window_tree_client_ = nullptr;
211// static
skya8b222f2017-01-12 15:47:13212aura::WindowManagerClient* Shell::window_manager_client_ = nullptr;
213// static
[email protected]9488d4d2012-02-29 18:32:37214bool Shell::initially_hide_cursor_ = false;
[email protected]2b4cd302012-02-24 20:21:13215
216////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56217// Shell, public:
218
[email protected]cac10fc62011-10-07 23:22:56219// static
[email protected]1b4c7472014-05-15 18:32:23220Shell* Shell::CreateInstance(const ShellInitParams& init_params) {
[email protected]3266c2b92011-11-14 00:06:08221 CHECK(!instance_);
sky11cf8db92017-04-10 23:38:08222 ShellPort* shell_port = init_params.shell_port;
223 if (!shell_port)
224 shell_port = new ShellPortClassic();
skyb073203a2017-03-13 16:59:16225 instance_ = new Shell(base::WrapUnique<ShellDelegate>(init_params.delegate),
sky11cf8db92017-04-10 23:38:08226 base::WrapUnique<ShellPort>(shell_port));
[email protected]1b4c7472014-05-15 18:32:23227 instance_->Init(init_params);
[email protected]3266c2b92011-11-14 00:06:08228 return instance_;
229}
230
231// static
skyb073203a2017-03-13 16:59:16232Shell* Shell::Get() {
jamescook518dccbd2017-05-18 04:57:07233 CHECK(!g_is_browser_process_with_mash) // Implies null |instance_|.
234 << "Ash is running in its own process so Shell::Get() will return null. "
235 "The browser process must use the mojo interfaces in //ash/public to "
236 "access ash. See ash/README.md for details.";
oshima9eea82da2014-09-13 01:11:07237 CHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56238 return instance_;
239}
240
[email protected]6377a002011-11-10 20:26:47241// static
[email protected]b3b7bcd2012-03-06 19:35:45242bool Shell::HasInstance() {
243 return !!instance_;
244}
245
246// static
[email protected]ef589af2011-12-03 01:07:15247void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47248 delete instance_;
[email protected]6377a002011-11-10 20:26:47249}
250
[email protected]e73bd7802012-02-17 20:10:34251// static
[email protected]093b8d642014-04-03 20:59:28252RootWindowController* Shell::GetPrimaryRootWindowController() {
oshima9eea82da2014-09-13 01:11:07253 CHECK(HasInstance());
[email protected]093b8d642014-04-03 20:59:28254 return GetRootWindowController(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23255}
256
257// static
258Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
oshima9eea82da2014-09-13 01:11:07259 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34260 RootWindowControllerList root_window_controllers;
sky11cf8db92017-04-10 23:38:08261 for (WmWindow* root_window : instance_->shell_port_->GetAllRootWindows())
skyabcae812017-01-18 17:01:34262 root_window_controllers.push_back(root_window->GetRootWindowController());
263 return root_window_controllers;
[email protected]d90b8392012-06-13 09:34:56264}
265
266// static
thanhphc90f49ca2017-03-03 17:48:53267RootWindowController* Shell::GetRootWindowControllerWithDisplayId(
268 int64_t display_id) {
269 CHECK(HasInstance());
270 WmWindow* root_window =
sky11cf8db92017-04-10 23:38:08271 instance_->shell_port_->GetRootWindowForDisplayId(display_id);
thanhphc90f49ca2017-03-03 17:48:53272 return root_window ? root_window->GetRootWindowController() : nullptr;
273}
274
275// static
[email protected]bf9cdb362013-10-25 19:22:45276aura::Window* Shell::GetPrimaryRootWindow() {
oshima9eea82da2014-09-13 01:11:07277 CHECK(HasInstance());
sky11cf8db92017-04-10 23:38:08278 return instance_->shell_port_->GetPrimaryRootWindow()->aura_window();
[email protected]e73bd7802012-02-17 20:10:34279}
280
[email protected]7b0f7502012-06-11 00:12:39281// static
sky27344382017-03-08 21:30:32282aura::Window* Shell::GetRootWindowForNewWindows() {
283 CHECK(Shell::HasInstance());
284 return WmWindow::GetAuraWindow(Shell::GetWmRootWindowForNewWindows());
[email protected]a857dbe2012-05-30 22:10:14285}
286
[email protected]7b0f7502012-06-11 00:12:39287// static
sky27344382017-03-08 21:30:32288WmWindow* Shell::GetWmRootWindowForNewWindows() {
289 CHECK(Shell::HasInstance());
skycb4be5b2017-04-06 17:52:45290 Shell* shell = Shell::Get();
sky27344382017-03-08 21:30:32291 if (shell->scoped_root_window_for_new_windows_)
292 return shell->scoped_root_window_for_new_windows_;
293 return shell->root_window_for_new_windows_;
mfomitcheva1a8aa62016-05-03 16:23:26294}
295
296// static
[email protected]c9390bd2013-11-08 20:33:13297aura::Window::Windows Shell::GetAllRootWindows() {
oshima9eea82da2014-09-13 01:11:07298 CHECK(HasInstance());
skyabcae812017-01-18 17:01:34299 aura::Window::Windows windows;
sky11cf8db92017-04-10 23:38:08300 for (WmWindow* window : instance_->shell_port_->GetAllRootWindows())
skyabcae812017-01-18 17:01:34301 windows.push_back(window->aura_window());
302 return windows;
[email protected]be65be362012-06-15 07:38:23303}
304
305// static
jamescookb8dcef522016-06-25 14:42:55306aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) {
[email protected]7b0f7502012-06-11 00:12:39307 return root_window->GetChildById(container_id);
308}
309
310// static
[email protected]bf9cdb362013-10-25 19:22:45311const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38312 int container_id) {
313 return root_window->GetChildById(container_id);
314}
315
sky494c6cbd2017-03-27 20:57:48316// static
jamescook0dfe5632017-04-05 18:49:02317Config Shell::GetAshConfig() {
sky11cf8db92017-04-10 23:38:08318 return Get()->shell_port_->GetAshConfig();
sky494c6cbd2017-03-27 20:57:48319}
320
moshayedic229a522017-05-05 18:14:26321// static
322bool Shell::ShouldUseIMEService() {
323 return Shell::GetAshConfig() == Config::MASH ||
324 (Shell::GetAshConfig() == Config::MUS &&
325 base::CommandLine::ForCurrentProcess()->HasSwitch(
326 switches::kUseIMEService));
327}
328
afakhrye4fae852017-05-09 18:49:06329// static
330void Shell::RegisterPrefs(PrefRegistrySimple* registry) {
331 NightLightController::RegisterPrefs(registry);
332}
333
[email protected]57b8bb352012-01-11 05:11:46334views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
335 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04336 // Use translucent-style window frames for dialogs.
[email protected]85501fe2013-10-18 10:15:27337 return new CustomFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46338}
339
[email protected]2e236a52012-06-27 22:21:47340void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44341 const gfx::Insets& insets) {
sky11cf8db92017-04-10 23:38:08342 shell_port_->SetDisplayWorkAreaInsets(WmWindow::Get(contains), insets);
[email protected]1a2145b2012-03-13 21:09:17343}
344
[email protected]58868abf2014-01-17 23:45:33345void Shell::OnCastingSessionStartedOrStopped(bool started) {
sky00c813f2017-03-08 22:48:55346 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18347 observer.OnCastingSessionStartedOrStopped(started);
[email protected]58868abf2014-01-17 23:45:33348}
349
sky80556bc42016-06-07 22:46:13350void Shell::OnRootWindowAdded(WmWindow* root_window) {
sky00c813f2017-03-08 22:48:55351 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18352 observer.OnRootWindowAdded(root_window);
[email protected]0e3e7cb2014-04-12 05:18:25353}
354
[email protected]51f438112013-11-18 19:32:50355void Shell::CreateKeyboard() {
[email protected]51f438112013-11-18 19:32:50356 InitKeyboard();
jamescookb8dcef522016-06-25 14:42:55357 GetPrimaryRootWindowController()->ActivateKeyboard(
358 keyboard::KeyboardController::GetInstance());
[email protected]51f438112013-11-18 19:32:50359}
360
[email protected]e1b299b2014-01-29 23:53:41361void Shell::DeactivateKeyboard() {
sky11cf8db92017-04-10 23:38:08362 // TODO(jamescook): Move keyboard create and hide into ShellPort.
sky79fa34712017-03-20 23:46:47363 keyboard_ui_->Hide();
[email protected]a0b3fb882014-04-07 19:26:03364 if (keyboard::KeyboardController::GetInstance()) {
[email protected]e1b299b2014-01-29 23:53:41365 RootWindowControllerList controllers = GetAllRootWindowControllers();
366 for (RootWindowControllerList::iterator iter = controllers.begin();
jamescookb8dcef522016-06-25 14:42:55367 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:03368 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]e1b299b2014-01-29 23:53:41369 }
370 }
achuith287b26e2015-09-03 17:49:18371 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]e1b299b2014-01-29 23:53:41372}
373
[email protected]da285852014-05-27 19:53:43374bool Shell::ShouldSaveDisplaySettings() {
skye5fd1222017-04-12 18:43:23375 DCHECK(GetAshConfig() != Config::MASH);
jamescookb8dcef522016-06-25 14:42:55376 return !(
377 screen_orientation_controller_->ignore_display_configuration_updates() ||
378 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43379}
[email protected]da285852014-05-27 19:53:43380
sky5ad143a2017-03-22 04:31:23381ShelfModel* Shell::shelf_model() {
382 return shelf_controller_->model();
383}
384
sky27344382017-03-08 21:30:32385aura::client::ActivationClient* Shell::activation_client() {
386 return focus_controller_.get();
387}
388
[email protected]c758fbf2012-03-25 22:53:59389void Shell::UpdateShelfVisibility() {
sky11cf8db92017-04-10 23:38:08390 for (WmWindow* root : shell_port_->GetAllRootWindows())
jamescookb551aba2016-09-01 01:00:16391 root->GetRootWindowController()->GetShelf()->UpdateVisibilityState();
[email protected]c758fbf2012-03-25 22:53:59392}
393
afakhry15eb9282017-04-27 04:03:31394PrefService* Shell::GetActiveUserPrefService() const {
395 if (shell_port_->GetAshConfig() == Config::MASH)
396 return pref_service_.get();
397
398 return shell_delegate_->GetActiveUserPrefService();
399}
400
[email protected]88d71122012-10-18 07:11:01401WebNotificationTray* Shell::GetWebNotificationTray() {
jamescook612205f2016-05-26 06:02:11402 return GetPrimaryRootWindowController()
jamescookb551aba2016-09-01 01:00:16403 ->GetStatusAreaWidget()
jamescook612205f2016-05-26 06:02:11404 ->web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28405}
406
[email protected]a0afeb12012-12-10 22:57:09407bool Shell::HasPrimaryStatusArea() {
jamescookb551aba2016-09-01 01:00:16408 return !!GetPrimaryRootWindowController()->GetStatusAreaWidget();
[email protected]31f19e32012-10-30 22:31:23409}
410
[email protected]a0afeb12012-12-10 22:57:09411SystemTray* Shell::GetPrimarySystemTray() {
412 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42413}
414
[email protected]2b8a9bb2013-07-01 22:43:40415void Shell::SetTouchHudProjectionEnabled(bool enabled) {
416 if (is_touch_hud_projection_enabled_ == enabled)
417 return;
418
[email protected]2b8a9bb2013-07-01 22:43:40419 is_touch_hud_projection_enabled_ = enabled;
sky00c813f2017-03-08 22:48:55420 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:18421 observer.OnTouchHudProjectionToggled(enabled);
[email protected]2b8a9bb2013-07-01 22:43:40422}
423
mswa7e8a5f2016-03-01 04:15:06424FirstRunHelper* Shell::CreateFirstRunHelper() {
425 return new FirstRunHelperImpl;
[email protected]59ccade2013-10-17 17:56:40426}
[email protected]87ec2202014-02-06 06:24:27427
sky5ad143a2017-03-22 04:31:23428void Shell::CreateShelfView() {
429 // Must occur after SessionController creation and user login.
430 DCHECK(session_controller());
431 DCHECK_GT(session_controller()->NumberOfLoggedInUsers(), 0);
sky5ad143a2017-03-22 04:31:23432
msw5138f3d2017-04-20 00:22:07433 // Notify the ShellDelegate that the shelf is being initialized.
msw5c06364c2017-04-27 02:49:06434 // TODO(msw): Refine ChromeLauncherController lifetime management.
msw5138f3d2017-04-20 00:22:07435 shell_delegate_->ShelfInit();
436
437 if (!shelf_window_watcher_)
438 shelf_window_watcher_ = base::MakeUnique<ShelfWindowWatcher>(shelf_model());
sky11cf8db92017-04-10 23:38:08439 for (WmWindow* root_window : shell_port_->GetAllRootWindows())
sky5ad143a2017-03-22 04:31:23440 root_window->GetRootWindowController()->CreateShelfView();
441}
442
yawanodc5533b32017-02-23 11:04:38443void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
444 window_tree_host_manager_->cursor_window_controller()
445 ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
446}
447
[email protected]87ec2202014-02-06 06:24:27448void Shell::SetCursorCompositingEnabled(bool enabled) {
jamescook0dfe5632017-04-05 18:49:02449 if (GetAshConfig() == Config::CLASSIC) {
sky494c6cbd2017-03-27 20:57:48450 // TODO: needs to work in mus. http://crbug.com/705592.
451 window_tree_host_manager_->cursor_window_controller()
452 ->SetCursorCompositingEnabled(enabled);
453 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
454 }
[email protected]87ec2202014-02-06 06:24:27455}
[email protected]59ccade2013-10-17 17:56:40456
[email protected]f9466702012-09-17 16:35:27457void Shell::DoInitialWorkspaceAnimation() {
jamescookb8dcef522016-06-25 14:42:55458 return GetPrimaryRootWindowController()
459 ->workspace_controller()
460 ->DoInitialAnimation();
[email protected]f9466702012-09-17 16:35:27461}
462
sky00c813f2017-03-08 22:48:55463void Shell::AddShellObserver(ShellObserver* observer) {
464 shell_observers_.AddObserver(observer);
465}
466
467void Shell::RemoveShellObserver(ShellObserver* observer) {
468 shell_observers_.RemoveObserver(observer);
469}
470
sky7db5ccf2017-03-14 21:52:29471void Shell::ShowAppList() {
472 // Show the app list on the default display for new windows.
473 app_list_->Show(
474 GetWmRootWindowForNewWindows()->GetDisplayNearestWindow().id());
475}
476
477void Shell::DismissAppList() {
478 app_list_->Dismiss();
479}
480
481void Shell::ToggleAppList() {
482 // Toggle the app list on the default display for new windows.
483 app_list_->ToggleAppList(
484 GetWmRootWindowForNewWindows()->GetDisplayNearestWindow().id());
485}
486
487bool Shell::IsAppListVisible() const {
488 return app_list_->IsVisible();
489}
490
491bool Shell::GetAppListTargetVisibility() const {
492 return app_list_->GetTargetVisibility();
493}
494
sky5ad143a2017-03-22 04:31:23495void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
sky11cf8db92017-04-10 23:38:08496 for (WmWindow* root_window : shell_port_->GetAllRootWindows()) {
sky5ad143a2017-03-22 04:31:23497 root_window->GetRootWindowController()->UpdateAfterLoginStatusChange(
498 status);
499 }
500}
501
sky00c813f2017-03-08 22:48:55502void Shell::NotifyMaximizeModeStarted() {
503 for (auto& observer : shell_observers_)
504 observer.OnMaximizeModeStarted();
505}
506
507void Shell::NotifyMaximizeModeEnding() {
508 for (auto& observer : shell_observers_)
509 observer.OnMaximizeModeEnding();
510}
511
512void Shell::NotifyMaximizeModeEnded() {
513 for (auto& observer : shell_observers_)
514 observer.OnMaximizeModeEnded();
515}
516
517void Shell::NotifyOverviewModeStarting() {
518 for (auto& observer : shell_observers_)
519 observer.OnOverviewModeStarting();
520}
521
522void Shell::NotifyOverviewModeEnded() {
523 for (auto& observer : shell_observers_)
524 observer.OnOverviewModeEnded();
525}
526
527void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
528 WmWindow* root_window) {
529 for (auto& observer : shell_observers_)
530 observer.OnFullscreenStateChanged(is_fullscreen, root_window);
531}
532
533void Shell::NotifyPinnedStateChanged(WmWindow* pinned_window) {
534 for (auto& observer : shell_observers_)
535 observer.OnPinnedStateChanged(pinned_window);
536}
537
xiyuan38160182017-03-14 22:50:13538void Shell::NotifyVirtualKeyboardActivated(bool activated,
sky97f9a7432017-05-09 05:14:31539 aura::Window* root_window) {
sky00c813f2017-03-08 22:48:55540 for (auto& observer : shell_observers_)
xiyuan38160182017-03-14 22:50:13541 observer.OnVirtualKeyboardStateChanged(activated, root_window);
sky00c813f2017-03-08 22:48:55542}
543
544void Shell::NotifyShelfCreatedForRootWindow(WmWindow* root_window) {
545 for (auto& observer : shell_observers_)
546 observer.OnShelfCreatedForRootWindow(root_window);
547}
548
549void Shell::NotifyShelfAlignmentChanged(WmWindow* root_window) {
550 for (auto& observer : shell_observers_)
551 observer.OnShelfAlignmentChanged(root_window);
552}
553
554void Shell::NotifyShelfAutoHideBehaviorChanged(WmWindow* root_window) {
555 for (auto& observer : shell_observers_)
556 observer.OnShelfAutoHideBehaviorChanged(root_window);
557}
558
jamescook518dccbd2017-05-18 04:57:07559// static
560void Shell::SetIsBrowserProcessWithMash() {
561 g_is_browser_process_with_mash = true;
562}
563
[email protected]b6ba05d902013-10-04 21:38:45564////////////////////////////////////////////////////////////////////////////////
565// Shell, private:
566
skyb073203a2017-03-13 16:59:16567Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate,
sky11cf8db92017-04-10 23:38:08568 std::unique_ptr<ShellPort> shell_port)
569 : shell_port_(std::move(shell_port)),
sky79fa34712017-03-20 23:46:47570 brightness_control_delegate_(
571 base::MakeUnique<system::BrightnessControllerChromeos>()),
572 cast_config_(base::MakeUnique<CastConfigController>()),
573 focus_cycler_(base::MakeUnique<FocusCycler>()),
sky5ab16472017-03-21 19:35:08574 immersive_context_(base::MakeUnique<ImmersiveContextAsh>()),
sky79fa34712017-03-20 23:46:47575 keyboard_brightness_control_delegate_(
576 base::MakeUnique<KeyboardBrightnessController>()),
577 locale_notification_controller_(
578 base::MakeUnique<LocaleNotificationController>()),
sky5ab16472017-03-21 19:35:08579 media_controller_(base::MakeUnique<MediaController>()),
580 new_window_controller_(base::MakeUnique<NewWindowController>()),
sky5ad143a2017-03-22 04:31:23581 session_controller_(base::MakeUnique<SessionController>()),
afakhrye4fae852017-05-09 18:49:06582 night_light_controller_(
583 base::MakeUnique<NightLightController>(session_controller_.get())),
sky5ad143a2017-03-22 04:31:23584 shelf_controller_(base::MakeUnique<ShelfController>()),
skyb073203a2017-03-13 16:59:16585 shell_delegate_(std::move(shell_delegate)),
sky5b45ed82017-03-27 02:54:23586 shutdown_controller_(base::MakeUnique<ShutdownController>()),
sky79fa34712017-03-20 23:46:47587 system_tray_controller_(base::MakeUnique<SystemTrayController>()),
sky5b45ed82017-03-27 02:54:23588 system_tray_notifier_(base::MakeUnique<SystemTrayNotifier>()),
tbarzicc78da1ff92017-05-08 20:46:15589 tray_action_(base::MakeUnique<TrayAction>()),
sky5b45ed82017-03-27 02:54:23590 vpn_list_(base::MakeUnique<VpnList>()),
591 window_cycle_controller_(base::MakeUnique<WindowCycleController>()),
592 window_selector_controller_(base::MakeUnique<WindowSelectorController>()),
sky7db5ccf2017-03-14 21:52:29593 app_list_(base::MakeUnique<app_list::AppList>()),
yusukes1168eda2016-04-27 07:52:08594 link_handler_model_factory_(nullptr),
jamescookac6724332017-03-21 02:54:43595 tray_bluetooth_helper_(base::MakeUnique<TrayBluetoothHelper>()),
kylechar7a067ec2017-01-07 01:16:28596 display_configurator_(new display::DisplayConfigurator()),
sadrul7a8785e2016-02-12 21:54:35597 native_cursor_manager_(nullptr),
[email protected]b6ba05d902013-10-04 21:38:45598 simulate_modal_window_open_for_testing_(false),
msw3f439af2016-09-08 22:35:26599 is_touch_hud_projection_enabled_(false) {
skyabcae812017-01-18 17:01:34600 // TODO(sky): better refactor cash/mash dependencies. Perhaps put all cash
sky11cf8db92017-04-10 23:38:08601 // state on ShellPortClassic. http://crbug.com/671246.
skyabcae812017-01-18 17:01:34602
skycfaad892017-04-28 20:52:58603 gpu_support_.reset(shell_delegate_->CreateGPUSupport());
604
skye5fd1222017-04-12 18:43:23605 // Don't use Shell::GetAshConfig() as |instance_| has not yet been set.
606 if (shell_port_->GetAshConfig() != Config::MASH) {
skyabcae812017-01-18 17:01:34607 display_manager_.reset(ScreenAsh::CreateDisplayManager());
608 window_tree_host_manager_.reset(new WindowTreeHostManager);
609 user_metrics_recorder_.reset(new UserMetricsRecorder);
610 }
[email protected]b6ba05d902013-10-04 21:38:45611
[email protected]093b8d642014-04-03 20:59:28612 PowerStatus::Initialize();
sky5ad143a2017-03-22 04:31:23613
Xiyuan Xia22b1a6c2017-04-18 22:46:01614 session_controller_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45615}
616
617Shell::~Shell() {
618 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
619
sky11cf8db92017-04-10 23:38:08620 const Config config = shell_port_->GetAshConfig();
skyabcae812017-01-18 17:01:34621
skyb5e13442017-04-06 02:11:23622 if (config != Config::MASH)
skyabcae812017-01-18 17:01:34623 user_metrics_recorder_->OnShellShuttingDown();
bruthigc24d11f2015-06-09 21:30:03624
skyb073203a2017-03-13 16:59:16625 shell_delegate_->PreShutdown();
[email protected]050e77182014-03-25 15:29:16626
[email protected]b6ba05d902013-10-04 21:38:45627 // Remove the focus from any window. This will prevent overhead and side
628 // effects (e.g. crashes) from changing focus during shutdown.
629 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18630 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45631
632 // Please keep in same order as in Init() because it's easy to miss one.
633 if (window_modality_controller_)
634 window_modality_controller_.reset();
skyb5e13442017-04-06 02:11:23635 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:34636 RemovePreTargetHandler(
637 window_tree_host_manager_->input_method_event_handler());
638 }
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());
skya5888e82017-05-05 17:56:31653 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:34654 RemovePreTargetHandler(system_gesture_filter_.get());
655 RemovePreTargetHandler(mouse_cursor_filter_.get());
skya5888e82017-05-05 17:56:31656 }
hariank0dd03dd2016-07-14 23:47:33657 RemovePreTargetHandler(modality_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45658
659 // TooltipController is deleted with the Shell so removing its references.
660 RemovePreTargetHandler(tooltip_controller_.get());
661
jonross0af45212015-01-13 18:55:46662 screen_orientation_controller_.reset();
yiyixa68ade512016-09-01 17:38:13663 screen_layout_observer_.reset();
jonross0af45212015-01-13 18:55:46664
jamescook01bf23e72017-01-09 19:58:15665 // Destroy the virtual keyboard controller before the maximize mode controller
666 // since the latters destructor triggers events that the former is listening
667 // to but no longer cares about.
rsadambbaf2c82015-01-07 17:54:13668 virtual_keyboard_controller_.reset();
jonross0af45212015-01-13 18:55:46669
[email protected]2a57beb52014-06-09 20:02:26670 // Destroy maximize mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57671 // need to be removed.
sky5ab16472017-03-21 19:35:08672 maximize_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57673
jdufault551152e2016-01-27 19:48:43674 // Destroy the keyboard before closing the shelf, since it will invoke a shelf
675 // layout.
676 DeactivateKeyboard();
677
sky07a24d42017-03-09 23:57:30678 toast_manager_.reset();
yoshiki32f51632016-03-24 01:24:43679
jdufault551152e2016-01-27 19:48:43680 // Destroy SystemTrayDelegate before destroying the status area(s). Make sure
681 // to deinitialize the shelf first, as it is initialized after the delegate.
sky11cf8db92017-04-10 23:38:08682 for (WmWindow* root : shell_port_->GetAllRootWindows())
jamescookb551aba2016-09-01 01:00:16683 root->GetRootWindowController()->GetShelf()->ShutdownShelfWidget();
jamescookac6724332017-03-21 02:54:43684 tray_bluetooth_helper_.reset();
sky79fa34712017-03-20 23:46:47685 DeleteSystemTrayDelegate();
[email protected]b6ba05d902013-10-04 21:38:45686
[email protected]b6ba05d902013-10-04 21:38:45687 // Drag-and-drop must be canceled prior to close all windows.
688 drag_drop_controller_.reset();
689
Xiyuan Xia22b1a6c2017-04-18 22:46:01690 // Controllers who have WindowObserver added must be deleted
691 // before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03692
[email protected]8c9d12a2013-12-06 18:39:03693 // VideoActivityNotifier must be deleted before |video_detector_| is
694 // deleted because it's observing video activity through
derat83b761392016-07-11 16:44:44695 // VideoDetector::Observer interface.
[email protected]8c9d12a2013-12-06 18:39:03696 video_activity_notifier_.reset();
[email protected]8c9d12a2013-12-06 18:39:03697 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25698 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03699
700 shadow_controller_.reset();
701 resize_shadow_controller_.reset();
702
sky37f0dd12016-07-19 18:00:59703 // Has to happen before ~MruWindowTracker.
sky5b45ed82017-03-27 02:54:23704 window_cycle_controller_.reset();
705 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03706
skyabcae812017-01-18 17:01:34707 CloseAllRootWindowChildWindows();
708
afakhry58159392015-05-22 02:45:52709 // MruWindowTracker must be destroyed after all windows have been deleted to
710 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
711 // path. (crbug.com/485438).
sky5ab16472017-03-21 19:35:08712 mru_window_tracker_.reset();
[email protected]b6ba05d902013-10-04 21:38:45713
[email protected]b6ba05d902013-10-04 21:38:45714 // These need a valid Shell instance to clean up properly, so explicitly
715 // delete them before invalidating the instance.
716 // Alphabetical. TODO(oshima): sort.
717 magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45718 tooltip_controller_.reset();
719 event_client_.reset();
[email protected]3537d472014-01-15 05:45:31720 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45721 visibility_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45722
723 power_button_controller_.reset();
724 lock_state_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45725
hidehiko6821ca42016-06-18 11:12:23726 screen_pinning_controller_.reset();
727
[email protected]b6ba05d902013-10-04 21:38:45728 resolution_notification_controller_.reset();
oshima5a296e82016-04-29 01:32:27729 screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49730 mouse_cursor_filter_.reset();
hariank0dd03dd2016-07-14 23:47:33731 modality_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45732
[email protected]03122891a2014-05-13 23:56:49733 touch_transformer_controller_.reset();
warx533c8f62016-04-12 01:19:43734 audio_a11y_controller_.reset();
sammiequon203ae022016-09-18 17:23:42735 laser_pointer_controller_.reset();
736 partial_magnification_controller_.reset();
warx533c8f62016-04-12 01:19:43737
[email protected]b6ba05d902013-10-04 21:38:45738 // This also deletes all RootWindows. Note that we invoke Shutdown() on
oshimae2818922015-07-28 01:18:52739 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
740 // destruction
[email protected]b6ba05d902013-10-04 21:38:45741 // of its owned RootWindowControllers relies on the value.
rjkroege2c9305402016-09-07 00:21:45742 ScreenAsh::CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12743 display_configuration_controller_.reset();
dtseng4ae0a882016-04-15 21:39:27744
sky15ef0aa2017-01-20 18:55:59745 // AppListDelegateImpl depends upon AppList.
746 app_list_delegate_impl_.reset();
747
sky07a24d42017-03-09 23:57:30748 // These members access Shell in their destructors.
749 wallpaper_controller_.reset();
750 accessibility_delegate_.reset();
751
752 // Balances the Install() in Initialize().
753 views::FocusManagerFactory::Install(nullptr);
754
sky5ad143a2017-03-22 04:31:23755 // ShelfWindowWatcher has window observers and a pointer to the shelf model.
756 shelf_window_watcher_.reset();
757
758 // ShelfItemDelegate subclasses it owns have complex cleanup to run (e.g. ARC
759 // shelf items in Chrome) so explicitly shutdown early.
760 shelf_model()->DestroyItemDelegates();
761
msw5138f3d2017-04-20 00:22:07762 // Notify the ShellDelegate that the shelf is shutting down.
msw5c06364c2017-04-27 02:49:06763 // TODO(msw): Refine ChromeLauncherController lifetime management.
msw5138f3d2017-04-20 00:22:07764 shell_delegate_->ShelfShutdown();
sky5ad143a2017-03-22 04:31:23765
tibellb93c729b2017-03-30 00:45:09766 // Removes itself as an observer of |pref_service_|.
sky5ad143a2017-03-22 04:31:23767 shelf_controller_.reset();
768
sky11cf8db92017-04-10 23:38:08769 shell_port_->Shutdown();
sky5ad143a2017-03-22 04:31:23770
sky27344382017-03-08 21:30:32771 // Depends on |focus_controller_|, so must be destroyed before.
oshimae2818922015-07-28 01:18:52772 window_tree_host_manager_.reset();
sky27344382017-03-08 21:30:32773 focus_controller_->RemoveObserver(this);
sky68612712017-04-27 04:45:04774 if (config != Config::CLASSIC &&
775 window_tree_client_->focus_synchronizer()->active_focus_client() ==
776 focus_controller_.get()) {
777 window_tree_client_->focus_synchronizer()->SetSingletonFocusClient(nullptr);
778 }
sky27344382017-03-08 21:30:32779 focus_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45780 screen_position_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45781
robert.bradfordab052492015-05-06 11:09:56782 display_color_manager_.reset();
[email protected]7bc49bd2014-01-22 09:30:34783 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11784 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45785 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11786 display_configurator_->RemoveObserver(display_error_observer_.get());
jdufault88fb76652015-04-30 22:36:43787 if (projecting_observer_) {
[email protected]1e31cbd2014-04-07 20:06:11788 display_configurator_->RemoveObserver(projecting_observer_.get());
sky00c813f2017-03-08 22:48:55789 RemoveShellObserver(projecting_observer_.get());
jdufault88fb76652015-04-30 22:36:43790 }
[email protected]b6ba05d902013-10-04 21:38:45791 display_change_observer_.reset();
kylechar98748a52016-12-03 01:33:22792 shutdown_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45793
[email protected]093b8d642014-04-03 20:59:28794 PowerStatus::Shutdown();
pneubeck8be1f5422014-10-09 16:46:18795
796 // Ensure that DBusThreadManager outlives this Shell.
797 DCHECK(chromeos::DBusThreadManager::IsInitialized());
[email protected]b6ba05d902013-10-04 21:38:45798
sky88bd4be62016-06-09 17:34:41799 // Needs to happen right before |instance_| is reset.
sky11cf8db92017-04-10 23:38:08800 shell_port_.reset();
Xiyuan Xia22b1a6c2017-04-18 22:46:01801 session_controller_->RemoveObserver(this);
skyb073203a2017-03-13 16:59:16802 wallpaper_delegate_.reset();
tibellb93c729b2017-03-30 00:45:09803 pref_service_ = nullptr;
skyb073203a2017-03-13 16:59:16804 shell_delegate_.reset();
sky88bd4be62016-06-09 17:34:41805
[email protected]b6ba05d902013-10-04 21:38:45806 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18807 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45808}
809
[email protected]1b4c7472014-05-15 18:32:23810void Shell::Init(const ShellInitParams& init_params) {
sky11cf8db92017-04-10 23:38:08811 const Config config = shell_port_->GetAshConfig();
skyabcae812017-01-18 17:01:34812
sky07a24d42017-03-09 23:57:30813 blocking_pool_ = init_params.blocking_pool;
814
skyb073203a2017-03-13 16:59:16815 wallpaper_delegate_ = shell_delegate_->CreateWallpaperDelegate();
816
817 // Can be null in tests.
skye5fd1222017-04-12 18:43:23818 if (config == Config::MASH && shell_delegate_->GetShellConnector()) {
afakhry606424bd2017-05-16 17:08:16819 auto pref_registry = base::MakeShared<PrefRegistrySimple>();
820 Shell::RegisterPrefs(pref_registry.get());
tibellb93c729b2017-03-30 00:45:09821 prefs::ConnectToPrefService(
afakhry606424bd2017-05-16 17:08:16822 shell_delegate_->GetShellConnector(), std::move(pref_registry),
tibell2961ff42017-04-06 05:31:16823 std::vector<PrefValueStore::PrefStoreType>(),
tibellb93c729b2017-03-30 00:45:09824 base::Bind(&Shell::OnPrefServiceInitialized, base::Unretained(this)),
825 prefs::mojom::kForwarderServiceName);
jonrossc4ba10602017-04-07 20:51:05826 }
skyb073203a2017-03-13 16:59:16827
sky11cf8db92017-04-10 23:38:08828 // Some delegates access ShellPort during their construction. Create them here
829 // instead of the ShellPort constructor.
skyb073203a2017-03-13 16:59:16830 accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate());
831 palette_delegate_ = shell_delegate_->CreatePaletteDelegate();
sky07a24d42017-03-09 23:57:30832 toast_manager_ = base::MakeUnique<ToastManager>();
833
sky07a24d42017-03-09 23:57:30834 // Install the custom factory early on so that views::FocusManagers for Tray,
835 // Shelf, and WallPaper could be created by the factory.
836 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
837
838 wallpaper_controller_ = base::MakeUnique<WallpaperController>(blocking_pool_);
839
840 // Start devtools server
841 devtools_server_ = ui::devtools::UiDevToolsServer::Create(nullptr);
842 if (devtools_server_) {
843 auto dom_backend = base::MakeUnique<devtools::AshDevToolsDOMAgent>();
844 auto css_backend =
845 base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_backend.get());
846 auto devtools_client = base::MakeUnique<ui::devtools::UiDevToolsClient>(
847 "Ash", devtools_server_.get());
848 devtools_client->AddAgent(std::move(dom_backend));
849 devtools_client->AddAgent(std::move(css_backend));
850 devtools_server_->AttachClient(std::move(devtools_client));
851 }
jamescook3daef412016-07-14 23:53:30852
skye5fd1222017-04-12 18:43:23853 if (config == Config::MASH)
sky15ef0aa2017-01-20 18:55:59854 app_list_delegate_impl_ = base::MakeUnique<AppListDelegateImpl>();
855
sky11cf8db92017-04-10 23:38:08856 // TODO(sky): move creation to ShellPort.
skye5fd1222017-04-12 18:43:23857 if (config != Config::MASH)
skyabcae812017-01-18 17:01:34858 immersive_handler_factory_ = base::MakeUnique<ImmersiveHandlerFactoryAsh>();
skyb7b54092016-08-19 16:00:09859
sky6624a7af2016-05-27 18:47:49860 scoped_overview_animation_settings_factory_.reset(
861 new ScopedOverviewAnimationSettingsFactoryAura);
sky5ab16472017-03-21 19:35:08862 window_positioner_ = base::MakeUnique<WindowPositioner>();
sky984c1892016-04-20 00:00:34863
sky494c6cbd2017-03-27 20:57:48864 if (config == Config::CLASSIC) {
865 // TODO: needs to work in mus. http://crbug.com/705592.
skyabcae812017-01-18 17:01:34866 native_cursor_manager_ = new AshNativeCursorManager;
867 cursor_manager_.reset(
868 new CursorManager(base::WrapUnique(native_cursor_manager_)));
869 }
skyfee520c2016-02-11 19:57:46870
skyb073203a2017-03-13 16:59:16871 shell_delegate_->PreInit();
skycfaad892017-04-28 20:52:58872 // TODO(sky): remove MASH from here.
873 bool display_initialized =
874 (config == Config::MASH || display_manager_->InitFromCommandLine());
875 if (config == Config::MUS && !display_initialized) {
876 // Run display configuration off device in mus mode.
877 display_manager_->set_configure_displays(true);
878 display_configurator_->set_configure_display(true);
879 }
880 if (config != Config::MASH) {
881 // TODO(sky): should work in mash too.
skyabcae812017-01-18 17:01:34882 display_configuration_controller_.reset(new DisplayConfigurationController(
883 display_manager_.get(), window_tree_host_manager_.get()));
skycfaad892017-04-28 20:52:58884 display_configurator_->Init(shell_port_->CreateNativeDisplayDelegate(),
885 !gpu_support_->IsPanelFittingDisabled());
skyabcae812017-01-18 17:01:34886 }
[email protected]0249a6532013-10-31 06:53:34887
pneubeck8be1f5422014-10-09 16:46:18888 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell.
889 chromeos::DBusThreadManager* dbus_thread_manager =
890 chromeos::DBusThreadManager::Get();
891 projecting_observer_.reset(
892 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient()));
[email protected]1e31cbd2014-04-07 20:06:11893 display_configurator_->AddObserver(projecting_observer_.get());
sky00c813f2017-03-08 22:48:55894 AddShellObserver(projecting_observer_.get());
[email protected]72bce522014-02-10 21:11:26895
skycfaad892017-04-28 20:52:58896 // TODO(sky): once simplified display management is enabled for mash
897 // config == Config::MUS should be config != Config::CLASSIC.
898 if (!display_initialized &&
899 (config == Config::MUS || chromeos::IsRunningAsSystemCompositor())) {
kylecharf2e4e412016-12-04 04:21:35900 display_change_observer_ = base::MakeUnique<display::DisplayChangeObserver>(
kylechar98748a52016-12-03 01:33:22901 display_configurator_.get(), display_manager_.get());
902
903 shutdown_observer_ =
904 base::MakeUnique<ShutdownObserver>(display_configurator_.get());
905
[email protected]b6ba05d902013-10-04 21:38:45906 // Register |display_change_observer_| first so that the rest of
907 // observer gets invoked after the root windows are configured.
[email protected]1e31cbd2014-04-07 20:06:11908 display_configurator_->AddObserver(display_change_observer_.get());
[email protected]093b8d642014-04-03 20:59:28909 display_error_observer_.reset(new DisplayErrorObserver());
[email protected]1e31cbd2014-04-07 20:06:11910 display_configurator_->AddObserver(display_error_observer_.get());
911 display_configurator_->set_state_controller(display_change_observer_.get());
912 display_configurator_->set_mirroring_controller(display_manager_.get());
913 display_configurator_->ForceInitialConfigure(
jamescookfda159002016-10-21 18:48:57914 base::CommandLine::ForCurrentProcess()->HasSwitch(
915 chromeos::switches::kFirstExecAfterBoot)
916 ? kChromeOsBootColor
917 : 0);
[email protected]b6ba05d902013-10-04 21:38:45918 display_initialized = true;
919 }
msw3f439af2016-09-08 22:35:26920 display_color_manager_.reset(new DisplayColorManager(
921 display_configurator_.get(), init_params.blocking_pool));
stevenjb537c5c3f2016-01-20 23:38:12922
[email protected]b6ba05d902013-10-04 21:38:45923 if (!display_initialized)
[email protected]0249a6532013-10-31 06:53:34924 display_manager_->InitDefaultDisplay();
[email protected]b6ba05d902013-10-04 21:38:45925
skyb5e13442017-04-06 02:11:23926 if (config == Config::CLASSIC) {
skyabcae812017-01-18 17:01:34927 display_manager_->RefreshFontParams();
[email protected]68d6080e2014-08-21 23:06:32928
skyabcae812017-01-18 17:01:34929 aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
930 aura::Env::GetInstance()->set_context_factory_private(
931 init_params.context_factory_private);
932 }
[email protected]ecca62b2013-10-09 16:18:53933
[email protected]b6ba05d902013-10-04 21:38:45934 // The WindowModalityController needs to be at the front of the input event
935 // pretarget handler list to ensure that it processes input events when modal
936 // windows are active.
jamescookb8dcef522016-06-25 14:42:55937 window_modality_controller_.reset(new ::wm::WindowModalityController(this));
[email protected]b6ba05d902013-10-04 21:38:45938
[email protected]e319c7e2014-03-14 19:56:14939 env_filter_.reset(new ::wm::CompoundEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45940 AddPreTargetHandler(env_filter_.get());
941
sky27344382017-03-08 21:30:32942 // FocusController takes ownership of AshFocusRules.
943 focus_controller_ =
944 base::MakeUnique<::wm::FocusController>(new wm::AshFocusRules());
945 focus_controller_->AddObserver(this);
sky68612712017-04-27 04:45:04946 if (config != Config::CLASSIC) {
947 window_tree_client_->focus_synchronizer()->SetSingletonFocusClient(
948 focus_controller_.get());
949 }
[email protected]b6ba05d902013-10-04 21:38:45950
[email protected]093b8d642014-04-03 20:59:28951 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:45952
sky11cf8db92017-04-10 23:38:08953 shell_port_->CreatePrimaryHost();
sky27344382017-03-08 21:30:32954 root_window_for_new_windows_ = WmWindow::Get(GetPrimaryRootWindow());
[email protected]b6ba05d902013-10-04 21:38:45955
skye5fd1222017-04-12 18:43:23956 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:34957 resolution_notification_controller_.reset(
958 new ResolutionNotificationController);
959 }
[email protected]b6ba05d902013-10-04 21:38:45960
deratc6250a02017-01-25 05:51:53961 if (cursor_manager_) {
oshimaf84b0da722016-04-27 19:47:19962 cursor_manager_->SetDisplay(
963 display::Screen::GetScreen()->GetPrimaryDisplay());
deratc6250a02017-01-25 05:51:53964 }
[email protected]b6ba05d902013-10-04 21:38:45965
sky11cf8db92017-04-10 23:38:08966 accelerator_controller_ = shell_port_->CreateAcceleratorController();
sky5ab16472017-03-21 19:35:08967 maximize_mode_controller_ = base::MakeUnique<MaximizeModeController>();
[email protected]b6ba05d902013-10-04 21:38:45968
moshayedic229a522017-05-05 18:14:26969 if (!ShouldUseIMEService()) {
970 // Not applicable when using IME service as events are already routed to
971 // InputMethod first.
skyabcae812017-01-18 17:01:34972 AddPreTargetHandler(
973 window_tree_host_manager_->input_method_event_handler());
974 }
oshima5e0fff82015-06-27 01:31:30975
spange9b51272014-12-11 01:20:10976 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06977 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
spange9b51272014-12-11 01:20:10978 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06979 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:39980
[email protected]b6ba05d902013-10-04 21:38:45981 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:45982
derat2d4e62d2015-01-09 16:09:17983 // ui::UserActivityDetector passes events to observers, so let them get
[email protected]b6ba05d902013-10-04 21:38:45984 // rewritten first.
derat2d4e62d2015-01-09 16:09:17985 user_activity_detector_.reset(new ui::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:45986
[email protected]093b8d642014-04-03 20:59:28987 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45988 AddPreTargetHandler(overlay_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45989
[email protected]60d677d2014-05-30 13:07:02990 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
dchenga94547472016-04-08 08:41:11991 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
sky81a2d792017-03-17 19:14:39992 accelerator_controller_->accelerator_history()));
[email protected]b6ba05d902013-10-04 21:38:45993 AddPreTargetHandler(accelerator_filter_.get());
994
[email protected]093b8d642014-04-03 20:59:28995 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:45996 AddPreTargetHandler(event_transformation_handler_.get());
997
sky11cf8db92017-04-10 23:38:08998 toplevel_window_event_handler_ =
999 base::MakeUnique<ToplevelWindowEventHandler>();
[email protected]3537d472014-01-15 05:45:311000
sky83b1bb12017-04-24 20:29:281001 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:341002 system_gesture_filter_.reset(new SystemGestureEventFilter);
1003 AddPreTargetHandler(system_gesture_filter_.get());
1004 }
[email protected]b6ba05d902013-10-04 21:38:451005
[email protected]354520b2014-06-21 04:31:011006 sticky_keys_controller_.reset(new StickyKeysController);
sky13857152017-03-29 15:46:041007 screen_pinning_controller_ = base::MakeUnique<ScreenPinningController>();
[email protected]354520b2014-06-21 04:31:011008
jamescookd9f152f2016-11-15 00:53:081009 lock_state_controller_ =
sky5b45ed82017-03-27 02:54:231010 base::MakeUnique<LockStateController>(shutdown_controller_.get());
jamescookb8dcef522016-06-25 14:42:551011 power_button_controller_.reset(
1012 new PowerButtonController(lock_state_controller_.get()));
[email protected]685442f32014-02-28 10:40:061013 // Pass the initial display state to PowerButtonController.
1014 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:091015 display_configurator_->cached_displays());
jamescook01bf23e72017-01-09 19:58:151016
derat036f91b92017-05-05 00:33:181017 // Forward user activity from the window server to |user_activity_detector_|.
derat94887a22017-01-20 18:17:251018 // The connector is unavailable in some tests.
derat036f91b92017-05-05 00:33:181019 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::MUS &&
1020 shell_delegate_->GetShellConnector()) {
derat94887a22017-01-20 18:17:251021 ui::mojom::UserActivityMonitorPtr user_activity_monitor;
skyb073203a2017-03-13 16:59:161022 shell_delegate_->GetShellConnector()->BindInterface(ui::mojom::kServiceName,
1023 &user_activity_monitor);
derat94887a22017-01-20 18:17:251024 user_activity_forwarder_ = base::MakeUnique<aura::UserActivityForwarder>(
1025 std::move(user_activity_monitor), user_activity_detector_.get());
1026 }
1027
[email protected]093b8d642014-04-03 20:59:281028 drag_drop_controller_.reset(new DragDropController);
oshima5a296e82016-04-29 01:32:271029 // |screenshot_controller_| needs to be created (and prepended as a
mukai19274bdd2015-02-24 22:37:481030 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
oshima5a296e82016-04-29 01:32:271031 // process mouse events prior to screenshot session.
mukai19274bdd2015-02-24 22:37:481032 // See http://crbug.com/459214
oshima5a296e82016-04-29 01:32:271033 screenshot_controller_.reset(new ScreenshotController());
skya5888e82017-05-05 17:56:311034 // TODO: evaluate if MouseCursorEventFilter needs to work for mash.
skyb5e13442017-04-06 02:11:231035 // http://crbug.com/706474.
skya5888e82017-05-05 17:56:311036 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:341037 mouse_cursor_filter_.reset(new MouseCursorEventFilter());
1038 PrependPreTargetHandler(mouse_cursor_filter_.get());
1039 }
[email protected]b6ba05d902013-10-04 21:38:451040
1041 // Create Controllers that may need root window.
1042 // TODO(oshima): Move as many controllers before creating
1043 // RootWindowController as possible.
1044 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:451045
sammiequon203ae022016-09-18 17:23:421046 laser_pointer_controller_.reset(new LaserPointerController());
1047 partial_magnification_controller_.reset(new PartialMagnificationController());
sammiequon203ae022016-09-18 17:23:421048
jamescookb8dcef522016-06-25 14:42:551049 magnification_controller_.reset(MagnificationController::CreateInstance());
sky5ab16472017-03-21 19:35:081050 mru_window_tracker_ = base::MakeUnique<MruWindowTracker>();
[email protected]b6ba05d902013-10-04 21:38:451051
[email protected]55398d22013-10-10 19:49:201052 autoclick_controller_.reset(AutoclickController::CreateInstance());
1053
[email protected]b6ba05d902013-10-04 21:38:451054 high_contrast_controller_.reset(new HighContrastController);
1055 video_detector_.reset(new VideoDetector);
[email protected]b6ba05d902013-10-04 21:38:451056
oshimaebbe63772015-02-19 18:41:321057 tooltip_controller_.reset(new views::corewm::TooltipController(
dchenga94547472016-04-08 08:41:111058 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451059 AddPreTargetHandler(tooltip_controller_.get());
1060
hariank0dd03dd2016-07-14 23:47:331061 modality_filter_.reset(new SystemModalContainerEventFilter(this));
1062 AddPreTargetHandler(modality_filter_.get());
1063
[email protected]093b8d642014-04-03 20:59:281064 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451065
skyb073203a2017-03-13 16:59:161066 session_state_delegate_.reset(shell_delegate_->CreateSessionStateDelegate());
skyabcae812017-01-18 17:01:341067 // Must occur after Shell has installed its early pre-target handlers (for
1068 // example, WindowModalityController).
sky11cf8db92017-04-10 23:38:081069 shell_port_->CreatePointerWatcherAdapter();
[email protected]b6ba05d902013-10-04 21:38:451070
[email protected]093b8d642014-04-03 20:59:281071 resize_shadow_controller_.reset(new ResizeShadowController());
sky27344382017-03-08 21:30:321072 shadow_controller_.reset(new ::wm::ShadowController(focus_controller_.get()));
[email protected]b6ba05d902013-10-04 21:38:451073
sky79fa34712017-03-20 23:46:471074 SetSystemTrayDelegate(
skyb073203a2017-03-13 16:59:161075 base::WrapUnique(shell_delegate_->CreateSystemTrayDelegate()));
[email protected]b6ba05d902013-10-04 21:38:451076
jamescookac6724332017-03-21 02:54:431077 // May trigger initialization of the Bluetooth adapter.
1078 tray_bluetooth_helper_->Initialize();
1079
kylechar55f0eaf22017-01-11 22:57:371080 // Create AshTouchTransformController before
oshimae2818922015-07-28 01:18:521081 // WindowTreeHostManager::InitDisplays()
kylechar55f0eaf22017-01-11 22:57:371082 // since AshTouchTransformController listens on
oshimae2818922015-07-28 01:18:521083 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
skycfaad892017-04-28 20:52:581084 // TODO(sky): needs to to work for mus too.
1085 if (config == Config::CLASSIC) {
skyabcae812017-01-18 17:01:341086 touch_transformer_controller_.reset(new AshTouchTransformController(
1087 display_configurator_.get(), display_manager_.get()));
1088 }
[email protected]03122891a2014-05-13 23:56:491089
sky11cf8db92017-04-10 23:38:081090 keyboard_ui_ = shell_port_->CreateKeyboardUI();
skyfee520c2016-02-11 19:57:461091
sky11cf8db92017-04-10 23:38:081092 shell_port_->InitHosts(init_params);
[email protected]b6ba05d902013-10-04 21:38:451093
rsadam9172bc8a2014-10-29 23:37:381094 // Needs to be created after InitDisplays() since it may cause the virtual
1095 // keyboard to be deployed.
sky83b1bb12017-04-24 20:29:281096 if (config != Config::MASH)
skyabcae812017-01-18 17:01:341097 virtual_keyboard_controller_.reset(new VirtualKeyboardController);
rsadam9172bc8a2014-10-29 23:37:381098
warx533c8f62016-04-12 01:19:431099 audio_a11y_controller_.reset(new chromeos::AudioA11yController);
warx533c8f62016-04-12 01:19:431100
msw0e91d932016-08-25 22:34:091101 // Initialize the wallpaper after the RootWindowController has been created,
1102 // otherwise the widget will not paint when restoring after a browser crash.
1103 // Also, initialize after display initialization to ensure correct sizing.
skyb073203a2017-03-13 16:59:161104 wallpaper_delegate_->InitializeWallpaper();
[email protected]b6ba05d902013-10-04 21:38:451105
sadrul7a8785e2016-02-12 21:54:351106 if (cursor_manager_) {
1107 if (initially_hide_cursor_)
1108 cursor_manager_->HideCursor();
ergeeba7c622017-04-25 18:06:161109 cursor_manager_->SetCursor(ui::CursorType::kPointer);
sadrul7a8785e2016-02-12 21:54:351110 }
[email protected]b6ba05d902013-10-04 21:38:451111
[email protected]093b8d642014-04-03 20:59:281112 power_event_observer_.reset(new PowerEventObserver());
[email protected]ded58fd2013-10-09 07:56:551113 user_activity_notifier_.reset(
[email protected]b0fa7012014-04-16 12:50:571114 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
[email protected]ded58fd2013-10-09 07:56:551115 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281116 new VideoActivityNotifier(video_detector_.get()));
1117 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
skye5fd1222017-04-12 18:43:231118 if (config != Config::MASH) {
skyabcae812017-01-18 17:01:341119 screen_orientation_controller_.reset(new ScreenOrientationController());
1120 screen_layout_observer_.reset(new ScreenLayoutObserver());
1121 }
yiyix90cfee22017-02-16 05:38:181122 sms_observer_.reset(new SmsObserver());
jamescook01bf23e72017-01-09 19:58:151123
[email protected]b6ba05d902013-10-04 21:38:451124 // The compositor thread and main message loop have to be running in
1125 // order to create mirror window. Run it after the main message loop
1126 // is started.
skye5fd1222017-04-12 18:43:231127 if (config != Config::MASH)
skyabcae812017-01-18 17:01:341128 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031129
sky00c813f2017-03-08 22:48:551130 for (auto& observer : shell_observers_)
ericwilligers5eff47d2016-10-17 19:19:181131 observer.OnShellInitialized();
phweiss0bf64c52015-11-17 12:56:181132
skye5fd1222017-04-12 18:43:231133 if (config != Config::MASH)
skyabcae812017-01-18 17:01:341134 user_metrics_recorder_->OnShellInitialized();
[email protected]b6ba05d902013-10-04 21:38:451135}
1136
[email protected]51f438112013-11-18 19:32:501137void Shell::InitKeyboard() {
[email protected]b6ba05d902013-10-04 21:38:451138 if (keyboard::IsKeyboardEnabled()) {
[email protected]a0b3fb882014-04-07 19:26:031139 if (keyboard::KeyboardController::GetInstance()) {
[email protected]b6ba05d902013-10-04 21:38:451140 RootWindowControllerList controllers = GetAllRootWindowControllers();
1141 for (RootWindowControllerList::iterator iter = controllers.begin();
1142 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:031143 (*iter)->DeactivateKeyboard(
1144 keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:451145 }
1146 }
[email protected]a0b3fb882014-04-07 19:26:031147 keyboard::KeyboardController::ResetInstance(
skyb073203a2017-03-13 16:59:161148 new keyboard::KeyboardController(shell_delegate_->CreateKeyboardUI(),
1149 virtual_keyboard_controller_.get()));
[email protected]b6ba05d902013-10-04 21:38:451150 }
1151}
1152
[email protected]41baaed2013-11-09 04:18:261153void Shell::InitRootWindow(aura::Window* root_window) {
sky27344382017-03-08 21:30:321154 DCHECK(focus_controller_);
[email protected]d90b8392012-06-13 09:34:561155 DCHECK(visibility_controller_.get());
1156 DCHECK(drag_drop_controller_.get());
[email protected]d90b8392012-06-13 09:34:561157
sky27344382017-03-08 21:30:321158 aura::client::SetFocusClient(root_window, focus_controller_.get());
1159 aura::client::SetActivationClient(root_window, focus_controller_.get());
1160 root_window->AddPreTargetHandler(focus_controller_.get());
[email protected]d90b8392012-06-13 09:34:561161 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
1162 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]8d625fb2012-07-18 16:40:061163 aura::client::SetScreenPositionClient(root_window,
1164 screen_position_controller_.get());
sadrul7a8785e2016-02-12 21:54:351165 aura::client::SetCursorClient(root_window, cursor_manager_.get());
[email protected]54a37cdc2012-07-25 19:16:011166 aura::client::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381167 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561168
[email protected]3537d472014-01-15 05:45:311169 aura::client::SetWindowMoveClient(root_window,
jamescookb8dcef522016-06-25 14:42:551170 toplevel_window_event_handler_.get());
[email protected]3537d472014-01-15 05:45:311171 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1172 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
[email protected]d90b8392012-06-13 09:34:561173}
1174
sky79fa34712017-03-20 23:46:471175void Shell::SetSystemTrayDelegate(
1176 std::unique_ptr<SystemTrayDelegate> delegate) {
1177 DCHECK(delegate);
1178 system_tray_delegate_ = std::move(delegate);
1179 system_tray_delegate_->Initialize();
sky11cf8db92017-04-10 23:38:081180 // Accesses ShellPort in its constructor.
sky79fa34712017-03-20 23:46:471181 logout_confirmation_controller_.reset(new LogoutConfirmationController(
1182 base::Bind(&SystemTrayController::SignOut,
1183 base::Unretained(system_tray_controller_.get()))));
1184}
1185
1186void Shell::DeleteSystemTrayDelegate() {
1187 DCHECK(system_tray_delegate_);
sky11cf8db92017-04-10 23:38:081188 // Accesses ShellPort in its destructor.
sky79fa34712017-03-20 23:46:471189 logout_confirmation_controller_.reset();
1190 system_tray_delegate_.reset();
1191}
1192
skyabcae812017-01-18 17:01:341193void Shell::CloseAllRootWindowChildWindows() {
sky11cf8db92017-04-10 23:38:081194 for (WmWindow* wm_root_window : shell_port_->GetAllRootWindows()) {
skyabcae812017-01-18 17:01:341195 aura::Window* root_window = wm_root_window->aura_window();
1196 RootWindowController* controller = GetRootWindowController(root_window);
1197 if (controller) {
1198 controller->CloseChildWindows();
1199 } else {
1200 while (!root_window->children().empty()) {
1201 aura::Window* child = root_window->children()[0];
1202 delete child;
1203 }
1204 }
1205 }
1206}
1207
[email protected]c0ce80e2012-10-05 23:28:271208bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1209 RootWindowControllerList controllers = GetAllRootWindowControllers();
oshima9a61ecf2016-06-18 10:43:051210 for (RootWindowController* controller : controllers) {
1211 if (controller->CanWindowReceiveEvents(window))
[email protected]602022b2014-03-31 17:07:311212 return true;
[email protected]c0ce80e2012-10-05 23:28:271213 }
1214 return false;
1215}
1216
[email protected]049cf34b2012-12-07 17:15:481217////////////////////////////////////////////////////////////////////////////////
1218// Shell, ui::EventTarget overrides:
1219
[email protected]869f6352012-12-06 20:47:171220bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411221 return true;
1222}
1223
1224ui::EventTarget* Shell::GetParentTarget() {
[email protected]ff0278852013-11-05 22:35:481225 return aura::Env::GetInstance();
[email protected]5097e692012-10-30 22:08:411226}
1227
dchenga94547472016-04-08 08:41:111228std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1229 return std::unique_ptr<ui::EventTargetIterator>();
[email protected]3e670aa2013-12-02 19:04:321230}
1231
1232ui::EventTargeter* Shell::GetEventTargeter() {
1233 NOTREACHED();
achuith287b26e2015-09-03 17:49:181234 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321235}
1236
sky27344382017-03-08 21:30:321237void Shell::OnWindowActivated(
1238 aura::client::ActivationChangeObserver::ActivationReason reason,
1239 aura::Window* gained_active,
1240 aura::Window* lost_active) {
1241 WmWindow* gained_active_wm = WmWindow::Get(gained_active);
1242 if (gained_active_wm)
1243 root_window_for_new_windows_ = gained_active_wm->GetRootWindow();
1244}
1245
Xiyuan Xiab64fd0a2017-04-13 17:53:141246void Shell::OnSessionStateChanged(session_manager::SessionState state) {
sky5ad143a2017-03-22 04:31:231247 // Create the shelf when a session becomes active. It's safe to do this
1248 // multiple times (e.g. initial login vs. multiprofile add session).
1249 if (state == session_manager::SessionState::ACTIVE) {
1250 CreateShelfView();
1251
skye5fd1222017-04-12 18:43:231252 if (GetAshConfig() != Config::MASH) {
sky5ad143a2017-03-22 04:31:231253 // Recreate the keyboard after initial login and after multiprofile login.
1254 CreateKeyboard();
1255 }
1256 }
xiyuan233f4e72017-04-06 06:59:561257}
sky5ad143a2017-03-22 04:31:231258
Xiyuan Xiab64fd0a2017-04-13 17:53:141259void Shell::OnLoginStatusChanged(LoginStatus login_status) {
xiyuan233f4e72017-04-06 06:59:561260 UpdateAfterLoginStatusChange(login_status);
sky5ad143a2017-03-22 04:31:231261}
1262
Xiyuan Xiab64fd0a2017-04-13 17:53:141263void Shell::OnLockStateChanged(bool locked) {
xiyuan7ebbf7f2017-04-10 16:49:101264#ifndef NDEBUG
1265 // Make sure that there is no system modal in Lock layer when unlocked.
1266 if (!locked) {
1267 aura::Window::Windows containers = wm::GetContainersFromAllRootWindows(
1268 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
1269 for (aura::Window* container : containers)
1270 DCHECK(container->children().empty());
1271 }
1272#endif
1273}
1274
tibellb93c729b2017-03-30 00:45:091275void Shell::OnPrefServiceInitialized(
1276 std::unique_ptr<::PrefService> pref_service) {
1277 if (!instance_)
1278 return;
sky7bd582ae2017-04-12 21:43:331279 // |pref_service_| is null if can't connect to Chrome (as happens when
1280 // running mash outside of chrome --mash and chrome isn't built).
tibellb93c729b2017-03-30 00:45:091281 pref_service_ = std::move(pref_service);
1282}
1283
[email protected]55f593352011-12-24 05:42:461284} // namespace ash