-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[iOS] Update params when Payments Bottom Sheet is about to be shown
Part 1 of the fix to fill the credit card fields properly with the payments bottom sheet. In this CL we are adding AutofillBottomSheetObserver to observe when the payments bottom sheet is about to be shown. We need to add this because we encountered an issue where if the auto focus of the page is on another field, the _lastSeenParams in FormInputAccessoryMediator still set as that auto focus field. When we tap on another field, keyboardWillShow will be called before anything else and in that method, we call retrieveSuggestionsForForm with the _lastSeenParams. This was causing conflict with our setup call: both FormInputAccessoryMediator and PaymentsSuggestionBottomSheetMediator are calling retrieveSuggestionsForForm and the first call to complete with a success will stop the pipeline. That means the first one to complete will be setting the query form and query field. We want the form and field to be the correct one in order to fill the credit card fields properly. Bug: 1491904 Change-Id: I7f8b00fbd3ef6265610c21ea8d8ff6ea26293dbb Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4974721 Reviewed-by: Tommy Martino <tmartino@chromium.org> Commit-Queue: Veronique Nguyen <veronguyen@google.com> Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Cr-Commit-Position: refs/heads/main@{#1217202}
- Loading branch information
Veronique Nguyen
authored and
Chromium LUCI CQ
committed
Oct 30, 2023
1 parent
5655160
commit 52d64f5
Showing
11 changed files
with
260 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
ios/chrome/browser/autofill/bottom_sheet/autofill_bottom_sheet_observer.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef IOS_CHROME_BROWSER_AUTOFILL_BOTTOM_SHEET_AUTOFILL_BOTTOM_SHEET_OBSERVER_H_ | ||
#define IOS_CHROME_BROWSER_AUTOFILL_BOTTOM_SHEET_AUTOFILL_BOTTOM_SHEET_OBSERVER_H_ | ||
|
||
namespace autofill { | ||
|
||
struct FormActivityParams; | ||
|
||
// Interface for observing autofill bottom sheet activity. | ||
class AutofillBottomSheetObserver { | ||
public: | ||
AutofillBottomSheetObserver() {} | ||
|
||
AutofillBottomSheetObserver(const AutofillBottomSheetObserver&) = delete; | ||
AutofillBottomSheetObserver& operator=(const AutofillBottomSheetObserver&) = | ||
delete; | ||
|
||
virtual ~AutofillBottomSheetObserver() {} | ||
|
||
// Called when the payments bottom sheet is about to be shown. Sends the | ||
// params used to open the payments bottom sheet. | ||
virtual void WillShowPaymentsBottomSheet(const FormActivityParams& params) {} | ||
}; | ||
|
||
} // namespace autofill | ||
|
||
#endif // IOS_CHROME_BROWSER_AUTOFILL_BOTTOM_SHEET_AUTOFILL_BOTTOM_SHEET_OBSERVER_H_ |
47 changes: 47 additions & 0 deletions
47
ios/chrome/browser/autofill/bottom_sheet/autofill_bottom_sheet_observer_bridge.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef IOS_CHROME_BROWSER_AUTOFILL_BOTTOM_SHEET_AUTOFILL_BOTTOM_SHEET_OBSERVER_BRIDGE_H_ | ||
#define IOS_CHROME_BROWSER_AUTOFILL_BOTTOM_SHEET_AUTOFILL_BOTTOM_SHEET_OBSERVER_BRIDGE_H_ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "base/scoped_observation.h" | ||
#import "ios/chrome/browser/autofill/bottom_sheet/autofill_bottom_sheet_observer.h" | ||
#import "ios/chrome/browser/autofill/bottom_sheet/autofill_bottom_sheet_tab_helper.h" | ||
|
||
@protocol AutofillBottomSheetObserving <NSObject> | ||
@optional | ||
// Invoked by AutofillBottomSheetObserverBridge::WillShowPaymentsBottomSheet. | ||
- (void)willShowPaymentsBottomSheetWithParams: | ||
(const autofill::FormActivityParams&)params; | ||
|
||
@end | ||
|
||
namespace autofill { | ||
|
||
// Use this class to be notified of the autofill bottom sheet activity in an | ||
// Objective-C class. Implement the AutofillBottomSheetObserving protocol and | ||
// create a AutofillBottomSheetObserverBridge passing self and | ||
// AutofillBottomSheetTabHelper. | ||
class AutofillBottomSheetObserverBridge : public AutofillBottomSheetObserver { | ||
public: | ||
// `owner` will not be retained. | ||
AutofillBottomSheetObserverBridge(id<AutofillBottomSheetObserving> owner, | ||
AutofillBottomSheetTabHelper* helper); | ||
~AutofillBottomSheetObserverBridge() override; | ||
|
||
// AutofillBottomSheetObserver overrides: | ||
void WillShowPaymentsBottomSheet(const FormActivityParams& params) override; | ||
|
||
private: | ||
__weak id<AutofillBottomSheetObserving> owner_ = nil; | ||
base::ScopedObservation<AutofillBottomSheetTabHelper, | ||
AutofillBottomSheetObserver> | ||
scoped_observation_{this}; | ||
}; | ||
|
||
} // namespace autofill | ||
|
||
#endif // IOS_CHROME_BROWSER_AUTOFILL_BOTTOM_SHEET_AUTOFILL_BOTTOM_SHEET_OBSERVER_BRIDGE_H_ |
22 changes: 22 additions & 0 deletions
22
ios/chrome/browser/autofill/bottom_sheet/autofill_bottom_sheet_observer_bridge.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "ios/chrome/browser/autofill/bottom_sheet/autofill_bottom_sheet_observer_bridge.h" | ||
|
||
namespace autofill { | ||
AutofillBottomSheetObserverBridge::AutofillBottomSheetObserverBridge( | ||
id<AutofillBottomSheetObserving> owner, | ||
AutofillBottomSheetTabHelper* helper) | ||
: owner_(owner) { | ||
scoped_observation_.Observe(helper); | ||
} | ||
|
||
AutofillBottomSheetObserverBridge::~AutofillBottomSheetObserverBridge() = | ||
default; | ||
|
||
void AutofillBottomSheetObserverBridge::WillShowPaymentsBottomSheet( | ||
const FormActivityParams& params) { | ||
[owner_ willShowPaymentsBottomSheetWithParams:params]; | ||
} | ||
} // namespace autofill |
86 changes: 86 additions & 0 deletions
86
ios/chrome/browser/autofill/bottom_sheet/autofill_bottom_sheet_observer_bridge_unittest.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#import "ios/chrome/browser/autofill/bottom_sheet/autofill_bottom_sheet_observer_bridge.h" | ||
|
||
#import "components/autofill/ios/form_util/form_activity_params.h" | ||
#import "ios/chrome/browser/autofill/bottom_sheet/autofill_bottom_sheet_java_script_feature.h" | ||
#import "ios/chrome/browser/autofill/bottom_sheet/autofill_bottom_sheet_observer.h" | ||
#import "ios/chrome/browser/autofill/bottom_sheet/autofill_bottom_sheet_tab_helper.h" | ||
#import "ios/web/public/test/fakes/fake_web_frames_manager.h" | ||
#import "ios/web/public/test/fakes/fake_web_state.h" | ||
#import "testing/platform_test.h" | ||
|
||
@interface FakeAutofillBottomSheetObserving | ||
: NSObject <AutofillBottomSheetObserving> | ||
|
||
- (autofill::FormActivityParams)params; | ||
|
||
@end | ||
|
||
@implementation FakeAutofillBottomSheetObserving { | ||
autofill::FormActivityParams _params; | ||
} | ||
|
||
- (autofill::FormActivityParams)params { | ||
return _params; | ||
} | ||
|
||
- (void)willShowPaymentsBottomSheetWithParams: | ||
(const autofill::FormActivityParams&)params { | ||
_params = params; | ||
} | ||
|
||
@end | ||
|
||
// Test fixture to test AutofillBottomSheetObserverBridge class. | ||
class AutofillBottomSheetObserverBridgeTest : public PlatformTest { | ||
protected: | ||
AutofillBottomSheetObserverBridgeTest() { | ||
observer_ = [[FakeAutofillBottomSheetObserving alloc] init]; | ||
|
||
auto fake_web_state = std::make_unique<web::FakeWebState>(); | ||
auto frames_manager = std::make_unique<web::FakeWebFramesManager>(); | ||
web::ContentWorld content_world = | ||
AutofillBottomSheetJavaScriptFeature::GetInstance() | ||
->GetSupportedContentWorld(); | ||
fake_web_state->SetWebFramesManager(content_world, | ||
std::move(frames_manager)); | ||
|
||
AutofillBottomSheetTabHelper::CreateForWebState(fake_web_state.get(), nil); | ||
AutofillBottomSheetTabHelper* helper = | ||
AutofillBottomSheetTabHelper::FromWebState(fake_web_state.get()); | ||
|
||
observer_bridge_ = | ||
std::make_unique<autofill::AutofillBottomSheetObserverBridge>(observer_, | ||
helper); | ||
} | ||
|
||
FakeAutofillBottomSheetObserving* observer_; | ||
std::unique_ptr<autofill::AutofillBottomSheetObserverBridge> observer_bridge_; | ||
}; | ||
|
||
// Tests willShowPaymentsBottomSheetWithParams: forwarding. | ||
TEST_F(AutofillBottomSheetObserverBridgeTest, TestShowPaymentsBottomSheet) { | ||
// Params values are empty. | ||
EXPECT_EQ("", [observer_ params].form_name); | ||
EXPECT_EQ("", [observer_ params].field_type); | ||
EXPECT_EQ("", [observer_ params].type); | ||
|
||
std::string form_name = "form-name"; | ||
std::string field_type = "text"; | ||
std::string type = "focus"; | ||
|
||
autofill::FormActivityParams params; | ||
params.form_name = form_name; | ||
params.field_type = field_type; | ||
params.type = type; | ||
|
||
observer_bridge_->WillShowPaymentsBottomSheet(params); | ||
|
||
// Params values are filled properly. | ||
EXPECT_EQ(form_name, [observer_ params].form_name); | ||
EXPECT_EQ(field_type, [observer_ params].field_type); | ||
EXPECT_EQ(type, [observer_ params].type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.