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 @@
#include "components/autofill/core/browser/payments/legal_message_line.h"
namespace autofill {
class AutofillProfile;
class CreditCard;
class FormStructure;
} // namespace autofill
......@@ -24,6 +25,10 @@ class FormStructure;
// WebView extension of 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|.
- (void)confirmSaveCreditCardLocally:(const autofill::CreditCard&)creditCard
saveCreditCardOptions:
......
......@@ -35,6 +35,7 @@
#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_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_credit_card_internal.h"
#import "ios/web_view/internal/autofill/cwv_credit_card_saver_internal.h"
......@@ -420,6 +421,26 @@ fetchNonPasswordSuggestionsForFormWithName:(NSString*)formName
[_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
saveCreditCardOptions:
(autofill::AutofillClient::SaveCreditCardOptions)
......
......@@ -171,9 +171,7 @@ void WebViewAutofillClientIOS::ShowWebauthnOfferDialog(
void WebViewAutofillClientIOS::ConfirmSaveAutofillProfile(
const AutofillProfile& profile,
base::OnceClosure callback) {
// Since there is no confirmation needed to save an Autofill Profile,
// running |callback| will proceed with saving |profile|.
std::move(callback).Run();
[bridge_ confirmSaveAutofillProfile:profile callback:std::move(callback)];
}
void WebViewAutofillClientIOS::ConfirmSaveCreditCardLocally(
......
......@@ -11,6 +11,7 @@ NS_ASSUME_NONNULL_BEGIN
@class CWVAutofillController;
@class CWVAutofillFormSuggestion;
@class CWVAutofillProfile;
@class CWVCreditCard;
@class CWVCreditCardSaver;
@class CWVCreditCardVerifier;
......@@ -76,6 +77,14 @@ typedef NS_ENUM(NSInteger, CWVPasswordUserDecision) {
- (void)autofillControllerDidInsertFormElements:
(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
// after a new card was entered in a form and submitted.
// |saver| encapsulates information needed to assist with this save attempt.
......@@ -113,6 +122,7 @@ typedef NS_ENUM(NSInteger, CWVPasswordUserDecision) {
decisionHandler:
(void (^)(CWVPasswordUserDecision decision))
decisionHandler;
@end
NS_ASSUME_NONNULL_END
......
......@@ -64,7 +64,20 @@ NSString* const kTestFormHtml =
// Tests autofill features in CWVWebViews.
class WebViewAutofillTest : public WebViewInttestBase {
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 {
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