Commit 34b26733 authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Pass in CWVPasswordController to CWVAutofillController

It will be easier to mock/fake the password controller in unit tests.

Bug: 1048256
Change-Id: Icaee411736f3a58ca0978a50762a014775deb032
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2047488Reviewed-by: default avatarHiroshi Ichikawa <ichikawa@chromium.org>
Commit-Queue: John Wu <jzw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741128}
parent 6095a592
...@@ -118,7 +118,8 @@ fetchNonPasswordSuggestionsForFormWithName:(NSString*)formName ...@@ -118,7 +118,8 @@ fetchNonPasswordSuggestionsForFormWithName:(NSString*)formName
- (instancetype)initWithWebState:(web::WebState*)webState - (instancetype)initWithWebState:(web::WebState*)webState
autofillAgent:(AutofillAgent*)autofillAgent autofillAgent:(AutofillAgent*)autofillAgent
JSAutofillManager:(JsAutofillManager*)JSAutofillManager JSAutofillManager:(JsAutofillManager*)JSAutofillManager
JSSuggestionManager:(JsSuggestionManager*)JSSuggestionManager { JSSuggestionManager:(JsSuggestionManager*)JSSuggestionManager
passwordController:(CWVPasswordController*)passwordController {
self = [super init]; self = [super init];
if (self) { if (self) {
DCHECK(webState); DCHECK(webState);
...@@ -161,9 +162,8 @@ fetchNonPasswordSuggestionsForFormWithName:(NSString*)formName ...@@ -161,9 +162,8 @@ fetchNonPasswordSuggestionsForFormWithName:(NSString*)formName
_JSSuggestionManager = JSSuggestionManager; _JSSuggestionManager = JSSuggestionManager;
_passwordController = _passwordController = passwordController;
[[CWVPasswordController alloc] initWithWebState:webState _passwordController.delegate = self;
andDelegate:self];
} }
return self; return self;
} }
......
...@@ -14,6 +14,7 @@ class WebState; ...@@ -14,6 +14,7 @@ class WebState;
} // namespace web } // namespace web
@class AutofillAgent; @class AutofillAgent;
@class CWVPasswordController;
@class JsAutofillManager; @class JsAutofillManager;
@class JsSuggestionManager; @class JsSuggestionManager;
...@@ -23,6 +24,7 @@ class WebState; ...@@ -23,6 +24,7 @@ class WebState;
autofillAgent:(AutofillAgent*)autofillAgent autofillAgent:(AutofillAgent*)autofillAgent
JSAutofillManager:(JsAutofillManager*)JSAutofillManager JSAutofillManager:(JsAutofillManager*)JSAutofillManager
JSSuggestionManager:(JsSuggestionManager*)JSSuggestionManager JSSuggestionManager:(JsSuggestionManager*)JSSuggestionManager
passwordController:(CWVPasswordController*)passwordController
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
@end @end
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "ios/web/public/test/web_task_environment.h" #include "ios/web/public/test/web_task_environment.h"
#include "ios/web/public/web_client.h" #include "ios/web/public/web_client.h"
#import "ios/web_view/internal/autofill/cwv_autofill_suggestion_internal.h" #import "ios/web_view/internal/autofill/cwv_autofill_suggestion_internal.h"
#import "ios/web_view/internal/passwords/cwv_password_controller.h"
#include "ios/web_view/internal/web_view_browser_state.h" #include "ios/web_view/internal/web_view_browser_state.h"
#import "ios/web_view/public/cwv_autofill_controller_delegate.h" #import "ios/web_view/public/cwv_autofill_controller_delegate.h"
#include "ios/web_view/test/test_with_locale_and_resources.h" #include "ios/web_view/test/test_with_locale_and_resources.h"
...@@ -77,11 +78,15 @@ class CWVAutofillControllerTest : public TestWithLocaleAndResources { ...@@ -77,11 +78,15 @@ class CWVAutofillControllerTest : public TestWithLocaleAndResources {
fake_web_frames_manager_ = frames_manager.get(); fake_web_frames_manager_ = frames_manager.get();
test_web_state_.SetWebFramesManager(std::move(frames_manager)); test_web_state_.SetWebFramesManager(std::move(frames_manager));
password_controller_ =
[[CWVPasswordController alloc] initWithWebState:&test_web_state_];
autofill_controller_ = autofill_controller_ =
[[CWVAutofillController alloc] initWithWebState:&test_web_state_ [[CWVAutofillController alloc] initWithWebState:&test_web_state_
autofillAgent:autofill_agent_ autofillAgent:autofill_agent_
JSAutofillManager:js_autofill_manager_ JSAutofillManager:js_autofill_manager_
JSSuggestionManager:js_suggestion_manager_]; JSSuggestionManager:js_suggestion_manager_
passwordController:password_controller_];
test_form_activity_tab_helper_ = test_form_activity_tab_helper_ =
std::make_unique<autofill::TestFormActivityTabHelper>(&test_web_state_); std::make_unique<autofill::TestFormActivityTabHelper>(&test_web_state_);
} }
...@@ -100,6 +105,7 @@ class CWVAutofillControllerTest : public TestWithLocaleAndResources { ...@@ -100,6 +105,7 @@ class CWVAutofillControllerTest : public TestWithLocaleAndResources {
CWVAutofillController* autofill_controller_; CWVAutofillController* autofill_controller_;
FakeAutofillAgent* autofill_agent_; FakeAutofillAgent* autofill_agent_;
FakeJSAutofillManager* js_autofill_manager_; FakeJSAutofillManager* js_autofill_manager_;
CWVPasswordController* password_controller_;
std::unique_ptr<autofill::TestFormActivityTabHelper> std::unique_ptr<autofill::TestFormActivityTabHelper>
test_form_activity_tab_helper_; test_form_activity_tab_helper_;
id js_suggestion_manager_; id js_suggestion_manager_;
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#import "ios/web_view/internal/cwv_ssl_status_internal.h" #import "ios/web_view/internal/cwv_ssl_status_internal.h"
#import "ios/web_view/internal/cwv_web_view_configuration_internal.h" #import "ios/web_view/internal/cwv_web_view_configuration_internal.h"
#import "ios/web_view/internal/language/web_view_url_language_histogram_factory.h" #import "ios/web_view/internal/language/web_view_url_language_histogram_factory.h"
#import "ios/web_view/internal/passwords/cwv_password_controller.h"
#import "ios/web_view/internal/translate/cwv_translation_controller_internal.h" #import "ios/web_view/internal/translate/cwv_translation_controller_internal.h"
#import "ios/web_view/internal/translate/web_view_translate_client.h" #import "ios/web_view/internal/translate/web_view_translate_client.h"
#include "ios/web_view/internal/web_view_browser_state.h" #include "ios/web_view/internal/web_view_browser_state.h"
...@@ -650,10 +651,13 @@ BOOL gChromeLongPressAndForceTouchHandlingEnabled = YES; ...@@ -650,10 +651,13 @@ BOOL gChromeLongPressAndForceTouchHandlingEnabled = YES;
[_webState->GetJSInjectionReceiver() [_webState->GetJSInjectionReceiver()
instanceOfClass:[JsSuggestionManager class]]); instanceOfClass:[JsSuggestionManager class]]);
[JSSuggestionManager setWebFramesManager:_webState->GetWebFramesManager()]; [JSSuggestionManager setWebFramesManager:_webState->GetWebFramesManager()];
CWVPasswordController* passwordController =
[[CWVPasswordController alloc] initWithWebState:_webState.get()];
return [[CWVAutofillController alloc] initWithWebState:_webState.get() return [[CWVAutofillController alloc] initWithWebState:_webState.get()
autofillAgent:autofillAgent autofillAgent:autofillAgent
JSAutofillManager:JSAutofillManager JSAutofillManager:JSAutofillManager
JSSuggestionManager:JSSuggestionManager]; JSSuggestionManager:JSSuggestionManager
passwordController:passwordController];
} }
#endif // BUILDFLAG(IOS_WEB_VIEW_ENABLE_AUTOFILL) #endif // BUILDFLAG(IOS_WEB_VIEW_ENABLE_AUTOFILL)
......
...@@ -47,11 +47,11 @@ class WebState; ...@@ -47,11 +47,11 @@ class WebState;
// autofilling password forms. // autofilling password forms.
@interface CWVPasswordController : NSObject @interface CWVPasswordController : NSObject
// Creates a new password controller with the given |webState|.
// |delegate| is used to receive password autofill suggestion callbacks. // |delegate| is used to receive password autofill suggestion callbacks.
@property(nonatomic, weak, nullable) id<CWVPasswordControllerDelegate> delegate;
// Creates a new password controller with the given |webState|.
- (instancetype)initWithWebState:(web::WebState*)webState - (instancetype)initWithWebState:(web::WebState*)webState
andDelegate:
(nullable id<CWVPasswordControllerDelegate>)delegate
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
......
...@@ -62,9 +62,6 @@ typedef void (^PasswordSuggestionsAvailableCompletion)( ...@@ -62,9 +62,6 @@ typedef void (^PasswordSuggestionsAvailableCompletion)(
// Helper contains common password suggestion logic. // Helper contains common password suggestion logic.
@property(nonatomic, readonly) PasswordSuggestionHelper* suggestionHelper; @property(nonatomic, readonly) PasswordSuggestionHelper* suggestionHelper;
// Delegate to receive password autofill suggestion callbacks.
@property(nonatomic, weak, nullable) id<CWVPasswordControllerDelegate> delegate;
// Informs the |_passwordManager| of the password forms (if any were present) // Informs the |_passwordManager| of the password forms (if any were present)
// that have been found on the page. // that have been found on the page.
- (void)didFinishPasswordFormExtraction:(const std::vector<FormData>&)forms; - (void)didFinishPasswordFormExtraction:(const std::vector<FormData>&)forms;
...@@ -104,9 +101,7 @@ typedef void (^PasswordSuggestionsAvailableCompletion)( ...@@ -104,9 +101,7 @@ typedef void (^PasswordSuggestionsAvailableCompletion)(
#pragma mark - Initialization #pragma mark - Initialization
- (instancetype)initWithWebState:(web::WebState*)webState - (instancetype)initWithWebState:(web::WebState*)webState {
andDelegate:
(nullable id<CWVPasswordControllerDelegate>)delegate {
self = [super init]; self = [super init];
if (self) { if (self) {
DCHECK(webState); DCHECK(webState);
...@@ -125,8 +120,6 @@ typedef void (^PasswordSuggestionsAvailableCompletion)( ...@@ -125,8 +120,6 @@ typedef void (^PasswordSuggestionsAvailableCompletion)(
_passwordManagerDriver = _passwordManagerDriver =
std::make_unique<WebViewPasswordManagerDriver>(self); std::make_unique<WebViewPasswordManagerDriver>(self);
_delegate = delegate;
// TODO(crbug.com/865114): Credential manager related logic // TODO(crbug.com/865114): Credential manager related logic
} }
return self; return self;
......
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