Commit b02a7719 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] add manual fallback credit card and address coordinator

And a common base class.

Bug: 845472
Change-Id: I12999d306804227e605e270c9b4f14bd8ee6a2bb
Reviewed-on: https://chromium-review.googlesource.com/c/1318914Reviewed-by: default avatarEric Noyau <noyau@chromium.org>
Commit-Queue: David Jean <djean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606850}
parent 7149ab70
...@@ -6,12 +6,18 @@ import("//ios/web/js_compile.gni") ...@@ -6,12 +6,18 @@ import("//ios/web/js_compile.gni")
source_set("manual_fill") { source_set("manual_fill") {
sources = [ sources = [
"address_coordinator.h",
"address_coordinator.mm",
"address_mediator.h", "address_mediator.h",
"address_mediator.mm", "address_mediator.mm",
"card_coordinator.h",
"card_coordinator.mm",
"card_mediator.h", "card_mediator.h",
"card_mediator.mm", "card_mediator.mm",
"credential_password_form.h", "credential_password_form.h",
"credential_password_form.mm", "credential_password_form.mm",
"fallback_coordinator.h",
"fallback_coordinator.mm",
"form_observer_helper.h", "form_observer_helper.h",
"form_observer_helper.mm", "form_observer_helper.mm",
"manual_fill_injection_handler.h", "manual_fill_injection_handler.h",
...@@ -31,6 +37,7 @@ source_set("manual_fill") { ...@@ -31,6 +37,7 @@ source_set("manual_fill") {
"//components/keyed_service/core:core", "//components/keyed_service/core:core",
"//components/password_manager/core/browser", "//components/password_manager/core/browser",
"//ios/chrome/app/strings:ios_strings_grit", "//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/autofill",
"//ios/chrome/browser/autofill:autofill_shared", "//ios/chrome/browser/autofill:autofill_shared",
"//ios/chrome/browser/autofill/manual_fill:manual_fill", "//ios/chrome/browser/autofill/manual_fill:manual_fill",
"//ios/chrome/browser/passwords", "//ios/chrome/browser/passwords",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ADDRESS_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ADDRESS_COORDINATOR_H_
#import "ios/chrome/browser/ui/autofill/manual_fill/fallback_coordinator.h"
// Delegate for the coordinator actions.
// TODO(crbug.com/845472): revise delegate method names.
@protocol AddressCoordinatorDelegate<FallbackCoordinatorDelegate>
// Opens the address settings.
- (void)openAddressSettings;
@end
// Creates and manages a view controller to present addresses to the user.
// Any selected address field will be sent to the current field in the active
// web state.
@interface AddressCoordinator : FallbackCoordinator
// The delegate for this coordinator. Delegate class extends
// FallbackCoordinatorDelegate, and replaces super class delegate.
@property(nonatomic, weak) id<AddressCoordinatorDelegate> delegate;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ADDRESS_COORDINATOR_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/autofill/manual_fill/address_coordinator.h"
#include "base/memory/ref_counted.h"
#include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/ios/browser/autofill_driver_ios.h"
#include "components/keyed_service/core/service_access_type.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_list_delegate.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_mediator.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_view_controller.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_injection_handler.h"
#import "ios/chrome/browser/ui/table_view/table_view_navigation_controller.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface AddressCoordinator ()<AddressListDelegate>
// The view controller presented above the keyboard where the user can select
// a field from one of their addresses.
@property(nonatomic, strong) AddressViewController* addressViewController;
// Fetches and filters the addresses for the view controller.
@property(nonatomic, strong) ManualFillAddressMediator* addressMediator;
@end
@implementation AddressCoordinator
// Property tagged dynamic because it overrides super class delegate with and
// extension of the super delegate type (i.e. AddressCoordinatorDelegate extends
// FallbackCoordinatorDelegate)
@dynamic delegate;
- (instancetype)
initWithBaseViewController:(UIViewController*)viewController
browserState:(ios::ChromeBrowserState*)browserState
injectionHandler:(ManualFillInjectionHandler*)injectionHandler {
self = [super initWithBaseViewController:viewController
browserState:browserState
injectionHandler:injectionHandler];
if (self) {
_addressViewController = [[AddressViewController alloc] init];
_addressViewController.contentInsetsAlwaysEqualToSafeArea = YES;
autofill::PersonalDataManager* personalDataManager =
autofill::PersonalDataManagerFactory::GetForBrowserState(browserState);
std::vector<autofill::AutofillProfile*> profiles =
personalDataManager->GetProfilesToSuggest();
_addressMediator =
[[ManualFillAddressMediator alloc] initWithProfiles:profiles];
_addressMediator.contentDelegate = self.manualFillInjectionHandler;
_addressMediator.consumer = _addressViewController;
}
return self;
}
#pragma mark - FallbackCoordinator
- (UIViewController*)viewController {
return self.addressViewController;
}
#pragma mark - AddressListDelegate
- (void)openAddressSettings {
__weak id<AddressCoordinatorDelegate> delegate = self.delegate;
[self dismissIfNecessaryThenDoCompletion:^{
[delegate openAddressSettings];
}];
}
@end
...@@ -8,10 +8,6 @@ ...@@ -8,10 +8,6 @@
// Delegate for actions in manual fallback's addresses list. // Delegate for actions in manual fallback's addresses list.
@protocol AddressListDelegate @protocol AddressListDelegate
// Dismisses the presented view controller and continues as pop over on iPads
// or above the keyboard elsewhere.
- (void)dismissPresentedViewController;
// Opens addresses settings. // Opens addresses settings.
- (void)openAddressSettings; - (void)openAddressSettings;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CARD_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CARD_COORDINATOR_H_
#import "ios/chrome/browser/ui/autofill/manual_fill/fallback_coordinator.h"
class WebStateList;
// Delegate for the coordinator actions.
// TODO(crbug.com/845472): revise delegate method names.
@protocol CardCoordinatorDelegate<FallbackCoordinatorDelegate>
// Opens the cards settings.
- (void)openCardSettings;
@end
// Creates and manages a view controller to present cards to the user.
// Any selected card will be sent to the current field in the active web
// state.
@interface CardCoordinator : FallbackCoordinator
// The delegate for this coordinator. Delegate class extends
// FallbackCoordinatorDelegate, and replaces super class delegate.
@property(nonatomic, weak) id<CardCoordinatorDelegate> delegate;
// Creates a coordinator that uses a |viewController|, |browserState|,
// |webStateList| and |injectionHandler|.
- (instancetype)
initWithBaseViewController:(UIViewController*)viewController
browserState:(ios::ChromeBrowserState*)browserState
webStateList:(WebStateList*)webStateList
injectionHandler:(ManualFillInjectionHandler*)injectionHandler
NS_DESIGNATED_INITIALIZER;
- (instancetype)
initWithBaseViewController:(UIViewController*)viewController
browserState:(ios::ChromeBrowserState*)browserState
injectionHandler:(ManualFillInjectionHandler*)injectionHandler
NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CARD_COORDINATOR_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/autofill/manual_fill/card_coordinator.h"
#include "base/memory/ref_counted.h"
#include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/ios/browser/autofill_driver_ios.h"
#include "components/keyed_service/core/service_access_type.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_list_delegate.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_mediator.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_view_controller.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/full_card_requester.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_injection_handler.h"
#import "ios/chrome/browser/ui/table_view/table_view_navigation_controller.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
#include "ios/web/public/web_state/web_frame.h"
#include "ios/web/public/web_state/web_frame_util.h"
#import "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface CardCoordinator ()<CardListDelegate>
// The view controller presented above the keyboard where the user can select
// one of their cards.
@property(nonatomic, strong) CardViewController* cardViewController;
// Fetches and filters the cards for the view controller.
@property(nonatomic, strong) ManualFillCardMediator* cardMediator;
// Requesters to unlock (through user CVC input) of server side credit cards.
@property(nonatomic, strong) ManualFillFullCardRequester* cardRequester;
@end
@implementation CardCoordinator
// Property tagged dynamic because it overrides super class delegate with and
// extension of the super delegate type (i.e. CardCoordinatorDelegate extends
// FallbackCoordinatorDelegate)
@dynamic delegate;
- (instancetype)
initWithBaseViewController:(UIViewController*)viewController
browserState:(ios::ChromeBrowserState*)browserState
webStateList:(WebStateList*)webStateList
injectionHandler:(ManualFillInjectionHandler*)injectionHandler {
self = [super initWithBaseViewController:viewController
browserState:browserState
injectionHandler:injectionHandler];
if (self) {
_cardViewController = [[CardViewController alloc] init];
_cardViewController.contentInsetsAlwaysEqualToSafeArea = YES;
autofill::PersonalDataManager* personalDataManager =
autofill::PersonalDataManagerFactory::GetForBrowserState(browserState);
std::vector<autofill::CreditCard*> cards =
personalDataManager->GetCreditCardsToSuggest(true);
_cardMediator = [[ManualFillCardMediator alloc] initWithCards:cards];
_cardMediator.navigationDelegate = self;
_cardMediator.contentDelegate = self.manualFillInjectionHandler;
_cardMediator.consumer = _cardViewController;
_cardRequester = [[ManualFillFullCardRequester alloc]
initWithBrowserState:browserState
webStateList:webStateList
resultDelegate:_cardMediator];
}
return self;
}
#pragma mark - FallbackCoordinator
- (UIViewController*)viewController {
return self.cardViewController;
}
#pragma mark - CardListDelegate
- (void)openCardSettings {
__weak id<CardCoordinatorDelegate> delegate = self.delegate;
[self dismissIfNecessaryThenDoCompletion:^{
[delegate openCardSettings];
}];
}
- (void)requestFullCreditCard:(const autofill::CreditCard&)card {
__weak __typeof(self) weakSelf = self;
// TODO(crbug.com/845472): resolve potential weak card here either using
// std::unique or an Obj-C Creditcard object as proposed in another TODO.
autofill::CreditCard cardCopy = card;
[self dismissIfNecessaryThenDoCompletion:^{
[weakSelf.cardRequester requestFullCreditCard:cardCopy
withBaseViewController:weakSelf.baseViewController];
}];
}
@end
...@@ -12,10 +12,6 @@ class CreditCard; ...@@ -12,10 +12,6 @@ class CreditCard;
// Delegate for actions in manual fallback's cards list. // Delegate for actions in manual fallback's cards list.
@protocol CardListDelegate @protocol CardListDelegate
// Dismisses the presented view controller and continues as pop over on iPads
// or above the keyboard elsewhere.
- (void)dismissPresentedViewController;
// Opens cards settings. // Opens cards settings.
- (void)openCardSettings; - (void)openCardSettings;
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_FALLBACK_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_FALLBACK_COORDINATOR_H_
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
@class ManualFillInjectionHandler;
@class ChromeTableViewController;
// Delegate for the coordinator actions.
@protocol FallbackCoordinatorDelegate<NSObject>
// Resets the accessory view.
- (void)resetAccessoryView;
@end
// Creates and manages a view controller to present some fallbacks (passwords,
// cards or addresses) to the user. Any selected fallback item will be sent to
// the current field in the active web state.
@interface FallbackCoordinator : ChromeCoordinator
// The view controller of this coordinator.
@property(nonatomic, readonly) UIViewController* viewController;
// The delegate for this coordinator.
@property(nonatomic, weak) id<FallbackCoordinatorDelegate> delegate;
// The object in charge of interacting with the web view. Used to fill the data
// in the forms.
@property(nonatomic, strong)
ManualFillInjectionHandler* manualFillInjectionHandler;
// Creates a coordinator that uses a |viewController|, |browserState| and an
// |injectionHandler|.
- (instancetype)
initWithBaseViewController:(UIViewController*)viewController
browserState:(ios::ChromeBrowserState*)browserState
injectionHandler:(ManualFillInjectionHandler*)injectionHandler
NS_DESIGNATED_INITIALIZER;
// Unavailable, use -initWithBaseViewController:browserState:injectionHandler:.
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browserState:
(ios::ChromeBrowserState*)browserState
NS_UNAVAILABLE;
// Presents the view controller as a popover from the passed button.
- (void)presentFromButton:(UIButton*)button;
// Dismisses the view controller, if needed, and according to the platform. It
// then calls the completer either way. Returns true if dismissing was
// necessary.
- (BOOL)dismissIfNecessaryThenDoCompletion:(void (^)(void))completion;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_FALLBACK_COORDINATOR_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/autofill/manual_fill/fallback_coordinator.h"
#include "base/memory/ref_counted.h"
#include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/ios/browser/autofill_driver_ios.h"
#include "components/keyed_service/core/service_access_type.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_injection_handler.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
#import "ios/chrome/browser/ui/table_view/table_view_navigation_controller.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface FallbackCoordinator ()<UIPopoverPresentationControllerDelegate>
@end
@implementation FallbackCoordinator
- (instancetype)
initWithBaseViewController:(UIViewController*)viewController
browserState:(ios::ChromeBrowserState*)browserState
injectionHandler:(ManualFillInjectionHandler*)injectionHandler {
self = [super initWithBaseViewController:viewController
browserState:browserState];
if (self) {
_manualFillInjectionHandler = injectionHandler;
}
return self;
}
- (BOOL)dismissIfNecessaryThenDoCompletion:(void (^)(void))completion {
// On iPad, dismiss the popover before the settings are presented.
if (IsIPadIdiom() && self.viewController.presentingViewController) {
[self.viewController dismissViewControllerAnimated:true
completion:completion];
return YES;
} else {
completion();
return NO;
}
}
- (void)presentFromButton:(UIButton*)button {
self.viewController.modalPresentationStyle = UIModalPresentationPopover;
// The |button.window.rootViewController| is used in order to present above
// the keyboard. This way the popover will be dismissed on keyboard
// interaction and it won't be covered when the keyboard is near the top of
// the screen.
[button.window.rootViewController presentViewController:self.viewController
animated:YES
completion:nil];
UIPopoverPresentationController* popoverPresentationController =
self.viewController.popoverPresentationController;
popoverPresentationController.sourceView = button;
popoverPresentationController.sourceRect = button.bounds;
popoverPresentationController.permittedArrowDirections =
UIPopoverArrowDirectionUp | UIMenuControllerArrowDown;
popoverPresentationController.delegate = self;
}
#pragma mark - ChromeCoordinator
- (void)stop {
[super stop];
if (![self dismissIfNecessaryThenDoCompletion:nil]) {
// TODO(crbug.com/845472): merge with password coordinator and explain why
// we remove from super view when we can't dismiss.
[self.viewController.view removeFromSuperview];
}
}
#pragma mark - UIPopoverPresentationControllerDelegate
- (void)popoverPresentationControllerDidDismissPopover:
(UIPopoverPresentationController*)popoverPresentationController {
[self.delegate resetAccessoryView];
}
@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