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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
// Copyright 2020 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/safe_browsing/android/password_reuse_controller_android.h"
#include <memory>
#include <string>
#include "base/android/build_info.h"
#include "base/functional/callback.h"
#include "chrome/browser/password_manager/android/password_manager_android_util.h"
#include "chrome/browser/ui/android/safe_browsing/password_reuse_dialog_view_android.h"
#include "components/password_manager/core/browser/features/password_features.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/browser/password_protection/metrics_util.h"
#include "components/strings/grit/components_strings.h"
#include "ui/android/window_android.h"
#include "ui/base/l10n/l10n_util.h"
namespace safe_browsing {
PasswordReuseControllerAndroid::PasswordReuseControllerAndroid(
content::WebContents* web_contents,
ChromePasswordProtectionService* service,
PrefService* pref_service,
ReusedPasswordAccountType password_type,
OnWarningDone done_callback)
: content::WebContentsObserver(web_contents),
service_(service),
pref_service_(pref_service),
url_(web_contents->GetLastCommittedURL()),
password_type_(password_type),
window_android_(web_contents->GetTopLevelNativeWindow()),
done_callback_(std::move(done_callback)) {
modal_construction_start_time_ = base::TimeTicks::Now();
// |service| can be nullptr in tests
if (service)
service_->AddObserver(this);
}
PasswordReuseControllerAndroid::~PasswordReuseControllerAndroid() {
if (service_)
service_->RemoveObserver(this);
dialog_view_.reset();
LogModalWarningDialogLifetime(modal_construction_start_time_);
}
void PasswordReuseControllerAndroid::ShowDialog() {
dialog_view_ = std::make_unique<PasswordReuseDialogViewAndroid>(this);
DCHECK(window_android_);
dialog_view_->Show(window_android_);
}
void PasswordReuseControllerAndroid::ShowCheckPasswords() {
if (done_callback_)
std::move(done_callback_).Run(WarningAction::CHANGE_PASSWORD);
delete this;
}
void PasswordReuseControllerAndroid::IgnoreDialog() {
if (done_callback_)
std::move(done_callback_).Run(WarningAction::IGNORE_WARNING);
delete this;
}
void PasswordReuseControllerAndroid::CloseDialog() {
if (done_callback_)
std::move(done_callback_).Run(WarningAction::CLOSE);
delete this;
}
std::u16string PasswordReuseControllerAndroid::GetPrimaryButtonText() const {
if (password_type_.account_type() == ReusedPasswordAccountType::GMAIL &&
password_type_.is_account_syncing()) {
return l10n_util::GetStringUTF16(IDS_PAGE_INFO_PROTECT_ACCOUNT_BUTTON);
}
// The modal can be shown on automotive, but should not lead users to the
// GMSCore Password Check UI, as that is not optimized for automotive.
if (base::android::BuildInfo::GetInstance()->is_automotive()) {
return l10n_util::GetStringUTF16(IDS_CLOSE);
}
// This is a rare corner-case. It can only occur for users with no GMS Core,
// outdated GMS Core, or users who have failed automatic password migration
// to GMS Core. In addition, for this case to occur the user has to have
// entered a password on a phishing website in the exact time interval in
// which Chrome was exporting passwods to an internally-stored CSV or
// in-between export tries if the first attempt failed.
if (base::FeatureList::IsEnabled(
password_manager::features::kLoginDbDeprecationAndroid) &&
!password_manager_android_util::LoginDbDeprecationReady(pref_service_)) {
return l10n_util::GetStringUTF16(IDS_CLOSE);
}
if (password_type_.account_type() ==
ReusedPasswordAccountType::SAVED_PASSWORD) {
return l10n_util::GetStringUTF16(IDS_PAGE_INFO_CHECK_PASSWORDS_BUTTON);
}
return l10n_util::GetStringUTF16(IDS_CLOSE);
}
std::u16string PasswordReuseControllerAndroid::GetSecondaryButtonText() const {
if (password_type_.account_type() == ReusedPasswordAccountType::GMAIL &&
password_type_.is_account_syncing()) {
return l10n_util::GetStringUTF16(
IDS_PAGE_INFO_IGNORE_PASSWORD_WARNING_BUTTON);
}
// The modal can be shown on automotive, but without any call to action as
// those are not optimized for automotive.
if (base::android::BuildInfo::GetInstance()->is_automotive()) {
return std::u16string();
}
if (base::FeatureList::IsEnabled(
password_manager::features::kLoginDbDeprecationAndroid) &&
!password_manager_android_util::LoginDbDeprecationReady(pref_service_)) {
return std::u16string();
}
if (password_type_.account_type() ==
ReusedPasswordAccountType::SAVED_PASSWORD) {
return l10n_util::GetStringUTF16(
IDS_PAGE_INFO_IGNORE_PASSWORD_WARNING_BUTTON);
}
return std::u16string();
}
std::u16string PasswordReuseControllerAndroid::GetWarningDetailText() const {
return service_->GetWarningDetailText(password_type_);
}
std::u16string PasswordReuseControllerAndroid::GetTitle() const {
if (password_type_.account_type() ==
ReusedPasswordAccountType::SAVED_PASSWORD) {
return l10n_util::GetStringUTF16(
IDS_PAGE_INFO_CHANGE_PASSWORD_SAVED_PASSWORD_SUMMARY);
}
return l10n_util::GetStringUTF16(IDS_PAGE_INFO_CHANGE_PASSWORD_SUMMARY);
}
void PasswordReuseControllerAndroid::OnGaiaPasswordChanged() {
delete this;
// Chrome on Android should not be able to capture Gaia password change
// events.
NOTREACHED();
}
void PasswordReuseControllerAndroid::OnMarkingSiteAsLegitimate(
const GURL& url) {
if (url_.GetWithEmptyPath() == url.GetWithEmptyPath())
delete this;
// Modal dialog on Android is above the screen, this function can't be called.
NOTREACHED();
}
void PasswordReuseControllerAndroid::InvokeActionForTesting(
WarningAction action) {
CloseDialog();
}
WarningUIType PasswordReuseControllerAndroid::GetObserverType() {
return WarningUIType::MODAL_DIALOG;
}
void PasswordReuseControllerAndroid::WebContentsDestroyed() {
delete this;
}
void PasswordReuseControllerAndroid::SetReusedPasswordAccountTypeForTesting(
ReusedPasswordAccountType password_type) {
password_type_ = password_type;
}
} // namespace safe_browsing
|