From d454946f5802ecb922f73fca2d1ecc34e7967144 Mon Sep 17 00:00:00 2001 From: Simon Hong Date: Fri, 6 Jan 2023 11:44:58 +0900 Subject: [PATCH] Launched additional confirmation dialog to the end of support fix https://github.com/brave/brave-browser/issues/27649 When user closes infobar with checked state, additional dialog is launched to confirm user's choice again. Obsolete system infobar will not be shown again when user clicks OK. BraveConfirmDialog is introduced to support checkbox to upstream confirm dialog. --- app/brave_generated_resources.grd | 15 ++++ browser/infobars/BUILD.gn | 1 + .../infobars/brave_confirm_infobar_creator.h | 20 +++++ browser/ui/BUILD.gn | 2 + browser/ui/browser_dialogs.h | 5 ++ .../brave_obsolete_system_infobar_delegate.cc | 74 +++++++++++++--- .../brave_obsolete_system_infobar_delegate.h | 27 ++++-- browser/ui/views/infobars/BUILD.gn | 3 + .../views/infobars/brave_confirm_infobar.cc | 88 +++++++++++++++++++ .../ui/views/infobars/brave_confirm_infobar.h | 44 ++++++++++ .../obsolete_system_confirm_dialog_view.cc | 86 ++++++++++++++++++ .../obsolete_system_confirm_dialog_view.h | 31 +++++++ .../browser/ui/startup/infobar_utils.cc | 1 + .../obsolete_system_infobar_delegate.h | 20 ----- .../ui/views/infobars/confirm_infobar.h | 4 + .../browser/ui/views/infobars/infobar_view.h | 21 +++++ components/infobars/core/BUILD.gn | 13 +++ .../core/brave_confirm_infobar_delegate.cc | 23 +++++ .../core/brave_confirm_infobar_delegate.h | 32 +++++++ 19 files changed, 472 insertions(+), 38 deletions(-) create mode 100644 browser/infobars/brave_confirm_infobar_creator.h create mode 100644 browser/ui/views/infobars/brave_confirm_infobar.cc create mode 100644 browser/ui/views/infobars/brave_confirm_infobar.h create mode 100644 browser/ui/views/obsolete_system_confirm_dialog_view.cc create mode 100644 browser/ui/views/obsolete_system_confirm_dialog_view.h delete mode 100644 chromium_src/chrome/browser/ui/startup/obsolete_system_infobar_delegate.h create mode 100644 chromium_src/chrome/browser/ui/views/infobars/infobar_view.h create mode 100644 components/infobars/core/BUILD.gn create mode 100644 components/infobars/core/brave_confirm_infobar_delegate.cc create mode 100644 components/infobars/core/brave_confirm_infobar_delegate.h diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd index 03f720c8d67b..7d01156fb2b2 100644 --- a/app/brave_generated_resources.grd +++ b/app/brave_generated_resources.grd @@ -604,6 +604,21 @@ Or change later at $2brave://settings/ext Don't show again + + + By clicking OK, you acknowledge that your installation of Brave will NOT receive critical security fixes until you update to Windows 10 or later. This warning will NOT show again. + + + + + By clicking OK, you acknowledge that your installation of Brave will NOT receive critical security fixes until you update to Windows 10 or later. This warning will NOT show again. + + + + + By clicking OK, you acknowledge that your installation of Brave will NOT receive critical security fixes until you update to Windows 10 or later. This warning will NOT show again. + + diff --git a/browser/infobars/BUILD.gn b/browser/infobars/BUILD.gn index fd9605455640..2373f93bbf39 100644 --- a/browser/infobars/BUILD.gn +++ b/browser/infobars/BUILD.gn @@ -11,6 +11,7 @@ source_set("infobars") { # Remove when https://github.com/brave/brave-browser/issues/10649 is resolved check_includes = false sources = [ + "brave_confirm_infobar_creator.h", "brave_confirm_p3a_infobar_delegate.cc", "brave_confirm_p3a_infobar_delegate.h", "brave_sync_account_deleted_infobar_delegate.cc", diff --git a/browser/infobars/brave_confirm_infobar_creator.h b/browser/infobars/brave_confirm_infobar_creator.h new file mode 100644 index 000000000000..f178cacb1243 --- /dev/null +++ b/browser/infobars/brave_confirm_infobar_creator.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_INFOBARS_BRAVE_CONFIRM_INFOBAR_CREATOR_H_ +#define BRAVE_BROWSER_INFOBARS_BRAVE_CONFIRM_INFOBAR_CREATOR_H_ + +#include + +class BraveConfirmInfoBarDelegate; + +namespace infobars { +class InfoBar; +} // namespace infobars + +std::unique_ptr CreateBraveConfirmInfoBar( + std::unique_ptr delegate); + +#endif // BRAVE_BROWSER_INFOBARS_BRAVE_CONFIRM_INFOBAR_CREATOR_H_ diff --git a/browser/ui/BUILD.gn b/browser/ui/BUILD.gn index a49470687436..73c1a4b2c192 100644 --- a/browser/ui/BUILD.gn +++ b/browser/ui/BUILD.gn @@ -242,6 +242,8 @@ source_set("ui") { "views/frame/brave_opaque_browser_frame_view.h", "views/frame/brave_window_frame_graphic.cc", "views/frame/brave_window_frame_graphic.h", + "views/obsolete_system_confirm_dialog_view.cc", + "views/obsolete_system_confirm_dialog_view.h", "views/omnibox/brave_omnibox_popup_contents_view.cc", "views/omnibox/brave_omnibox_popup_contents_view.h", "views/omnibox/brave_omnibox_result_view.cc", diff --git a/browser/ui/browser_dialogs.h b/browser/ui/browser_dialogs.h index 566d3a9cd92e..2eb4b26549cb 100644 --- a/browser/ui/browser_dialogs.h +++ b/browser/ui/browser_dialogs.h @@ -6,6 +6,8 @@ #ifndef BRAVE_BROWSER_UI_BROWSER_DIALOGS_H_ #define BRAVE_BROWSER_UI_BROWSER_DIALOGS_H_ +#include "base/callback_forward.h" + class Browser; namespace brave { @@ -13,6 +15,9 @@ namespace brave { // Tab restore dialog will be launched after ask dialog is closed. void ShowCrashReportPermissionAskDialog(Browser* browser); +// Run |callback| when dialog closed. +void ShowObsoleteSystemConfirmDialog(base::OnceCallback callback); + } // namespace brave #endif // BRAVE_BROWSER_UI_BROWSER_DIALOGS_H_ diff --git a/browser/ui/startup/brave_obsolete_system_infobar_delegate.cc b/browser/ui/startup/brave_obsolete_system_infobar_delegate.cc index bb32b6201dbc..33ffb00fa94f 100644 --- a/browser/ui/startup/brave_obsolete_system_infobar_delegate.cc +++ b/browser/ui/startup/brave_obsolete_system_infobar_delegate.cc @@ -3,23 +3,29 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#include "brave/browser/ui/startup/brave_obsolete_system_infobar_delegate.h" + #include -#include "brave/browser/ui/startup/brave_obsolete_system_infobar_delegate.h" +#include "base/bind.h" +#include "brave/browser/infobars/brave_confirm_infobar_creator.h" +#include "brave/browser/ui/browser_dialogs.h" #include "brave/grit/brave_generated_resources.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/infobars/confirm_infobar_creator.h" +#include "chrome/browser/obsolete_system/obsolete_system.h" #include "chrome/common/pref_names.h" #include "components/infobars/content/content_infobar_manager.h" #include "components/infobars/core/infobar.h" #include "components/prefs/pref_service.h" +#include "components/strings/grit/components_strings.h" #include "ui/base/l10n/l10n_util.h" // static void BraveObsoleteSystemInfoBarDelegate::Create( infobars::ContentInfoBarManager* infobar_manager) { infobar_manager->AddInfoBar( - CreateConfirmInfoBar(std::unique_ptr( + CreateBraveConfirmInfoBar(std::unique_ptr( new BraveObsoleteSystemInfoBarDelegate()))); } @@ -28,19 +34,67 @@ BraveObsoleteSystemInfoBarDelegate::BraveObsoleteSystemInfoBarDelegate() = BraveObsoleteSystemInfoBarDelegate::~BraveObsoleteSystemInfoBarDelegate() = default; -int BraveObsoleteSystemInfoBarDelegate::GetButtons() const { - return BUTTON_OK; +bool BraveObsoleteSystemInfoBarDelegate::HasCheckbox() const { + return true; } -std::u16string BraveObsoleteSystemInfoBarDelegate::GetButtonLabel( - InfoBarButton button) const { +std::u16string BraveObsoleteSystemInfoBarDelegate::GetCheckboxText() const { return l10n_util::GetStringUTF16( IDS_OBSOLERE_SYSTEM_INFOBAR_DONT_SHOW_BUTTON); } -bool BraveObsoleteSystemInfoBarDelegate::Accept() { - if (PrefService* local_state = g_browser_process->local_state()) { - local_state->SetBoolean(prefs::kSuppressUnsupportedOSWarning, true); - } +void BraveObsoleteSystemInfoBarDelegate::SetCheckboxChecked(bool checked) { + launch_confirmation_dialog_ = checked; +} + +bool BraveObsoleteSystemInfoBarDelegate::InterceptClosing() { + if (!launch_confirmation_dialog_) + return false; + + // This infobar will be destroyed after confirmation dialog closed. + brave::ShowObsoleteSystemConfirmDialog(base::BindOnce( + &BraveObsoleteSystemInfoBarDelegate::OnConfirmDialogClosing, + weak_factory_.GetWeakPtr())); return true; } + +int BraveObsoleteSystemInfoBarDelegate::GetButtons() const { + return BUTTON_NONE; +} + +void BraveObsoleteSystemInfoBarDelegate::OnConfirmDialogClosing(bool suppress) { + if (suppress) { + if (PrefService* local_state = g_browser_process->local_state()) { + local_state->SetBoolean(prefs::kSuppressUnsupportedOSWarning, true); + } + } + + // infobar()->RemoveSelf() will destroy this also. + // Do not refer anything after this. + infobar()->RemoveSelf(); +} + +infobars::InfoBarDelegate::InfoBarIdentifier +BraveObsoleteSystemInfoBarDelegate::GetIdentifier() const { + return OBSOLETE_SYSTEM_INFOBAR_DELEGATE; +} + +std::u16string BraveObsoleteSystemInfoBarDelegate::GetLinkText() const { + return l10n_util::GetStringUTF16(IDS_LEARN_MORE); +} + +GURL BraveObsoleteSystemInfoBarDelegate::GetLinkURL() const { + return GURL(ObsoleteSystem::GetLinkURL()); +} + +std::u16string BraveObsoleteSystemInfoBarDelegate::GetMessageText() const { + return ObsoleteSystem::LocalizedObsoleteString(); +} + +bool BraveObsoleteSystemInfoBarDelegate::ShouldExpire( + const NavigationDetails& details) const { + // Since the obsolete system infobar communicates critical state ("your system + // is no longer receiving updates") it should persist until explicitly + // dismissed. + return false; +} diff --git a/browser/ui/startup/brave_obsolete_system_infobar_delegate.h b/browser/ui/startup/brave_obsolete_system_infobar_delegate.h index d30854e501c0..14a2f66270e4 100644 --- a/browser/ui/startup/brave_obsolete_system_infobar_delegate.h +++ b/browser/ui/startup/brave_obsolete_system_infobar_delegate.h @@ -8,16 +8,14 @@ #include -#include "chrome/browser/ui/startup/obsolete_system_infobar_delegate.h" +#include "base/memory/weak_ptr.h" +#include "brave/components/infobars/core/brave_confirm_infobar_delegate.h" namespace infobars { class ContentInfoBarManager; } // namespace infobars -// Subclassed for showing "Don't show again" button. -// W/o this button, user will see this infobar whenever launched. -class BraveObsoleteSystemInfoBarDelegate - : public ObsoleteSystemInfoBarDelegate { +class BraveObsoleteSystemInfoBarDelegate : public BraveConfirmInfoBarDelegate { public: static void Create(infobars::ContentInfoBarManager* infobar_manager); @@ -30,10 +28,23 @@ class BraveObsoleteSystemInfoBarDelegate BraveObsoleteSystemInfoBarDelegate(); ~BraveObsoleteSystemInfoBarDelegate() override; - // ObsoleteSystemInfoBarDelegate overrides: + // BraveConfirmInfoBarDelegate overrides: + bool HasCheckbox() const override; + std::u16string GetCheckboxText() const override; + void SetCheckboxChecked(bool checked) override; + bool InterceptClosing() override; + infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; + std::u16string GetLinkText() const override; + GURL GetLinkURL() const override; + std::u16string GetMessageText() const override; int GetButtons() const override; - std::u16string GetButtonLabel(InfoBarButton button) const override; - bool Accept() override; + bool ShouldExpire(const NavigationDetails& details) const override; + + void OnConfirmDialogClosing(bool suppress); + + bool launch_confirmation_dialog_ = false; + + base::WeakPtrFactory weak_factory_{this}; }; #endif // BRAVE_BROWSER_UI_STARTUP_BRAVE_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_ diff --git a/browser/ui/views/infobars/BUILD.gn b/browser/ui/views/infobars/BUILD.gn index f5e543fcc755..14bbee0ff680 100644 --- a/browser/ui/views/infobars/BUILD.gn +++ b/browser/ui/views/infobars/BUILD.gn @@ -10,6 +10,8 @@ source_set("infobars") { check_includes = false sources = [ + "brave_confirm_infobar.cc", + "brave_confirm_infobar.h", "brave_infobar_container_view.cc", "brave_infobar_container_view.h", "custom_styled_label.cc", @@ -26,6 +28,7 @@ source_set("infobars") { "//brave/app/theme:brave_theme_resources", "//brave/app/vector_icons", "//brave/components/constants", + "//brave/components/infobars/core", "//components/infobars/core", "//content/public/browser", "//third_party/abseil-cpp:absl", diff --git a/browser/ui/views/infobars/brave_confirm_infobar.cc b/browser/ui/views/infobars/brave_confirm_infobar.cc new file mode 100644 index 000000000000..e62eb46cb293 --- /dev/null +++ b/browser/ui/views/infobars/brave_confirm_infobar.cc @@ -0,0 +1,88 @@ +/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/ui/views/infobars/brave_confirm_infobar.h" + +#include +#include + +#include "base/bind.h" +#include "ui/base/metadata/metadata_impl_macros.h" +#include "ui/views/controls/button/checkbox.h" + +namespace { + +constexpr int kCheckboxSpacing = 20; + +} // namespace + +std::unique_ptr CreateBraveConfirmInfoBar( + std::unique_ptr delegate) { + return std::make_unique(std::move(delegate)); +} + +BraveConfirmInfoBar::BraveConfirmInfoBar( + std::unique_ptr delegate) + : ConfirmInfoBar(std::move(delegate)) { + auto* delegate_ptr = GetBraveDelegate(); + DCHECK(delegate_ptr); + + if (delegate_ptr->HasCheckbox()) { + // We don't consider case where ok/cancel button and check box exist + // together. + DCHECK(!ok_button_ && !cancel_button_); + checkbox_ = AddChildView(std::make_unique( + delegate_ptr->GetCheckboxText(), + base::BindRepeating(&BraveConfirmInfoBar::CheckboxPressed, + base::Unretained(this)))); + } +} + +BraveConfirmInfoBar::~BraveConfirmInfoBar() = default; + +void BraveConfirmInfoBar::Layout() { + ConfirmInfoBar::Layout(); + + // Early return when checkbox is not used. + // This class is only valid when this infobar has checkbox now. + // NOTE: Revisit when we want to use other buttons together with checkbox. + if (!checkbox_) + return; + + checkbox_->SizeToPreferredSize(); + + const int x = label_->bounds().right() + kCheckboxSpacing; + checkbox_->SetPosition(gfx::Point(x, OffsetY(checkbox_))); +} + +BraveConfirmInfoBarDelegate* BraveConfirmInfoBar::GetBraveDelegate() { + return static_cast( + ConfirmInfoBar::GetDelegate()); +} + +void BraveConfirmInfoBar::CheckboxPressed() { + GetBraveDelegate()->SetCheckboxChecked(checkbox_->GetChecked()); +} + +int BraveConfirmInfoBar::NonLabelWidth() const { + const int width = ConfirmInfoBar::NonLabelWidth(); + + // Early return when checkbox is not used. + // This class is only valid when this infobar has checkbox now. + if (!checkbox_) + return width; + + return width + checkbox_->width() + kCheckboxSpacing; +} + +void BraveConfirmInfoBar::CloseButtonPressed() { + if (GetBraveDelegate()->InterceptClosing()) + return; + + ConfirmInfoBar::CloseButtonPressed(); +} + +BEGIN_METADATA(BraveConfirmInfoBar, ConfirmInfoBar) +END_METADATA diff --git a/browser/ui/views/infobars/brave_confirm_infobar.h b/browser/ui/views/infobars/brave_confirm_infobar.h new file mode 100644 index 000000000000..9abc4b77d84d --- /dev/null +++ b/browser/ui/views/infobars/brave_confirm_infobar.h @@ -0,0 +1,44 @@ +/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_CONFIRM_INFOBAR_H_ +#define BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_CONFIRM_INFOBAR_H_ + +#include + +#include "base/memory/raw_ptr.h" +#include "brave/components/infobars/core/brave_confirm_infobar_delegate.h" +#include "chrome/browser/ui/views/infobars/confirm_infobar.h" +#include "ui/base/metadata/metadata_header_macros.h" + +namespace views { +class Checkbox; +} // namespace views + +// Add checkbox to ConfirmInfoBar. +// "Would you like to do X? [Checkbox] _Learn More_ [x]" +class BraveConfirmInfoBar : public ConfirmInfoBar { + public: + METADATA_HEADER(BraveConfirmInfoBar); + explicit BraveConfirmInfoBar( + std::unique_ptr delegate); + BraveConfirmInfoBar(const BraveConfirmInfoBar&) = delete; + BraveConfirmInfoBar& operator=(const BraveConfirmInfoBar&) = delete; + ~BraveConfirmInfoBar() override; + + // ConfirmInfoBar overrides: + void Layout() override; + int NonLabelWidth() const override; + void CloseButtonPressed() override; + + private: + BraveConfirmInfoBarDelegate* GetBraveDelegate(); + + void CheckboxPressed(); + + raw_ptr checkbox_ = nullptr; +}; + +#endif // BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_CONFIRM_INFOBAR_H_ diff --git a/browser/ui/views/obsolete_system_confirm_dialog_view.cc b/browser/ui/views/obsolete_system_confirm_dialog_view.cc new file mode 100644 index 000000000000..529be305b92f --- /dev/null +++ b/browser/ui/views/obsolete_system_confirm_dialog_view.cc @@ -0,0 +1,86 @@ +/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/ui/views/obsolete_system_confirm_dialog_view.h" + +#include +#include + +#include "base/callback.h" +#include "base/notreached.h" +#include "brave/components/l10n/common/localization_util.h" +#include "brave/grit/brave_generated_resources.h" +#include "build/build_config.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_finder.h" +#include "chrome/browser/ui/browser_window.h" +#include "components/constrained_window/constrained_window_views.h" +#include "ui/base/metadata/metadata_impl_macros.h" +#include "ui/views/controls/label.h" + +namespace { + +std::u16string GetObsoleteSystemDialogContent() { + int id = -1; +#if BUILDFLAG(IS_WIN) + id = IDS_OBSOLETE_SYSTEM_CONFIRM_DIALOG_CONTENT_WIN; +#elif BUILDFLAG(IS_MAC) + id = IDS_OBSOLETE_SYSTEM_CONFIRM_DIALOG_CONTENT_MAC; +#elif BUILDFLAG(IS_LINUX) + id = IDS_OBSOLETE_SYSTEM_CONFIRM_DIALOG_CONTENT_LINUX; +#elif + NOTREACHED(); +#endif + return brave_l10n::GetLocalizedResourceUTF16String(id); +} + +} // namespace + +namespace brave { + +void ShowObsoleteSystemConfirmDialog(base::OnceCallback callback) { + if (auto* browser = chrome::FindLastActive()) { + constrained_window::CreateBrowserModalDialogViews( + new ObsoleteSystemConfirmDialogView(std::move(callback)), + browser->window()->GetNativeWindow()) + ->Show(); + } +} + +} // namespace brave + +ObsoleteSystemConfirmDialogView::ObsoleteSystemConfirmDialogView( + base::OnceCallback closing_callback) + : closing_callback_(std::move(closing_callback)) { + SetModalType(ui::MODAL_TYPE_WINDOW); + SetShowCloseButton(false); + SetUseDefaultFillLayout(true); + SetAcceptCallback( + base::BindOnce(&ObsoleteSystemConfirmDialogView::OnButtonPressed, + base::Unretained(this), true)); + SetCancelCallback( + base::BindOnce(&ObsoleteSystemConfirmDialogView::OnButtonPressed, + base::Unretained(this), false)); + set_margins(gfx::Insets::VH(20, 30)); + + auto* label = AddChildView(std::make_unique()); + label->SetMultiLine(true); + label->SetMaximumWidth(330); + label->SetText(GetObsoleteSystemDialogContent()); + const int size_diff = 14 - views::Label::GetDefaultFontList().GetFontSize(); + label->SetFontList(views::Label::GetDefaultFontList() + .DeriveWithSizeDelta(size_diff) + .DeriveWithWeight(gfx::Font::Weight::SEMIBOLD)); + label->SetHorizontalAlignment(gfx::ALIGN_LEFT); +} + +ObsoleteSystemConfirmDialogView::~ObsoleteSystemConfirmDialogView() = default; + +void ObsoleteSystemConfirmDialogView::OnButtonPressed(bool accept) { + std::move(closing_callback_).Run(accept); +} + +BEGIN_METADATA(ObsoleteSystemConfirmDialogView, views::DialogDelegateView) +END_METADATA diff --git a/browser/ui/views/obsolete_system_confirm_dialog_view.h b/browser/ui/views/obsolete_system_confirm_dialog_view.h new file mode 100644 index 000000000000..7eac3d7ae6c2 --- /dev/null +++ b/browser/ui/views/obsolete_system_confirm_dialog_view.h @@ -0,0 +1,31 @@ +/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_UI_VIEWS_OBSOLETE_SYSTEM_CONFIRM_DIALOG_VIEW_H_ +#define BRAVE_BROWSER_UI_VIEWS_OBSOLETE_SYSTEM_CONFIRM_DIALOG_VIEW_H_ + +#include "base/callback_forward.h" +#include "ui/base/metadata/metadata_header_macros.h" +#include "ui/views/window/dialog_delegate.h" + +class ObsoleteSystemConfirmDialogView : public views::DialogDelegateView { + public: + METADATA_HEADER(ObsoleteSystemConfirmDialogView); + + explicit ObsoleteSystemConfirmDialogView( + base::OnceCallback closing_callback); + ObsoleteSystemConfirmDialogView(const ObsoleteSystemConfirmDialogView&) = + delete; + ObsoleteSystemConfirmDialogView& operator=( + const ObsoleteSystemConfirmDialogView&) = delete; + ~ObsoleteSystemConfirmDialogView() override; + + private: + void OnButtonPressed(bool accept); + + base::OnceCallback closing_callback_; +}; + +#endif // BRAVE_BROWSER_UI_VIEWS_OBSOLETE_SYSTEM_CONFIRM_DIALOG_VIEW_H_ diff --git a/chromium_src/chrome/browser/ui/startup/infobar_utils.cc b/chromium_src/chrome/browser/ui/startup/infobar_utils.cc index c584171fe1f1..26002e2d0669 100644 --- a/chromium_src/chrome/browser/ui/startup/infobar_utils.cc +++ b/chromium_src/chrome/browser/ui/startup/infobar_utils.cc @@ -6,6 +6,7 @@ #include "brave/browser/ui/startup/brave_obsolete_system_infobar_delegate.h" #include "chrome/browser/ui/session_crashed_bubble.h" #include "chrome/browser/ui/startup/google_api_keys_infobar_delegate.h" +#include "chrome/browser/ui/startup/obsolete_system_infobar_delegate.h" #include "components/infobars/content/content_infobar_manager.h" class BraveGoogleKeysInfoBarDelegate { diff --git a/chromium_src/chrome/browser/ui/startup/obsolete_system_infobar_delegate.h b/chromium_src/chrome/browser/ui/startup/obsolete_system_infobar_delegate.h deleted file mode 100644 index 17d76010bfeb..000000000000 --- a/chromium_src/chrome/browser/ui/startup/obsolete_system_infobar_delegate.h +++ /dev/null @@ -1,20 +0,0 @@ -/* 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 https://mozilla.org/MPL/2.0/. */ - -#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_STARTUP_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_ -#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_STARTUP_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_ - -#include "components/infobars/core/confirm_infobar_delegate.h" - -#define Create \ - Create_UnUsed() {} \ - friend class BraveObsoleteSystemInfoBarDelegate; \ - static void Create - -#include "src/chrome/browser/ui/startup/obsolete_system_infobar_delegate.h" - -#undef Create - -#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_STARTUP_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_ diff --git a/chromium_src/chrome/browser/ui/views/infobars/confirm_infobar.h b/chromium_src/chrome/browser/ui/views/infobars/confirm_infobar.h index 47122baa8399..53cb929fc195 100644 --- a/chromium_src/chrome/browser/ui/views/infobars/confirm_infobar.h +++ b/chromium_src/chrome/browser/ui/views/infobars/confirm_infobar.h @@ -9,10 +9,14 @@ #define GetDelegate \ Unused() { return nullptr; } \ friend class BraveSyncAccountDeletedInfoBar; \ + friend class BraveConfirmInfoBar; \ ConfirmInfoBarDelegate* GetDelegate +#define NonLabelWidth virtual NonLabelWidth + #include "src/chrome/browser/ui/views/infobars/confirm_infobar.h" +#undef NonLabelWidth #undef GetDelegate #endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_INFOBARS_CONFIRM_INFOBAR_H_ diff --git a/chromium_src/chrome/browser/ui/views/infobars/infobar_view.h b/chromium_src/chrome/browser/ui/views/infobars/infobar_view.h new file mode 100644 index 000000000000..e15156b756d3 --- /dev/null +++ b/chromium_src/chrome/browser/ui/views/infobars/infobar_view.h @@ -0,0 +1,21 @@ +/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ +#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ + +#define RecalculateHeight \ + RecalculateHeight_Unused() {} \ + friend class BraveConfirmInfoBar; \ + void RecalculateHeight + +#define CloseButtonPressed virtual CloseButtonPressed + +#include "src/chrome/browser/ui/views/infobars/infobar_view.h" + +#undef CloseButtonPressed +#undef RecalculateHeight + +#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_VIEWS_INFOBARS_INFOBAR_VIEW_H_ diff --git a/components/infobars/core/BUILD.gn b/components/infobars/core/BUILD.gn new file mode 100644 index 000000000000..4a4f361603fc --- /dev/null +++ b/components/infobars/core/BUILD.gn @@ -0,0 +1,13 @@ +# Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. + +static_library("core") { + sources = [ + "brave_confirm_infobar_delegate.cc", + "brave_confirm_infobar_delegate.h", + ] + + public_deps = [ "//components/infobars/core" ] +} diff --git a/components/infobars/core/brave_confirm_infobar_delegate.cc b/components/infobars/core/brave_confirm_infobar_delegate.cc new file mode 100644 index 000000000000..bdc9c7993c55 --- /dev/null +++ b/components/infobars/core/brave_confirm_infobar_delegate.cc @@ -0,0 +1,23 @@ +/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ + +#include "brave/components/infobars/core/brave_confirm_infobar_delegate.h" + +BraveConfirmInfoBarDelegate::BraveConfirmInfoBarDelegate() = default; +BraveConfirmInfoBarDelegate::~BraveConfirmInfoBarDelegate() = default; + +bool BraveConfirmInfoBarDelegate::HasCheckbox() const { + return false; +} + +std::u16string BraveConfirmInfoBarDelegate::GetCheckboxText() const { + return std::u16string(); +} + +void BraveConfirmInfoBarDelegate::SetCheckboxChecked(bool checked) {} + +bool BraveConfirmInfoBarDelegate::InterceptClosing() { + return false; +} diff --git a/components/infobars/core/brave_confirm_infobar_delegate.h b/components/infobars/core/brave_confirm_infobar_delegate.h new file mode 100644 index 000000000000..fc26c7a4448a --- /dev/null +++ b/components/infobars/core/brave_confirm_infobar_delegate.h @@ -0,0 +1,32 @@ +/* Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_COMPONENTS_INFOBARS_CORE_BRAVE_CONFIRM_INFOBAR_DELEGATE_H_ +#define BRAVE_COMPONENTS_INFOBARS_CORE_BRAVE_CONFIRM_INFOBAR_DELEGATE_H_ + +#include + +#include "components/infobars/core/confirm_infobar_delegate.h" + +class BraveConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { + public: + BraveConfirmInfoBarDelegate(const BraveConfirmInfoBarDelegate&) = delete; + BraveConfirmInfoBarDelegate& operator=(const BraveConfirmInfoBarDelegate&) = + delete; + ~BraveConfirmInfoBarDelegate() override; + + virtual bool HasCheckbox() const; + virtual std::u16string GetCheckboxText() const; + virtual void SetCheckboxChecked(bool checked); + // Returns true when delegate wants to intercept closing. + // Then closing will be cancelled and delegate should remove infobar + // after doing something. + virtual bool InterceptClosing(); + + protected: + BraveConfirmInfoBarDelegate(); +}; + +#endif // BRAVE_COMPONENTS_INFOBARS_CORE_BRAVE_CONFIRM_INFOBAR_DELEGATE_H_