blob: a5f1b6f2abe688427c85241d26e8f28f6f8c4411 [file] [log] [blame]
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_PASSWORDS_IOS_CHROME_PASSWORD_MANAGER_CLIENT_H_
#define IOS_CHROME_BROWSER_PASSWORDS_IOS_CHROME_PASSWORD_MANAGER_CLIENT_H_
#include <memory>
#include "base/macros.h"
#include "components/password_manager/core/browser/leak_detection_dialog_utils.h"
#include "components/password_manager/core/browser/password_feature_manager_impl.h"
#import "components/password_manager/core/browser/password_manager_client.h"
#include "components/password_manager/core/browser/password_manager_client_helper.h"
#include "components/password_manager/core/browser/password_manager_metrics_recorder.h"
#include "components/password_manager/core/browser/sync_credentials_filter.h"
#include "components/prefs/pref_member.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
namespace ios {
class ChromeBrowserState;
}
namespace autofill {
class LogManager;
}
namespace password_manager {
class PasswordFormManagerForUI;
class PasswordManagerDriver;
}
namespace web {
class WebState;
}
using password_manager::CredentialLeakType;
@protocol PasswordManagerClientDelegate
// Shows UI to prompt the user to save the password.
- (void)showSavePasswordInfoBar:
(std::unique_ptr<password_manager::PasswordFormManagerForUI>)formToSave;
// Shows UI to prompt the user to update the password.
- (void)showUpdatePasswordInfoBar:
(std::unique_ptr<password_manager::PasswordFormManagerForUI>)formToUpdate;
// Shows UI to notify the user about auto sign in.
- (void)showAutosigninNotification:
(std::unique_ptr<autofill::PasswordForm>)formSignedIn;
// Shows Password Breach for |URL| and |leakType|.
- (void)showPasswordBreachForLeakType:(CredentialLeakType)leakType
URL:(const GURL&)URL;
@property(readonly, nonatomic) web::WebState* webState;
@property(readonly, nonatomic) ios::ChromeBrowserState* browserState;
@property(readonly) password_manager::PasswordManager* passwordManager;
@property(readonly, nonatomic) const GURL& lastCommittedURL;
@property(readonly, nonatomic) ukm::SourceId ukmSourceId;
@end
// An iOS implementation of password_manager::PasswordManagerClient.
// TODO(crbug.com/958833): write unit tests for this class.
class IOSChromePasswordManagerClient
: public password_manager::PasswordManagerClient {
public:
explicit IOSChromePasswordManagerClient(
id<PasswordManagerClientDelegate> delegate);
~IOSChromePasswordManagerClient() override;
// password_manager::PasswordManagerClient implementation.
password_manager::SyncState GetPasswordSyncState() const override;
bool PromptUserToSaveOrUpdatePassword(
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save,
bool update_password) override;
bool ShowOnboarding(
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save)
override;
void ShowManualFallbackForSaving(
std::unique_ptr<password_manager::PasswordFormManagerForUI> form_to_save,
bool has_generated_password,
bool is_update) override;
void HideManualFallbackForSaving() override;
void FocusedInputChanged(
password_manager::PasswordManagerDriver* driver,
autofill::mojom::FocusedFieldType focused_field_type) override;
bool PromptUserToChooseCredentials(
std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms,
const GURL& origin,
const CredentialsCallback& callback) override;
void AutomaticPasswordSave(
std::unique_ptr<password_manager::PasswordFormManagerForUI>
saved_form_manager) override;
void PromptUserToEnableAutosignin() override;
bool IsIncognito() const override;
const password_manager::PasswordManager* GetPasswordManager() const override;
const password_manager::PasswordFeatureManager* GetPasswordFeatureManager()
const override;
bool IsMainFrameSecure() const override;
PrefService* GetPrefs() const override;
password_manager::PasswordStore* GetProfilePasswordStore() const override;
password_manager::PasswordStore* GetAccountPasswordStore() const override;
void NotifyUserAutoSignin(
std::vector<std::unique_ptr<autofill::PasswordForm>> local_forms,
const GURL& origin) override;
void NotifyUserCouldBeAutoSignedIn(
std::unique_ptr<autofill::PasswordForm> form) override;
void NotifySuccessfulLoginWithExistingPassword(
const autofill::PasswordForm& form) override;
void NotifyStorePasswordCalled() override;
void NotifyUserCredentialsWereLeaked(
password_manager::CredentialLeakType leak_type,
const GURL& origin) override;
bool IsSavingAndFillingEnabled(const GURL& url) const override;
bool IsFillingEnabled(const GURL& url) const override;
const GURL& GetLastCommittedEntryURL() const override;
std::string GetPageLanguage() const override;
const password_manager::CredentialsFilter* GetStoreResultFilter()
const override;
const autofill::LogManager* GetLogManager() const override;
ukm::SourceId GetUkmSourceId() override;
password_manager::PasswordManagerMetricsRecorder* GetMetricsRecorder()
override;
signin::IdentityManager* GetIdentityManager() override;
scoped_refptr<network::SharedURLLoaderFactory> GetURLLoaderFactory() override;
password_manager::PasswordRequirementsService*
GetPasswordRequirementsService() override;
bool IsIsolationForPasswordSitesEnabled() const override;
bool IsNewTabPage() const override;
password_manager::FieldInfoManager* GetFieldInfoManager() const override;
private:
__weak id<PasswordManagerClientDelegate> delegate_;
const password_manager::PasswordFeatureManagerImpl password_feature_manager_;
// The preference associated with
// password_manager::prefs::kCredentialsEnableService.
BooleanPrefMember saving_passwords_enabled_;
const password_manager::SyncCredentialsFilter credentials_filter_;
std::unique_ptr<autofill::LogManager> log_manager_;
// Recorder of metrics that is associated with the last committed navigation
// of the tab owning this ChromePasswordManagerClient. May be unset at
// times. Sends statistics on destruction.
base::Optional<password_manager::PasswordManagerMetricsRecorder>
metrics_recorder_;
// Helper for performing logic that is common between
// ChromePasswordManagerClient and IOSChromePasswordManagerClient.
password_manager::PasswordManagerClientHelper helper_;
DISALLOW_COPY_AND_ASSIGN(IOSChromePasswordManagerClient);
};
#endif // IOS_CHROME_BROWSER_PASSWORDS_IOS_CHROME_PASSWORD_MANAGER_CLIENT_H_