[iOS] Add code to trigger bottom sheet for edit address in SaveAddressProfileInfobarModalOverlayCoordinator
The next CLs would implement the bottom sheet itself.
Low-Coverage-Reason: TESTS_IN_SEPARATE_CL (https://crrev.com/c/5440193) The feature is in development and more tests will be added.
Bug: 1482269
Change-Id: Id4b93b04f11aed908cbebc3d38bfb2c6f53ee39b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5385790
Reviewed-by: Gauthier Ambard <gambard@chromium.org>
Commit-Queue: Vidhan Jain <vidhanj@google.com>
Reviewed-by: Tommy Martino <tmartino@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1285941}
diff --git a/ios/chrome/browser/autofill/model/bottom_sheet/autofill_bottom_sheet_tab_helper.h b/ios/chrome/browser/autofill/model/bottom_sheet/autofill_bottom_sheet_tab_helper.h
index 6da9ff12..d966ff6d 100644
--- a/ios/chrome/browser/autofill/model/bottom_sheet/autofill_bottom_sheet_tab_helper.h
+++ b/ios/chrome/browser/autofill/model/bottom_sheet/autofill_bottom_sheet_tab_helper.h
@@ -79,6 +79,9 @@
autofill::VirtualCardEnrollUiModel model,
autofill::VirtualCardEnrollmentCallbacks callbacks);
+ // Send a command to show the bottom sheet to edit an address.
+ void ShowEditAddressBottomSheet();
+
// Handler for JavaScript messages. Dispatch to more specific handler.
void OnFormMessageReceived(const web::ScriptMessage& message);
diff --git a/ios/chrome/browser/autofill/model/bottom_sheet/autofill_bottom_sheet_tab_helper.mm b/ios/chrome/browser/autofill/model/bottom_sheet/autofill_bottom_sheet_tab_helper.mm
index fc08086..4fd52e6 100644
--- a/ios/chrome/browser/autofill/model/bottom_sheet/autofill_bottom_sheet_tab_helper.mm
+++ b/ios/chrome/browser/autofill/model/bottom_sheet/autofill_bottom_sheet_tab_helper.mm
@@ -86,6 +86,10 @@
[commands_handler_ showVirtualCardEnrollmentBottomSheet:model];
}
+void AutofillBottomSheetTabHelper::ShowEditAddressBottomSheet() {
+ [commands_handler_ showEditAddressBottomSheet];
+}
+
void AutofillBottomSheetTabHelper::SetAutofillBottomSheetHandler(
id<AutofillCommands> commands_handler) {
commands_handler_ = commands_handler;
diff --git a/ios/chrome/browser/shared/public/commands/autofill_commands.h b/ios/chrome/browser/shared/public/commands/autofill_commands.h
index 2ee82ff8..ba80405 100644
--- a/ios/chrome/browser/shared/public/commands/autofill_commands.h
+++ b/ios/chrome/browser/shared/public/commands/autofill_commands.h
@@ -31,10 +31,13 @@
// Shows the plus address bottom sheet view controller.
- (void)showPlusAddressesBottomSheet;
-// Shows a command to show the VCN enrollment Bottom Sheet.
+// Sends a command to show the VCN enrollment Bottom Sheet.
- (void)showVirtualCardEnrollmentBottomSheet:
(const autofill::VirtualCardEnrollUiModel&)model;
+// Sends a command to show the bottom sheet to edit an address.
+- (void)showEditAddressBottomSheet;
+
// Commands to manage the Autofill error dialog.
- (void)showAutofillErrorDialog:
(autofill::AutofillErrorDialogContext)errorContext;
diff --git a/ios/chrome/browser/ui/browser_view/browser_coordinator.mm b/ios/chrome/browser/ui/browser_view/browser_coordinator.mm
index 70df046..c3f34e0d 100644
--- a/ios/chrome/browser/ui/browser_view/browser_coordinator.mm
+++ b/ios/chrome/browser/ui/browser_view/browser_coordinator.mm
@@ -1687,6 +1687,10 @@
[self.virtualCardEnrollmentBottomSheetCoordinator start];
}
+- (void)showEditAddressBottomSheet {
+ // TODO(crbug.com/148226): Implement.
+}
+
- (void)showAutofillErrorDialog:
(autofill::AutofillErrorDialogContext)errorContext {
if (self.autofillErrorDialogCoordinator) {
diff --git a/ios/chrome/browser/ui/overlays/infobar_modal/autofill_address_profile/BUILD.gn b/ios/chrome/browser/ui/overlays/infobar_modal/autofill_address_profile/BUILD.gn
index 237c6a1..82318148 100644
--- a/ios/chrome/browser/ui/overlays/infobar_modal/autofill_address_profile/BUILD.gn
+++ b/ios/chrome/browser/ui/overlays/infobar_modal/autofill_address_profile/BUILD.gn
@@ -15,13 +15,16 @@
"//base",
"//components/autofill/core/browser",
"//components/autofill/core/common",
+ "//components/autofill/ios/common",
"//ios/chrome/app/strings",
"//ios/chrome/browser/autofill/model",
+ "//ios/chrome/browser/autofill/model/bottom_sheet",
"//ios/chrome/browser/overlays/model",
"//ios/chrome/browser/overlays/model/public/common/infobars",
"//ios/chrome/browser/overlays/model/public/infobar_modal",
"//ios/chrome/browser/shared/model/browser",
"//ios/chrome/browser/shared/model/browser_state",
+ "//ios/chrome/browser/shared/model/web_state_list",
"//ios/chrome/browser/shared/ui/util",
"//ios/chrome/browser/ui/autofill:autofill_shared_ui",
"//ios/chrome/browser/ui/autofill/cells",
diff --git a/ios/chrome/browser/ui/overlays/infobar_modal/autofill_address_profile/save_address_profile_infobar_modal_overlay_coordinator.mm b/ios/chrome/browser/ui/overlays/infobar_modal/autofill_address_profile/save_address_profile_infobar_modal_overlay_coordinator.mm
index 5a91f9d..e2b5474e 100644
--- a/ios/chrome/browser/ui/overlays/infobar_modal/autofill_address_profile/save_address_profile_infobar_modal_overlay_coordinator.mm
+++ b/ios/chrome/browser/ui/overlays/infobar_modal/autofill_address_profile/save_address_profile_infobar_modal_overlay_coordinator.mm
@@ -8,12 +8,15 @@
#import "base/feature_list.h"
#import "base/strings/sys_string_conversions.h"
#import "components/autofill/core/common/autofill_features.h"
+#import "components/autofill/ios/common/features.h"
+#import "ios/chrome/browser/autofill/model/bottom_sheet/autofill_bottom_sheet_tab_helper.h"
#import "ios/chrome/browser/autofill/model/personal_data_manager_factory.h"
#import "ios/chrome/browser/overlays/model/public/infobar_modal/save_address_profile_infobar_modal_overlay_request_config.h"
#import "ios/chrome/browser/overlays/model/public/overlay_callback_manager.h"
#import "ios/chrome/browser/overlays/model/public/overlay_response.h"
#import "ios/chrome/browser/shared/model/browser/browser.h"
#import "ios/chrome/browser/shared/model/browser_state/chrome_browser_state.h"
+#import "ios/chrome/browser/shared/model/web_state_list/web_state_list.h"
#import "ios/chrome/browser/ui/autofill/autofill_country_selection_table_view_controller.h"
#import "ios/chrome/browser/ui/autofill/autofill_profile_edit_mediator.h"
#import "ios/chrome/browser/ui/autofill/autofill_profile_edit_mediator_delegate.h"
@@ -85,57 +88,72 @@
#pragma mark - Private
- (void)onSaveUpdateViewDismissed {
- SaveAddressProfileInfobarModalOverlayMediator* modalMediator =
- static_cast<SaveAddressProfileInfobarModalOverlayMediator*>(
- self.modalMediator);
if (!self.config) {
return;
}
- _autofillProfile =
- std::make_unique<autofill::AutofillProfile>(*(self.config->GetProfile()));
- autofill::PersonalDataManager* personalDataManager =
- autofill::PersonalDataManagerFactory::GetForBrowserState(
- self.browser->GetBrowserState()->GetOriginalChromeBrowserState());
- self.sharedEditViewMediator = [[AutofillProfileEditMediator alloc]
- initWithDelegate:self
- personalDataManager:personalDataManager
- autofillProfile:_autofillProfile.get()
- countryCode:nil
- isMigrationPrompt:self.config->is_migration_to_account()];
- LegacyInfobarEditAddressProfileTableViewController* editModalViewController =
- [[LegacyInfobarEditAddressProfileTableViewController alloc]
- initWithModalDelegate:modalMediator];
- self.sharedEditViewController =
- [[AutofillProfileEditTableViewController alloc]
- initWithDelegate:self.sharedEditViewMediator
- userEmail:(self.config->user_email()
- ? base::SysUTF16ToNSString(
- self.config->user_email().value())
- : nil)controller:editModalViewController
- settingsView:NO];
- self.sharedEditViewMediator.consumer = self.sharedEditViewController;
- editModalViewController.handler = self.sharedEditViewController;
+ if (base::FeatureList::IsEnabled(
+ kAutofillDynamicallyLoadsFieldsForAddressInput)) {
+ web::WebState* webState =
+ self.browser->GetWebStateList()->GetActiveWebState();
+ AutofillBottomSheetTabHelper* bottomSheetTabHelper =
+ AutofillBottomSheetTabHelper::FromWebState(webState);
+ bottomSheetTabHelper->ShowEditAddressBottomSheet();
+ } else {
+ SaveAddressProfileInfobarModalOverlayMediator* modalMediator =
+ static_cast<SaveAddressProfileInfobarModalOverlayMediator*>(
+ self.modalMediator);
+ _autofillProfile = std::make_unique<autofill::AutofillProfile>(
+ *(self.config->GetProfile()));
+ autofill::PersonalDataManager* personalDataManager =
+ autofill::PersonalDataManagerFactory::GetForBrowserState(
+ self.browser->GetBrowserState()->GetOriginalChromeBrowserState());
+ self.sharedEditViewMediator = [[AutofillProfileEditMediator alloc]
+ initWithDelegate:self
+ personalDataManager:personalDataManager
+ autofillProfile:_autofillProfile.get()
+ countryCode:nil
+ isMigrationPrompt:self.config->is_migration_to_account()];
- modalMediator.editAddressConsumer = editModalViewController;
- self.modalMediator = modalMediator;
- self.modalViewController = editModalViewController;
+ LegacyInfobarEditAddressProfileTableViewController*
+ editModalViewController =
+ [[LegacyInfobarEditAddressProfileTableViewController alloc]
+ initWithModalDelegate:modalMediator];
+ self.sharedEditViewController =
+ [[AutofillProfileEditTableViewController alloc]
+ initWithDelegate:self.sharedEditViewMediator
+ userEmail:(self.config->user_email()
+ ? base::SysUTF16ToNSString(
+ self.config->user_email().value())
+ : nil)controller:editModalViewController
+ settingsView:NO];
+ self.sharedEditViewMediator.consumer = self.sharedEditViewController;
+ editModalViewController.handler = self.sharedEditViewController;
- [self configureViewController];
- [self.baseViewController presentViewController:self.viewController
- animated:YES
- completion:nil];
+ modalMediator.editAddressConsumer = editModalViewController;
+ self.modalMediator = modalMediator;
+ self.modalViewController = editModalViewController;
+
+ [self configureViewController];
+ [self.baseViewController presentViewController:self.viewController
+ animated:YES
+ completion:nil];
+ }
}
#pragma mark - AutofillProfileEditMediatorDelegate
- (void)autofillEditProfileMediatorDidFinish:
(AutofillProfileEditMediator*)mediator {
+ CHECK(!base::FeatureList::IsEnabled(
+ kAutofillDynamicallyLoadsFieldsForAddressInput));
}
- (void)willSelectCountryWithCurrentlySelectedCountry:(NSString*)country
countryList:(NSArray<CountryItem*>*)
allCountries {
+ CHECK(!base::FeatureList::IsEnabled(
+ kAutofillDynamicallyLoadsFieldsForAddressInput));
AutofillCountrySelectionTableViewController*
autofillCountrySelectionTableViewController =
[[AutofillCountrySelectionTableViewController alloc]
@@ -150,14 +168,18 @@
}
- (void)didSaveProfile {
+ CHECK(!base::FeatureList::IsEnabled(
+ kAutofillDynamicallyLoadsFieldsForAddressInput));
[self.modalMediator saveEditedProfileWithProfileData:_autofillProfile.get()];
}
#pragma mark - AutofillCountrySelectionTableViewControllerDelegate
- (void)didSelectCountry:(CountryItem*)selectedCountry {
+ CHECK(!base::FeatureList::IsEnabled(
+ kAutofillDynamicallyLoadsFieldsForAddressInput));
[self.modalViewController.navigationController popViewControllerAnimated:YES];
- DCHECK(self.sharedEditViewMediator);
+ CHECK(self.sharedEditViewMediator);
[self.sharedEditViewMediator didSelectCountry:selectedCountry];
}