chromium/chrome/browser/extensions/api/passwords_private/passwords_private_delegate_impl.cc

// Copyright 2015 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/extensions/api/passwords_private/passwords_private_delegate_impl.h"

#include <memory>
#include <optional>
#include <utility>

#include "base/check.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/notreached.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/affiliations/affiliation_service_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/device_reauth/chrome_device_authenticator_factory.h"
#include "chrome/browser/extensions/api/passwords_private/passwords_private_event_router.h"
#include "chrome/browser/extensions/api/passwords_private/passwords_private_event_router_factory.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/password_sender_service_factory.h"
#include "chrome/browser/password_manager/profile_password_store_factory.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_window.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/web_applications/app_browser_controller.h"
#include "chrome/browser/ui/web_applications/web_app_dialog_utils.h"
#include "chrome/browser/web_applications/web_app_id_constants.h"
#include "chrome/browser/web_applications/web_app_install_params.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/webauthn/change_pin_controller.h"
#include "chrome/browser/webauthn/enclave_manager.h"
#include "chrome/browser/webauthn/enclave_manager_factory.h"
#include "chrome/browser/webauthn/passkey_model_factory.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/extensions/api/passwords_private.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/constants/chromeos_features.h"
#include "components/affiliations/core/browser/affiliation_utils.h"
#include "components/keyed_service/core/service_access_type.h"
#include "components/password_manager/core/browser/features/password_features.h"
#include "components/password_manager/core/browser/features/password_manager_features_util.h"
#include "components/password_manager/core/browser/leak_detection/leak_detection_request_utils.h"
#include "components/password_manager/core/browser/password_form.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_sync_util.h"
#include "components/password_manager/core/browser/sharing/password_sender_service.h"
#include "components/password_manager/core/browser/sharing/recipients_fetcher_impl.h"
#include "components/password_manager/core/browser/ui/credential_ui_entry.h"
#include "components/password_manager/core/browser/ui/credential_utils.h"
#include "components/password_manager/core/common/password_manager_constants.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/base/signin_metrics.h"
#include "components/sync/base/features.h"
#include "components/sync/service/sync_user_settings.h"
#include "components/url_formatter/elide_url.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
#include "url/scheme_host_port.h"

#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/device_reauth/chrome_device_authenticator_factory.h"
#endif

#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/extensions/api/passwords_private/passwords_private_utils_chromeos.h"
#endif

namespace {

CredentialFacet;
CredentialUIEntry;
FetchFamilyMembersRequestStatus;
kPasswordManagerAuthValidity;

// The error message returned to the UI when Chrome refuses to start multiple
// exports.
const char kExportInProgress[] =;
// The error message returned to the UI when the user fails to reauthenticate.
const char kReauthenticationFailed[] =;

// Map password_manager::ExportProgressStatus to
// extensions::api::passwords_private::ExportProgressStatus.
extensions::api::passwords_private::ExportProgressStatus ConvertStatus(
    password_manager::ExportProgressStatus status) {}

std::u16string GetReauthPurpose(
    extensions::api::passwords_private::PlaintextReason reason) {}

password_manager::metrics_util::AccessPasswordInSettingsEvent
ConvertPlaintextReason(
    extensions::api::passwords_private::PlaintextReason reason) {}

base::flat_set<password_manager::PasswordForm::Store>
ConvertToPasswordFormStores(
    extensions::api::passwords_private::PasswordStoreSet store) {}

extensions::api::passwords_private::ImportEntry ConvertImportEntry(
    const password_manager::ImportEntry& entry) {}

// Maps password_manager::ImportResults to
// extensions::api::passwords_private::ImportResults.
extensions::api::passwords_private::ImportResults ConvertImportResults(
    const password_manager::ImportResults& results) {}

#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)

using password_manager::prefs::kBiometricAuthenticationBeforeFilling;

void ChangeBiometricAuthenticationBeforeFillingSetting(
    PrefService* prefs,
    extensions::PasswordsPrivateDelegate::AuthenticationCallback callback,
    bool success) {
  if (success) {
    prefs->SetBoolean(
        kBiometricAuthenticationBeforeFilling,
        !prefs->GetBoolean(kBiometricAuthenticationBeforeFilling));
  }

  std::move(callback).Run(success);
}

std::u16string GetMessageForBiometricAuthenticationBeforeFillingSetting(
    PrefService* prefs) {
  const bool pref_enabled =
      prefs->GetBoolean(kBiometricAuthenticationBeforeFilling);
#if BUILDFLAG(IS_MAC)
  return l10n_util::GetStringUTF16(
      pref_enabled ? IDS_PASSWORD_MANAGER_TURN_OFF_FILLING_REAUTH_MAC
                   : IDS_PASSWORD_MANAGER_TURN_ON_FILLING_REAUTH_MAC);
#elif BUILDFLAG(IS_WIN)
  return l10n_util::GetStringUTF16(
      pref_enabled ? IDS_PASSWORD_MANAGER_TURN_OFF_FILLING_REAUTH_WIN
                   : IDS_PASSWORD_MANAGER_TURN_ON_FILLING_REAUTH_WIN);
#endif
}

#endif

void MaybeShowProfileSwitchIPH(Profile* profile) {}

// Returns a passkey model instance if the feature is enabled.
webauthn::PasskeyModel* MaybeGetPasskeyModel(Profile* profile) {}

std::string GetGroupIconUrl(const password_manager::AffiliatedGroup& group,
                            const syncer::SyncService* sync_service) {}

}  // namespace

namespace extensions {

PasswordsPrivateDelegateImpl::PasswordsPrivateDelegateImpl(Profile* profile)
    :{}

PasswordsPrivateDelegateImpl::~PasswordsPrivateDelegateImpl() {}

#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN) || BUILDFLAG(IS_CHROMEOS)
std::unique_ptr<device_reauth::DeviceAuthenticator>
PasswordsPrivateDelegateImpl::GetDeviceAuthenticator(
    content::WebContents* web_contents,
    base::TimeDelta auth_validity_period) {
  if (test_device_authenticator_) {
    return std::move(test_device_authenticator_);
  }

  device_reauth::DeviceAuthParams params(
      auth_validity_period, device_reauth::DeviceAuthSource::kPasswordManager,
      "PasswordManager.ReauthToAccessPasswordInSettings");

  return ChromeDeviceAuthenticatorFactory::GetForProfile(
      Profile::FromBrowserContext(web_contents->GetBrowserContext()),
      web_contents->GetTopLevelNativeWindow(), params);
}
#endif

void PasswordsPrivateDelegateImpl::GetSavedPasswordsList(
    UiEntriesCallback callback) {}

PasswordsPrivateDelegate::CredentialsGroups
PasswordsPrivateDelegateImpl::GetCredentialGroups() {}

void PasswordsPrivateDelegateImpl::GetPasswordExceptionsList(
    ExceptionEntriesCallback callback) {}

std::optional<api::passwords_private::UrlCollection>
PasswordsPrivateDelegateImpl::GetUrlCollection(const std::string& url) {}

bool PasswordsPrivateDelegateImpl::IsAccountStoreDefault(
    content::WebContents* web_contents) {}

bool PasswordsPrivateDelegateImpl::AddPassword(
    const std::string& url,
    const std::u16string& username,
    const std::u16string& password,
    const std::u16string& note,
    bool use_account_store,
    content::WebContents* web_contents) {}

bool PasswordsPrivateDelegateImpl::ChangeCredential(
    const api::passwords_private::PasswordUiEntry& credential) {}

void PasswordsPrivateDelegateImpl::RemoveCredential(
    int id,
    api::passwords_private::PasswordStoreSet from_stores) {}

void PasswordsPrivateDelegateImpl::RemovePasswordException(int id) {}

void PasswordsPrivateDelegateImpl::UndoRemoveSavedPasswordOrException() {}

void PasswordsPrivateDelegateImpl::RequestPlaintextPassword(
    int id,
    api::passwords_private::PlaintextReason reason,
    PlaintextPasswordCallback callback,
    content::WebContents* web_contents) {}

void PasswordsPrivateDelegateImpl::RequestCredentialsDetails(
    const std::vector<int>& ids,
    UiEntriesCallback callback,
    content::WebContents* web_contents) {}

void PasswordsPrivateDelegateImpl::OnFetchingFamilyMembersCompleted(
    FetchFamilyResultsCallback callback,
    std::vector<password_manager::RecipientInfo> family_members,
    FetchFamilyMembersRequestStatus request_status) {}

void PasswordsPrivateDelegateImpl::OsReauthTimeoutCall() {}

void PasswordsPrivateDelegateImpl::SetCredentials(
    std::vector<CredentialUIEntry> credentials) {}

void PasswordsPrivateDelegateImpl::MovePasswordsToAccount(
    const std::vector<int>& ids,
    content::WebContents* web_contents) {}

void PasswordsPrivateDelegateImpl::FetchFamilyMembers(
    FetchFamilyResultsCallback callback) {}

void PasswordsPrivateDelegateImpl::SharePassword(
    int id,
    const ShareRecipients& recipients) {}

void PasswordsPrivateDelegateImpl::ImportPasswords(
    api::passwords_private::PasswordStoreSet to_store,
    ImportResultsCallback results_callback,
    content::WebContents* web_contents) {}

void PasswordsPrivateDelegateImpl::ContinueImport(
    const std::vector<int>& selected_ids,
    ImportResultsCallback results_callback,
    content::WebContents* web_contents) {}

void PasswordsPrivateDelegateImpl::ResetImporter(bool delete_file) {}

void PasswordsPrivateDelegateImpl::ExportPasswords(
    base::OnceCallback<void(const std::string&)> accepted_callback,
    content::WebContents* web_contents) {}

api::passwords_private::ExportProgressStatus
PasswordsPrivateDelegateImpl::GetExportProgressStatus() {}

bool PasswordsPrivateDelegateImpl::IsOptedInForAccountStorage() {}

void PasswordsPrivateDelegateImpl::SetAccountStorageOptIn(
    bool opt_in,
    content::WebContents* web_contents) {}

std::vector<api::passwords_private::PasswordUiEntry>
PasswordsPrivateDelegateImpl::GetInsecureCredentials() {}

std::vector<api::passwords_private::PasswordUiEntryList>
PasswordsPrivateDelegateImpl::GetCredentialsWithReusedPassword() {}

bool PasswordsPrivateDelegateImpl::MuteInsecureCredential(
    const api::passwords_private::PasswordUiEntry& credential) {}

bool PasswordsPrivateDelegateImpl::UnmuteInsecureCredential(
    const api::passwords_private::PasswordUiEntry& credential) {}

void PasswordsPrivateDelegateImpl::StartPasswordCheck(
    StartPasswordCheckCallback callback) {}

api::passwords_private::PasswordCheckStatus
PasswordsPrivateDelegateImpl::GetPasswordCheckStatus() {}

void PasswordsPrivateDelegateImpl::SwitchBiometricAuthBeforeFillingState(

    content::WebContents* web_contents,
    AuthenticationCallback authentication_callback) {}

void PasswordsPrivateDelegateImpl::ShowAddShortcutDialog(
    content::WebContents* web_contents) {}

void PasswordsPrivateDelegateImpl::ShowExportedFileInShell(
    content::WebContents* web_contents,
    std::string file_path) {}

void PasswordsPrivateDelegateImpl::ChangePasswordManagerPin(
    content::WebContents* web_contents,
    base::OnceCallback<void(bool)> success_callback) {}

void PasswordsPrivateDelegateImpl::IsPasswordManagerPinAvailable(
    content::WebContents* web_contents,
    base::OnceCallback<void(bool)> pin_available_callback) {}

void PasswordsPrivateDelegateImpl::DisconnectCloudAuthenticator(
    content::WebContents* web_contents,
    base::OnceCallback<void(bool)> success_callback) {}

bool PasswordsPrivateDelegateImpl::IsConnectedToCloudAuthenticator(
    content::WebContents* web_contents) {}

void PasswordsPrivateDelegateImpl::DeleteAllPasswordManagerData(
    content::WebContents* web_contents,
    base::OnceCallback<void(bool)> success_callback) {}

void PasswordsPrivateDelegateImpl::OnDeleteAllDataAuthResult(
    base::OnceCallback<void(bool)> success_callback,
    bool authenticated) {}

base::WeakPtr<PasswordsPrivateDelegate>
PasswordsPrivateDelegateImpl::AsWeakPtr() {}

password_manager::InsecureCredentialsManager*
PasswordsPrivateDelegateImpl::GetInsecureCredentialsManager() {}

void PasswordsPrivateDelegateImpl::RestartAuthTimer() {}

void PasswordsPrivateDelegateImpl::MaybeShowPasswordShareButtonIPH(
    base::WeakPtr<content::WebContents> web_contents) {}

void PasswordsPrivateDelegateImpl::OnPasswordsExportProgress(
    const password_manager::PasswordExportInfo& progress) {}

void PasswordsPrivateDelegateImpl::OnRequestPlaintextPasswordAuthResult(
    int id,
    api::passwords_private::PlaintextReason reason,
    PlaintextPasswordCallback callback,
    bool authenticated) {}

void PasswordsPrivateDelegateImpl::OnRequestCredentialDetailsAuthResult(
    const std::vector<int>& ids,
    UiEntriesCallback callback,
    base::WeakPtr<content::WebContents> web_contents,
    bool authenticated) {}

void PasswordsPrivateDelegateImpl::OnExportPasswordsAuthResult(
    base::OnceCallback<void(const std::string&)> accepted_callback,
    base::WeakPtr<content::WebContents> web_contents,
    bool authenticated) {}

void PasswordsPrivateDelegateImpl::OnImportPasswordsAuthResult(
    ImportResultsCallback results_callback,
    const std::vector<int>& selected_ids,
    bool authenticated) {}

void PasswordsPrivateDelegateImpl::OnStateChanged(
    syncer::SyncService* sync_service) {}

void PasswordsPrivateDelegateImpl::OnSyncShutdown(syncer::SyncService* sync) {}

void PasswordsPrivateDelegateImpl::OnReauthCompleted(bool authenticated) {}

void PasswordsPrivateDelegateImpl::OnSavedPasswordsChanged(
    const password_manager::PasswordStoreChangeList& changes) {}

void PasswordsPrivateDelegateImpl::OnWebAppInstalledWithOsHooks(
    const webapps::AppId& app_id) {}

void PasswordsPrivateDelegateImpl::OnWebAppInstallManagerDestroyed() {}

void PasswordsPrivateDelegateImpl::EmitHistogramsForCredentialAccess(
    const CredentialUIEntry& entry,
    api::passwords_private::PlaintextReason reason) {}

void PasswordsPrivateDelegateImpl::AuthenticateUser(
    content::WebContents* web_contents,
    base::TimeDelta auth_validity_period,
    const std::u16string& message,
    AuthResultCallback auth_callback) {}

api::passwords_private::PasswordUiEntry
PasswordsPrivateDelegateImpl::CreatePasswordUiEntryFromCredentialUiEntry(
    CredentialUIEntry credential) {}

}  // namespace extensions