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

[ios] Add helpers to manual fill to unlock credit cards

These helpers create a bridge between manual fill credit card and
payments' FullCardRequester to let user 'unlock' server side credit card
by entering correct cvc.

Bug: 845472
Change-Id: I9fcf013a0352673659d77291c03faa8aa31a9980
Reviewed-on: https://chromium-review.googlesource.com/c/1304413Reviewed-by: default avatarEric Noyau <noyau@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Commit-Queue: David Jean <djean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606382}
parent 715f3cda
......@@ -65,7 +65,6 @@ source_set("autofill") {
"//ios/chrome/browser/passwords:passwords_generation_utils",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/autofill/manual_fill",
"//ios/chrome/browser/ui/autofill/manual_fill:manual_fill_ui",
"//ios/chrome/browser/ui/image_util",
"//ios/web",
......
......@@ -116,6 +116,27 @@ source_set("unit_tests") {
]
}
source_set("requesters") {
sources = [
"full_card_request_result_delegate_bridge.h",
"full_card_request_result_delegate_bridge.mm",
"full_card_requester.h",
"full_card_requester.mm",
]
deps = [
"//base",
"//components/autofill/core/browser",
"//components/autofill/core/common",
"//components/autofill/ios/browser:browser",
"//ios/chrome/browser/ui/payments:requesters",
"//ios/chrome/browser/web_state_list:web_state_list",
"//ios/web/public:public",
"//ui/base:base",
]
libs = [ "UIKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
......
// 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_FULL_CARD_REQUEST_RESULT_DELEGATE_BRIDGE_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_FULL_CARD_REQUEST_RESULT_DELEGATE_BRIDGE_H_
#import <Foundation/Foundation.h>
#include <memory>
#include <vector>
#include "base/macros.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/payments/full_card_request.h"
// Obj-C delegate to receive the success or failure result, when asking credit
// card unlocking.
@protocol FullCardRequestResultDelegateObserving<NSObject>
// Called with unlocked credit card, when CVC input succeeded.
- (void)onFullCardRequestSucceeded:(const autofill::CreditCard&)card;
// Called when CVC input didn't succeeded, including when cancelled by user.
- (void)onFullCardRequestFailed;
@end
// Bridge between cpp payments::FullCardRequest::ResultDelegate and Obj-C
// ManualFillCardMediator.
class FullCardRequestResultDelegateBridge
: public autofill::payments::FullCardRequest::ResultDelegate {
public:
FullCardRequestResultDelegateBridge(
id<FullCardRequestResultDelegateObserving> delegate);
~FullCardRequestResultDelegateBridge() override;
base::WeakPtr<FullCardRequestResultDelegateBridge> GetWeakPtr();
private:
// payments::FullCardRequest::ResultDelegate:
void OnFullCardRequestSucceeded(
const autofill::payments::FullCardRequest& full_card_request,
const autofill::CreditCard& card,
const base::string16& cvc) override;
void OnFullCardRequestFailed() override;
__weak id<FullCardRequestResultDelegateObserving> delegate_ = nil;
base::WeakPtrFactory<FullCardRequestResultDelegateBridge> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(FullCardRequestResultDelegateBridge);
};
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_FULL_CARD_REQUEST_RESULT_DELEGATE_BRIDGE_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.
#include "ios/chrome/browser/ui/autofill/manual_fill/full_card_request_result_delegate_bridge.h"
#include "base/containers/adapters.h"
#include "base/strings/string16.h"
#include "components/autofill/core/browser/autofill_manager.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/form_structure.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
FullCardRequestResultDelegateBridge::FullCardRequestResultDelegateBridge(
id<FullCardRequestResultDelegateObserving> delegate)
: delegate_(delegate), weak_ptr_factory_(this) {}
FullCardRequestResultDelegateBridge::~FullCardRequestResultDelegateBridge() {}
base::WeakPtr<FullCardRequestResultDelegateBridge>
FullCardRequestResultDelegateBridge::GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
void FullCardRequestResultDelegateBridge::OnFullCardRequestSucceeded(
const autofill::payments::FullCardRequest& /* full_card_request */,
const autofill::CreditCard& card,
const base::string16& /* cvc */) {
[delegate_ onFullCardRequestSucceeded:card];
}
void FullCardRequestResultDelegateBridge::OnFullCardRequestFailed() {
[delegate_ onFullCardRequestFailed];
}
// 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_FULL_CARD_REQUESTER_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_FULL_CARD_REQUESTER_H_
#import <UIKit/UIKit.h>
#include "base/memory/ref_counted.h"
namespace autofill {
class CreditCard;
} // namespace autofill
namespace ios {
class ChromeBrowserState;
} // namespace ios
class WebStateList;
@protocol FullCardRequestResultDelegateObserving;
// Bridge between manual fill credit card and payments' FullCardRequester to
// let user 'unlock' server side credit card by input correct CVC.
@interface ManualFillFullCardRequester : NSObject
// Inits the requests with required parameters and the |delegate| to receive the
// success/failure state of the request.
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
webStateList:(WebStateList*)webStateList
resultDelegate:
(id<FullCardRequestResultDelegateObserving>)delegate;
// Executes the request, putting up a CVC input requester then unlocking a
// server side credit card if the CVC is correct. The delegate will receive the
// result of the operation.
- (void)requestFullCreditCard:(autofill::CreditCard)card
withBaseViewController:(UIViewController*)viewController;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_FULL_CARD_REQUESTER_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/full_card_requester.h"
#include <vector>
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/ios/browser/autofill_driver_ios.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/full_card_request_result_delegate_bridge.h"
#include "ios/chrome/browser/ui/payments/full_card_requester.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
namespace autofill {
class CreditCard;
} // namespace autofill
@interface ManualFillFullCardRequester ()
// The ios::ChromeBrowserState instance passed to the initializer.
@property(nonatomic, readonly) ios::ChromeBrowserState* browserState;
// The WebStateList for this instance. Used to instantiate the child
// coordinators lazily.
@property(nonatomic, readonly) WebStateList* webStateList;
@end
@implementation ManualFillFullCardRequester {
std::unique_ptr<FullCardRequester> _fullCardRequester;
// Obj-C delegate to receive the success or failure result, when
// asking credit card unlocking.
std::unique_ptr<FullCardRequestResultDelegateBridge> _cardAssistant;
}
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
webStateList:(WebStateList*)webStateList
resultDelegate:
(id<FullCardRequestResultDelegateObserving>)delegate {
self = [super init];
if (self) {
_browserState = browserState;
_webStateList = webStateList;
_cardAssistant =
std::make_unique<FullCardRequestResultDelegateBridge>(delegate);
}
return self;
}
- (void)requestFullCreditCard:(autofill::CreditCard)card
withBaseViewController:(UIViewController*)viewController {
// Payment Request is only enabled in main frame.
web::WebState* webState = self.webStateList->GetActiveWebState();
web::WebFrame* mainFrame = web::GetMainWebFrame(webState);
autofill::AutofillManager* autofillManager =
autofill::AutofillDriverIOS::FromWebStateAndWebFrame(webState, mainFrame)
->autofill_manager();
DCHECK(autofillManager);
_fullCardRequester =
std::make_unique<FullCardRequester>(viewController, self.browserState);
_fullCardRequester->GetFullCard(card, autofillManager,
_cardAssistant->GetWeakPtr());
// TODO(crbug.com/845472): closing CVC requester doesn't restore icon bar
// above keyboard.
}
@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