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

Add confirmation callback for saving addresses

Change-Id: Ia85f646245f86b4a8e9b6899c9185f88ea35e360
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1817321
Commit-Queue: John Wu <jzw@chromium.org>
Reviewed-by: default avatarHiroshi Ichikawa <ichikawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699396}
parent 3cb120c2
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "components/autofill/core/browser/payments/legal_message_line.h" #include "components/autofill/core/browser/payments/legal_message_line.h"
namespace autofill { namespace autofill {
class AutofillProfile;
class CreditCard; class CreditCard;
class FormStructure; class FormStructure;
} // namespace autofill } // namespace autofill
...@@ -24,6 +25,10 @@ class FormStructure; ...@@ -24,6 +25,10 @@ class FormStructure;
// WebView extension of AutofillClientIOSBridge. // WebView extension of AutofillClientIOSBridge.
@protocol CWVAutofillClientIOSBridge<AutofillClientIOSBridge> @protocol CWVAutofillClientIOSBridge<AutofillClientIOSBridge>
// Bridge for AutofillClient's method |ConfirmSaveAutofillProfile|.
- (void)confirmSaveAutofillProfile:(const autofill::AutofillProfile&)profile
callback:(base::OnceClosure)callback;
// Bridge for AutofillClient's method |ConfirmSaveCreditCardLocally|. // Bridge for AutofillClient's method |ConfirmSaveCreditCardLocally|.
- (void)confirmSaveCreditCardLocally:(const autofill::CreditCard&)creditCard - (void)confirmSaveCreditCardLocally:(const autofill::CreditCard&)creditCard
saveCreditCardOptions: saveCreditCardOptions:
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "ios/web_view/internal/app/application_context.h" #include "ios/web_view/internal/app/application_context.h"
#import "ios/web_view/internal/autofill/cwv_autofill_client_ios_bridge.h" #import "ios/web_view/internal/autofill/cwv_autofill_client_ios_bridge.h"
#import "ios/web_view/internal/autofill/cwv_autofill_form_internal.h" #import "ios/web_view/internal/autofill/cwv_autofill_form_internal.h"
#import "ios/web_view/internal/autofill/cwv_autofill_profile_internal.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/autofill/cwv_credit_card_internal.h" #import "ios/web_view/internal/autofill/cwv_credit_card_internal.h"
#import "ios/web_view/internal/autofill/cwv_credit_card_saver_internal.h" #import "ios/web_view/internal/autofill/cwv_credit_card_saver_internal.h"
...@@ -420,6 +421,26 @@ fetchNonPasswordSuggestionsForFormWithName:(NSString*)formName ...@@ -420,6 +421,26 @@ fetchNonPasswordSuggestionsForFormWithName:(NSString*)formName
[_autofillAgent hideAutofillPopup]; [_autofillAgent hideAutofillPopup];
} }
- (void)confirmSaveAutofillProfile:(const autofill::AutofillProfile&)profile
callback:(base::OnceClosure)callback {
if (![_delegate respondsToSelector:@selector
(autofillController:
decideSavePolicyForAutofillProfile:decisionHandler:)]) {
return;
}
__block base::OnceClosure scopedCallback = std::move(callback);
CWVAutofillProfile* autofillProfile =
[[CWVAutofillProfile alloc] initWithProfile:profile];
[_delegate autofillController:self
decideSavePolicyForAutofillProfile:autofillProfile
decisionHandler:^(BOOL save) {
if (save) {
std::move(scopedCallback).Run();
}
}];
}
- (void)confirmSaveCreditCardLocally:(const autofill::CreditCard&)creditCard - (void)confirmSaveCreditCardLocally:(const autofill::CreditCard&)creditCard
saveCreditCardOptions: saveCreditCardOptions:
(autofill::AutofillClient::SaveCreditCardOptions) (autofill::AutofillClient::SaveCreditCardOptions)
......
...@@ -171,9 +171,7 @@ void WebViewAutofillClientIOS::ShowWebauthnOfferDialog( ...@@ -171,9 +171,7 @@ void WebViewAutofillClientIOS::ShowWebauthnOfferDialog(
void WebViewAutofillClientIOS::ConfirmSaveAutofillProfile( void WebViewAutofillClientIOS::ConfirmSaveAutofillProfile(
const AutofillProfile& profile, const AutofillProfile& profile,
base::OnceClosure callback) { base::OnceClosure callback) {
// Since there is no confirmation needed to save an Autofill Profile, [bridge_ confirmSaveAutofillProfile:profile callback:std::move(callback)];
// running |callback| will proceed with saving |profile|.
std::move(callback).Run();
} }
void WebViewAutofillClientIOS::ConfirmSaveCreditCardLocally( void WebViewAutofillClientIOS::ConfirmSaveCreditCardLocally(
......
...@@ -11,6 +11,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -11,6 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
@class CWVAutofillController; @class CWVAutofillController;
@class CWVAutofillFormSuggestion; @class CWVAutofillFormSuggestion;
@class CWVAutofillProfile;
@class CWVCreditCard; @class CWVCreditCard;
@class CWVCreditCardSaver; @class CWVCreditCardSaver;
@class CWVCreditCardVerifier; @class CWVCreditCardVerifier;
...@@ -76,6 +77,14 @@ typedef NS_ENUM(NSInteger, CWVPasswordUserDecision) { ...@@ -76,6 +77,14 @@ typedef NS_ENUM(NSInteger, CWVPasswordUserDecision) {
- (void)autofillControllerDidInsertFormElements: - (void)autofillControllerDidInsertFormElements:
(CWVAutofillController*)autofillController; (CWVAutofillController*)autofillController;
// Called when it is possible to save a new autofill profile used in filling
// address forms. This is usually invoked after successfully submitting an
// address form with a new profile. The profile will only be saved if this
// method is implemented and |decisionHandler| is called with |YES|.
- (void)autofillController:(CWVAutofillController*)autofillController
decideSavePolicyForAutofillProfile:(CWVAutofillProfile*)autofillProfile
decisionHandler:(void (^)(BOOL save))decisionHandler;
// Called when it is possible to save a new credit card. This is usually called // Called when it is possible to save a new credit card. This is usually called
// after a new card was entered in a form and submitted. // after a new card was entered in a form and submitted.
// |saver| encapsulates information needed to assist with this save attempt. // |saver| encapsulates information needed to assist with this save attempt.
...@@ -113,6 +122,7 @@ typedef NS_ENUM(NSInteger, CWVPasswordUserDecision) { ...@@ -113,6 +122,7 @@ typedef NS_ENUM(NSInteger, CWVPasswordUserDecision) {
decisionHandler: decisionHandler:
(void (^)(CWVPasswordUserDecision decision)) (void (^)(CWVPasswordUserDecision decision))
decisionHandler; decisionHandler;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
......
...@@ -64,7 +64,20 @@ NSString* const kTestFormHtml = ...@@ -64,7 +64,20 @@ NSString* const kTestFormHtml =
// Tests autofill features in CWVWebViews. // Tests autofill features in CWVWebViews.
class WebViewAutofillTest : public WebViewInttestBase { class WebViewAutofillTest : public WebViewInttestBase {
protected: protected:
WebViewAutofillTest() : autofill_controller_(web_view_.autofillController) {} WebViewAutofillTest() : autofill_controller_(web_view_.autofillController) {
// Ensure CWVAutofillProfiles are saved by default.
id delegate = OCMProtocolMock(@protocol(CWVAutofillControllerDelegate));
autofill_controller_.delegate = delegate;
[[delegate stub] autofillController:autofill_controller_
decideSavePolicyForAutofillProfile:[OCMArg any]
decisionHandler:[OCMArg
checkWithBlock:^BOOL(id param) {
void (^decisionHandler)(BOOL) =
param;
decisionHandler(YES);
return YES;
}]];
}
bool LoadTestPage() WARN_UNUSED_RESULT { bool LoadTestPage() WARN_UNUSED_RESULT {
std::string html = base::SysNSStringToUTF8(kTestFormHtml); std::string html = base::SysNSStringToUTF8(kTestFormHtml);
......
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