From b092ae622b9ab3856d64d3eca543e4ecb243be77 Mon Sep 17 00:00:00 2001 From: Scott Violet Date: Sat, 11 Aug 2018 01:14:35 +0000 Subject: [PATCH] chromeos: add SingleProcessMash mode This makes Ash create an Env if passed SingleProcessMash. In addition this makes all window creation go through a factory that ensures the right env is supplied. See https://docs.google.com/document/d/11ha_KioDdXe4iZS2AML1foKnCJlNKm7Q1hFr6VW8dV4/edit for more details. This also adds the feature to ui/base. BUG=847992 TEST=covered by tests Change-Id: Ica3c433627222f0e076dddaf19b1ab09168cebeb Reviewed-on: https://chromium-review.googlesource.com/1168282 Commit-Queue: Scott Violet Reviewed-by: James Cook Cr-Commit-Position: refs/heads/master@{#582411} --- ash/BUILD.gn | 6 +++ ash/README.md | 22 +++++++++ ash/app_launch_unittest.cc | 6 +++ ash/ash_service_unittest.cc | 6 +++ ash/components/fast_ink/fast_ink_view.cc | 6 ++- ash/display/cursor_window_controller.cc | 7 +-- ash/display/display_manager_unittest.cc | 4 +- ash/display/display_util.cc | 2 +- ash/display/mirror_window_controller.cc | 28 +++++------ .../mouse_cursor_event_filter_unittest.cc | 18 +++---- .../root_window_transformers_unittest.cc | 6 +-- ash/display/screen_ash.cc | 15 +++++- .../screen_position_controller_unittest.cc | 9 ++-- .../unified_mouse_warp_controller_unittest.cc | 20 ++++---- .../window_tree_host_manager_unittest.cc | 12 ++--- ash/drag_drop/drag_drop_tracker.cc | 13 +++-- ash/events/event_rewriter_controller.cc | 4 +- ash/extended_desktop_unittest.cc | 7 +-- ash/frame/detached_title_area_renderer.cc | 3 +- ash/frame/header_view.cc | 3 +- ash/host/DEPS | 1 + ash/host/ash_window_tree_host.cc | 5 -- ash/host/ash_window_tree_host_platform.cc | 7 ++- ...c_input_method_surface_manager_unittest.cc | 3 +- ash/keyboard/test_keyboard_ui.cc | 3 +- ash/magnifier/docked_magnifier_controller.cc | 6 +-- .../magnification_controller_unittest.cc | 8 +-- ...op_task_switch_metric_recorder_unittest.cc | 9 ++-- ash/public/cpp/frame_border_hit_test.cc | 3 +- ash/root_window_controller.cc | 4 +- ash/root_window_controller_unittest.cc | 22 +++++---- ash/shelf/shelf_layout_manager_unittest.cc | 5 +- ash/shelf/shelf_window_watcher_unittest.cc | 11 +++-- ash/shell.cc | 49 +++++++++++++------ ash/shell.h | 9 ++++ ash/shell_unittest.cc | 14 ++++-- .../arc_notification_content_view_unittest.cc | 2 +- .../arc/arc_notification_view_unittest.cc | 4 +- .../arc/mock_arc_notification_surface.cc | 12 +++-- .../arc/mock_arc_notification_surface.h | 7 ++- .../night_light/night_light_controller.cc | 4 +- .../overview/overview_button_tray_unittest.cc | 3 +- ash/system/tray/tray_background_view.cc | 3 +- ash/test/ash_test_base.cc | 7 +-- ash/test/ash_test_helper.cc | 19 ++++++- ash/test/ash_test_suite.cc | 6 ++- ash/test/ui_controls_factory_ash.cc | 2 +- ash/utility/screenshot_controller_unittest.cc | 4 +- ash/wayland/wayland_server_controller.cc | 11 +++-- ash/wayland/wayland_server_controller.h | 11 +++-- ash/window_factory.cc | 20 ++++++++ ash/window_factory.h | 31 ++++++++++++ ash/window_user_data_unittest.cc | 18 +++---- ash/wm/ash_focus_rules_unittest.cc | 3 +- ash/wm/cursor_manager_chromeos.cc | 3 +- ash/wm/drag_window_controller.cc | 3 +- ash/wm/drag_window_resizer_unittest.cc | 29 +++++------ ...mmersive_fullscreen_controller_unittest.cc | 2 +- ash/wm/native_cursor_manager_ash_classic.cc | 9 ++-- ash/wm/non_client_frame_controller.cc | 6 +-- ash/wm/overview/window_selector_unittest.cc | 4 +- ash/wm/stacking_controller_unittest.cc | 6 ++- .../system_gesture_event_filter_unittest.cc | 9 ++-- ...modal_container_layout_manager_unittest.cc | 6 ++- ash/wm/top_level_window_factory.cc | 3 +- ash/wm/toplevel_window_event_handler.cc | 2 +- .../toplevel_window_event_handler_unittest.cc | 6 ++- ash/wm/video_detector.cc | 4 +- ash/wm/window_dimmer.cc | 5 +- ash/wm/window_dimmer_unittest.cc | 14 ++++-- .../workspace_event_handler_unittest.cc | 6 ++- .../workspace_layout_manager_unittest.cc | 15 +++--- .../workspace_window_resizer_unittest.cc | 9 ++-- ash/wm/workspace_controller_unittest.cc | 5 +- ash/ws/window_service_owner.cc | 3 +- ...accessibility_helper_bridge_browsertest.cc | 2 +- chrome/browser/ui/ash/ksv/DEPS | 2 +- .../ash/ksv/keyboard_shortcut_viewer_util.cc | 12 ++++- components/exo/test/exo_test_base.cc | 2 +- .../clients/test/wayland_client_test.cc | 2 +- ui/aura/env.cc | 41 ++++++++++------ ui/aura/env.h | 13 +++++ ui/aura/test/test_windows.cc | 6 ++- ui/aura/test/test_windows.h | 1 + ui/aura/window.cc | 17 +++++++ ui/aura/window.h | 7 +++ ui/aura/window_tree_host_platform.cc | 6 ++- ui/base/ui_base_features.cc | 7 +++ ui/base/ui_base_features.h | 9 ++++ 89 files changed, 551 insertions(+), 248 deletions(-) create mode 100644 ash/window_factory.cc create mode 100644 ash/window_factory.h diff --git a/ash/BUILD.gn b/ash/BUILD.gn index b3c9b28a7ec922..475cacebb01d00 100644 --- a/ash/BUILD.gn +++ b/ash/BUILD.gn @@ -23,6 +23,10 @@ assert(enable_hidpi) assert(use_ozone) component("ash") { + friend = [ + ":ash_unittests", + ":test_support_common", + ] public = [ "accelerators/accelerator_commands.h", "accelerators/accelerator_confirmation_dialog.h", @@ -1180,6 +1184,8 @@ component("ash") { "wallpaper/wallpaper_view.cc", "wallpaper/wallpaper_widget_controller.cc", "wallpaper/wallpaper_window_state_manager.cc", + "window_factory.cc", + "window_factory.h", "wm/always_on_top_controller.cc", "wm/ash_focus_rules.cc", "wm/base_state.cc", diff --git a/ash/README.md b/ash/README.md index 9de5c3b8e770df..951f871ea23273 100644 --- a/ash/README.md +++ b/ash/README.md @@ -41,6 +41,28 @@ Ash used to support a "mus" mode that ran the mojo window service from //services/ui on a background thread in the browser process. This configuration was deprecated in April 2018. +SingleProcessMash +----------------- + +Before launching Mash we plan to launch SingleProcessMash. SingleProcessMash is +similar to "classic ash" in that ash and the browser still live in the same +process and on the same thread, but all non-ash UI code (such as browser +windows) will use the WindowService over mojo. This results in exercising much +of the same code as in mash, but everything is still in the process. + +In SingleProcessMash mode there are two aura::Envs. Ash (Shell) creates one and +the browser creates one. In order to ensure the right one is used do the +following: + +. When creating a Widget set the parent and/or context. If you don't need a + specific parent (container), more often than not using a context of + Shell::GetRootWindowForNewWindows() is what you want. +. If you are creating aura::Windows directly, use the ash::window_factory. +. If you need access to aura::Env, get it from Shell. Shell always returns the + right one, regardless of mode. + +See https://docs.google.com/document/d/11ha_KioDdXe4iZS2AML1foKnCJlNKm7Q1hFr6VW8dV4/edit for more details. + Mash Tests ----- ash_unittests has some tests specific to Mash, but in general Ash code should diff --git a/ash/app_launch_unittest.cc b/ash/app_launch_unittest.cc index d4101b7fadab47..89ac6d94944711 100644 --- a/ash/app_launch_unittest.cc +++ b/ash/app_launch_unittest.cc @@ -10,6 +10,7 @@ #include "services/service_manager/public/cpp/service_test.h" #include "services/ui/public/interfaces/constants.mojom.h" #include "services/ui/public/interfaces/window_server_test.mojom.h" +#include "ui/base/ui_base_features.h" #include "ui/views/layout/layout_provider.h" namespace ash { @@ -36,6 +37,11 @@ class AppLaunchTest : public service_manager::test::ServiceTest { }; TEST_F(AppLaunchTest, TestQuickLaunch) { + // This test launches ash in a separate service. That doesn't make sense with + // SingleProcessMash. + if (features::IsSingleProcessMash()) + return; + connector()->StartService(mojom::kServiceName); connector()->StartService(quick_launch::mojom::kServiceName); diff --git a/ash/ash_service_unittest.cc b/ash/ash_service_unittest.cc index 6aafc69fc99c9a..596252340c7173 100644 --- a/ash/ash_service_unittest.cc +++ b/ash/ash_service_unittest.cc @@ -26,6 +26,7 @@ #include "ui/aura/mus/window_tree_host_mus_init_params.h" #include "ui/aura/test/env_test_helper.h" #include "ui/aura/window.h" +#include "ui/base/ui_base_features.h" #include "ui/display/display.h" #include "ui/display/display_list.h" #include "ui/display/screen_base.h" @@ -93,6 +94,11 @@ void OnEmbed(bool success) { } TEST_F(AshServiceTest, OpenWindow) { + // This test launches ash in a separate service. That doesn't make sense with + // SingleProcessMash. + if (features::IsSingleProcessMash()) + return; + display::ScreenBase screen; screen.display_list().AddDisplay( display::Display(1, gfx::Rect(0, 0, 200, 200)), diff --git a/ash/components/fast_ink/fast_ink_view.cc b/ash/components/fast_ink/fast_ink_view.cc index ecf29c6bed02d4..085756a8e39e59 100644 --- a/ash/components/fast_ink/fast_ink_view.cc +++ b/ash/components/fast_ink/fast_ink_view.cc @@ -313,7 +313,8 @@ FastInkView::FastInkView(aura::Window* container, // but with potential tearing. Note that we have to draw into a temporary // surface and copy it into GPU memory buffer to avoid flicker. gpu_memory_buffer_ = - aura::Env::GetInstance() + widget_->GetNativeWindow() + ->env() ->context_factory() ->GetGpuMemoryBufferManager() ->CreateGpuMemoryBuffer(buffer_size_, @@ -395,7 +396,8 @@ void FastInkView::SubmitCompositorFrame() { // new instance to be created in lost context situations is acceptable and // keeps the code simple. if (!resource->context_provider) { - resource->context_provider = aura::Env::GetInstance() + resource->context_provider = widget_->GetNativeWindow() + ->env() ->context_factory() ->SharedMainThreadContextProvider(); if (!resource->context_provider) { diff --git a/ash/display/cursor_window_controller.cc b/ash/display/cursor_window_controller.cc index fda1aaed895740..5e4a19911b0a1e 100644 --- a/ash/display/cursor_window_controller.cc +++ b/ash/display/cursor_window_controller.cc @@ -16,6 +16,7 @@ #include "ash/root_window_controller.h" #include "ash/session/session_controller.h" #include "ash/shell.h" +#include "ash/window_factory.h" #include "base/command_line.h" #include "base/metrics/histogram_macros.h" #include "components/prefs/pref_service.h" @@ -219,7 +220,7 @@ void CursorWindowController::SetDisplay(const display::Display& display) { void CursorWindowController::UpdateLocation() { if (!cursor_window_) return; - gfx::Point point = aura::Env::GetInstance()->last_mouse_location(); + gfx::Point point = Shell::Get()->aura_env()->last_mouse_location(); point.Offset(-bounds_in_screen_.x(), -bounds_in_screen_.y()); point.Offset(-hot_point_.x(), -hot_point_.y()); gfx::Rect bounds = cursor_window_->bounds(); @@ -263,7 +264,7 @@ void CursorWindowController::SetContainer(aura::Window* container) { } else { // Reusing the window does not work when the display is disconnected. // Just creates a new one instead. crbug.com/384218. - cursor_window_.reset(new aura::Window(delegate_.get())); + cursor_window_ = window_factory::NewWindow(delegate_.get()); cursor_window_->SetTransparent(true); cursor_window_->Init(ui::LAYER_TEXTURED); cursor_window_->SetEventTargetingPolicy( @@ -371,7 +372,7 @@ void CursorWindowController::UpdateCursorVisibility() { void CursorWindowController::UpdateCursorView() { cursor_view_.reset(new cursor::CursorView( - container_, aura::Env::GetInstance()->last_mouse_location(), + container_, Shell::Get()->aura_env()->last_mouse_location(), is_cursor_motion_blur_enabled_)); UpdateCursorImage(); } diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc index 0fc195491df353..9659641ac79ce9 100644 --- a/ash/display/display_manager_unittest.cc +++ b/ash/display/display_manager_unittest.cc @@ -2053,7 +2053,7 @@ TEST_F(DisplayManagerTest, UpdateMouseCursorAfterRotateZoom) { // Make sure just rotating will not change native location. UpdateDisplay("300x200,200x150"); aura::Window::Windows root_windows = Shell::GetAllRootWindows(); - aura::Env* env = aura::Env::GetInstance(); + aura::Env* env = Shell::Get()->aura_env(); ui::test::EventGenerator generator1(root_windows[0]); ui::test::EventGenerator generator2(root_windows[1]); @@ -3589,7 +3589,7 @@ TEST_F(DisplayManagerUiScaleTest, UpdateMouseCursorAfterRotateZoom) { // Make sure just zooming will not change native location. UpdateDisplay("600x400*2,400x300"); aura::Window::Windows root_windows = Shell::GetAllRootWindows(); - aura::Env* env = aura::Env::GetInstance(); + aura::Env* env = Shell::Get()->aura_env(); ui::test::EventGenerator generator1(root_windows[0]); ui::test::EventGenerator generator2(root_windows[1]); diff --git a/ash/display/display_util.cc b/ash/display/display_util.cc index 698663aa08add0..3e2d26c3800657 100644 --- a/ash/display/display_util.cc +++ b/ash/display/display_util.cc @@ -133,7 +133,7 @@ void MoveCursorTo(AshWindowTreeHost* ash_host, Shell::GetPrimaryRootWindow()->GetHost()->ConvertScreenInPixelsToDIP( &new_point_in_screen); } - aura::Env::GetInstance()->SetLastMouseLocation(new_point_in_screen); + Shell::Get()->aura_env()->SetLastMouseLocation(new_point_in_screen); } } diff --git a/ash/display/mirror_window_controller.cc b/ash/display/mirror_window_controller.cc index 5522c46ebe4f40..add0108d496f1e 100644 --- a/ash/display/mirror_window_controller.cc +++ b/ash/display/mirror_window_controller.cc @@ -16,6 +16,7 @@ #include "ash/public/cpp/config.h" #include "ash/root_window_settings.h" #include "ash/shell.h" +#include "ash/window_factory.h" #include "base/strings/stringprintf.h" #include "base/threading/thread_task_runner_handle.h" #include "ui/aura/client/capture_client.h" @@ -122,6 +123,10 @@ int64_t GetCurrentReflectingSourceId() { return display::kInvalidDisplayId; } +ui::ContextFactoryPrivate* GetContextFactoryPrivate() { + return Shell::Get()->aura_env()->context_factory_private(); +} + } // namespace struct MirrorWindowController::MirroringHostInfo { @@ -213,7 +218,7 @@ void MirrorWindowController::UpdateWindow( host->Show(); aura::Window* mirror_window = host_info->mirror_window = - new aura::Window(nullptr); + window_factory::NewWindow().release(); mirror_window->Init(ui::LAYER_SOLID_COLOR); host->window()->AddChild(mirror_window); host_info->ash_host->SetRootWindowTransformer(std::move(transformer)); @@ -223,15 +228,12 @@ void MirrorWindowController::UpdateWindow( DCHECK_NE(gfx::kNullAcceleratedWidget, host->GetAcceleratedWidget()); if (reflector_) { reflector_->AddMirroringLayer(mirror_window->layer()); - } else if (aura::Env::GetInstance()->context_factory_private()) { - reflector_ = - aura::Env::GetInstance() - ->context_factory_private() - ->CreateReflector( - Shell::GetRootWindowForDisplayId(reflecting_source_id_) - ->GetHost() - ->compositor(), - mirror_window->layer()); + } else if (GetContextFactoryPrivate()) { + reflector_ = GetContextFactoryPrivate()->CreateReflector( + Shell::GetRootWindowForDisplayId(reflecting_source_id_) + ->GetHost() + ->compositor(), + mirror_window->layer()); } } else { AshWindowTreeHost* ash_host = @@ -261,8 +263,7 @@ void MirrorWindowController::UpdateWindow( if (mirroring_host_info_map_.empty() && reflector_) { // Close the mirror window if all displays are disconnected. - aura::Env::GetInstance()->context_factory_private()->RemoveReflector( - reflector_.get()); + GetContextFactoryPrivate()->RemoveReflector(reflector_.get()); reflector_.reset(); } } @@ -301,8 +302,7 @@ void MirrorWindowController::CloseIfNotNecessary() { void MirrorWindowController::Close(bool delay_host_deletion) { if (reflector_) { - aura::Env::GetInstance()->context_factory_private()->RemoveReflector( - reflector_.get()); + GetContextFactoryPrivate()->RemoveReflector(reflector_.get()); reflector_.reset(); } diff --git a/ash/display/mouse_cursor_event_filter_unittest.cc b/ash/display/mouse_cursor_event_filter_unittest.cc index a3165a2af53c2c..ef5341a514edb6 100644 --- a/ash/display/mouse_cursor_event_filter_unittest.cc +++ b/ash/display/mouse_cursor_event_filter_unittest.cc @@ -50,12 +50,12 @@ TEST_F(MouseCursorEventFilterTest, WarpMouse) { // Touch the right edge of the primary root window. Pointer should warp. EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 11))); EXPECT_EQ("501,11", // by 2px. - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); // Touch the left edge of the secondary root window. Pointer should warp. EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(500, 11))); EXPECT_EQ("498,11", // by 2px. - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); // Touch the left edge of the primary root window. EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(0, 11))); @@ -86,13 +86,13 @@ TEST_F(MouseCursorEventFilterTest, WarpMouseDifferentSizeDisplays) { // because 1px left of (0, 500) is outside the primary root window. EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(501, 500))); EXPECT_EQ("501,500", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); // Touch the left edge of the secondary root window. Pointer should warp // because 1px left of (0, 480) is inside the primary root window. EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(500, 480))); EXPECT_EQ("498,480", // by 2px. - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); } // Verifies if the mouse pointer correctly moves between displays with @@ -107,18 +107,18 @@ TEST_F(MouseCursorEventFilterTest, WarpMouseDifferentScaleDisplaysInNative) { .placement_list[0] .position); - aura::Env::GetInstance()->SetLastMouseLocation(gfx::Point(900, 123)); + Shell::Get()->aura_env()->SetLastMouseLocation(gfx::Point(900, 123)); EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 123))); EXPECT_EQ("500,123", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); // Touch the edge of 2nd display again and make sure it warps to // 1st dislay. EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(500, 123))); // TODO(oshima): Due to a bug in EventGenerator, the screen coordinates // is shrunk by dsf once. Fix this. EXPECT_EQ("498,61", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); } // Verifies if MouseCursorEventFilter::set_mouse_warp_enabled() works as @@ -129,12 +129,12 @@ TEST_F(MouseCursorEventFilterTest, SetMouseWarpModeFlag) { event_filter()->set_mouse_warp_enabled(false); EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(499, 11))); EXPECT_EQ("499,11", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); event_filter()->set_mouse_warp_enabled(true); EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 11))); EXPECT_EQ("501,11", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); } // Verifies cursor's device scale factor is updated when a cursor has moved diff --git a/ash/display/root_window_transformers_unittest.cc b/ash/display/root_window_transformers_unittest.cc index 0b6ed8e2348f97..143e9fc6bb12e0 100644 --- a/ash/display/root_window_transformers_unittest.cc +++ b/ash/display/root_window_transformers_unittest.cc @@ -188,7 +188,7 @@ TEST_F(RootWindowTransformersTest, RotateAndMagnify) { generator1.MoveMouseToInHost(40, 80); EXPECT_EQ("50,90", event_handler.GetLocationAndReset()); EXPECT_EQ("50,90", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); EXPECT_EQ(display::Display::ROTATE_0, GetActiveDisplayRotation(display1.id())); EXPECT_EQ(display::Display::ROTATE_0, GetActiveDisplayRotation(display2_id)); @@ -209,7 +209,7 @@ TEST_F(RootWindowTransformersTest, RotateAndMagnify) { generator1.MoveMouseToInHost(39, 120); EXPECT_EQ("110,70", event_handler.GetLocationAndReset()); EXPECT_EQ("110,70", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); EXPECT_EQ(display::Display::ROTATE_90, GetActiveDisplayRotation(display1.id())); EXPECT_EQ(display::Display::ROTATE_0, GetActiveDisplayRotation(display2_id)); @@ -235,7 +235,7 @@ TEST_F(RootWindowTransformersTest, RotateAndMagnify) { generator2.MoveMouseToInHost(172, 219); EXPECT_EQ("95,80", event_handler.GetLocationAndReset()); EXPECT_EQ("145,200", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); EXPECT_EQ(display::Display::ROTATE_90, GetActiveDisplayRotation(display1.id())); EXPECT_EQ(display::Display::ROTATE_270, diff --git a/ash/display/screen_ash.cc b/ash/display/screen_ash.cc index 1dce2510ab2588..0637ebf88f7546 100644 --- a/ash/display/screen_ash.cc +++ b/ash/display/screen_ash.cc @@ -15,8 +15,10 @@ #include "base/logging.h" #include "ui/aura/client/screen_position_client.h" #include "ui/aura/env.h" +#include "ui/aura/mus/window_tree_host_mus.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" +#include "ui/base/ui_base_features.h" #include "ui/display/display.h" #include "ui/display/display_finder.h" #include "ui/display/manager/display_manager.h" @@ -89,7 +91,7 @@ ScreenAsh::ScreenAsh() = default; ScreenAsh::~ScreenAsh() = default; gfx::Point ScreenAsh::GetCursorScreenPoint() { - return aura::Env::GetInstance()->last_mouse_location(); + return Shell::Get()->aura_env()->last_mouse_location(); } bool ScreenAsh::IsWindowUnderCursor(gfx::NativeWindow window) { @@ -121,6 +123,17 @@ display::Display ScreenAsh::GetDisplayNearestWindow( gfx::NativeView window) const { if (!window) return GetPrimaryDisplay(); + + if (::features::IsSingleProcessMash()) { + // In IsSingleProcessMash() ScreenAsh is also called from non-ash code. + // Non-ash code creates aura Windows that are not parented to Ash's root + // Windows. Check for this first. + aura::WindowTreeHostMus* window_tree_host_mus = + aura::WindowTreeHostMus::ForWindow(window); + if (window_tree_host_mus) + return window_tree_host_mus->GetDisplay(); + } + const aura::Window* root_window = window->GetRootWindow(); if (!root_window) return GetPrimaryDisplay(); diff --git a/ash/display/screen_position_controller_unittest.cc b/ash/display/screen_position_controller_unittest.cc index 5597fc4deb14e7..5456f48eb00091 100644 --- a/ash/display/screen_position_controller_unittest.cc +++ b/ash/display/screen_position_controller_unittest.cc @@ -11,6 +11,7 @@ #include "ash/shell.h" #include "ash/shell_test_api.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "base/test/scoped_feature_list.h" #include "ui/aura/env.h" #include "ui/aura/test/test_window_delegate.h" @@ -39,7 +40,7 @@ class ScreenPositionControllerTest : public AshTestBase { void SetUp() override { AshTestBase::SetUp(); - window_.reset(new aura::Window(&window_delegate_)); + window_ = window_factory::NewWindow(&window_delegate_); window_->SetType(aura::client::WINDOW_TYPE_NORMAL); window_->Init(ui::LAYER_NOT_DRAWN); ParentWindowInPrimaryRootWindow(window_.get()); @@ -320,10 +321,10 @@ namespace { class ConvertToScreenEventHandler : public ui::EventHandler { public: ConvertToScreenEventHandler() : could_convert_to_screen_(true) { - aura::Env::GetInstance()->AddPreTargetHandler(this); + Shell::Get()->aura_env()->AddPreTargetHandler(this); } ~ConvertToScreenEventHandler() override { - aura::Env::GetInstance()->RemovePreTargetHandler(this); + Shell::Get()->aura_env()->RemovePreTargetHandler(this); } bool could_convert_to_screen() const { return could_convert_to_screen_; } @@ -365,7 +366,7 @@ TEST_F(ScreenPositionControllerTest, // ScreenPositionClient has been detached from the root window. GetEventGenerator()->MoveMouseTo(800, 200); EXPECT_TRUE(window_->GetBoundsInScreen().Contains( - aura::Env::GetInstance()->last_mouse_location())); + Shell::Get()->aura_env()->last_mouse_location())); aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); aura::WindowTracker tracker; diff --git a/ash/display/unified_mouse_warp_controller_unittest.cc b/ash/display/unified_mouse_warp_controller_unittest.cc index 36efbfef3a9ea6..7280e46bac3643 100644 --- a/ash/display/unified_mouse_warp_controller_unittest.cc +++ b/ash/display/unified_mouse_warp_controller_unittest.cc @@ -86,7 +86,7 @@ class UnifiedMouseWarpControllerTest : public AshTestBase { aura::Window* root = Shell::GetPrimaryRootWindow(); gfx::Point new_location_in_unified_host = - aura::Env::GetInstance()->last_mouse_location(); + Shell::Get()->aura_env()->last_mouse_location(); // Convert screen to the host. root->GetHost()->ConvertDIPToPixels(&new_location_in_unified_host); @@ -148,7 +148,7 @@ class UnifiedMouseWarpControllerTest : public AshTestBase { for (const auto& group : warp_groups) { EXPECT_TRUE(TestIfMouseWarpsAt(group.native_point_at_edge)); - gfx::Point new_location = aura::Env::GetInstance()->last_mouse_location(); + gfx::Point new_location = Shell::Get()->aura_env()->last_mouse_location(); EXPECT_EQ(group.expected_point_after_warp, new_location); // Convert screen to the host. @@ -399,12 +399,12 @@ TEST_F(UnifiedMouseWarpControllerTest, WarpMouse) { // Touch the right edge of the first display. Pointer should warp. EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 10))); EXPECT_EQ("501,10", // by 2px. - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); // Touch the left edge of the second display. Pointer should warp. EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(600, 10))); EXPECT_EQ("498,10", // by 2px. - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); { SCOPED_TRACE("1x1 NO WARP"); NoWarpTestBody(); @@ -418,12 +418,12 @@ TEST_F(UnifiedMouseWarpControllerTest, WarpMouse) { // Touch the right edge of the first display. Pointer should warp. EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 10))); EXPECT_EQ("250,5", // moved to 501 by 2px, divided by 2 (dsf). - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); // Touch the left edge of the second display. Pointer should warp. EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(600, 10))); EXPECT_EQ("249,5", // moved to 498 by 2px, divided by 2 (dsf). - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); { SCOPED_TRACE("2x1 NO WARP"); @@ -438,12 +438,12 @@ TEST_F(UnifiedMouseWarpControllerTest, WarpMouse) { // Touch the right edge of the first display. Pointer should warp. EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 10))); EXPECT_EQ("501,10", // by 2px. - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); // Touch the left edge of the second display. Pointer should warp. EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(600, 10))); EXPECT_EQ("498,10", // by 2px. - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); { SCOPED_TRACE("1x2 NO WARP"); NoWarpTestBody(); @@ -457,12 +457,12 @@ TEST_F(UnifiedMouseWarpControllerTest, WarpMouse) { // Touch the right edge of the first display. Pointer should warp. EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 10))); EXPECT_EQ("250,5", // by 2px. - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); // Touch the left edge of the second display. Pointer should warp. EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(600, 10))); EXPECT_EQ("249,5", // moved to 498 by 2px, divided by 2 (dsf). - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); { SCOPED_TRACE("1x2 NO WARP"); NoWarpTestBody(); diff --git a/ash/display/window_tree_host_manager_unittest.cc b/ash/display/window_tree_host_manager_unittest.cc index f3af31475c16de..ab364c797446d8 100644 --- a/ash/display/window_tree_host_manager_unittest.cc +++ b/ash/display/window_tree_host_manager_unittest.cc @@ -1657,7 +1657,7 @@ TEST_F(WindowTreeHostManagerTest, UpdateMouseLocationAfterDisplayChange) { UpdateDisplay("200x200,300x300"); aura::Window::Windows root_windows = Shell::GetAllRootWindows(); - aura::Env* env = aura::Env::GetInstance(); + aura::Env* env = Shell::Get()->aura_env(); ui::test::EventGenerator generator(root_windows[0]); @@ -1698,7 +1698,7 @@ TEST_F(WindowTreeHostManagerTest, UpdateDisplay("500x300"); aura::Window::Windows root_windows = Shell::GetAllRootWindows(); - aura::Env* env = aura::Env::GetInstance(); + aura::Env* env = Shell::Get()->aura_env(); ui::test::EventGenerator generator(root_windows[0]); @@ -1733,7 +1733,7 @@ TEST_F(WindowTreeHostManagerTest, EXPECT_EQ("-300,0 300x300", display_manager()->GetSecondaryDisplay().bounds().ToString()); - aura::Env* env = aura::Env::GetInstance(); + aura::Env* env = Shell::Get()->aura_env(); // Set the initial position. root_windows[0]->MoveCursorTo(gfx::Point(-150, 250)); @@ -1760,7 +1760,7 @@ TEST_F(WindowTreeHostManagerTest, UpdateMouseLocationAfterDisplayChange_SwapPrimary) { UpdateDisplay("200x200,200x200*2/r"); - aura::Env* env = aura::Env::GetInstance(); + aura::Env* env = Shell::Get()->aura_env(); Shell* shell = Shell::Get(); WindowTreeHostManager* window_tree_host_manager = shell->window_tree_host_manager(); @@ -1784,7 +1784,7 @@ TEST_F(WindowTreeHostManagerTest, // and rotation are updated when the primary display is disconnected. TEST_F(WindowTreeHostManagerTest, UpdateMouseLocationAfterDisplayChange_PrimaryDisconnected) { - aura::Env* env = aura::Env::GetInstance(); + aura::Env* env = Shell::Get()->aura_env(); Shell* shell = Shell::Get(); WindowTreeHostManager* window_tree_host_manager = shell->window_tree_host_manager(); @@ -1815,7 +1815,7 @@ TEST_F(WindowTreeHostManagerTest, TEST_F(WindowTreeHostManagerTest, UpdateNonVisibleMouseLocationAfterDisplayChange_PrimaryDisconnected) { - aura::Env* env = aura::Env::GetInstance(); + aura::Env* env = Shell::Get()->aura_env(); Shell* shell = Shell::Get(); WindowTreeHostManager* window_tree_host_manager = shell->window_tree_host_manager(); diff --git a/ash/drag_drop/drag_drop_tracker.cc b/ash/drag_drop/drag_drop_tracker.cc index 63ba697e170540..687004d80299c0 100644 --- a/ash/drag_drop/drag_drop_tracker.cc +++ b/ash/drag_drop/drag_drop_tracker.cc @@ -6,6 +6,7 @@ #include "ash/public/cpp/shell_window_ids.h" #include "ash/shell.h" +#include "ash/window_factory.h" #include "ash/wm/root_window_finder.h" #include "ui/aura/client/window_parenting_client.h" #include "ui/aura/window.h" @@ -32,18 +33,20 @@ class CaptureWindowActivationDelegate : public ::wm::ActivationDelegate { }; // Creates a window for capturing drag events. -aura::Window* CreateCaptureWindow(aura::Window* context_root, - aura::WindowDelegate* delegate) { +std::unique_ptr CreateCaptureWindow( + aura::Window* context_root, + aura::WindowDelegate* delegate) { static CaptureWindowActivationDelegate* activation_delegate_instance = NULL; if (!activation_delegate_instance) activation_delegate_instance = new CaptureWindowActivationDelegate; - aura::Window* window = new aura::Window(delegate); + std::unique_ptr window = window_factory::NewWindow(delegate); // Set type of window as popup to prevent different window manager codes // trying to manage this window. window->SetType(aura::client::WINDOW_TYPE_POPUP); window->Init(ui::LAYER_NOT_DRAWN); - aura::client::ParentWindowWithContext(window, context_root, gfx::Rect()); - ::wm::SetActivationDelegate(window, activation_delegate_instance); + aura::client::ParentWindowWithContext(window.get(), context_root, + gfx::Rect()); + ::wm::SetActivationDelegate(window.get(), activation_delegate_instance); window->Show(); DCHECK(window->bounds().size().IsEmpty()); return window; diff --git a/ash/events/event_rewriter_controller.cc b/ash/events/event_rewriter_controller.cc index cb66bbc378519b..a5b87dc1021b2b 100644 --- a/ash/events/event_rewriter_controller.cc +++ b/ash/events/event_rewriter_controller.cc @@ -21,7 +21,7 @@ namespace ash { EventRewriterController::EventRewriterController() { // Add the controller as an observer for new root windows. - aura::Env::GetInstance()->AddObserver(this); + Shell::Get()->aura_env()->AddObserver(this); std::unique_ptr keyboard_driven_event_rewriter = std::make_unique(); @@ -35,7 +35,7 @@ EventRewriterController::EventRewriterController() { } EventRewriterController::~EventRewriterController() { - aura::Env::GetInstance()->RemoveObserver(this); + Shell::Get()->aura_env()->RemoveObserver(this); // Remove the rewriters from every root window EventSource and destroy them. for (const auto& rewriter : rewriters_) { for (auto* window : Shell::GetAllRootWindows()) diff --git a/ash/extended_desktop_unittest.cc b/ash/extended_desktop_unittest.cc index 0884b85f44720c..ae7431ce41c2c3 100644 --- a/ash/extended_desktop_unittest.cc +++ b/ash/extended_desktop_unittest.cc @@ -11,6 +11,7 @@ #include "ash/system/tray/system_tray.h" #include "ash/system/unified/unified_system_tray.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "ash/wm/root_window_finder.h" #include "ash/wm/window_properties.h" #include "ash/wm/window_util.h" @@ -346,7 +347,7 @@ TEST_F(ExtendedDesktopTest, GetRootWindowMatching) { TEST_F(ExtendedDesktopTest, Capture) { // This test deals with input events but not visuals so don't throttle input // on visuals. - aura::Env::GetInstance()->set_throttle_input_on_resize_for_testing(false); + Shell::Get()->aura_env()->set_throttle_input_on_resize_for_testing(false); UpdateDisplay("1000x600,600x400"); aura::Window::Windows root_windows = Shell::GetAllRootWindows(); @@ -653,7 +654,7 @@ TEST_F(ExtendedDesktopTest, PostMoveParentTransientChild) { wm::ActivateWindow(window); // Create a transient child window of |window| without parenting to |window| // yet. - std::unique_ptr child(new aura::Window(nullptr)); + std::unique_ptr child = window_factory::NewWindow(); child->SetType(aura::client::WINDOW_TYPE_NORMAL); child->Init(ui::LAYER_TEXTURED); child->SetBounds(gfx::Rect(50, 50, 50, 50)); @@ -868,7 +869,7 @@ TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) { TEST_F(ExtendedDesktopTest, PassiveGrab) { // This test deals with input events but not visuals so don't throttle input // on visuals. - aura::Env::GetInstance()->set_throttle_input_on_resize_for_testing(false); + Shell::Get()->aura_env()->set_throttle_input_on_resize_for_testing(false); EventLocationRecordingEventHandler event_handler; ash::Shell::Get()->AddPreTargetHandler(&event_handler); diff --git a/ash/frame/detached_title_area_renderer.cc b/ash/frame/detached_title_area_renderer.cc index 0d8fea5b96fcf4..d651037ae429d1 100644 --- a/ash/frame/detached_title_area_renderer.cc +++ b/ash/frame/detached_title_area_renderer.cc @@ -8,6 +8,7 @@ #include "ash/frame/caption_buttons/caption_button_model.h" #include "ash/frame/header_view.h" +#include "ash/shell.h" #include "ash/wm/property_util.h" #include "ash/wm/window_state.h" #include "services/ui/public/interfaces/window_tree_constants.mojom.h" @@ -102,7 +103,7 @@ DetachedTitleAreaRendererForClient::DetachedTitleAreaRendererForClient( std::unique_ptr params = CreateInitParams("DetachedTitleAreaRendererForClient"); views::NativeWidgetAura* native_widget = - new views::NativeWidgetAura(widget_, true); + new views::NativeWidgetAura(widget_, true, Shell::Get()->aura_env()); aura::SetWindowType(native_widget->GetNativeWindow(), ui::mojom::WindowType::POPUP); ApplyProperties(native_widget->GetNativeWindow(), property_converter, diff --git a/ash/frame/header_view.cc b/ash/frame/header_view.cc index 21a5c0a11f1689..4cff58130e2745 100644 --- a/ash/frame/header_view.cc +++ b/ash/frame/header_view.cc @@ -132,7 +132,8 @@ HeaderView::HeaderView(views::Widget* target_widget, target_widget, this, caption_button_container_); } else { DCHECK_EQ(mojom::WindowStyle::BROWSER, window_style); - DCHECK(!::features::IsAshInBrowserProcess()); + DCHECK(!::features::IsAshInBrowserProcess() || + ::features::IsSingleProcessMash()); appearance_provider_ = std::make_unique( target_widget_->GetNativeWindow()); auto frame_header = std::make_unique( diff --git a/ash/host/DEPS b/ash/host/DEPS index 7ffc8e2a3ef995..a11daf244df843 100644 --- a/ash/host/DEPS +++ b/ash/host/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+ash/ime", "+ash/ash_export.h", "+ash/public/cpp/ash_switches.h", + "+ash/window_factory.h", ] specific_include_rules = { diff --git a/ash/host/ash_window_tree_host.cc b/ash/host/ash_window_tree_host.cc index 916b5995a5ac9f..30d5b3f753b038 100644 --- a/ash/host/ash_window_tree_host.cc +++ b/ash/host/ash_window_tree_host.cc @@ -38,11 +38,6 @@ AshWindowTreeHost::AshWindowTreeHost() AshWindowTreeHost::~AshWindowTreeHost() = default; void AshWindowTreeHost::TranslateLocatedEvent(ui::LocatedEvent* event) { - // NOTE: This code is not called in mus/mash, it is handled on the server - // side. - // TODO(sky): remove this when mus is the default http://crbug.com/763996. - DCHECK_EQ(aura::Env::Mode::LOCAL, aura::Env::GetInstance()->mode()); - if (event->IsTouchEvent()) return; diff --git a/ash/host/ash_window_tree_host_platform.cc b/ash/host/ash_window_tree_host_platform.cc index 511987a7adb499..2a4ceb284996d2 100644 --- a/ash/host/ash_window_tree_host_platform.cc +++ b/ash/host/ash_window_tree_host_platform.cc @@ -10,6 +10,7 @@ #include "ash/host/transformer_helper.h" #include "ash/shell.h" #include "ash/shell_delegate.h" +#include "ash/window_factory.h" #include "base/feature_list.h" #include "base/trace_event/trace_event.h" #include "services/ui/public/cpp/input_devices/input_device_controller_client.h" @@ -35,14 +36,16 @@ namespace ash { AshWindowTreeHostPlatform::AshWindowTreeHostPlatform( ui::PlatformWindowInitProperties properties) - : aura::WindowTreeHostPlatform(std::move(properties)), + : aura::WindowTreeHostPlatform(std::move(properties), + window_factory::NewWindow()), transformer_helper_(this) { transformer_helper_.Init(); InitInputMethodIfNecessary(); } AshWindowTreeHostPlatform::AshWindowTreeHostPlatform() - : transformer_helper_(this) { + : aura::WindowTreeHostPlatform(window_factory::NewWindow()), + transformer_helper_(this) { CreateCompositor(); transformer_helper_.Init(); InitInputMethodIfNecessary(); diff --git a/ash/keyboard/arc/arc_input_method_surface_manager_unittest.cc b/ash/keyboard/arc/arc_input_method_surface_manager_unittest.cc index 6b05fef8814c6b..5c925ab6035311 100644 --- a/ash/keyboard/arc/arc_input_method_surface_manager_unittest.cc +++ b/ash/keyboard/arc/arc_input_method_surface_manager_unittest.cc @@ -4,6 +4,7 @@ #include "ash/keyboard/arc/arc_input_method_surface_manager.h" +#include "ash/shell.h" #include "ash/test/ash_test_base.h" #include "base/macros.h" #include "components/exo/input_method_surface.h" @@ -20,7 +21,7 @@ class ArcInputMethodSurfaceManagerTest : public AshTestBase { void SetUp() override { AshTestBase::SetUp(); - wm_helper_ = std::make_unique(aura::Env::GetInstance()); + wm_helper_ = std::make_unique(Shell::Get()->aura_env()); exo::WMHelper::SetInstance(wm_helper_.get()); } diff --git a/ash/keyboard/test_keyboard_ui.cc b/ash/keyboard/test_keyboard_ui.cc index a665ef29aedd15..6437f077ca42e3 100644 --- a/ash/keyboard/test_keyboard_ui.cc +++ b/ash/keyboard/test_keyboard_ui.cc @@ -5,6 +5,7 @@ #include "ash/keyboard/test_keyboard_ui.h" #include "ash/shell.h" +#include "ash/window_factory.h" #include "ash/wm/window_util.h" #include "ui/aura/window.h" #include "ui/aura/window_tree_host.h" @@ -21,7 +22,7 @@ bool TestKeyboardUI::HasKeyboardWindow() const { aura::Window* TestKeyboardUI::GetKeyboardWindow() { if (!keyboard_window_) { - keyboard_window_.reset(new aura::Window(&delegate_)); + keyboard_window_ = window_factory::NewWindow(&delegate_); keyboard_window_->Init(ui::LAYER_NOT_DRAWN); } return keyboard_window_.get(); diff --git a/ash/magnifier/docked_magnifier_controller.cc b/ash/magnifier/docked_magnifier_controller.cc index 8ec30a518e7d29..79158e30af8078 100644 --- a/ash/magnifier/docked_magnifier_controller.cc +++ b/ash/magnifier/docked_magnifier_controller.cc @@ -453,7 +453,7 @@ void DockedMagnifierController::SwitchCurrentSourceRootWindowIfNeeded( // reflector and the viewport widget and its layers. New viewport and // reflector may be recreated later if |new_root_window| is not |nullptr|. if (reflector_) { - aura::Env::GetInstance()->context_factory_private()->RemoveReflector( + Shell::Get()->aura_env()->context_factory_private()->RemoveReflector( reflector_.get()); reflector_.reset(); } @@ -481,10 +481,10 @@ void DockedMagnifierController::SwitchCurrentSourceRootWindowIfNeeded( if (new_input_method) new_input_method->AddObserver(this); - DCHECK(aura::Env::GetInstance()->context_factory_private()); + DCHECK(Shell::Get()->aura_env()->context_factory_private()); DCHECK(viewport_widget_); reflector_ = - aura::Env::GetInstance()->context_factory_private()->CreateReflector( + Shell::Get()->aura_env()->context_factory_private()->CreateReflector( current_source_root_window_->layer()->GetCompositor(), viewport_magnifier_layer_.get()); } diff --git a/ash/magnifier/magnification_controller_unittest.cc b/ash/magnifier/magnification_controller_unittest.cc index 53543e9258a79c..e539683d76586e 100644 --- a/ash/magnifier/magnification_controller_unittest.cc +++ b/ash/magnifier/magnification_controller_unittest.cc @@ -277,7 +277,7 @@ TEST_F(MagnificationControllerTest, FollowFocusChanged) { } TEST_F(MagnificationControllerTest, PanWindow2xLeftToRight) { - const aura::Env* env = aura::Env::GetInstance(); + const aura::Env* env = Shell::Get()->aura_env(); ui::test::EventGenerator* event_generator = GetEventGenerator(); event_generator->MoveMouseToInHost(gfx::Point(0, 0)); @@ -381,7 +381,7 @@ TEST_F(MagnificationControllerTest, PanWindow2xLeftToRight) { } TEST_F(MagnificationControllerTest, PanWindow2xRightToLeft) { - const aura::Env* env = aura::Env::GetInstance(); + const aura::Env* env = Shell::Get()->aura_env(); ui::test::EventGenerator* event_generator = GetEventGenerator(); event_generator->MoveMouseToInHost(gfx::Point(799, 300)); @@ -434,7 +434,7 @@ TEST_F(MagnificationControllerTest, PanWindow2xRightToLeft) { } TEST_F(MagnificationControllerTest, PanWindowToRight) { - const aura::Env* env = aura::Env::GetInstance(); + const aura::Env* env = Shell::Get()->aura_env(); ui::test::EventGenerator* event_generator = GetEventGenerator(); event_generator->MoveMouseToInHost(gfx::Point(400, 300)); @@ -480,7 +480,7 @@ TEST_F(MagnificationControllerTest, PanWindowToRight) { } TEST_F(MagnificationControllerTest, PanWindowToLeft) { - const aura::Env* env = aura::Env::GetInstance(); + const aura::Env* env = Shell::Get()->aura_env(); ui::test::EventGenerator* event_generator = GetEventGenerator(); event_generator->MoveMouseToInHost(gfx::Point(400, 300)); diff --git a/ash/metrics/desktop_task_switch_metric_recorder_unittest.cc b/ash/metrics/desktop_task_switch_metric_recorder_unittest.cc index 19e8d8240bb32d..ff18c9ce729739 100644 --- a/ash/metrics/desktop_task_switch_metric_recorder_unittest.cc +++ b/ash/metrics/desktop_task_switch_metric_recorder_unittest.cc @@ -8,6 +8,7 @@ #include "ash/shell.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "base/test/metrics/user_action_tester.h" #include "ui/aura/client/window_types.h" #include "ui/aura/test/test_window_delegate.h" @@ -101,8 +102,8 @@ int DesktopTaskSwitchMetricRecorderTest::GetActionCount() const { std::unique_ptr DesktopTaskSwitchMetricRecorderTest::CreatePositionableWindow() const { - std::unique_ptr window(new aura::Window( - aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate())); + std::unique_ptr window = window_factory::NewWindow( + aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate()); window->SetType(aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_NOT_DRAWN); return window; @@ -110,8 +111,8 @@ DesktopTaskSwitchMetricRecorderTest::CreatePositionableWindow() const { std::unique_ptr DesktopTaskSwitchMetricRecorderTest::CreateNonPositionableWindow() const { - std::unique_ptr window(new aura::Window( - aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate())); + std::unique_ptr window = window_factory::NewWindow( + aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate()); window->SetType(aura::client::WINDOW_TYPE_UNKNOWN); window->Init(ui::LAYER_NOT_DRAWN); return window; diff --git a/ash/public/cpp/frame_border_hit_test.cc b/ash/public/cpp/frame_border_hit_test.cc index 151d67591f764d..d78b58dd1b2ad8 100644 --- a/ash/public/cpp/frame_border_hit_test.cc +++ b/ash/public/cpp/frame_border_hit_test.cc @@ -6,6 +6,7 @@ #include "ash/public/cpp/ash_constants.h" #include "ui/aura/env.h" +#include "ui/aura/window.h" #include "ui/base/hit_test.h" #include "ui/views/view_properties.h" #include "ui/views/widget/widget.h" @@ -19,7 +20,7 @@ int FrameBorderNonClientHitTest(views::NonClientFrameView* view, gfx::Rect expanded_bounds = view->bounds(); int outside_bounds = kResizeOutsideBoundsSize; - if (aura::Env::GetInstance()->is_touch_down()) + if (view->GetWidget()->GetNativeWindow()->env()->is_touch_down()) outside_bounds *= kResizeOutsideBoundsScaleForTouch; expanded_bounds.Inset(-outside_bounds, -outside_bounds); diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc index 629f173d9f080e..a361842c3794c2 100644 --- a/ash/root_window_controller.cc +++ b/ash/root_window_controller.cc @@ -43,6 +43,7 @@ #include "ash/touch/touch_hud_debug.h" #include "ash/touch/touch_observer_hud.h" #include "ash/wallpaper/wallpaper_widget_controller.h" +#include "ash/window_factory.h" #include "ash/wm/always_on_top_controller.h" #include "ash/wm/container_finder.h" #include "ash/wm/fullscreen_window_finder.h" @@ -246,7 +247,8 @@ aura::Window* CreateContainer(int window_id, const char* name, aura::Window* parent) { aura::Window* window = - new aura::Window(nullptr, aura::client::WINDOW_TYPE_UNKNOWN); + window_factory::NewWindow(nullptr, aura::client::WINDOW_TYPE_UNKNOWN) + .release(); window->Init(ui::LAYER_NOT_DRAWN); window->set_id(window_id); window->SetName(name); diff --git a/ash/root_window_controller_unittest.cc b/ash/root_window_controller_unittest.cc index 3b110e2396a8fd..1e97ff1a181493 100644 --- a/ash/root_window_controller_unittest.cc +++ b/ash/root_window_controller_unittest.cc @@ -11,6 +11,7 @@ #include "ash/session/test_session_controller_client.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "ash/wm/system_modal_container_layout_manager.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/window_properties.h" @@ -29,6 +30,7 @@ #include "ui/base/ime/dummy_text_input_client.h" #include "ui/base/ime/input_method.h" #include "ui/base/ime/text_input_client.h" +#include "ui/base/ui_base_features.h" #include "ui/display/manager/display_manager.h" #include "ui/display/test/display_manager_test_api.h" #include "ui/events/test/event_generator.h" @@ -621,28 +623,28 @@ class DestroyedWindowObserver : public aura::WindowObserver { TEST_F(RootWindowControllerTest, DontDeleteWindowsNotOwnedByParent) { DestroyedWindowObserver observer1; aura::test::TestWindowDelegate delegate1; - aura::Window* window1 = new aura::Window(&delegate1); - window1->SetType(aura::client::WINDOW_TYPE_CONTROL); + std::unique_ptr window1 = + window_factory::NewWindow(&delegate1, aura::client::WINDOW_TYPE_CONTROL); window1->set_owned_by_parent(false); - observer1.SetWindow(window1); + observer1.SetWindow(window1.get()); window1->Init(ui::LAYER_NOT_DRAWN); - aura::client::ParentWindowWithContext(window1, Shell::GetPrimaryRootWindow(), - gfx::Rect()); + aura::client::ParentWindowWithContext( + window1.get(), Shell::GetPrimaryRootWindow(), gfx::Rect()); DestroyedWindowObserver observer2; - aura::Window* window2 = new aura::Window(NULL); + std::unique_ptr window2 = window_factory::NewWindow(); window2->set_owned_by_parent(false); - observer2.SetWindow(window2); + observer2.SetWindow(window2.get()); window2->Init(ui::LAYER_NOT_DRAWN); - Shell::GetPrimaryRootWindow()->AddChild(window2); + Shell::GetPrimaryRootWindow()->AddChild(window2.get()); Shell::GetPrimaryRootWindowController()->CloseChildWindows(); ASSERT_FALSE(observer1.destroyed()); - delete window1; + window1.reset(); ASSERT_FALSE(observer2.destroyed()); - delete window2; + window2.reset(); } // Verify that the context menu gets hidden when entering or exiting tablet diff --git a/ash/shelf/shelf_layout_manager_unittest.cc b/ash/shelf/shelf_layout_manager_unittest.cc index 8bc70666dd1fed..b53ca5ca1d391f 100644 --- a/ash/shelf/shelf_layout_manager_unittest.cc +++ b/ash/shelf/shelf_layout_manager_unittest.cc @@ -34,6 +34,7 @@ #include "ash/system/unified/unified_system_tray.h" #include "ash/test/ash_test_base.h" #include "ash/wallpaper/wallpaper_controller.h" +#include "ash/window_factory.h" #include "ash/wm/lock_state_controller.h" #include "ash/wm/splitview/split_view_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h" @@ -269,7 +270,7 @@ class ShelfLayoutManagerTest : public AshTestBase { } aura::Window* CreateTestWindow() { - aura::Window* window = new aura::Window(nullptr); + aura::Window* window = window_factory::NewWindow().release(); window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); window->SetType(aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); @@ -278,7 +279,7 @@ class ShelfLayoutManagerTest : public AshTestBase { } aura::Window* CreateTestWindowInParent(aura::Window* root_window) { - aura::Window* window = new aura::Window(nullptr); + aura::Window* window = window_factory::NewWindow().release(); window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); window->SetType(aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); diff --git a/ash/shelf/shelf_window_watcher_unittest.cc b/ash/shelf/shelf_window_watcher_unittest.cc index 5ce1267979738a..2356b65b60fe34 100644 --- a/ash/shelf/shelf_window_watcher_unittest.cc +++ b/ash/shelf/shelf_window_watcher_unittest.cc @@ -15,6 +15,7 @@ #include "ash/session/session_controller.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "ash/wm/window_resizer.h" #include "ash/wm/window_state.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -116,7 +117,7 @@ TEST_F(ShelfWindowWatcherTest, OpenAndCloseMash) { aura::client::WINDOW_TYPE_TOOLTIP}; for (aura::client::WindowType type : no_item_types) { std::unique_ptr window = - std::make_unique(nullptr, type); + window_factory::NewWindow(nullptr, type); window->Init(ui::LAYER_NOT_DRAWN); Shell::GetPrimaryRootWindow() ->GetChildById(kShellWindowId_DefaultContainer) @@ -305,7 +306,7 @@ TEST_F(ShelfWindowWatcherTest, ItemIcon) { TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) { std::unique_ptr window = - std::make_unique(nullptr, aura::client::WINDOW_TYPE_NORMAL); + window_factory::NewWindow(nullptr, aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_NOT_DRAWN); window->SetProperty(kShelfIDKey, new std::string(ShelfID("a").Serialize())); window->SetProperty(kShelfItemTypeKey, static_cast(TYPE_DIALOG)); @@ -316,7 +317,7 @@ TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) { EXPECT_EQ(3, model_->item_count()); std::unique_ptr child = - std::make_unique(nullptr, aura::client::WINDOW_TYPE_NORMAL); + window_factory::NewWindow(nullptr, aura::client::WINDOW_TYPE_NORMAL); child->Init(ui::LAYER_NOT_DRAWN); child->SetProperty(kShelfIDKey, new std::string(ShelfID("b").Serialize())); child->SetProperty(kShelfItemTypeKey, static_cast(TYPE_DIALOG)); @@ -333,7 +334,7 @@ TEST_F(ShelfWindowWatcherTest, DontCreateShelfEntriesForChildWindows) { TEST_F(ShelfWindowWatcherTest, CreateShelfEntriesForTransientWindows) { std::unique_ptr window = - std::make_unique(nullptr, aura::client::WINDOW_TYPE_NORMAL); + window_factory::NewWindow(nullptr, aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_NOT_DRAWN); window->SetProperty(kShelfIDKey, new std::string(ShelfID("a").Serialize())); window->SetProperty(kShelfItemTypeKey, static_cast(TYPE_DIALOG)); @@ -344,7 +345,7 @@ TEST_F(ShelfWindowWatcherTest, CreateShelfEntriesForTransientWindows) { EXPECT_EQ(3, model_->item_count()); std::unique_ptr transient = - std::make_unique(nullptr, aura::client::WINDOW_TYPE_NORMAL); + window_factory::NewWindow(nullptr, aura::client::WINDOW_TYPE_NORMAL); transient->Init(ui::LAYER_NOT_DRAWN); transient->SetProperty(kShelfIDKey, new std::string(ShelfID("b").Serialize())); diff --git a/ash/shell.cc b/ash/shell.cc index 7f2fadfaa2fc4f..e7e2e917b57880 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -136,6 +136,7 @@ #include "ash/wm/lock_state_controller.h" #include "ash/wm/mru_window_tracker.h" #include "ash/wm/native_cursor_manager_ash_classic.h" +#include "ash/wm/non_client_frame_controller.h" #include "ash/wm/overlay_event_filter.h" #include "ash/wm/overview/window_selector_controller.h" #include "ash/wm/resize_shadow_controller.h" @@ -208,6 +209,7 @@ #include "ui/views/corewm/tooltip_aura.h" #include "ui/views/corewm/tooltip_controller.h" #include "ui/views/focus/focus_manager_factory.h" +#include "ui/views/mus/window_manager_frame_values.h" #include "ui/views/widget/native_widget_aura.h" #include "ui/views/widget/widget.h" #include "ui/wm/core/accelerator_filter.h" @@ -431,8 +433,8 @@ void Shell::RegisterUserProfilePrefs(PrefRegistrySimple* registry, } void Shell::InitWaylandServer(std::unique_ptr file_helper) { - wayland_server_controller_ = - WaylandServerController::CreateIfNecessary(std::move(file_helper)); + wayland_server_controller_ = WaylandServerController::CreateIfNecessary( + std::move(file_helper), aura_env_); } void Shell::DestroyWaylandServer() { @@ -688,7 +690,12 @@ void Shell::NotifyAppListVisibilityChanged(bool visible, Shell::Shell(std::unique_ptr shell_delegate, service_manager::Connector* connector) - : ash_display_controller_(std::make_unique()), + : owned_aura_env_(::features::IsSingleProcessMash() + ? aura::Env::CreateLocalInstanceForInProcess() + : nullptr), + aura_env_(owned_aura_env_.get() ? owned_aura_env_.get() + : aura::Env::GetInstance()), + ash_display_controller_(std::make_unique()), brightness_control_delegate_( std::make_unique()), cast_config_(std::make_unique()), @@ -966,6 +973,17 @@ void Shell::Init( ui::ContextFactoryPrivate* context_factory_private, std::unique_ptr initial_display_prefs, std::unique_ptr gpu_interface_provider) { + if (::features::IsSingleProcessMash()) { + // In SingleProcessMash mode ScreenMus is not created, which means Ash needs + // to set the WindowManagerFrameValues. + views::WindowManagerFrameValues frame_values; + frame_values.normal_insets = frame_values.maximized_insets = + NonClientFrameController::GetPreferredClientAreaInsets(); + frame_values.max_title_bar_button_width = + NonClientFrameController::GetMaxTitleBarButtonWidth(); + views::WindowManagerFrameValues::SetInstance(frame_values); + } + // This creates the MessageCenter object which is used by some other objects // initialized here, so it needs to come early. message_center_controller_ = std::make_unique(); @@ -1042,11 +1060,9 @@ void Shell::Init( // This will initialize aura::Env which requires |display_manager_| to // be initialized first. if (context_factory) - aura::Env::GetInstance()->set_context_factory(context_factory); - if (context_factory_private) { - aura::Env::GetInstance()->set_context_factory_private( - context_factory_private); - } + aura_env_->set_context_factory(context_factory); + if (context_factory_private) + aura_env_->set_context_factory_private(context_factory_private); // Night Light depends on the display manager, the display color manager, and // aura::Env, so initialize it after all have been initialized. @@ -1056,11 +1072,12 @@ void Shell::Init( // The WindowModalityController needs to be at the front of the input event // pretarget handler list to ensure that it processes input events when modal // windows are active. - window_modality_controller_.reset(new ::wm::WindowModalityController(this)); + window_modality_controller_ = + std::make_unique<::wm::WindowModalityController>(this, aura_env_); event_rewriter_controller_ = std::make_unique(); - env_filter_.reset(new ::wm::CompoundEventFilter); + env_filter_ = std::make_unique<::wm::CompoundEventFilter>(); AddPreTargetHandler(env_filter_.get()); // FocusController takes ownership of AshFocusRules. @@ -1140,7 +1157,7 @@ void Shell::Init( power_button_controller_->OnDisplayModeChanged( display_configurator_->cached_displays()); - if (!::features::IsAshInBrowserProcess()) + if (!::features::IsAshInBrowserProcess() || ::features::IsSingleProcessMash()) client_image_registry_ = std::make_unique(); drag_drop_controller_ = std::make_unique(); @@ -1185,8 +1202,7 @@ void Shell::Init( viz::mojom::VideoDetectorObserverPtr observer; video_detector_ = std::make_unique(mojo::MakeRequest(&observer)); - aura::Env::GetInstance() - ->context_factory_private() + aura_env_->context_factory_private() ->GetHostFrameSinkManager() ->AddVideoDetectorObserver(std::move(observer)); @@ -1204,8 +1220,9 @@ void Shell::Init( pointer_watcher_adapter_ = std::make_unique(); resize_shadow_controller_.reset(new ResizeShadowController()); - shadow_controller_.reset(new ::wm::ShadowController( - focus_controller_.get(), std::make_unique())); + shadow_controller_ = std::make_unique<::wm::ShadowController>( + focus_controller_.get(), std::make_unique(), + aura_env_); logout_confirmation_controller_ = std::make_unique(); @@ -1394,7 +1411,7 @@ bool Shell::CanAcceptEvent(const ui::Event& event) { } ui::EventTarget* Shell::GetParentTarget() { - return aura::Env::GetInstance(); + return aura_env_; } std::unique_ptr Shell::GetChildIterator() const { diff --git a/ash/shell.h b/ash/shell.h index 92316828fa7a7f..05cc777a1527b8 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -31,6 +31,7 @@ class PrefRegistrySimple; class PrefService; namespace aura { +class Env; class RootWindow; class Window; } // namespace aura @@ -397,6 +398,7 @@ class ASH_EXPORT Shell : public SessionObserver, } DockedMagnifierController* docked_magnifier_controller(); + aura::Env* aura_env() { return aura_env_; } ::wm::CompoundEventFilter* env_filter() { return env_filter_.get(); } EventRewriterController* event_rewriter_controller() { return event_rewriter_controller_.get(); @@ -709,6 +711,13 @@ class ASH_EXPORT Shell : public SessionObserver, static Shell* instance_; + // |owned_aura_env_| is non-null if Shell created aura::Env. Shell creates + // aura::Env only in single-process-mash mode. + std::unique_ptr owned_aura_env_; + + // This is either |owned_aura_env_|, or Env::GetInstance(). + aura::Env* aura_env_; + // The CompoundEventFilter owned by aura::Env object. std::unique_ptr<::wm::CompoundEventFilter> env_filter_; diff --git a/ash/shell_unittest.cc b/ash/shell_unittest.cc index 61fd9e7b5d1046..a6fd3b9632387d 100644 --- a/ash/shell_unittest.cc +++ b/ash/shell_unittest.cc @@ -24,6 +24,7 @@ #include "ash/test/ash_test_helper.h" #include "ash/test_shell_delegate.h" #include "ash/wallpaper/wallpaper_widget_controller.h" +#include "ash/window_factory.h" #include "ash/wm/window_util.h" #include "base/command_line.h" #include "base/macros.h" @@ -497,7 +498,7 @@ TEST_F(ShellTest, FullscreenWindowHidesShelf) { // Various assertions around auto-hide behavior. // TODO(jamescook): Move this to ShelfTest. TEST_F(ShellTest, ToggleAutoHide) { - std::unique_ptr window(new aura::Window(NULL)); + std::unique_ptr window = window_factory::NewWindow(); window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); window->SetType(aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); @@ -542,11 +543,11 @@ TEST_F(ShellTest, TestPreTargetHandlerOrder) { // Verifies an EventHandler added to Env gets notified from EventGenerator. TEST_F(ShellTest, EnvPreTargetHandler) { ui::test::TestEventHandler event_handler; - aura::Env::GetInstance()->AddPreTargetHandler(&event_handler); + Shell::Get()->aura_env()->AddPreTargetHandler(&event_handler); ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); generator.MoveMouseBy(1, 1); EXPECT_NE(0, event_handler.num_mouse_events()); - aura::Env::GetInstance()->RemovePreTargetHandler(&event_handler); + Shell::Get()->aura_env()->RemovePreTargetHandler(&event_handler); } // Verifies keyboard is re-enabled on proper timing. @@ -585,7 +586,12 @@ class ShellTest2 : public AshTestBase { }; TEST_F(ShellTest2, DontCrashWhenWindowDeleted) { - window_.reset(new aura::Window(NULL)); + // This test explicitly uses aura::Env::GetInstance() rather than + // Shell->aura_env() as the Window outlives the Shell. In order for a Window + // to outlive Shell the Window must be created outside of Ash, which uses + // aura::Env::GetInstance() as the Env. + window_ = std::make_unique( + nullptr, aura::client::WINDOW_TYPE_UNKNOWN, aura::Env::GetInstance()); window_->Init(ui::LAYER_NOT_DRAWN); } diff --git a/ash/system/message_center/arc/arc_notification_content_view_unittest.cc b/ash/system/message_center/arc/arc_notification_content_view_unittest.cc index fac937dbbb13d8..d0d171d67f6f49 100644 --- a/ash/system/message_center/arc/arc_notification_content_view_unittest.cc +++ b/ash/system/message_center/arc/arc_notification_content_view_unittest.cc @@ -117,7 +117,7 @@ class ArcNotificationContentViewTest : public AshTestBase { MessageCenterView::disable_animation_for_testing = true; - wm_helper_ = std::make_unique(aura::Env::GetInstance()); + wm_helper_ = std::make_unique(ash::Shell::Get()->aura_env()); exo::WMHelper::SetInstance(wm_helper_.get()); DCHECK(exo::WMHelper::HasInstance()); diff --git a/ash/system/message_center/arc/arc_notification_view_unittest.cc b/ash/system/message_center/arc/arc_notification_view_unittest.cc index ce0866d1dea975..dc56133cd8ac43 100644 --- a/ash/system/message_center/arc/arc_notification_view_unittest.cc +++ b/ash/system/message_center/arc/arc_notification_view_unittest.cc @@ -75,8 +75,8 @@ class ArcNotificationViewTest : public AshTestBase { notification_view_.reset(static_cast( message_center::MessageViewFactory::Create(*notification, true))); notification_view_->set_owned_by_client(); - surface_ = - std::make_unique(kDefaultNotificationKey); + surface_ = std::make_unique( + kDefaultNotificationKey, Shell::Get()->aura_env()); notification_view_->content_view_->SetSurface(surface_.get()); UpdateNotificationViews(*notification); diff --git a/ash/system/message_center/arc/mock_arc_notification_surface.cc b/ash/system/message_center/arc/mock_arc_notification_surface.cc index a482667a46a89c..25af5fbf451742 100644 --- a/ash/system/message_center/arc/mock_arc_notification_surface.cc +++ b/ash/system/message_center/arc/mock_arc_notification_surface.cc @@ -9,12 +9,18 @@ namespace ash { MockArcNotificationSurface::MockArcNotificationSurface( - const std::string& notification_key) + const std::string& notification_key, + aura::Env* aura_env) : notification_key_(notification_key), ax_tree_id_(-1), native_view_host_(nullptr), - window_(new aura::Window(nullptr)), - content_window_(new aura::Window(nullptr)) { + window_(std::make_unique(nullptr, + aura::client::WINDOW_TYPE_UNKNOWN, + aura_env)), + content_window_( + std::make_unique(nullptr, + aura::client::WINDOW_TYPE_UNKNOWN, + aura_env)) { window_->Init(ui::LAYER_NOT_DRAWN); content_window_->Init(ui::LAYER_NOT_DRAWN); } diff --git a/ash/system/message_center/arc/mock_arc_notification_surface.h b/ash/system/message_center/arc/mock_arc_notification_surface.h index 52d20b8c2b77c7..09cc2cdf516ce6 100644 --- a/ash/system/message_center/arc/mock_arc_notification_surface.h +++ b/ash/system/message_center/arc/mock_arc_notification_surface.h @@ -7,11 +7,16 @@ #include "ash/system/message_center/arc/arc_notification_surface.h" +namespace aura { +class Env; +} + namespace ash { class MockArcNotificationSurface : public ArcNotificationSurface { public: - explicit MockArcNotificationSurface(const std::string& notification_key); + explicit MockArcNotificationSurface(const std::string& notification_key, + aura::Env* aura_env = nullptr); ~MockArcNotificationSurface() override; gfx::Size GetSize() const override; diff --git a/ash/system/night_light/night_light_controller.cc b/ash/system/night_light/night_light_controller.cc index 6508903b040e6f..24c4f3c8787fa2 100644 --- a/ash/system/night_light/night_light_controller.cc +++ b/ash/system/night_light/night_light_controller.cc @@ -300,7 +300,7 @@ NightLightController::NightLightController() binding_(this) { Shell::Get()->session_controller()->AddObserver(this); Shell::Get()->window_tree_host_manager()->AddObserver(this); - aura::Env::GetInstance()->AddObserver(this); + Shell::Get()->aura_env()->AddObserver(this); chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver( this); } @@ -308,7 +308,7 @@ NightLightController::NightLightController() NightLightController::~NightLightController() { chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver( this); - aura::Env::GetInstance()->RemoveObserver(this); + Shell::Get()->aura_env()->RemoveObserver(this); Shell::Get()->window_tree_host_manager()->RemoveObserver(this); Shell::Get()->session_controller()->RemoveObserver(this); } diff --git a/ash/system/overview/overview_button_tray_unittest.cc b/ash/system/overview/overview_button_tray_unittest.cc index 686aae0e71ab40..5093ec0a4d931c 100644 --- a/ash/system/overview/overview_button_tray_unittest.cc +++ b/ash/system/overview/overview_button_tray_unittest.cc @@ -15,6 +15,7 @@ #include "ash/system/status_area_widget_test_helper.h" #include "ash/test/ash_test_base.h" #include "ash/test/ash_test_helper.h" +#include "ash/window_factory.h" #include "ash/wm/overview/window_selector_controller.h" #include "ash/wm/splitview/split_view_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h" @@ -301,7 +302,7 @@ TEST_F(OverviewButtonTrayTest, HideAnimationAlwaysCompletesOnDelete) { TEST_F(OverviewButtonTrayTest, VisibilityChangesForSystemModalWindow) { // TODO(jonross): When CreateTestWindow*() have been unified, use the // appropriate method to replace this setup. (crbug.com/483503) - std::unique_ptr window(new aura::Window(nullptr)); + std::unique_ptr window = window_factory::NewWindow(); window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); window->SetType(aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); diff --git a/ash/system/tray/tray_background_view.cc b/ash/system/tray/tray_background_view.cc index 33a93ec1754a6b..150e30773ee010 100644 --- a/ash/system/tray/tray_background_view.cc +++ b/ash/system/tray/tray_background_view.cc @@ -23,6 +23,7 @@ #include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_container.h" #include "ash/system/tray/tray_event_filter.h" +#include "ash/window_factory.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ui/accessibility/ax_node_data.h" #include "ui/compositor/layer.h" @@ -502,7 +503,7 @@ aura::Window* TrayBackgroundView::GetBubbleWindowContainer() { ->IsTabletModeWindowManagerEnabled() && drag_controller()) { if (!clipping_window_.get()) { - clipping_window_ = std::make_unique(nullptr); + clipping_window_ = window_factory::NewWindow(); clipping_window_->Init(ui::LAYER_NOT_DRAWN); clipping_window_->layer()->SetMasksToBounds(true); container->AddChild(clipping_window_.get()); diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc index 264286323c01cc..c2fb9d1edf7a2e 100644 --- a/ash/test/ash_test_base.cc +++ b/ash/test/ash_test_base.cc @@ -29,6 +29,7 @@ #include "ash/test_screenshot_delegate.h" #include "ash/test_shell_delegate.h" #include "ash/utility/screenshot_controller.h" +#include "ash/window_factory.h" #include "ash/wm/top_level_window_factory.h" #include "ash/wm/window_positioner.h" #include "ash/ws/window_service_owner.h" @@ -325,7 +326,7 @@ std::unique_ptr AshTestBase::CreateChildWindow( const gfx::Rect& bounds, int shell_window_id) { std::unique_ptr window = - std::make_unique(nullptr, aura::client::WINDOW_TYPE_NORMAL); + window_factory::NewWindow(nullptr, aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_NOT_DRAWN); window->SetBounds(bounds); window->set_id(shell_window_id); @@ -347,7 +348,7 @@ aura::Window* AshTestBase::CreateTestWindowInShellWithDelegateAndType( aura::client::WindowType type, int id, const gfx::Rect& bounds) { - aura::Window* window = new aura::Window(delegate); + aura::Window* window = window_factory::NewWindow(delegate).release(); window->set_id(id); window->SetType(type); window->Init(ui::LAYER_TEXTURED); @@ -500,7 +501,7 @@ bool AshTestBase::TestIfMouseWarpsAt(ui::test::EventGenerator* event_generator, return original_display.id() != screen ->GetDisplayNearestPoint( - aura::Env::GetInstance()->last_mouse_location()) + Shell::Get()->aura_env()->last_mouse_location()) .id(); } diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc index f18ea5e2ccdfb8..b8cb7b481bfdcc 100644 --- a/ash/test/ash_test_helper.cc +++ b/ash/test/ash_test_helper.cc @@ -44,6 +44,7 @@ #include "ui/aura/input_state_lookup.h" #include "ui/aura/test/env_test_helper.h" #include "ui/aura/test/event_generator_delegate_aura.h" +#include "ui/aura/test/test_windows.h" #include "ui/base/ime/input_method_initializer.h" #include "ui/base/material_design/material_design_controller.h" #include "ui/base/platform_window_defaults.h" @@ -165,6 +166,13 @@ AshTestHelper::~AshTestHelper() { } void AshTestHelper::SetUp(bool start_session, bool provide_local_state) { +#if !defined(NDEBUG) + aura::Window::SetEnvArgRequired( + "Within ash you must supply a non-null aura::Env when creating a Window, " + "use window_factory, or supply the Env obtained from " + "Shell::Get()->aura_env()"); +#endif + // TODO(jamescook): Can we do this without changing command line? // Use the origin (1,1) so that it doesn't over // lap with the native mouse cursor. @@ -235,8 +243,10 @@ void AshTestHelper::SetUp(bool start_session, bool provide_local_state) { CreateShell(); - aura::test::EnvTestHelper().SetInputStateLookup( - std::unique_ptr()); + aura::test::SetEnvForTestWindows(Shell::Get()->aura_env()); + + aura::test::EnvTestHelper(Shell::Get()->aura_env()) + .SetInputStateLookup(std::unique_ptr()); Shell* shell = Shell::Get(); @@ -278,6 +288,8 @@ void AshTestHelper::SetUp(bool start_session, bool provide_local_state) { void AshTestHelper::TearDown() { app_list_test_helper_.reset(); + aura::test::SetEnvForTestWindows(nullptr); + Shell::DeleteInstance(); // Suspend the tear down until all resources are returned via @@ -318,6 +330,9 @@ void AshTestHelper::TearDown() { env_window_tree_client_setter_.reset(); CHECK(!::wm::CaptureController::Get()); +#if !defined(NDEBUG) + aura::Window::SetEnvArgRequired(nullptr); +#endif } PrefService* AshTestHelper::GetLocalStatePrefService() { diff --git a/ash/test/ash_test_suite.cc b/ash/test/ash_test_suite.cc index a80f65fb7e9221..ee7477cc0ac337 100644 --- a/ash/test/ash_test_suite.cc +++ b/ash/test/ash_test_suite.cc @@ -12,6 +12,7 @@ #include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/base/ui_base_features.h" #include "ui/base/ui_base_paths.h" #include "ui/base/ui_base_switches.h" #include "ui/compositor/test/context_factories_for_test.h" @@ -63,7 +64,10 @@ void AshTestSuite::Initialize() { } base::DiscardableMemoryAllocator::SetInstance(&discardable_memory_allocator_); - env_ = aura::Env::CreateInstance(); + // Simulate what happens with single-process-mash. + env_ = aura::Env::CreateInstance(::features::IsSingleProcessMash() + ? aura::Env::Mode::MUS + : aura::Env::Mode::LOCAL); } void AshTestSuite::Shutdown() { diff --git a/ash/test/ui_controls_factory_ash.cc b/ash/test/ui_controls_factory_ash.cc index bd1a127297836c..c6c061f3b145e6 100644 --- a/ash/test/ui_controls_factory_ash.cc +++ b/ash/test/ui_controls_factory_ash.cc @@ -107,7 +107,7 @@ class UIControlsAsh : public UIControlsAura { int button_state, base::OnceClosure closure, int accelerator_state) override { - gfx::Point p(aura::Env::GetInstance()->last_mouse_location()); + gfx::Point p(Shell::Get()->aura_env()->last_mouse_location()); UIControlsAura* ui_controls = GetUIControlsAt(p); return ui_controls && ui_controls->SendMouseEventsNotifyWhenDone( diff --git a/ash/utility/screenshot_controller_unittest.cc b/ash/utility/screenshot_controller_unittest.cc index 070b98f0995f2a..2dce4a36f17698 100644 --- a/ash/utility/screenshot_controller_unittest.cc +++ b/ash/utility/screenshot_controller_unittest.cc @@ -260,12 +260,12 @@ TEST_F(PartialScreenshotControllerTest, MouseWarpTest) { StartPartialScreenshotSession(); EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(499, 11))); EXPECT_EQ(gfx::Point(499, 11), - aura::Env::GetInstance()->last_mouse_location()); + Shell::Get()->aura_env()->last_mouse_location()); Cancel(); EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 11))); EXPECT_EQ(gfx::Point(501, 11), - aura::Env::GetInstance()->last_mouse_location()); + Shell::Get()->aura_env()->last_mouse_location()); } TEST_F(PartialScreenshotControllerTest, CursorVisibilityTest) { diff --git a/ash/wayland/wayland_server_controller.cc b/ash/wayland/wayland_server_controller.cc index 95f10481a55a60..9243705364c23a 100644 --- a/ash/wayland/wayland_server_controller.cc +++ b/ash/wayland/wayland_server_controller.cc @@ -49,13 +49,15 @@ class WaylandServerController::WaylandWatcher // static std::unique_ptr WaylandServerController::CreateIfNecessary( - std::unique_ptr file_helper) { + std::unique_ptr file_helper, + aura::Env* env) { if (!base::CommandLine::ForCurrentProcess()->HasSwitch( switches::kAshEnableWaylandServer)) { return nullptr; } - return base::WrapUnique(new WaylandServerController(std::move(file_helper))); + return base::WrapUnique( + new WaylandServerController(std::move(file_helper), env)); } WaylandServerController::~WaylandServerController() { @@ -67,12 +69,13 @@ WaylandServerController::~WaylandServerController() { } WaylandServerController::WaylandServerController( - std::unique_ptr file_helper) { + std::unique_ptr file_helper, + aura::Env* env) { arc_notification_surface_manager_ = std::make_unique(); arc_input_method_surface_manager_ = std::make_unique(); - wm_helper_ = std::make_unique(aura::Env::GetInstance()); + wm_helper_ = std::make_unique(env); exo::WMHelper::SetInstance(wm_helper_.get()); display_ = std::make_unique( arc_notification_surface_manager_.get(), diff --git a/ash/wayland/wayland_server_controller.h b/ash/wayland/wayland_server_controller.h index 951ba2e141b180..75509fd89e9a11 100644 --- a/ash/wayland/wayland_server_controller.h +++ b/ash/wayland/wayland_server_controller.h @@ -9,6 +9,10 @@ #include "base/macros.h" +namespace aura { +class Env; +} + namespace exo { class Display; class FileHelper; @@ -28,13 +32,14 @@ class WaylandServerController { // Creates WaylandServerController. Returns null if controller should not be // created. static std::unique_ptr CreateIfNecessary( - std::unique_ptr file_helper); + std::unique_ptr file_helper, + aura::Env* env); ~WaylandServerController(); private: - explicit WaylandServerController( - std::unique_ptr file_helper); + WaylandServerController(std::unique_ptr file_helper, + aura::Env* env); std::unique_ptr wm_helper_; std::unique_ptr display_; diff --git a/ash/window_factory.cc b/ash/window_factory.cc new file mode 100644 index 00000000000000..a276464399b19d --- /dev/null +++ b/ash/window_factory.cc @@ -0,0 +1,20 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/window_factory.h" + +#include "ash/shell.h" +#include "ui/aura/window.h" + +namespace ash { +namespace window_factory { + +std::unique_ptr NewWindow(aura::WindowDelegate* delegate, + aura::client::WindowType type) { + return std::make_unique(delegate, type, + Shell::Get()->aura_env()); +} + +} // namespace window_factory +} // namespace ash diff --git a/ash/window_factory.h b/ash/window_factory.h new file mode 100644 index 00000000000000..f0fc75b888ef6f --- /dev/null +++ b/ash/window_factory.h @@ -0,0 +1,31 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_WINDOW_FACTORY_H_ +#define ASH_WINDOW_FACTORY_H_ + +#include + +#include "ash/ash_export.h" +#include "ui/aura/client/window_types.h" + +namespace aura { +class Window; +class WindowDelegate; +} // namespace aura + +namespace ash { +namespace window_factory { + +// All aura::Window creation in Ash goes through this function. It ensures the +// aura::Window is created as appropriate for Ash. +// Exporting solely for tests. +ASH_EXPORT std::unique_ptr NewWindow( + aura::WindowDelegate* delegate = nullptr, + aura::client::WindowType type = aura::client::WINDOW_TYPE_UNKNOWN); + +} // namespace window_factory +} // namespace ash + +#endif // ASH_WINDOW_FACTORY_H_ diff --git a/ash/window_user_data_unittest.cc b/ash/window_user_data_unittest.cc index 352d5844d4867a..1ee1dc3fa1b3d3 100644 --- a/ash/window_user_data_unittest.cc +++ b/ash/window_user_data_unittest.cc @@ -7,6 +7,7 @@ #include #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "ash/window_user_data.h" #include "ui/aura/window.h" #include "ui/compositor/layer_type.h" @@ -34,10 +35,10 @@ using WindowUserDataTest = AshTestBase; // Verifies clear() deletes the data associated with a window. TEST_F(WindowUserDataTest, ClearDestroys) { WindowUserData user_data; - aura::Window window(nullptr, aura::client::WINDOW_TYPE_UNKNOWN); - window.Init(ui::LAYER_NOT_DRAWN); + std::unique_ptr window = window_factory::NewWindow(); + window->Init(ui::LAYER_NOT_DRAWN); bool data_deleted = false; - user_data.Set(&window, std::make_unique(&data_deleted)); + user_data.Set(window.get(), std::make_unique(&data_deleted)); EXPECT_FALSE(data_deleted); user_data.clear(); EXPECT_TRUE(data_deleted); @@ -46,8 +47,7 @@ TEST_F(WindowUserDataTest, ClearDestroys) { // Verifies Set() called with an existing window replaces the existing data. TEST_F(WindowUserDataTest, ReplaceDestroys) { WindowUserData user_data; - std::unique_ptr window(std::make_unique( - nullptr, aura::client::WINDOW_TYPE_UNKNOWN)); + std::unique_ptr window = window_factory::NewWindow(); window->Init(ui::LAYER_NOT_DRAWN); bool data1_deleted = false; user_data.Set(window.get(), std::make_unique(&data1_deleted)); @@ -66,12 +66,12 @@ TEST_F(WindowUserDataTest, ReplaceDestroys) { // Verifies Set() with null deletes existing data. TEST_F(WindowUserDataTest, NullClears) { WindowUserData user_data; - aura::Window window(nullptr, aura::client::WINDOW_TYPE_UNKNOWN); - window.Init(ui::LAYER_NOT_DRAWN); + std::unique_ptr window = window_factory::NewWindow(); + window->Init(ui::LAYER_NOT_DRAWN); bool data1_deleted = false; - user_data.Set(&window, std::make_unique(&data1_deleted)); + user_data.Set(window.get(), std::make_unique(&data1_deleted)); EXPECT_FALSE(data1_deleted); - user_data.Set(&window, nullptr); + user_data.Set(window.get(), nullptr); EXPECT_TRUE(data1_deleted); EXPECT_TRUE(user_data.GetWindows().empty()); } diff --git a/ash/wm/ash_focus_rules_unittest.cc b/ash/wm/ash_focus_rules_unittest.cc index 764597ddb422c8..53dc1b987cb279 100644 --- a/ash/wm/ash_focus_rules_unittest.cc +++ b/ash/wm/ash_focus_rules_unittest.cc @@ -10,6 +10,7 @@ #include "ash/shell.h" #include "ash/test/ash_test_base.h" #include "ash/test/ash_test_helper.h" +#include "ash/window_factory.h" #include "ash/wm/lock_state_controller.h" #include "ash/wm/window_state.h" #include "ash/wm/window_util.h" @@ -131,7 +132,7 @@ class LockScreenAshFocusRulesTest : public AshTestBase { aura::Window* CreateWindowInContainer(int container_id) { aura::Window* root_window = Shell::GetPrimaryRootWindow(); aura::Window* container = Shell::GetContainer(root_window, container_id); - aura::Window* window = new aura::Window(nullptr); + aura::Window* window = window_factory::NewWindow().release(); window->set_id(0); window->SetType(aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); diff --git a/ash/wm/cursor_manager_chromeos.cc b/ash/wm/cursor_manager_chromeos.cc index 2fa44ddbdf9482..f3070f11da7eeb 100644 --- a/ash/wm/cursor_manager_chromeos.cc +++ b/ash/wm/cursor_manager_chromeos.cc @@ -6,6 +6,7 @@ #include +#include "ash/shell.h" #include "base/logging.h" #include "ui/aura/env.h" #include "ui/events/event.h" @@ -27,7 +28,7 @@ bool CursorManager::ShouldHideCursorOnKeyEvent( return false; // Do not hide cursor when clicking the key with mouse button pressed. - if (aura::Env::GetInstance()->IsMouseButtonDown()) + if (Shell::Get()->aura_env()->IsMouseButtonDown()) return false; // Clicking on a key when the accessibility virtual keyboard is enabled should diff --git a/ash/wm/drag_window_controller.cc b/ash/wm/drag_window_controller.cc index 1ae4478c68d730..7e43feccdb706c 100644 --- a/ash/wm/drag_window_controller.cc +++ b/ash/wm/drag_window_controller.cc @@ -9,6 +9,7 @@ #include "ash/public/cpp/shell_window_ids.h" #include "ash/shell.h" +#include "ash/window_factory.h" #include "ash/wm/window_util.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/client/screen_position_client.h" @@ -80,7 +81,7 @@ class DragWindowController::DragWindowDetails : public aura::WindowDelegate { const gfx::Rect& bounds_in_screen) { DCHECK(!drag_window_); original_window_ = original_window; - drag_window_ = new aura::Window(this); + drag_window_ = window_factory::NewWindow(this).release(); int parent_id = original_window->parent()->id(); aura::Window* container = root_window_->GetChildById(parent_id); diff --git a/ash/wm/drag_window_resizer_unittest.cc b/ash/wm/drag_window_resizer_unittest.cc index ee30cc6d869fb2..a20726c7cc9e9a 100644 --- a/ash/wm/drag_window_resizer_unittest.cc +++ b/ash/wm/drag_window_resizer_unittest.cc @@ -10,6 +10,7 @@ #include "ash/shelf/shelf_layout_manager.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "ash/wm/cursor_manager_test_api.h" #include "ash/wm/drag_window_controller.h" #include "ash/wm/window_positioning_utils.h" @@ -72,20 +73,20 @@ class DragWindowResizerTest : public AshTestBase { gfx::Rect root_bounds(root->bounds()); EXPECT_EQ(kRootHeight, root_bounds.height()); EXPECT_EQ(800, root_bounds.width()); - window_.reset(new aura::Window(&delegate_)); + window_ = window_factory::NewWindow(&delegate_); window_->SetType(aura::client::WINDOW_TYPE_NORMAL); window_->Init(ui::LAYER_NOT_DRAWN); ParentWindowInPrimaryRootWindow(window_.get()); window_->set_id(1); - always_on_top_window_.reset(new aura::Window(&delegate2_)); + always_on_top_window_ = window_factory::NewWindow(&delegate2_); always_on_top_window_->SetType(aura::client::WINDOW_TYPE_NORMAL); always_on_top_window_->SetProperty(aura::client::kAlwaysOnTopKey, true); always_on_top_window_->Init(ui::LAYER_NOT_DRAWN); ParentWindowInPrimaryRootWindow(always_on_top_window_.get()); always_on_top_window_->set_id(2); - system_modal_window_.reset(new aura::Window(&delegate3_)); + system_modal_window_ = window_factory::NewWindow(&delegate3_); system_modal_window_->SetType(aura::client::WINDOW_TYPE_NORMAL); system_modal_window_->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); @@ -93,20 +94,20 @@ class DragWindowResizerTest : public AshTestBase { ParentWindowInPrimaryRootWindow(system_modal_window_.get()); system_modal_window_->set_id(3); - transient_child_ = new aura::Window(&delegate4_); + transient_child_ = window_factory::NewWindow(&delegate4_).release(); transient_child_->SetType(aura::client::WINDOW_TYPE_NORMAL); transient_child_->Init(ui::LAYER_NOT_DRAWN); ParentWindowInPrimaryRootWindow(transient_child_); transient_child_->set_id(4); - transient_parent_.reset(new aura::Window(&delegate5_)); + transient_parent_ = window_factory::NewWindow(&delegate5_); transient_parent_->SetType(aura::client::WINDOW_TYPE_NORMAL); transient_parent_->Init(ui::LAYER_NOT_DRAWN); ParentWindowInPrimaryRootWindow(transient_parent_.get()); ::wm::AddTransientChild(transient_parent_.get(), transient_child_); transient_parent_->set_id(5); - panel_window_.reset(new aura::Window(&delegate6_)); + panel_window_ = window_factory::NewWindow(&delegate6_); panel_window_->SetType(aura::client::WINDOW_TYPE_PANEL); panel_window_->Init(ui::LAYER_NOT_DRAWN); ParentWindowInPrimaryRootWindow(panel_window_.get()); @@ -297,7 +298,7 @@ TEST_F(DragWindowResizerTest, WindowDragWithMultiDisplaysActiveRoot) { ASSERT_EQ(2U, root_windows.size()); aura::test::TestWindowDelegate delegate; - std::unique_ptr window(new aura::Window(&delegate)); + std::unique_ptr window = window_factory::NewWindow(&delegate); window->SetType(aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); ParentWindowInPrimaryRootWindow(window.get()); @@ -656,7 +657,7 @@ TEST_F(DragWindowResizerTest, MoveWindowAcrossDisplays) { resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(399, 200))); EXPECT_EQ("401,200", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); resizer->CompleteDrag(); } @@ -673,7 +674,7 @@ TEST_F(DragWindowResizerTest, MoveWindowAcrossDisplays) { resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(399, 200))); EXPECT_EQ("401,200", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); resizer->CompleteDrag(); } @@ -683,7 +684,7 @@ TEST_F(DragWindowResizerTest, MoveWindowAcrossDisplays) { window->SetBoundsInScreen( gfx::Rect(0, 0, 50, 60), display::Screen::GetScreen()->GetPrimaryDisplay()); - aura::Env::GetInstance()->SetLastMouseLocation(gfx::Point(0, 0)); + Shell::Get()->aura_env()->SetLastMouseLocation(gfx::Point(0, 0)); // Grab (0, 0) of the window. std::unique_ptr resizer( CreateDragWindowResizer(window, gfx::Point(), HTCAPTION)); @@ -691,7 +692,7 @@ TEST_F(DragWindowResizerTest, MoveWindowAcrossDisplays) { resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(399, 200))); EXPECT_EQ("401,200", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); resizer->CompleteDrag(); } @@ -708,7 +709,7 @@ TEST_F(DragWindowResizerTest, MoveWindowAcrossDisplays) { resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(399, 200))); EXPECT_EQ("399,200", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); resizer->CompleteDrag(); } @@ -725,7 +726,7 @@ TEST_F(DragWindowResizerTest, MoveWindowAcrossDisplays) { resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(399, 200))); EXPECT_EQ("401,200", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); resizer->CompleteDrag(); } @@ -742,7 +743,7 @@ TEST_F(DragWindowResizerTest, MoveWindowAcrossDisplays) { resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(399, 200))); EXPECT_EQ("401,200", - aura::Env::GetInstance()->last_mouse_location().ToString()); + Shell::Get()->aura_env()->last_mouse_location().ToString()); resizer->CompleteDrag(); } } diff --git a/ash/wm/immersive_fullscreen_controller_unittest.cc b/ash/wm/immersive_fullscreen_controller_unittest.cc index 6b979d117f72f7..8e5819c6f1c516 100644 --- a/ash/wm/immersive_fullscreen_controller_unittest.cc +++ b/ash/wm/immersive_fullscreen_controller_unittest.cc @@ -556,7 +556,7 @@ TEST_F(ImmersiveFullscreenControllerTest, MouseEventsVerticalDisplayLayout) { event_generator->MoveMouseTo(x, y_top_edge + 1); EXPECT_TRUE(top_edge_hover_timer_running()); EXPECT_EQ(y_top_edge + 1, - aura::Env::GetInstance()->last_mouse_location().y()); + Shell::Get()->aura_env()->last_mouse_location().y()); // The timer should continue running if the user moves the mouse to the top // edge even though the mouse is warped to the secondary display. diff --git a/ash/wm/native_cursor_manager_ash_classic.cc b/ash/wm/native_cursor_manager_ash_classic.cc index 399b82379a3e97..e11dadf84fd95c 100644 --- a/ash/wm/native_cursor_manager_ash_classic.cc +++ b/ash/wm/native_cursor_manager_ash_classic.cc @@ -150,11 +150,10 @@ void NativeCursorManagerAshClassic::SetMouseEventsEnabled( ::wm::NativeCursorManagerDelegate* delegate) { delegate->CommitMouseEventsEnabled(enabled); - if (enabled) { - aura::Env::GetInstance()->SetLastMouseLocation(disabled_cursor_location_); - } else { - disabled_cursor_location_ = aura::Env::GetInstance()->last_mouse_location(); - } + if (enabled) + Shell::Get()->aura_env()->SetLastMouseLocation(disabled_cursor_location_); + else + disabled_cursor_location_ = Shell::Get()->aura_env()->last_mouse_location(); SetVisibility(delegate->IsCursorVisible(), delegate); NotifyMouseEventsEnableStateChange(enabled); diff --git a/ash/wm/non_client_frame_controller.cc b/ash/wm/non_client_frame_controller.cc index 624a566a8c1c88..4462f7d9fea277 100644 --- a/ash/wm/non_client_frame_controller.cc +++ b/ash/wm/non_client_frame_controller.cc @@ -177,9 +177,9 @@ class WmNativeWidgetAura : public views::NativeWidgetAura { mojom::WindowStyle window_style) // The NativeWidget is mirroring the real Widget created in client code. // |is_parallel_widget_in_window_manager| is used to indicate this - : views::NativeWidgetAura( - delegate, - true /* is_parallel_widget_in_window_manager */), + : views::NativeWidgetAura(delegate, + true /* is_parallel_widget_in_window_manager */, + Shell::Get()->aura_env()), remove_standard_frame_(remove_standard_frame), enable_immersive_(enable_immersive), window_style_(window_style) {} diff --git a/ash/wm/overview/window_selector_unittest.cc b/ash/wm/overview/window_selector_unittest.cc index 4d7a9b820bf569..58de64cced0369 100644 --- a/ash/wm/overview/window_selector_unittest.cc +++ b/ash/wm/overview/window_selector_unittest.cc @@ -3237,7 +3237,7 @@ TEST_F(SplitViewWindowSelectorTest, DragOverviewWindowToSnap) { } TEST_F(SplitViewWindowSelectorTest, Dragging) { - aura::Env::GetInstance()->set_throttle_input_on_resize_for_testing(false); + Shell::Get()->aura_env()->set_throttle_input_on_resize_for_testing(false); ui::test::EventGenerator* generator = GetEventGenerator(); @@ -3324,7 +3324,7 @@ TEST_F(SplitViewWindowSelectorTest, Dragging) { // Verify the correct behavior when dragging windows in overview mode. TEST_F(SplitViewWindowSelectorTest, OverviewDragControllerBehavior) { - aura::Env::GetInstance()->set_throttle_input_on_resize_for_testing(false); + Shell::Get()->aura_env()->set_throttle_input_on_resize_for_testing(false); base::test::ScopedFeatureList scoped_feature_list; scoped_feature_list.InitAndEnableFeature(features::kOverviewSwipeToClose); diff --git a/ash/wm/stacking_controller_unittest.cc b/ash/wm/stacking_controller_unittest.cc index e8217ff8509c9d..192ae932529f46 100644 --- a/ash/wm/stacking_controller_unittest.cc +++ b/ash/wm/stacking_controller_unittest.cc @@ -5,6 +5,7 @@ #include "ash/public/cpp/shell_window_ids.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "ash/wm/window_properties.h" #include "ash/wm/window_util.h" #include "ui/aura/client/aura_constants.h" @@ -22,9 +23,10 @@ class StackingControllerTest : public AshTestBase { ~StackingControllerTest() override = default; aura::Window* CreateTestWindow() { - aura::Window* window = new aura::Window(NULL); + aura::Window* window = + window_factory::NewWindow(nullptr, aura::client::WINDOW_TYPE_NORMAL) + .release(); window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); - window->SetType(aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); return window; } diff --git a/ash/wm/system_gesture_event_filter_unittest.cc b/ash/wm/system_gesture_event_filter_unittest.cc index 70b09aba0cfb59..6805d5a1b92d14 100644 --- a/ash/wm/system_gesture_event_filter_unittest.cc +++ b/ash/wm/system_gesture_event_filter_unittest.cc @@ -10,6 +10,7 @@ #include "ash/shell.h" #include "ash/shell_test_api.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "ash/wm/window_positioning_utils.h" #include "ash/wm/window_state.h" #include "base/time/time.h" @@ -456,15 +457,15 @@ TEST_F(SystemGestureEventFilterTest, aura::test::EventCountDelegate delegate; delegate.set_window_component(HTCLIENT); - std::unique_ptr child(new aura::Window(&delegate)); - child->SetType(aura::client::WINDOW_TYPE_CONTROL); + std::unique_ptr child = + window_factory::NewWindow(&delegate, aura::client::WINDOW_TYPE_CONTROL); child->Init(ui::LAYER_TEXTURED); parent->AddChild(child.get()); child->SetBounds(gfx::Rect(100, 100)); child->Show(); ui::test::TestEventHandler event_handler; - aura::Env::GetInstance()->AddPreTargetHandler( + Shell::Get()->aura_env()->AddPreTargetHandler( &event_handler, ui::EventTarget::Priority::kSystem); GetEventGenerator()->MoveMouseTo(0, 0); @@ -475,7 +476,7 @@ TEST_F(SystemGestureEventFilterTest, EXPECT_EQ(event_handler.num_gesture_events(), delegate.GetGestureCountAndReset()); - aura::Env::GetInstance()->RemovePreTargetHandler(&event_handler); + Shell::Get()->aura_env()->RemovePreTargetHandler(&event_handler); } } // namespace ash diff --git a/ash/wm/system_modal_container_layout_manager_unittest.cc b/ash/wm/system_modal_container_layout_manager_unittest.cc index 0d2bbb0c8aa8d4..8db37d05bc9287 100644 --- a/ash/wm/system_modal_container_layout_manager_unittest.cc +++ b/ash/wm/system_modal_container_layout_manager_unittest.cc @@ -10,6 +10,7 @@ #include "ash/root_window_controller.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "ash/wm/container_finder.h" #include "ash/wm/window_util.h" #include "base/command_line.h" @@ -417,7 +418,8 @@ TEST_F(SystemModalContainerLayoutManagerTest, ModalTransientChildEvents) { // Create a child control for modal1_transient and it receives mouse events. aura::test::EventCountDelegate control_delegate; control_delegate.set_window_component(HTCLIENT); - std::unique_ptr child(new aura::Window(&control_delegate)); + std::unique_ptr child = + window_factory::NewWindow(&control_delegate); child->SetType(aura::client::WINDOW_TYPE_CONTROL); child->Init(ui::LAYER_TEXTURED); modal1_transient->AddChild(child.get()); @@ -800,7 +802,7 @@ TEST_F(SystemModalContainerLayoutManagerTest, VisibilityChange) { // Make sure that a child visibility change should not cause // inconsistent state. - std::unique_ptr child = std::make_unique(nullptr); + std::unique_ptr child = window_factory::NewWindow(); child->SetType(aura::client::WINDOW_TYPE_CONTROL); child->Init(ui::LAYER_TEXTURED); modal_window->AddChild(child.get()); diff --git a/ash/wm/top_level_window_factory.cc b/ash/wm/top_level_window_factory.cc index d5ef8f394ca8a9..3361431e2b4adc 100644 --- a/ash/wm/top_level_window_factory.cc +++ b/ash/wm/top_level_window_factory.cc @@ -10,6 +10,7 @@ #include "ash/root_window_controller.h" #include "ash/root_window_settings.h" #include "ash/shell.h" +#include "ash/window_factory.h" #include "ash/wm/container_finder.h" #include "ash/wm/non_client_frame_controller.h" #include "ash/wm/property_util.h" @@ -173,7 +174,7 @@ aura::Window* CreateAndParentTopLevelWindowInRoot( // destroyed. ui::ws2::WindowDelegateImpl* window_delegate = new ui::ws2::WindowDelegateImpl(); - aura::Window* window = new aura::Window(window_delegate); + aura::Window* window = window_factory::NewWindow(window_delegate).release(); window_delegate->set_window(window); aura::SetWindowType(window, window_type); ApplyProperties(window, property_converter, *properties); diff --git a/ash/wm/toplevel_window_event_handler.cc b/ash/wm/toplevel_window_event_handler.cc index f59765a2699a2d..011b654745fedd 100644 --- a/ash/wm/toplevel_window_event_handler.cc +++ b/ash/wm/toplevel_window_event_handler.cc @@ -69,7 +69,7 @@ ::wm::WindowMoveResult ToplevelWindowEventHandler::RunMoveLoop( DCHECK(root_window); gfx::Point drag_location; if (move_source == ::wm::WINDOW_MOVE_SOURCE_TOUCH && - aura::Env::GetInstance()->is_touch_down()) { + Shell::Get()->aura_env()->is_touch_down()) { gfx::PointF drag_location_f; bool has_point = ui::GestureRecognizer::Get()->GetLastTouchPointForTarget( source, &drag_location_f); diff --git a/ash/wm/toplevel_window_event_handler_unittest.cc b/ash/wm/toplevel_window_event_handler_unittest.cc index 2cf0a25c991deb..9483c9fa615ec7 100644 --- a/ash/wm/toplevel_window_event_handler_unittest.cc +++ b/ash/wm/toplevel_window_event_handler_unittest.cc @@ -8,6 +8,7 @@ #include "ash/root_window_controller.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "ash/wm/resize_shadow.h" #include "ash/wm/resize_shadow_controller.h" #include "ash/wm/window_state.h" @@ -60,8 +61,9 @@ class ToplevelWindowEventHandlerTest : public AshTestBase { protected: aura::Window* CreateWindow(int hittest_code) { TestWindowDelegate* d1 = new TestWindowDelegate(hittest_code); - aura::Window* w1 = new aura::Window(d1); - w1->SetType(aura::client::WINDOW_TYPE_NORMAL); + aura::Window* w1 = + window_factory::NewWindow(d1, aura::client::WINDOW_TYPE_NORMAL) + .release(); w1->set_id(1); w1->Init(ui::LAYER_TEXTURED); aura::Window* parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(), diff --git a/ash/wm/video_detector.cc b/ash/wm/video_detector.cc index 4c4626d5b88cd1..5f7cc38496844b 100644 --- a/ash/wm/video_detector.cc +++ b/ash/wm/video_detector.cc @@ -22,13 +22,13 @@ VideoDetector::VideoDetector(viz::mojom::VideoDetectorObserverRequest request) scoped_session_observer_(this), is_shutting_down_(false), binding_(this, std::move(request)) { - aura::Env::GetInstance()->AddObserver(this); + Shell::Get()->aura_env()->AddObserver(this); Shell::Get()->AddShellObserver(this); } VideoDetector::~VideoDetector() { Shell::Get()->RemoveShellObserver(this); - aura::Env::GetInstance()->RemoveObserver(this); + Shell::Get()->aura_env()->RemoveObserver(this); } void VideoDetector::AddObserver(Observer* observer) { diff --git a/ash/wm/window_dimmer.cc b/ash/wm/window_dimmer.cc index 64dcf1d8363891..4460e743ccbcc7 100644 --- a/ash/wm/window_dimmer.cc +++ b/ash/wm/window_dimmer.cc @@ -6,6 +6,7 @@ #include +#include "ash/window_factory.h" #include "base/time/time.h" #include "ui/aura/window.h" #include "ui/compositor/layer.h" @@ -23,7 +24,9 @@ const float kDefaultDimOpacity = 0.5f; WindowDimmer::WindowDimmer(aura::Window* parent) : parent_(parent), - window_(new aura::Window(nullptr, aura::client::WINDOW_TYPE_NORMAL)) { + window_( + window_factory::NewWindow(nullptr, aura::client::WINDOW_TYPE_NORMAL) + .release()) { window_->Init(ui::LAYER_SOLID_COLOR); ::wm::SetWindowVisibilityChangesAnimated(window_); ::wm::SetWindowVisibilityAnimationType( diff --git a/ash/wm/window_dimmer_unittest.cc b/ash/wm/window_dimmer_unittest.cc index dbddc049640e17..b220a43c55ce33 100644 --- a/ash/wm/window_dimmer_unittest.cc +++ b/ash/wm/window_dimmer_unittest.cc @@ -3,6 +3,9 @@ // found in the LICENSE file. #include "ash/wm/window_dimmer.h" + +#include "ash/test/ash_test_base.h" +#include "ash/test/ash_test_helper.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/aura/test/aura_test_base.h" #include "ui/aura/test/test_windows.h" @@ -10,19 +13,20 @@ namespace ash { -using WindowDimmerTest = aura::test::AuraTestBase; +using WindowDimmerTest = ash::AshTestBase; // Verify that a window underneath the window dimmer is not occluded. TEST_F(WindowDimmerTest, Occlusion) { + aura::Window* root_window = CurrentContext(); aura::Window* bottom_window = aura::test::CreateTestWindow( - SK_ColorWHITE, 1, root_window()->bounds(), root_window()); + SK_ColorWHITE, 1, root_window->bounds(), root_window); aura::WindowOcclusionTracker::Track(bottom_window); - WindowDimmer dimmer(root_window()); + WindowDimmer dimmer(root_window); EXPECT_EQ(aura::Window::OcclusionState::VISIBLE, bottom_window->occlusion_state()); // Sanity check: An opaque window on top of |bottom_window| occludes it. - aura::test::CreateTestWindow(SK_ColorWHITE, 2, root_window()->bounds(), - root_window()); + aura::test::CreateTestWindow(SK_ColorWHITE, 2, root_window->bounds(), + root_window); EXPECT_EQ(aura::Window::OcclusionState::OCCLUDED, bottom_window->occlusion_state()); } diff --git a/ash/wm/workspace/workspace_event_handler_unittest.cc b/ash/wm/workspace/workspace_event_handler_unittest.cc index 6025b9b776e0db..38a2787478d37c 100644 --- a/ash/wm/workspace/workspace_event_handler_unittest.cc +++ b/ash/wm/workspace/workspace_event_handler_unittest.cc @@ -7,6 +7,7 @@ #include "ash/screen_util.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "ash/wm/window_state.h" #include "ash/wm/window_util.h" #include "ash/wm/wm_event.h" @@ -54,8 +55,9 @@ class WorkspaceEventHandlerTest : public AshTestBase { protected: aura::Window* CreateTestWindow(aura::WindowDelegate* delegate, const gfx::Rect& bounds) { - aura::Window* window = new aura::Window(delegate); - window->SetType(aura::client::WINDOW_TYPE_NORMAL); + aura::Window* window = + window_factory::NewWindow(delegate, aura::client::WINDOW_TYPE_NORMAL) + .release(); window->Init(ui::LAYER_TEXTURED); ParentWindowInPrimaryRootWindow(window); window->SetBounds(bounds); diff --git a/ash/wm/workspace/workspace_layout_manager_unittest.cc b/ash/wm/workspace/workspace_layout_manager_unittest.cc index 173e4a71218315..307f6d8ac426bc 100644 --- a/ash/wm/workspace/workspace_layout_manager_unittest.cc +++ b/ash/wm/workspace/workspace_layout_manager_unittest.cc @@ -28,6 +28,7 @@ #include "ash/shell_test_api.h" #include "ash/test/ash_test_base.h" #include "ash/wallpaper/wallpaper_controller_test_api.h" +#include "ash/window_factory.h" #include "ash/wm/fullscreen_window_finder.h" #include "ash/wm/overview/window_selector_controller.h" #include "ash/wm/splitview/split_view_controller.h" @@ -402,8 +403,8 @@ class DontClobberRestoreBoundsWindowObserver : public aura::WindowObserver { // doesn't effect the restore bounds. TEST_F(WorkspaceLayoutManagerTest, DontClobberRestoreBounds) { DontClobberRestoreBoundsWindowObserver window_observer; - std::unique_ptr window(std::make_unique( - nullptr, aura::client::WINDOW_TYPE_NORMAL)); + std::unique_ptr window = + window_factory::NewWindow(nullptr, aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); window->SetBounds(gfx::Rect(10, 20, 30, 40)); // NOTE: for this test to exercise the failure the observer needs to be added @@ -442,8 +443,8 @@ TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { // Verifies a window created with maximized state has the maximized // bounds. TEST_F(WorkspaceLayoutManagerTest, MaximizeWithEmptySize) { - std::unique_ptr window(std::make_unique( - nullptr, aura::client::WINDOW_TYPE_NORMAL)); + std::unique_ptr window = + window_factory::NewWindow(nullptr, aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); wm::GetWindowState(window.get())->Maximize(); aura::Window* default_container = @@ -669,8 +670,8 @@ TEST_F(WorkspaceLayoutManagerTest, AdjustSnappedBoundsWidth) { TEST_F(WorkspaceLayoutManagerTest, DoNotAdjustTransientWindowBoundsToEnsureMinimumVisibility) { UpdateDisplay("300x400"); - std::unique_ptr window(std::make_unique( - nullptr, aura::client::WINDOW_TYPE_NORMAL)); + std::unique_ptr window = + window_factory::NewWindow(nullptr, aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); window->SetBounds(gfx::Rect(10, 0, 100, 200)); ParentWindowInPrimaryRootWindow(window.get()); @@ -1063,7 +1064,7 @@ class WorkspaceLayoutManagerBackdropTest : public AshTestBase { } aura::Window* CreateTestWindowInParent(aura::Window* root_window) { - aura::Window* window = new aura::Window(nullptr); + aura::Window* window = window_factory::NewWindow().release(); window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); window->SetType(aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); diff --git a/ash/wm/workspace/workspace_window_resizer_unittest.cc b/ash/wm/workspace/workspace_window_resizer_unittest.cc index b2cdb9ee627cfd..f4bfa76fd85a2d 100644 --- a/ash/wm/workspace/workspace_window_resizer_unittest.cc +++ b/ash/wm/workspace/workspace_window_resizer_unittest.cc @@ -10,6 +10,7 @@ #include "ash/shelf/shelf_constants.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "ash/wm/window_positioning_utils.h" #include "ash/wm/window_state.h" #include "ash/wm/window_util.h" @@ -111,25 +112,25 @@ class WorkspaceWindowResizerTest : public AshTestBase { gfx::Rect root_bounds(root->bounds()); EXPECT_EQ(800, root_bounds.width()); Shell::Get()->SetDisplayWorkAreaInsets(root, gfx::Insets()); - window_.reset(new aura::Window(&delegate_)); + window_ = window_factory::NewWindow(&delegate_); window_->SetType(aura::client::WINDOW_TYPE_NORMAL); window_->Init(ui::LAYER_NOT_DRAWN); ParentWindowInPrimaryRootWindow(window_.get()); window_->set_id(1); - window2_.reset(new aura::Window(&delegate2_)); + window2_ = window_factory::NewWindow(&delegate2_); window2_->SetType(aura::client::WINDOW_TYPE_NORMAL); window2_->Init(ui::LAYER_NOT_DRAWN); ParentWindowInPrimaryRootWindow(window2_.get()); window2_->set_id(2); - window3_.reset(new aura::Window(&delegate3_)); + window3_ = window_factory::NewWindow(&delegate3_); window3_->SetType(aura::client::WINDOW_TYPE_NORMAL); window3_->Init(ui::LAYER_NOT_DRAWN); ParentWindowInPrimaryRootWindow(window3_.get()); window3_->set_id(3); - window4_.reset(new aura::Window(&delegate4_)); + window4_ = window_factory::NewWindow(&delegate4_); window4_->SetType(aura::client::WINDOW_TYPE_NORMAL); window4_->Init(ui::LAYER_NOT_DRAWN); ParentWindowInPrimaryRootWindow(window4_.get()); diff --git a/ash/wm/workspace_controller_unittest.cc b/ash/wm/workspace_controller_unittest.cc index 88abf701e2f21d..f0a195263a0ea6 100644 --- a/ash/wm/workspace_controller_unittest.cc +++ b/ash/wm/workspace_controller_unittest.cc @@ -16,6 +16,7 @@ #include "ash/shell_test_api.h" #include "ash/system/status_area_widget.h" #include "ash/test/ash_test_base.h" +#include "ash/window_factory.h" #include "ash/wm/window_state.h" #include "ash/wm/window_util.h" #include "ash/wm/wm_event.h" @@ -80,7 +81,7 @@ class WorkspaceControllerTest : public AshTestBase { ~WorkspaceControllerTest() override = default; aura::Window* CreateTestWindowUnparented() { - aura::Window* window = new aura::Window(NULL); + aura::Window* window = window_factory::NewWindow().release(); window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); window->SetType(aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); @@ -88,7 +89,7 @@ class WorkspaceControllerTest : public AshTestBase { } aura::Window* CreateTestWindow() { - aura::Window* window = new aura::Window(NULL); + aura::Window* window = window_factory::NewWindow().release(); window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); window->SetType(aura::client::WINDOW_TYPE_NORMAL); window->Init(ui::LAYER_TEXTURED); diff --git a/ash/ws/window_service_owner.cc b/ash/ws/window_service_owner.cc index 945de14a6d26ed..98a19958e1eddf 100644 --- a/ash/ws/window_service_owner.cc +++ b/ash/ws/window_service_owner.cc @@ -36,7 +36,8 @@ void WindowServiceOwner::BindWindowService( std::unique_ptr window_service = std::make_unique( window_service_delegate_.get(), std::move(gpu_interface_provider_), - Shell::Get()->focus_controller(), features::IsAshInBrowserProcess()); + Shell::Get()->focus_controller(), features::IsAshInBrowserProcess(), + Shell::Get()->aura_env()); window_service_ = window_service.get(); window_service_->SetFrameDecorationValues( NonClientFrameController::GetPreferredClientAreaInsets(), diff --git a/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_browsertest.cc b/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_browsertest.cc index e457bd8f946e47..434cb843f5676e 100644 --- a/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_browsertest.cc +++ b/chrome/browser/chromeos/arc/accessibility/arc_accessibility_helper_bridge_browsertest.cc @@ -45,7 +45,7 @@ class ArcAccessibilityHelperBridgeBrowserTest : public InProcessBrowserTest { chromeos::AccessibilityManager::Get()->SetProfileForTest( browser()->profile()); - wm_helper_ = std::make_unique(aura::Env::GetInstance()); + wm_helper_ = std::make_unique(ash::Shell::Get()->aura_env()); exo::WMHelper::SetInstance(wm_helper_.get()); } diff --git a/chrome/browser/ui/ash/ksv/DEPS b/chrome/browser/ui/ash/ksv/DEPS index 185fb4f3009766..f361719c8d6cce 100644 --- a/chrome/browser/ui/ash/ksv/DEPS +++ b/chrome/browser/ui/ash/ksv/DEPS @@ -8,8 +8,8 @@ include_rules = [ specific_include_rules = { # mash-ok. https://crbug.com/841020 "keyboard_shortcut_viewer_util\.cc": [ - "+ash/shell.h", "+ash/components/shortcut_viewer/views/keyboard_shortcut_view.h", + "+ash/shell.h", ], # Tests. "keyboard_shortcut_viewer_metadata_unittest\.cc": [ diff --git a/chrome/browser/ui/ash/ksv/keyboard_shortcut_viewer_util.cc b/chrome/browser/ui/ash/ksv/keyboard_shortcut_viewer_util.cc index 612c8e9d7be0d9..c74a63c4d40edc 100644 --- a/chrome/browser/ui/ash/ksv/keyboard_shortcut_viewer_util.cc +++ b/chrome/browser/ui/ash/ksv/keyboard_shortcut_viewer_util.cc @@ -11,6 +11,7 @@ #include "base/time/time.h" #include "content/public/common/service_manager_connection.h" #include "services/service_manager/public/cpp/connector.h" +#include "ui/base/ui_base_features.h" namespace keyboard_shortcut_viewer_util { @@ -24,8 +25,15 @@ void ToggleKeyboardShortcutViewer() { &shortcut_viewer_ptr); shortcut_viewer_ptr->Toggle(user_gesture_time); } else { - keyboard_shortcut_viewer::KeyboardShortcutView::Toggle( - user_gesture_time, ash::Shell::Get()->GetRootWindowForNewWindows()); + // A value of |null| while IsSingleProcessMash() results in the keyboard + // shortcut viewer using DesktopNativeWidgetAura, just as all other non-ash + // codes does in single-process-mash. + aura::Window* context = + features::IsSingleProcessMash() + ? nullptr + : ash::Shell::Get()->GetRootWindowForNewWindows(); + keyboard_shortcut_viewer::KeyboardShortcutView::Toggle(user_gesture_time, + context); } } diff --git a/components/exo/test/exo_test_base.cc b/components/exo/test/exo_test_base.cc index b6a89d59ae3ea5..9a19351536cc49 100644 --- a/components/exo/test/exo_test_base.cc +++ b/components/exo/test/exo_test_base.cc @@ -29,7 +29,7 @@ void ExoTestBase::SetUp() { command_line->AppendSwitch(wm::switches::kWindowAnimationsDisabled); ui::SetUpInputMethodFactoryForTesting(); AshTestBase::SetUp(); - wm_helper_ = std::make_unique(aura::Env::GetInstance()); + wm_helper_ = std::make_unique(ash::Shell::Get()->aura_env()); WMHelper::SetInstance(wm_helper_.get()); test::TestClientControlledStateDelegate::InstallFactory(); } diff --git a/components/exo/wayland/clients/test/wayland_client_test.cc b/components/exo/wayland/clients/test/wayland_client_test.cc index 6f8c86f2d4cfcd..34100a2fbc5410 100644 --- a/components/exo/wayland/clients/test/wayland_client_test.cc +++ b/components/exo/wayland/clients/test/wayland_client_test.cc @@ -145,7 +145,7 @@ void WaylandClientTest::SetUpOnUIThread(base::WaitableEvent* event) { gesture_config->set_long_press_time_in_ms(1000); gesture_config->set_max_touch_move_in_pixels_for_click(5); - wm_helper_ = std::make_unique(aura::Env::GetInstance()); + wm_helper_ = std::make_unique(ash::Shell::Get()->aura_env()); WMHelper::SetInstance(wm_helper_.get()); display_ = std::make_unique(nullptr, nullptr, nullptr); wayland_server_ = exo::wayland::Server::Create(display_.get()); diff --git a/ui/aura/env.cc b/ui/aura/env.cc index b8c4f9a6b931ac..517d9739f236d0 100644 --- a/ui/aura/env.cc +++ b/ui/aura/env.cc @@ -6,7 +6,6 @@ #include "base/command_line.h" #include "base/lazy_instance.h" -#include "base/threading/thread_local.h" #include "services/ui/public/interfaces/window_tree.mojom.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/env_input_state_controller.h" @@ -34,9 +33,9 @@ namespace aura { namespace { -// Env is thread local so that aura may be used on multiple threads. -base::LazyInstance>::Leaky lazy_tls_ptr = - LAZY_INSTANCE_INITIALIZER; +// Instance created by all static functions, except +// CreateLocalInstanceForInProcess(). See GetInstance() for details. +Env* g_primary_instance = nullptr; } // namespace @@ -52,14 +51,29 @@ Env::~Env() { for (EnvObserver& observer : observers_) observer.OnWillDestroyEnv(); - DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); - lazy_tls_ptr.Pointer()->Set(NULL); + if (this == g_primary_instance) + g_primary_instance = nullptr; } // static std::unique_ptr Env::CreateInstance(Mode mode) { - DCHECK(!lazy_tls_ptr.Pointer()->Get()); + DCHECK(!g_primary_instance); + // No make_unique as constructor is private. std::unique_ptr env(new Env(mode)); + g_primary_instance = env.get(); + env->Init(nullptr); + return env; +} + +// static +std::unique_ptr Env::CreateLocalInstanceForInProcess() { + // It is expected this constructor is called *after* an instance has been + // created of type MUS. The order, and DCHECKs, aren't strictly necessary but + // help reinforce when this should be used. + DCHECK(g_primary_instance); + DCHECK(g_primary_instance->mode() == Mode::MUS); + // No make_unique as constructor is private. + std::unique_ptr env(new Env(Mode::LOCAL)); env->Init(nullptr); return env; } @@ -68,8 +82,10 @@ std::unique_ptr Env::CreateInstance(Mode mode) { // static std::unique_ptr Env::CreateInstanceToHostViz( service_manager::Connector* connector) { - DCHECK(!lazy_tls_ptr.Pointer()->Get()); + DCHECK(!g_primary_instance); + // No make_unique as constructor is private. std::unique_ptr env(new Env(Mode::LOCAL)); + g_primary_instance = env.get(); env->Init(connector); return env; } @@ -77,7 +93,7 @@ std::unique_ptr Env::CreateInstanceToHostViz( // static Env* Env::GetInstance() { - Env* env = lazy_tls_ptr.Pointer()->Get(); + Env* env = g_primary_instance; DCHECK(env) << "Env::CreateInstance must be called before getting the " "instance of Env."; return env; @@ -85,7 +101,7 @@ Env* Env::GetInstance() { // static Env* Env::GetInstanceDontCreate() { - return lazy_tls_ptr.Pointer()->Get(); + return g_primary_instance; } std::unique_ptr Env::CreateWindowPort(Window* window) { @@ -193,10 +209,7 @@ Env::Env(Mode mode) get_last_mouse_location_from_mus_(mode_ == Mode::MUS), input_state_lookup_(InputStateLookup::Create()), context_factory_(nullptr), - context_factory_private_(nullptr) { - DCHECK(lazy_tls_ptr.Pointer()->Get() == NULL); - lazy_tls_ptr.Pointer()->Set(this); -} + context_factory_private_(nullptr) {} void Env::Init(service_manager::Connector* connector) { if (mode_ == Mode::MUS) { diff --git a/ui/aura/env.h b/ui/aura/env.h index c8056133f81d34..a8c1b98b16e855 100644 --- a/ui/aura/env.h +++ b/ui/aura/env.h @@ -79,6 +79,11 @@ class AURA_EXPORT Env : public ui::EventTarget, // SetWindowTreeClient() before any windows are created. static std::unique_ptr CreateInstance(Mode mode = Mode::LOCAL); + // Creates a new Env of type LOCAL. This factory function is intended for + // use when this process is providing the WindowService *and* acting as a + // client of the WindowService, for example, ash with SingleProcessMash. + static std::unique_ptr CreateLocalInstanceForInProcess(); + #if defined(USE_OZONE) // used to create a new Env that hosts the viz process. |connector| is the // connector used to establish outbound connections. @@ -86,6 +91,14 @@ class AURA_EXPORT Env : public ui::EventTarget, service_manager::Connector* connector); #endif + // This returns the instance created by CreateInstance() or + // CreateInstanceToHostViz(). This does *not* return the instance returned + // by CreateLocalInstanceForInProcess(). The instance returned by + // CreateLocalInstanceForInProcess() is intended for use when an Env has + // already been created. For example, in chrome with SingleProcessMash an + // instance is created by way of CreateInstance() (which is the instance + // returned by GetInstance()) *and* an instance is created via + // CreateLocalInstanceForInProcess(). static Env* GetInstance(); static Env* GetInstanceDontCreate(); diff --git a/ui/aura/test/test_windows.cc b/ui/aura/test/test_windows.cc index 07328d80b34a63..b4bd15b12b4f0c 100644 --- a/ui/aura/test/test_windows.cc +++ b/ui/aura/test/test_windows.cc @@ -25,6 +25,10 @@ void SetEnvForTestWindows(Env* env) { g_env = env; } +Env* GetEnvForTestWindows() { + return g_env ? g_env : Env::GetInstance(); +} + Window* CreateTestWindowWithId(int id, Window* parent) { return CreateTestWindowWithDelegate(NULL, id, gfx::Rect(), parent); } @@ -55,7 +59,7 @@ Window* CreateTestWindowWithDelegateAndType(WindowDelegate* delegate, const gfx::Rect& bounds, Window* parent, bool show_on_creation) { - Window* window = new Window(delegate, type, g_env); + Window* window = new Window(delegate, type, GetEnvForTestWindows()); window->set_id(id); window->Init(ui::LAYER_TEXTURED); window->SetProperty(aura::client::kResizeBehaviorKey, diff --git a/ui/aura/test/test_windows.h b/ui/aura/test/test_windows.h index 6379ff12b49be3..af3434a4569895 100644 --- a/ui/aura/test/test_windows.h +++ b/ui/aura/test/test_windows.h @@ -21,6 +21,7 @@ namespace test { // Sets the Env to use for creation of new Windows. If null, Env::GetInstance() // is used. void SetEnvForTestWindows(Env* env); +Env* GetEnvForTestWindows(); Window* CreateTestWindowWithId(int id, Window* parent); Window* CreateTestWindowWithBounds(const gfx::Rect& bounds, Window* parent); diff --git a/ui/aura/window.cc b/ui/aura/window.cc index ff65b9e10d4043..fec64faf937064 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -51,6 +51,12 @@ #include "ui/gfx/scoped_canvas.h" namespace aura { +namespace { +#if !defined(NDEBUG) +const char* g_env_arg_required_string = nullptr; +#endif + +} // namespace Window::Window(WindowDelegate* delegate, client::WindowType type, Env* env) : Window(delegate, nullptr, type, env) {} @@ -78,6 +84,10 @@ Window::Window(WindowDelegate* delegate, // notification (such as the workspace code). observers_(base::ObserverListPolicy::EXISTING_ONLY) { SetTargetHandler(delegate_); +#if !defined(NDEBUG) + // NOTE: at the time of adding this this function is only called from ash. + DCHECK(env || !g_env_arg_required_string) << g_env_arg_required_string; +#endif } Window::~Window() { @@ -1150,6 +1160,13 @@ bool Window::RequiresDoubleTapGestureEvents() const { return delegate_ && delegate_->RequiresDoubleTapGestureEvents(); } +#if !defined(NDEBUG) +// static +void Window::SetEnvArgRequired(const char* error_string) { + g_env_arg_required_string = error_string; +} +#endif + void Window::OnPaintLayer(const ui::PaintContext& context) { Paint(context); } diff --git a/ui/aura/window.h b/ui/aura/window.h index b042268a757dd7..7873991d9aead2 100644 --- a/ui/aura/window.h +++ b/ui/aura/window.h @@ -428,6 +428,13 @@ class AURA_EXPORT Window : public ui::LayerDelegate, Env* env() { return env_; } const Env* env() const { return env_; } +#if !defined(NDEBUG) + // If passed a non-null value then a non-null aura::Env must be supplied to + // the constructor. |error_string| is the string supplied to the DCHECK + // calls. + static void SetEnvArgRequired(const char* error_string); +#endif + // ui::GestureConsumer: bool RequiresDoubleTapGestureEvents() const override; diff --git a/ui/aura/window_tree_host_platform.cc b/ui/aura/window_tree_host_platform.cc index 75eb9f58f70d8f..76865a51750d74 100644 --- a/ui/aura/window_tree_host_platform.cc +++ b/ui/aura/window_tree_host_platform.cc @@ -10,6 +10,7 @@ #include "base/run_loop.h" #include "base/trace_event/trace_event.h" #include "build/build_config.h" +#include "ui/aura/env.h" #include "ui/aura/window.h" #include "ui/aura/window_event_dispatcher.h" #include "ui/base/layout.h" @@ -42,7 +43,10 @@ namespace aura { // static std::unique_ptr WindowTreeHost::Create( ui::PlatformWindowInitProperties properties) { - return std::make_unique(std::move(properties)); + return std::make_unique( + std::move(properties), + std::make_unique(nullptr, client::WINDOW_TYPE_UNKNOWN, + Env::GetInstance())); } WindowTreeHostPlatform::WindowTreeHostPlatform( diff --git a/ui/base/ui_base_features.cc b/ui/base/ui_base_features.cc index c7b47212726f75..f97011e3955397 100644 --- a/ui/base/ui_base_features.cc +++ b/ui/base/ui_base_features.cc @@ -129,10 +129,17 @@ const base::Feature kDirectManipulationStylus = { const base::Feature kMash = {"Mash", base::FEATURE_DISABLED_BY_DEFAULT}; +const base::Feature kSingleProcessMash = {"SingleProcessMash", + base::FEATURE_DISABLED_BY_DEFAULT}; + bool IsAshInBrowserProcess() { return !base::FeatureList::IsEnabled(features::kMash); } +bool IsSingleProcessMash() { + return base::FeatureList::IsEnabled(features::kSingleProcessMash); +} + #if defined(OS_MACOSX) // When enabled, the NSWindows for apps will be created in the app's process, // and will forward input to the browser process. diff --git a/ui/base/ui_base_features.h b/ui/base/ui_base_features.h index b377efb288d4d7..ec684017b52598 100644 --- a/ui/base/ui_base_features.h +++ b/ui/base/ui_base_features.h @@ -50,10 +50,19 @@ UI_BASE_EXPORT extern const base::Feature kDirectManipulationStylus; // TODO(jamescook): Make flag only available in Chrome OS. UI_BASE_EXPORT extern const base::Feature kMash; +UI_BASE_EXPORT extern const base::Feature kSingleProcessMash; + // Returns true if ash is in process (the default). A value of false means ash // is running in a separate process (and is hosting the UI Service and Viz). UI_BASE_EXPORT bool IsAshInBrowserProcess(); +// Returns true if code outside of ash is using the WindowService. In this mode +// there are two aura::Envs. Ash uses one with Env::Mode::LOCAL. Non-ash code +// uses an aura::Env with a mode of MUS. The non-ash code using mus targets the +// WindowService that ash is running. This exercises the WindowService mojo APIs +// similar to kMash, but leaves ash and browser running in the same process. +UI_BASE_EXPORT bool IsSingleProcessMash(); + #if defined(OS_MACOSX) // Returns true if the NSWindows for apps will be created in the app's process, // and will forward input to the browser process.