Commit d5ca5fe6 authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Use CWVPassword class in save/update delegate callbacks

Change-Id: I37c0dfe768d60b4306c0c1745517936425047ea9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1817291Reviewed-by: default avatarHiroshi Ichikawa <ichikawa@chromium.org>
Commit-Queue: John Wu <jzw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699631}
parent e800d80e
...@@ -645,30 +645,28 @@ showUnmaskPromptForCard:(const autofill::CreditCard&)creditCard ...@@ -645,30 +645,28 @@ showUnmaskPromptForCard:(const autofill::CreditCard&)creditCard
#pragma mark - CWVPasswordControllerDelegate #pragma mark - CWVPasswordControllerDelegate
- (void)passwordController:(CWVPasswordController*)passwordController - (void)passwordController:(CWVPasswordController*)passwordController
decidePasswordSavingPolicyForUsername:(NSString*)username decideSavePolicyForPassword:(CWVPassword*)password
decisionHandler: decisionHandler:(void (^)(CWVPasswordUserDecision decision))
(void (^)(CWVPasswordUserDecision decision)) decisionHandler {
decisionHandler {
if ([self.delegate respondsToSelector:@selector if ([self.delegate respondsToSelector:@selector
(autofillController:decidePasswordSavingPolicyForUsername (autofillController:
:decisionHandler:)]) { decideSavePolicyForPassword:decisionHandler:)]) {
[self.delegate autofillController:self [self.delegate autofillController:self
decidePasswordSavingPolicyForUsername:username decideSavePolicyForPassword:password
decisionHandler:decisionHandler]; decisionHandler:decisionHandler];
} }
} }
- (void)passwordController:(CWVPasswordController*)passwordController - (void)passwordController:(CWVPasswordController*)passwordController
decidePasswordUpdatingPolicyForUsername:(NSString*)username decideUpdatePolicyForPassword:(CWVPassword*)password
decisionHandler: decisionHandler:(void (^)(CWVPasswordUserDecision decision))
(void (^)(CWVPasswordUserDecision decision)) decisionHandler {
decisionHandler {
if ([self.delegate respondsToSelector:@selector if ([self.delegate respondsToSelector:@selector
(autofillController:decidePasswordUpdatingPolicyForUsername (autofillController:
:decisionHandler:)]) { decideUpdatePolicyForPassword:decisionHandler:)]) {
[self.delegate autofillController:self [self.delegate autofillController:self
decidePasswordUpdatingPolicyForUsername:username decideUpdatePolicyForPassword:password
decisionHandler:decisionHandler]; decisionHandler:decisionHandler];
} }
} }
......
...@@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, CWVPasswordUserDecision); typedef NS_ENUM(NSInteger, CWVPasswordUserDecision);
@class CWVAutofillSuggestion; @class CWVAutofillSuggestion;
@class CWVPasswordController; @class CWVPasswordController;
@class CWVPassword;
namespace web { namespace web {
class WebState; class WebState;
...@@ -20,29 +21,25 @@ class WebState; ...@@ -20,29 +21,25 @@ class WebState;
// Internal protocol to receive callbacks related to password autofilling. // Internal protocol to receive callbacks related to password autofilling.
@protocol CWVPasswordControllerDelegate @protocol CWVPasswordControllerDelegate
// Called when user needs to decide on whether or not to save the // Called when user needs to decide on whether or not to save the |password|.
// password for |username|.
// This can happen when user is successfully logging into a web site with a new // This can happen when user is successfully logging into a web site with a new
// username. // username.
// Pass user decision to |decisionHandler|. This block should be called only // Pass user decision to |decisionHandler|. This block should be called only
// once if user made the decision, or not get called if user ignores the prompt. // once if user made the decision, or not get called if user ignores the prompt.
- (void)passwordController:(CWVPasswordController*)passwordController - (void)passwordController:(CWVPasswordController*)passwordController
decidePasswordSavingPolicyForUsername:(NSString*)username decideSavePolicyForPassword:(CWVPassword*)password
decisionHandler: decisionHandler:
(void (^)(CWVPasswordUserDecision decision)) (void (^)(CWVPasswordUserDecision decision))decisionHandler;
decisionHandler;
// Called when user needs to decide on whether or not to update the // Called when user needs to decide on whether or not to update the |password|.
// password for |username|.
// This can happen when user is successfully logging into a web site with a new // This can happen when user is successfully logging into a web site with a new
// password and an existing username. // password and an existing username.
// Pass user decision to |decisionHandler|. This block should be called only // Pass user decision to |decisionHandler|. This block should be called only
// once if user made the decision, or not get called if user ignores the prompt. // once if user made the decision, or not get called if user ignores the prompt.
- (void)passwordController:(CWVPasswordController*)passwordController - (void)passwordController:(CWVPasswordController*)passwordController
decidePasswordUpdatingPolicyForUsername:(NSString*)username decideUpdatePolicyForPassword:(CWVPassword*)password
decisionHandler: decisionHandler:(void (^)(CWVPasswordUserDecision decision))
(void (^)(CWVPasswordUserDecision decision)) decisionHandler;
decisionHandler;
@end @end
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#import "ios/web/public/web_state.h" #import "ios/web/public/web_state.h"
#import "ios/web/public/web_state_observer_bridge.h" #import "ios/web/public/web_state_observer_bridge.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_internal.h"
#import "ios/web_view/internal/passwords/web_view_password_manager_client.h" #import "ios/web_view/internal/passwords/web_view_password_manager_client.h"
#import "ios/web_view/internal/passwords/web_view_password_manager_driver.h" #import "ios/web_view/internal/passwords/web_view_password_manager_driver.h"
#include "ios/web_view/internal/web_view_browser_state.h" #include "ios/web_view/internal/web_view_browser_state.h"
...@@ -207,25 +208,25 @@ typedef void (^PasswordSuggestionsAvailableCompletion)( ...@@ -207,25 +208,25 @@ typedef void (^PasswordSuggestionsAvailableCompletion)(
__block std::unique_ptr<PasswordFormManagerForUI> formPtr( __block std::unique_ptr<PasswordFormManagerForUI> formPtr(
std::move(formToSave)); std::move(formToSave));
NSString* userName = const PasswordForm& credentials = formPtr->GetPendingCredentials();
base::SysUTF16ToNSString(formPtr->GetPendingCredentials().username_value); CWVPassword* password =
[[CWVPassword alloc] initWithPasswordForm:credentials];
[self.delegate passwordController:self [self.delegate passwordController:self
decidePasswordSavingPolicyForUsername:userName decideSavePolicyForPassword:password
decisionHandler:^( decisionHandler:^(CWVPasswordUserDecision decision) {
CWVPasswordUserDecision decision) { switch (decision) {
switch (decision) { case CWVPasswordUserDecisionYes:
case CWVPasswordUserDecisionYes: formPtr->Save();
formPtr->Save(); break;
break; case CWVPasswordUserDecisionNever:
case CWVPasswordUserDecisionNever: formPtr->PermanentlyBlacklist();
formPtr->PermanentlyBlacklist(); break;
break; default:
default: // Do nothing.
// Do nothing. break;
break; }
} }];
}];
} }
- (void)showUpdatePasswordInfoBar: - (void)showUpdatePasswordInfoBar:
...@@ -240,18 +241,17 @@ typedef void (^PasswordSuggestionsAvailableCompletion)( ...@@ -240,18 +241,17 @@ typedef void (^PasswordSuggestionsAvailableCompletion)(
std::move(formToUpdate)); std::move(formToUpdate));
const PasswordForm& credentials = formPtr->GetPendingCredentials(); const PasswordForm& credentials = formPtr->GetPendingCredentials();
NSString* userName = base::SysUTF16ToNSString(credentials.username_value); CWVPassword* password =
[[CWVPassword alloc] initWithPasswordForm:credentials];
[self.delegate passwordController:self [self.delegate passwordController:self
decidePasswordUpdatingPolicyForUsername:userName decideUpdatePolicyForPassword:password
decisionHandler:^( decisionHandler:^(CWVPasswordUserDecision decision) {
CWVPasswordUserDecision decision) { DCHECK_NE(decision, CWVPasswordUserDecisionNever);
DCHECK_NE(decision, if (decision == CWVPasswordUserDecisionYes) {
CWVPasswordUserDecisionNever); formPtr->Update(credentials);
if (decision == CWVPasswordUserDecisionYes) { }
formPtr->Update(credentials); }];
}
}];
} }
- (void)showAutosigninNotification:(std::unique_ptr<PasswordForm>)formSignedIn { - (void)showAutosigninNotification:(std::unique_ptr<PasswordForm>)formSignedIn {
......
...@@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -15,6 +15,7 @@ NS_ASSUME_NONNULL_BEGIN
@class CWVCreditCard; @class CWVCreditCard;
@class CWVCreditCardSaver; @class CWVCreditCardSaver;
@class CWVCreditCardVerifier; @class CWVCreditCardVerifier;
@class CWVPassword;
// User decision for saving / updating password. // User decision for saving / updating password.
// Note: CWVPasswordUserDecisionNever is only used in saving scenarios. // Note: CWVPasswordUserDecisionNever is only used in saving scenarios.
...@@ -97,31 +98,27 @@ typedef NS_ENUM(NSInteger, CWVPasswordUserDecision) { ...@@ -97,31 +98,27 @@ typedef NS_ENUM(NSInteger, CWVPasswordUserDecision) {
- (void)autofillController:(CWVAutofillController*)autofillController - (void)autofillController:(CWVAutofillController*)autofillController
verifyCreditCardWithVerifier:(CWVCreditCardVerifier*)verifier; verifyCreditCardWithVerifier:(CWVCreditCardVerifier*)verifier;
// Called when user needs to decide on whether or not to save the // Called when user needs to decide on whether or not to save the |password|.
// password for |username|.
// This can happen when user successfully logs into a web site with a new // This can happen when user successfully logs into a web site with a new
// username. // username.
// Pass user decision to |decisionHandler|. This block should be called only // Pass user decision to |decisionHandler|. This block should be called only
// once if user made the decision, or not get called if user ignores the prompt. // once if user made the decision, or not get called if user ignores the prompt.
// Not implementing it is equivalent of not calling |decisionHandler|. // Not implementing it is equivalent of not calling |decisionHandler|.
- (void)autofillController:(CWVAutofillController*)autofillController - (void)autofillController:(CWVAutofillController*)autofillController
decidePasswordSavingPolicyForUsername:(NSString*)username decideSavePolicyForPassword:(CWVPassword*)password
decisionHandler: decisionHandler:
(void (^)(CWVPasswordUserDecision decision)) (void (^)(CWVPasswordUserDecision decision))decisionHandler;
decisionHandler;
// Called when user needs to decide on whether or not to update the // Called when user needs to decide on whether or not to update the |password|.
// password for |username|.
// This can happen when user successfully logs into a web site with a new // This can happen when user successfully logs into a web site with a new
// password and an existing username. // password and an existing username.
// Pass user decision to |decisionHandler|. This block should be called only // Pass user decision to |decisionHandler|. This block should be called only
// once if user made the decision, or not get called if user ignores the prompt. // once if user made the decision, or not get called if user ignores the prompt.
// Not implementing it is equivalent of not calling |decisionHandler|. // Not implementing it is equivalent of not calling |decisionHandler|.
- (void)autofillController:(CWVAutofillController*)autofillController - (void)autofillController:(CWVAutofillController*)autofillController
decidePasswordUpdatingPolicyForUsername:(NSString*)username decideUpdatePolicyForPassword:(CWVPassword*)password
decisionHandler: decisionHandler:(void (^)(CWVPasswordUserDecision decision))
(void (^)(CWVPasswordUserDecision decision)) decisionHandler;
decisionHandler;
@end @end
......
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