Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launched additional confirmation dialog to the end of support (uplift to 1.48.x) #16733

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,14 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
No thanks
</message>
<!-- obsolete system InfoBar -->
<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_INFOBAR_DONT_SHOW_BUTTON" desc="The text for don't show again button">
Don't show again
</message>
<message name="IDS_OBSOLETE_SYSTEM_CONFIRM_DIALOG_CONTENT" 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_
17 changes: 15 additions & 2 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ source_set("ui") {
"omnibox/brave_omnibox_client_impl.cc",
"omnibox/brave_omnibox_client_impl.h",
"session_crashed_bubble_brave.cc",
"startup/brave_obsolete_system_infobar_delegate.cc",
"startup/brave_obsolete_system_infobar_delegate.h",
"toolbar/brave_app_menu_model.cc",
"toolbar/brave_app_menu_model.h",
"toolbar/brave_recent_tabs_sub_menu_model.h",
Expand Down Expand Up @@ -339,6 +337,21 @@ source_set("ui") {
]
}

# brave's obsolete infobar is only used on Windows now.
if (is_win) {
sources += [
"startup/brave_obsolete_system_infobar_delegate.cc",
"startup/brave_obsolete_system_infobar_delegate.h",
]

if (toolkit_views) {
sources += [
"views/obsolete_system_confirm_dialog_view.cc",
"views/obsolete_system_confirm_dialog_view.h",
]
}
}

if (is_linux) {
sources += [
"views/brave_views_delegate_linux.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_
76 changes: 65 additions & 11 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);
IDS_OBSOLETE_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
Loading