Skip to content

Commit b9714d8

Browse files
committed
Shared FirstRun dialog on Win & Linux
issue: brave/brave-browser#21804
1 parent 06487d9 commit b9714d8

File tree

5 files changed

+76
-177
lines changed

5 files changed

+76
-177
lines changed

app/brave_generated_resources.grd

+12-14
Original file line numberDiff line numberDiff line change
@@ -1656,20 +1656,18 @@ Are you sure you want to do this?
16561656
<message name="IDS_FIRSTRUN_DLG_COMPLETE_INSTALLATION_LABEL_BRAVE" desc="Label at top of Dialog noting what's going to happen">
16571657
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.
16581658
</message>
1659-
<if expr="is_win">
1660-
<message name="IDS_FIRSTRUN_DLG_WIN_HEADER_TEXT" desc="Text for FirstRun dialog header">
1661-
Ready for the best privacy online?
1662-
</message>
1663-
<message name="IDS_FIRSTRUN_DLG_WIN_CONTENTS_TEXT" desc="Text for FirstRun dialog contents">
1664-
Set Brave as your default browser to get Brave's privacy protections on every web page you open.
1665-
</message>
1666-
<message name="IDS_FIRSTRUN_DLG_WIN_OK_BUTTON_LABEL" desc="Text for FirstRun dialog ok button">
1667-
Set Brave as default
1668-
</message>
1669-
<message name="IDS_FIRSTRUN_DLG_WIN_CANCEL_BUTTON_LABEL" desc="Text for FirstRun dialog cancel button">
1670-
Maybe later
1671-
</message>
1672-
</if>
1659+
<message name="IDS_FIRSTRUN_DLG_HEADER_TEXT" desc="Text for FirstRun dialog header">
1660+
Ready for the best privacy online?
1661+
</message>
1662+
<message name="IDS_FIRSTRUN_DLG_CONTENTS_TEXT" desc="Text for FirstRun dialog contents">
1663+
Set Brave as your default browser to get Brave's privacy protections on every web page you open.
1664+
</message>
1665+
<message name="IDS_FIRSTRUN_DLG_OK_BUTTON_LABEL" desc="Text for FirstRun dialog ok button">
1666+
Set Brave as default
1667+
</message>
1668+
<message name="IDS_FIRSTRUN_DLG_CANCEL_BUTTON_LABEL" desc="Text for FirstRun dialog cancel button">
1669+
Maybe later
1670+
</message>
16731671
<message name="IDS_SETTINGS_WALLET_NETWORKS_ITEM" desc="The label for opening wallet networks list">
16741672
Networks
16751673
</message>

browser/ui/BUILD.gn

+2-9
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ source_set("ui") {
154154
"views/bookmarks/bookmark_bar_instructions_view.h",
155155
"views/brave_default_browser_dialog_view.cc",
156156
"views/brave_default_browser_dialog_view.h",
157+
"views/brave_first_run_dialog.cc",
158+
"views/brave_first_run_dialog.h",
157159
"views/brave_layout_provider.cc",
158160
"views/brave_layout_provider.h",
159161
"views/crash_report_permission_ask_dialog_view.cc",
@@ -182,15 +184,6 @@ source_set("ui") {
182184
"views/web_discovery_dialog_view.h",
183185
]
184186

185-
# Use different FirstRun dialog UI on Win.
186-
# Upstream only includes it on mac/Linux.
187-
if (is_win) {
188-
sources += [
189-
"views/first_run_dialog_win.cc",
190-
"views/first_run_dialog_win.h",
191-
]
192-
}
193-
194187
if (use_aura) {
195188
sources += [
196189
"views/renderer_context_menu/brave_render_view_context_menu_views.cc",

browser/ui/views/first_run_dialog_win.cc renamed to browser/ui/views/brave_first_run_dialog.cc

+48-19
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
44
* You can obtain one at http://mozilla.org/MPL/2.0/. */
55

6-
#include "brave/browser/ui/views/first_run_dialog_win.h"
6+
#include "brave/browser/ui/views/brave_first_run_dialog.h"
77

88
#include <memory>
99
#include <utility>
1010

1111
#include "base/bind.h"
1212
#include "base/memory/scoped_refptr.h"
1313
#include "base/run_loop.h"
14-
#include "brave/browser/brave_shell_integration.h"
1514
#include "brave/grit/brave_generated_resources.h"
15+
#include "build/build_config.h"
1616
#include "chrome/browser/first_run/first_run.h"
17+
#include "chrome/browser/ui/ui_features.h"
18+
#include "chrome/grit/chromium_strings.h"
1719
#include "ui/base/l10n/l10n_util.h"
1820
#include "ui/base/metadata/metadata_impl_macros.h"
1921
#include "ui/gfx/font.h"
@@ -22,31 +24,55 @@
2224
#include "ui/views/layout/box_layout.h"
2325
#include "ui/views/window/dialog_delegate.h"
2426

27+
#if BUILDFLAG(IS_WIN)
28+
#include "brave/browser/brave_shell_integration.h"
29+
#else
30+
#include "chrome/browser/shell_integration.h"
31+
#endif
32+
2533
namespace first_run {
2634

27-
void ShowFirstRunDialog(Profile* profile) {
35+
namespace {
36+
37+
void ShowBraveFirstRunDialogViews(Profile* profile) {
2838
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
29-
FirstRunDialogWin::Show(run_loop.QuitClosure());
39+
BraveFirstRunDialog::Show(run_loop.QuitClosure());
3040
run_loop.Run();
3141
}
3242

43+
} // namespace
44+
45+
void ShowFirstRunDialog(Profile* profile) {
46+
#if BUILDFLAG(IS_MAC)
47+
if (base::FeatureList::IsEnabled(features::kViewsFirstRunDialog))
48+
ShowFirstRunDialogViews(profile);
49+
else
50+
ShowFirstRunDialogCocoa(profile);
51+
#else
52+
ShowBraveFirstRunDialogViews(profile);
53+
#endif
54+
}
55+
3356
} // namespace first_run
3457

3558
// static
36-
void FirstRunDialogWin::Show(base::RepeatingClosure quit_runloop) {
37-
FirstRunDialogWin* dialog = new FirstRunDialogWin(std::move(quit_runloop));
59+
void BraveFirstRunDialog::Show(base::RepeatingClosure quit_runloop) {
60+
BraveFirstRunDialog* dialog =
61+
new BraveFirstRunDialog(std::move(quit_runloop));
3862
views::DialogDelegate::CreateDialogWidget(dialog, NULL, NULL)->Show();
3963
}
4064

41-
FirstRunDialogWin::FirstRunDialogWin(base::RepeatingClosure quit_runloop)
65+
BraveFirstRunDialog::BraveFirstRunDialog(base::RepeatingClosure quit_runloop)
4266
: quit_runloop_(quit_runloop) {
4367
set_should_ignore_snapping(true);
44-
SetButtonLabel(
45-
ui::DIALOG_BUTTON_OK,
46-
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_OK_BUTTON_LABEL));
68+
#if BUILDFLAG(IS_LINUX)
69+
SetTitle(IDS_FIRST_RUN_DIALOG_WINDOW_TITLE);
70+
#endif
71+
SetButtonLabel(ui::DIALOG_BUTTON_OK,
72+
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_OK_BUTTON_LABEL));
4773
SetButtonLabel(
4874
ui::DIALOG_BUTTON_CANCEL,
49-
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_CANCEL_BUTTON_LABEL));
75+
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_CANCEL_BUTTON_LABEL));
5076
constexpr int kChildSpacing = 16;
5177
constexpr int kPadding = 24;
5278
constexpr int kTopPadding = 20;
@@ -65,8 +91,7 @@ FirstRunDialogWin::FirstRunDialogWin(base::RepeatingClosure quit_runloop)
6591
.DeriveWithSizeDelta(size_diff)
6692
.DeriveWithWeight(gfx::Font::Weight::SEMIBOLD)};
6793
auto* header_label = AddChildView(std::make_unique<views::Label>(
68-
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_HEADER_TEXT),
69-
header_font));
94+
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_HEADER_TEXT), header_font));
7095
header_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
7196

7297
constexpr int kContentFontSize = 15;
@@ -77,35 +102,39 @@ FirstRunDialogWin::FirstRunDialogWin(base::RepeatingClosure quit_runloop)
77102
.DeriveWithSizeDelta(size_diff)
78103
.DeriveWithWeight(gfx::Font::Weight::NORMAL)};
79104
auto* contents_label = AddChildView(std::make_unique<views::Label>(
80-
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_CONTENTS_TEXT),
105+
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_CONTENTS_TEXT),
81106
contents_font));
82107
contents_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
83108
contents_label->SetMultiLine(true);
84109
constexpr int kMaxWidth = 350;
85110
contents_label->SetMaximumWidth(kMaxWidth);
86111
}
87112

88-
FirstRunDialogWin::~FirstRunDialogWin() = default;
113+
BraveFirstRunDialog::~BraveFirstRunDialog() = default;
89114

90-
void FirstRunDialogWin::Done() {
115+
void BraveFirstRunDialog::Done() {
91116
CHECK(!quit_runloop_.is_null());
92117
quit_runloop_.Run();
93118
}
94119

95-
bool FirstRunDialogWin::Accept() {
120+
bool BraveFirstRunDialog::Accept() {
96121
GetWidget()->Hide();
97122

123+
#if BUILDFLAG(IS_WIN)
98124
base::MakeRefCounted<shell_integration::BraveDefaultBrowserWorker>()
99125
->StartSetAsDefault(base::NullCallback());
126+
#else
127+
shell_integration::SetAsDefaultBrowser();
128+
#endif
100129

101130
Done();
102131
return true;
103132
}
104133

105-
void FirstRunDialogWin::WindowClosing() {
134+
void BraveFirstRunDialog::WindowClosing() {
106135
first_run::SetShouldShowWelcomePage();
107136
Done();
108137
}
109138

110-
BEGIN_METADATA(FirstRunDialogWin, views::DialogDelegateView)
139+
BEGIN_METADATA(BraveFirstRunDialog, views::DialogDelegateView)
111140
END_METADATA

browser/ui/views/first_run_dialog_win.h renamed to browser/ui/views/brave_first_run_dialog.h

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@
33
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
44
* You can obtain one at http://mozilla.org/MPL/2.0/. */
55

6-
#ifndef BRAVE_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_WIN_H_
7-
#define BRAVE_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_WIN_H_
6+
#ifndef BRAVE_BROWSER_UI_VIEWS_BRAVE_FIRST_RUN_DIALOG_H_
7+
#define BRAVE_BROWSER_UI_VIEWS_BRAVE_FIRST_RUN_DIALOG_H_
88

99
#include "base/callback.h"
1010
#include "ui/base/metadata/metadata_header_macros.h"
1111
#include "ui/views/window/dialog_delegate.h"
1212

13-
class FirstRunDialogWin : public views::DialogDelegateView {
13+
class BraveFirstRunDialog : public views::DialogDelegateView {
1414
public:
15-
METADATA_HEADER(FirstRunDialogWin);
15+
METADATA_HEADER(BraveFirstRunDialog);
1616

17-
FirstRunDialogWin(const FirstRunDialogWin&) = delete;
18-
FirstRunDialogWin& operator=(const FirstRunDialogWin&) = delete;
17+
BraveFirstRunDialog(const BraveFirstRunDialog&) = delete;
18+
BraveFirstRunDialog& operator=(const BraveFirstRunDialog&) = delete;
1919

2020
static void Show(base::RepeatingClosure quit_runloop);
2121

2222
private:
23-
explicit FirstRunDialogWin(base::RepeatingClosure quit_runloop);
24-
~FirstRunDialogWin() override;
23+
explicit BraveFirstRunDialog(base::RepeatingClosure quit_runloop);
24+
~BraveFirstRunDialog() override;
2525

2626
// This terminates the nested message-loop.
2727
void Done();
@@ -35,4 +35,4 @@ class FirstRunDialogWin : public views::DialogDelegateView {
3535
base::RepeatingClosure quit_runloop_;
3636
};
3737

38-
#endif // BRAVE_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_WIN_H_
38+
#endif // BRAVE_BROWSER_UI_VIEWS_BRAVE_FIRST_RUN_DIALOG_H_

chromium_src/chrome/browser/ui/views/first_run_dialog.cc

+5-126
Original file line numberDiff line numberDiff line change
@@ -3,131 +3,10 @@
33
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
44
* You can obtain one at http://mozilla.org/MPL/2.0/. */
55

6-
#include "chrome/browser/ui/views/first_run_dialog.h"
6+
// We use our own FirstRun dialog on Windows/Linux.
7+
// ShowFirstRunDialog() is re-defined at brave_first_run_dialog.cc.
8+
#define ShowFirstRunDialog ShowFirstRunDialog_UnUsed
79

8-
#include <string>
10+
#include "src/chrome/browser/ui/views/first_run_dialog.cc"
911

10-
#include "base/bind.h"
11-
#include "base/run_loop.h"
12-
#include "brave/grit/brave_generated_resources.h"
13-
#include "build/build_config.h"
14-
#include "chrome/browser/first_run/first_run.h"
15-
#include "chrome/browser/first_run/first_run_dialog.h"
16-
#include "chrome/browser/platform_util.h"
17-
#include "chrome/browser/shell_integration.h"
18-
#include "chrome/browser/ui/browser_dialogs.h"
19-
#include "chrome/browser/ui/ui_features.h"
20-
#include "chrome/common/url_constants.h"
21-
#include "chrome/grit/chromium_strings.h"
22-
#include "chrome/grit/generated_resources.h"
23-
#include "components/strings/grit/components_strings.h"
24-
#include "ui/base/l10n/l10n_util.h"
25-
#include "ui/base/metadata/metadata_impl_macros.h"
26-
#include "ui/views/border.h"
27-
#include "ui/views/controls/button/checkbox.h"
28-
#include "ui/views/controls/link.h"
29-
#include "ui/views/layout/box_layout.h"
30-
#include "ui/views/widget/widget.h"
31-
#include "ui/views/window/dialog_delegate.h"
32-
33-
namespace first_run {
34-
35-
void ShowFirstRunDialog(Profile* profile) {
36-
#if BUILDFLAG(IS_MAC)
37-
if (base::FeatureList::IsEnabled(features::kViewsFirstRunDialog))
38-
ShowFirstRunDialogViews(profile);
39-
else
40-
ShowFirstRunDialogCocoa(profile);
41-
#else
42-
ShowFirstRunDialogViews(profile);
43-
#endif
44-
}
45-
46-
void ShowFirstRunDialogViews(Profile* profile) {
47-
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
48-
FirstRunDialog::Show(
49-
base::BindRepeating(&platform_util::OpenExternal,
50-
base::Unretained(profile),
51-
GURL(chrome::kLearnMoreReportingURL)),
52-
run_loop.QuitClosure());
53-
run_loop.Run();
54-
}
55-
56-
} // namespace first_run
57-
58-
// static
59-
void FirstRunDialog::Show(base::RepeatingClosure learn_more_callback,
60-
base::RepeatingClosure quit_runloop) {
61-
FirstRunDialog* dialog = new FirstRunDialog(std::move(learn_more_callback),
62-
std::move(quit_runloop));
63-
views::DialogDelegate::CreateDialogWidget(dialog, NULL, NULL)->Show();
64-
}
65-
66-
FirstRunDialog::FirstRunDialog(base::RepeatingClosure learn_more_callback,
67-
base::RepeatingClosure quit_runloop)
68-
: quit_runloop_(quit_runloop) {
69-
// ALLOW_UNUSED_LOCAL has been removed and [[maybe_unused]] can only be used
70-
// alongside declarations, so reference it here just to silence the compiler's
71-
// -Wunused errors without having to override the header file.
72-
if (report_crashes_)
73-
report_crashes_->GetChecked();
74-
75-
SetTitle(l10n_util::GetStringUTF16(IDS_FIRST_RUN_DIALOG_WINDOW_TITLE));
76-
SetButtons(ui::DIALOG_BUTTON_OK);
77-
SetExtraView(
78-
std::make_unique<views::Link>(l10n_util::GetStringUTF16(IDS_LEARN_MORE)))
79-
->SetCallback(std::move(learn_more_callback));
80-
81-
constexpr int kChildSpacing = 16;
82-
constexpr int kPadding = 24;
83-
84-
SetLayoutManager(std::make_unique<views::BoxLayout>(
85-
views::BoxLayout::Orientation::kVertical,
86-
gfx::Insets(kPadding, kPadding, kPadding, kPadding), kChildSpacing));
87-
88-
constexpr int kFontSize = 15;
89-
int size_diff = kFontSize - views::Label::GetDefaultFontList().GetFontSize();
90-
views::Label::CustomFont contents_font = {
91-
views::Label::GetDefaultFontList()
92-
.DeriveWithSizeDelta(size_diff)
93-
.DeriveWithWeight(gfx::Font::Weight::NORMAL)};
94-
auto* contents_label = AddChildView(std::make_unique<views::Label>(
95-
l10n_util::GetStringUTF16(
96-
IDS_FIRSTRUN_DLG_COMPLETE_INSTALLATION_LABEL_BRAVE),
97-
contents_font));
98-
contents_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
99-
contents_label->SetMultiLine(true);
100-
constexpr int kMaxWidth = 450;
101-
contents_label->SetMaximumWidth(kMaxWidth);
102-
103-
make_default_ = AddChildView(std::make_unique<views::Checkbox>(
104-
l10n_util::GetStringUTF16(IDS_FR_CUSTOMIZE_DEFAULT_BROWSER_BRAVE)));
105-
make_default_->SetChecked(true);
106-
107-
chrome::RecordDialogCreation(chrome::DialogIdentifier::FIRST_RUN_DIALOG);
108-
}
109-
110-
FirstRunDialog::~FirstRunDialog() = default;
111-
112-
void FirstRunDialog::Done() {
113-
CHECK(!quit_runloop_.is_null());
114-
quit_runloop_.Run();
115-
}
116-
117-
bool FirstRunDialog::Accept() {
118-
GetWidget()->Hide();
119-
120-
if (make_default_->GetChecked())
121-
shell_integration::SetAsDefaultBrowser();
122-
123-
Done();
124-
return true;
125-
}
126-
127-
void FirstRunDialog::WindowClosing() {
128-
first_run::SetShouldShowWelcomePage();
129-
Done();
130-
}
131-
132-
BEGIN_METADATA(FirstRunDialog, views::DialogDelegateView)
133-
END_METADATA
12+
#undef ShowFirstRunDialog

0 commit comments

Comments
 (0)