Skip to content

Commit

Permalink
Merge pull request #12692 from brave/uplift_windows_default_dialog_1.…
Browse files Browse the repository at this point in the history
…37.x

Launch FirstRun dialog on Windows (uplift to 1.37.x)
  • Loading branch information
kjozwiak authored Apr 4, 2022
2 parents 3fb570c + a09befb commit 45a5801
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 5 deletions.
14 changes: 14 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,20 @@ Are you sure you want to do this?
<message name="IDS_FIRSTRUN_DLG_COMPLETE_INSTALLATION_LABEL_BRAVE" desc="Label at top of Dialog noting what's going to happen">
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.
</message>
<if expr="is_win">
<message name="IDS_FIRSTRUN_DLG_WIN_HEADER_TEXT" desc="Text for FirstRun dialog header">
Ready for the best privacy online?
</message>
<message name="IDS_FIRSTRUN_DLG_WIN_CONTENTS_TEXT" desc="Text for FirstRun dialog contents">
Set Brave as your default browser to get Brave's privacy protections on every web page you open.
</message>
<message name="IDS_FIRSTRUN_DLG_WIN_OK_BUTTON_LABEL" desc="Text for FirstRun dialog ok button">
Set Brave as default
</message>
<message name="IDS_FIRSTRUN_DLG_WIN_CANCEL_BUTTON_LABEL" desc="Text for FirstRun dialog cancel button">
Maybe later
</message>
</if>
<message name="IDS_SETTINGS_WALLET_NETWORKS_ITEM" desc="The label for opening wallet networks list">
Networks
</message>
Expand Down
9 changes: 9 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
111 changes: 111 additions & 0 deletions browser/ui/views/first_run_dialog_win.cc
Original file line number Diff line number Diff line change
@@ -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 <memory>
#include <utility>

#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>(
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<views::Label>(
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<views::Label>(
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<shell_integration::BraveDefaultBrowserWorker>()
->StartSetAsDefault(base::NullCallback());

Done();
return true;
}

void FirstRunDialogWin::WindowClosing() {
first_run::SetShouldShowWelcomePage();
Done();
}

BEGIN_METADATA(FirstRunDialogWin, views::DialogDelegateView)
END_METADATA
38 changes: 38 additions & 0 deletions browser/ui/views/first_run_dialog_win.h
Original file line number Diff line number Diff line change
@@ -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_
27 changes: 27 additions & 0 deletions chromium_src/chrome/browser/first_run/first_run_dialog.h
Original file line number Diff line number Diff line change
@@ -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_
40 changes: 40 additions & 0 deletions chromium_src/chrome/browser/first_run/first_run_internal_win.cc
Original file line number Diff line number Diff line change
@@ -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
6 changes: 1 addition & 5 deletions chromium_src/chrome/browser/ui/views/first_run_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down

0 comments on commit 45a5801

Please sign in to comment.