diff --git a/BUILD.gn b/BUILD.gn index 932a881e1a9cd9..75b942f91db348 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -439,7 +439,6 @@ group("gn_all") { if (is_chromeos) { deps += [ - "//ash:ash_shell_with_content", "//ash:ash_unittests", "//ash/app_list:app_list_demo", "//ash/app_list:app_list_unittests", diff --git a/ash/BUILD.gn b/ash/BUILD.gn index 9fe6cc5ac6dd4f..d0fa89669670a2 100644 --- a/ash/BUILD.gn +++ b/ash/BUILD.gn @@ -1686,125 +1686,6 @@ component("ash") { } } -static_library("ash_shell_lib") { - testonly = true - sources = [ - "../ui/views/test/test_views_delegate_aura.cc", - "shell/bubble.cc", - "shell/example_app_list_client.cc", - "shell/example_app_list_client.h", - "shell/example_factory.h", - "shell/example_session_controller_client.cc", - "shell/example_session_controller_client.h", - "shell/lock_view.cc", - "shell/shell_delegate_impl.cc", - "shell/shell_delegate_impl.h", - "shell/shell_views_delegate.cc", - "shell/shell_views_delegate.h", - "shell/toplevel_window.cc", - "shell/toplevel_window.h", - "shell/widgets.cc", - "shell/window_type_launcher.cc", - "shell/window_type_launcher.h", - "shell/window_watcher.cc", - "shell/window_watcher.h", - "shell/window_watcher_shelf_item_delegate.cc", - "shell/window_watcher_shelf_item_delegate.h", - ] - - # Usage of content should be in ash_shell_lib_with_content. - assert_no_deps = [ - "//ash/public/cpp/external_arc", - "//components/arc", - "//components/exo", - "//content/public/browser", - "//content/public/common", - ] - - deps = [ - ":ash", - ":test_support", - "//ash/app_list", - "//ash/public/cpp", - "//base", - "//base:i18n", - "//components/user_manager", - "//skia", - "//ui/aura", - "//ui/base", - "//ui/gfx", - "//ui/gfx/geometry", - "//ui/message_center", - "//ui/views", - "//ui/views:test_support", - "//ui/views/examples:views_examples_lib", - "//ui/wm", - ] -} - -static_library("ash_shell_lib_with_content") { - testonly = true - sources = [ - "shell/content/client/shell_browser_main_parts.cc", - "shell/content/client/shell_browser_main_parts.h", - "shell/content/client/shell_content_browser_client.cc", - "shell/content/client/shell_content_browser_client.h", - "shell/content/client/shell_main_delegate.cc", - "shell/content/client/shell_main_delegate.h", - "shell/content/client/shell_new_window_delegate.cc", - "shell/content/client/shell_new_window_delegate.h", - "shell/content/embedded_browser.cc", - "shell/content/embedded_browser.h", - ] - - deps = [ - ":test_support", - "//ash/public/cpp", - "//ash/shortcut_viewer", - "//base:i18n", - "//chrome:packed_resources", - - # TODO(https://crbug.com/644336): Make CrasAudioHandler Chrome or Ash only. - "//chromeos/audio", - "//chromeos/constants", - "//chromeos/dbus/biod", - "//chromeos/dbus/power", - "//chromeos/dbus/shill", - "//chromeos/network", - "//chromeos/services/network_config", - "//chromeos/services/network_config/public/mojom", - "//chromeos/system", - "//components/discardable_memory/public/mojom", - "//components/services/font:lib", - "//components/services/font/public/mojom", - "//content", - "//content/shell:content_shell_lib", - "//device/bluetooth", - "//net", - "//services/device/public/mojom", - "//skia", - "//ui/aura", - "//ui/base", - "//ui/base/ime/chromeos", - "//ui/base/ime/init", - "//ui/chromeos/events", - "//ui/compositor", - "//ui/display", - "//ui/events/devices", - "//ui/message_center", - "//ui/views:test_support", - "//ui/views/controls/webview", - "//ui/views/examples:views_examples_with_content_lib", - "//ui/wm", - ] - public_deps = [ ":ash_shell_lib" ] - data_deps = [ - "//ash/resources:ash_test_resources_200_percent", - "//ash/resources:ash_test_resources_with_content_100_percent", - "//ash/strings:ash_test_strings", - ] -} - action("dbus_service_files") { sources = [ "dbus/org.chromium.DisplayService.conf", @@ -2369,53 +2250,6 @@ test("ash_perftests") { ] } -test("ash_ui_perftests") { - defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ] - - sources = [ - "perftests/overview_animations_preftest.cc", - "shell/content/test/ash_content_perf_test_launcher.cc", - "shell/content/test/ash_content_test.cc", - "shell/content/test/ash_content_test.h", - ] - - deps = [ - ":ash_shell_lib_with_content", - ":test_support", - "//ash/public/cpp", - "//base/test:test_support", - "//cc/base", - "//chromeos/constants:constants", - "//content/shell:content_shell_app", - "//content/shell:content_shell_lib", - "//content/test:browsertest_support", - "//content/test:test_support", - "//mojo/core/embedder", - "//testing/gtest", - "//testing/perf", - "//ui/aura", - "//ui/base", - "//ui/base:test_support", - "//ui/compositor:test_support", - "//ui/events:test_support", - "//ui/gl:test_support", - ] -} - -executable("ash_shell_with_content") { - testonly = true - sources = [ "shell/content/shell_with_content_main.cc" ] - - deps = [ - ":ash_shell_lib_with_content", - "//base", - "//components/user_manager", - "//content", - "//content/public/app", - "//device/bluetooth", - ] -} - static_library("test_support") { testonly = true friend = [ @@ -2499,8 +2333,6 @@ static_library("test_support") { "shelf/shelf_view_test_api.h", "shelf/test/widget_animation_waiter.cc", "shelf/test/widget_animation_waiter.h", - "shell/toplevel_window.cc", - "shell/toplevel_window.h", "shell_test_api.cc", "system/message_center/test_notifier_settings_controller.cc", "system/message_center/test_notifier_settings_controller.h", @@ -2527,6 +2359,8 @@ static_library("test_support") { "test/ash_test_views_delegate.h", "test/fake_android_intent_helper.cc", "test/fake_android_intent_helper.h", + "test/toplevel_window.cc", + "test/toplevel_window.h", "test/ui_controls_factory_ash.cc", "test/ui_controls_factory_ash.h", "test_media_client.cc", diff --git a/ash/perftests/overview_animations_preftest.cc b/ash/perftests/overview_animations_preftest.cc deleted file mode 100644 index 6872469ce3f80e..00000000000000 --- a/ash/perftests/overview_animations_preftest.cc +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2019 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/public/cpp/test/shell_test_api.h" -#include "ash/shell/content/test/ash_content_test.h" -#include "base/macros.h" -#include "base/run_loop.h" -#include "base/system/sys_info.h" -#include "base/threading/thread_task_runner_handle.h" -#include "ui/base/test/ui_controls.h" - -// Test overview enter/exit animations with following conditions -// int: number of windows : 2, 8 -// bool: the window type (browser window with content, or non browser window) -// bool: tablet mode, if true. -// TODO(oshima): Add Tablet/SplitView mode. -class OverviewAnimationsTest - : public AshContentTest, - public testing::WithParamInterface<::testing::tuple> { - public: - OverviewAnimationsTest() = default; - ~OverviewAnimationsTest() override = default; - - // AshContentTest: - void SetUpOnMainThread() override { - AshContentTest::SetUpOnMainThread(); - - int n_browsers = std::get<0>(GetParam()); - bool browser = std::get<1>(GetParam()); - tablet_mode_ = std::get<2>(GetParam()); - - if (tablet_mode_) - ash::ShellTestApi().SetTabletModeEnabledForTest(true); - - const GURL google_url("https://www.google.com"); - - for (int i = 0; i < n_browsers; ++i) { - auto* window = browser ? CreateBrowserWindow(google_url) - : CreateBrowserWindow(GURL()); - if (!window_) - window_ = window; - } - - float cost_per_browser = browser ? 0.5 : 0.1; - int wait_seconds = (base::SysInfo::IsRunningOnChromeOS() ? 5 : 0) + - n_browsers * cost_per_browser; - base::RunLoop run_loop; - base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( - FROM_HERE, run_loop.QuitClosure(), - base::TimeDelta::FromSeconds(wait_seconds)); - run_loop.Run(); - } - - // UIPerformanceTest: - std::vector GetUMAHistogramNames() const override { - if (tablet_mode_) { - return {"Ash.Overview.AnimationSmoothness.Enter.TabletMode", - "Ash.Overview.AnimationSmoothness.Exit.TabletMode"}; - } - return {"Ash.Overview.AnimationSmoothness.Enter.ClamshellMode", - "Ash.Overview.AnimationSmoothness.Exit.ClamshellMode"}; - } - - aura::Window* window() { return window_; } - - private: - aura::Window* window_ = nullptr; - bool tablet_mode_ = false; - DISALLOW_COPY_AND_ASSIGN(OverviewAnimationsTest); -}; - -ASH_CONTENT_TEST_P(OverviewAnimationsTest, EnterExit) { - TRACE_EVENT_NESTABLE_ASYNC_BEGIN0("ui", "Interaction.ui_Overview", this); - // Browser window is used just to identify display. - ui_controls::SendKeyPress(window(), ui::VKEY_MEDIA_LAUNCH_APP1, - /*control=*/false, - /*shift=*/false, - /*alt=*/false, - /*command=*/false); - ash::ShellTestApi().WaitForOverviewAnimationState( - ash::OverviewAnimationState::kEnterAnimationComplete); - // TODO(oshima): Wait until frame animation ends. - ui_controls::SendKeyPress(window(), ui::VKEY_MEDIA_LAUNCH_APP1, - /*control=*/false, - /*shift=*/false, - /*alt=*/false, - /*command=*/false); - ash::ShellTestApi().WaitForOverviewAnimationState( - ash::OverviewAnimationState::kExitAnimationComplete); - TRACE_EVENT_NESTABLE_ASYNC_END0("ui", "Interaction.ui_Overview", this); -} - -INSTANTIATE_TEST_SUITE_P(All, - OverviewAnimationsTest, - ::testing::Combine(::testing::Values(2, 8), - /*blank=*/testing::Bool(), - /*tablet=*/testing::Bool())); diff --git a/ash/shell/DEPS b/ash/shell/DEPS deleted file mode 100644 index 2e87ae565b8348..00000000000000 --- a/ash/shell/DEPS +++ /dev/null @@ -1,6 +0,0 @@ -include_rules = [ - "+content/public", - "+content/shell", - "+gin", - "+sandbox", -] diff --git a/ash/shell/OWNERS b/ash/shell/OWNERS deleted file mode 100644 index c8dc16e2ce8b39..00000000000000 --- a/ash/shell/OWNERS +++ /dev/null @@ -1 +0,0 @@ -per-file *app_list*=xiyuan@chromium.org diff --git a/ash/shell/bubble.cc b/ash/shell/bubble.cc deleted file mode 100644 index 5d44e5ea8d9dcd..00000000000000 --- a/ash/shell/bubble.cc +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2011 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 "base/strings/utf_string_conversions.h" -#include "ui/views/bubble/bubble_border.h" -#include "ui/views/bubble/bubble_dialog_delegate_view.h" -#include "ui/views/controls/label.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/widget/widget.h" - -namespace ash { -namespace shell { - -struct BubbleConfig { - base::string16 label; - views::View* anchor_view; - views::BubbleBorder::Arrow arrow; -}; - -class ExampleBubbleDialogDelegateView : public views::BubbleDialogDelegateView { - public: - explicit ExampleBubbleDialogDelegateView(const BubbleConfig& config); - ~ExampleBubbleDialogDelegateView() override; - - void Init() override { - SetLayoutManager(std::make_unique()); - views::Label* label = new views::Label(label_); - AddChildView(label); - } - - private: - base::string16 label_; -}; - -ExampleBubbleDialogDelegateView::ExampleBubbleDialogDelegateView( - const BubbleConfig& config) - : BubbleDialogDelegateView(config.anchor_view, config.arrow), - label_(config.label) {} - -ExampleBubbleDialogDelegateView::~ExampleBubbleDialogDelegateView() = default; - -void CreatePointyBubble(views::View* anchor_view) { - BubbleConfig config; - config.label = base::ASCIIToUTF16("Pointy Dialog Bubble"); - config.anchor_view = anchor_view; - config.arrow = views::BubbleBorder::TOP_LEFT; - ExampleBubbleDialogDelegateView* bubble = - new ExampleBubbleDialogDelegateView(config); - views::BubbleDialogDelegateView::CreateBubble(bubble)->Show(); -} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/content/client/DEPS b/ash/shell/content/client/DEPS deleted file mode 100644 index fe45514d6ca2fe..00000000000000 --- a/ash/shell/content/client/DEPS +++ /dev/null @@ -1,10 +0,0 @@ -include_rules = [ - "+ash/components/shortcut_viewer", - "+chromeos/dbus/biod", - "+chromeos/services/network_config", - "+components/discardable_memory/public/interfaces", - "+content/public", - "+content/shell", - "+storage/browser/quota", - "+services/device/public", -] diff --git a/ash/shell/content/client/shell_browser_main_parts.cc b/ash/shell/content/client/shell_browser_main_parts.cc deleted file mode 100644 index a1da34355f6007..00000000000000 --- a/ash/shell/content/client/shell_browser_main_parts.cc +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (c) 2012 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/shell/content/client/shell_browser_main_parts.h" - -#include -#include - -#include "ash/display/privacy_screen_controller.h" -#include "ash/login_status.h" -#include "ash/public/cpp/event_rewriter_controller.h" -#include "ash/session/test_pref_service_provider.h" -#include "ash/shell.h" -#include "ash/shell/content/client/shell_new_window_delegate.h" -#include "ash/shell/content/embedded_browser.h" -#include "ash/shell/example_app_list_client.h" -#include "ash/shell/example_session_controller_client.h" -#include "ash/shell/shell_delegate_impl.h" -#include "ash/shell/shell_views_delegate.h" -#include "ash/shell/window_type_launcher.h" -#include "ash/shell/window_watcher.h" -#include "ash/sticky_keys/sticky_keys_controller.h" -#include "ash/test/ash_test_helper.h" -#include "base/bind.h" -#include "base/command_line.h" -#include "base/run_loop.h" -#include "chromeos/dbus/biod/biod_client.h" -#include "chromeos/dbus/shill/shill_clients.h" -#include "chromeos/network/network_handler.h" -#include "components/exo/file_helper.h" -#include "content/public/browser/context_factory.h" -#include "content/public/common/content_switches.h" -#include "content/shell/browser/shell_browser_context.h" -#include "net/base/net_module.h" -#include "ui/base/ui_base_features.h" -#include "ui/chromeos/events/event_rewriter_chromeos.h" -#include "ui/views/examples/examples_window_with_content.h" - -namespace ash { -namespace shell { -namespace { -ShellBrowserMainParts* main_parts = nullptr; -} - -// static -content::BrowserContext* ShellBrowserMainParts::GetBrowserContext() { - DCHECK(main_parts); - return main_parts->browser_context(); -} - -ShellBrowserMainParts::ShellBrowserMainParts( - const content::MainFunctionParams& parameters) - : parameters_(parameters) { - DCHECK(!main_parts); - main_parts = this; -} - -ShellBrowserMainParts::~ShellBrowserMainParts() { - DCHECK(main_parts); - main_parts = nullptr; -} - -void ShellBrowserMainParts::PostEarlyInitialization() { - content::BrowserMainParts::PostEarlyInitialization(); - chromeos::shill_clients::InitializeFakes(); - chromeos::NetworkHandler::Initialize(); -} - -void ShellBrowserMainParts::PreMainMessageLoopStart() {} - -void ShellBrowserMainParts::PostMainMessageLoopStart() { - chromeos::BiodClient::InitializeFake(); -} - -void ShellBrowserMainParts::ToolkitInitialized() { - // A ViewsDelegate is required. - views_delegate_ = std::make_unique(); -} - -void ShellBrowserMainParts::PreMainMessageLoopRun() { - browser_context_.reset(new content::ShellBrowserContext(false)); - - if (!parameters_.ui_task) - new_window_delegate_ = std::make_unique(); - - // TODO(oshima): Separate the class for ash_shell to reduce the test binary - // size. - ash_test_helper_ = std::make_unique( - parameters_.ui_task ? AshTestHelper::kPerfTest : AshTestHelper::kShell, - content::GetContextFactory()); - AshTestHelper::InitParams init_params; - init_params.delegate = std::make_unique(); - ash_test_helper_->SetUp(std::move(init_params)); - - window_watcher_ = std::make_unique(); - - if (!parameters_.ui_task) { - // Install Rewriter so that function keys are properly re-mapped. - auto* event_rewriter_controller = EventRewriterController::Get(); - bool privacy_screen_supported = false; - if (Shell::Get()->privacy_screen_controller() && - Shell::Get()->privacy_screen_controller()->IsSupported()) { - privacy_screen_supported = true; - } - event_rewriter_controller->AddEventRewriter( - std::make_unique( - nullptr, Shell::Get()->sticky_keys_controller(), - privacy_screen_supported)); - - // Initialize session controller client and create fake user sessions. The - // fake user sessions makes ash into the logged in state. - example_session_controller_client_ = - std::make_unique( - Shell::Get()->session_controller(), - ash_test_helper_->prefs_provider()); - example_session_controller_client_->Initialize(); - - example_app_list_client_ = std::make_unique( - Shell::Get()->app_list_controller()); - - InitWindowTypeLauncher( - base::BindRepeating(views::examples::ShowExamplesWindowWithContent, - base::Passed(base::OnceClosure()), - base::Unretained(browser_context_.get()), nullptr), - base::BindRepeating(base::IgnoreResult(&EmbeddedBrowser::Create), - base::Unretained(browser_context_.get()), - GURL("https://www.google.com"), base::nullopt)); - } -} - -bool ShellBrowserMainParts::MainMessageLoopRun(int* result_code) { - if (parameters_.ui_task) { - std::move(*parameters_.ui_task).Run(); - delete parameters_.ui_task; - } else { - base::RunLoop run_loop; - example_session_controller_client_->set_quit_closure( - run_loop.QuitWhenIdleClosure()); - run_loop.Run(); - } - return true; -} - -void ShellBrowserMainParts::PostMainMessageLoopRun() { - window_watcher_.reset(); - example_app_list_client_.reset(); - example_session_controller_client_.reset(); - - ash_test_helper_.reset(); - - views_delegate_.reset(); - - // The keyboard may have created a WebContents. The WebContents is destroyed - // with the UI, and it needs the BrowserContext to be alive during its - // destruction. So destroy all of the UI elements before destroying the - // browser context. - browser_context_.reset(); -} - -void ShellBrowserMainParts::PostDestroyThreads() { - chromeos::NetworkHandler::Shutdown(); - chromeos::shill_clients::Shutdown(); - content::BrowserMainParts::PostDestroyThreads(); -} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/content/client/shell_browser_main_parts.h b/ash/shell/content/client/shell_browser_main_parts.h deleted file mode 100644 index d1b754f3045e75..00000000000000 --- a/ash/shell/content/client/shell_browser_main_parts.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2012 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_SHELL_CONTENT_CLIENT_SHELL_BROWSER_MAIN_PARTS_H_ -#define ASH_SHELL_CONTENT_CLIENT_SHELL_BROWSER_MAIN_PARTS_H_ - -#include - -#include "base/macros.h" -#include "content/public/browser/browser_main_parts.h" -#include "content/public/common/main_function_params.h" -#include "mojo/public/cpp/system/message_pipe.h" - -namespace content { -class BrowserContext; -struct MainFunctionParams; -} // namespace content - -namespace views { -class ViewsDelegate; -} - -namespace ash { -class AshTestHelper; - -namespace shell { -class ExampleAppListClient; -class ExampleSessionControllerClient; -class ShellNewWindowDelegate; -class WindowWatcher; - -class ShellBrowserMainParts : public content::BrowserMainParts { - public: - static content::BrowserContext* GetBrowserContext(); - - explicit ShellBrowserMainParts(const content::MainFunctionParams& parameters); - ~ShellBrowserMainParts() override; - - // Overridden from content::BrowserMainParts: - void PostEarlyInitialization() override; - void PreMainMessageLoopStart() override; - void PostMainMessageLoopStart() override; - void ToolkitInitialized() override; - void PreMainMessageLoopRun() override; - bool MainMessageLoopRun(int* result_code) override; - void PostMainMessageLoopRun() override; - void PostDestroyThreads() override; - - content::BrowserContext* browser_context() { return browser_context_.get(); } - - private: - std::unique_ptr browser_context_; - std::unique_ptr views_delegate_; - std::unique_ptr window_watcher_; - std::unique_ptr - example_session_controller_client_; - std::unique_ptr example_app_list_client_; - std::unique_ptr ash_test_helper_; - std::unique_ptr new_window_delegate_; - content::MainFunctionParams parameters_; - - DISALLOW_COPY_AND_ASSIGN(ShellBrowserMainParts); -}; - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_CONTENT_CLIENT_SHELL_BROWSER_MAIN_PARTS_H_ diff --git a/ash/shell/content/client/shell_content_browser_client.cc b/ash/shell/content/client/shell_content_browser_client.cc deleted file mode 100644 index 83e5587518efaf..00000000000000 --- a/ash/shell/content/client/shell_content_browser_client.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2012 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/shell/content/client/shell_content_browser_client.h" - -#include -#include - -#include "ash/public/cpp/window_properties.h" -#include "ash/shell.h" -#include "ash/shell/content/client/shell_browser_main_parts.h" -#include "base/base_switches.h" -#include "base/bind.h" -#include "base/command_line.h" -#include "base/no_destructor.h" -#include "base/stl_util.h" -#include "base/strings/utf_string_conversions.h" -#include "content/public/browser/browser_context.h" -#include "content/public/utility/content_utility_client.h" -#include "third_party/skia/include/core/SkBitmap.h" - -namespace ash { -namespace shell { - -ShellContentBrowserClient::ShellContentBrowserClient() = default; - -ShellContentBrowserClient::~ShellContentBrowserClient() = default; - -std::unique_ptr -ShellContentBrowserClient::CreateBrowserMainParts( - const content::MainFunctionParams& parameters) { - return std::make_unique(parameters); -} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/content/client/shell_content_browser_client.h b/ash/shell/content/client/shell_content_browser_client.h deleted file mode 100644 index c7c9feddffcdba..00000000000000 --- a/ash/shell/content/client/shell_content_browser_client.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2012 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_SHELL_CONTENT_CLIENT_SHELL_CONTENT_BROWSER_CLIENT_H_ -#define ASH_SHELL_CONTENT_CLIENT_SHELL_CONTENT_BROWSER_CLIENT_H_ - -#include -#include - -#include "base/compiler_specific.h" -#include "base/macros.h" -#include "content/public/browser/content_browser_client.h" - -namespace ash { -namespace shell { - -class ShellContentBrowserClient : public content::ContentBrowserClient { - public: - ShellContentBrowserClient(); - ~ShellContentBrowserClient() override; - - // Overridden from content::ContentBrowserClient: - std::unique_ptr CreateBrowserMainParts( - const content::MainFunctionParams& parameters) override; - - private: - DISALLOW_COPY_AND_ASSIGN(ShellContentBrowserClient); -}; - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_CONTENT_CLIENT_SHELL_CONTENT_BROWSER_CLIENT_H_ diff --git a/ash/shell/content/client/shell_main_delegate.cc b/ash/shell/content/client/shell_main_delegate.cc deleted file mode 100644 index 1159e3c44b3ffe..00000000000000 --- a/ash/shell/content/client/shell_main_delegate.cc +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2012 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/shell/content/client/shell_main_delegate.h" - -#include "ash/shell/content/client/shell_content_browser_client.h" -#include "base/bind.h" -#include "base/command_line.h" -#include "base/files/file_path.h" -#include "base/path_service.h" -#include "content/public/utility/utility_thread.h" -#include "ui/base/ime/init/input_method_initializer.h" -#include "ui/base/resource/resource_bundle.h" - -namespace ash { -namespace shell { - -ShellMainDelegate::ShellMainDelegate() = default; - -ShellMainDelegate::~ShellMainDelegate() = default; - -void ShellMainDelegate::PreSandboxStartup() { - InitializeResourceBundle(); - ui::InitializeInputMethodForTesting(); -} - -content::ContentClient* ShellMainDelegate::CreateContentClient() { - return &content_client_; -} - -content::ContentBrowserClient* ShellMainDelegate::CreateContentBrowserClient() { - browser_client_.reset(new ShellContentBrowserClient); - return browser_client_.get(); -} - -void ShellMainDelegate::InitializeResourceBundle() { - // Load ash resources and strings; not 'common' (Chrome) resources. - base::FilePath path; - base::PathService::Get(base::DIR_MODULE, &path); - base::FilePath ash_test_strings = - path.Append(FILE_PATH_LITERAL("ash_test_strings.pak")); - - ui::ResourceBundle::InitSharedInstanceWithPakPath(ash_test_strings); - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - if (ui::ResourceBundle::IsScaleFactorSupported(ui::SCALE_FACTOR_100P)) { - base::FilePath ash_test_resources_100 = path.Append( - FILE_PATH_LITERAL("ash_test_resources_with_content_100_percent.pak")); - rb.AddDataPackFromPath(ash_test_resources_100, ui::SCALE_FACTOR_100P); - } - if (ui::ResourceBundle::IsScaleFactorSupported(ui::SCALE_FACTOR_200P)) { - base::FilePath ash_test_resources_200 = - path.Append(FILE_PATH_LITERAL("ash_test_resources_200_percent.pak")); - rb.AddDataPackFromPath(ash_test_resources_200, ui::SCALE_FACTOR_200P); - } -} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/content/client/shell_main_delegate.h b/ash/shell/content/client/shell_main_delegate.h deleted file mode 100644 index 52009252153ab6..00000000000000 --- a/ash/shell/content/client/shell_main_delegate.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2012 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_SHELL_CONTENT_CLIENT_SHELL_MAIN_DELEGATE_H_ -#define ASH_SHELL_CONTENT_CLIENT_SHELL_MAIN_DELEGATE_H_ - -#include - -#include "base/compiler_specific.h" -#include "base/macros.h" -#include "content/public/app/content_main_delegate.h" -#include "content/shell/common/shell_content_client.h" - -namespace ash { -namespace shell { - -class ShellContentBrowserClient; - -class ShellMainDelegate : public content::ContentMainDelegate { - public: - ShellMainDelegate(); - ~ShellMainDelegate() override; - - void PreSandboxStartup() override; - content::ContentClient* CreateContentClient() override; - content::ContentBrowserClient* CreateContentBrowserClient() override; - - private: - void InitializeResourceBundle(); - - std::unique_ptr browser_client_; - content::ShellContentClient content_client_; - - DISALLOW_COPY_AND_ASSIGN(ShellMainDelegate); -}; - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_CONTENT_CLIENT_SHELL_MAIN_DELEGATE_H_ diff --git a/ash/shell/content/client/shell_new_window_delegate.cc b/ash/shell/content/client/shell_new_window_delegate.cc deleted file mode 100644 index c4d9744204c555..00000000000000 --- a/ash/shell/content/client/shell_new_window_delegate.cc +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2019 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/shell/content/client/shell_new_window_delegate.h" - -#include "ash/public/cpp/keyboard_shortcut_viewer.h" -#include "ash/shell/content/client/shell_browser_main_parts.h" -#include "ash/shell/content/embedded_browser.h" - -namespace ash { -namespace shell { - -ShellNewWindowDelegate::ShellNewWindowDelegate() = default; -ShellNewWindowDelegate::~ShellNewWindowDelegate() = default; - -void ShellNewWindowDelegate::NewTab() { - EmbeddedBrowser::Create( - ash::shell::ShellBrowserMainParts::GetBrowserContext(), - GURL("https://www.google.com")); -} - -void ShellNewWindowDelegate::NewTabWithUrl(const GURL& url, - bool from_user_interaction) { - EmbeddedBrowser::Create( - ash::shell::ShellBrowserMainParts::GetBrowserContext(), url); -} - -void ShellNewWindowDelegate::NewWindow(bool incognito) { - EmbeddedBrowser::Create( - ash::shell::ShellBrowserMainParts::GetBrowserContext(), - GURL("https://www.google.com")); -} - -void ShellNewWindowDelegate::OpenFileManager() {} - -void ShellNewWindowDelegate::OpenCrosh() {} - -void ShellNewWindowDelegate::OpenGetHelp() {} - -void ShellNewWindowDelegate::RestoreTab() {} - -void ShellNewWindowDelegate::ShowKeyboardShortcutViewer() { - ash::ToggleKeyboardShortcutViewer(); -} - -void ShellNewWindowDelegate::ShowTaskManager() {} - -void ShellNewWindowDelegate::OpenFeedbackPage(bool from_assistant) {} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/content/client/shell_new_window_delegate.h b/ash/shell/content/client/shell_new_window_delegate.h deleted file mode 100644 index c61a3bee0d27d0..00000000000000 --- a/ash/shell/content/client/shell_new_window_delegate.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2019 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_SHELL_CONTENT_CLIENT_SHELL_NEW_WINDOW_DELEGATE_H_ -#define ASH_SHELL_CONTENT_CLIENT_SHELL_NEW_WINDOW_DELEGATE_H_ - -#include -#include - -#include "ash/public/cpp/new_window_delegate.h" -#include "base/compiler_specific.h" -#include "base/macros.h" -#include "content/public/browser/content_browser_client.h" - -namespace ash { -namespace shell { - -class ShellNewWindowDelegate : public ash::NewWindowDelegate { - public: - ShellNewWindowDelegate(); - ~ShellNewWindowDelegate() override; - - // ash::NewWindowDelegate: - void NewTab() override; - void NewTabWithUrl(const GURL& url, bool from_user_interaction) override; - void NewWindow(bool incognito) override; - void OpenFileManager() override; - void OpenCrosh() override; - void OpenGetHelp() override; - void RestoreTab() override; - void ShowKeyboardShortcutViewer() override; - void ShowTaskManager() override; - void OpenFeedbackPage(bool from_assistant) override; - - private: - DISALLOW_COPY_AND_ASSIGN(ShellNewWindowDelegate); -}; - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_CONTENT_CLIENT_SHELL_NEW_WINDOW_DELEGATE_H_ diff --git a/ash/shell/content/embedded_browser.cc b/ash/shell/content/embedded_browser.cc deleted file mode 100644 index f2bf2e0bba2788..00000000000000 --- a/ash/shell/content/embedded_browser.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2019 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/shell/content/embedded_browser.h" - -#include "ash/public/cpp/app_types.h" -#include "ash/wm/window_state.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/views/controls/webview/webview.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/widget/widget.h" -#include "ui/views/widget/widget_delegate.h" -#include "url/gurl.h" - -namespace ash { -namespace shell { - -namespace { - -class BrowserWidgetDelegateView : public views::WidgetDelegateView { - public: - BrowserWidgetDelegateView(content::BrowserContext* context, const GURL& url) { - SetCanMaximize(true); - SetCanMinimize(true); - SetCanResize(true); - SetTitle(base::ASCIIToUTF16("WebView Browser")); - SetLayoutManager(std::make_unique()); - auto* webview = new views::WebView(context); - AddChildView(webview); - Layout(); - webview->LoadInitialURL(url); - } - ~BrowserWidgetDelegateView() override = default; - - private: - DISALLOW_COPY_AND_ASSIGN(BrowserWidgetDelegateView); -}; - -} // namespace - -EmbeddedBrowser::EmbeddedBrowser(content::BrowserContext* context, - const GURL& url, - const gfx::Rect& bounds) - : widget_(new views::Widget) { - views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); - params.bounds = bounds; - params.delegate = new BrowserWidgetDelegateView(context, url); - widget_->Init(std::move(params)); - WindowState::Get(widget_->GetNativeWindow())->SetWindowPositionManaged(true); - widget_->Show(); -} - -EmbeddedBrowser::~EmbeddedBrowser() = default; - -aura::Window* EmbeddedBrowser::GetWindow() { - return widget_->GetNativeView(); -} - -// static -aura::Window* EmbeddedBrowser::Create(content::BrowserContext* context, - const GURL& url, - base::Optional bounds) { - static const gfx::Rect default_bounds(20, 20, 800, 600); - - // EmbeddedBrowser deletes itself when the widget is closed. - aura::Window* browser_window = - (new EmbeddedBrowser(context, url, bounds ? *bounds : default_bounds)) - ->GetWindow(); - browser_window->SetProperty(aura::client::kAppType, - static_cast(ash::AppType::BROWSER)); - return browser_window; -} - -void EmbeddedBrowser::OnUnembed() { - delete this; -} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/content/embedded_browser.h b/ash/shell/content/embedded_browser.h deleted file mode 100644 index 70ae5336d07fe5..00000000000000 --- a/ash/shell/content/embedded_browser.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2019 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_SHELL_CONTENT_EMBEDDED_BROWSER_H_ -#define ASH_SHELL_CONTENT_EMBEDDED_BROWSER_H_ - -#include - -#include "base/macros.h" -#include "base/optional.h" -#include "ui/gfx/geometry/rect.h" - -class GURL; - -namespace aura { -class Window; -} - -namespace content { -class BrowserContext; -} - -namespace views { -class Widget; -} - -namespace ash { -namespace shell { - -// Exercises ServerRemoteViewHost to embed a content::WebContents. -class EmbeddedBrowser { - public: - aura::Window* GetWindow(); - - // Factory. - static aura::Window* Create(content::BrowserContext* context, - const GURL& url, - base::Optional bounds = base::nullopt); - - private: - EmbeddedBrowser(content::BrowserContext* context, - const GURL& url, - const gfx::Rect& bounds); - ~EmbeddedBrowser(); - - // Callback invoked when the embedding is broken. - void OnUnembed(); - - views::Widget* widget_ = nullptr; - - DISALLOW_COPY_AND_ASSIGN(EmbeddedBrowser); -}; - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_CONTENT_EMBEDDED_BROWSER_H_ diff --git a/ash/shell/content/shell_with_content_main.cc b/ash/shell/content/shell_with_content_main.cc deleted file mode 100644 index ce9ba21ee17306..00000000000000 --- a/ash/shell/content/shell_with_content_main.cc +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2012 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/shell/content/client/shell_main_delegate.h" -#include "base/at_exit.h" -#include "base/command_line.h" -#include "base/files/file_path.h" -#include "base/logging.h" -#include "base/path_service.h" -#include "content/public/app/content_main.h" - -int main(int argc, const char** argv) { - base::CommandLine::Init(argc, argv); - base::AtExitManager exit_manager; - - base::FilePath log_filename; - base::PathService::Get(base::DIR_EXE, &log_filename); - log_filename = log_filename.AppendASCII("ash_shell.log"); - logging::LoggingSettings settings; - settings.logging_dest = logging::LOG_TO_ALL; - settings.log_file_path = log_filename.value().c_str(); - settings.delete_old = logging::DELETE_OLD_LOG_FILE; - logging::InitLogging(settings); - logging::SetLogItems(true /* process_id */, true /* thread_id */, - true /* timestamp */, false /* tick_count */); - ash::shell::ShellMainDelegate delegate; - content::ContentMainParams params(&delegate); - params.argc = argc; - params.argv = argv; - - return content::ContentMain(params); -} diff --git a/ash/shell/content/test/DEPS b/ash/shell/content/test/DEPS deleted file mode 100644 index 99f2c5b114ccaa..00000000000000 --- a/ash/shell/content/test/DEPS +++ /dev/null @@ -1,3 +0,0 @@ -include_rules = [ - "+services/tracing/public/cpp" -] diff --git a/ash/shell/content/test/ash_content_perf_test_launcher.cc b/ash/shell/content/test/ash_content_perf_test_launcher.cc deleted file mode 100644 index 54de03474bb87b..00000000000000 --- a/ash/shell/content/test/ash_content_perf_test_launcher.cc +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2019 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 "content/public/test/test_launcher.h" - -#include "ash/shell/content/client/shell_main_delegate.h" -#include "ash/test/ui_controls_factory_ash.h" -#include "base/base_paths.h" -#include "base/command_line.h" -#include "base/i18n/icu_util.h" -#include "base/macros.h" -#include "base/system/sys_info.h" -#include "base/test/launcher/test_launcher.h" -#include "base/test/test_suite.h" -#include "content/public/common/content_switches.h" -#include "content/public/test/content_test_suite_base.h" -#include "content/shell/app/shell_main_delegate.h" -#include "content/shell/common/shell_switches.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/base/test/ui_controls.h" - -namespace { - -class AshContentTestSuite : public content::ContentTestSuiteBase { - public: - AshContentTestSuite(int argc, char** argv) - : ContentTestSuiteBase(argc, argv) {} - ~AshContentTestSuite() override {} - - protected: - // content::ContentTestSuiteBase: - void Initialize() override { - // Browser tests are expected not to tear-down various globals. - base::TestSuite::DisableCheckForLeakedGlobals(); - ContentTestSuiteBase::Initialize(); - ui_controls::InstallUIControlsAura(ash::test::CreateAshUIControls()); - } - - DISALLOW_COPY_AND_ASSIGN(AshContentTestSuite); -}; - -class AshContentPerfTestLauncherDelegate : public content::TestLauncherDelegate { - public: - AshContentPerfTestLauncherDelegate() {} - ~AshContentPerfTestLauncherDelegate() override {} - - // content::TestLancherDelegate: - int RunTestSuite(int argc, char** argv) override { - return AshContentTestSuite(argc, argv).Run(); - } - std::string GetUserDataDirectoryCommandLineSwitch() override { - return switches::kContentShellDataPath; - } - - protected: - content::ContentMainDelegate* CreateContentMainDelegate() override { - return new ash::shell::ShellMainDelegate(); - } - - private: - DISALLOW_COPY_AND_ASSIGN(AshContentPerfTestLauncherDelegate); -}; - -} // namespace - -int main(int argc, char** argv) { - base::CommandLine::Init(argc, argv); - AshContentPerfTestLauncherDelegate launcher_delegate; - // Perf tests should run all tests sequentially. - return LaunchTests(&launcher_delegate, 1, argc, argv); -} diff --git a/ash/shell/content/test/ash_content_test.cc b/ash/shell/content/test/ash_content_test.cc deleted file mode 100644 index 5a52a7443523e8..00000000000000 --- a/ash/shell/content/test/ash_content_test.cc +++ /dev/null @@ -1,234 +0,0 @@ -// Copyright 2019 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/shell/content/test/ash_content_test.h" - -#include -#include - -#include "ash/public/cpp/shelf_config.h" -#include "ash/shell.h" -#include "ash/shell/content/client/shell_browser_main_parts.h" -#include "ash/shell/content/embedded_browser.h" -#include "ash/shell/window_type_launcher.h" -#include "ash/wm/mru_window_tracker.h" -#include "base/auto_reset.h" -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/command_line.h" -#include "base/feature_list.h" -#include "base/files/file_path.h" -#include "base/files/file_util.h" -#include "base/location.h" -#include "base/macros.h" -#include "base/metrics/histogram_samples.h" -#include "base/metrics/statistics_recorder.h" -#include "base/no_destructor.h" -#include "base/run_loop.h" -#include "base/system/sys_info.h" -#include "base/task/post_task.h" -#include "base/test/test_file_util.h" -#include "base/threading/thread_restrictions.h" -#include "base/trace_event/trace_event.h" -#include "build/build_config.h" -#include "chromeos/constants/chromeos_switches.h" -#include "components/user_manager/user_names.h" -#include "content/public/browser/tracing_controller.h" -#include "content/public/test/browser_test_utils.h" -#include "services/tracing/public/cpp/trace_event_agent.h" -#include "testing/perf/luci_test_result.h" -#include "ui/aura/window_tracker.h" -#include "ui/compositor/compositor_switches.h" -#include "ui/display/display_switches.h" -#include "ui/gl/gl_switches.h" -#include "ui/views/widget/widget.h" - -namespace { - -constexpr char kTraceDir[] = "trace-dir"; -constexpr char kPerfTestPrintUmaMeans[] = "perf-test-print-uma-means"; - -float GetHistogramMean(const std::string& name) { - auto* histogram = base::StatisticsRecorder::FindHistogram(name); - if (!histogram) - return 0; - // Use SnapshotFinalDelta() so that it won't contain the samples before the - // subclass invokes SnapshotDelta() during the test. - auto samples = histogram->SnapshotFinalDelta(); - DCHECK_NE(0, samples->TotalCount()); - return static_cast(samples->sum()) / samples->TotalCount(); -} - -perf_test::LuciTestResult CreateTestResult( - const base::FilePath& trace_file, - const std::vector& tbm_metrics) { - perf_test::LuciTestResult result = - perf_test::LuciTestResult::CreateForGTest(); - result.AddOutputArtifactFile("trace/1.json", trace_file, "application/json"); - for (auto& metric : tbm_metrics) - result.AddTag("tbmv2", metric); - - return result; -} - -} // namespace - -class AshContentTest::Tracer { - public: - Tracer(base::FilePath trace_dir, - std::string tracing_categories, - std::vector histograms, - std::vector tbm_metrics) - : trace_dir_(std::move(trace_dir)), - tracing_categories_(std::move(tracing_categories)), - tbm_metrics_(std::move(tbm_metrics)) { - auto* controller = content::TracingController::GetInstance(); - base::trace_event::TraceConfig config( - tracing_categories_, base::trace_event::RECORD_CONTINUOUSLY); - - for (const auto& histogram : histograms) - config.EnableHistogram(histogram); - - base::RunLoop runloop; - bool result = controller->StartTracing(config, runloop.QuitClosure()); - runloop.Run(); - CHECK(result); - } - - ~Tracer() { - base::ScopedAllowBlockingForTesting allow_io; - CreateTmp(); - - { - base::RunLoop runloop; - auto trace_data_endpoint = content::TracingController::CreateFileEndpoint( - trace_file_, runloop.QuitClosure()); - auto* controller = content::TracingController::GetInstance(); - bool result = controller->StopTracing(trace_data_endpoint); - runloop.Run(); - CHECK(result); - } - - base::FilePath report_file = - trace_file_.AddExtension(FILE_PATH_LITERAL("test_result.json")); - CreateTestResult(trace_file_, tbm_metrics_).WriteToFile(report_file); - } - - void CreateTmp() { - CHECK(base::CreateTemporaryFileInDir(trace_dir_, &trace_file_)); - } - - base::FilePath trace_dir_; - base::FilePath trace_file_; - std::string tracing_categories_; - std::vector tbm_metrics_; -}; - -AshContentTest::AshContentTest() - : enable_trace_( - base::CommandLine::ForCurrentProcess()->HasSwitch(kTraceDir)) { - auto* cmd = base::CommandLine::ForCurrentProcess(); - if (enable_trace_) { - cmd->AppendSwitch(switches::kUseGpuInTests); - cmd->AppendSwitch(switches::kEnablePixelOutputInTests); - } -} - -AshContentTest::~AshContentTest() = default; - -void AshContentTest::SetUp() { - base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - // Add command line arguments that are used by all AshContentTests. - if (!command_line->HasSwitch(switches::kHostWindowBounds) && - !base::SysInfo::IsRunningOnChromeOS()) { - // Adjusting window location & size so that the ash desktop window fits - // inside the Xvfb's default resolution. Only do that when not running - // on device. Otherwise, device display is not properly configured. - command_line->AppendSwitchASCII(switches::kHostWindowBounds, - "0+0-1280x800"); - } - content::ContentBrowserTest::SetUp(); -} - -void AshContentTest::SetUpOnMainThread() { - content::ContentBrowserTest::SetUpOnMainThread(); - if (enable_trace_) { - base::FilePath dir = - base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(kTraceDir); - tracer_ = std::make_unique( - std::move(dir), - std::move( - "benchmark,cc,viz,input,latency,gpu,rail,toplevel,ui,views,viz"), - GetUMAHistogramNames(), GetTimelineBasedMetrics()); - } - gfx::Size display_size = ash::Shell::GetPrimaryRootWindow()->bounds().size(); - test_window_size_.set_height( - (display_size.height() - ash::ShelfConfig::Get()->shelf_size()) * 0.95f); - test_window_size_.set_width(display_size.width() * 0.7f); -} - -void AshContentTest::TearDownOnMainThread() { - tracer_.reset(); - auto* command_line = base::CommandLine::ForCurrentProcess(); - const bool print = command_line->HasSwitch(kPerfTestPrintUmaMeans); - LOG_IF(INFO, print) << "=== Histogram Means ==="; - for (auto name : GetUMAHistogramNames()) { - EXPECT_TRUE(!!base::StatisticsRecorder::FindHistogram(name)) - << " missing histogram:" << name; - LOG_IF(INFO, print) << name << ": " << GetHistogramMean(name); - } - LOG_IF(INFO, print) << "=== End Histogram Means ==="; - - content::ContentBrowserTest::TearDownOnMainThread(); -} - -aura::Window* AshContentTest::CreateBrowserWindow(const GURL& url) { - return ash::shell::EmbeddedBrowser::Create( - ash::shell::ShellBrowserMainParts::GetBrowserContext(), url, - gfx::Rect(test_window_size_)); -} - -aura::Window* AshContentTest::CreateTestWindow() { - views::Widget* widget = views::Widget::CreateWindowWithContext( - new ash::shell::WindowTypeLauncher(base::NullCallback(), - base::NullCallback()), - ash::Shell::GetPrimaryRootWindow(), gfx::Rect(test_window_size_)); - widget->GetNativeView()->SetName("WindowTypeLauncher"); - widget->Show(); - - return widget->GetNativeWindow(); -} - -void AshContentTest::PreRunTestOnMainThread() { - // We're not calling ContentBrowserTest's method because it performs content - // shell initialization. Same in PostRunTestOnMainThread. - - // Pump startup related events. - base::RunLoop().RunUntilIdle(); -} - -void AshContentTest::PostRunTestOnMainThread() { - // Cleanup all application windows. - aura::WindowTracker tracker( - ash::Shell::Get()->mru_window_tracker()->BuildWindowForCycleList( - ash::kAllDesks)); - while (!tracker.windows().empty()) { - auto* widget = views::Widget::GetWidgetForNativeWindow(tracker.Pop()); - widget->Close(); - } - - // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's - // run all pending messages here to avoid preempting the QuitBrowsers tasks. - // TODO(https://crbug.com/922118): Remove this once it is no longer possible - // to post QuitCurrent* tasks. - base::RunLoop().RunUntilIdle(); -} - -std::vector AshContentTest::GetUMAHistogramNames() const { - return {}; -} - -std::vector AshContentTest::GetTimelineBasedMetrics() const { - return {"renderingMetric", "umaMetric"}; -} diff --git a/ash/shell/content/test/ash_content_test.h b/ash/shell/content/test/ash_content_test.h deleted file mode 100644 index 9958806e6edfa1..00000000000000 --- a/ash/shell/content/test/ash_content_test.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2019 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_SHELL_CONTENT_TEST_ASH_CONTENT_TEST_H_ -#define ASH_SHELL_CONTENT_TEST_ASH_CONTENT_TEST_H_ - -#include -#include -#include - -#include "base/macros.h" -#include "content/public/test/content_browser_test.h" - -// A base class for ash test with content. The test will run with multi process -// with gpu/viz process, much closer to real environment than ash_unittests. -class AshContentTest : public content::ContentBrowserTest { - public: - AshContentTest(); - ~AshContentTest() override; - - // contnet::ContentBrowserTest: - void SetUp() override; - void SetUpOnMainThread() override; - void TearDownOnMainThread() override; - void PreRunTestOnMainThread() override; - void PostRunTestOnMainThread() override; - - protected: - aura::Window* CreateBrowserWindow(const GURL& url); - aura::Window* CreateTestWindow(); - - virtual std::vector GetUMAHistogramNames() const; - - // Returns the names of timeline based metrics (TBM) to be extracted from - // the generated trace. The metrics must be defined in telemetry - // third_party/catapult/tracing/tracing/metrics/ - // so that third_party/catapult/tracing/bin/run_metric could handle them. - // Default is "renderingMetric", "umaMetric". - virtual std::vector GetTimelineBasedMetrics() const; - - private: - class Tracer; - - gfx::Size test_window_size_; - bool enable_trace_; - std::unique_ptr tracer_; - - DISALLOW_COPY_AND_ASSIGN(AshContentTest); -}; - -#define ASH_CONTENT_TEST_F(test_fixture, test_name) \ - IN_PROC_BROWSER_TEST_F(test_fixture, test_name) -#define ASH_CONTENT_TEST_P(test_fixture, test_name) \ - IN_PROC_BROWSER_TEST_P(test_fixture, test_name) - -#endif // ASH_SHELL_CONTENT_TEST_ASH_CONTENT_TEST_H_ diff --git a/ash/shell/example_app_list_client.cc b/ash/shell/example_app_list_client.cc deleted file mode 100644 index 8790a14b82f15c..00000000000000 --- a/ash/shell/example_app_list_client.cc +++ /dev/null @@ -1,260 +0,0 @@ -// Copyright (c) 2012 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/shell/example_app_list_client.h" - -#include -#include - -#include "ash/app_list/app_list_controller_impl.h" -#include "ash/app_list/model/app_list_item.h" -#include "ash/app_list/model/search/search_result.h" -#include "ash/session/session_controller_impl.h" -#include "ash/shell.h" -#include "ash/shell/example_factory.h" -#include "ash/shell/toplevel_window.h" -#include "base/bind_helpers.h" -#include "base/i18n/case_conversion.h" -#include "base/i18n/string_search.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/utf_string_conversions.h" -#include "ui/gfx/image/image_skia.h" -#include "ui/views/examples/example_base.h" -#include "ui/views/examples/examples_window.h" - -namespace ash { -namespace shell { - -// WindowTypeShelfItem is an app item of app list. It carries a window -// launch type and launches corresponding example window when activated. -class WindowTypeShelfItem : public AppListItem { - public: - enum Type { - TOPLEVEL_WINDOW = 0, - NON_RESIZABLE_WINDOW, - LOCK_SCREEN, - WIDGETS_WINDOW, - EXAMPLES_WINDOW, - LAST_TYPE, - }; - - WindowTypeShelfItem(const std::string& id, Type type); - ~WindowTypeShelfItem() override; - - static gfx::ImageSkia GetIcon(Type type) { - static const SkColor kColors[] = { - SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN, - }; - - const int kIconSize = 128; - SkBitmap icon; - icon.allocN32Pixels(kIconSize, kIconSize); - icon.eraseColor(kColors[static_cast(type) % base::size(kColors)]); - return gfx::ImageSkia::CreateFrom1xBitmap(icon); - } - - // The text below is not localized as this is an example code. - static std::string GetTitle(Type type) { - switch (type) { - case TOPLEVEL_WINDOW: - return "Create Window"; - case NON_RESIZABLE_WINDOW: - return "Create Non-Resizable Window"; - case LOCK_SCREEN: - return "Lock Screen"; - case WIDGETS_WINDOW: - return "Show Example Widgets"; - case EXAMPLES_WINDOW: - return "Open Views Examples Window"; - default: - return "Unknown window type."; - } - } - - // The text below is not localized as this is an example code. - static std::string GetDetails(Type type) { - // Assigns details only to some types so that we see both one-line - // and two-line results. - switch (type) { - case WIDGETS_WINDOW: - return "Creates a window to show example widgets"; - case EXAMPLES_WINDOW: - return "Creates a window to show views example."; - default: - return std::string(); - } - } - - static void ActivateItem(Type type, int event_flags) { - switch (type) { - case TOPLEVEL_WINDOW: { - ToplevelWindow::CreateParams params; - params.can_resize = true; - ToplevelWindow::CreateToplevelWindow(params); - break; - } - case NON_RESIZABLE_WINDOW: { - ToplevelWindow::CreateToplevelWindow(ToplevelWindow::CreateParams()); - break; - } - case LOCK_SCREEN: { - Shell::Get()->session_controller()->LockScreen(); - break; - } - case WIDGETS_WINDOW: { - CreateWidgetsWindow(); - break; - } - case EXAMPLES_WINDOW: { - views::examples::ShowExamplesWindow(base::DoNothing()); - break; - } - default: - break; - } - } - - Type type() const { return type_; } - - private: - Type type_; - - DISALLOW_COPY_AND_ASSIGN(WindowTypeShelfItem); -}; - -WindowTypeShelfItem::WindowTypeShelfItem(const std::string& id, Type type) - : AppListItem(id), type_(type) { - std::string title(GetTitle(type)); - SetIcon(ash::AppListConfigType::kShared, GetIcon(type)); - SetName(title); -} - -WindowTypeShelfItem::~WindowTypeShelfItem() = default; - -// ExampleSearchResult is an app list search result. It provides what icon to -// show, what should title and details text look like. It also carries the -// matching window launch type so that AppListViewDelegate knows how to open -// it. -class ExampleSearchResult : public SearchResult { - public: - ExampleSearchResult(WindowTypeShelfItem::Type type, - const base::string16& query) - : type_(type) { - SetIcon(WindowTypeShelfItem::GetIcon(type_)); - - base::string16 title = - base::UTF8ToUTF16(WindowTypeShelfItem::GetTitle(type_)); - set_title(title); - - if (query.empty()) { - set_is_recommendation(true); - SetChipIcon(WindowTypeShelfItem::GetIcon(type_)); - } else { - Tags title_tags; - - // Highlight matching parts in title with bold. - // Note the following is not a proper way to handle i18n string. - title = base::i18n::ToLower(title); - const size_t match_len = query.length(); - size_t match_start = title.find(query); - while (match_start != base::string16::npos) { - title_tags.push_back( - Tag(Tag::MATCH, match_start, match_start + match_len)); - match_start = title.find(query, match_start + match_len); - } - set_title_tags(title_tags); - } - - base::string16 details = - base::UTF8ToUTF16(WindowTypeShelfItem::GetDetails(type_)); - set_details(details); - Tags details_tags; - details_tags.push_back(Tag(Tag::DIM, 0, details.length())); - set_details_tags(details_tags); - } - - WindowTypeShelfItem::Type type() const { return type_; } - - private: - WindowTypeShelfItem::Type type_; - - DISALLOW_COPY_AND_ASSIGN(ExampleSearchResult); -}; - -ExampleAppListClient::ExampleAppListClient(AppListControllerImpl* controller) - : controller_(controller) { - controller_->SetClient(this); - - PopulateApps(); -} - -ExampleAppListClient::~ExampleAppListClient() { - controller_->SetClient(nullptr); -} - -void ExampleAppListClient::PopulateApps() { - for (int i = 0; i < static_cast(WindowTypeShelfItem::LAST_TYPE); ++i) { - WindowTypeShelfItem::Type type = static_cast(i); - const std::string id = base::NumberToString(i); - auto app = std::make_unique(id, type); - controller_->AddItem(app->CloneMetadata()); - apps_.emplace_back(std::move(app)); - } -} - -void ExampleAppListClient::StartSearch(const base::string16& trimmed_query) { - base::string16 query; - query = base::i18n::ToLower(trimmed_query); - - search_results_.clear(); - std::vector> result_data; - for (int i = 0; i < static_cast(WindowTypeShelfItem::LAST_TYPE); ++i) { - WindowTypeShelfItem::Type type = static_cast(i); - - const base::string16 title = - base::UTF8ToUTF16(WindowTypeShelfItem::GetTitle(type)); - if (query.empty() || base::i18n::StringSearchIgnoringCaseAndAccents( - query, title, nullptr, nullptr)) { - search_results_.emplace_back( - std::make_unique(type, query)); - result_data.emplace_back(search_results_.back()->CloneMetadata()); - } - } - controller_->PublishSearchResults(std::move(result_data)); -} - -void ExampleAppListClient::OpenSearchResult( - const std::string& result_id, - int event_flags, - ash::AppListLaunchedFrom launched_from, - ash::AppListLaunchType launch_type, - int suggestion_index, - bool launch_as_default) { - auto it = std::find_if( - search_results_.begin(), search_results_.end(), - [&result_id](const std::unique_ptr& result) { - return result->id() == result_id; - }); - if (it == search_results_.end()) - return; - - WindowTypeShelfItem::ActivateItem((*it)->type(), event_flags); -} - -void ExampleAppListClient::ActivateItem(int profile_id, - const std::string& id, - int event_flags) { - auto it = - std::find_if(apps_.begin(), apps_.end(), - [&id](const std::unique_ptr& app) { - return app->id() == id; - }); - if (it == apps_.end()) - return; - - WindowTypeShelfItem::ActivateItem((*it)->type(), event_flags); -} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/example_app_list_client.h b/ash/shell/example_app_list_client.h deleted file mode 100644 index f6800e95e7e820..00000000000000 --- a/ash/shell/example_app_list_client.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2019 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_SHELL_EXAMPLE_APP_LIST_CLIENT_H_ -#define ASH_SHELL_EXAMPLE_APP_LIST_CLIENT_H_ - -#include -#include -#include - -#include "ash/app_list/test/test_app_list_client.h" -#include "base/macros.h" - -namespace ash { - -class AppListControllerImpl; - -namespace shell { - -class WindowTypeShelfItem; -class ExampleSearchResult; - -class ExampleAppListClient : public TestAppListClient { - public: - explicit ExampleAppListClient(AppListControllerImpl* controller); - ~ExampleAppListClient() override; - - private: - void PopulateApps(); - - // TestAppListClient: - void StartSearch(const base::string16& trimmed_query) override; - void OpenSearchResult(const std::string& result_id, - int event_flags, - ash::AppListLaunchedFrom launched_from, - ash::AppListLaunchType launch_type, - int suggestion_index, - bool launch_as_default) override; - void ActivateItem(int profile_id, - const std::string& id, - int event_flags) override; - - AppListControllerImpl* controller_; - - std::vector> apps_; - std::vector> search_results_; - - DISALLOW_COPY_AND_ASSIGN(ExampleAppListClient); -}; - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_EXAMPLE_APP_LIST_CLIENT_H_ diff --git a/ash/shell/example_factory.h b/ash/shell/example_factory.h deleted file mode 100644 index a2e12d50e63c29..00000000000000 --- a/ash/shell/example_factory.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2012 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_SHELL_EXAMPLE_FACTORY_H_ -#define ASH_SHELL_EXAMPLE_FACTORY_H_ - -namespace views { -class View; -} - -namespace ash { -class AppListViewDelegate; - -namespace shell { - -void CreatePointyBubble(views::View* anchor_view); - -void CreateLockScreen(); - -// Creates a window showing samples of commonly used widgets. -void CreateWidgetsWindow(); - -AppListViewDelegate* CreateAppListViewDelegate(); - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_EXAMPLE_FACTORY_H_ diff --git a/ash/shell/example_session_controller_client.cc b/ash/shell/example_session_controller_client.cc deleted file mode 100644 index 0e29e95e010efc..00000000000000 --- a/ash/shell/example_session_controller_client.cc +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2017 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/shell/example_session_controller_client.h" - -#include "ash/shell.h" -#include "ash/shell/example_factory.h" -#include "base/check_op.h" - -namespace ash { -namespace shell { - -namespace { - -ExampleSessionControllerClient* instance = nullptr; - -} // namespace - -ExampleSessionControllerClient::ExampleSessionControllerClient( - SessionControllerImpl* controller, - TestPrefServiceProvider* prefs_provider) - : TestSessionControllerClient(controller, prefs_provider) { - DCHECK_EQ(instance, nullptr); - DCHECK(controller); - instance = this; -} - -ExampleSessionControllerClient::~ExampleSessionControllerClient() { - DCHECK_EQ(instance, this); - instance = nullptr; -} - -// static -ExampleSessionControllerClient* ExampleSessionControllerClient::Get() { - return instance; -} - -void ExampleSessionControllerClient::Initialize() { - // Initialize and bind with the session controller. - InitializeAndSetClient(); - - // ash_shell has 2 users. - CreatePredefinedUserSessions(2); -} - -void ExampleSessionControllerClient::RequestLockScreen() { - TestSessionControllerClient::RequestLockScreen(); - CreateLockScreen(); - Shell::Get()->UpdateShelfVisibility(); -} - -void ExampleSessionControllerClient::UnlockScreen() { - TestSessionControllerClient::UnlockScreen(); - Shell::Get()->UpdateShelfVisibility(); -} - -void ExampleSessionControllerClient::RequestSignOut() { - DCHECK(quit_closure_); - std::move(quit_closure_).Run(); -} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/example_session_controller_client.h b/ash/shell/example_session_controller_client.h deleted file mode 100644 index ef8779f61f8522..00000000000000 --- a/ash/shell/example_session_controller_client.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2017 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_SHELL_EXAMPLE_SESSION_CONTROLLER_CLIENT_H_ -#define ASH_SHELL_EXAMPLE_SESSION_CONTROLLER_CLIENT_H_ - -#include - -#include "ash/session/test_session_controller_client.h" -#include "base/callback.h" -#include "base/macros.h" - -namespace ash { - -class SessionControllerImpl; - -namespace shell { - -class ExampleSessionControllerClient : public TestSessionControllerClient { - public: - ExampleSessionControllerClient(SessionControllerImpl* controller, - TestPrefServiceProvider* prefs_provider); - ~ExampleSessionControllerClient() override; - - static ExampleSessionControllerClient* Get(); - - void Initialize(); - - void set_quit_closure(base::OnceClosure quit_closure) { - quit_closure_ = std::move(quit_closure); - } - - // TestSessionControllerClient - void RequestLockScreen() override; - void UnlockScreen() override; - void RequestSignOut() override; - - private: - base::OnceClosure quit_closure_; - - DISALLOW_COPY_AND_ASSIGN(ExampleSessionControllerClient); -}; - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_EXAMPLE_SESSION_CONTROLLER_CLIENT_H_ diff --git a/ash/shell/lock_view.cc b/ash/shell/lock_view.cc deleted file mode 100644 index 089d822a814d38..00000000000000 --- a/ash/shell/lock_view.cc +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright (c) 2012 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/public/cpp/shell_window_ids.h" -#include "ash/session/session_controller_impl.h" -#include "ash/shell.h" -#include "ash/shell/example_factory.h" -#include "ash/shell/example_session_controller_client.h" -#include "base/strings/utf_string_conversions.h" -#include "ui/aura/window.h" -#include "ui/aura/window_event_dispatcher.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/font_list.h" -#include "ui/gfx/geometry/rect.h" -#include "ui/gfx/text_utils.h" -#include "ui/views/controls/button/md_text_button.h" -#include "ui/views/controls/label.h" -#include "ui/views/corewm/tooltip_controller.h" -#include "ui/views/widget/widget.h" -#include "ui/views/widget/widget_delegate.h" - -namespace ash { -namespace shell { - -class LockView : public views::WidgetDelegateView, - public views::ButtonListener { - public: - LockView() : text_(new views::Label(base::ASCIIToUTF16("LOCKED!"))) { - text_->SetEnabledColor(SK_ColorRED); - AddChildView(text_); - unlock_button_ = AddChildView( - views::MdTextButton::Create(this, base::ASCIIToUTF16("Unlock"))); - } - ~LockView() override = default; - - // Overridden from views::View: - gfx::Size CalculatePreferredSize() const override { - return gfx::Size(500, 400); - } - - private: - // Overridden from views::View: - void OnPaint(gfx::Canvas* canvas) override { - canvas->FillRect(GetLocalBounds(), SK_ColorYELLOW); - } - - void Layout() override { - gfx::Rect bounds = GetLocalBounds(); - gfx::Size ts = text_->GetPreferredSize(); - text_->SetBoundsRect(gfx::Rect((bounds.width() - ts.width()) / 2, - (bounds.height() - ts.height()) / 2, - ts.width(), ts.height())); - - gfx::Size ps = unlock_button_->GetPreferredSize(); - bounds.set_y(bounds.bottom() - ps.height() - 5); - bounds.set_x((bounds.width() - ps.width()) / 2); - bounds.set_size(ps); - unlock_button_->SetBoundsRect(bounds); - } - - void ViewHierarchyChanged( - const views::ViewHierarchyChangedDetails& details) override { - if (details.is_add && details.child == this) - unlock_button_->RequestFocus(); - } - - // Overridden from views::WidgetDelegateView: - void WindowClosing() override { - ExampleSessionControllerClient::Get()->UnlockScreen(); - } - - // Overridden from views::ButtonListener: - void ButtonPressed(views::Button* sender, const ui::Event& event) override { - DCHECK(sender == unlock_button_); - GetWidget()->Close(); - } - - views::Label* text_; - views::Button* unlock_button_; - - DISALLOW_COPY_AND_ASSIGN(LockView); -}; - -void CreateLockScreen() { - LockView* lock_view = new LockView; - views::Widget* widget = new views::Widget; - views::Widget::InitParams params( - views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); - gfx::Size ps = lock_view->GetPreferredSize(); - - gfx::Size root_window_size = Shell::GetPrimaryRootWindow()->bounds().size(); - params.bounds = gfx::Rect((root_window_size.width() - ps.width()) / 2, - (root_window_size.height() - ps.height()) / 2, - ps.width(), ps.height()); - params.delegate = lock_view; - params.parent = Shell::GetContainer(Shell::GetPrimaryRootWindow(), - kShellWindowId_LockScreenContainer); - widget->Init(std::move(params)); - widget->Show(); - widget->GetNativeView()->SetName("LockView"); - widget->GetNativeView()->Focus(); - - // TODO: it shouldn't be necessary to invoke UpdateTooltip() here. - Shell::Get()->tooltip_controller()->UpdateTooltip(widget->GetNativeView()); -} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/shell_delegate_impl.cc b/ash/shell/shell_delegate_impl.cc deleted file mode 100644 index ba554f87ed47d9..00000000000000 --- a/ash/shell/shell_delegate_impl.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2012 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/shell/shell_delegate_impl.h" - -#include - -#include "ash/accessibility/default_accessibility_delegate.h" -#include "ash/test_screenshot_delegate.h" -#include "ash/wm/gestures/back_gesture/test_back_gesture_contextual_nudge_delegate.h" - -namespace ash { -namespace shell { - -ShellDelegateImpl::ShellDelegateImpl() = default; - -ShellDelegateImpl::~ShellDelegateImpl() = default; - -bool ShellDelegateImpl::CanShowWindowForUser(const aura::Window* window) const { - return true; -} - -std::unique_ptr -ShellDelegateImpl::CreateScreenshotDelegate() { - return std::make_unique(); -} - -AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() { - return new DefaultAccessibilityDelegate; -} - -std::unique_ptr -ShellDelegateImpl::CreateBackGestureContextualNudgeDelegate( - BackGestureContextualNudgeController* controller) { - return std::make_unique(controller); -} - -bool ShellDelegateImpl::CanGoBack(gfx::NativeWindow window) const { - return true; -} - -void ShellDelegateImpl::BindNavigableContentsFactory( - mojo::PendingReceiver receiver) {} - -void ShellDelegateImpl::BindMultiDeviceSetup( - mojo::PendingReceiver - receiver) {} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/shell_delegate_impl.h b/ash/shell/shell_delegate_impl.h deleted file mode 100644 index 6c6a043a61b0b9..00000000000000 --- a/ash/shell/shell_delegate_impl.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2012 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_SHELL_SHELL_DELEGATE_IMPL_H_ -#define ASH_SHELL_SHELL_DELEGATE_IMPL_H_ - -#include -#include - -#include "ash/shell_delegate.h" -#include "base/macros.h" - -namespace ash { -namespace shell { - -class ShellDelegateImpl : public ShellDelegate { - public: - ShellDelegateImpl(); - ~ShellDelegateImpl() override; - - // ShellDelegate: - bool CanShowWindowForUser(const aura::Window* window) const override; - std::unique_ptr CreateScreenshotDelegate() override; - AccessibilityDelegate* CreateAccessibilityDelegate() override; - std::unique_ptr - CreateBackGestureContextualNudgeDelegate( - BackGestureContextualNudgeController* controller) override; - bool CanGoBack(gfx::NativeWindow window) const override; - void BindNavigableContentsFactory( - mojo::PendingReceiver receiver) - override; - void BindMultiDeviceSetup( - mojo::PendingReceiver< - chromeos::multidevice_setup::mojom::MultiDeviceSetup> receiver) - override; - - private: - DISALLOW_COPY_AND_ASSIGN(ShellDelegateImpl); -}; - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_SHELL_DELEGATE_IMPL_H_ diff --git a/ash/shell/shell_views_delegate.cc b/ash/shell/shell_views_delegate.cc deleted file mode 100644 index 84011863b6bc7d..00000000000000 --- a/ash/shell/shell_views_delegate.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2017 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/shell/shell_views_delegate.h" - -#include "ash/shell.h" - -namespace ash { -namespace shell { - -ShellViewsDelegate::ShellViewsDelegate() = default; - -ShellViewsDelegate::~ShellViewsDelegate() = default; - -std::unique_ptr -ShellViewsDelegate::CreateDefaultNonClientFrameView(views::Widget* widget) { - return ash::Shell::Get()->CreateDefaultNonClientFrameView(widget); -} - -void ShellViewsDelegate::OnBeforeWidgetInit( - views::Widget::InitParams* params, - views::internal::NativeWidgetDelegate* delegate) { - if (params->opacity == views::Widget::InitParams::WindowOpacity::kInferred) - params->opacity = views::Widget::InitParams::WindowOpacity::kTranslucent; - - if (params->native_widget) - return; - - if (!params->parent && !params->context && !params->child) - params->context = Shell::GetPrimaryRootWindow(); -} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/shell_views_delegate.h b/ash/shell/shell_views_delegate.h deleted file mode 100644 index 69ec21bab608e1..00000000000000 --- a/ash/shell/shell_views_delegate.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2017 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_SHELL_SHELL_VIEWS_DELEGATE_H_ -#define ASH_SHELL_SHELL_VIEWS_DELEGATE_H_ - -#include "ui/views/test/test_views_delegate.h" - -namespace ash { -namespace shell { - -class ShellViewsDelegate : public views::TestViewsDelegate { - public: - ShellViewsDelegate(); - ~ShellViewsDelegate() override; - - // views::TestViewsDelegate: - std::unique_ptr CreateDefaultNonClientFrameView( - views::Widget* widget) override; - void OnBeforeWidgetInit( - views::Widget::InitParams* params, - views::internal::NativeWidgetDelegate* delegate) override; - - private: - DISALLOW_COPY_AND_ASSIGN(ShellViewsDelegate); -}; - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_SHELL_VIEWS_DELEGATE_H_ diff --git a/ash/shell/widgets.cc b/ash/shell/widgets.cc deleted file mode 100644 index 2b486c4cb9eff7..00000000000000 --- a/ash/shell/widgets.cc +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (c) 2012 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/shell.h" -#include "base/strings/utf_string_conversions.h" -#include "ui/aura/window.h" -#include "ui/aura/window_event_dispatcher.h" -#include "ui/gfx/canvas.h" -#include "ui/views/controls/button/checkbox.h" -#include "ui/views/controls/button/md_text_button.h" -#include "ui/views/controls/button/radio_button.h" -#include "ui/views/widget/widget.h" -#include "ui/views/widget/widget_delegate.h" - -namespace { - -// Default window position. -const int kWindowLeft = 170; -const int kWindowTop = 200; - -// Default window size. -const int kWindowWidth = 400; -const int kWindowHeight = 400; - -// A window showing samples of commonly used widgets. -class WidgetsWindow : public views::WidgetDelegateView { - public: - WidgetsWindow(); - ~WidgetsWindow() override; - - // Overridden from views::View: - void OnPaint(gfx::Canvas* canvas) override; - void Layout() override; - gfx::Size CalculatePreferredSize() const override; - - // Overridden from views::WidgetDelegate: - bool CanResize() const override; - - private: - views::LabelButton* button_; - views::LabelButton* disabled_button_; - views::Checkbox* checkbox_; - views::Checkbox* checkbox_disabled_; - views::Checkbox* checkbox_checked_; - views::Checkbox* checkbox_checked_disabled_; - views::RadioButton* radio_button_; - views::RadioButton* radio_button_disabled_; - views::RadioButton* radio_button_selected_; - views::RadioButton* radio_button_selected_disabled_; -}; - -WidgetsWindow::WidgetsWindow() - : checkbox_(new views::Checkbox(base::ASCIIToUTF16("Checkbox"))), - checkbox_disabled_( - new views::Checkbox(base::ASCIIToUTF16("Checkbox disabled"))), - checkbox_checked_( - new views::Checkbox(base::ASCIIToUTF16("Checkbox checked"))), - checkbox_checked_disabled_( - new views::Checkbox(base::ASCIIToUTF16("Checkbox checked disabled"))), - radio_button_( - new views::RadioButton(base::ASCIIToUTF16("Radio button"), 0)), - radio_button_disabled_( - new views::RadioButton(base::ASCIIToUTF16("Radio button disabled"), - 0)), - radio_button_selected_( - new views::RadioButton(base::ASCIIToUTF16("Radio button selected"), - 0)), - radio_button_selected_disabled_(new views::RadioButton( - base::ASCIIToUTF16("Radio button selected disabled"), - 1)) { - SetTitle(base::ASCIIToUTF16("Examples: Widgets")); - button_ = AddChildView( - views::MdTextButton::Create(nullptr, base::ASCIIToUTF16("Button"))); - disabled_button_ = AddChildView(views::MdTextButton::Create( - nullptr, base::ASCIIToUTF16("Disabled button"))); - disabled_button_->SetEnabled(false); - AddChildView(checkbox_); - checkbox_disabled_->SetEnabled(false); - AddChildView(checkbox_disabled_); - checkbox_checked_->SetChecked(true); - AddChildView(checkbox_checked_); - checkbox_checked_disabled_->SetChecked(true); - checkbox_checked_disabled_->SetEnabled(false); - AddChildView(checkbox_checked_disabled_); - AddChildView(radio_button_); - radio_button_disabled_->SetEnabled(false); - AddChildView(radio_button_disabled_); - radio_button_selected_->SetChecked(true); - AddChildView(radio_button_selected_); - radio_button_selected_disabled_->SetChecked(true); - radio_button_selected_disabled_->SetEnabled(false); - AddChildView(radio_button_selected_disabled_); -} - -WidgetsWindow::~WidgetsWindow() = default; - -void WidgetsWindow::OnPaint(gfx::Canvas* canvas) { - canvas->FillRect(GetLocalBounds(), SK_ColorWHITE); -} - -void WidgetsWindow::Layout() { - const int kVerticalPad = 5; - int left = 5; - int top = kVerticalPad; - for (auto* view : children()) { - gfx::Size preferred = view->GetPreferredSize(); - view->SetBounds(left, top, preferred.width(), preferred.height()); - top += preferred.height() + kVerticalPad; - } -} - -gfx::Size WidgetsWindow::CalculatePreferredSize() const { - return gfx::Size(kWindowWidth, kWindowHeight); -} - -bool WidgetsWindow::CanResize() const { - return true; -} - -} // namespace - -namespace ash { -namespace shell { - -void CreateWidgetsWindow() { - views::Widget* widget = views::Widget::CreateWindowWithContext( - new WidgetsWindow, Shell::GetPrimaryRootWindow(), - gfx::Rect(kWindowLeft, kWindowTop, kWindowWidth, kWindowHeight)); - widget->GetNativeView()->SetName("WidgetsWindow"); - widget->Show(); -} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/window_type_launcher.cc b/ash/shell/window_type_launcher.cc deleted file mode 100644 index 56e4485577147f..00000000000000 --- a/ash/shell/window_type_launcher.cc +++ /dev/null @@ -1,319 +0,0 @@ -// Copyright (c) 2012 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/shell/window_type_launcher.h" - -#include - -#include "ash/public/cpp/shell_window_ids.h" -#include "ash/root_window_controller.h" -#include "ash/session/session_controller_impl.h" -#include "ash/shell.h" -#include "ash/shell/example_factory.h" -#include "ash/shell/toplevel_window.h" -#include "ash/wm/test_child_modal_parent.h" -#include "base/stl_util.h" -#include "base/strings/utf_string_conversions.h" -#include "ui/aura/window.h" -#include "ui/aura/window_event_dispatcher.h" -#include "ui/compositor/layer.h" -#include "ui/gfx/canvas.h" -#include "ui/message_center/message_center.h" -#include "ui/message_center/public/cpp/notification_types.h" -#include "ui/views/border.h" -#include "ui/views/controls/button/md_text_button.h" -#include "ui/views/controls/menu/menu_item_view.h" -#include "ui/views/controls/menu/menu_runner.h" -#include "ui/views/layout/grid_layout.h" -#include "ui/views/widget/widget.h" -#include "ui/wm/core/shadow_types.h" - -using views::MdTextButton; -using views::MenuItemView; -using views::MenuRunner; - -namespace ash { -namespace shell { - -namespace { - -constexpr int kWindowShadowElevation = 8; -constexpr const SkColor kColors[] = {SK_ColorRED, SK_ColorYELLOW, SK_ColorBLUE, - SK_ColorGREEN}; - -int g_color_index = 0; - -class ModalWindow : public views::WidgetDelegateView, - public views::ButtonListener { - public: - explicit ModalWindow(ui::ModalType modal_type) - : modal_type_(modal_type), color_(kColors[g_color_index]) { - SetTitle(base::ASCIIToUTF16("Modal Window")); - ++g_color_index %= base::size(kColors); - open_button_ = - AddChildView(MdTextButton::Create(this, base::ASCIIToUTF16("Moar!"))); - } - ~ModalWindow() override = default; - - static void OpenModalWindow(aura::Window* parent, ui::ModalType modal_type) { - views::Widget* widget = views::Widget::CreateWindowWithParent( - new ModalWindow(modal_type), parent); - widget->GetNativeView()->SetName("ModalWindow"); - widget->Show(); - } - - // Overridden from views::View: - void OnPaint(gfx::Canvas* canvas) override { - canvas->FillRect(GetLocalBounds(), color_); - } - gfx::Size CalculatePreferredSize() const override { - return gfx::Size(200, 200); - } - void Layout() override { - gfx::Size open_ps = open_button_->GetPreferredSize(); - gfx::Rect local_bounds = GetLocalBounds(); - open_button_->SetBounds(5, local_bounds.bottom() - open_ps.height() - 5, - open_ps.width(), open_ps.height()); - } - - // Overridden from views::WidgetDelegate: - bool CanResize() const override { return true; } - ui::ModalType GetModalType() const override { return modal_type_; } - - // Overridden from views::ButtonListener: - void ButtonPressed(views::Button* sender, const ui::Event& event) override { - DCHECK(sender == open_button_); - OpenModalWindow(GetWidget()->GetNativeView(), modal_type_); - } - - private: - ui::ModalType modal_type_; - SkColor color_; - views::Button* open_button_; - - DISALLOW_COPY_AND_ASSIGN(ModalWindow); -}; - -class NonModalTransient : public views::WidgetDelegateView { - public: - NonModalTransient() : color_(kColors[g_color_index]) { - SetTitle(base::ASCIIToUTF16("Non-Modal Transient")); - ++g_color_index %= base::size(kColors); - } - ~NonModalTransient() override = default; - - static void OpenNonModalTransient(aura::Window* parent) { - views::Widget* widget = - views::Widget::CreateWindowWithParent(new NonModalTransient, parent); - widget->GetNativeView()->SetName("NonModalTransient"); - widget->Show(); - } - - static void ToggleNonModalTransient(aura::Window* parent) { - if (!non_modal_transient_) { - non_modal_transient_ = - views::Widget::CreateWindowWithParent(new NonModalTransient, parent); - non_modal_transient_->GetNativeView()->SetName("NonModalTransient"); - } - if (non_modal_transient_->IsVisible()) - non_modal_transient_->Hide(); - else - non_modal_transient_->Show(); - } - - // Overridden from views::View: - void OnPaint(gfx::Canvas* canvas) override { - canvas->FillRect(GetLocalBounds(), color_); - } - gfx::Size CalculatePreferredSize() const override { - return gfx::Size(250, 250); - } - - // Overridden from views::WidgetDelegate: - bool CanResize() const override { return true; } - void DeleteDelegate() override { - if (GetWidget() == non_modal_transient_) - non_modal_transient_ = nullptr; - - delete this; - } - - private: - SkColor color_; - - static views::Widget* non_modal_transient_; - - DISALLOW_COPY_AND_ASSIGN(NonModalTransient); -}; - -// static -views::Widget* NonModalTransient::non_modal_transient_ = nullptr; - -template -T* AddViewToLayout(views::GridLayout* layout, std::unique_ptr view) { - layout->StartRow(0, 0); - T* result = layout->AddView(std::move(view)); - layout->AddPaddingRow(0, 5); - return result; -} - -} // namespace - -void InitWindowTypeLauncher( - base::RepeatingClosure show_views_examples_callback, - base::RepeatingClosure create_embedded_browser_callback) { - views::Widget* widget = views::Widget::CreateWindowWithContext( - new WindowTypeLauncher(show_views_examples_callback, - create_embedded_browser_callback), - Shell::GetPrimaryRootWindow(), gfx::Rect(120, 120, 300, 410)); - widget->GetNativeView()->SetName("WindowTypeLauncher"); - ::wm::SetShadowElevation(widget->GetNativeView(), kWindowShadowElevation); - widget->Show(); -} - -WindowTypeLauncher::WindowTypeLauncher( - base::RepeatingClosure show_views_examples_callback, - base::RepeatingClosure create_embedded_browser_callback) - : show_views_examples_callback_(std::move(show_views_examples_callback)), - create_embedded_browser_callback_( - std::move(create_embedded_browser_callback)) { - SetCanMaximize(true); - SetCanMinimize(true); - SetCanResize(true); - SetTitle(base::ASCIIToUTF16("Examples: Window Builder")); - views::GridLayout* layout = - SetLayoutManager(std::make_unique()); - SetBorder(views::CreateEmptyBorder(gfx::Insets(5))); - views::ColumnSet* column_set = layout->AddColumnSet(0); - column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, - 0, views::GridLayout::ColumnSize::kUsePreferred, 0, 0); - create_button_ = AddViewToLayout( - layout, MdTextButton::Create(this, base::ASCIIToUTF16("Create Window"))); - create_nonresizable_button_ = AddViewToLayout( - layout, MdTextButton::Create( - this, base::ASCIIToUTF16("Create Non-Resizable Window"))); - bubble_button_ = AddViewToLayout( - layout, - MdTextButton::Create(this, base::ASCIIToUTF16("Create Pointy Bubble"))); - lock_button_ = AddViewToLayout( - layout, MdTextButton::Create(this, base::ASCIIToUTF16("Lock Screen"))); - widgets_button_ = AddViewToLayout( - layout, - MdTextButton::Create(this, base::ASCIIToUTF16("Show Example Widgets"))); - system_modal_button_ = AddViewToLayout( - layout, MdTextButton::Create( - this, base::ASCIIToUTF16("Open System Modal Window"))); - window_modal_button_ = AddViewToLayout( - layout, MdTextButton::Create( - this, base::ASCIIToUTF16("Open Window Modal Window"))); - child_modal_button_ = AddViewToLayout( - layout, MdTextButton::Create( - this, base::ASCIIToUTF16("Open Child Modal Window"))); - transient_button_ = AddViewToLayout( - layout, MdTextButton::Create( - this, base::ASCIIToUTF16("Open Non-Modal Transient Window"))); - examples_button_ = AddViewToLayout( - layout, MdTextButton::Create( - this, base::ASCIIToUTF16("Open Views Examples Window"))); - show_hide_window_button_ = AddViewToLayout( - layout, - MdTextButton::Create(this, base::ASCIIToUTF16("Show/Hide a Window"))); - show_web_notification_ = AddViewToLayout( - layout, MdTextButton::Create( - this, base::ASCIIToUTF16("Show a web/app notification"))); - embedded_browser_button_ = AddViewToLayout( - layout, - MdTextButton::Create(this, base::ASCIIToUTF16("Embedded Browser"))); - set_context_menu_controller(this); -} - -WindowTypeLauncher::~WindowTypeLauncher() = default; - -void WindowTypeLauncher::OnPaint(gfx::Canvas* canvas) { - canvas->FillRect(GetLocalBounds(), SK_ColorWHITE); -} - -bool WindowTypeLauncher::OnMousePressed(const ui::MouseEvent& event) { - // Overridden so we get OnMouseReleased and can show the context menu. - return true; -} - -void WindowTypeLauncher::ButtonPressed(views::Button* sender, - const ui::Event& event) { - if (sender == create_button_) { - ToplevelWindow::CreateParams params; - params.can_resize = true; - params.can_maximize = true; - ToplevelWindow::CreateToplevelWindow(params); - } else if (sender == create_nonresizable_button_) { - ToplevelWindow::CreateToplevelWindow(ToplevelWindow::CreateParams()); - } else if (sender == embedded_browser_button_) { - create_embedded_browser_callback_.Run(); - } else if (sender == bubble_button_) { - CreatePointyBubble(sender); - } else if (sender == lock_button_) { - Shell::Get()->session_controller()->LockScreen(); - } else if (sender == widgets_button_) { - CreateWidgetsWindow(); - } else if (sender == system_modal_button_) { - ModalWindow::OpenModalWindow(GetWidget()->GetNativeView(), - ui::MODAL_TYPE_SYSTEM); - } else if (sender == window_modal_button_) { - ModalWindow::OpenModalWindow(GetWidget()->GetNativeView(), - ui::MODAL_TYPE_WINDOW); - } else if (sender == child_modal_button_) { - TestChildModalParent::Show(GetWidget()->GetNativeView()->GetRootWindow()); - } else if (sender == transient_button_) { - NonModalTransient::OpenNonModalTransient(GetWidget()->GetNativeView()); - } else if (sender == show_hide_window_button_) { - NonModalTransient::ToggleNonModalTransient(GetWidget()->GetNativeView()); - } else if (sender == show_web_notification_) { - std::unique_ptr notification = - std::make_unique( - message_center::NOTIFICATION_TYPE_SIMPLE, "id0", - base::ASCIIToUTF16("Test Shell Web Notification"), - base::ASCIIToUTF16("Notification message body."), gfx::Image(), - base::ASCIIToUTF16("www.testshell.org"), GURL(), - message_center::NotifierId( - message_center::NotifierType::APPLICATION, "test-id"), - message_center::RichNotificationData(), nullptr /* delegate */); - - message_center::MessageCenter::Get()->AddNotification( - std::move(notification)); - } else if (sender == examples_button_) { - show_views_examples_callback_.Run(); - } -} - -void WindowTypeLauncher::ExecuteCommand(int id, int event_flags) { - switch (id) { - case COMMAND_NEW_WINDOW: - InitWindowTypeLauncher(show_views_examples_callback_, - create_embedded_browser_callback_); - break; - case COMMAND_TOGGLE_FULLSCREEN: - GetWidget()->SetFullscreen(!GetWidget()->IsFullscreen()); - break; - default: - break; - } -} - -void WindowTypeLauncher::ShowContextMenuForViewImpl( - views::View* source, - const gfx::Point& point, - ui::MenuSourceType source_type) { - MenuItemView* root = new MenuItemView(this); - root->AppendMenuItem(COMMAND_NEW_WINDOW, base::ASCIIToUTF16("New Window")); - root->AppendMenuItem(COMMAND_TOGGLE_FULLSCREEN, - base::ASCIIToUTF16("Toggle FullScreen")); - // MenuRunner takes ownership of root. - menu_runner_.reset(new MenuRunner( - root, MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU)); - menu_runner_->RunMenuAt(GetWidget(), nullptr, gfx::Rect(point, gfx::Size()), - views::MenuAnchorPosition::kTopLeft, source_type); -} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/window_type_launcher.h b/ash/shell/window_type_launcher.h deleted file mode 100644 index d75f08bad94032..00000000000000 --- a/ash/shell/window_type_launcher.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) 2012 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_SHELL_WINDOW_TYPE_LAUNCHER_H_ -#define ASH_SHELL_WINDOW_TYPE_LAUNCHER_H_ - -#include - -#include "base/callback_forward.h" -#include "base/macros.h" -#include "ui/views/context_menu_controller.h" -#include "ui/views/controls/button/button.h" -#include "ui/views/controls/menu/menu_delegate.h" -#include "ui/views/widget/widget_delegate.h" - -namespace views { -class MenuRunner; -} - -namespace ash { -namespace shell { - -// Creates a Widget to host WindowTypeLauncher. |show_views_examples_callback| -// is Run() when the user clicks on the views examples button. This should -// be bound to either views::examples::ShowExamplesWindow() or -// views::examples::ShowExamplesWindowWithContent(). -// |create_embedded_browser_callback| is Run when user clicks the "embedded -// browser" button. -void InitWindowTypeLauncher( - base::RepeatingClosure show_views_examples_callback, - base::RepeatingClosure create_embedded_browser_callback); - -// The contents view/delegate of a window that shows some buttons that create -// various window types. -class WindowTypeLauncher : public views::WidgetDelegateView, - public views::ButtonListener, - public views::MenuDelegate, - public views::ContextMenuController { - public: - WindowTypeLauncher(base::RepeatingClosure show_views_examples_callback, - base::RepeatingClosure create_embedded_browser_callback); - ~WindowTypeLauncher() override; - - private: - typedef std::pair WindowAndBoundsPair; - - enum MenuCommands { - COMMAND_NEW_WINDOW = 1, - COMMAND_TOGGLE_FULLSCREEN = 3, - }; - - // Overridden from views::View: - void OnPaint(gfx::Canvas* canvas) override; - bool OnMousePressed(const ui::MouseEvent& event) override; - - // Overridden from views::ButtonListener: - void ButtonPressed(views::Button* sender, const ui::Event& event) override; - - // Overridden from views::MenuDelegate: - void ExecuteCommand(int id, int event_flags) override; - - // Override from views::ContextMenuController: - void ShowContextMenuForViewImpl(views::View* source, - const gfx::Point& point, - ui::MenuSourceType source_type) override; - - views::Button* create_button_; - views::Button* create_nonresizable_button_; - views::Button* bubble_button_; - views::Button* lock_button_; - views::Button* widgets_button_; - views::Button* system_modal_button_; - views::Button* window_modal_button_; - views::Button* child_modal_button_; - views::Button* transient_button_; - views::Button* examples_button_; - views::Button* show_hide_window_button_; - views::Button* show_web_notification_; - views::Button* embedded_browser_button_; - - std::unique_ptr menu_runner_; - - base::RepeatingClosure show_views_examples_callback_; - base::RepeatingClosure create_embedded_browser_callback_; - - DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncher); -}; - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_WINDOW_TYPE_LAUNCHER_H_ diff --git a/ash/shell/window_watcher.cc b/ash/shell/window_watcher.cc deleted file mode 100644 index 06a4f25ac2a33d..00000000000000 --- a/ash/shell/window_watcher.cc +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright (c) 2012 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/shell/window_watcher.h" - -#include -#include - -#include "ash/public/cpp/shelf_item.h" -#include "ash/public/cpp/shelf_model.h" -#include "ash/public/cpp/shell_window_ids.h" -#include "ash/public/cpp/window_properties.h" -#include "ash/shelf/shelf_widget.h" -#include "ash/shell.h" -#include "ash/shell/window_watcher_shelf_item_delegate.h" -#include "ash/wm/desks/desks_util.h" -#include "ash/wm/window_util.h" -#include "base/strings/string_number_conversions.h" -#include "third_party/skia/include/core/SkColor.h" -#include "ui/aura/window.h" - -namespace ash { -namespace shell { - -namespace { - -} // namespace - -class WindowWatcher::WorkspaceWindowWatcher : public aura::WindowObserver { - public: - explicit WorkspaceWindowWatcher(WindowWatcher* watcher) : watcher_(watcher) {} - - ~WorkspaceWindowWatcher() override = default; - - void OnWindowAdded(aura::Window* new_window) override { - new_window->AddObserver(watcher_); - } - - void OnWillRemoveWindow(aura::Window* window) override { - DCHECK(window->children().empty()); - window->RemoveObserver(watcher_); - } - - void RootWindowAdded(aura::Window* root) { - // The shelf is globally observing all active and inactive desks containers. - for (aura::Window* container : desks_util::GetDesksContainers(root)) { - container->AddObserver(watcher_); - for (aura::Window* window : container->children()) - watcher_->OnWindowAdded(window); - } - } - - void RootWindowRemoved(aura::Window* root) { - for (aura::Window* container : desks_util::GetDesksContainers(root)) { - container->RemoveObserver(watcher_); - for (aura::Window* window : container->children()) - watcher_->OnWillRemoveWindow(window); - } - } - - private: - WindowWatcher* watcher_; - - DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowWatcher); -}; - -WindowWatcher::WindowWatcher() { - Shell::Get()->AddShellObserver(this); - workspace_window_watcher_ = std::make_unique(this); - for (aura::Window* root : Shell::GetAllRootWindows()) - workspace_window_watcher_->RootWindowAdded(root); -} - -WindowWatcher::~WindowWatcher() { - for (aura::Window* root : Shell::GetAllRootWindows()) - workspace_window_watcher_->RootWindowRemoved(root); - Shell::Get()->RemoveShellObserver(this); -} - -aura::Window* WindowWatcher::GetWindowByID(const ShelfID& id) { - IDToWindow::const_iterator i = id_to_window_.find(id); - return i != id_to_window_.end() ? i->second : NULL; -} - -// aura::WindowObserver overrides: -void WindowWatcher::OnWindowAdded(aura::Window* new_window) { - if (!window_util::IsWindowUserPositionable(new_window)) - return; - - ShelfModel* model = ShelfModel::Get(); - ShelfItem item; - item.type = TYPE_APP; - static int shelf_id = 0; - item.id = ShelfID(base::NumberToString(shelf_id++)); - id_to_window_[item.id] = new_window; - - SkBitmap icon_bitmap; - icon_bitmap.allocN32Pixels(16, 16); - constexpr SkColor colors[] = {SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE}; - icon_bitmap.eraseColor(colors[shelf_id % 3]); - item.image = gfx::ImageSkia(gfx::ImageSkiaRep(icon_bitmap, 1.0f)); - item.title = base::NumberToString16(shelf_id); - model->Add(item); - - model->SetShelfItemDelegate( - item.id, std::make_unique(item.id, this)); - new_window->SetProperty(kShelfIDKey, item.id.Serialize()); -} - -void WindowWatcher::OnWillRemoveWindow(aura::Window* window) { - for (IDToWindow::iterator i = id_to_window_.begin(); i != id_to_window_.end(); - ++i) { - if (i->second == window) { - ShelfModel* model = ShelfModel::Get(); - int index = model->ItemIndexByID(i->first); - DCHECK_NE(-1, index); - model->RemoveItemAt(index); - id_to_window_.erase(i); - break; - } - } -} - -void WindowWatcher::OnRootWindowAdded(aura::Window* root_window) { - workspace_window_watcher_->RootWindowAdded(root_window); -} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/window_watcher.h b/ash/shell/window_watcher.h deleted file mode 100644 index 2c0e6f29155b11..00000000000000 --- a/ash/shell/window_watcher.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2012 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_SHELL_WINDOW_WATCHER_H_ -#define ASH_SHELL_WINDOW_WATCHER_H_ - -#include - -#include -#include - -#include "ash/public/cpp/shelf_types.h" -#include "ash/shell_observer.h" -#include "base/macros.h" -#include "ui/aura/window_observer.h" - -namespace ash { -namespace shell { - -// WindowWatcher is responsible for listening for newly created windows and -// creating items on the Shelf for them. -class WindowWatcher : public aura::WindowObserver, public ShellObserver { - public: - WindowWatcher(); - ~WindowWatcher() override; - - aura::Window* GetWindowByID(const ShelfID& id); - - // aura::WindowObserver overrides: - void OnWindowAdded(aura::Window* new_window) override; - void OnWillRemoveWindow(aura::Window* window) override; - - // ShellObserver: - void OnRootWindowAdded(aura::Window* root_window) override; - - private: - class WorkspaceWindowWatcher; - - typedef std::map IDToWindow; - - // Maps from window to the id we gave it. - IDToWindow id_to_window_; - - std::unique_ptr workspace_window_watcher_; - - DISALLOW_COPY_AND_ASSIGN(WindowWatcher); -}; - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_WINDOW_WATCHER_H_ diff --git a/ash/shell/window_watcher_shelf_item_delegate.cc b/ash/shell/window_watcher_shelf_item_delegate.cc deleted file mode 100644 index e37349dd38d2c3..00000000000000 --- a/ash/shell/window_watcher_shelf_item_delegate.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2013 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/shell/window_watcher_shelf_item_delegate.h" - -#include - -#include "ash/shell/window_watcher.h" -#include "ash/wm/window_util.h" -#include "ui/aura/window.h" - -namespace ash { -namespace shell { - -WindowWatcherShelfItemDelegate::WindowWatcherShelfItemDelegate( - ShelfID id, - WindowWatcher* watcher) - : ShelfItemDelegate(id), watcher_(watcher) { - DCHECK(!id.IsNull()); - DCHECK(watcher_); -} - -WindowWatcherShelfItemDelegate::~WindowWatcherShelfItemDelegate() = default; - -void WindowWatcherShelfItemDelegate::ItemSelected( - std::unique_ptr event, - int64_t display_id, - ShelfLaunchSource source, - ItemSelectedCallback callback, - const ItemFilterPredicate& filter_predicate) { - aura::Window* window = watcher_->GetWindowByID(shelf_id()); - window->Show(); - wm::ActivateWindow(window); - std::move(callback).Run(SHELF_ACTION_WINDOW_ACTIVATED, {}); -} - -void WindowWatcherShelfItemDelegate::ExecuteCommand(bool from_context_menu, - int64_t command_id, - int32_t event_flags, - int64_t display_id) { - // This delegate does not show custom context or application menu items. - NOTIMPLEMENTED(); -} - -void WindowWatcherShelfItemDelegate::Close() {} - -} // namespace shell -} // namespace ash diff --git a/ash/shell/window_watcher_shelf_item_delegate.h b/ash/shell/window_watcher_shelf_item_delegate.h deleted file mode 100644 index 50e076fafb5f1d..00000000000000 --- a/ash/shell/window_watcher_shelf_item_delegate.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2013 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_SHELL_WINDOW_WATCHER_SHELF_ITEM_DELEGATE_H_ -#define ASH_SHELL_WINDOW_WATCHER_SHELF_ITEM_DELEGATE_H_ - -#include "ash/public/cpp/shelf_item.h" -#include "ash/public/cpp/shelf_item_delegate.h" -#include "base/compiler_specific.h" -#include "base/macros.h" - -namespace ash { -namespace shell { - -class WindowWatcher; - -// ShelfItemDelegate implementation used by WindowWatcher. -class WindowWatcherShelfItemDelegate : public ShelfItemDelegate { - public: - WindowWatcherShelfItemDelegate(ShelfID id, WindowWatcher* watcher); - ~WindowWatcherShelfItemDelegate() override; - - // ShelfItemDelegate: - void ItemSelected(std::unique_ptr event, - int64_t display_id, - ShelfLaunchSource source, - ItemSelectedCallback callback, - const ItemFilterPredicate& filter_predicate) override; - void ExecuteCommand(bool from_context_menu, - int64_t command_id, - int32_t event_flags, - int64_t display_id) override; - void Close() override; - - private: - WindowWatcher* watcher_; - - DISALLOW_COPY_AND_ASSIGN(WindowWatcherShelfItemDelegate); -}; - -} // namespace shell -} // namespace ash - -#endif // ASH_SHELL_WINDOW_WATCHER_SHELF_ITEM_DELEGATE_H_ diff --git a/ash/test/ash_test_helper.cc b/ash/test/ash_test_helper.cc index 415f897220e0d2..6bebed303e7cbc 100644 --- a/ash/test/ash_test_helper.cc +++ b/ash/test/ash_test_helper.cc @@ -19,11 +19,11 @@ #include "ash/public/cpp/test/test_new_window_delegate.h" #include "ash/session/test_session_controller_client.h" #include "ash/shell.h" -#include "ash/shell/toplevel_window.h" #include "ash/shell_init_params.h" #include "ash/system/model/system_tray_model.h" #include "ash/system/screen_layout_observer.h" #include "ash/test/ash_test_views_delegate.h" +#include "ash/test/toplevel_window.h" #include "ash/test_shell_delegate.h" #include "ash/wallpaper/wallpaper_controller_impl.h" #include "ash/wm/overview/overview_controller.h" diff --git a/ash/shell/toplevel_window.cc b/ash/test/toplevel_window.cc similarity index 96% rename from ash/shell/toplevel_window.cc rename to ash/test/toplevel_window.cc index 392197a5ad3313..7bd204c225278c 100644 --- a/ash/shell/toplevel_window.cc +++ b/ash/test/toplevel_window.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ash/shell/toplevel_window.h" +#include "ash/test/toplevel_window.h" #include "ash/shell.h" #include "ash/wm/window_positioner.h" @@ -24,7 +24,7 @@ struct SavedState { // The last window state in ash_shell. We don't bother deleting // this on shutdown. -SavedState* saved_state = NULL; +SavedState* saved_state = nullptr; } // namespace @@ -46,7 +46,7 @@ views::Widget* ToplevelWindow::CreateToplevelWindow( // static void ToplevelWindow::ClearSavedStateForTest() { delete saved_state; - saved_state = NULL; + saved_state = nullptr; } ToplevelWindow::ToplevelWindow(const CreateParams& params) diff --git a/ash/shell/toplevel_window.h b/ash/test/toplevel_window.h similarity index 92% rename from ash/shell/toplevel_window.h rename to ash/test/toplevel_window.h index 77dc0487884530..bf07671dbcbb46 100644 --- a/ash/shell/toplevel_window.h +++ b/ash/test/toplevel_window.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef ASH_SHELL_TOPLEVEL_WINDOW_H_ -#define ASH_SHELL_TOPLEVEL_WINDOW_H_ +#ifndef ASH_TEST_TOPLEVEL_WINDOW_H_ +#define ASH_TEST_TOPLEVEL_WINDOW_H_ #include "base/macros.h" #include "ui/views/widget/widget_delegate.h" @@ -48,4 +48,4 @@ class ToplevelWindow : public views::WidgetDelegateView { } // namespace shell } // namespace ash -#endif // ASH_SHELL_TOPLEVEL_WINDOW_H_ +#endif // ASH_TEST_TOPLEVEL_WINDOW_H_ diff --git a/ash/wm/window_positioner_unittest.cc b/ash/wm/window_positioner_unittest.cc index e698657f0646a6..bcd8ff3b1f91b1 100644 --- a/ash/wm/window_positioner_unittest.cc +++ b/ash/wm/window_positioner_unittest.cc @@ -8,8 +8,8 @@ #include "ash/public/cpp/shelf_config.h" #include "ash/shell.h" -#include "ash/shell/toplevel_window.h" #include "ash/test/ash_test_base.h" +#include "ash/test/toplevel_window.h" #include "ash/test_shell_delegate.h" #include "ash/wm/window_positioner.h" #include "ash/wm/window_state.h"