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
- (instancetype)initWithWebState:(web::WebState*)webState
autofillAgent:(AutofillAgent*)autofillAgent
JSAutofillManager:(JsAutofillManager*)JSAutofillManager
JSSuggestionManager:(JsSuggestionManager*)JSSuggestionManager {
JSSuggestionManager:(JsSuggestionManager*)JSSuggestionManager
passwordController:(CWVPasswordController*)passwordController {
self = [super init];
if (self) {
DCHECK(webState);
......@@ -161,9 +162,8 @@ fetchNonPasswordSuggestionsForFormWithName:(NSString*)formName
_JSSuggestionManager = JSSuggestionManager;
_passwordController =
[[CWVPasswordController alloc] initWithWebState:webState
andDelegate:self];
_passwordController = passwordController;
_passwordController.delegate = self;
}
return self;
}
......
......@@ -14,6 +14,7 @@ class WebState;
} // namespace web
@class AutofillAgent;
@class CWVPasswordController;
@class JsAutofillManager;
@class JsSuggestionManager;
......@@ -23,6 +24,7 @@ class WebState;
autofillAgent:(AutofillAgent*)autofillAgent
JSAutofillManager:(JsAutofillManager*)JSAutofillManager
JSSuggestionManager:(JsSuggestionManager*)JSSuggestionManager
passwordController:(CWVPasswordController*)passwordController
NS_DESIGNATED_INITIALIZER;
@end
......
......@@ -28,6 +28,7 @@
#include "ios/web/public/test/web_task_environment.h"
#include "ios/web/public/web_client.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"
#import "ios/web_view/public/cwv_autofill_controller_delegate.h"
#include "ios/web_view/test/test_with_locale_and_resources.h"
......@@ -77,11 +78,15 @@ class CWVAutofillControllerTest : public TestWithLocaleAndResources {
fake_web_frames_manager_ = frames_manager.get();
test_web_state_.SetWebFramesManager(std::move(frames_manager));
password_controller_ =
[[CWVPasswordController alloc] initWithWebState:&test_web_state_];
autofill_controller_ =
[[CWVAutofillController alloc] initWithWebState:&test_web_state_
autofillAgent:autofill_agent_
JSAutofillManager:js_autofill_manager_
JSSuggestionManager:js_suggestion_manager_];
JSSuggestionManager:js_suggestion_manager_
passwordController:password_controller_];
test_form_activity_tab_helper_ =
std::make_unique<autofill::TestFormActivityTabHelper>(&test_web_state_);
}
......@@ -100,6 +105,7 @@ class CWVAutofillControllerTest : public TestWithLocaleAndResources {
CWVAutofillController* autofill_controller_;
FakeAutofillAgent* autofill_agent_;
FakeJSAutofillManager* js_autofill_manager_;
CWVPasswordController* password_controller_;
std::unique_ptr<autofill::TestFormActivityTabHelper>
test_form_activity_tab_helper_;
id js_suggestion_manager_;
......
......@@ -48,6 +48,7 @@
#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/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/web_view_translate_client.h"
#include "ios/web_view/internal/web_view_browser_state.h"
......@@ -650,10 +651,13 @@ BOOL gChromeLongPressAndForceTouchHandlingEnabled = YES;
[_webState->GetJSInjectionReceiver()
instanceOfClass:[JsSuggestionManager class]]);
[JSSuggestionManager setWebFramesManager:_webState->GetWebFramesManager()];
CWVPasswordController* passwordController =
[[CWVPasswordController alloc] initWithWebState:_webState.get()];
return [[CWVAutofillController alloc] initWithWebState:_webState.get()
autofillAgent:autofillAgent
JSAutofillManager:JSAutofillManager
JSSuggestionManager:JSSuggestionManager];
JSSuggestionManager:JSSuggestionManager
passwordController:passwordController];
}
#endif // BUILDFLAG(IOS_WEB_VIEW_ENABLE_AUTOFILL)
......
......@@ -47,11 +47,11 @@ class WebState;
// autofilling password forms.
@interface CWVPasswordController : NSObject
// Creates a new password controller with the given |webState|.
// |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
andDelegate:
(nullable id<CWVPasswordControllerDelegate>)delegate
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
......
......@@ -62,9 +62,6 @@ typedef void (^PasswordSuggestionsAvailableCompletion)(
// Helper contains common password suggestion logic.
@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)
// that have been found on the page.
- (void)didFinishPasswordFormExtraction:(const std::vector<FormData>&)forms;
......@@ -104,9 +101,7 @@ typedef void (^PasswordSuggestionsAvailableCompletion)(
#pragma mark - Initialization
- (instancetype)initWithWebState:(web::WebState*)webState
andDelegate:
(nullable id<CWVPasswordControllerDelegate>)delegate {
- (instancetype)initWithWebState:(web::WebState*)webState {
self = [super init];
if (self) {
DCHECK(webState);
......@@ -125,8 +120,6 @@ typedef void (^PasswordSuggestionsAvailableCompletion)(
_passwordManagerDriver =
std::make_unique<WebViewPasswordManagerDriver>(self);
_delegate = delegate;
// TODO(crbug.com/865114): Credential manager related logic
}
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