Commit 182d71d6 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Misc. cleanup for infobars.

* Init members in declaration
* Use =default
* Shorten code
* Use enum names instead of constant values
* Add comments
* Better use of auto
* Remove some bare news
* Remove using declarations

Bug: none
Change-Id: I710527a697406510143575ec4d582c5b5b37a071
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1983508
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728803}
parent 5936ab4d
...@@ -39,7 +39,7 @@ class GlobalConfirmInfoBar::DelegateProxy : public ConfirmInfoBarDelegate { ...@@ -39,7 +39,7 @@ class GlobalConfirmInfoBar::DelegateProxy : public ConfirmInfoBarDelegate {
bool Accept() override; bool Accept() override;
bool Cancel() override; bool Cancel() override;
infobars::InfoBar* info_bar_; infobars::InfoBar* info_bar_ = nullptr;
base::WeakPtr<GlobalConfirmInfoBar> global_info_bar_; base::WeakPtr<GlobalConfirmInfoBar> global_info_bar_;
DISALLOW_COPY_AND_ASSIGN(DelegateProxy); DISALLOW_COPY_AND_ASSIGN(DelegateProxy);
...@@ -47,12 +47,9 @@ class GlobalConfirmInfoBar::DelegateProxy : public ConfirmInfoBarDelegate { ...@@ -47,12 +47,9 @@ class GlobalConfirmInfoBar::DelegateProxy : public ConfirmInfoBarDelegate {
GlobalConfirmInfoBar::DelegateProxy::DelegateProxy( GlobalConfirmInfoBar::DelegateProxy::DelegateProxy(
base::WeakPtr<GlobalConfirmInfoBar> global_info_bar) base::WeakPtr<GlobalConfirmInfoBar> global_info_bar)
: info_bar_(nullptr), : global_info_bar_(global_info_bar) {}
global_info_bar_(global_info_bar) {
}
GlobalConfirmInfoBar::DelegateProxy::~DelegateProxy() { GlobalConfirmInfoBar::DelegateProxy::~DelegateProxy() = default;
}
infobars::InfoBarDelegate::InfoBarIdentifier infobars::InfoBarDelegate::InfoBarIdentifier
GlobalConfirmInfoBar::DelegateProxy::GetIdentifier() const { GlobalConfirmInfoBar::DelegateProxy::GetIdentifier() const {
...@@ -71,9 +68,8 @@ GURL GlobalConfirmInfoBar::DelegateProxy::GetLinkURL() const { ...@@ -71,9 +68,8 @@ GURL GlobalConfirmInfoBar::DelegateProxy::GetLinkURL() const {
bool GlobalConfirmInfoBar::DelegateProxy::LinkClicked( bool GlobalConfirmInfoBar::DelegateProxy::LinkClicked(
WindowOpenDisposition disposition) { WindowOpenDisposition disposition) {
return global_info_bar_ return global_info_bar_ &&
? global_info_bar_->delegate_->LinkClicked(disposition) global_info_bar_->delegate_->LinkClicked(disposition);
: false;
} }
void GlobalConfirmInfoBar::DelegateProxy::InfoBarDismissed() { void GlobalConfirmInfoBar::DelegateProxy::InfoBarDismissed() {
...@@ -102,7 +98,7 @@ GlobalConfirmInfoBar::DelegateProxy::GetMessageElideBehavior() const { ...@@ -102,7 +98,7 @@ GlobalConfirmInfoBar::DelegateProxy::GetMessageElideBehavior() const {
int GlobalConfirmInfoBar::DelegateProxy::GetButtons() const { int GlobalConfirmInfoBar::DelegateProxy::GetButtons() const {
return global_info_bar_ ? global_info_bar_->delegate_->GetButtons() return global_info_bar_ ? global_info_bar_->delegate_->GetButtons()
: 0; : BUTTON_NONE;
} }
base::string16 GlobalConfirmInfoBar::DelegateProxy::GetButtonLabel( base::string16 GlobalConfirmInfoBar::DelegateProxy::GetButtonLabel(
...@@ -150,9 +146,9 @@ void GlobalConfirmInfoBar::DelegateProxy::Detach() { ...@@ -150,9 +146,9 @@ void GlobalConfirmInfoBar::DelegateProxy::Detach() {
// static // static
base::WeakPtr<GlobalConfirmInfoBar> GlobalConfirmInfoBar::Show( base::WeakPtr<GlobalConfirmInfoBar> GlobalConfirmInfoBar::Show(
std::unique_ptr<ConfirmInfoBarDelegate> delegate) { std::unique_ptr<ConfirmInfoBarDelegate> delegate) {
GlobalConfirmInfoBar* info_bar = // Owns itself, deleted by Close().
new GlobalConfirmInfoBar(std::move(delegate)); auto* infobar = new GlobalConfirmInfoBar(std::move(delegate));
return info_bar->weak_factory_.GetWeakPtr(); return infobar->weak_factory_.GetWeakPtr();
} }
void GlobalConfirmInfoBar::Close() { void GlobalConfirmInfoBar::Close() {
...@@ -161,9 +157,7 @@ void GlobalConfirmInfoBar::Close() { ...@@ -161,9 +157,7 @@ void GlobalConfirmInfoBar::Close() {
GlobalConfirmInfoBar::GlobalConfirmInfoBar( GlobalConfirmInfoBar::GlobalConfirmInfoBar(
std::unique_ptr<ConfirmInfoBarDelegate> delegate) std::unique_ptr<ConfirmInfoBarDelegate> delegate)
: delegate_(std::move(delegate)), : delegate_(std::move(delegate)) {
browser_tab_strip_tracker_(this, nullptr, nullptr),
is_closing_(false) {
browser_tab_strip_tracker_.Init(); browser_tab_strip_tracker_.Init();
} }
...@@ -196,7 +190,7 @@ void GlobalConfirmInfoBar::TabChangedAt(content::WebContents* web_contents, ...@@ -196,7 +190,7 @@ void GlobalConfirmInfoBar::TabChangedAt(content::WebContents* web_contents,
void GlobalConfirmInfoBar::OnInfoBarRemoved(infobars::InfoBar* info_bar, void GlobalConfirmInfoBar::OnInfoBarRemoved(infobars::InfoBar* info_bar,
bool animate) { bool animate) {
// Do not process alien infobars. // Do not process alien infobars.
for (auto it : proxies_) { for (const auto& it : proxies_) {
if (it.second->info_bar_ == info_bar) { if (it.second->info_bar_ == info_bar) {
OnManagerShuttingDown(info_bar->owner()); OnManagerShuttingDown(info_bar->owner());
break; break;
...@@ -218,8 +212,8 @@ void GlobalConfirmInfoBar::MaybeAddInfoBar(content::WebContents* web_contents) { ...@@ -218,8 +212,8 @@ void GlobalConfirmInfoBar::MaybeAddInfoBar(content::WebContents* web_contents) {
if (base::Contains(proxies_, infobar_service)) if (base::Contains(proxies_, infobar_service))
return; return;
std::unique_ptr<GlobalConfirmInfoBar::DelegateProxy> proxy( auto proxy = std::make_unique<GlobalConfirmInfoBar::DelegateProxy>(
new GlobalConfirmInfoBar::DelegateProxy(weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr());
GlobalConfirmInfoBar::DelegateProxy* proxy_ptr = proxy.get(); GlobalConfirmInfoBar::DelegateProxy* proxy_ptr = proxy.get();
infobars::InfoBar* added_bar = infobar_service->AddInfoBar( infobars::InfoBar* added_bar = infobar_service->AddInfoBar(
infobar_service->CreateConfirmInfoBar(std::move(proxy))); infobar_service->CreateConfirmInfoBar(std::move(proxy)));
......
...@@ -56,11 +56,11 @@ class GlobalConfirmInfoBar : public TabStripModelObserver, ...@@ -56,11 +56,11 @@ class GlobalConfirmInfoBar : public TabStripModelObserver,
std::unique_ptr<ConfirmInfoBarDelegate> delegate_; std::unique_ptr<ConfirmInfoBarDelegate> delegate_;
std::map<infobars::InfoBarManager*, DelegateProxy*> proxies_; std::map<infobars::InfoBarManager*, DelegateProxy*> proxies_;
BrowserTabStripTracker browser_tab_strip_tracker_; BrowserTabStripTracker browser_tab_strip_tracker_{this, nullptr, nullptr};
// Indicates if the global infobar is currently in the process of shutting // Indicates if the global infobar is currently in the process of shutting
// down. // down.
bool is_closing_; bool is_closing_ = false;
base::WeakPtrFactory<GlobalConfirmInfoBar> weak_factory_{this}; base::WeakPtrFactory<GlobalConfirmInfoBar> weak_factory_{this};
......
...@@ -18,11 +18,9 @@ void NaClInfoBarDelegate::Create(InfoBarService* infobar_service) { ...@@ -18,11 +18,9 @@ void NaClInfoBarDelegate::Create(InfoBarService* infobar_service) {
std::unique_ptr<ConfirmInfoBarDelegate>(new NaClInfoBarDelegate()))); std::unique_ptr<ConfirmInfoBarDelegate>(new NaClInfoBarDelegate())));
} }
NaClInfoBarDelegate::NaClInfoBarDelegate() : ConfirmInfoBarDelegate() { NaClInfoBarDelegate::NaClInfoBarDelegate() = default;
}
NaClInfoBarDelegate::~NaClInfoBarDelegate() { NaClInfoBarDelegate::~NaClInfoBarDelegate() = default;
}
infobars::InfoBarDelegate::InfoBarIdentifier infobars::InfoBarDelegate::InfoBarIdentifier
NaClInfoBarDelegate::GetIdentifier() const { NaClInfoBarDelegate::GetIdentifier() const {
......
...@@ -12,11 +12,7 @@ ...@@ -12,11 +12,7 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
PasswordManagerInfoBarDelegate::~PasswordManagerInfoBarDelegate() {} PasswordManagerInfoBarDelegate::~PasswordManagerInfoBarDelegate() = default;
PasswordManagerInfoBarDelegate::PasswordManagerInfoBarDelegate()
: ConfirmInfoBarDelegate(),
details_message_(base::string16()) {}
base::string16 PasswordManagerInfoBarDelegate::GetDetailsMessageText() const { base::string16 PasswordManagerInfoBarDelegate::GetDetailsMessageText() const {
return details_message_; return details_message_;
...@@ -50,6 +46,8 @@ base::string16 PasswordManagerInfoBarDelegate::GetMessageText() const { ...@@ -50,6 +46,8 @@ base::string16 PasswordManagerInfoBarDelegate::GetMessageText() const {
return message_; return message_;
} }
PasswordManagerInfoBarDelegate::PasswordManagerInfoBarDelegate() = default;
void PasswordManagerInfoBarDelegate::SetMessage(const base::string16& message) { void PasswordManagerInfoBarDelegate::SetMessage(const base::string16& message) {
message_ = message; message_ = message;
} }
......
...@@ -40,8 +40,7 @@ PepperBrokerInfoBarDelegate::PepperBrokerInfoBarDelegate( ...@@ -40,8 +40,7 @@ PepperBrokerInfoBarDelegate::PepperBrokerInfoBarDelegate(
HostContentSettingsMap* content_settings, HostContentSettingsMap* content_settings,
TabSpecificContentSettings* tab_content_settings, TabSpecificContentSettings* tab_content_settings,
base::OnceCallback<void(bool)> callback) base::OnceCallback<void(bool)> callback)
: ConfirmInfoBarDelegate(), : url_(url),
url_(url),
plugin_name_(plugin_name), plugin_name_(plugin_name),
content_settings_(content_settings), content_settings_(content_settings),
tab_content_settings_(tab_content_settings), tab_content_settings_(tab_content_settings),
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include <memory> #include <memory>
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/time/time.h"
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h" #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/infobar_service.h"
...@@ -26,33 +25,6 @@ ...@@ -26,33 +25,6 @@
#include "url/gurl.h" #include "url/gurl.h"
#include "url/url_constants.h" #include "url/url_constants.h"
namespace {
constexpr base::TimeDelta kMessageCooldown = base::TimeDelta::FromDays(14);
// This duration is the same as the "default browser" banner's duration.
constexpr base::TimeDelta kMinimumDurationBeforeExpiryOnNavigation =
base::TimeDelta::FromSeconds(8);
bool IsFlashDeprecationWarningCooldownActive(Profile* profile) {
base::Time last_dismissal =
profile->GetPrefs()->GetTime(prefs::kPluginsDeprecationInfobarLastShown);
// More than |kMessageCooldown| days have passed.
if (base::Time::Now() - last_dismissal > kMessageCooldown) {
return false;
}
return true;
}
void ActivateFlashDeprecationWarningCooldown(Profile* profile) {
profile->GetPrefs()->SetTime(prefs::kPluginsDeprecationInfobarLastShown,
base::Time::Now());
}
} // namespace
// static // static
void FlashDeprecationInfoBarDelegate::Create(InfoBarService* infobar_service, void FlashDeprecationInfoBarDelegate::Create(InfoBarService* infobar_service,
Profile* profile) { Profile* profile) {
...@@ -63,38 +35,39 @@ void FlashDeprecationInfoBarDelegate::Create(InfoBarService* infobar_service, ...@@ -63,38 +35,39 @@ void FlashDeprecationInfoBarDelegate::Create(InfoBarService* infobar_service,
// static // static
bool FlashDeprecationInfoBarDelegate::ShouldDisplayFlashDeprecation( bool FlashDeprecationInfoBarDelegate::ShouldDisplayFlashDeprecation(
Profile* profile) { Profile* profile) {
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(profile);
DCHECK(host_content_settings_map);
if (!base::FeatureList::IsEnabled(features::kFlashDeprecationWarning)) if (!base::FeatureList::IsEnabled(features::kFlashDeprecationWarning))
return false; return false;
// Generally, display the infobar if the Flash setting is anything other than
// BLOCK.
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(profile);
DCHECK(host_content_settings_map);
bool is_managed = false; bool is_managed = false;
ContentSetting flash_setting = ContentSetting flash_setting =
PluginUtils::UnsafeGetRawDefaultFlashContentSetting( PluginUtils::UnsafeGetRawDefaultFlashContentSetting(
host_content_settings_map, &is_managed); host_content_settings_map, &is_managed);
if (flash_setting == CONTENT_SETTING_BLOCK)
return false;
// If the user can't do anything about their browser's Flash behavior // However, if the user can't do anything about their browser's Flash
// there's no point to showing a Flash deprecation warning infobar. // behavior, there's no point to showing a Flash deprecation warning infobar.
// if (is_managed)
// Also limit showing the infobar to at most once per |kMessageCooldown|.
// Users should be periodically reminded that they need to take action, but
// if they couldn't take action and turn off flash it's unlikely they will
// able to the next time they start a session. The message become more
// annoying than informative in that case.
if (is_managed || IsFlashDeprecationWarningCooldownActive(profile)) {
return false; return false;
}
// Display the infobar if the Flash setting is anything other than BLOCK. // Also limit how frequently the infobar is shown. Users should be
return flash_setting != CONTENT_SETTING_BLOCK; // periodically reminded that they need to take action, but if they couldn't
// take action and turn off flash it's unlikely they will able to the next
// time they start a session. The message becomes more annoying than
// informative in that case.
const base::Time last_dismissal =
profile->GetPrefs()->GetTime(prefs::kPluginsDeprecationInfobarLastShown);
return (base::Time::Now() - last_dismissal) > base::TimeDelta::FromDays(14);
} }
FlashDeprecationInfoBarDelegate::FlashDeprecationInfoBarDelegate( FlashDeprecationInfoBarDelegate::FlashDeprecationInfoBarDelegate(
Profile* profile) Profile* profile)
: profile_(profile), display_start_(base::Time::Now()) {} : profile_(profile) {}
infobars::InfoBarDelegate::InfoBarIdentifier infobars::InfoBarDelegate::InfoBarIdentifier
FlashDeprecationInfoBarDelegate::GetIdentifier() const { FlashDeprecationInfoBarDelegate::GetIdentifier() const {
...@@ -116,14 +89,16 @@ GURL FlashDeprecationInfoBarDelegate::GetLinkURL() const { ...@@ -116,14 +89,16 @@ GURL FlashDeprecationInfoBarDelegate::GetLinkURL() const {
bool FlashDeprecationInfoBarDelegate::ShouldExpire( bool FlashDeprecationInfoBarDelegate::ShouldExpire(
const NavigationDetails& details) const { const NavigationDetails& details) const {
bool minimum_duration_elapsed = base::Time::Now() - display_start_ > // This duration is the same as the "default browser" banner's duration.
kMinimumDurationBeforeExpiryOnNavigation; const bool minimum_duration_elapsed =
(base::Time::Now() - display_start_) > base::TimeDelta::FromSeconds(8);
return minimum_duration_elapsed && return minimum_duration_elapsed &&
ConfirmInfoBarDelegate::ShouldExpire(details); ConfirmInfoBarDelegate::ShouldExpire(details);
} }
void FlashDeprecationInfoBarDelegate::InfoBarDismissed() { void FlashDeprecationInfoBarDelegate::InfoBarDismissed() {
ActivateFlashDeprecationWarningCooldown(profile_); profile_->GetPrefs()->SetTime(prefs::kPluginsDeprecationInfobarLastShown,
base::Time::Now());
} }
base::string16 FlashDeprecationInfoBarDelegate::GetMessageText() const { base::string16 FlashDeprecationInfoBarDelegate::GetMessageText() const {
...@@ -136,18 +111,16 @@ int FlashDeprecationInfoBarDelegate::GetButtons() const { ...@@ -136,18 +111,16 @@ int FlashDeprecationInfoBarDelegate::GetButtons() const {
base::string16 FlashDeprecationInfoBarDelegate::GetButtonLabel( base::string16 FlashDeprecationInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const { InfoBarButton button) const {
DCHECK_EQ(button, BUTTON_OK);
return l10n_util::GetStringUTF16(IDS_TURN_OFF); return l10n_util::GetStringUTF16(IDS_TURN_OFF);
} }
bool FlashDeprecationInfoBarDelegate::Accept() { bool FlashDeprecationInfoBarDelegate::Accept() {
HostContentSettingsMap* host_content_settings_map = HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(profile_); HostContentSettingsMapFactory::GetForProfile(profile_);
// Can be nullptr in tests. // Can be null in tests.
if (!host_content_settings_map) if (host_content_settings_map) {
return true; host_content_settings_map->SetDefaultContentSetting(
ContentSettingsType::PLUGINS, CONTENT_SETTING_DEFAULT);
host_content_settings_map->SetDefaultContentSetting( }
ContentSettingsType::PLUGINS, CONTENT_SETTING_DEFAULT);
return true; return true;
} }
...@@ -5,15 +5,12 @@ ...@@ -5,15 +5,12 @@
#ifndef CHROME_BROWSER_PLUGINS_FLASH_DEPRECATION_INFOBAR_DELEGATE_H_ #ifndef CHROME_BROWSER_PLUGINS_FLASH_DEPRECATION_INFOBAR_DELEGATE_H_
#define CHROME_BROWSER_PLUGINS_FLASH_DEPRECATION_INFOBAR_DELEGATE_H_ #define CHROME_BROWSER_PLUGINS_FLASH_DEPRECATION_INFOBAR_DELEGATE_H_
#include "base/time/time.h"
#include "components/infobars/core/confirm_infobar_delegate.h" #include "components/infobars/core/confirm_infobar_delegate.h"
class Profile; class Profile;
class InfoBarService; class InfoBarService;
namespace base {
class Time;
}
class FlashDeprecationInfoBarDelegate : public ConfirmInfoBarDelegate { class FlashDeprecationInfoBarDelegate : public ConfirmInfoBarDelegate {
public: public:
static void Create(InfoBarService* infobar_service, Profile* profile); static void Create(InfoBarService* infobar_service, Profile* profile);
...@@ -43,7 +40,7 @@ class FlashDeprecationInfoBarDelegate : public ConfirmInfoBarDelegate { ...@@ -43,7 +40,7 @@ class FlashDeprecationInfoBarDelegate : public ConfirmInfoBarDelegate {
// The time at which the banner has started to be displayed. Used to determine // The time at which the banner has started to be displayed. Used to determine
// if the banner should expire on navigation, based on how long it has been // if the banner should expire on navigation, based on how long it has been
// visible. // visible.
base::Time display_start_; base::Time display_start_ = base::Time::Now();
}; };
#endif // CHROME_BROWSER_PLUGINS_FLASH_DEPRECATION_INFOBAR_DELEGATE_H_ #endif // CHROME_BROWSER_PLUGINS_FLASH_DEPRECATION_INFOBAR_DELEGATE_H_
...@@ -38,7 +38,7 @@ class PreviewsLitePageInfoBarDelegate : public ConfirmInfoBarDelegate { ...@@ -38,7 +38,7 @@ class PreviewsLitePageInfoBarDelegate : public ConfirmInfoBarDelegate {
PreviewsLitePageInfoBarDelegate(); PreviewsLitePageInfoBarDelegate();
// ConfirmInfoBarDelegate: // ConfirmInfoBarDelegate:
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; InfoBarIdentifier GetIdentifier() const override;
void InfoBarDismissed() override; void InfoBarDismissed() override;
int GetButtons() const override; int GetButtons() const override;
base::string16 GetMessageText() const override; base::string16 GetMessageText() const override;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <utility> #include <utility>
#include "base/time/clock.h" #include "base/time/clock.h"
#include "base/time/default_clock.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -26,24 +25,12 @@ ...@@ -26,24 +25,12 @@
#include "chrome/browser/ssl/known_interception_disclosure_infobar.h" #include "chrome/browser/ssl/known_interception_disclosure_infobar.h"
#endif #endif
namespace {
// How long to suppress the disclosure UI after showing it to the user. On
// Android, this is measured across browser sessions (which tend to be short)
// by storing the last dismissal time in a pref. On Desktop, the last dismissal
// time is stored in memory, so this is is only measured within the same
// browsing session (and thus will trigger on every browser startup).
constexpr base::TimeDelta kMessageCooldown = base::TimeDelta::FromDays(7);
} // namespace
KnownInterceptionDisclosureCooldown* KnownInterceptionDisclosureCooldown*
KnownInterceptionDisclosureCooldown::GetInstance() { KnownInterceptionDisclosureCooldown::GetInstance() {
return base::Singleton<KnownInterceptionDisclosureCooldown>::get(); return base::Singleton<KnownInterceptionDisclosureCooldown>::get();
} }
bool KnownInterceptionDisclosureCooldown:: bool KnownInterceptionDisclosureCooldown::IsActive(Profile* profile) {
IsKnownInterceptionDisclosureCooldownActive(Profile* profile) {
base::Time last_dismissal; base::Time last_dismissal;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
...@@ -53,15 +40,11 @@ bool KnownInterceptionDisclosureCooldown:: ...@@ -53,15 +40,11 @@ bool KnownInterceptionDisclosureCooldown::
last_dismissal = last_dismissal_time_; last_dismissal = last_dismissal_time_;
#endif #endif
// More than |kMessageCooldown| days have passed. // Suppress the disclosure UI for 7 days after showing it to the user.
if (clock_->Now() - last_dismissal > kMessageCooldown) return (clock_->Now() - last_dismissal) <= base::TimeDelta::FromDays(7);
return false;
return true;
} }
void KnownInterceptionDisclosureCooldown:: void KnownInterceptionDisclosureCooldown::Activate(Profile* profile) {
ActivateKnownInterceptionDisclosureCooldown(Profile* profile) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
profile->GetPrefs()->SetTime( profile->GetPrefs()->SetTime(
prefs::kKnownInterceptionDisclosureInfobarLastShown, clock_->Now()); prefs::kKnownInterceptionDisclosureInfobarLastShown, clock_->Now());
...@@ -75,16 +58,16 @@ void KnownInterceptionDisclosureCooldown::SetClockForTesting( ...@@ -75,16 +58,16 @@ void KnownInterceptionDisclosureCooldown::SetClockForTesting(
clock_ = std::move(clock); clock_ = std::move(clock);
} }
KnownInterceptionDisclosureCooldown::KnownInterceptionDisclosureCooldown() KnownInterceptionDisclosureCooldown::KnownInterceptionDisclosureCooldown() =
: clock_(std::make_unique<base::DefaultClock>()) {} default;
KnownInterceptionDisclosureCooldown::~KnownInterceptionDisclosureCooldown() = KnownInterceptionDisclosureCooldown::~KnownInterceptionDisclosureCooldown() =
default; default;
void MaybeShowKnownInterceptionDisclosureDialog( void MaybeShowKnownInterceptionDisclosureDialog(
content::WebContents* web_contents, content::WebContents* web_contents,
net::CertStatus cert_status) { net::CertStatus cert_status) {
KnownInterceptionDisclosureCooldown* disclosure_tracker = auto* disclosure_tracker = KnownInterceptionDisclosureCooldown::GetInstance();
KnownInterceptionDisclosureCooldown::GetInstance();
if (!(cert_status & net::CERT_STATUS_KNOWN_INTERCEPTION_DETECTED) && if (!(cert_status & net::CERT_STATUS_KNOWN_INTERCEPTION_DETECTED) &&
!disclosure_tracker->get_has_seen_known_interception()) { !disclosure_tracker->get_has_seen_known_interception()) {
return; return;
...@@ -100,8 +83,7 @@ void MaybeShowKnownInterceptionDisclosureDialog( ...@@ -100,8 +83,7 @@ void MaybeShowKnownInterceptionDisclosureDialog(
std::make_unique<KnownInterceptionDisclosureInfoBarDelegate>(profile); std::make_unique<KnownInterceptionDisclosureInfoBarDelegate>(profile);
infobars::InfoBar* infobar = nullptr; infobars::InfoBar* infobar = nullptr;
if (!KnownInterceptionDisclosureCooldown::GetInstance() if (!KnownInterceptionDisclosureCooldown::GetInstance()->IsActive(profile)) {
->IsKnownInterceptionDisclosureCooldownActive(profile)) {
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
infobar = infobar_service->AddInfoBar( infobar = infobar_service->AddInfoBar(
KnownInterceptionDisclosureInfoBar::CreateInfoBar(std::move(delegate))); KnownInterceptionDisclosureInfoBar::CreateInfoBar(std::move(delegate)));
...@@ -135,8 +117,7 @@ bool KnownInterceptionDisclosureInfoBarDelegate::ShouldExpire( ...@@ -135,8 +117,7 @@ bool KnownInterceptionDisclosureInfoBarDelegate::ShouldExpire(
} }
void KnownInterceptionDisclosureInfoBarDelegate::InfoBarDismissed() { void KnownInterceptionDisclosureInfoBarDelegate::InfoBarDismissed() {
KnownInterceptionDisclosureCooldown::GetInstance() KnownInterceptionDisclosureCooldown::GetInstance()->Activate(profile_);
->ActivateKnownInterceptionDisclosureCooldown(profile_);
Cancel(); Cancel();
} }
...@@ -154,8 +135,7 @@ int KnownInterceptionDisclosureInfoBarDelegate::GetButtons() const { ...@@ -154,8 +135,7 @@ int KnownInterceptionDisclosureInfoBarDelegate::GetButtons() const {
} }
bool KnownInterceptionDisclosureInfoBarDelegate::Accept() { bool KnownInterceptionDisclosureInfoBarDelegate::Accept() {
KnownInterceptionDisclosureCooldown::GetInstance() KnownInterceptionDisclosureCooldown::GetInstance()->Activate(profile_);
->ActivateKnownInterceptionDisclosureCooldown(profile_);
return true; return true;
} }
...@@ -167,17 +147,7 @@ int KnownInterceptionDisclosureInfoBarDelegate::GetIconId() const { ...@@ -167,17 +147,7 @@ int KnownInterceptionDisclosureInfoBarDelegate::GetIconId() const {
base::string16 KnownInterceptionDisclosureInfoBarDelegate::GetButtonLabel( base::string16 KnownInterceptionDisclosureInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const { InfoBarButton button) const {
switch (button) { return l10n_util::GetStringUTF16(IDS_KNOWN_INTERCEPTION_INFOBAR_BUTTON_TEXT);
case BUTTON_OK:
return l10n_util::GetStringUTF16(
IDS_KNOWN_INTERCEPTION_INFOBAR_BUTTON_TEXT);
case BUTTON_CANCEL:
FALLTHROUGH;
case BUTTON_NONE:
NOTREACHED();
}
NOTREACHED();
return base::string16();
} }
base::string16 KnownInterceptionDisclosureInfoBarDelegate::GetDescriptionText() base::string16 KnownInterceptionDisclosureInfoBarDelegate::GetDescriptionText()
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <algorithm> #include <algorithm>
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/time/default_clock.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "components/infobars/core/confirm_infobar_delegate.h" #include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar_delegate.h" #include "components/infobars/core/infobar_delegate.h"
...@@ -27,13 +28,17 @@ class PrefRegistrySyncable; ...@@ -27,13 +28,17 @@ class PrefRegistrySyncable;
class Profile; class Profile;
// Singleton that tracks the known interception disclosure cooldown time. // Singleton that tracks the known interception disclosure cooldown time. On
// Android, this is measured across browser sessions (which tend to be short) by
// storing the last dismissal time in a pref. On Desktop, the last dismissal
// time is stored in memory, so this is is only measured within the same
// browsing session (and thus will trigger on every browser startup).
class KnownInterceptionDisclosureCooldown { class KnownInterceptionDisclosureCooldown {
public: public:
static KnownInterceptionDisclosureCooldown* GetInstance(); static KnownInterceptionDisclosureCooldown* GetInstance();
bool IsKnownInterceptionDisclosureCooldownActive(Profile* profile); bool IsActive(Profile* profile);
void ActivateKnownInterceptionDisclosureCooldown(Profile* profile); void Activate(Profile* profile);
bool get_has_seen_known_interception() { bool get_has_seen_known_interception() {
return has_seen_known_interception_; return has_seen_known_interception_;
...@@ -51,7 +56,7 @@ class KnownInterceptionDisclosureCooldown { ...@@ -51,7 +56,7 @@ class KnownInterceptionDisclosureCooldown {
KnownInterceptionDisclosureCooldown(); KnownInterceptionDisclosureCooldown();
~KnownInterceptionDisclosureCooldown(); ~KnownInterceptionDisclosureCooldown();
std::unique_ptr<base::Clock> clock_; std::unique_ptr<base::Clock> clock_ = std::make_unique<base::DefaultClock>();
bool has_seen_known_interception_ = false; bool has_seen_known_interception_ = false;
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
......
...@@ -25,10 +25,7 @@ void AdsBlockedInfobarDelegate::Create(InfoBarService* infobar_service) { ...@@ -25,10 +25,7 @@ void AdsBlockedInfobarDelegate::Create(InfoBarService* infobar_service) {
base::WrapUnique(new AdsBlockedInfobarDelegate()))); base::WrapUnique(new AdsBlockedInfobarDelegate())));
} }
AdsBlockedInfobarDelegate::AdsBlockedInfobarDelegate() AdsBlockedInfobarDelegate::~AdsBlockedInfobarDelegate() = default;
: ConfirmInfoBarDelegate() {}
AdsBlockedInfobarDelegate::~AdsBlockedInfobarDelegate() {}
base::string16 AdsBlockedInfobarDelegate::GetExplanationText() const { base::string16 AdsBlockedInfobarDelegate::GetExplanationText() const {
return l10n_util::GetStringUTF16(IDS_BLOCKED_ADS_PROMPT_EXPLANATION); return l10n_util::GetStringUTF16(IDS_BLOCKED_ADS_PROMPT_EXPLANATION);
...@@ -54,20 +51,14 @@ GURL AdsBlockedInfobarDelegate::GetLinkURL() const { ...@@ -54,20 +51,14 @@ GURL AdsBlockedInfobarDelegate::GetLinkURL() const {
bool AdsBlockedInfobarDelegate::LinkClicked(WindowOpenDisposition disposition) { bool AdsBlockedInfobarDelegate::LinkClicked(WindowOpenDisposition disposition) {
if (infobar_expanded_) { if (infobar_expanded_) {
DCHECK_EQ(disposition, WindowOpenDisposition::NEW_FOREGROUND_TAB);
infobar()->owner()->OpenURL(GetLinkURL(),
WindowOpenDisposition::NEW_FOREGROUND_TAB);
ChromeSubresourceFilterClient::LogAction( ChromeSubresourceFilterClient::LogAction(
SubresourceFilterAction::kClickedLearnMore); SubresourceFilterAction::kClickedLearnMore);
} else { return ConfirmInfoBarDelegate::LinkClicked(disposition);
ChromeSubresourceFilterClient::LogAction(
SubresourceFilterAction::kDetailsShown);
infobar_expanded_ = true;
} }
// Returning false keeps the infobar up, which is the behavior we want in all
// cases. If the user is navigating via a new foreground tab we do not want ChromeSubresourceFilterClient::LogAction(
// the infobar going away on the tab (and therefore invoking our smart-hiding SubresourceFilterAction::kDetailsShown);
// logic). infobar_expanded_ = true;
return false; return false;
} }
...@@ -81,15 +72,15 @@ int AdsBlockedInfobarDelegate::GetButtons() const { ...@@ -81,15 +72,15 @@ int AdsBlockedInfobarDelegate::GetButtons() const {
base::string16 AdsBlockedInfobarDelegate::GetButtonLabel( base::string16 AdsBlockedInfobarDelegate::GetButtonLabel(
InfoBarButton button) const { InfoBarButton button) const {
if (button == BUTTON_OK) return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_OK
return l10n_util::GetStringUTF16(IDS_OK); : IDS_APP_MENU_RELOAD);
return l10n_util::GetStringUTF16(IDS_APP_MENU_RELOAD);
} }
bool AdsBlockedInfobarDelegate::Cancel() { bool AdsBlockedInfobarDelegate::Cancel() {
content::WebContents* web_contents = auto* filter_client = ChromeSubresourceFilterClient::FromWebContents(
InfoBarService::WebContentsFromInfoBar(infobar()); InfoBarService::WebContentsFromInfoBar(infobar()));
ChromeSubresourceFilterClient::FromWebContents(web_contents) filter_client->OnReloadRequested();
->OnReloadRequested();
return true; return true;
} }
AdsBlockedInfobarDelegate::AdsBlockedInfobarDelegate() = default;
...@@ -28,7 +28,7 @@ class AdsBlockedInfobarDelegate : public ConfirmInfoBarDelegate { ...@@ -28,7 +28,7 @@ class AdsBlockedInfobarDelegate : public ConfirmInfoBarDelegate {
base::string16 GetToggleText() const; base::string16 GetToggleText() const;
// ConfirmInfoBarDelegate: // ConfirmInfoBarDelegate:
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override; InfoBarIdentifier GetIdentifier() const override;
int GetIconId() const override; int GetIconId() const override;
GURL GetLinkURL() const override; GURL GetLinkURL() const override;
bool LinkClicked(WindowOpenDisposition disposition) override; bool LinkClicked(WindowOpenDisposition disposition) override;
......
...@@ -5,17 +5,13 @@ ...@@ -5,17 +5,13 @@
#include "components/infobars/core/confirm_infobar_delegate.h" #include "components/infobars/core/confirm_infobar_delegate.h"
#include "base/logging.h" #include "base/logging.h"
#include "components/infobars/core/infobar.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/strings/grit/ui_strings.h" #include "ui/strings/grit/ui_strings.h"
using infobars::InfoBarDelegate; ConfirmInfoBarDelegate::~ConfirmInfoBarDelegate() = default;
ConfirmInfoBarDelegate::~ConfirmInfoBarDelegate() { infobars::InfoBarDelegate::InfoBarAutomationType
} ConfirmInfoBarDelegate::GetInfoBarAutomationType() const {
InfoBarDelegate::InfoBarAutomationType
ConfirmInfoBarDelegate::GetInfoBarAutomationType() const {
return CONFIRM_INFOBAR; return CONFIRM_INFOBAR;
} }
...@@ -29,8 +25,8 @@ int ConfirmInfoBarDelegate::GetButtons() const { ...@@ -29,8 +25,8 @@ int ConfirmInfoBarDelegate::GetButtons() const {
base::string16 ConfirmInfoBarDelegate::GetButtonLabel( base::string16 ConfirmInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const { InfoBarButton button) const {
return l10n_util::GetStringUTF16((button == BUTTON_OK) ? return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_APP_OK
IDS_APP_OK : IDS_APP_CANCEL); : IDS_APP_CANCEL);
} }
bool ConfirmInfoBarDelegate::OKButtonTriggersUACPrompt() const { bool ConfirmInfoBarDelegate::OKButtonTriggersUACPrompt() const {
...@@ -45,9 +41,10 @@ bool ConfirmInfoBarDelegate::Cancel() { ...@@ -45,9 +41,10 @@ bool ConfirmInfoBarDelegate::Cancel() {
return true; return true;
} }
ConfirmInfoBarDelegate::ConfirmInfoBarDelegate() {} ConfirmInfoBarDelegate::ConfirmInfoBarDelegate() = default;
bool ConfirmInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { bool ConfirmInfoBarDelegate::EqualsDelegate(
infobars::InfoBarDelegate* delegate) const {
ConfirmInfoBarDelegate* confirm_delegate = ConfirmInfoBarDelegate* confirm_delegate =
delegate->AsConfirmInfoBarDelegate(); delegate->AsConfirmInfoBarDelegate();
return confirm_delegate && return confirm_delegate &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment