|
| 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 from upstream and p3a prefs part added. |
| 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 |
0 commit comments