Skip to content

Commit

Permalink
Launched additional confirmation dialog to the end of support
Browse files Browse the repository at this point in the history
fix brave/brave-browser#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.
  • Loading branch information
simonhong committed Jan 10, 2023
1 parent 2c8a303 commit d454946
Show file tree
Hide file tree
Showing 19 changed files with 472 additions and 38 deletions.
15 changes: 15 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,21 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
<message name="IDS_OBSOLERE_SYSTEM_INFOBAR_DONT_SHOW_BUTTON" desc="The text for don't show again button">
Don't show again
</message>
<if expr="is_win">
<message name="IDS_OBSOLETE_SYSTEM_CONFIRM_DIALOG_CONTENT_WIN" desc="The text for obsolete system confirm dialog">
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.
</message>
</if>
<if expr="is_macosx">
<message name="IDS_OBSOLETE_SYSTEM_CONFIRM_DIALOG_CONTENT_MAC" desc="The text for obsolete system confirm dialog">
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.
</message>
</if>
<if expr="is_linux">
<message name="IDS_OBSOLETE_SYSTEM_CONFIRM_DIALOG_CONTENT_LINUX" desc="The text for obsolete system confirm dialog">
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.
</message>
</if>
</if>

<!-- Brave Ads -->
Expand Down
1 change: 1 addition & 0 deletions browser/infobars/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions browser/infobars/brave_confirm_infobar_creator.h
Original file line number Diff line number Diff line change
@@ -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 <memory>

class BraveConfirmInfoBarDelegate;

namespace infobars {
class InfoBar;
} // namespace infobars

std::unique_ptr<infobars::InfoBar> CreateBraveConfirmInfoBar(
std::unique_ptr<BraveConfirmInfoBarDelegate> delegate);

#endif // BRAVE_BROWSER_INFOBARS_BRAVE_CONFIRM_INFOBAR_CREATOR_H_
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions browser/ui/browser_dialogs.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
#ifndef BRAVE_BROWSER_UI_BROWSER_DIALOGS_H_
#define BRAVE_BROWSER_UI_BROWSER_DIALOGS_H_

#include "base/callback_forward.h"

class Browser;

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<void(bool)> callback);

} // namespace brave

#endif // BRAVE_BROWSER_UI_BROWSER_DIALOGS_H_
74 changes: 64 additions & 10 deletions browser/ui/startup/brave_obsolete_system_infobar_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>

#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<ConfirmInfoBarDelegate>(
CreateBraveConfirmInfoBar(std::unique_ptr<BraveConfirmInfoBarDelegate>(
new BraveObsoleteSystemInfoBarDelegate())));
}

Expand All @@ -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;
}
27 changes: 19 additions & 8 deletions browser/ui/startup/brave_obsolete_system_infobar_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@

#include <string>

#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);

Expand All @@ -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<BraveObsoleteSystemInfoBarDelegate> weak_factory_{this};
};

#endif // BRAVE_BROWSER_UI_STARTUP_BRAVE_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_
3 changes: 3 additions & 0 deletions browser/ui/views/infobars/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
88 changes: 88 additions & 0 deletions browser/ui/views/infobars/brave_confirm_infobar.cc
Original file line number Diff line number Diff line change
@@ -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 <memory>
#include <utility>

#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<infobars::InfoBar> CreateBraveConfirmInfoBar(
std::unique_ptr<BraveConfirmInfoBarDelegate> delegate) {
return std::make_unique<BraveConfirmInfoBar>(std::move(delegate));
}

BraveConfirmInfoBar::BraveConfirmInfoBar(
std::unique_ptr<BraveConfirmInfoBarDelegate> 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<views::Checkbox>(
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<BraveConfirmInfoBarDelegate*>(
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
44 changes: 44 additions & 0 deletions browser/ui/views/infobars/brave_confirm_infobar.h
Original file line number Diff line number Diff line change
@@ -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 <memory>

#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<BraveConfirmInfoBarDelegate> 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<views::Checkbox> checkbox_ = nullptr;
};

#endif // BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_CONFIRM_INFOBAR_H_
Loading

0 comments on commit d454946

Please sign in to comment.