-
Notifications
You must be signed in to change notification settings - Fork 887
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Launched additional confirmation dialog to the end of support (uplift…
… to 1.47.x) (#16734)
- Loading branch information
Showing
19 changed files
with
572 additions
and
1 deletion.
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
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,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_ |
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
100 changes: 100 additions & 0 deletions
100
browser/ui/startup/brave_obsolete_system_infobar_delegate.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,100 @@ | ||
/* 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/. */ | ||
|
||
#include "brave/browser/ui/startup/brave_obsolete_system_infobar_delegate.h" | ||
|
||
#include <memory> | ||
|
||
#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( | ||
CreateBraveConfirmInfoBar(std::unique_ptr<BraveConfirmInfoBarDelegate>( | ||
new BraveObsoleteSystemInfoBarDelegate()))); | ||
} | ||
|
||
BraveObsoleteSystemInfoBarDelegate::BraveObsoleteSystemInfoBarDelegate() = | ||
default; | ||
BraveObsoleteSystemInfoBarDelegate::~BraveObsoleteSystemInfoBarDelegate() = | ||
default; | ||
|
||
bool BraveObsoleteSystemInfoBarDelegate::HasCheckbox() const { | ||
return true; | ||
} | ||
|
||
std::u16string BraveObsoleteSystemInfoBarDelegate::GetCheckboxText() const { | ||
return l10n_util::GetStringUTF16( | ||
IDS_OBSOLETE_SYSTEM_INFOBAR_DONT_SHOW_BUTTON); | ||
} | ||
|
||
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; | ||
} |
50 changes: 50 additions & 0 deletions
50
browser/ui/startup/brave_obsolete_system_infobar_delegate.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,50 @@ | ||
/* 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_BROWSER_UI_STARTUP_BRAVE_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_ | ||
#define BRAVE_BROWSER_UI_STARTUP_BRAVE_OBSOLETE_SYSTEM_INFOBAR_DELEGATE_H_ | ||
|
||
#include <string> | ||
|
||
#include "base/memory/weak_ptr.h" | ||
#include "brave/components/infobars/core/brave_confirm_infobar_delegate.h" | ||
|
||
namespace infobars { | ||
class ContentInfoBarManager; | ||
} // namespace infobars | ||
|
||
class BraveObsoleteSystemInfoBarDelegate : public BraveConfirmInfoBarDelegate { | ||
public: | ||
static void Create(infobars::ContentInfoBarManager* infobar_manager); | ||
|
||
BraveObsoleteSystemInfoBarDelegate( | ||
const BraveObsoleteSystemInfoBarDelegate&) = delete; | ||
BraveObsoleteSystemInfoBarDelegate& operator=( | ||
const BraveObsoleteSystemInfoBarDelegate&) = delete; | ||
|
||
private: | ||
BraveObsoleteSystemInfoBarDelegate(); | ||
~BraveObsoleteSystemInfoBarDelegate() override; | ||
|
||
// 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; | ||
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_ |
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,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 |
Oops, something went wrong.