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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
// 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.
#include "chrome/browser/ssl/known_interception_disclosure_infobar_delegate.h"
#include <memory>
#include <utility>
#include "base/time/clock.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/infobars/confirm_infobar_creator.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "components/infobars/content/content_infobar_manager.h"
#include "components/infobars/core/infobar.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/security_interstitials/content/urls.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#if BUILDFLAG(IS_ANDROID)
#include "chrome/browser/android/android_theme_resources.h"
#include "chrome/browser/android/tab_android.h"
#include "chrome/browser/ssl/known_interception_disclosure_infobar.h"
#endif
KnownInterceptionDisclosureCooldown*
KnownInterceptionDisclosureCooldown::GetInstance() {
return base::Singleton<KnownInterceptionDisclosureCooldown>::get();
}
bool KnownInterceptionDisclosureCooldown::IsActive(Profile* profile) {
base::Time last_dismissal;
#if BUILDFLAG(IS_ANDROID)
last_dismissal = profile->GetPrefs()->GetTime(
prefs::kKnownInterceptionDisclosureInfobarLastShown);
#else
last_dismissal = last_dismissal_time_;
#endif
// Suppress the disclosure UI for 7 days after showing it to the user.
return (clock_->Now() - last_dismissal) <= base::Days(7);
}
void KnownInterceptionDisclosureCooldown::Activate(Profile* profile) {
#if BUILDFLAG(IS_ANDROID)
profile->GetPrefs()->SetTime(
prefs::kKnownInterceptionDisclosureInfobarLastShown, clock_->Now());
#else
last_dismissal_time_ = clock_->Now();
#endif
}
void KnownInterceptionDisclosureCooldown::SetClockForTesting(
std::unique_ptr<base::Clock> clock) {
clock_ = std::move(clock);
}
KnownInterceptionDisclosureCooldown::KnownInterceptionDisclosureCooldown() =
default;
KnownInterceptionDisclosureCooldown::~KnownInterceptionDisclosureCooldown() =
default;
void MaybeShowKnownInterceptionDisclosureDialog(
content::WebContents* web_contents,
net::CertStatus cert_status) {
auto* disclosure_tracker = KnownInterceptionDisclosureCooldown::GetInstance();
if (!(cert_status & net::CERT_STATUS_KNOWN_INTERCEPTION_DETECTED) &&
!disclosure_tracker->get_has_seen_known_interception()) {
return;
}
disclosure_tracker->set_has_seen_known_interception(true);
infobars::ContentInfoBarManager* infobar_manager =
infobars::ContentInfoBarManager::FromWebContents(web_contents);
auto* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
auto delegate =
std::make_unique<KnownInterceptionDisclosureInfoBarDelegate>(profile);
if (!KnownInterceptionDisclosureCooldown::GetInstance()->IsActive(profile)) {
#if BUILDFLAG(IS_ANDROID)
infobar_manager->AddInfoBar(
KnownInterceptionDisclosureInfoBar::CreateInfoBar(std::move(delegate)));
#else
infobar_manager->AddInfoBar(CreateConfirmInfoBar(std::move(delegate)));
#endif
}
}
KnownInterceptionDisclosureInfoBarDelegate::
KnownInterceptionDisclosureInfoBarDelegate(Profile* profile)
: profile_(profile) {}
infobars::InfoBarDelegate::InfoBarIdentifier
KnownInterceptionDisclosureInfoBarDelegate::GetIdentifier() const {
return KNOWN_INTERCEPTION_DISCLOSURE_INFOBAR_DELEGATE;
}
std::u16string KnownInterceptionDisclosureInfoBarDelegate::GetLinkText() const {
return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
}
GURL KnownInterceptionDisclosureInfoBarDelegate::GetLinkURL() const {
return GURL("chrome://connection-monitoring-detected/");
}
bool KnownInterceptionDisclosureInfoBarDelegate::ShouldExpire(
const NavigationDetails& details) const {
return false;
}
void KnownInterceptionDisclosureInfoBarDelegate::InfoBarDismissed() {
KnownInterceptionDisclosureCooldown::GetInstance()->Activate(profile_);
Cancel();
}
std::u16string KnownInterceptionDisclosureInfoBarDelegate::GetMessageText()
const {
return l10n_util::GetStringUTF16(IDS_KNOWN_INTERCEPTION_HEADER);
}
int KnownInterceptionDisclosureInfoBarDelegate::GetButtons() const {
#if BUILDFLAG(IS_ANDROID)
return BUTTON_OK;
#else
return BUTTON_NONE;
#endif
}
bool KnownInterceptionDisclosureInfoBarDelegate::Accept() {
KnownInterceptionDisclosureCooldown::GetInstance()->Activate(profile_);
return true;
}
// Platform specific implementations.
#if BUILDFLAG(IS_ANDROID)
int KnownInterceptionDisclosureInfoBarDelegate::GetIconId() const {
return IDR_ANDROID_INFOBAR_WARNING;
}
std::u16string KnownInterceptionDisclosureInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const {
return l10n_util::GetStringUTF16(IDS_KNOWN_INTERCEPTION_INFOBAR_BUTTON_TEXT);
}
std::u16string KnownInterceptionDisclosureInfoBarDelegate::GetDescriptionText()
const {
return l10n_util::GetStringUTF16(IDS_KNOWN_INTERCEPTION_BODY1);
}
// static
void KnownInterceptionDisclosureInfoBarDelegate::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
registry->RegisterTimePref(
prefs::kKnownInterceptionDisclosureInfobarLastShown, base::Time());
}
#endif
|