#include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
#include <optional>
#include <string>
#include <utility>
#include "base/auto_reset.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/timer/timer.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/feature_engagement/tracker_factory.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/password_manager/account_password_store_factory.h"
#include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "chrome/browser/password_manager/profile_password_store_factory.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_promo_util.h"
#include "chrome/browser/signin/signin_ui_util.h"
#include "chrome/browser/signin/signin_util.h"
#include "chrome/browser/ui/autofill/autofill_signin_promo_tab_helper.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/hats/hats_service.h"
#include "chrome/browser/ui/hats/hats_service_factory.h"
#include "chrome/browser/ui/hats/survey_config.h"
#include "chrome/browser/ui/hats/trust_safety_sentiment_service.h"
#include "chrome/browser/ui/hats/trust_safety_sentiment_service_factory.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/page_action/page_action_icon_type.h"
#include "chrome/browser/ui/passwords/credential_leak_dialog_controller_impl.h"
#include "chrome/browser/ui/passwords/credential_manager_dialog_controller_impl.h"
#include "chrome/browser/ui/passwords/manage_passwords_icon_view.h"
#include "chrome/browser/ui/passwords/password_dialog_prompts.h"
#include "chrome/browser/ui/passwords/ui_utils.h"
#include "chrome/browser/ui/simple_message_box.h"
#include "chrome/browser/ui/tab_dialogs.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/autofill/core/browser/logging/log_manager.h"
#include "components/autofill/core/common/save_password_progress_logger.h"
#include "components/browsing_data/content/browsing_data_helper.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/feature_engagement/public/tracker.h"
#include "components/password_manager/core/browser/browser_save_password_progress_logger.h"
#include "components/password_manager/core/browser/features/password_features.h"
#include "components/password_manager/core/browser/form_saver_impl.h"
#include "components/password_manager/core/browser/leak_detection_dialog_utils.h"
#include "components/password_manager/core/browser/move_password_to_account_store_helper.h"
#include "components/password_manager/core/browser/password_bubble_experiment.h"
#include "components/password_manager/core/browser/password_form_manager_for_ui.h"
#include "components/password_manager/core/browser/password_manager_constants.h"
#include "components/password_manager/core/browser/password_manager_metrics_util.h"
#include "components/password_manager/core/browser/password_manager_util.h"
#include "components/password_manager/core/browser/password_store/interactions_stats.h"
#include "components/password_manager/core/browser/password_ui_utils.h"
#include "components/password_manager/core/browser/ui/password_check_referrer.h"
#include "components/password_manager/core/common/credential_manager_types.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/password_manager/core/common/password_manager_ui.h"
#include "components/signin/public/base/signin_metrics.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
#if BUILDFLAG(IS_WIN)
#include "chrome/browser/password_manager/password_manager_util_win.h"
#elif BUILDFLAG(IS_MAC)
#include "chrome/browser/password_manager/password_manager_util_mac.h"
#endif
MovePasswordToAccountStoreHelper;
PasswordFormManagerForUI;
int ManagePasswordsUIController::save_fallback_timeout_in_seconds_ = …;
namespace {
Logger;
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
constexpr int kMaxNumberOfTimesKeychainErrorBubbleIsShown = …;
#endif
password_manager::PasswordStoreInterface* GetProfilePasswordStore(
content::WebContents* web_contents) { … }
password_manager::PasswordStoreInterface* GetAccountPasswordStore(
content::WebContents* web_contents) { … }
std::vector<std::unique_ptr<password_manager::PasswordForm>> CopyFormVector(
const std::vector<std::unique_ptr<password_manager::PasswordForm>>& forms) { … }
const password_manager::InteractionsStats* FindStatsByUsername(
base::span<const password_manager::InteractionsStats> stats,
const std::u16string& username) { … }
void MaybeShowPasswordManagerShortcutIPH(Browser* browser) { … }
std::optional<password_manager::BrowserSavePasswordProgressLogger>
GetSaveProgressLogger(password_manager::PasswordManagerClient* client) { … }
}
ManagePasswordsUIController::ManagePasswordsUIController(
content::WebContents* web_contents)
: … { … }
ManagePasswordsUIController::~ManagePasswordsUIController() = default;
void ManagePasswordsUIController::OnPasswordSubmitted(
std::unique_ptr<PasswordFormManagerForUI> form_manager) { … }
void ManagePasswordsUIController::OnUpdatePasswordSubmitted(
std::unique_ptr<PasswordFormManagerForUI> form_manager) { … }
void ManagePasswordsUIController::OnShowManualFallbackForSaving(
std::unique_ptr<PasswordFormManagerForUI> form_manager,
bool has_generated_password,
bool is_update) { … }
void ManagePasswordsUIController::OnHideManualFallbackForSaving() { … }
void ManagePasswordsUIController::OnOpenPasswordDetailsBubble(
const password_manager::PasswordForm& form) { … }
bool ManagePasswordsUIController::OnChooseCredentials(
std::vector<std::unique_ptr<password_manager::PasswordForm>>
local_credentials,
const url::Origin& origin,
ManagePasswordsState::CredentialsCallback callback) { … }
void ManagePasswordsUIController::OnAutoSignin(
std::vector<std::unique_ptr<password_manager::PasswordForm>> local_forms,
const url::Origin& origin) { … }
void ManagePasswordsUIController::OnPromptEnableAutoSignin() { … }
void ManagePasswordsUIController::OnAutomaticPasswordSave(
std::unique_ptr<PasswordFormManagerForUI> form_manager,
bool is_update_confirmation) { … }
void ManagePasswordsUIController::OnPasswordAutofilled(
base::span<const password_manager::PasswordForm> password_forms,
const url::Origin& origin,
base::span<const password_manager::PasswordForm> federated_matches) { … }
void ManagePasswordsUIController::OnCredentialLeak(
const password_manager::CredentialLeakType leak_type,
const GURL& url,
const std::u16string& username) { … }
void ManagePasswordsUIController::OnShowMoveToAccountBubble(
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_move) { … }
void ManagePasswordsUIController::OnBiometricAuthenticationForFilling(
PrefService* prefs) { … }
void ManagePasswordsUIController::ShowBiometricActivationConfirmation() { … }
void ManagePasswordsUIController::ShowMovePasswordBubble(
const password_manager::PasswordForm& form) { … }
void ManagePasswordsUIController::OnBiometricAuthBeforeFillingDeclined() { … }
void ManagePasswordsUIController::OnKeychainError() { … }
void ManagePasswordsUIController::OnPasskeySaved(bool gpm_pin_created) { … }
void ManagePasswordsUIController::OnPasskeyDeleted() { … }
void ManagePasswordsUIController::OnPasskeyUpdated() { … }
void ManagePasswordsUIController::OnPasskeyNotAccepted() { … }
void ManagePasswordsUIController::OnAddUsernameSaveClicked(
const std::u16string& username,
const password_manager::PasswordForm& form_to_update) { … }
void ManagePasswordsUIController::NotifyUnsyncedCredentialsWillBeDeleted(
std::vector<password_manager::PasswordForm> unsynced_credentials) { … }
void ManagePasswordsUIController::OnLoginsChanged(
password_manager::PasswordStoreInterface* ,
const password_manager::PasswordStoreChangeList& changes) { … }
void ManagePasswordsUIController::OnLoginsRetained(
password_manager::PasswordStoreInterface* ,
const std::vector<password_manager::PasswordForm>& ) { … }
void ManagePasswordsUIController::UpdateIconAndBubbleState(
ManagePasswordsIconView* icon) { … }
base::WeakPtr<PasswordsModelDelegate>
ManagePasswordsUIController::GetModelDelegateProxy() { … }
content::WebContents* ManagePasswordsUIController::GetWebContents() const { … }
url::Origin ManagePasswordsUIController::GetOrigin() const { … }
password_manager::PasswordFormMetricsRecorder*
ManagePasswordsUIController::GetPasswordFormMetricsRecorder() { … }
password_manager::PasswordFeatureManager*
ManagePasswordsUIController::GetPasswordFeatureManager() { … }
password_manager::ui::State ManagePasswordsUIController::GetState() const { … }
const password_manager::PasswordForm&
ManagePasswordsUIController::GetPendingPassword() const { … }
password_manager::metrics_util::CredentialSourceType
ManagePasswordsUIController::GetCredentialSource() const { … }
const std::vector<password_manager::PasswordForm>&
ManagePasswordsUIController::GetUnsyncedCredentials() const { … }
const std::vector<std::unique_ptr<password_manager::PasswordForm>>&
ManagePasswordsUIController::GetCurrentForms() const { … }
const std::optional<password_manager::PasswordForm>&
ManagePasswordsUIController::
GetManagePasswordsSingleCredentialDetailsModeCredential() const { … }
const password_manager::InteractionsStats*
ManagePasswordsUIController::GetCurrentInteractionStats() const { … }
size_t ManagePasswordsUIController::GetTotalNumberCompromisedPasswords() const { … }
bool ManagePasswordsUIController::DidAuthForAccountStoreOptInFail() const { … }
bool ManagePasswordsUIController::BubbleIsManualFallbackForSaving() const { … }
bool ManagePasswordsUIController::GpmPinCreatedDuringRecentPasskeyCreation()
const { … }
void ManagePasswordsUIController::OnBubbleShown() { … }
void ManagePasswordsUIController::OnBubbleHidden() { … }
void ManagePasswordsUIController::OnNoInteraction() { … }
void ManagePasswordsUIController::OnNopeUpdateClicked() { … }
void ManagePasswordsUIController::NeverSavePassword() { … }
void ManagePasswordsUIController::OnPasswordsRevealed() { … }
void ManagePasswordsUIController::SavePassword(const std::u16string& username,
const std::u16string& password) { … }
void ManagePasswordsUIController::SaveUnsyncedCredentialsInProfileStore(
const std::vector<password_manager::PasswordForm>& selected_credentials) { … }
void ManagePasswordsUIController::DiscardUnsyncedCredentials() { … }
void ManagePasswordsUIController::MovePasswordToAccountStore() { … }
void ManagePasswordsUIController::BlockMovingPasswordToAccountStore() { … }
void ManagePasswordsUIController::PromptSaveBubbleAfterDefaultStoreChanged() { … }
void ManagePasswordsUIController::ChooseCredential(
const password_manager::PasswordForm& form,
password_manager::CredentialType credential_type) { … }
void ManagePasswordsUIController::NavigateToPasswordManagerSettingsPage(
password_manager::ManagePasswordsReferrer referrer) { … }
void ManagePasswordsUIController::
NavigateToPasswordDetailsPageInPasswordManager(
const std::string& password_domain_name,
password_manager::ManagePasswordsReferrer referrer) { … }
void ManagePasswordsUIController::
NavigateToPasswordManagerSettingsAccountStoreToggle(
password_manager::ManagePasswordsReferrer referrer) { … }
void ManagePasswordsUIController::NavigateToPasswordCheckup(
password_manager::PasswordCheckReferrer referrer) { … }
void ManagePasswordsUIController::SignIn(
const AccountInfo& account,
const password_manager::PasswordForm& password_to_move) { … }
void ManagePasswordsUIController::OnDialogHidden() { … }
void ManagePasswordsUIController::OnLeakDialogHidden() { … }
bool ManagePasswordsUIController::IsSavingPromptBlockedExplicitlyOrImplicitly()
const { … }
void ManagePasswordsUIController::AuthenticateUserWithMessage(
const std::u16string& message,
AvailabilityCallback callback) { … }
void ManagePasswordsUIController::
AuthenticateUserForAccountStoreOptInAndSavePassword(
const std::u16string& username,
const std::u16string& password) { … }
void ManagePasswordsUIController::
AuthenticateUserForAccountStoreOptInAfterSavingLocallyAndMovePassword() { … }
void ManagePasswordsUIController::MaybeShowIOSPasswordPromo() { … }
void ManagePasswordsUIController::RelaunchChrome() { … }
[[nodiscard]] std::unique_ptr<base::AutoReset<bool>>
ManagePasswordsUIController::BypassUserAuthtForTesting() { … }
void ManagePasswordsUIController::HidePasswordBubble() { … }
void ManagePasswordsUIController::UpdateBubbleAndIconVisibility() { … }
AccountChooserPrompt* ManagePasswordsUIController::CreateAccountChooser(
CredentialManagerDialogController* controller) { … }
AutoSigninFirstRunPrompt* ManagePasswordsUIController::CreateAutoSigninPrompt(
CredentialManagerDialogController* controller) { … }
CredentialLeakPrompt* ManagePasswordsUIController::CreateCredentialLeakPrompt(
CredentialLeakDialogController* controller) { … }
bool ManagePasswordsUIController::HasBrowserWindow() const { … }
std::unique_ptr<MovePasswordToAccountStoreHelper>
ManagePasswordsUIController::CreateMovePasswordToAccountStoreHelper(
const password_manager::PasswordForm& form,
password_manager::metrics_util::MoveToAccountStoreTrigger trigger,
base::OnceCallback<void()> on_move_finished) { … }
void ManagePasswordsUIController::MovePendingPasswordToAccountStoreUsingHelper(
const password_manager::PasswordForm& form,
password_manager::metrics_util::MoveToAccountStoreTrigger trigger) { … }
void ManagePasswordsUIController::PrimaryPageChanged(content::Page& page) { … }
void ManagePasswordsUIController::OnVisibilityChanged(
content::Visibility visibility) { … }
base::TimeDelta ManagePasswordsUIController::GetTimeoutForSaveFallback() { … }
void ManagePasswordsUIController::ShowBubbleWithoutUserInteraction() { … }
void ManagePasswordsUIController::ClearPopUpFlagForBubble() { … }
void ManagePasswordsUIController::DestroyPopups() { … }
void ManagePasswordsUIController::WebContentsDestroyed() { … }
void ManagePasswordsUIController::
FinishSavingPasswordAfterAccountStoreOptInAuth(
const url::Origin& origin,
password_manager::PasswordFormManagerForUI* form_manager,
const std::u16string& username,
const std::u16string& password,
password_manager::PasswordManagerClient::ReauthSucceeded
reauth_succeeded) { … }
void ManagePasswordsUIController::OnTriggerPostSaveCompromisedBubble(
password_manager::PostSaveCompromisedHelper::BubbleType type,
size_t count_compromised_passwords_) { … }
void ManagePasswordsUIController::MoveJustSavedPasswordAfterAccountStoreOptIn(
const password_manager::PasswordForm& form,
password_manager::PasswordManagerClient::ReauthSucceeded reauth_succeeded) { … }
void ManagePasswordsUIController::
OnMoveJustSavedPasswordAfterAccountStoreOptInCompleted(
std::list<std::unique_ptr<MovePasswordToAccountStoreHelper>>::iterator
done_helper_it) { … }
void ManagePasswordsUIController::OnReauthCompleted() { … }
void ManagePasswordsUIController::CancelAnyOngoingBiometricAuth() { … }
bool ManagePasswordsUIController::IsPendingPasswordPhished() const { … }
WEB_CONTENTS_USER_DATA_KEY_IMPL(ManagePasswordsUIController);