1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SSL_KNOWN_INTERCEPTION_DISCLOSURE_INFOBAR_DELEGATE_H_
#define CHROME_BROWSER_SSL_KNOWN_INTERCEPTION_DISCLOSURE_INFOBAR_DELEGATE_H_
#include <algorithm>
#include "base/memory/raw_ptr.h"
#include "base/memory/singleton.h"
#include "base/time/default_clock.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/infobars/core/confirm_infobar_delegate.h"
#include "components/infobars/core/infobar_delegate.h"
#include "net/cert/cert_status_flags.h"
#include "url/gurl.h"
namespace base {
class Clock;
} // namespace base
namespace content {
class WebContents;
}
namespace user_prefs {
class PrefRegistrySyncable;
} // namespace user_prefs
class Profile;
// 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 {
public:
static KnownInterceptionDisclosureCooldown* GetInstance();
bool IsActive(Profile* profile);
void Activate(Profile* profile);
bool get_has_seen_known_interception() {
return has_seen_known_interception_;
}
void set_has_seen_known_interception(bool has_seen) {
has_seen_known_interception_ = has_seen;
}
void SetClockForTesting(std::unique_ptr<base::Clock> clock);
private:
friend struct base::DefaultSingletonTraits<
KnownInterceptionDisclosureCooldown>;
KnownInterceptionDisclosureCooldown();
~KnownInterceptionDisclosureCooldown();
std::unique_ptr<base::Clock> clock_ = std::make_unique<base::DefaultClock>();
bool has_seen_known_interception_ = false;
#if !BUILDFLAG(IS_ANDROID)
base::Time last_dismissal_time_;
#endif
};
// Shows the known interception disclosure UI if it has not been recently
// dismissed.
void MaybeShowKnownInterceptionDisclosureDialog(
content::WebContents* web_contents,
net::CertStatus cert_status);
class KnownInterceptionDisclosureInfoBarDelegate
: public ConfirmInfoBarDelegate {
public:
explicit KnownInterceptionDisclosureInfoBarDelegate(Profile* profile);
~KnownInterceptionDisclosureInfoBarDelegate() override = default;
// ConfirmInfoBarDelegate:
infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
std::u16string GetLinkText() const override;
GURL GetLinkURL() const override;
bool ShouldExpire(const NavigationDetails& details) const override;
void InfoBarDismissed() override;
std::u16string GetMessageText() const override;
int GetButtons() const override;
bool Accept() override;
#if BUILDFLAG(IS_ANDROID)
int GetIconId() const override;
std::u16string GetButtonLabel(InfoBarButton button) const override;
// This function is the equivalent of GetMessageText(), but for the portion of
// the infobar below the 'message' title for the Android infobar.
std::u16string GetDescriptionText() const;
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
#endif
private:
raw_ptr<Profile> profile_;
};
#endif // CHROME_BROWSER_SSL_KNOWN_INTERCEPTION_DISCLOSURE_INFOBAR_DELEGATE_H_
|