Commit ff7402f2 authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][MF] Hide and show autofill buttons

Hide card and address icons when no data is available. Show them again
if data becomes available.

Bug: 845472, 905650
Change-Id: If0420746b2df8fd3ebbbbd8dff6524eb326cef7c
Reviewed-on: https://chromium-review.googlesource.com/c/1335570
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608462}
parent b002b137
...@@ -4,13 +4,18 @@ ...@@ -4,13 +4,18 @@
#import "ios/chrome/browser/ui/autofill/form_input_accessory_coordinator.h" #import "ios/chrome/browser/ui/autofill/form_input_accessory_coordinator.h"
#include <vector>
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
#import "components/autofill/ios/browser/js_suggestion_manager.h" #import "components/autofill/ios/browser/js_suggestion_manager.h"
#import "components/autofill/ios/browser/personal_data_manager_observer_bridge.h"
#include "components/keyed_service/core/service_access_type.h" #include "components/keyed_service/core/service_access_type.h"
#include "components/password_manager/core/browser/password_store.h" #include "components/password_manager/core/browser/password_store.h"
#import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h"
#import "ios/chrome/browser/autofill/manual_fill/passwords_fetcher.h" #import "ios/chrome/browser/autofill/manual_fill/passwords_fetcher.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h" #include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h"
#import "ios/chrome/browser/ui/autofill/form_input_accessory_mediator.h" #import "ios/chrome/browser/ui/autofill/form_input_accessory_mediator.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/address_coordinator.h" #import "ios/chrome/browser/ui/autofill/manual_fill/address_coordinator.h"
...@@ -29,7 +34,15 @@ ...@@ -29,7 +34,15 @@
AddressCoordinatorDelegate, AddressCoordinatorDelegate,
CardCoordinatorDelegate, CardCoordinatorDelegate,
PasswordCoordinatorDelegate, PasswordCoordinatorDelegate,
PasswordFetcherDelegate> PasswordFetcherDelegate,
PersonalDataManagerObserver> {
// Personal data manager to be observed.
autofill::PersonalDataManager* _personalDataManager;
// C++ to ObjC bridge for PersonalDataManagerObserver.
std::unique_ptr<autofill::PersonalDataManagerObserverBridge>
_personalDataManagerObserver;
}
// The Mediator for the input accessory view controller. // The Mediator for the input accessory view controller.
@property(nonatomic, strong) @property(nonatomic, strong)
...@@ -97,10 +110,35 @@ ...@@ -97,10 +110,35 @@
[[PasswordFetcher alloc] initWithPasswordStore:passwordStore [[PasswordFetcher alloc] initWithPasswordStore:passwordStore
delegate:self]; delegate:self];
} }
autofill::PersonalDataManager* personalDataManager =
autofill::PersonalDataManagerFactory::GetForBrowserState(browserState);
// There is no personal data manager in OTR (incognito).
// TODO:(crbug.com/905720) Support Incognito.
if (personalDataManager) {
_personalDataManager = personalDataManager;
_personalDataManagerObserver.reset(
new autofill::PersonalDataManagerObserverBridge(self));
personalDataManager->AddObserver(_personalDataManagerObserver.get());
_manualFillAccessoryViewController.creditCardButtonHidden =
personalDataManager->GetCreditCardsToSuggest(true).empty();
_manualFillAccessoryViewController.creditCardButtonHidden =
personalDataManager->GetProfilesToSuggest().empty();
} else {
_manualFillAccessoryViewController.creditCardButtonHidden = YES;
_manualFillAccessoryViewController.addressButtonHidden = YES;
}
} }
return self; return self;
} }
- (void)dealloc {
if (_personalDataManager) {
_personalDataManager->RemoveObserver(_personalDataManagerObserver.get());
}
}
- (void)stop { - (void)stop {
[self stopChildren]; [self stopChildren];
[self.manualFillAccessoryViewController reset]; [self.manualFillAccessoryViewController reset];
...@@ -223,4 +261,19 @@ ...@@ -223,4 +261,19 @@
passwords.empty(); passwords.empty();
} }
#pragma mark - PersonalDataManagerObserver
- (void)onPersonalDataChanged {
autofill::PersonalDataManager* personalDataManager =
autofill::PersonalDataManagerFactory::GetForBrowserState(
self.browserState);
DCHECK(personalDataManager);
self.manualFillAccessoryViewController.creditCardButtonHidden =
personalDataManager->GetCreditCardsToSuggest(true).empty();
self.manualFillAccessoryViewController.addressButtonHidden =
personalDataManager->GetProfilesToSuggest().empty();
}
@end @end
...@@ -41,6 +41,14 @@ extern NSString* const AccessoryCreditCardAccessibilityIdentifier; ...@@ -41,6 +41,14 @@ extern NSString* const AccessoryCreditCardAccessibilityIdentifier;
// shown above the keyboard on iPhone and above the manual fill view. // shown above the keyboard on iPhone and above the manual fill view.
@interface ManualFillAccessoryViewController : UIViewController @interface ManualFillAccessoryViewController : UIViewController
// Changing this property hides and shows the address button.
@property(nonatomic, assign, getter=isAddressButtonHidden)
BOOL addressButtonHidden;
// Changing this property hides and shows the credit card button.
@property(nonatomic, assign, getter=isCreditCardButtonHidden)
BOOL creditCardButtonHidden;
// Changing this property hides and shows the password button. // Changing this property hides and shows the password button.
@property(nonatomic, assign, getter=isPasswordButtonHidden) @property(nonatomic, assign, getter=isPasswordButtonHidden)
BOOL passwordButtonHidden; BOOL passwordButtonHidden;
......
...@@ -81,6 +81,22 @@ static NSTimeInterval MFAnimationDuration = 0.20; ...@@ -81,6 +81,22 @@ static NSTimeInterval MFAnimationDuration = 0.20;
#pragma mark - Setters #pragma mark - Setters
- (void)setAddressButtonHidden:(BOOL)addressButtonHidden {
if (addressButtonHidden == _addressButtonHidden) {
return;
}
_accountButton.hidden = addressButtonHidden;
_addressButtonHidden = addressButtonHidden;
}
- (void)setCreditCardButtonHidden:(BOOL)creditCardButtonHidden {
if (creditCardButtonHidden == _creditCardButtonHidden) {
return;
}
_cardsButton.hidden = creditCardButtonHidden;
_creditCardButtonHidden = creditCardButtonHidden;
}
- (void)setPasswordButtonHidden:(BOOL)passwordButtonHidden { - (void)setPasswordButtonHidden:(BOOL)passwordButtonHidden {
if (passwordButtonHidden == _passwordButtonHidden) { if (passwordButtonHidden == _passwordButtonHidden) {
return; return;
...@@ -136,6 +152,7 @@ static NSTimeInterval MFAnimationDuration = 0.20; ...@@ -136,6 +152,7 @@ static NSTimeInterval MFAnimationDuration = 0.20;
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
self.cardsButton.accessibilityIdentifier = self.cardsButton.accessibilityIdentifier =
manual_fill::AccessoryCreditCardAccessibilityIdentifier; manual_fill::AccessoryCreditCardAccessibilityIdentifier;
self.cardsButton.hidden = self.isCreditCardButtonHidden;
[icons addObject:self.cardsButton]; [icons addObject:self.cardsButton];
self.accountButton = [UIButton buttonWithType:UIButtonTypeSystem]; self.accountButton = [UIButton buttonWithType:UIButtonTypeSystem];
...@@ -148,6 +165,7 @@ static NSTimeInterval MFAnimationDuration = 0.20; ...@@ -148,6 +165,7 @@ static NSTimeInterval MFAnimationDuration = 0.20;
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
self.accountButton.accessibilityIdentifier = self.accountButton.accessibilityIdentifier =
manual_fill::AccessoryAddressAccessibilityIdentifier; manual_fill::AccessoryAddressAccessibilityIdentifier;
self.accountButton.hidden = self.isAddressButtonHidden;
[icons addObject:self.accountButton]; [icons addObject:self.accountButton];
} }
UIStackView* stackView = [[UIStackView alloc] initWithArrangedSubviews:icons]; UIStackView* stackView = [[UIStackView alloc] initWithArrangedSubviews:icons];
......
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