Commit d0131b2e authored by John Z Wu's avatar John Z Wu Committed by Commit Bot

Define CWVAutofillDataManagerDelegate.

This delegate will provide change notifications so the client knows
when data has changed.

Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: If9fd061ef1ecded33acf4847582d027435509f9a
Reviewed-on: https://chromium-review.googlesource.com/1064544
Commit-Queue: John Wu <jzw@chromium.org>
Reviewed-by: default avatarHiroshi Ichikawa <ichikawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#560751}
parent c89f0a2e
......@@ -77,6 +77,7 @@ if (ios_web_view_enable_autofill) {
"public/cwv_autofill_controller.h",
"public/cwv_autofill_controller_delegate.h",
"public/cwv_autofill_data_manager.h",
"public/cwv_autofill_data_manager_delegate.h",
"public/cwv_autofill_profile.h",
"public/cwv_autofill_suggestion.h",
"public/cwv_credit_card.h",
......
......@@ -4,27 +4,74 @@
#import "ios/web_view/internal/autofill/cwv_autofill_data_manager_internal.h"
#include <memory>
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/browser/personal_data_manager_observer.h"
#import "ios/web_view/internal/autofill/cwv_autofill_profile_internal.h"
#import "ios/web_view/internal/autofill/cwv_credit_card_internal.h"
#import "ios/web_view/public/cwv_autofill_data_manager_delegate.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface CWVAutofillDataManager ()
// Called when WebViewPersonalDataManagerObserverBridge's
// |OnPersonalDataChanged| is invoked.
- (void)personalDataDidChange;
@end
namespace ios_web_view {
// C++ to ObjC bridge for PersonalDataManagerObserver.
class WebViewPersonalDataManagerObserverBridge
: public autofill::PersonalDataManagerObserver {
public:
explicit WebViewPersonalDataManagerObserverBridge(
CWVAutofillDataManager* data_manager)
: data_manager_(data_manager){};
~WebViewPersonalDataManagerObserverBridge() override = default;
// autofill::PersonalDataManagerObserver implementation.
void OnPersonalDataChanged() override {
[data_manager_ personalDataDidChange];
}
void OnInsufficientFormData() override {
// Nop.
}
private:
__weak CWVAutofillDataManager* data_manager_;
};
} // namespace ios_web_view
@implementation CWVAutofillDataManager {
autofill::PersonalDataManager* _personalDataManager;
std::unique_ptr<ios_web_view::WebViewPersonalDataManagerObserverBridge>
_personalDataManagerObserverBridge;
}
@synthesize delegate = _delegate;
- (instancetype)initWithPersonalDataManager:
(autofill::PersonalDataManager*)personalDataManager {
self = [super init];
if (self) {
_personalDataManager = personalDataManager;
_personalDataManagerObserverBridge = std::make_unique<
ios_web_view::WebViewPersonalDataManagerObserverBridge>(self);
_personalDataManager->AddObserver(_personalDataManagerObserverBridge.get());
}
return self;
}
- (void)dealloc {
_personalDataManager->RemoveObserver(
_personalDataManagerObserverBridge.get());
}
#pragma mark - Public Methods
- (NSArray<CWVAutofillProfile*>*)profiles {
......@@ -65,4 +112,10 @@
_personalDataManager->RemoveByGUID(creditCard.internalCard->guid());
}
#pragma mark - Private Methods
- (void)personalDataDidChange {
[_delegate autofillDataManagerDataDidChange:self];
}
@end
......@@ -13,11 +13,15 @@ NS_ASSUME_NONNULL_BEGIN
@class CWVAutofillProfile;
@class CWVCreditCard;
@protocol CWVAutofillDataManagerDelegate;
CWV_EXPORT
// Exposes saved autofill data such as address profiles and credit cards.
@interface CWVAutofillDataManager : NSObject
// Delegate for CWVAutofillDataManagerDelegate.
@property(nonatomic, weak) id<CWVAutofillDataManagerDelegate> delegate;
// Returns all saved profiles for address autofill.
@property(nonatomic, readonly) NSArray<CWVAutofillProfile*>* profiles;
......
// 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_WEB_VIEW_PUBLIC_CWV_AUTOFILL_DATA_MANAGER_DELEGATE_H_
#define IOS_WEB_VIEW_PUBLIC_CWV_AUTOFILL_DATA_MANAGER_DELEGATE_H_
#import <Foundation/Foundation.h>
#import "cwv_export.h"
NS_ASSUME_NONNULL_BEGIN
@class CWVAutofillDataManager;
CWV_EXPORT
// Protocol to receive change notifications from CWVAutofillDataManager.
@protocol CWVAutofillDataManagerDelegate<NSObject>
// Called whenever CWVAutofillDataManager's autofill profiles or credit cards
// have been loaded for the first time, added, deleted, or updated.
- (void)autofillDataManagerDataDidChange:
(CWVAutofillDataManager*)autofillDataManager;
@end
NS_ASSUME_NONNULL_END
#endif // IOS_WEB_VIEW_PUBLIC_CWV_AUTOFILL_DATA_MANAGER_DELEGATE_H_
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