Skip to content

Commit

Permalink
Launch first run dialog on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Feb 1, 2021
1 parent 5a36d78 commit e373bc5
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,12 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_RESET_REWARDS_DATA" desc="The label for opening rewards manage wallet dialog">
Reset Brave Rewards data...
</message>
<!--First-run dialog messages -->
<if expr="is_macosx">
<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">
Help improve <ph name="PRODUCT_NAME">$1<ex>Brave</ex></ph> by sending crash reports and completely anonymised, private product analytics.
</message>
</if>
</messages>
</release>
</grit>
39 changes: 39 additions & 0 deletions chromium_src/chrome/browser/first_run/first_run_internal_posix.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Copyright (c) 2020 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_internal.h"

#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.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/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/installer/util/google_update_settings.h"
#include "chrome/installer/util/initial_preferences.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_reporting_default_state.h"
#include "components/prefs/pref_service.h"
#include "components/startup_metric_utils/browser/startup_metric_utils.h"

// All above headers copied from original first_run_internal_posix.cc are
// included to prevent below GOOGLE_CHROEM_BUILD affect them.

// First run dialog is only enabled for google chrome by default.
#if defined(OFFICIAL_BUILD) && defined(OS_MAC)
#undef BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING
#define BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING() (1)
#endif
#include "../../../../../chrome/browser/first_run/first_run_internal_posix.cc"
#if defined(OFFICIAL_BUILD) && defined(OS_MAC)
#undef BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING
#endif
55 changes: 55 additions & 0 deletions chromium_src/chrome/browser/ui/cocoa/first_run_dialog.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Copyright (c) 2020 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/components/p3a/buildflags.h"
#include "chrome/browser/browser_process.h"
#include "components/prefs/pref_service.h"

#if BUILDFLAG(BRAVE_P3A_ENABLED)
#include "brave/components/p3a/pref_names.h"
#endif

#define ShowFirstRunDialog ShowFirstRunDialog_UnUsed
#include "../../../../../../chrome/browser/ui/cocoa/first_run_dialog.mm"
#undef ShowFirstRunDialog

namespace {

// Copied ShowFirstRunModal from upstream and p3a prefs part added.
void ShowFirstRunModalBrave(Profile* profile) {
base::scoped_nsobject<FirstRunDialogController> dialog(
[[FirstRunDialogController alloc] init]);

[dialog.get() showWindow:nil];

// If the dialog asked the user to opt-in for stats and crash reporting,
// record the decision and enable the crash reporter if appropriate.
bool consent_given = [dialog.get() isStatsReportingEnabled];
ChangeMetricsReportingState(consent_given);

#if BUILDFLAG(BRAVE_P3A_ENABLED)
PrefService* local_state = g_browser_process->local_state();
local_state->SetBoolean(brave::kP3AEnabled, consent_given);
#endif

// If selected, set as default browser. Skip in automated tests so that an OS
// dialog confirming the default browser choice isn't left on screen.
BOOL make_default_browser =
[dialog.get() isMakeDefaultBrowserEnabled] &&
!base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType);
if (make_default_browser) {
bool success = shell_integration::SetAsDefaultBrowser();
DCHECK(success);
}
}
} // namespace

namespace first_run {

void ShowFirstRunDialog(Profile* profile) {
ShowFirstRunModalBrave(profile);
}

} // namespace first_run
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright (c) 2020 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/grit/brave_generated_resources.h"
#include "chrome/grit/generated_resources.h"

// Replaced string here instead of by running 'npm run chromium_rebase_l10n'
// because string replacement failed with string that include place holder like
// <ph name="PRODUCT_NAME">$1<ex>Brave</ex></ph>. I assume this include some
// special charactors.
#undef IDS_FIRSTRUN_DLG_MAC_OPTIONS_SEND_USAGE_STATS_LABEL
#define IDS_FIRSTRUN_DLG_MAC_OPTIONS_SEND_USAGE_STATS_LABEL \
IDS_FIRSTRUN_DLG_MAC_OPTIONS_SEND_USAGE_STATS_LABEL_BRAVE
#include "../../../../../../chrome/browser/ui/cocoa/first_run_dialog_controller.mm"
#undef IDS_FIRSTRUN_DLG_MAC_OPTIONS_SEND_USAGE_STATS_LABEL

0 comments on commit e373bc5

Please sign in to comment.