Skip to content

Commit

Permalink
Use first run dialog on Windows
Browse files Browse the repository at this point in the history
fix brave/brave-browser#21464
Enabled first run dialog on Windows.
  • Loading branch information
simonhong committed Mar 22, 2022
1 parent aed6276 commit dd6e135
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 7 deletions.
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1650,6 +1650,9 @@ 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>
<message name="IDS_FIRSTRUN_DIALOG_WINDOW_TITLE_BRAVE" desc="Window title of First Run dialog, displayed in title bar">
Welcome to Brave
</message>
<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",
]

# Enable FirstRun dialog on Win.
# Upstream only includes it on mac/Linux.
if (is_win) {
sources += [
"//chrome/browser/ui/views/first_run_dialog.cc",
"//chrome/browser/ui/views/first_run_dialog.h",
]
}

if (use_aura) {
sources += [
"views/renderer_context_menu/brave_render_view_context_menu_views.cc",
Expand Down
28 changes: 28 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,28 @@
/* 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);
void ShowFirstRunDialogViews(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
24 changes: 17 additions & 7 deletions chromium_src/chrome/browser/ui/views/first_run_dialog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@
#include <string>

#include "base/bind.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "brave/grit/brave_generated_resources.h"
#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 @@ -34,10 +31,14 @@
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"

#if BUILDFLAG(IS_WIN)
#include "brave/browser/brave_shell_integration.h"
#endif

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 Expand Up @@ -72,7 +73,7 @@ FirstRunDialog::FirstRunDialog(base::RepeatingClosure learn_more_callback,
: quit_runloop_(quit_runloop) {
ALLOW_UNUSED_LOCAL(report_crashes_);

SetTitle(l10n_util::GetStringUTF16(IDS_FIRST_RUN_DIALOG_WINDOW_TITLE));
SetTitle(l10n_util::GetStringUTF16(IDS_FIRSTRUN_DIALOG_WINDOW_TITLE_BRAVE));
SetButtons(ui::DIALOG_BUTTON_OK);
SetExtraView(
std::make_unique<views::Link>(l10n_util::GetStringUTF16(IDS_LEARN_MORE)))
Expand Down Expand Up @@ -117,8 +118,17 @@ void FirstRunDialog::Done() {
bool FirstRunDialog::Accept() {
GetWidget()->Hide();

if (make_default_->GetChecked())
if (make_default_->GetChecked()) {
// shell_integration::SetAsDefaultBrowser() doesn't work on Windows 8+.
// Upstream will use DefaultBrowserWorker when it's available on all OSs.
// See the comments of shell_integration::SetAsDefaultBrowser().
#if BUILDFLAG(IS_WIN)
base::MakeRefCounted<shell_integration::BraveDefaultBrowserWorker>()
->StartSetAsDefault(base::NullCallback());
#else
shell_integration::SetAsDefaultBrowser();
#endif
}

Done();
return true;
Expand Down

0 comments on commit dd6e135

Please sign in to comment.