Commit 76401fe8 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] add manual fallback credit card mediator

Bug: 845472
Change-Id: Id8d909eb12468774b52b74e0684b6ab1e72ad1f2
Reviewed-on: https://chromium-review.googlesource.com/c/1318975
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606603}
parent 001618fc
......@@ -8,6 +8,8 @@ source_set("manual_fill") {
sources = [
"address_mediator.h",
"address_mediator.mm",
"card_mediator.h",
"card_mediator.mm",
"credential_password_form.h",
"credential_password_form.mm",
"form_observer_helper.h",
......@@ -20,6 +22,7 @@ source_set("manual_fill") {
"password_mediator.mm",
]
deps = [
":requesters",
"//base",
"//components/autofill/core/browser",
"//components/autofill/core/common",
......@@ -51,6 +54,7 @@ source_set("manual_fill_ui") {
"action_cell.mm",
"address_consumer.h",
"address_list_delegate.h",
"card_consumer.h",
"card_list_delegate.h",
"credential.h",
"credential.mm",
......
// 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_CONSUMER_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CARD_CONSUMER_H_
#import <Foundation/Foundation.h>
@class ManualFillActionItem;
@class ManualFillCardItem;
// Objects conforming to this protocol need to react when new data is available.
// TODO(crbug.com/845472): rename all class/file with 'Card' to 'CreditCard'.
@protocol ManualFillCardConsumer
// Tells the consumer to show the passed cards.
- (void)presentCards:(NSArray<ManualFillCardItem*>*)cards;
// Asks the consumer to present the passed actions
- (void)presentActions:(NSArray<ManualFillActionItem*>*)actions;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CARD_CONSUMER_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.
#ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CARD_MEDIATOR_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CARD_MEDIATOR_H_
#import <UIKit/UIKit.h>
#include "base/memory/ref_counted.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/full_card_request_result_delegate_bridge.h"
namespace autofill {
class CreditCard;
} // namespace autofill
@protocol ManualFillContentDelegate;
@protocol ManualFillCardConsumer;
@protocol CardListDelegate;
namespace manual_fill {
extern NSString* const ManageCardsAccessibilityIdentifier;
extern NSString* const OtherCardsAccessibilityIdentifier;
} // namespace manual_fill
// Object in charge of getting the cards relevant for the manual fill
// cards UI.
@interface ManualFillCardMediator
: NSObject<FullCardRequestResultDelegateObserving>
// The consumer for cards updates. Setting it will trigger the consumer
// methods with the current data.
@property(nonatomic, weak) id<ManualFillCardConsumer> consumer;
// The delegate in charge of using the content selected by the user.
@property(nonatomic, weak) id<ManualFillContentDelegate> contentDelegate;
// The delegate in charge of navigation.
@property(nonatomic, weak) id<CardListDelegate> navigationDelegate;
// The designated initializer. |cards| must not be nil.
- (instancetype)initWithCards:(std::vector<autofill::CreditCard*>)cards
NS_DESIGNATED_INITIALIZER;
// Unavailable. Use |initWithCards:|.
- (instancetype)init NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CARD_MEDIATOR_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_mediator.h"
#include <vector>
#include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/browser/autofill_manager.h"
#include "components/autofill/core/browser/credit_card.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/action_cell.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_consumer.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/card_list_delegate.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/full_card_request_result_delegate_bridge.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_card_cell.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_content_delegate.h"
#import "ios/chrome/browser/ui/list_model/list_model.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/web/public/web_state/web_state.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace autofill {
class CreditCard;
} // namespace autofill
namespace manual_fill {
NSString* const ManageCardsAccessibilityIdentifier =
@"kManualFillManageCardsAccessibilityIdentifier";
} // namespace manual_fill
@interface ManualFillCardMediator ()
// All available credit cards.
@property(nonatomic, assign) std::vector<autofill::CreditCard*> cards;
@end
@implementation ManualFillCardMediator
- (instancetype)initWithCards:(std::vector<autofill::CreditCard*>)cards {
self = [super init];
if (self) {
_cards = cards;
}
return self;
}
- (void)setConsumer:(id<ManualFillCardConsumer>)consumer {
if (consumer == _consumer) {
return;
}
_consumer = consumer;
[self postCardsToConsumer];
[self postActionsToConsumer];
}
#pragma mark - Private
// Posts the cards to the consumer.
- (void)postCardsToConsumer {
if (!self.consumer) {
return;
}
NSMutableArray* items =
[[NSMutableArray alloc] initWithCapacity:self.cards.size()];
for (autofill::CreditCard* card : self.cards) {
// TODO(crbug.com/845472): create a pure objc object instead.
auto item =
[[ManualFillCardItem alloc] initWithCreditCard:*card
contentDelegate:self.contentDelegate
navigationDelegate:self.navigationDelegate];
[items addObject:item];
}
[self.consumer presentCards:items];
}
- (void)postActionsToConsumer {
if (!self.consumer) {
return;
}
// TODO(crbug.com/845472): implement.
[self.consumer presentActions:@[]];
}
#pragma mark - FullCardRequestResultDelegateObserving
- (void)onFullCardRequestSucceeded:(const autofill::CreditCard&)card {
// Credit card are not shown as 'Secure'.
NSString* cardNumber =
base::SysUTF16ToNSString(autofill::CreditCard::StripSeparators(
card.GetRawInfo(autofill::CREDIT_CARD_NUMBER)));
// TODO(crbug.com/845472): update userDidPickContent to have an isHttps
// parameter.
[self.contentDelegate userDidPickContent:cardNumber isSecure:NO];
}
- (void)onFullCardRequestFailed {
// TODO(crbug.com/845472): handle failure to unlock card.
}
@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