From dd6e135121729a66e466a58b8668d5b4dd9493ca Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Fri, 4 Mar 2022 16:45:48 +0900 Subject: [PATCH] Use first run dialog on Windows fix https://github.com/brave/brave-browser/issues/21464 Enabled first run dialog on Windows. --- app/brave_generated_resources.grd | 3 ++ browser/ui/BUILD.gn | 9 +++++ .../browser/first_run/first_run_dialog.h | 28 +++++++++++++ .../first_run/first_run_internal_win.cc | 40 +++++++++++++++++++ .../browser/ui/views/first_run_dialog.cc | 24 +++++++---- 5 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 chromium_src/chrome/browser/first_run/first_run_dialog.h create mode 100644 chromium_src/chrome/browser/first_run/first_run_internal_win.cc diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd index 92ad474efdaa..dbf687ac2621 100644 --- a/app/brave_generated_resources.grd +++ b/app/brave_generated_resources.grd @@ -1650,6 +1650,9 @@ Are you sure you want to do this? 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. + + Welcome to Brave + Networks diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index 56b946489655..0de8e5fd638d 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -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", diff --git a/chromium_src/chrome/browser/first_run/first_run_dialog.h b/chromium_src/chrome/browser/first_run/first_run_dialog.h new file mode 100644 index 000000000000..45202af888f1 --- /dev/null +++ b/chromium_src/chrome/browser/first_run/first_run_dialog.h @@ -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_ diff --git a/chromium_src/chrome/browser/first_run/first_run_internal_win.cc b/chromium_src/chrome/browser/first_run/first_run_internal_win.cc new file mode 100644 index 000000000000..46ecb78f71ea --- /dev/null +++ b/chromium_src/chrome/browser/first_run/first_run_internal_win.cc @@ -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 diff --git a/chromium_src/chrome/browser/ui/views/first_run_dialog.cc b/chromium_src/chrome/browser/ui/views/first_run_dialog.cc index f5328cd1e797..8df1f94b28a6 100644 --- a/chromium_src/chrome/browser/ui/views/first_run_dialog.cc +++ b/chromium_src/chrome/browser/ui/views/first_run_dialog.cc @@ -8,22 +8,19 @@ #include #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" @@ -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 @@ -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(l10n_util::GetStringUTF16(IDS_LEARN_MORE))) @@ -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() + ->StartSetAsDefault(base::NullCallback()); +#else shell_integration::SetAsDefaultBrowser(); +#endif + } Done(); return true;