-
Notifications
You must be signed in to change notification settings - Fork 926
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce IPFS promo infobar (#19588)
* Introduce IPFS promo infobar Resolves brave/brave-browser#32010
- Loading branch information
Showing
18 changed files
with
750 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* 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/infobars/brave_ipfs_infobar_delegate.h" | ||
|
||
#include <algorithm> | ||
#include <utility> | ||
|
||
#include "brave/browser/ui/views/infobars/brave_confirm_infobar.h" | ||
#include "brave/components/ipfs/ipfs_constants.h" | ||
#include "brave/components/ipfs/pref_names.h" | ||
#include "brave/components/l10n/common/localization_util.h" | ||
#include "brave/grit/brave_generated_resources.h" | ||
#include "components/infobars/core/infobar.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "ui/views/vector_icons.h" | ||
|
||
// BraveIPFSInfoBarDelegateObserver | ||
BraveIPFSInfoBarDelegateObserver::BraveIPFSInfoBarDelegateObserver() = default; | ||
|
||
BraveIPFSInfoBarDelegateObserver::~BraveIPFSInfoBarDelegateObserver() = default; | ||
|
||
// BraveIPFSInfoBarDelegate | ||
// static | ||
void BraveIPFSInfoBarDelegate::Create( | ||
infobars::ContentInfoBarManager* infobar_manager, | ||
std::unique_ptr<BraveIPFSInfoBarDelegateObserver> observer, | ||
PrefService* local_state) { | ||
if (!local_state->GetBoolean(kShowIPFSPromoInfobar)) { | ||
return; | ||
} | ||
infobar_manager->AddInfoBar(std::make_unique<BraveConfirmInfoBar>( | ||
std::make_unique<BraveIPFSInfoBarDelegate>( | ||
std::move(observer), local_state)), | ||
true); | ||
} | ||
|
||
BraveIPFSInfoBarDelegate::BraveIPFSInfoBarDelegate( | ||
std::unique_ptr<BraveIPFSInfoBarDelegateObserver> observer, | ||
PrefService* local_state) | ||
: observer_(std::move(observer)), local_state_(local_state) {} | ||
|
||
BraveIPFSInfoBarDelegate::~BraveIPFSInfoBarDelegate() {} | ||
|
||
// BraveConfirmInfoBarDelegate | ||
bool BraveIPFSInfoBarDelegate::HasCheckbox() const { | ||
return false; | ||
} | ||
|
||
std::u16string BraveIPFSInfoBarDelegate::GetCheckboxText() const { | ||
NOTREACHED_NORETURN(); | ||
} | ||
|
||
void BraveIPFSInfoBarDelegate::SetCheckboxChecked(bool checked) { | ||
NOTREACHED(); | ||
} | ||
|
||
bool BraveIPFSInfoBarDelegate::InterceptClosing() { | ||
return false; | ||
} | ||
|
||
// ConfirmInfoBarDelegate | ||
infobars::InfoBarDelegate::InfoBarIdentifier | ||
BraveIPFSInfoBarDelegate::GetIdentifier() const { | ||
return BRAVE_IPFS_INFOBAR_DELEGATE; | ||
} | ||
|
||
const gfx::VectorIcon& BraveIPFSInfoBarDelegate::GetVectorIcon() const { | ||
return views::kInfoIcon; | ||
} | ||
|
||
bool BraveIPFSInfoBarDelegate::ShouldExpire( | ||
const NavigationDetails& details) const { | ||
return details.is_navigation_to_different_page; | ||
} | ||
|
||
void BraveIPFSInfoBarDelegate::InfoBarDismissed() {} | ||
|
||
std::u16string BraveIPFSInfoBarDelegate::GetMessageText() const { | ||
return brave_l10n::GetLocalizedResourceUTF16String( | ||
IDS_BRAVE_IPFS_INFOBAR_TEXT); | ||
} | ||
|
||
int BraveIPFSInfoBarDelegate::GetButtons() const { | ||
return BUTTON_OK | BUTTON_CANCEL | BUTTON_EXTRA; | ||
} | ||
|
||
bool BraveIPFSInfoBarDelegate::IsProminent(int id) const { | ||
return id == BUTTON_OK || id == BUTTON_EXTRA; | ||
} | ||
|
||
std::u16string BraveIPFSInfoBarDelegate::GetButtonLabel( | ||
InfoBarButton button) const { | ||
switch (button) { | ||
case InfoBarButton::BUTTON_OK: | ||
return brave_l10n::GetLocalizedResourceUTF16String( | ||
IDS_BRAVE_IPFS_INFOBAR_APPROVE); | ||
case InfoBarButton::BUTTON_EXTRA: | ||
return brave_l10n::GetLocalizedResourceUTF16String( | ||
IDS_BRAVE_IPFS_INFOBAR_APPROVE_ONCE); | ||
case InfoBarButton::BUTTON_CANCEL: | ||
return brave_l10n::GetLocalizedResourceUTF16String( | ||
IDS_BRAVE_IPFS_INFOBAR_NEVER); | ||
default: | ||
NOTREACHED_NORETURN(); | ||
} | ||
} | ||
|
||
std::vector<int> BraveIPFSInfoBarDelegate::GetButtonsOrder() const { | ||
return {InfoBarButton::BUTTON_OK, InfoBarButton::BUTTON_EXTRA, | ||
InfoBarButton::BUTTON_CANCEL}; | ||
} | ||
|
||
std::u16string BraveIPFSInfoBarDelegate::GetLinkText() const { | ||
return brave_l10n::GetLocalizedResourceUTF16String( | ||
IDS_BRAVE_IPFS_INFOBAR_LINK); | ||
} | ||
|
||
GURL BraveIPFSInfoBarDelegate::GetLinkURL() const { | ||
return GURL(ipfs::kIPFSLearnMorePrivacyURL); | ||
} | ||
|
||
bool BraveIPFSInfoBarDelegate::Accept() { | ||
if (observer_) { | ||
local_state_->SetBoolean(kShowIPFSPromoInfobar, false); | ||
observer_->OnRedirectToIPFS(true); | ||
} | ||
return true; | ||
} | ||
|
||
bool BraveIPFSInfoBarDelegate::ExtraButtonPressed() { | ||
if (observer_) { | ||
observer_->OnRedirectToIPFS(false); | ||
} | ||
return true; | ||
} | ||
|
||
bool BraveIPFSInfoBarDelegate::Cancel() { | ||
local_state_->SetBoolean(kShowIPFSPromoInfobar, false); | ||
return true; | ||
} |
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,73 @@ | ||
/* 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_IPFS_INFOBAR_DELEGATE_H_ | ||
#define BRAVE_BROWSER_INFOBARS_BRAVE_IPFS_INFOBAR_DELEGATE_H_ | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
#include "base/compiler_specific.h" | ||
#include "base/memory/raw_ptr.h" | ||
#include "brave/components/infobars/core/brave_confirm_infobar_delegate.h" | ||
#include "components/infobars/content/content_infobar_manager.h" | ||
#include "url/gurl.h" | ||
|
||
class PrefService; | ||
|
||
namespace infobars { | ||
class ContentInfoBarManager; | ||
} // namespace infobars | ||
|
||
class BraveIPFSInfoBarDelegateObserver { | ||
public: | ||
BraveIPFSInfoBarDelegateObserver(); | ||
virtual void OnRedirectToIPFS(bool remember) = 0; | ||
virtual ~BraveIPFSInfoBarDelegateObserver(); | ||
}; | ||
|
||
class BraveIPFSInfoBarDelegate : public BraveConfirmInfoBarDelegate { | ||
public: | ||
BraveIPFSInfoBarDelegate(const BraveIPFSInfoBarDelegate&) = delete; | ||
BraveIPFSInfoBarDelegate& operator=(const BraveIPFSInfoBarDelegate&) = delete; | ||
|
||
BraveIPFSInfoBarDelegate( | ||
std::unique_ptr<BraveIPFSInfoBarDelegateObserver> observer, | ||
PrefService* local_state); | ||
~BraveIPFSInfoBarDelegate() override; | ||
|
||
static void Create(infobars::ContentInfoBarManager* infobar_manager, | ||
std::unique_ptr<BraveIPFSInfoBarDelegateObserver> observer, | ||
PrefService* local_state); | ||
|
||
private: | ||
// BraveConfirmInfoBarDelegate | ||
bool HasCheckbox() const override; | ||
std::u16string GetCheckboxText() const override; | ||
void SetCheckboxChecked(bool checked) override; | ||
bool InterceptClosing() override; | ||
|
||
// ConfirmInfoBarDelegate | ||
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; | ||
const gfx::VectorIcon& GetVectorIcon() const override; | ||
bool ShouldExpire(const NavigationDetails& details) const override; | ||
void InfoBarDismissed() override; | ||
std::u16string GetMessageText() const override; | ||
int GetButtons() const override; | ||
std::vector<int> GetButtonsOrder() const override; | ||
bool IsProminent(int id) const override; | ||
std::u16string GetButtonLabel(InfoBarButton button) const override; | ||
std::u16string GetLinkText() const override; | ||
GURL GetLinkURL() const override; | ||
|
||
bool Accept() override; | ||
bool Cancel() override; | ||
bool ExtraButtonPressed() override; | ||
|
||
std::unique_ptr<BraveIPFSInfoBarDelegateObserver> observer_; | ||
raw_ptr<PrefService> local_state_ = nullptr; | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_INFOBARS_BRAVE_IPFS_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
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
Oops, something went wrong.