shell.cc 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/shell.h"
  5. #include <algorithm>
  6. #include <memory>
  7. #include <string>
  8. #include <utility>
  9. #include "ash/accelerators/accelerator_controller_impl.h"
  10. #include "ash/accelerators/ash_focus_manager_factory.h"
  11. #include "ash/accelerators/magnifier_key_scroller.h"
  12. #include "ash/accelerators/pre_target_accelerator_handler.h"
  13. #include "ash/accelerators/spoken_feedback_toggler.h"
  14. #include "ash/accelerometer/accelerometer_reader.h"
  15. #include "ash/accessibility/accessibility_controller_impl.h"
  16. #include "ash/accessibility/accessibility_delegate.h"
  17. #include "ash/accessibility/autoclick/autoclick_controller.h"
  18. #include "ash/accessibility/chromevox/key_accessibility_enabler.h"
  19. #include "ash/accessibility/magnifier/docked_magnifier_controller.h"
  20. #include "ash/accessibility/magnifier/fullscreen_magnifier_controller.h"
  21. #include "ash/accessibility/magnifier/partial_magnifier_controller.h"
  22. #include "ash/accessibility/sticky_keys/sticky_keys_controller.h"
  23. #include "ash/accessibility/ui/accessibility_focus_ring_controller_impl.h"
  24. #include "ash/ambient/ambient_controller.h"
  25. #include "ash/app_list/app_list_controller_impl.h"
  26. #include "ash/app_list/app_list_feature_usage_metrics.h"
  27. #include "ash/assistant/assistant_controller_impl.h"
  28. #include "ash/calendar/calendar_controller.h"
  29. #include "ash/capture_mode/capture_mode_controller.h"
  30. #include "ash/child_accounts/parent_access_controller_impl.h"
  31. #include "ash/clipboard/clipboard_history_controller_impl.h"
  32. #include "ash/clipboard/control_v_histogram_recorder.h"
  33. #include "ash/constants/ash_features.h"
  34. #include "ash/constants/ash_switches.h"
  35. #include "ash/controls/contextual_tooltip.h"
  36. #include "ash/dbus/ash_dbus_services.h"
  37. #include "ash/detachable_base/detachable_base_handler.h"
  38. #include "ash/detachable_base/detachable_base_notification_controller.h"
  39. #include "ash/display/cros_display_config.h"
  40. #include "ash/display/cursor_window_controller.h"
  41. #include "ash/display/display_alignment_controller.h"
  42. #include "ash/display/display_color_manager.h"
  43. #include "ash/display/display_configuration_controller.h"
  44. #include "ash/display/display_configuration_observer.h"
  45. #include "ash/display/display_error_observer.h"
  46. #include "ash/display/display_highlight_controller.h"
  47. #include "ash/display/display_prefs.h"
  48. #include "ash/display/display_shutdown_observer.h"
  49. #include "ash/display/event_transformation_handler.h"
  50. #include "ash/display/mouse_cursor_event_filter.h"
  51. #include "ash/display/persistent_window_controller.h"
  52. #include "ash/display/privacy_screen_controller.h"
  53. #include "ash/display/projecting_observer.h"
  54. #include "ash/display/refresh_rate_throttle_controller.h"
  55. #include "ash/display/resolution_notification_controller.h"
  56. #include "ash/display/screen_ash.h"
  57. #include "ash/display/screen_orientation_controller.h"
  58. #include "ash/display/screen_position_controller.h"
  59. #include "ash/display/window_tree_host_manager.h"
  60. #include "ash/drag_drop/drag_drop_controller.h"
  61. #include "ash/events/event_rewriter_controller_impl.h"
  62. #include "ash/fast_ink/laser/laser_pointer_controller.h"
  63. #include "ash/focus_cycler.h"
  64. #include "ash/frame/non_client_frame_view_ash.h"
  65. #include "ash/frame/snap_controller_impl.h"
  66. #include "ash/frame_throttler/frame_throttling_controller.h"
  67. #include "ash/glanceables/glanceables_controller.h"
  68. #include "ash/high_contrast/high_contrast_controller.h"
  69. #include "ash/highlighter/highlighter_controller.h"
  70. #include "ash/host/ash_window_tree_host_init_params.h"
  71. #include "ash/hud_display/hud_display.h"
  72. #include "ash/ime/ime_controller_impl.h"
  73. #include "ash/in_session_auth/in_session_auth_dialog_controller_impl.h"
  74. #include "ash/in_session_auth/webauthn_dialog_controller_impl.h"
  75. #include "ash/keyboard/keyboard_controller_impl.h"
  76. #include "ash/keyboard/ui/keyboard_ui_factory.h"
  77. #include "ash/login/login_screen_controller.h"
  78. #include "ash/login_status.h"
  79. #include "ash/media/media_controller_impl.h"
  80. #include "ash/metrics/feature_discovery_duration_reporter_impl.h"
  81. #include "ash/metrics/login_unlock_throughput_recorder.h"
  82. #include "ash/metrics/user_metrics_recorder.h"
  83. #include "ash/multi_capture/multi_capture_service_client.h"
  84. #include "ash/multi_device_setup/multi_device_notification_presenter.h"
  85. #include "ash/policy/policy_recommendation_restorer.h"
  86. #include "ash/projector/projector_controller_impl.h"
  87. #include "ash/public/cpp/ash_prefs.h"
  88. #include "ash/public/cpp/desks_templates_delegate.h"
  89. #include "ash/public/cpp/holding_space/holding_space_controller.h"
  90. #include "ash/public/cpp/nearby_share_delegate.h"
  91. #include "ash/public/cpp/shelf_config.h"
  92. #include "ash/public/cpp/shelf_model.h"
  93. #include "ash/public/cpp/shell_window_ids.h"
  94. #include "ash/public/cpp/tab_cluster/tab_cluster_ui_controller.h"
  95. #include "ash/public/cpp/views_text_services_context_menu_impl.h"
  96. #include "ash/quick_pair/keyed_service/quick_pair_mediator.h"
  97. #include "ash/rgb_keyboard/rgb_keyboard_manager.h"
  98. #include "ash/root_window_controller.h"
  99. #include "ash/session/session_controller_impl.h"
  100. #include "ash/shelf/shelf_controller.h"
  101. #include "ash/shelf/shelf_window_watcher.h"
  102. #include "ash/shell_delegate.h"
  103. #include "ash/shell_init_params.h"
  104. #include "ash/shell_observer.h"
  105. #include "ash/shell_tab_handler.h"
  106. #include "ash/shutdown_controller_impl.h"
  107. #include "ash/style/ash_color_mixer.h"
  108. #include "ash/style/ash_color_provider.h"
  109. #include "ash/style/dark_light_mode_controller_impl.h"
  110. #include "ash/system/audio/display_speaker_controller.h"
  111. #include "ash/system/bluetooth/bluetooth_device_status_ui_handler.h"
  112. #include "ash/system/bluetooth/bluetooth_notification_controller.h"
  113. #include "ash/system/bluetooth/bluetooth_power_controller.h"
  114. #include "ash/system/bluetooth/tray_bluetooth_helper_experimental.h"
  115. #include "ash/system/bluetooth/tray_bluetooth_helper_legacy.h"
  116. #include "ash/system/brightness/brightness_controller_chromeos.h"
  117. #include "ash/system/brightness_control_delegate.h"
  118. #include "ash/system/camera/autozoom_controller_impl.h"
  119. #include "ash/system/caps_lock_notification_controller.h"
  120. #include "ash/system/diagnostics/diagnostics_log_controller.h"
  121. #include "ash/system/firmware_update/firmware_update_notification_controller.h"
  122. #include "ash/system/geolocation/geolocation_controller.h"
  123. #include "ash/system/human_presence/human_presence_orientation_controller.h"
  124. #include "ash/system/human_presence/snooping_protection_controller.h"
  125. #include "ash/system/keyboard_brightness/keyboard_backlight_color_controller.h"
  126. #include "ash/system/keyboard_brightness/keyboard_brightness_controller.h"
  127. #include "ash/system/keyboard_brightness_control_delegate.h"
  128. #include "ash/system/locale/locale_update_controller_impl.h"
  129. #include "ash/system/machine_learning/user_settings_event_logger.h"
  130. #include "ash/system/media/media_notification_provider_impl.h"
  131. #include "ash/system/message_center/message_center_ash_impl.h"
  132. #include "ash/system/message_center/message_center_controller.h"
  133. #include "ash/system/model/system_tray_model.h"
  134. #include "ash/system/model/virtual_keyboard_model.h"
  135. #include "ash/system/nearby_share/nearby_share_controller_impl.h"
  136. #include "ash/system/network/sms_observer.h"
  137. #include "ash/system/night_light/night_light_controller_impl.h"
  138. #include "ash/system/pcie_peripheral/pcie_peripheral_notification_controller.h"
  139. #include "ash/system/power/adaptive_charging_controller.h"
  140. #include "ash/system/power/backlights_forced_off_setter.h"
  141. #include "ash/system/power/peripheral_battery_notifier.h"
  142. #include "ash/system/power/power_button_controller.h"
  143. #include "ash/system/power/power_event_observer.h"
  144. #include "ash/system/power/power_prefs.h"
  145. #include "ash/system/power/power_status.h"
  146. #include "ash/system/power/video_activity_notifier.h"
  147. #include "ash/system/privacy_hub/privacy_hub_controller.h"
  148. #include "ash/system/screen_layout_observer.h"
  149. #include "ash/system/screen_security/screen_switch_check_controller.h"
  150. #include "ash/system/session/logout_confirmation_controller.h"
  151. #include "ash/system/status_area_widget.h"
  152. #include "ash/system/system_notification_controller.h"
  153. #include "ash/system/toast/toast_manager_impl.h"
  154. #include "ash/system/tray/system_tray_notifier.h"
  155. #include "ash/system/usb_peripheral/usb_peripheral_notification_controller.h"
  156. #include "ash/touch/ash_touch_transform_controller.h"
  157. #include "ash/touch/touch_devices_controller.h"
  158. #include "ash/tray_action/tray_action.h"
  159. #include "ash/utility/occlusion_tracker_pauser.h"
  160. #include "ash/wallpaper/wallpaper_controller_impl.h"
  161. #include "ash/wm/ash_focus_rules.h"
  162. #include "ash/wm/container_finder.h"
  163. #include "ash/wm/cursor_manager_chromeos.h"
  164. #include "ash/wm/desks/desks_controller.h"
  165. #include "ash/wm/desks/persistent_desks_bar_controller.h"
  166. #include "ash/wm/event_client_impl.h"
  167. #include "ash/wm/float/float_controller.h"
  168. #include "ash/wm/gestures/back_gesture/back_gesture_event_handler.h"
  169. #include "ash/wm/immersive_context_ash.h"
  170. #include "ash/wm/lock_state_controller.h"
  171. #include "ash/wm/mru_window_tracker.h"
  172. #include "ash/wm/multitask_menu_nudge_controller.h"
  173. #include "ash/wm/native_cursor_manager_ash.h"
  174. #include "ash/wm/overlay_event_filter.h"
  175. #include "ash/wm/overview/overview_controller.h"
  176. #include "ash/wm/resize_shadow_controller.h"
  177. #include "ash/wm/screen_pinning_controller.h"
  178. #include "ash/wm/system_gesture_event_filter.h"
  179. #include "ash/wm/system_modal_container_event_filter.h"
  180. #include "ash/wm/system_modal_container_layout_manager.h"
  181. #include "ash/wm/tablet_mode/tablet_mode_controller.h"
  182. #include "ash/wm/tablet_mode/tablet_mode_window_manager.h"
  183. #include "ash/wm/toplevel_window_event_handler.h"
  184. #include "ash/wm/video_detector.h"
  185. #include "ash/wm/window_animations.h"
  186. #include "ash/wm/window_cycle/window_cycle_controller.h"
  187. #include "ash/wm/window_positioner.h"
  188. #include "ash/wm/window_properties.h"
  189. #include "ash/wm/window_restore/window_restore_controller.h"
  190. #include "ash/wm/window_util.h"
  191. #include "ash/wm/wm_shadow_controller_delegate.h"
  192. #include "ash/wm/workspace_controller.h"
  193. #include "base/bind.h"
  194. #include "base/callback_helpers.h"
  195. #include "base/check.h"
  196. #include "base/command_line.h"
  197. #include "base/memory/ptr_util.h"
  198. #include "base/notreached.h"
  199. #include "base/system/sys_info.h"
  200. #include "base/trace_event/trace_event.h"
  201. #include "chromeos/ash/components/dbus/usb/usbguard_client.h"
  202. #include "chromeos/ash/services/assistant/public/cpp/features.h"
  203. #include "chromeos/dbus/init/initialize_dbus_client.h"
  204. #include "chromeos/dbus/power/power_policy_controller.h"
  205. #include "chromeos/system/devicemode.h"
  206. #include "chromeos/ui/wm/features.h"
  207. #include "components/prefs/pref_registry_simple.h"
  208. #include "components/prefs/pref_service.h"
  209. #include "components/viz/host/host_frame_sink_manager.h"
  210. #include "dbus/bus.h"
  211. #include "media/capture/video/chromeos/video_capture_features_chromeos.h"
  212. #include "services/video_capture/public/mojom/multi_capture_service.mojom.h"
  213. #include "ui/aura/client/aura_constants.h"
  214. #include "ui/aura/env.h"
  215. #include "ui/aura/layout_manager.h"
  216. #include "ui/aura/window.h"
  217. #include "ui/aura/window_event_dispatcher.h"
  218. #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
  219. #include "ui/base/ui_base_features.h"
  220. #include "ui/base/user_activity/user_activity_detector.h"
  221. #include "ui/chromeos/user_activity_power_manager_notifier.h"
  222. #include "ui/color/color_provider_manager.h"
  223. #include "ui/compositor/layer.h"
  224. #include "ui/compositor/layer_animator.h"
  225. #include "ui/display/display.h"
  226. #include "ui/display/manager/default_touch_transform_setter.h"
  227. #include "ui/display/manager/display_change_observer.h"
  228. #include "ui/display/manager/display_configurator.h"
  229. #include "ui/display/manager/display_manager.h"
  230. #include "ui/display/manager/touch_transform_setter.h"
  231. #include "ui/display/screen.h"
  232. #include "ui/display/types/native_display_delegate.h"
  233. #include "ui/events/event_target_iterator.h"
  234. #include "ui/gfx/geometry/insets.h"
  235. #include "ui/gfx/image/image_skia.h"
  236. #include "ui/message_center/message_center.h"
  237. #include "ui/ozone/public/ozone_platform.h"
  238. #include "ui/views/controls/views_text_services_context_menu_chromeos.h"
  239. #include "ui/views/corewm/tooltip_aura.h"
  240. #include "ui/views/corewm/tooltip_controller.h"
  241. #include "ui/views/focus/focus_manager_factory.h"
  242. #include "ui/views/widget/native_widget_aura.h"
  243. #include "ui/views/widget/widget.h"
  244. #include "ui/wm/core/accelerator_filter.h"
  245. #include "ui/wm/core/compound_event_filter.h"
  246. #include "ui/wm/core/focus_controller.h"
  247. #include "ui/wm/core/shadow_controller.h"
  248. #include "ui/wm/core/visibility_controller.h"
  249. #include "ui/wm/core/window_modality_controller.h"
  250. namespace ash {
  251. namespace {
  252. using aura::Window;
  253. using views::Widget;
  254. // A Corewm VisibilityController subclass that calls the Ash animation routine
  255. // so we can pick up our extended animations. See ash/wm/window_animations.h.
  256. class AshVisibilityController : public ::wm::VisibilityController {
  257. public:
  258. AshVisibilityController() = default;
  259. AshVisibilityController(const AshVisibilityController&) = delete;
  260. AshVisibilityController& operator=(const AshVisibilityController&) = delete;
  261. ~AshVisibilityController() override = default;
  262. private:
  263. // Overridden from ::wm::VisibilityController:
  264. bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
  265. bool visible) override {
  266. return AnimateOnChildWindowVisibilityChanged(window, visible);
  267. }
  268. };
  269. } // namespace
  270. // static
  271. Shell* Shell::instance_ = nullptr;
  272. ////////////////////////////////////////////////////////////////////////////////
  273. // Shell, public:
  274. // static
  275. Shell* Shell::CreateInstance(ShellInitParams init_params) {
  276. CHECK(!instance_);
  277. instance_ = new Shell(std::move(init_params.delegate));
  278. instance_->Init(init_params.context_factory, init_params.local_state,
  279. std::move(init_params.keyboard_ui_factory),
  280. init_params.dbus_bus);
  281. return instance_;
  282. }
  283. // static
  284. Shell* Shell::Get() {
  285. CHECK(instance_);
  286. return instance_;
  287. }
  288. // static
  289. bool Shell::HasInstance() {
  290. return !!instance_;
  291. }
  292. // static
  293. void Shell::DeleteInstance() {
  294. delete instance_;
  295. }
  296. // static
  297. RootWindowController* Shell::GetPrimaryRootWindowController() {
  298. CHECK(HasInstance());
  299. return RootWindowController::ForWindow(GetPrimaryRootWindow());
  300. }
  301. // static
  302. Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
  303. CHECK(HasInstance());
  304. RootWindowControllerList root_window_controllers;
  305. for (aura::Window* root : GetAllRootWindows())
  306. root_window_controllers.push_back(RootWindowController::ForWindow(root));
  307. return root_window_controllers;
  308. }
  309. // static
  310. RootWindowController* Shell::GetRootWindowControllerWithDisplayId(
  311. int64_t display_id) {
  312. CHECK(HasInstance());
  313. aura::Window* root = GetRootWindowForDisplayId(display_id);
  314. return root ? RootWindowController::ForWindow(root) : nullptr;
  315. }
  316. // static
  317. aura::Window* Shell::GetRootWindowForDisplayId(int64_t display_id) {
  318. CHECK(HasInstance());
  319. return instance_->window_tree_host_manager_->GetRootWindowForDisplayId(
  320. display_id);
  321. }
  322. // static
  323. aura::Window* Shell::GetPrimaryRootWindow() {
  324. CHECK(HasInstance());
  325. return instance_->window_tree_host_manager_->GetPrimaryRootWindow();
  326. }
  327. // static
  328. void Shell::SetRootWindowForNewWindows(aura::Window* root) {
  329. display::Screen::GetScreen()->SetDisplayForNewWindows(
  330. display::Screen::GetScreen()->GetDisplayNearestWindow(root).id());
  331. }
  332. // static
  333. aura::Window* Shell::GetRootWindowForNewWindows() {
  334. return GetRootWindowForDisplayId(
  335. display::Screen::GetScreen()->GetDisplayForNewWindows().id());
  336. }
  337. // static
  338. aura::Window::Windows Shell::GetAllRootWindows() {
  339. CHECK(HasInstance());
  340. return instance_->window_tree_host_manager_->GetAllRootWindows();
  341. }
  342. // static
  343. aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) {
  344. return root_window->GetChildById(container_id);
  345. }
  346. // static
  347. const aura::Window* Shell::GetContainer(const aura::Window* root_window,
  348. int container_id) {
  349. return root_window->GetChildById(container_id);
  350. }
  351. // static
  352. int Shell::GetOpenSystemModalWindowContainerId() {
  353. // The test boolean is not static to avoid leaking state between tests.
  354. if (Get()->simulate_modal_window_open_for_test_)
  355. return kShellWindowId_SystemModalContainer;
  356. // Traverse all system modal containers, and find its direct child window
  357. // with "SystemModal" setting, and visible.
  358. for (aura::Window* root : Shell::GetAllRootWindows()) {
  359. for (int modal_window_id : kSystemModalContainerIds) {
  360. aura::Window* system_modal = root->GetChildById(modal_window_id);
  361. if (!system_modal)
  362. continue;
  363. for (const aura::Window* child : system_modal->children()) {
  364. if (child->GetProperty(aura::client::kModalKey) ==
  365. ui::MODAL_TYPE_SYSTEM &&
  366. child->layer()->GetTargetVisibility()) {
  367. return modal_window_id;
  368. }
  369. }
  370. }
  371. }
  372. return -1;
  373. }
  374. // static
  375. bool Shell::IsSystemModalWindowOpen() {
  376. return GetOpenSystemModalWindowContainerId() >= 0;
  377. }
  378. display::DisplayConfigurator* Shell::display_configurator() {
  379. return display_manager_->configurator();
  380. }
  381. void Shell::TrackInputMethodBounds(ArcInputMethodBoundsTracker* tracker) {
  382. system_tray_model()->virtual_keyboard()->SetInputMethodBoundsTrackerObserver(
  383. tracker);
  384. }
  385. void Shell::UntrackTrackInputMethodBounds(
  386. ArcInputMethodBoundsTracker* tracker) {
  387. system_tray_model()
  388. ->virtual_keyboard()
  389. ->RemoveInputMethodBoundsTrackerObserver(tracker);
  390. }
  391. std::unique_ptr<views::NonClientFrameView>
  392. Shell::CreateDefaultNonClientFrameView(views::Widget* widget) {
  393. // Use translucent-style window frames for dialogs.
  394. return std::make_unique<NonClientFrameViewAsh>(widget);
  395. }
  396. void Shell::OnCastingSessionStartedOrStopped(bool started) {
  397. for (auto& observer : shell_observers_)
  398. observer.OnCastingSessionStartedOrStopped(started);
  399. }
  400. void Shell::OnRootWindowAdded(aura::Window* root_window) {
  401. for (auto& observer : shell_observers_)
  402. observer.OnRootWindowAdded(root_window);
  403. }
  404. void Shell::OnRootWindowWillShutdown(aura::Window* root_window) {
  405. for (auto& observer : shell_observers_)
  406. observer.OnRootWindowWillShutdown(root_window);
  407. }
  408. void Shell::OnDictationStarted() {
  409. for (auto& observer : shell_observers_)
  410. observer.OnDictationStarted();
  411. }
  412. void Shell::OnDictationEnded() {
  413. for (auto& observer : shell_observers_)
  414. observer.OnDictationEnded();
  415. }
  416. bool Shell::IsInTabletMode() const {
  417. return tablet_mode_controller()->InTabletMode();
  418. }
  419. bool Shell::ShouldSaveDisplaySettings() {
  420. return !(
  421. screen_orientation_controller_->ignore_display_configuration_updates() ||
  422. // Save display settings if we don't need to show the display change
  423. // dialog.
  424. resolution_notification_controller_->ShouldShowDisplayChangeDialog());
  425. }
  426. ::wm::ActivationClient* Shell::activation_client() {
  427. return focus_controller_.get();
  428. }
  429. bool Shell::HasPrimaryStatusArea() {
  430. return !!GetPrimaryRootWindowController()->GetStatusAreaWidget();
  431. }
  432. void Shell::SetLargeCursorSizeInDip(int large_cursor_size_in_dip) {
  433. window_tree_host_manager_->cursor_window_controller()
  434. ->SetLargeCursorSizeInDip(large_cursor_size_in_dip);
  435. }
  436. void Shell::SetCursorColor(SkColor cursor_color) {
  437. window_tree_host_manager_->cursor_window_controller()->SetCursorColor(
  438. cursor_color);
  439. }
  440. void Shell::UpdateCursorCompositingEnabled() {
  441. SetCursorCompositingEnabled(
  442. window_tree_host_manager_->cursor_window_controller()
  443. ->ShouldEnableCursorCompositing());
  444. }
  445. void Shell::SetCursorCompositingEnabled(bool enabled) {
  446. CursorWindowController* cursor_window_controller =
  447. window_tree_host_manager_->cursor_window_controller();
  448. if (cursor_window_controller->is_cursor_compositing_enabled() == enabled)
  449. return;
  450. cursor_window_controller->SetCursorCompositingEnabled(enabled);
  451. native_cursor_manager_->SetNativeCursorEnabled(!enabled);
  452. }
  453. void Shell::DoInitialWorkspaceAnimation() {
  454. // Uses the active desk's workspace.
  455. auto* workspace = GetActiveWorkspaceController(GetPrimaryRootWindow());
  456. DCHECK(workspace);
  457. workspace->DoInitialAnimation();
  458. }
  459. void Shell::ShowContextMenu(const gfx::Point& location_in_screen,
  460. ui::MenuSourceType source_type) {
  461. // Bail with no active user session, in the lock screen, or in app/kiosk mode.
  462. if (session_controller_->NumberOfLoggedInUsers() < 1 ||
  463. session_controller_->IsScreenLocked() ||
  464. session_controller_->IsRunningInAppMode()) {
  465. return;
  466. }
  467. aura::Window* root = window_util::GetRootWindowAt(location_in_screen);
  468. RootWindowController::ForWindow(root)->ShowContextMenu(location_in_screen,
  469. source_type);
  470. }
  471. void Shell::AddShellObserver(ShellObserver* observer) {
  472. shell_observers_.AddObserver(observer);
  473. }
  474. void Shell::RemoveShellObserver(ShellObserver* observer) {
  475. shell_observers_.RemoveObserver(observer);
  476. }
  477. void Shell::ShutdownEventDispatch() {
  478. for (aura::Window* root : GetAllRootWindows())
  479. aura::client::SetDragDropClient(root, nullptr);
  480. // Stop dispatching events (e.g. synthesized mouse exits from window close).
  481. // https://crbug.com/874156
  482. for (RootWindowController* rwc : GetAllRootWindowControllers())
  483. rwc->GetHost()->dispatcher()->Shutdown();
  484. }
  485. void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
  486. for (auto* root_window_controller : GetAllRootWindowControllers())
  487. root_window_controller->UpdateAfterLoginStatusChange(status);
  488. }
  489. void Shell::NotifyFullscreenStateChanged(bool is_fullscreen,
  490. aura::Window* container) {
  491. for (auto& observer : shell_observers_)
  492. observer.OnFullscreenStateChanged(is_fullscreen, container);
  493. }
  494. void Shell::NotifyPinnedStateChanged(aura::Window* pinned_window) {
  495. for (auto& observer : shell_observers_)
  496. observer.OnPinnedStateChanged(pinned_window);
  497. }
  498. void Shell::NotifyUserWorkAreaInsetsChanged(aura::Window* root_window) {
  499. for (auto& observer : shell_observers_)
  500. observer.OnUserWorkAreaInsetsChanged(root_window);
  501. }
  502. void Shell::NotifyShelfAlignmentChanged(aura::Window* root_window,
  503. ShelfAlignment old_alignment) {
  504. for (auto& observer : shell_observers_)
  505. observer.OnShelfAlignmentChanged(root_window, old_alignment);
  506. }
  507. ////////////////////////////////////////////////////////////////////////////////
  508. // Shell, private:
  509. Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate)
  510. : brightness_control_delegate_(
  511. std::make_unique<system::BrightnessControllerChromeos>()),
  512. focus_cycler_(std::make_unique<FocusCycler>()),
  513. ime_controller_(std::make_unique<ImeControllerImpl>()),
  514. immersive_context_(std::make_unique<ImmersiveContextAsh>()),
  515. webauthn_dialog_controller_(
  516. std::make_unique<WebAuthNDialogControllerImpl>()),
  517. in_session_auth_dialog_controller_(
  518. std::make_unique<InSessionAuthDialogControllerImpl>()),
  519. keyboard_brightness_control_delegate_(
  520. std::make_unique<KeyboardBrightnessController>()),
  521. locale_update_controller_(std::make_unique<LocaleUpdateControllerImpl>()),
  522. parent_access_controller_(std::make_unique<ParentAccessControllerImpl>()),
  523. session_controller_(std::make_unique<SessionControllerImpl>()),
  524. feature_discover_reporter_(
  525. std::make_unique<FeatureDiscoveryDurationReporterImpl>(
  526. session_controller_.get())),
  527. shell_delegate_(std::move(shell_delegate)),
  528. shutdown_controller_(std::make_unique<ShutdownControllerImpl>()),
  529. system_tray_notifier_(std::make_unique<SystemTrayNotifier>()),
  530. native_cursor_manager_(nullptr) {
  531. AccelerometerReader::GetInstance()->Initialize();
  532. if (features::AreGlanceablesEnabled()) {
  533. glanceables_controller_ = std::make_unique<GlanceablesController>();
  534. }
  535. login_screen_controller_ =
  536. std::make_unique<LoginScreenController>(system_tray_notifier_.get());
  537. display_manager_ = ScreenAsh::CreateDisplayManager();
  538. window_tree_host_manager_ = std::make_unique<WindowTreeHostManager>();
  539. user_metrics_recorder_ = std::make_unique<UserMetricsRecorder>();
  540. keyboard_controller_ =
  541. std::make_unique<KeyboardControllerImpl>(session_controller_.get());
  542. if (!ash::features::IsBluetoothRevampEnabled()) {
  543. if (base::FeatureList::IsEnabled(features::kUseBluetoothSystemInAsh)) {
  544. mojo::PendingRemote<device::mojom::BluetoothSystemFactory>
  545. bluetooth_system_factory;
  546. shell_delegate_->BindBluetoothSystemFactory(
  547. bluetooth_system_factory.InitWithNewPipeAndPassReceiver());
  548. tray_bluetooth_helper_ =
  549. std::make_unique<TrayBluetoothHelperExperimental>(
  550. std::move(bluetooth_system_factory));
  551. } else {
  552. tray_bluetooth_helper_ = std::make_unique<TrayBluetoothHelperLegacy>();
  553. }
  554. }
  555. PowerStatus::Initialize();
  556. session_controller_->AddObserver(this);
  557. }
  558. Shell::~Shell() {
  559. TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
  560. #if DCHECK_IS_ON()
  561. // All WindowEventDispatchers should be shutdown before the Shell is
  562. // destroyed.
  563. for (RootWindowController* rwc : GetAllRootWindowControllers())
  564. DCHECK(rwc->GetHost()->dispatcher()->in_shutdown());
  565. #endif
  566. login_unlock_throughput_recorder_.reset();
  567. hud_display::HUDDisplayView::Destroy();
  568. // Observes `SessionController` and must be destroyed before it.
  569. privacy_hub_controller_.reset();
  570. for (auto& observer : shell_observers_)
  571. observer.OnShellDestroying();
  572. ash_dbus_services_.reset();
  573. desks_templates_delegate_.reset();
  574. desks_controller_->Shutdown();
  575. user_metrics_recorder_->OnShellShuttingDown();
  576. cros_display_config_.reset();
  577. display_configuration_observer_.reset();
  578. display_prefs_.reset();
  579. display_alignment_controller_.reset();
  580. refresh_rate_throttle_controller_.reset();
  581. // Remove the focus from any window. This will prevent overhead and side
  582. // effects (e.g. crashes) from changing focus during shutdown.
  583. // See bug crbug.com/134502.
  584. aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
  585. // Please keep in reverse order as in Init() because it's easy to miss one.
  586. if (window_modality_controller_)
  587. window_modality_controller_.reset();
  588. RemovePreTargetHandler(shell_tab_handler_.get());
  589. shell_tab_handler_.reset();
  590. RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
  591. magnifier_key_scroll_handler_.reset();
  592. RemovePreTargetHandler(speech_feedback_handler_.get());
  593. speech_feedback_handler_.reset();
  594. RemovePreTargetHandler(overlay_filter_.get());
  595. overlay_filter_.reset();
  596. RemovePreTargetHandler(control_v_histogram_recorder_.get());
  597. RemovePreTargetHandler(accelerator_filter_.get());
  598. RemovePreTargetHandler(event_transformation_handler_.get());
  599. if (back_gesture_event_handler_)
  600. RemovePreTargetHandler(back_gesture_event_handler_.get());
  601. RemovePreTargetHandler(toplevel_window_event_handler_.get());
  602. RemovePostTargetHandler(toplevel_window_event_handler_.get());
  603. RemovePreTargetHandler(system_gesture_filter_.get());
  604. RemovePreTargetHandler(mouse_cursor_filter_.get());
  605. RemovePreTargetHandler(modality_filter_.get());
  606. RemovePreTargetHandler(tooltip_controller_.get());
  607. // Resets the text context menu implementation factory.
  608. views::ViewsTextServicesContextMenuChromeos::SetImplFactory(
  609. base::NullCallback());
  610. event_rewriter_controller_.reset();
  611. screen_orientation_controller_.reset();
  612. screen_layout_observer_.reset();
  613. // Destroy the virtual keyboard controller before the tablet mode controller
  614. // since the latters destructor triggers events that the former is listening
  615. // to but no longer cares about.
  616. keyboard_controller_->DestroyVirtualKeyboard();
  617. // Depends on |tablet_mode_controller_|.
  618. window_restore_controller_.reset();
  619. shelf_controller_->Shutdown();
  620. shelf_config_->Shutdown();
  621. // Destroy PersistentDesksBarController before `overview_controller_`,
  622. // `tablet_mode_controller_`, `desks_controller_` and
  623. // `app_list_controller_` that it observes.
  624. persistent_desks_bar_controller_.reset();
  625. // Depends on `app_list_controller_` and `tablet_mode_controller_`.
  626. app_list_feature_usage_metrics_.reset();
  627. // Destroy |app_list_controller_| earlier than |tablet_mode_controller_| since
  628. // the former may use the latter before destruction.
  629. app_list_controller_.reset();
  630. // Accelerometer file reader stops listening to tablet mode controller.
  631. AccelerometerReader::GetInstance()->StopListenToTabletModeController();
  632. if (features::AreGlanceablesEnabled()) {
  633. // Close all glanceables so that all widgets are destroyed.
  634. glanceables_controller_->DestroyUi();
  635. }
  636. // Destroy |ambient_controller_| before |assistant_controller_|.
  637. ambient_controller_.reset();
  638. // Destroy |assistant_controller_| earlier than |tablet_mode_controller_| so
  639. // that the former will destroy the Assistant view hierarchy which has a
  640. // dependency on the latter.
  641. assistant_controller_.reset();
  642. // Because this function will call |TabletModeController::RemoveObserver|, do
  643. // it before destroying |tablet_mode_controller_|.
  644. accessibility_controller_->Shutdown();
  645. // Must be destructed before human_presence_orientation_controller_.
  646. power_prefs_.reset();
  647. // Must be destructed before the tablet mode and message center controllers,
  648. // both of which these rely on.
  649. snooping_protection_controller_.reset();
  650. human_presence_orientation_controller_.reset();
  651. // Shutdown tablet mode controller early on since it has some observers which
  652. // need to be removed. It will be destroyed later after all windows are closed
  653. // since it might be accessed during this process.
  654. tablet_mode_controller_->Shutdown();
  655. // Shutdown the clipboard history controller to clean up the child windows and
  656. // widgets that may be animating out.
  657. clipboard_history_controller_->Shutdown();
  658. // Destroy UserSettingsEventLogger before |system_tray_model_| and
  659. // |video_detector_| which it observes.
  660. ml::UserSettingsEventLogger::DeleteInstance();
  661. toast_manager_.reset();
  662. tray_bluetooth_helper_.reset();
  663. // Accesses root window containers.
  664. logout_confirmation_controller_.reset();
  665. adaptive_charging_controller_.reset();
  666. // Drag-and-drop must be canceled prior to close all windows.
  667. drag_drop_controller_.reset();
  668. // Controllers who have WindowObserver added must be deleted
  669. // before |window_tree_host_manager_| is deleted.
  670. persistent_window_controller_.reset();
  671. display_highlight_controller_.reset();
  672. // VideoActivityNotifier must be deleted before |video_detector_| is
  673. // deleted because it's observing video activity through
  674. // VideoDetector::Observer interface.
  675. video_activity_notifier_.reset();
  676. video_detector_.reset();
  677. high_contrast_controller_.reset();
  678. shadow_controller_.reset();
  679. resize_shadow_controller_.reset();
  680. // Has to happen before ~MruWindowTracker.
  681. window_cycle_controller_.reset();
  682. overview_controller_.reset();
  683. // This must be destroyed before deleting all the windows below in
  684. // `CloseAllRootWindowChildWindows()`, since shutting down the session will
  685. // need to access those windows and it will be a UAF.
  686. // https://crbug.com/1350711.
  687. capture_mode_controller_.reset();
  688. // Close all widgets (including the shelf) and destroy all window containers.
  689. CloseAllRootWindowChildWindows();
  690. multitask_menu_nudge_controller_.reset();
  691. tablet_mode_controller_.reset();
  692. login_screen_controller_.reset();
  693. system_notification_controller_.reset();
  694. // Should be destroyed after Shelf and |system_notification_controller_|.
  695. system_tray_model_.reset();
  696. // MruWindowTracker must be destroyed after all windows have been deleted to
  697. // avoid a possible crash when Shell is destroyed from a non-normal shutdown
  698. // path. (crbug.com/485438).
  699. mru_window_tracker_.reset();
  700. // These need a valid Shell instance to clean up properly, so explicitly
  701. // delete them before invalidating the instance.
  702. // Alphabetical. TODO(oshima): sort.
  703. autoclick_controller_.reset();
  704. fullscreen_magnifier_controller_.reset();
  705. tooltip_controller_.reset();
  706. event_client_.reset();
  707. toplevel_window_event_handler_.reset();
  708. visibility_controller_.reset();
  709. tray_action_.reset();
  710. power_button_controller_.reset();
  711. lock_state_controller_.reset();
  712. backlights_forced_off_setter_.reset();
  713. float_controller_.reset();
  714. screen_pinning_controller_.reset();
  715. multidevice_notification_presenter_.reset();
  716. resolution_notification_controller_.reset();
  717. mouse_cursor_filter_.reset();
  718. modality_filter_.reset();
  719. touch_transformer_controller_.reset();
  720. highlighter_controller_.reset();
  721. key_accessibility_enabler_.reset();
  722. display_speaker_controller_.reset();
  723. screen_switch_check_controller_.reset();
  724. ScreenAsh::CreateScreenForShutdown();
  725. display_configuration_controller_.reset();
  726. // Needs to be destructed before `ime_controler_`.
  727. keyboard_backlight_color_controller_.reset();
  728. rgb_keyboard_manager_.reset();
  729. ash_color_provider_.reset();
  730. // Depends on `geolocation_controller_` and `wallpaper_controller_`, so it
  731. // must be destructed before the geolocation controller and wallpaper
  732. // controller.
  733. dark_light_mode_controller_.reset();
  734. // These members access Shell in their destructors.
  735. wallpaper_controller_.reset();
  736. accessibility_controller_.reset();
  737. accessibility_delegate_.reset();
  738. accessibility_focus_ring_controller_.reset();
  739. policy_recommendation_restorer_.reset();
  740. ime_controller_.reset();
  741. back_gesture_event_handler_.reset();
  742. // Balances the Install() in Initialize().
  743. views::FocusManagerFactory::Install(nullptr);
  744. // ShelfWindowWatcher has window observers and a pointer to the shelf model.
  745. shelf_window_watcher_.reset();
  746. // Removes itself as an observer of |pref_service_|.
  747. shelf_controller_.reset();
  748. // NightLightControllerImpl depends on the PrefService, the window tree host
  749. // manager, and `geolocation_controller_`, so it must be destructed before
  750. // them. crbug.com/724231.
  751. night_light_controller_ = nullptr;
  752. // Similarly for DockedMagnifierController.
  753. docked_magnifier_controller_ = nullptr;
  754. // Similarly for PrivacyScreenController.
  755. privacy_screen_controller_ = nullptr;
  756. // Similarly for AutozoomControllerImpl
  757. autozoom_controller_ = nullptr;
  758. geolocation_controller_.reset();
  759. // NearbyShareDelegateImpl must be destroyed before SessionController and
  760. // NearbyShareControllerImpl.
  761. nearby_share_delegate_.reset();
  762. nearby_share_controller_.reset();
  763. // Stop observing window activation changes before closing all windows.
  764. focus_controller_->RemoveObserver(this);
  765. // Depends on shelf owned by RootWindowController so destroy this before the
  766. // |window_tree_host_manager_|.
  767. clipboard_history_controller_.reset();
  768. // This also deletes all RootWindows. Note that we invoke Shutdown() on
  769. // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
  770. // destruction of its owned RootWindowControllers relies on the value.
  771. window_tree_host_manager_->Shutdown();
  772. // Depends on |focus_controller_|, so must be destroyed before.
  773. window_tree_host_manager_.reset();
  774. // The desks controller is destroyed after the window tree host manager and
  775. // before the focus controller. At this point it is guaranteed that querying
  776. // the active desk is no longer needed.
  777. desks_controller_.reset();
  778. tab_cluster_ui_controller_.reset();
  779. focus_rules_ = nullptr;
  780. focus_controller_.reset();
  781. screen_position_controller_.reset();
  782. display_color_manager_.reset();
  783. projecting_observer_.reset();
  784. projector_controller_.reset();
  785. partial_magnifier_controller_.reset();
  786. laser_pointer_controller_.reset();
  787. if (display_change_observer_)
  788. display_manager_->configurator()->RemoveObserver(
  789. display_change_observer_.get());
  790. if (display_error_observer_)
  791. display_manager_->configurator()->RemoveObserver(
  792. display_error_observer_.get());
  793. display_change_observer_.reset();
  794. display_shutdown_observer_.reset();
  795. keyboard_controller_.reset();
  796. PowerStatus::Shutdown();
  797. // Depends on SessionController.
  798. power_event_observer_.reset();
  799. session_controller_->RemoveObserver(this);
  800. // BluetoothPowerController depends on the PrefService and must be destructed
  801. // before it.
  802. bluetooth_power_controller_ = nullptr;
  803. // TouchDevicesController depends on the PrefService and must be destructed
  804. // before it.
  805. touch_devices_controller_ = nullptr;
  806. // DetachableBaseNotificationController depends on DetachableBaseHandler, and
  807. // has to be destructed before it.
  808. detachable_base_notification_controller_.reset();
  809. // DetachableBaseHandler depends on the PrefService and must be destructed
  810. // before it.
  811. detachable_base_handler_.reset();
  812. diagnostics_log_controller_.reset();
  813. firmware_update_notification_controller_.reset();
  814. pcie_peripheral_notification_controller_.reset();
  815. usb_peripheral_notification_controller_.reset();
  816. message_center_ash_impl_.reset();
  817. // Destroys the MessageCenter singleton, so must happen late.
  818. message_center_controller_.reset();
  819. // `HoldingSpaceController` observes `SessionController` and must be
  820. // destructed before it.
  821. holding_space_controller_.reset();
  822. // `CalendarController` observes `SessionController` and must be destructed
  823. // before it.
  824. calendar_controller_.reset();
  825. shell_delegate_.reset();
  826. multi_capture_service_client_.reset();
  827. UsbguardClient::Shutdown();
  828. // Must be shut down after detachable_base_handler_.
  829. HammerdClient::Shutdown();
  830. for (auto& observer : shell_observers_)
  831. observer.OnShellDestroyed();
  832. DCHECK(instance_ == this);
  833. instance_ = nullptr;
  834. }
  835. void Shell::Init(
  836. ui::ContextFactory* context_factory,
  837. PrefService* local_state,
  838. std::unique_ptr<keyboard::KeyboardUIFactory> keyboard_ui_factory,
  839. scoped_refptr<dbus::Bus> dbus_bus) {
  840. login_unlock_throughput_recorder_ =
  841. std::make_unique<LoginUnlockThroughputRecorder>();
  842. // Required by DetachableBaseHandler.
  843. chromeos::InitializeDBusClient<HammerdClient>(dbus_bus.get());
  844. chromeos::InitializeDBusClient<UsbguardClient>(dbus_bus.get());
  845. local_state_ = local_state;
  846. // This creates the MessageCenter object which is used by some other objects
  847. // initialized here, so it needs to come early.
  848. message_center_controller_ = std::make_unique<MessageCenterController>();
  849. message_center_ash_impl_ = std::make_unique<MessageCenterAshImpl>();
  850. // These controllers call Shell::Get() in their constructors, so they cannot
  851. // be in the member initialization list.
  852. privacy_hub_controller_ = std::make_unique<PrivacyHubController>();
  853. touch_devices_controller_ = std::make_unique<TouchDevicesController>();
  854. if (!ash::features::IsBluetoothRevampEnabled()) {
  855. bluetooth_power_controller_ =
  856. std::make_unique<BluetoothPowerController>(local_state_);
  857. }
  858. detachable_base_handler_ =
  859. std::make_unique<DetachableBaseHandler>(local_state_);
  860. detachable_base_notification_controller_ =
  861. std::make_unique<DetachableBaseNotificationController>(
  862. detachable_base_handler_.get());
  863. display_speaker_controller_ = std::make_unique<DisplaySpeakerController>();
  864. policy_recommendation_restorer_ =
  865. std::make_unique<PolicyRecommendationRestorer>();
  866. screen_switch_check_controller_ =
  867. std::make_unique<ScreenSwitchCheckController>();
  868. multidevice_notification_presenter_ =
  869. std::make_unique<MultiDeviceNotificationPresenter>(
  870. message_center::MessageCenter::Get());
  871. media_controller_ = std::make_unique<MediaControllerImpl>();
  872. media_notification_provider_ =
  873. std::make_unique<MediaNotificationProviderImpl>(
  874. shell_delegate_->GetMediaSessionService());
  875. tablet_mode_controller_ = std::make_unique<TabletModeController>();
  876. if (features::IsRgbKeyboardEnabled()) {
  877. rgb_keyboard_manager_ =
  878. std::make_unique<RgbKeyboardManager>(ime_controller_.get());
  879. }
  880. // Observes the tablet mode controller if any hps feature is enabled.
  881. if (features::IsSnoopingProtectionEnabled() ||
  882. features::IsQuickDimEnabled()) {
  883. human_presence_orientation_controller_ =
  884. std::make_unique<HumanPresenceOrientationController>();
  885. }
  886. // Construct SnoopingProtectionController, must be constructed after
  887. // HumanPresenceOrientationController.
  888. if (features::IsSnoopingProtectionEnabled()) {
  889. snooping_protection_controller_ =
  890. std::make_unique<SnoopingProtectionController>();
  891. }
  892. // Manages lifetime of DiagnosticApp logs.
  893. if (features::IsLogControllerForDiagnosticsAppEnabled()) {
  894. diagnostics_log_controller_ =
  895. std::make_unique<diagnostics::DiagnosticsLogController>();
  896. }
  897. firmware_update_notification_controller_ =
  898. std::make_unique<FirmwareUpdateNotificationController>(
  899. message_center::MessageCenter::Get());
  900. pcie_peripheral_notification_controller_ =
  901. std::make_unique<PciePeripheralNotificationController>(
  902. message_center::MessageCenter::Get());
  903. usb_peripheral_notification_controller_ =
  904. std::make_unique<UsbPeripheralNotificationController>(
  905. message_center::MessageCenter::Get());
  906. accessibility_focus_ring_controller_ =
  907. std::make_unique<AccessibilityFocusRingControllerImpl>();
  908. accessibility_delegate_.reset(shell_delegate_->CreateAccessibilityDelegate());
  909. accessibility_controller_ = std::make_unique<AccessibilityControllerImpl>();
  910. toast_manager_ = std::make_unique<ToastManagerImpl>();
  911. peripheral_battery_listener_ = std::make_unique<PeripheralBatteryListener>();
  912. peripheral_battery_notifier_ = std::make_unique<PeripheralBatteryNotifier>(
  913. peripheral_battery_listener_.get());
  914. power_event_observer_ = std::make_unique<PowerEventObserver>();
  915. window_cycle_controller_ = std::make_unique<WindowCycleController>();
  916. multitask_menu_nudge_controller_ =
  917. std::make_unique<MultitaskMenuNudgeController>();
  918. capture_mode_controller_ = std::make_unique<CaptureModeController>(
  919. shell_delegate_->CreateCaptureModeDelegate());
  920. // Accelerometer file reader starts listening to tablet mode controller.
  921. AccelerometerReader::GetInstance()->StartListenToTabletModeController();
  922. // Install the custom factory early on so that views::FocusManagers for Tray,
  923. // Shelf, and WallPaper could be created by the factory.
  924. views::FocusManagerFactory::Install(new AshFocusManagerFactory);
  925. wallpaper_controller_ = WallpaperControllerImpl::Create(local_state_);
  926. if (features::IsRgbKeyboardEnabled()) {
  927. // Initialized after |wallpaper_controller_| because we will need to observe
  928. // when the extracted wallpaper color changes.
  929. keyboard_backlight_color_controller_ =
  930. std::make_unique<KeyboardBacklightColorController>();
  931. }
  932. window_positioner_ = std::make_unique<WindowPositioner>();
  933. native_cursor_manager_ = new NativeCursorManagerAsh;
  934. cursor_manager_ =
  935. std::make_unique<CursorManager>(base::WrapUnique(native_cursor_manager_));
  936. InitializeDisplayManager();
  937. // RefreshFontParams depends on display prefs.
  938. display_manager_->RefreshFontParams();
  939. // This will initialize aura::Env which requires |display_manager_| to
  940. // be initialized first.
  941. aura::Env* env = aura::Env::GetInstance();
  942. if (context_factory)
  943. env->set_context_factory(context_factory);
  944. ash_color_provider_ = std::make_unique<AshColorProvider>();
  945. ui::ColorProviderManager::Get().AppendColorProviderInitializer(
  946. base::BindRepeating(AddCrosStylesColorMixer));
  947. ui::ColorProviderManager::Get().AppendColorProviderInitializer(
  948. base::BindRepeating(AddAshColorMixer));
  949. // Geolocation controller needs to be created before any `ScheduledFeature`
  950. // subclasses such as night light and dark mode controllers because
  951. // `ScheduledFeature` ctor will access `geolocation_controller_` from
  952. // `Shell`.
  953. geolocation_controller_ = std::make_unique<GeolocationController>(
  954. shell_delegate_->GetGeolocationUrlLoaderFactory());
  955. // Night Light depends on the display manager, the display color manager,
  956. // aura::Env, and geolocation controller, so initialize it after all have
  957. // been initialized.
  958. night_light_controller_ = std::make_unique<NightLightControllerImpl>();
  959. dark_light_mode_controller_ = std::make_unique<DarkLightModeControllerImpl>();
  960. // Privacy Screen depends on the display manager, so initialize it after
  961. // display manager was properly initialized.
  962. privacy_screen_controller_ = std::make_unique<PrivacyScreenController>();
  963. if (media::ShouldEnableAutoFraming())
  964. autozoom_controller_ = std::make_unique<AutozoomControllerImpl>();
  965. // Fast Pair depends on the display manager, so initialize it after
  966. // display manager was properly initialized.
  967. if (base::FeatureList::IsEnabled(features::kFastPair)) {
  968. quick_pair_mediator_ = quick_pair::Mediator::Factory::Create();
  969. }
  970. // The WindowModalityController needs to be at the front of the input event
  971. // pretarget handler list to ensure that it processes input events when modal
  972. // windows are active.
  973. window_modality_controller_ =
  974. std::make_unique<::wm::WindowModalityController>(this, env);
  975. event_rewriter_controller_ = std::make_unique<EventRewriterControllerImpl>();
  976. env_filter_ = std::make_unique<::wm::CompoundEventFilter>();
  977. AddPreTargetHandler(env_filter_.get());
  978. // FocusController takes ownership of AshFocusRules.
  979. focus_rules_ = new AshFocusRules();
  980. focus_controller_ = std::make_unique<::wm::FocusController>(focus_rules_);
  981. focus_controller_->AddObserver(this);
  982. overview_controller_ = std::make_unique<OverviewController>();
  983. screen_position_controller_ = std::make_unique<ScreenPositionController>();
  984. frame_throttling_controller_ =
  985. std::make_unique<FrameThrottlingController>(context_factory);
  986. if (features::IsTabClusterUIEnabled())
  987. tab_cluster_ui_controller_ = std::make_unique<TabClusterUIController>();
  988. window_tree_host_manager_->Start();
  989. AshWindowTreeHostInitParams ash_init_params;
  990. window_tree_host_manager_->CreatePrimaryHost(ash_init_params);
  991. // Create the desks controller right after the window tree host manager is
  992. // started, and before anything else is created, including the initialization
  993. // of the hosts and the root window controllers. Many things may need to query
  994. // the active desk, even at this early stage. For this the controller must be
  995. // present at all times. The desks controller also depends on the focus
  996. // controller.
  997. desks_controller_ = std::make_unique<DesksController>();
  998. desks_templates_delegate_ = shell_delegate_->CreateDesksTemplatesDelegate();
  999. Shell::SetRootWindowForNewWindows(GetPrimaryRootWindow());
  1000. resolution_notification_controller_ =
  1001. std::make_unique<ResolutionNotificationController>();
  1002. cursor_manager_->SetDisplay(
  1003. display::Screen::GetScreen()->GetPrimaryDisplay());
  1004. accelerator_controller_ = std::make_unique<AcceleratorControllerImpl>();
  1005. clipboard_history_controller_ =
  1006. std::make_unique<ClipboardHistoryControllerImpl>();
  1007. // `HoldingSpaceController` must be instantiated before the shelf.
  1008. holding_space_controller_ = std::make_unique<HoldingSpaceController>();
  1009. calendar_controller_ = std::make_unique<CalendarController>();
  1010. shelf_config_ = std::make_unique<ShelfConfig>();
  1011. shelf_controller_ = std::make_unique<ShelfController>();
  1012. shell_tab_handler_ = std::make_unique<ShellTabHandler>(this);
  1013. AddPreTargetHandler(shell_tab_handler_.get());
  1014. magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
  1015. AddPreTargetHandler(magnifier_key_scroll_handler_.get());
  1016. speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
  1017. AddPreTargetHandler(speech_feedback_handler_.get());
  1018. // The order in which event filters are added is significant.
  1019. // ui::UserActivityDetector passes events to observers, so let them get
  1020. // rewritten first.
  1021. user_activity_detector_ = std::make_unique<ui::UserActivityDetector>();
  1022. overlay_filter_ = std::make_unique<OverlayEventFilter>();
  1023. AddPreTargetHandler(overlay_filter_.get());
  1024. control_v_histogram_recorder_ = std::make_unique<ControlVHistogramRecorder>();
  1025. AddPreTargetHandler(control_v_histogram_recorder_.get());
  1026. accelerator_filter_ = std::make_unique<::wm::AcceleratorFilter>(
  1027. std::make_unique<PreTargetAcceleratorHandler>());
  1028. AddPreTargetHandler(accelerator_filter_.get());
  1029. event_transformation_handler_ =
  1030. std::make_unique<EventTransformationHandler>();
  1031. AddPreTargetHandler(event_transformation_handler_.get());
  1032. back_gesture_event_handler_ = std::make_unique<BackGestureEventHandler>();
  1033. AddPreTargetHandler(back_gesture_event_handler_.get());
  1034. toplevel_window_event_handler_ =
  1035. std::make_unique<ToplevelWindowEventHandler>();
  1036. system_gesture_filter_ = std::make_unique<SystemGestureEventFilter>();
  1037. AddPreTargetHandler(system_gesture_filter_.get());
  1038. sticky_keys_controller_ = std::make_unique<StickyKeysController>();
  1039. screen_pinning_controller_ = std::make_unique<ScreenPinningController>();
  1040. power_prefs_ = std::make_unique<PowerPrefs>(
  1041. chromeos::PowerPolicyController::Get(),
  1042. chromeos::PowerManagerClient::Get(), local_state_);
  1043. backlights_forced_off_setter_ = std::make_unique<BacklightsForcedOffSetter>();
  1044. tray_action_ =
  1045. std::make_unique<TrayAction>(backlights_forced_off_setter_.get());
  1046. lock_state_controller_ = std::make_unique<LockStateController>(
  1047. shutdown_controller_.get(), local_state_);
  1048. power_button_controller_ = std::make_unique<PowerButtonController>(
  1049. backlights_forced_off_setter_.get());
  1050. // Pass the initial display state to PowerButtonController.
  1051. power_button_controller_->OnDisplayModeChanged(
  1052. display_configurator()->cached_displays());
  1053. drag_drop_controller_ = std::make_unique<DragDropController>();
  1054. mouse_cursor_filter_ = std::make_unique<MouseCursorEventFilter>();
  1055. AddPreTargetHandler(mouse_cursor_filter_.get(),
  1056. ui::EventTarget::Priority::kAccessibility);
  1057. if (features::IsAdaptiveChargingEnabled()) {
  1058. adaptive_charging_controller_ =
  1059. std::make_unique<AdaptiveChargingController>();
  1060. }
  1061. // Create Controllers that may need root window.
  1062. // TODO(oshima): Move as many controllers before creating
  1063. // RootWindowController as possible.
  1064. visibility_controller_ = std::make_unique<AshVisibilityController>();
  1065. laser_pointer_controller_ = std::make_unique<LaserPointerController>();
  1066. partial_magnifier_controller_ =
  1067. std::make_unique<PartialMagnifierController>();
  1068. highlighter_controller_ = std::make_unique<HighlighterController>();
  1069. fullscreen_magnifier_controller_ =
  1070. std::make_unique<FullscreenMagnifierController>();
  1071. mru_window_tracker_ = std::make_unique<MruWindowTracker>();
  1072. assistant_controller_ = std::make_unique<AssistantControllerImpl>();
  1073. // |assistant_controller_| is put before |ambient_controller_| as it will be
  1074. // used by the latter.
  1075. if (chromeos::features::IsAmbientModeEnabled()) {
  1076. mojo::PendingRemote<device::mojom::Fingerprint> fingerprint;
  1077. shell_delegate_->BindFingerprint(
  1078. fingerprint.InitWithNewPipeAndPassReceiver());
  1079. ambient_controller_ =
  1080. std::make_unique<AmbientController>(std::move(fingerprint));
  1081. }
  1082. mojo::PendingRemote<video_capture::mojom::MultiCaptureService>
  1083. multi_capture_service;
  1084. shell_delegate_->BindMultiCaptureService(
  1085. multi_capture_service.InitWithNewPipeAndPassReceiver());
  1086. multi_capture_service_client_ = std::make_unique<MultiCaptureServiceClient>(
  1087. std::move(multi_capture_service));
  1088. // |tablet_mode_controller_| |mru_window_tracker_|, and
  1089. // |assistant_controller_| are put before |app_list_controller_| as they are
  1090. // used in its constructor.
  1091. app_list_controller_ = std::make_unique<AppListControllerImpl>();
  1092. // Create PersistentDesksBarController after `overview_controller_`,
  1093. // `tablet_mode_controller_`, `desks_controller_` and
  1094. // `app_list_controller_` that it observes.
  1095. if (features::IsBentoBarEnabled()) {
  1096. persistent_desks_bar_controller_ =
  1097. std::make_unique<PersistentDesksBarController>();
  1098. }
  1099. autoclick_controller_ = std::make_unique<AutoclickController>();
  1100. high_contrast_controller_ = std::make_unique<HighContrastController>();
  1101. docked_magnifier_controller_ = std::make_unique<DockedMagnifierController>();
  1102. video_detector_ = std::make_unique<VideoDetector>();
  1103. tooltip_controller_ = std::make_unique<views::corewm::TooltipController>(
  1104. std::make_unique<views::corewm::TooltipAura>(), activation_client());
  1105. AddPreTargetHandler(tooltip_controller_.get());
  1106. modality_filter_ = std::make_unique<SystemModalContainerEventFilter>(this);
  1107. AddPreTargetHandler(modality_filter_.get());
  1108. event_client_ = std::make_unique<EventClientImpl>();
  1109. resize_shadow_controller_ = std::make_unique<ResizeShadowController>();
  1110. shadow_controller_ = std::make_unique<::wm::ShadowController>(
  1111. focus_controller_.get(), std::make_unique<WmShadowControllerDelegate>(),
  1112. env);
  1113. logout_confirmation_controller_ =
  1114. std::make_unique<LogoutConfirmationController>();
  1115. if (!ash::features::IsBluetoothRevampEnabled()) {
  1116. // May trigger initialization of the Bluetooth adapter.
  1117. tray_bluetooth_helper_->Initialize();
  1118. }
  1119. // Create AshTouchTransformController before
  1120. // WindowTreeHostManager::InitDisplays()
  1121. // since AshTouchTransformController listens on
  1122. // WindowTreeHostManager::Observer::OnDisplaysInitialized().
  1123. touch_transformer_controller_ = std::make_unique<AshTouchTransformController>(
  1124. display_manager_.get(),
  1125. std::make_unique<display::DefaultTouchTransformSetter>());
  1126. // |system_tray_model_| should be available before
  1127. // |system_notification_controller_| is initialized and Shelf is created by
  1128. // WindowTreeHostManager::InitHosts.
  1129. system_tray_model_ = std::make_unique<SystemTrayModel>();
  1130. // The |shelf_config_| needs |app_list_controller_| and |system_tray_model_|
  1131. // to initialize itself.
  1132. shelf_config_->Init();
  1133. // The `shelf_controller_` needs `app_list_controller_` to initialize
  1134. // launcher_nudge_controller_.
  1135. shelf_controller_->Init();
  1136. nearby_share_controller_ = std::make_unique<NearbyShareControllerImpl>();
  1137. nearby_share_delegate_ = shell_delegate_->CreateNearbyShareDelegate(
  1138. nearby_share_controller_.get());
  1139. system_notification_controller_ =
  1140. std::make_unique<SystemNotificationController>();
  1141. window_tree_host_manager_->InitHosts();
  1142. // Create virtual keyboard after WindowTreeHostManager::InitHosts() since
  1143. // it may enable the virtual keyboard immediately, which requires a
  1144. // WindowTreeHostManager to host the keyboard window.
  1145. keyboard_controller_->CreateVirtualKeyboard(std::move(keyboard_ui_factory));
  1146. // Create window restore controller after WindowTreeHostManager::InitHosts()
  1147. // since it may need to add observers to root windows.
  1148. window_restore_controller_ = std::make_unique<WindowRestoreController>();
  1149. cursor_manager_->HideCursor(); // Hide the mouse cursor on startup.
  1150. cursor_manager_->SetCursor(ui::mojom::CursorType::kPointer);
  1151. mojo::PendingRemote<device::mojom::Fingerprint> fingerprint;
  1152. shell_delegate_->BindFingerprint(
  1153. fingerprint.InitWithNewPipeAndPassReceiver());
  1154. user_activity_notifier_ =
  1155. std::make_unique<ui::UserActivityPowerManagerNotifier>(
  1156. user_activity_detector_.get(), std::move(fingerprint));
  1157. video_activity_notifier_ =
  1158. std::make_unique<VideoActivityNotifier>(video_detector_.get());
  1159. if (ash::features::IsBluetoothRevampEnabled()) {
  1160. bluetooth_device_status_ui_handler_ =
  1161. std::make_unique<BluetoothDeviceStatusUiHandler>();
  1162. }
  1163. bluetooth_notification_controller_ =
  1164. std::make_unique<BluetoothNotificationController>(
  1165. message_center::MessageCenter::Get());
  1166. screen_orientation_controller_ =
  1167. std::make_unique<ScreenOrientationController>();
  1168. cros_display_config_ = std::make_unique<CrosDisplayConfig>();
  1169. screen_layout_observer_ = std::make_unique<ScreenLayoutObserver>();
  1170. sms_observer_ = std::make_unique<SmsObserver>();
  1171. snap_controller_ = std::make_unique<SnapControllerImpl>();
  1172. key_accessibility_enabler_ = std::make_unique<KeyAccessibilityEnabler>();
  1173. // Create UserSettingsEventLogger after |system_tray_model_| and
  1174. // |video_detector_| which it observes.
  1175. ml::UserSettingsEventLogger::CreateInstance();
  1176. // The compositor thread and main message loop have to be running in
  1177. // order to create mirror window. Run it after the main message loop
  1178. // is started.
  1179. display_manager_->CreateMirrorWindowAsyncIfAny();
  1180. // TODO(1091497): Consider combining DisplayHighlightController and
  1181. // DisplayAlignmentController.
  1182. display_highlight_controller_ =
  1183. std::make_unique<DisplayHighlightController>();
  1184. if (features::IsDisplayAlignmentAssistanceEnabled()) {
  1185. display_alignment_controller_ =
  1186. std::make_unique<DisplayAlignmentController>();
  1187. }
  1188. if (chromeos::features::IsProjectorEnabled())
  1189. projector_controller_ = std::make_unique<ProjectorControllerImpl>();
  1190. if (chromeos::wm::features::IsFloatWindowEnabled())
  1191. float_controller_ = std::make_unique<FloatController>();
  1192. // Injects the factory which fulfills the implementation of the text context
  1193. // menu exclusive to CrOS.
  1194. views::ViewsTextServicesContextMenuChromeos::SetImplFactory(
  1195. base::BindRepeating(
  1196. [](ui::SimpleMenuModel* menu_model, views::Textfield* textfield)
  1197. -> std::unique_ptr<views::ViewsTextServicesContextMenu> {
  1198. return std::make_unique<ViewsTextServicesContextMenuImpl>(
  1199. menu_model, textfield);
  1200. }));
  1201. for (auto& observer : shell_observers_)
  1202. observer.OnShellInitialized();
  1203. user_metrics_recorder_->OnShellInitialized();
  1204. occlusion_tracker_pauser_ = std::make_unique<OcclusionTrackerPauser>();
  1205. // Initialize the D-Bus bus and services for ash.
  1206. dbus_bus_ = dbus_bus;
  1207. ash_dbus_services_ = std::make_unique<AshDBusServices>(dbus_bus.get());
  1208. }
  1209. void Shell::InitializeDisplayManager() {
  1210. display_manager_->InitConfigurator(
  1211. ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate());
  1212. display_configuration_controller_ =
  1213. std::make_unique<DisplayConfigurationController>(
  1214. display_manager_.get(), window_tree_host_manager_.get());
  1215. display_configuration_observer_ =
  1216. std::make_unique<DisplayConfigurationObserver>();
  1217. persistent_window_controller_ =
  1218. std::make_unique<PersistentWindowController>();
  1219. projecting_observer_ =
  1220. std::make_unique<ProjectingObserver>(display_manager_->configurator());
  1221. if (base::FeatureList::IsEnabled(features::kSeamlessRefreshRateSwitching)) {
  1222. refresh_rate_throttle_controller_ =
  1223. std::make_unique<RefreshRateThrottleController>(
  1224. display_manager_->configurator(), PowerStatus::Get());
  1225. }
  1226. display_prefs_ = std::make_unique<DisplayPrefs>(local_state_);
  1227. bool display_initialized = display_manager_->InitFromCommandLine();
  1228. if (!display_initialized) {
  1229. if (chromeos::IsRunningAsSystemCompositor()) {
  1230. display_change_observer_ =
  1231. std::make_unique<display::DisplayChangeObserver>(
  1232. display_manager_.get());
  1233. display_error_observer_ = std::make_unique<DisplayErrorObserver>();
  1234. display_shutdown_observer_ = std::make_unique<DisplayShutdownObserver>(
  1235. display_manager_->configurator());
  1236. display_manager_->ForceInitialConfigureWithObservers(
  1237. display_change_observer_.get(), display_error_observer_.get());
  1238. display_initialized = true;
  1239. }
  1240. }
  1241. display_color_manager_ =
  1242. std::make_unique<DisplayColorManager>(display_manager_->configurator());
  1243. if (!display_initialized)
  1244. display_manager_->InitDefaultDisplay();
  1245. }
  1246. void Shell::InitRootWindow(aura::Window* root_window) {
  1247. DCHECK(focus_controller_);
  1248. DCHECK(visibility_controller_.get());
  1249. aura::client::SetFocusClient(root_window, focus_controller_.get());
  1250. ::wm::SetActivationClient(root_window, focus_controller_.get());
  1251. root_window->AddPreTargetHandler(focus_controller_.get());
  1252. aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
  1253. aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
  1254. aura::client::SetScreenPositionClient(root_window,
  1255. screen_position_controller_.get());
  1256. aura::client::SetCursorClient(root_window, cursor_manager_.get());
  1257. ::wm::SetTooltipClient(root_window, tooltip_controller_.get());
  1258. aura::client::SetEventClient(root_window, event_client_.get());
  1259. ::wm::SetWindowMoveClient(root_window, toplevel_window_event_handler_.get());
  1260. root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
  1261. root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
  1262. }
  1263. void Shell::CloseAllRootWindowChildWindows() {
  1264. for (aura::Window* root : GetAllRootWindows()) {
  1265. RootWindowController* controller = RootWindowController::ForWindow(root);
  1266. if (controller) {
  1267. controller->CloseChildWindows();
  1268. } else {
  1269. while (!root->children().empty()) {
  1270. aura::Window* child = root->children()[0];
  1271. delete child;
  1272. }
  1273. }
  1274. }
  1275. }
  1276. bool Shell::CanWindowReceiveEvents(aura::Window* window) {
  1277. RootWindowControllerList controllers = GetAllRootWindowControllers();
  1278. for (RootWindowController* controller : controllers) {
  1279. if (controller->CanWindowReceiveEvents(window))
  1280. return true;
  1281. }
  1282. return false;
  1283. }
  1284. ////////////////////////////////////////////////////////////////////////////////
  1285. // Shell, ui::EventTarget overrides:
  1286. bool Shell::CanAcceptEvent(const ui::Event& event) {
  1287. return true;
  1288. }
  1289. ui::EventTarget* Shell::GetParentTarget() {
  1290. return aura::Env::GetInstance();
  1291. }
  1292. std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
  1293. return nullptr;
  1294. }
  1295. ui::EventTargeter* Shell::GetEventTargeter() {
  1296. NOTREACHED();
  1297. return nullptr;
  1298. }
  1299. void Shell::OnWindowActivated(
  1300. ::wm::ActivationChangeObserver::ActivationReason reason,
  1301. aura::Window* gained_active,
  1302. aura::Window* lost_active) {
  1303. if (!gained_active)
  1304. return;
  1305. Shell::SetRootWindowForNewWindows(gained_active->GetRootWindow());
  1306. }
  1307. void Shell::OnFirstSessionStarted() {
  1308. // Enable magnifier scroll keys as there may be no mouse cursor in kiosk mode.
  1309. MagnifierKeyScroller::SetEnabled(session_controller_->IsRunningInAppMode());
  1310. // Enable long press action to toggle spoken feedback with hotrod remote
  1311. // which can't handle shortcuts.
  1312. SpokenFeedbackToggler::SetEnabled(session_controller_->IsRunningInAppMode());
  1313. // Reset user prefs related to contextual tooltips.
  1314. if (switches::ContextualNudgesResetShownCount())
  1315. contextual_tooltip::ClearPrefs();
  1316. // The launcher is not available before login, so start tracking usage after
  1317. // the session starts.
  1318. app_list_feature_usage_metrics_ =
  1319. std::make_unique<AppListFeatureUsageMetrics>();
  1320. if (features::AreGlanceablesEnabled()) {
  1321. // Show glanceables after signin.
  1322. // TODO(crbug.com/1353119): Show only when session restore would trigger.
  1323. glanceables_controller_->CreateUi();
  1324. glanceables_controller_->FetchData();
  1325. }
  1326. }
  1327. void Shell::OnSessionStateChanged(session_manager::SessionState state) {
  1328. const bool is_session_active = state == session_manager::SessionState::ACTIVE;
  1329. // Initialize the |shelf_window_watcher_| when a session becomes active.
  1330. // Shelf itself is initialized in RootWindowController.
  1331. if (is_session_active && !shelf_window_watcher_) {
  1332. shelf_window_watcher_ =
  1333. std::make_unique<ShelfWindowWatcher>(shelf_controller()->model());
  1334. }
  1335. // Disable drag-and-drop during OOBE and GAIA login screens by only enabling
  1336. // the controller when the session is active. https://crbug.com/464118
  1337. drag_drop_controller_->set_enabled(is_session_active);
  1338. }
  1339. void Shell::OnLoginStatusChanged(LoginStatus login_status) {
  1340. UpdateAfterLoginStatusChange(login_status);
  1341. }
  1342. void Shell::OnLockStateChanged(bool locked) {
  1343. #ifndef NDEBUG
  1344. // Make sure that there is no system modal in Lock layer when unlocked.
  1345. if (!locked) {
  1346. aura::Window::Windows containers = GetContainersForAllRootWindows(
  1347. kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
  1348. for (aura::Window* container : containers)
  1349. DCHECK(container->children().empty());
  1350. }
  1351. #endif
  1352. }
  1353. } // namespace ash