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
|
// 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/password_manager/android/credential_leak_controller_android.h"
#include <memory>
#include "base/android/jni_android.h"
#include "chrome/browser/password_manager/android/password_checkup_launcher_helper.h"
#include "chrome/browser/password_manager/android/password_manager_android_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/android/passwords/credential_leak_dialog_view_android.h"
#include "components/password_manager/core/browser/features/password_features.h"
#include "components/password_manager/core/browser/leak_detection_dialog_utils.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "ui/android/window_android.h"
using password_manager::CreateDialogTraits;
using password_manager::CredentialLeakType;
using password_manager::PasswordCheckReferrerAndroid;
using password_manager::metrics_util::LeakDialogDismissalReason;
using password_manager::metrics_util::LeakDialogMetricsRecorder;
using password_manager::metrics_util::LeakDialogType;
namespace {
CredentialLeakType AdjustLeakTypeForLoginDbDeprecation(
CredentialLeakType leak_type,
Profile* profile) {
if (base::FeatureList::IsEnabled(
password_manager::features::kLoginDbDeprecationAndroid) &&
!password_manager_android_util::LoginDbDeprecationReady(
profile->GetPrefs())) {
// While the login DB deprecation is being prepared (passwords are
// exported), saved passwords from the DB are still visible to the leak
// service (until the export finishes). Resetting the leak type to 0,
// ensures we don't show a dialog with options for saved passwords
// (i.e. Password Checkup), because those are not available at this time.
return 0;
}
return leak_type;
}
} // namespace
CredentialLeakControllerAndroid::CredentialLeakControllerAndroid(
password_manager::CredentialLeakType leak_type,
const GURL& origin,
const std::u16string& username,
Profile* profile,
ui::WindowAndroid* window_android,
std::unique_ptr<PasswordCheckupLauncherHelper> checkup_launcher,
std::unique_ptr<LeakDialogMetricsRecorder> metrics_recorder,
std::string account_email)
: leak_type_(AdjustLeakTypeForLoginDbDeprecation(leak_type, profile)),
origin_(origin),
username_(username),
profile_(profile),
window_android_(window_android),
leak_dialog_traits_(CreateDialogTraits(leak_type_)),
checkup_launcher_(std::move(checkup_launcher)),
metrics_recorder_(std::move(metrics_recorder)),
account_email_(account_email) {}
CredentialLeakControllerAndroid::~CredentialLeakControllerAndroid() = default;
void CredentialLeakControllerAndroid::ShowDialog() {
dialog_view_ = std::make_unique<CredentialLeakDialogViewAndroid>(this);
dialog_view_->Show(window_android_);
}
void CredentialLeakControllerAndroid::OnCancelDialog() {
metrics_recorder_->LogLeakDialogTypeAndDismissalReason(
LeakDialogDismissalReason::kClickedClose);
delete this;
}
void CredentialLeakControllerAndroid::OnAcceptDialog() {
LeakDialogType dialog_type = password_manager::GetLeakDialogType(leak_type_);
LeakDialogDismissalReason dismissal_reason =
LeakDialogDismissalReason::kClickedOk;
switch (dialog_type) {
case LeakDialogType::kChange:
dismissal_reason = LeakDialogDismissalReason::kClickedOk;
break;
case LeakDialogType::kCheckup:
case LeakDialogType::kCheckupAndChange:
dismissal_reason = LeakDialogDismissalReason::kClickedCheckPasswords;
break;
}
metrics_recorder_->LogLeakDialogTypeAndDismissalReason(dismissal_reason);
JNIEnv* env = base::android::AttachCurrentThread();
switch (dialog_type) {
case LeakDialogType::kChange:
// No-op.
break;
case LeakDialogType::kCheckup:
case LeakDialogType::kCheckupAndChange:
checkup_launcher_->LaunchCheckupOnDevice(
env, profile_, window_android_,
PasswordCheckReferrerAndroid::kLeakDialog, account_email_);
break;
}
delete this;
}
void CredentialLeakControllerAndroid::OnCloseDialog() {
metrics_recorder_->LogLeakDialogTypeAndDismissalReason(
LeakDialogDismissalReason::kNoDirectInteraction);
delete this;
}
std::u16string CredentialLeakControllerAndroid::GetAcceptButtonLabel() const {
return leak_dialog_traits_->GetAcceptButtonLabel();
}
std::u16string CredentialLeakControllerAndroid::GetCancelButtonLabel() const {
return leak_dialog_traits_->GetCancelButtonLabel();
}
std::u16string CredentialLeakControllerAndroid::GetDescription() const {
return leak_dialog_traits_->GetDescription();
}
std::u16string CredentialLeakControllerAndroid::GetTitle() const {
return leak_dialog_traits_->GetTitle();
}
bool CredentialLeakControllerAndroid::ShouldShowCancelButton() const {
return leak_dialog_traits_->ShouldShowCancelButton();
}
|