Skip to content

Commit 48feb39

Browse files
committed
Launch first run dialog on macOS
Fix brave/brave-browser#12679
1 parent a02f479 commit 48feb39

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed

app/brave_generated_resources.grd

+6
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,12 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
10331033
<message name="IDS_SETTINGS_RESET_REWARDS_DATA" desc="The label for opening rewards manage wallet dialog">
10341034
Reset Brave Rewards data...
10351035
</message>
1036+
<!--First-run dialog messages -->
1037+
<if expr="is_macosx">
1038+
<message name="IDS_FIRSTRUN_DLG_MAC_OPTIONS_SEND_USAGE_STATS_LABEL_BRAVE" desc="Label for checkbox to ask whether to send usage stats to Google">
1039+
Help improve <ph name="PRODUCT_NAME">$1<ex>Brave</ex></ph> by sending crash reports and completely anonymised, private product analytics.
1040+
</message>
1041+
</if>
10361042
</messages>
10371043
</release>
10381044
</grit>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "chrome/browser/first_run/first_run_internal.h"
7+
8+
#include "base/files/file_path.h"
9+
#include "base/files/file_util.h"
10+
#include "base/no_destructor.h"
11+
#include "base/path_service.h"
12+
#include "build/branding_buildflags.h"
13+
#include "build/build_config.h"
14+
#include "chrome/browser/browser_process.h"
15+
#include "chrome/browser/first_run/first_run.h"
16+
#include "chrome/browser/first_run/first_run_dialog.h"
17+
#include "chrome/browser/metrics/metrics_reporting_state.h"
18+
#include "chrome/common/chrome_constants.h"
19+
#include "chrome/common/chrome_paths.h"
20+
#include "chrome/common/chrome_switches.h"
21+
#include "chrome/installer/util/google_update_settings.h"
22+
#include "chrome/installer/util/initial_preferences.h"
23+
#include "components/metrics/metrics_pref_names.h"
24+
#include "components/metrics/metrics_reporting_default_state.h"
25+
#include "components/prefs/pref_service.h"
26+
#include "components/startup_metric_utils/browser/startup_metric_utils.h"
27+
28+
// All above headers copied from original first_run_internal_posix.cc are
29+
// included to prevent below GOOGLE_CHROEM_BUILD affect them.
30+
31+
// First run dialog is only enabled for google chrome by default.
32+
#if defined(OFFICIAL_BUILD) && defined(OS_MAC)
33+
#undef BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING
34+
#define BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING() (1)
35+
#endif
36+
#include "../../../../../chrome/browser/first_run/first_run_internal_posix.cc"
37+
#if defined(OFFICIAL_BUILD) && defined(OS_MAC)
38+
#undef BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING
39+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "brave/components/p3a/buildflags.h"
7+
#include "chrome/browser/browser_process.h"
8+
#include "components/prefs/pref_service.h"
9+
10+
#if BUILDFLAG(BRAVE_P3A_ENABLED)
11+
#include "brave/components/p3a/pref_names.h"
12+
#endif
13+
14+
#define ShowFirstRunDialog ShowFirstRunDialog_UnUsed
15+
#include "../../../../../../chrome/browser/ui/cocoa/first_run_dialog.mm"
16+
#undef ShowFirstRunDialog
17+
18+
namespace {
19+
20+
// Copied ShowFirstRunModal and set p3a prefs.
21+
void ShowFirstRunModalBrave(Profile* profile) {
22+
base::scoped_nsobject<FirstRunDialogController> dialog(
23+
[[FirstRunDialogController alloc] init]);
24+
25+
[dialog.get() showWindow:nil];
26+
27+
// If the dialog asked the user to opt-in for stats and crash reporting,
28+
// record the decision and enable the crash reporter if appropriate.
29+
bool consent_given = [dialog.get() isStatsReportingEnabled];
30+
ChangeMetricsReportingState(consent_given);
31+
32+
#if BUILDFLAG(BRAVE_P3A_ENABLED)
33+
PrefService* local_state = g_browser_process->local_state();
34+
local_state->SetBoolean(brave::kP3AEnabled, consent_given);
35+
#endif
36+
37+
// If selected, set as default browser. Skip in automated tests so that an OS
38+
// dialog confirming the default browser choice isn't left on screen.
39+
BOOL make_default_browser =
40+
[dialog.get() isMakeDefaultBrowserEnabled] &&
41+
!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType);
42+
if (make_default_browser) {
43+
bool success = shell_integration::SetAsDefaultBrowser();
44+
DCHECK(success);
45+
}
46+
}
47+
} // namespace
48+
49+
namespace first_run {
50+
51+
void ShowFirstRunDialog(Profile* profile) {
52+
ShowFirstRunModalBrave(profile);
53+
}
54+
55+
} // namespace first_run
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* Copyright (c) 2020 The Brave Authors. All rights reserved.
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
#include "brave/grit/brave_generated_resources.h"
7+
#include "chrome/grit/generated_resources.h"
8+
9+
// Replaced string here instead of by running 'npm run chromium_rebase_l10n'
10+
// because string replacement failed with string that include place holder like
11+
// <ph name="PRODUCT_NAME">$1<ex>Brave</ex></ph>. I assume this include some
12+
// special charactors.
13+
#undef IDS_FIRSTRUN_DLG_MAC_OPTIONS_SEND_USAGE_STATS_LABEL
14+
#define IDS_FIRSTRUN_DLG_MAC_OPTIONS_SEND_USAGE_STATS_LABEL \
15+
IDS_FIRSTRUN_DLG_MAC_OPTIONS_SEND_USAGE_STATS_LABEL_BRAVE
16+
#include "../../../../../../chrome/browser/ui/cocoa/first_run_dialog_controller.mm"
17+
#undef IDS_FIRSTRUN_DLG_MAC_OPTIONS_SEND_USAGE_STATS_LABEL

0 commit comments

Comments
 (0)