Commit 97418a9f authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] add manual fallback address mediator

Bug: 845472
Change-Id: I6ba687245c8493d21bc305c1f530146ef97e59aa
Reviewed-on: https://chromium-review.googlesource.com/c/1318972
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606533}
parent a9142d46
......@@ -6,6 +6,8 @@ import("//ios/web/js_compile.gni")
source_set("manual_fill") {
sources = [
"address_mediator.h",
"address_mediator.mm",
"credential_password_form.h",
"credential_password_form.mm",
"form_observer_helper.h",
......@@ -19,6 +21,7 @@ source_set("manual_fill") {
]
deps = [
"//base",
"//components/autofill/core/browser",
"//components/autofill/core/common",
"//components/autofill/ios/browser",
"//components/autofill/ios/form_util",
......@@ -46,6 +49,7 @@ source_set("manual_fill_ui") {
sources = [
"action_cell.h",
"action_cell.mm",
"address_consumer.h",
"address_list_delegate.h",
"card_list_delegate.h",
"credential.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_ADDRESS_CONSUMER_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ADDRESS_CONSUMER_H_
#import <Foundation/Foundation.h>
@class ManualFillActionItem;
@class ManualFillAddressItem;
// Objects conforming to this protocol need to react when new data is available.
@protocol ManualFillAddressConsumer
// Tells the consumer to show the passed addreses.
- (void)presentAddresses:(NSArray<ManualFillAddressItem*>*)addresses;
// Asks the consumer to present the passed actions
- (void)presentActions:(NSArray<ManualFillActionItem*>*)actions;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ADDRESS_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_ADDRESS_MEDIATOR_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ADDRESS_MEDIATOR_H_
#import <UIKit/UIKit.h>
#include <memory>
namespace autofill {
class AutofillProfile;
} // namespace autofill
@protocol ManualFillContentDelegate;
@protocol ManualFillAddressConsumer;
@protocol AddressListDelegate;
namespace manual_fill {
extern NSString* const ManageAddressAccessibilityIdentifier;
} // namespace manual_fill
// Object in charge of getting the addresses relevant for the manual fill UI.
@interface ManualFillAddressMediator : NSObject
// The consumer for addresses updates. Setting it will trigger the consumer
// methods with the current data.
@property(nonatomic, weak) id<ManualFillAddressConsumer> consumer;
// The delegate in charge of using the content selected by the user.
@property(nonatomic, weak) id<ManualFillContentDelegate> contentDelegate;
// The designated initializer.
- (instancetype)initWithProfiles:
(std::vector<autofill::AutofillProfile*>)profiles NS_DESIGNATED_INITIALIZER;
// Unavailable. Use |initWithProfiles:|.
- (instancetype)init NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ADDRESS_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/address_mediator.h"
#include <vector>
#include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/browser/autofill_manager.h"
#include "components/autofill/core/browser/autofill_profile.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/action_cell.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_consumer.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_list_delegate.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/manual_fill_address_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 manual_fill {
NSString* const ManageAddressAccessibilityIdentifier =
@"kManualFillManageAddressAccessibilityIdentifier";
} // namespace manual_fill
@interface ManualFillAddressMediator ()
// All available addresses.
@property(nonatomic, assign) std::vector<autofill::AutofillProfile*> profiles;
@end
@implementation ManualFillAddressMediator
- (instancetype)initWithProfiles:
(std::vector<autofill::AutofillProfile*>)profiles {
self = [super init];
if (self) {
_profiles = profiles;
}
return self;
}
- (void)setConsumer:(id<ManualFillAddressConsumer>)consumer {
if (consumer == _consumer) {
return;
}
_consumer = consumer;
[self postAddressesToConsumer];
[self postActionsToConsumer];
}
#pragma mark - Private
// Posts the addresses to the consumer.
- (void)postAddressesToConsumer {
if (!self.consumer) {
return;
}
NSMutableArray* items =
[[NSMutableArray alloc] initWithCapacity:self.profiles.size()];
for (autofill::AutofillProfile* profile : self.profiles) {
auto item = [[ManualFillAddressItem alloc]
initWithAutofillProfile:*profile
delegate:self.contentDelegate];
[items addObject:item];
}
[self.consumer presentAddresses:items];
}
- (void)postActionsToConsumer {
if (!self.consumer) {
return;
}
// TODO(crbug.com/845472): implement.
[self.consumer presentActions:@[]];
}
@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