-
Notifications
You must be signed in to change notification settings - Fork 877
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12692 from brave/uplift_windows_default_dialog_1.…
…37.x Launch FirstRun dialog on Windows (uplift to 1.37.x)
- Loading branch information
Showing
7 changed files
with
240 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* 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 "brave/browser/ui/views/first_run_dialog_win.h" | ||
|
||
#include <memory> | ||
#include <utility> | ||
|
||
#include "base/bind.h" | ||
#include "base/memory/scoped_refptr.h" | ||
#include "base/run_loop.h" | ||
#include "brave/browser/brave_shell_integration.h" | ||
#include "brave/grit/brave_generated_resources.h" | ||
#include "chrome/browser/first_run/first_run.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "ui/base/metadata/metadata_impl_macros.h" | ||
#include "ui/gfx/font.h" | ||
#include "ui/gfx/geometry/insets.h" | ||
#include "ui/views/controls/label.h" | ||
#include "ui/views/layout/box_layout.h" | ||
#include "ui/views/window/dialog_delegate.h" | ||
|
||
namespace first_run { | ||
|
||
void ShowFirstRunDialog(Profile* profile) { | ||
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed); | ||
FirstRunDialogWin::Show(run_loop.QuitClosure()); | ||
run_loop.Run(); | ||
} | ||
|
||
} // namespace first_run | ||
|
||
// static | ||
void FirstRunDialogWin::Show(base::RepeatingClosure quit_runloop) { | ||
FirstRunDialogWin* dialog = new FirstRunDialogWin(std::move(quit_runloop)); | ||
views::DialogDelegate::CreateDialogWidget(dialog, NULL, NULL)->Show(); | ||
} | ||
|
||
FirstRunDialogWin::FirstRunDialogWin(base::RepeatingClosure quit_runloop) | ||
: quit_runloop_(quit_runloop) { | ||
set_should_ignore_snapping(true); | ||
SetButtonLabel( | ||
ui::DIALOG_BUTTON_OK, | ||
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_OK_BUTTON_LABEL)); | ||
SetButtonLabel( | ||
ui::DIALOG_BUTTON_CANCEL, | ||
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_CANCEL_BUTTON_LABEL)); | ||
constexpr int kChildSpacing = 16; | ||
constexpr int kPadding = 24; | ||
constexpr int kTopPadding = 20; | ||
constexpr int kBottomPadding = 55; | ||
|
||
SetLayoutManager(std::make_unique<views::BoxLayout>( | ||
views::BoxLayout::Orientation::kVertical, | ||
gfx::Insets(kTopPadding, kPadding, kBottomPadding, kPadding), | ||
kChildSpacing)); | ||
|
||
constexpr int kHeaderFontSize = 16; | ||
int size_diff = | ||
kHeaderFontSize - views::Label::GetDefaultFontList().GetFontSize(); | ||
views::Label::CustomFont header_font = { | ||
views::Label::GetDefaultFontList() | ||
.DeriveWithSizeDelta(size_diff) | ||
.DeriveWithWeight(gfx::Font::Weight::SEMIBOLD)}; | ||
auto* header_label = AddChildView(std::make_unique<views::Label>( | ||
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_HEADER_TEXT), | ||
header_font)); | ||
header_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | ||
|
||
constexpr int kContentFontSize = 15; | ||
size_diff = | ||
kContentFontSize - views::Label::GetDefaultFontList().GetFontSize(); | ||
views::Label::CustomFont contents_font = { | ||
views::Label::GetDefaultFontList() | ||
.DeriveWithSizeDelta(size_diff) | ||
.DeriveWithWeight(gfx::Font::Weight::NORMAL)}; | ||
auto* contents_label = AddChildView(std::make_unique<views::Label>( | ||
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_WIN_CONTENTS_TEXT), | ||
contents_font)); | ||
contents_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | ||
contents_label->SetMultiLine(true); | ||
constexpr int kMaxWidth = 350; | ||
contents_label->SetMaximumWidth(kMaxWidth); | ||
} | ||
|
||
FirstRunDialogWin::~FirstRunDialogWin() = default; | ||
|
||
void FirstRunDialogWin::Done() { | ||
CHECK(!quit_runloop_.is_null()); | ||
quit_runloop_.Run(); | ||
} | ||
|
||
bool FirstRunDialogWin::Accept() { | ||
GetWidget()->Hide(); | ||
|
||
base::MakeRefCounted<shell_integration::BraveDefaultBrowserWorker>() | ||
->StartSetAsDefault(base::NullCallback()); | ||
|
||
Done(); | ||
return true; | ||
} | ||
|
||
void FirstRunDialogWin::WindowClosing() { | ||
first_run::SetShouldShowWelcomePage(); | ||
Done(); | ||
} | ||
|
||
BEGIN_METADATA(FirstRunDialogWin, views::DialogDelegateView) | ||
END_METADATA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* 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_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_WIN_H_ | ||
#define BRAVE_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_WIN_H_ | ||
|
||
#include "base/callback.h" | ||
#include "ui/base/metadata/metadata_header_macros.h" | ||
#include "ui/views/window/dialog_delegate.h" | ||
|
||
class FirstRunDialogWin : public views::DialogDelegateView { | ||
public: | ||
METADATA_HEADER(FirstRunDialogWin); | ||
|
||
FirstRunDialogWin(const FirstRunDialogWin&) = delete; | ||
FirstRunDialogWin& operator=(const FirstRunDialogWin&) = delete; | ||
|
||
static void Show(base::RepeatingClosure quit_runloop); | ||
|
||
private: | ||
explicit FirstRunDialogWin(base::RepeatingClosure quit_runloop); | ||
~FirstRunDialogWin() override; | ||
|
||
// This terminates the nested message-loop. | ||
void Done(); | ||
|
||
// views::DialogDelegate overrides: | ||
bool Accept() override; | ||
|
||
// views::WidgetDelegate overrides: | ||
void WindowClosing() override; | ||
|
||
base::RepeatingClosure quit_runloop_; | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_UI_VIEWS_FIRST_RUN_DIALOG_WIN_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* 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); | ||
|
||
} // 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
40
chromium_src/chrome/browser/first_run/first_run_internal_win.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters