diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd index 92ad474efdaa..bc140e7af757 100644 --- a/app/brave_generated_resources.grd +++ b/app/brave_generated_resources.grd @@ -1650,6 +1650,20 @@ Are you sure you want to do this? To ensure the best privacy online, consider setting Brave as the default browser on your computer. With Brave as default, any web link you click will open with Brave's privacy protections. + + + Ready for the best privacy online? + + + Set Brave as your default browser to get Brave's privacy protections on every web page you open. + + + Set Brave as default + + + Maybe later + + Networks diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 56b946489655..ffbab5c2c0bb 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -182,6 +182,15 @@ source_set("ui") { "views/web_discovery_dialog_view.h", ] + # Use different FirstRun dialog UI on Win. + # Upstream only includes it on mac/Linux. + if (is_win) { + sources += [ + "views/first_run_dialog_win.cc", + "views/first_run_dialog_win.h", + ] + } + if (use_aura) { sources += [ "views/renderer_context_menu/brave_render_view_context_menu_views.cc", diff --git a/browser/ui/views/first_run_dialog_win.cc b/browser/ui/views/first_run_dialog_win.cc new file mode 100644 index 000000000000..ad7a75cf0da1 --- /dev/null +++ b/browser/ui/views/first_run_dialog_win.cc @@ -0,0 +1,111 @@ +/* Copyright (c) 2022 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/ui/views/first_run_dialog_win.h" + +#include +#include + +#include "base/bind.h" +#include "base/memory/scoped_refptr.h" +#include "base/run_loop.h" +#include "brave/browser/brave_shell_integration.h" +#include "brave/grit/brave_generated_resources.h" +#include "chrome/browser/first_run/first_run.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/metadata/metadata_impl_macros.h" +#include "ui/gfx/font.h" +#include "ui/gfx/geometry/insets.h" +#include "ui/views/controls/label.h" +#include "ui/views/layout/box_layout.h" +#include "ui/views/window/dialog_delegate.h" + +namespace first_run { + +void ShowFirstRunDialog(Profile* profile) { + base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed); + FirstRunDialogWin::Show(run_loop.QuitClosure()); + run_loop.Run(); +} + +} // namespace first_run + +// static +void FirstRunDialogWin::Show(base::RepeatingClosure quit_runloop) { + FirstRunDialogWin* dialog = new FirstRunDialogWin(std::move(quit_runloop)); + views::DialogDelegate::CreateDialogWidget(dialog, NULL, NULL)->Show(); +} + +FirstRunDialogWin::FirstRunDialogWin(base::RepeatingClosure quit_runloop) + : quit_runloop_(quit_runloop) { + set_should_ignore_snapping(true); + SetButtonLabel( + ui::DIALOG_BUTTON_OK, + l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_OK_BUTTON_LABEL)); + SetButtonLabel( + ui::DIALOG_BUTTON_CANCEL, + l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_CANCEL_BUTTON_LABEL)); + constexpr int kChildSpacing = 16; + constexpr int kPadding = 24; + constexpr int kTopPadding = 20; + constexpr int kBottomPadding = 55; + + SetLayoutManager(std::make_unique( + views::BoxLayout::Orientation::kVertical, + gfx::Insets(kTopPadding, kPadding, kBottomPadding, kPadding), + kChildSpacing)); + + constexpr int kHeaderFontSize = 16; + int size_diff = + kHeaderFontSize - views::Label::GetDefaultFontList().GetFontSize(); + views::Label::CustomFont header_font = { + views::Label::GetDefaultFontList() + .DeriveWithSizeDelta(size_diff) + .DeriveWithWeight(gfx::Font::Weight::SEMIBOLD)}; + auto* header_label = AddChildView(std::make_unique( + l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_HEADER_TEXT), + header_font)); + header_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); + + constexpr int kContentFontSize = 15; + size_diff = + kContentFontSize - views::Label::GetDefaultFontList().GetFontSize(); + views::Label::CustomFont contents_font = { + views::Label::GetDefaultFontList() + .DeriveWithSizeDelta(size_diff) + .DeriveWithWeight(gfx::Font::Weight::NORMAL)}; + auto* contents_label = AddChildView(std::make_unique( + l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_CONTENTS_TEXT), + contents_font)); + contents_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); + contents_label->SetMultiLine(true); + constexpr int kMaxWidth = 350; + contents_label->SetMaximumWidth(kMaxWidth); +} + +FirstRunDialogWin::~FirstRunDialogWin() = default; + +void FirstRunDialogWin::Done() { + CHECK(!quit_runloop_.is_null()); + quit_runloop_.Run(); +} + +bool FirstRunDialogWin::Accept() { + GetWidget()->Hide(); + + base::MakeRefCounted() + ->StartSetAsDefault(base::NullCallback()); + + Done(); + return true; +} + +void FirstRunDialogWin::WindowClosing() { + first_run::SetShouldShowWelcomePage(); + Done(); +} + +BEGIN_METADATA(FirstRunDialogWin, views::DialogDelegateView) +END_METADATA diff --git a/browser/ui/views/first_run_dialog_win.h b/browser/ui/views/first_run_dialog_win.h new file mode 100644 index 000000000000..456830a8b0df --- /dev/null +++ b/browser/ui/views/first_run_dialog_win.h @@ -0,0 +1,38 @@ +/* Copyright (c) 2022 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_WIN_H_ +#define BRAVE_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_WIN_H_ + +#include "base/callback.h" +#include "ui/base/metadata/metadata_header_macros.h" +#include "ui/views/window/dialog_delegate.h" + +class FirstRunDialogWin : public views::DialogDelegateView { + public: + METADATA_HEADER(FirstRunDialogWin); + + FirstRunDialogWin(const FirstRunDialogWin&) = delete; + FirstRunDialogWin& operator=(const FirstRunDialogWin&) = delete; + + static void Show(base::RepeatingClosure quit_runloop); + + private: + explicit FirstRunDialogWin(base::RepeatingClosure quit_runloop); + ~FirstRunDialogWin() override; + + // This terminates the nested message-loop. + void Done(); + + // views::DialogDelegate overrides: + bool Accept() override; + + // views::WidgetDelegate overrides: + void WindowClosing() override; + + base::RepeatingClosure quit_runloop_; +}; + +#endif // BRAVE_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_WIN_H_ diff --git a/chromium_src/chrome/browser/first_run/first_run_dialog.h b/chromium_src/chrome/browser/first_run/first_run_dialog.h new file mode 100644 index 000000000000..69e6fef1ba30 --- /dev/null +++ b/chromium_src/chrome/browser/first_run/first_run_dialog.h @@ -0,0 +1,27 @@ +/* Copyright (c) 2022 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_FIRST_RUN_FIRST_RUN_DIALOG_H_ +#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_FIRST_RUN_FIRST_RUN_DIALOG_H_ + +#include "build/build_config.h" + +#include "src/chrome/browser/first_run/first_run_dialog.h" + +#if BUILDFLAG(IS_WIN) + +class Profile; + +namespace first_run { + +// Enable first run dialog on Win also. +// Upstream only uses it for macOS/Linux. +void ShowFirstRunDialog(Profile* profile); + +} // namespace first_run + +#endif // BUILDFLAG(IS_WIN) + +#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_FIRST_RUN_FIRST_RUN_DIALOG_H_ diff --git a/chromium_src/chrome/browser/first_run/first_run_internal_win.cc b/chromium_src/chrome/browser/first_run/first_run_internal_win.cc new file mode 100644 index 000000000000..46ecb78f71ea --- /dev/null +++ b/chromium_src/chrome/browser/first_run/first_run_internal_win.cc @@ -0,0 +1,40 @@ +/* Copyright (c) 2022 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "chrome/browser/first_run/first_run_dialog.h" +#include "chrome/browser/first_run/first_run_internal.h" + +namespace { + +bool ShouldShowFirstRunDialog() { +#if defined(OFFICIAL_BUILD) + return first_run::internal::IsOrganicFirstRun(); +#else + return false; +#endif +} + +} // namespace + +#define DoPostImportPlatformSpecificTasks \ + DoPostImportPlatformSpecificTasks_ChromiumImpl + +#include "src/chrome/browser/first_run/first_run_internal_win.cc" + +#undef DoPostImportPlatformSpecificTasks + +namespace first_run { +namespace internal { + +void DoPostImportPlatformSpecificTasks(Profile* profile) { + if (ShouldShowFirstRunDialog()) { + ShowFirstRunDialog(profile); + } + + DoPostImportPlatformSpecificTasks_ChromiumImpl(profile); +} + +} // namespace internal +} // namespace first_run diff --git a/chromium_src/chrome/browser/ui/views/first_run_dialog.cc b/chromium_src/chrome/browser/ui/views/first_run_dialog.cc index f5328cd1e797..204ab69130c6 100644 --- a/chromium_src/chrome/browser/ui/views/first_run_dialog.cc +++ b/chromium_src/chrome/browser/ui/views/first_run_dialog.cc @@ -13,17 +13,13 @@ #include "build/build_config.h" #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/first_run/first_run_dialog.h" -#include "chrome/browser/metrics/metrics_reporting_state.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/shell_integration.h" #include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/ui_features.h" -#include "chrome/browser/ui/views/chrome_layout_provider.h" #include "chrome/common/url_constants.h" #include "chrome/grit/chromium_strings.h" #include "chrome/grit/generated_resources.h" -#include "components/crash/core/app/breakpad_linux.h" -#include "components/crash/core/app/crashpad.h" #include "components/strings/grit/components_strings.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/metadata/metadata_impl_macros.h" @@ -37,7 +33,7 @@ namespace first_run { void ShowFirstRunDialog(Profile* profile) { -#if defined(OS_MAC) +#if BUILDFLAG(IS_MAC) if (base::FeatureList::IsEnabled(features::kViewsFirstRunDialog)) ShowFirstRunDialogViews(profile); else