Commit 2173bc3c authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Move PasswordManagerDriverDelegate and PasswordManagerClientDelegate

These protocols are moved into components/password_manager/ios to be
shared with other objc embedders of PasswordManagerDriver and
PasswordManagerClient.

Also renamed them to XXXBridge to make it clear the these @protocols are
simply used to bridge C++ methods into ObjC methods.

Change-Id: I13c11d7abf49482fe1355e6b48d54ec9a90d9483
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2252856
Commit-Queue: John Wu <jzw@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784267}
parent b0e78262
......@@ -32,6 +32,8 @@ component("ios") {
"js_password_manager.mm",
"password_form_helper.h",
"password_form_helper.mm",
"password_manager_client_bridge.h",
"password_manager_driver_bridge.h",
"password_suggestion_helper.h",
"password_suggestion_helper.mm",
"unique_id_tab_helper.h",
......
// Copyright 2020 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 COMPONENTS_PASSWORD_MANAGER_IOS_PASSWORD_MANAGER_CLIENT_BRIDGE_H_
#define COMPONENTS_PASSWORD_MANAGER_IOS_PASSWORD_MANAGER_CLIENT_BRIDGE_H_
#import <Foundation/Foundation.h>
#include <memory>
#include "components/password_manager/core/browser/leak_detection_dialog_utils.h"
class GURL;
namespace password_manager {
class PasswordFormManagerForUI;
class PasswordManager;
} // namespace password_manager
namespace web {
class WebState;
} // namespace web
using password_manager::CredentialLeakType;
// C++ to ObjC bridge for methods of PasswordManagerClient.
@protocol PasswordManagerClientBridge
@property(readonly, nonatomic) web::WebState* webState;
@property(readonly, nonatomic)
password_manager::PasswordManager* passwordManager;
@property(readonly, nonatomic) const GURL& lastCommittedURL;
// Shows UI to prompt the user to save the password.
- (void)showSavePasswordInfoBar:
(std::unique_ptr<password_manager::PasswordFormManagerForUI>)
formToSave
manual:(BOOL)manual;
// Shows UI to prompt the user to update the password.
- (void)showUpdatePasswordInfoBar:
(std::unique_ptr<password_manager::PasswordFormManagerForUI>)
formToUpdate
manual:(BOOL)manual;
// Removes the saving/updating password Infobar from the InfobarManager.
// This also causes the UI to be dismissed.
- (void)removePasswordInfoBarManualFallback:(BOOL)manual;
// Shows Password Breach for |URL| and |leakType|.
- (void)showPasswordBreachForLeakType:(CredentialLeakType)leakType
URL:(const GURL&)URL;
@end
#endif // COMPONENTS_PASSWORD_MANAGER_IOS_PASSWORD_MANAGER_CLIENT_BRIDGE_H_
// Copyright 2020 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 COMPONENTS_PASSWORD_MANAGER_IOS_PASSWORD_MANAGER_DRIVER_BRIDGE_H_
#define COMPONENTS_PASSWORD_MANAGER_IOS_PASSWORD_MANAGER_DRIVER_BRIDGE_H_
#import <Foundation/Foundation.h>
namespace autofill {
struct PasswordFormFillData;
struct PasswordFormGenerationData;
} // namespace autofill
class GURL;
namespace password_manager {
class PasswordGenerationFrameHelper;
class PasswordManager;
} // namespace password_manager
// C++ to ObjC bridge for methods of PasswordManagerDriver.
@protocol PasswordManagerDriverBridge
@property(readonly, nonatomic) const GURL& lastCommittedURL;
@property(readonly, nonatomic)
password_manager::PasswordManager* passwordManager;
// Finds and fills the password form using the supplied |formData| to
// match the password form and to populate the field values. Calls
// |completionHandler| with YES if a form field has been filled, NO otherwise.
// |completionHandler| can be nil.
- (void)fillPasswordForm:(const autofill::PasswordFormFillData&)formData
completionHandler:(void (^)(BOOL))completionHandler;
// Informs delegate that there are no saved credentials for the current page.
- (void)onNoSavedCredentials;
// Gets the PasswordGenerationFrameHelper owned by this delegate.
- (password_manager::PasswordGenerationFrameHelper*)passwordGenerationHelper;
// Informs delegate of form for password generation found.
- (void)formEligibleForGenerationFound:
(const autofill::PasswordFormGenerationData&)form;
@end
#endif // COMPONENTS_PASSWORD_MANAGER_IOS_PASSWORD_MANAGER_DRIVER_BRIDGE_H_
......@@ -15,6 +15,7 @@
#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/password_manager/ios/password_manager_client_bridge.h"
#include "components/prefs/pref_member.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
......@@ -29,48 +30,14 @@ 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
manual:(BOOL)manual;
@protocol IOSChromePasswordManagerClientBridge <PasswordManagerClientBridge>
// Shows UI to prompt the user to update the password.
- (void)showUpdatePasswordInfoBar:
(std::unique_ptr<password_manager::PasswordFormManagerForUI>)
formToUpdate
manual:(BOOL)manual;
// Removes the saving/updating password Infobar from the InfobarManager.
// This also causes the UI to be dismissed.
- (void)removePasswordInfoBarManualFallback:(BOOL)manual;
@property(readonly, nonatomic) ChromeBrowserState* browserState;
// 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) 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.
......@@ -79,7 +46,7 @@ class IOSChromePasswordManagerClient
: public password_manager::PasswordManagerClient {
public:
explicit IOSChromePasswordManagerClient(
id<PasswordManagerClientDelegate> delegate);
id<IOSChromePasswordManagerClientBridge> bridge);
~IOSChromePasswordManagerClient() override;
......@@ -151,7 +118,7 @@ class IOSChromePasswordManagerClient
password_manager::FieldInfoManager* GetFieldInfoManager() const override;
private:
__weak id<PasswordManagerClientDelegate> delegate_;
__weak id<IOSChromePasswordManagerClientBridge> bridge_;
password_manager::PasswordFeatureManagerImpl password_feature_manager_;
......
......@@ -24,6 +24,7 @@
#include "components/password_manager/ios/credential_manager_util.h"
#include "components/sync/driver/sync_service.h"
#include "components/translate/core/browser/translate_manager.h"
#import "components/ukm/ios/ukm_url_recorder.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h"
......@@ -56,22 +57,22 @@ const syncer::SyncService* GetSyncService(ChromeBrowserState* browser_state) {
} // namespace
IOSChromePasswordManagerClient::IOSChromePasswordManagerClient(
id<PasswordManagerClientDelegate> delegate)
: delegate_(delegate),
id<IOSChromePasswordManagerClientBridge> bridge)
: bridge_(bridge),
password_feature_manager_(GetPrefs(),
GetSyncService(delegate_.browserState)),
GetSyncService(bridge_.browserState)),
credentials_filter_(
this,
base::BindRepeating(&GetSyncService, delegate_.browserState)),
base::BindRepeating(&GetSyncService, bridge_.browserState)),
helper_(this) {
saving_passwords_enabled_.Init(
password_manager::prefs::kCredentialsEnableService, GetPrefs());
static base::NoDestructor<password_manager::StoreMetricsReporter> reporter(
this, GetSyncService(delegate_.browserState), GetIdentityManager(),
this, GetSyncService(bridge_.browserState), GetIdentityManager(),
GetPrefs());
log_manager_ = autofill::LogManager::Create(
ios::PasswordManagerLogRouterFactory::GetForBrowserState(
delegate_.browserState),
bridge_.browserState),
base::Closure());
}
......@@ -79,7 +80,7 @@ IOSChromePasswordManagerClient::~IOSChromePasswordManagerClient() = default;
SyncState IOSChromePasswordManagerClient::GetPasswordSyncState() const {
syncer::SyncService* sync_service =
ProfileSyncServiceFactory::GetForBrowserState(delegate_.browserState);
ProfileSyncServiceFactory::GetForBrowserState(bridge_.browserState);
return password_manager_util::GetPasswordSyncState(sync_service);
}
......@@ -97,12 +98,12 @@ bool IOSChromePasswordManagerClient::PromptUserToSaveOrUpdatePassword(
if (form_to_save->IsBlacklisted())
return false;
[delegate_ removePasswordInfoBarManualFallback:YES];
[bridge_ removePasswordInfoBarManualFallback:YES];
if (update_password) {
[delegate_ showUpdatePasswordInfoBar:std::move(form_to_save) manual:NO];
[bridge_ showUpdatePasswordInfoBar:std::move(form_to_save) manual:NO];
} else {
[delegate_ showSavePasswordInfoBar:std::move(form_to_save) manual:NO];
[bridge_ showSavePasswordInfoBar:std::move(form_to_save) manual:NO];
}
return true;
......@@ -123,14 +124,14 @@ void IOSChromePasswordManagerClient::ShowManualFallbackForSaving(
bool has_generated_password,
bool is_update) {
if (is_update) {
[delegate_ showUpdatePasswordInfoBar:std::move(form_to_save) manual:YES];
[bridge_ showUpdatePasswordInfoBar:std::move(form_to_save) manual:YES];
} else {
[delegate_ showSavePasswordInfoBar:std::move(form_to_save) manual:YES];
[bridge_ showSavePasswordInfoBar:std::move(form_to_save) manual:YES];
}
}
void IOSChromePasswordManagerClient::HideManualFallbackForSaving() {
[delegate_ removePasswordInfoBarManualFallback:YES];
[bridge_ removePasswordInfoBarManualFallback:YES];
}
void IOSChromePasswordManagerClient::FocusedInputChanged(
......@@ -150,12 +151,12 @@ void IOSChromePasswordManagerClient::PromptUserToEnableAutosignin() {
}
bool IOSChromePasswordManagerClient::IsIncognito() const {
return (delegate_.browserState)->IsOffTheRecord();
return (bridge_.browserState)->IsOffTheRecord();
}
const password_manager::PasswordManager*
IOSChromePasswordManagerClient::GetPasswordManager() const {
return delegate_.passwordManager;
return bridge_.passwordManager;
}
const password_manager::PasswordFeatureManager*
......@@ -164,12 +165,12 @@ IOSChromePasswordManagerClient::GetPasswordFeatureManager() const {
}
PrefService* IOSChromePasswordManagerClient::GetPrefs() const {
return (delegate_.browserState)->GetPrefs();
return (bridge_.browserState)->GetPrefs();
}
PasswordStore* IOSChromePasswordManagerClient::GetProfilePasswordStore() const {
return IOSChromePasswordStoreFactory::GetForBrowserState(
delegate_.browserState, ServiceAccessType::EXPLICIT_ACCESS)
bridge_.browserState, ServiceAccessType::EXPLICIT_ACCESS)
.get();
}
......@@ -183,7 +184,7 @@ void IOSChromePasswordManagerClient::NotifyUserAutoSignin(
const url::Origin& origin) {
DCHECK(!local_forms.empty());
helper_.NotifyUserAutoSignin();
[delegate_ showAutosigninNotification:std::move(local_forms[0])];
[bridge_ showAutosigninNotification:std::move(local_forms[0])];
}
void IOSChromePasswordManagerClient::NotifyUserCouldBeAutoSignedIn(
......@@ -206,7 +207,7 @@ void IOSChromePasswordManagerClient::NotifyUserCredentialsWereLeaked(
password_manager::CredentialLeakType leak_type,
const GURL& origin,
const base::string16& username) {
[delegate_ showPasswordBreachForLeakType:leak_type URL:origin];
[bridge_ showPasswordBreachForLeakType:leak_type URL:origin];
}
bool IOSChromePasswordManagerClient::IsSavingAndFillingEnabled(
......@@ -222,15 +223,15 @@ bool IOSChromePasswordManagerClient::IsFillingEnabled(const GURL& url) const {
}
bool IOSChromePasswordManagerClient::IsCommittedMainFrameSecure() const {
return password_manager::WebStateContentIsSecureHtml(delegate_.webState);
return password_manager::WebStateContentIsSecureHtml(bridge_.webState);
}
const GURL& IOSChromePasswordManagerClient::GetLastCommittedURL() const {
return delegate_.lastCommittedURL;
return bridge_.lastCommittedURL;
}
url::Origin IOSChromePasswordManagerClient::GetLastCommittedOrigin() const {
return url::Origin::Create(delegate_.lastCommittedURL);
return url::Origin::Create(bridge_.lastCommittedURL);
}
std::string IOSChromePasswordManagerClient::GetPageLanguage() const {
......@@ -250,7 +251,9 @@ const autofill::LogManager* IOSChromePasswordManagerClient::GetLogManager()
}
ukm::SourceId IOSChromePasswordManagerClient::GetUkmSourceId() {
return delegate_.ukmSourceId;
return bridge_.webState
? ukm::GetSourceIdForWebStateDocument(bridge_.webState)
: ukm::kInvalidSourceId;
}
PasswordManagerMetricsRecorder*
......@@ -263,18 +266,18 @@ IOSChromePasswordManagerClient::GetMetricsRecorder() {
}
signin::IdentityManager* IOSChromePasswordManagerClient::GetIdentityManager() {
return IdentityManagerFactory::GetForBrowserState(delegate_.browserState);
return IdentityManagerFactory::GetForBrowserState(bridge_.browserState);
}
scoped_refptr<network::SharedURLLoaderFactory>
IOSChromePasswordManagerClient::GetURLLoaderFactory() {
return (delegate_.browserState)->GetSharedURLLoaderFactory();
return (bridge_.browserState)->GetSharedURLLoaderFactory();
}
password_manager::PasswordRequirementsService*
IOSChromePasswordManagerClient::GetPasswordRequirementsService() {
return IOSPasswordRequirementsServiceFactory::GetForBrowserState(
delegate_.browserState, ServiceAccessType::EXPLICIT_ACCESS);
bridge_.browserState, ServiceAccessType::EXPLICIT_ACCESS);
}
bool IOSChromePasswordManagerClient::IsIsolationForPasswordSitesEnabled()
......
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "components/password_manager/core/browser/password_manager_driver.h"
#include "components/password_manager/ios/password_manager_driver_bridge.h"
namespace autofill {
struct PasswordFormFillData;
......@@ -19,38 +20,13 @@ class PasswordAutofillManager;
class PasswordManager;
} // namespace password_manager
// Defines the interface the driver needs to the controller.
@protocol PasswordManagerDriverDelegate
@property(readonly, nonatomic) const GURL& lastCommittedURL;
- (password_manager::PasswordManager*)passwordManager;
// Finds and fills the password form using the supplied |formData| to
// match the password form and to populate the field values. Calls
// |completionHandler| with YES if a form field has been filled, NO otherwise.
// |completionHandler| can be nil.
- (void)fillPasswordForm:(const autofill::PasswordFormFillData&)formData
completionHandler:(void (^)(BOOL))completionHandler;
// Informs delegate that there are no saved credentials for the current page.
- (void)onNoSavedCredentials;
// Gets the PasswordGenerationFrameHelper owned by this delegate.
- (password_manager::PasswordGenerationFrameHelper*)passwordGenerationHelper;
// Informs delegate of form for password generation found.
- (void)formEligibleForGenerationFound:
(const autofill::PasswordFormGenerationData&)form;
@end
// An iOS implementation of password_manager::PasswordManagerDriver.
class IOSChromePasswordManagerDriver
: public password_manager::PasswordManagerDriver {
public:
explicit IOSChromePasswordManagerDriver(
id<PasswordManagerDriverDelegate> controller);
id<PasswordManagerDriverBridge> bridge);
~IOSChromePasswordManagerDriver() override;
// password_manager::PasswordManagerDriver implementation.
......@@ -78,7 +54,7 @@ class IOSChromePasswordManagerDriver
const GURL& GetLastCommittedURL() const override;
private:
id<PasswordManagerDriverDelegate> delegate_; // (weak)
__weak id<PasswordManagerDriverBridge> bridge_; // (weak)
DISALLOW_COPY_AND_ASSIGN(IOSChromePasswordManagerDriver);
};
......
......@@ -18,8 +18,8 @@ using password_manager::PasswordAutofillManager;
using password_manager::PasswordManager;
IOSChromePasswordManagerDriver::IOSChromePasswordManagerDriver(
id<PasswordManagerDriverDelegate> delegate)
: delegate_(delegate) {}
id<PasswordManagerDriverBridge> bridge)
: bridge_(bridge) {}
IOSChromePasswordManagerDriver::~IOSChromePasswordManagerDriver() = default;
......@@ -30,12 +30,12 @@ int IOSChromePasswordManagerDriver::GetId() const {
void IOSChromePasswordManagerDriver::FillPasswordForm(
const autofill::PasswordFormFillData& form_data) {
[delegate_ fillPasswordForm:form_data completionHandler:nil];
[bridge_ fillPasswordForm:form_data completionHandler:nil];
}
void IOSChromePasswordManagerDriver::InformNoSavedCredentials(
bool should_show_popup_without_passwords) {
[delegate_ onNoSavedCredentials];
[bridge_ onNoSavedCredentials];
}
void IOSChromePasswordManagerDriver::FormEligibleForGenerationFound(
......@@ -43,7 +43,7 @@ void IOSChromePasswordManagerDriver::FormEligibleForGenerationFound(
if (GetPasswordGenerationHelper() &&
GetPasswordGenerationHelper()->IsGenerationEnabled(
/*log_debug_data*/ true)) {
[delegate_ formEligibleForGenerationFound:form];
[bridge_ formEligibleForGenerationFound:form];
}
}
......@@ -70,11 +70,11 @@ void IOSChromePasswordManagerDriver::ClearPreviewedForm() {
password_manager::PasswordGenerationFrameHelper*
IOSChromePasswordManagerDriver::GetPasswordGenerationHelper() {
return [delegate_ passwordGenerationHelper];
return [bridge_ passwordGenerationHelper];
}
PasswordManager* IOSChromePasswordManagerDriver::GetPasswordManager() {
return [delegate_ passwordManager];
return [bridge_ passwordManager];
}
PasswordAutofillManager*
......@@ -99,5 +99,5 @@ bool IOSChromePasswordManagerDriver::CanShowAutofillUi() const {
}
const GURL& IOSChromePasswordManagerDriver::GetLastCommittedURL() const {
return delegate_.lastCommittedURL;
return bridge_.lastCommittedURL;
}
......@@ -10,6 +10,8 @@
#import "components/autofill/ios/browser/form_suggestion_provider.h"
#import "components/password_manager/ios/password_form_helper.h"
#import "components/password_manager/ios/password_manager_client_bridge.h"
#import "components/password_manager/ios/password_manager_driver_bridge.h"
#import "ios/chrome/browser/passwords/ios_chrome_password_manager_client.h"
#import "ios/chrome/browser/passwords/ios_chrome_password_manager_driver.h"
#import "ios/web/public/web_state_observer_bridge.h"
......@@ -41,10 +43,10 @@ class PasswordManagerClient;
@end
// Per-tab password controller. Handles password autofill and saving.
@interface PasswordController : NSObject<CRWWebStateObserver,
PasswordManagerClientDelegate,
PasswordManagerDriverDelegate,
PasswordFormHelperDelegate>
@interface PasswordController : NSObject <CRWWebStateObserver,
IOSChromePasswordManagerClientBridge,
PasswordManagerDriverBridge,
PasswordFormHelperDelegate>
// An object that can provide suggestions from this PasswordController.
@property(nonatomic, readonly) id<FormSuggestionProvider> suggestionProvider;
......
......@@ -558,7 +558,7 @@ NSString* const kSuggestionSuffix = @" ••••••••";
}
}
#pragma mark - PasswordManagerClientDelegate
#pragma mark - IOSChromePasswordManagerClientBridge
- (WebState*)webState {
return _webState;
......@@ -645,7 +645,7 @@ NSString* const kSuggestionSuffix = @" ••••••••";
URL:URL];
}
#pragma mark - PasswordManagerDriverDelegate
#pragma mark - PasswordManagerDriverBridge
- (void)fillPasswordForm:(const autofill::PasswordFormFillData&)formData
completionHandler:(void (^)(BOOL))completionHandler {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment