Commit 9d616e50 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] use coordinator base class for manual fill passwords

Bug: 845472
Change-Id: Ia214b22388823eee5baa82ffaeb0224981b63a12
Reviewed-on: https://chromium-review.googlesource.com/c/1337610Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Commit-Queue: David Jean <djean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609251}
parent 45fda935
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#import "ios/chrome/browser/ui/autofill/manual_fill/fallback_coordinator.h" #import "ios/chrome/browser/ui/autofill/manual_fill/fallback_coordinator.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/browser/personal_data_manager.h" #include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/ios/browser/autofill_driver_ios.h" #include "components/autofill/ios/browser/autofill_driver_ios.h"
#include "components/keyed_service/core/service_access_type.h" #include "components/keyed_service/core/service_access_type.h"
...@@ -77,8 +77,8 @@ initWithBaseViewController:(UIViewController*)viewController ...@@ -77,8 +77,8 @@ initWithBaseViewController:(UIViewController*)viewController
- (void)stop { - (void)stop {
[super stop]; [super stop];
if (![self dismissIfNecessaryThenDoCompletion:nil]) { if (![self dismissIfNecessaryThenDoCompletion:nil]) {
// TODO(crbug.com/845472): merge with password coordinator and explain why // dismissIfNecessaryThenDoCompletion dismisses, via the UIKit API, only
// we remove from super view when we can't dismiss. // for popovers (iPads). For iPhones we need to remove the view.
[self.viewController.view removeFromSuperview]; [self.viewController.view removeFromSuperview];
} }
} }
...@@ -87,6 +87,7 @@ initWithBaseViewController:(UIViewController*)viewController ...@@ -87,6 +87,7 @@ initWithBaseViewController:(UIViewController*)viewController
- (void)popoverPresentationControllerDidDismissPopover: - (void)popoverPresentationControllerDidDismissPopover:
(UIPopoverPresentationController*)popoverPresentationController { (UIPopoverPresentationController*)popoverPresentationController {
base::RecordAction(base::UserMetricsAction("ManualFallback_ClosePopover"));
[self.delegate resetAccessoryView]; [self.delegate resetAccessoryView];
} }
......
...@@ -5,9 +5,8 @@ ...@@ -5,9 +5,8 @@
#ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_PASSWORD_COORDINATOR_H_ #ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_PASSWORD_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_PASSWORD_COORDINATOR_H_ #define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_PASSWORD_COORDINATOR_H_
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h" #import "ios/chrome/browser/ui/autofill/manual_fill/fallback_coordinator.h"
@class ManualFillInjectionHandler;
class WebStateList; class WebStateList;
namespace manual_fill { namespace manual_fill {
...@@ -17,10 +16,7 @@ extern NSString* const PasswordDoneButtonAccessibilityIdentifier; ...@@ -17,10 +16,7 @@ extern NSString* const PasswordDoneButtonAccessibilityIdentifier;
} // namespace manual_fill } // namespace manual_fill
// Delegate for the coordinator actions. // Delegate for the coordinator actions.
@protocol PasswordCoordinatorDelegate<NSObject> @protocol PasswordCoordinatorDelegate<FallbackCoordinatorDelegate>
// Resets the accessory view.
- (void)resetAccessoryView;
// Opens the passwords settings. // Opens the passwords settings.
- (void)openPasswordSettings; - (void)openPasswordSettings;
...@@ -30,12 +26,10 @@ extern NSString* const PasswordDoneButtonAccessibilityIdentifier; ...@@ -30,12 +26,10 @@ extern NSString* const PasswordDoneButtonAccessibilityIdentifier;
// Creates and manages a view controller to present passwords to the user. // Creates and manages a view controller to present passwords to the user.
// Any selected password will be sent to the current field in the active web // Any selected password will be sent to the current field in the active web
// state. // state.
@interface ManualFillPasswordCoordinator : ChromeCoordinator @interface ManualFillPasswordCoordinator : FallbackCoordinator
// The view controller of this coordinator.
@property(nonatomic, readonly) UIViewController* viewController;
// The delegate for this coordinator. // The delegate for this coordinator. Delegate class extends
// FallbackCoordinatorDelegate, and replaces super class delegate.
@property(nonatomic, weak) id<PasswordCoordinatorDelegate> delegate; @property(nonatomic, weak) id<PasswordCoordinatorDelegate> delegate;
// Creates a coordinator that uses a |viewController|, |browserState|, // Creates a coordinator that uses a |viewController|, |browserState|,
...@@ -44,12 +38,15 @@ extern NSString* const PasswordDoneButtonAccessibilityIdentifier; ...@@ -44,12 +38,15 @@ extern NSString* const PasswordDoneButtonAccessibilityIdentifier;
initWithBaseViewController:(UIViewController*)viewController initWithBaseViewController:(UIViewController*)viewController
browserState:(ios::ChromeBrowserState*)browserState browserState:(ios::ChromeBrowserState*)browserState
webStateList:(WebStateList*)webStateList webStateList:(WebStateList*)webStateList
injectionHandler:(ManualFillInjectionHandler*)injectionHandler; injectionHandler:(ManualFillInjectionHandler*)injectionHandler
NS_DESIGNATED_INITIALIZER;
// Unavailable, use -initWithBaseViewController:browserState:webStateList:. // Unavailable, use
- (instancetype)initWithBaseViewController:(UIViewController*)viewController // -initWithBaseViewController:browserState:webStateList:injectionHandler:.
browserState: - (instancetype)
(ios::ChromeBrowserState*)browserState initWithBaseViewController:(UIViewController*)viewController
browserState:(ios::ChromeBrowserState*)browserState
injectionHandler:(ManualFillInjectionHandler*)injectionHandler
NS_UNAVAILABLE; NS_UNAVAILABLE;
// Presents the password view controller as a popover from the passed button. // Presents the password view controller as a popover from the passed button.
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#import "ios/chrome/browser/ui/autofill/manual_fill/password_coordinator.h" #import "ios/chrome/browser/ui/autofill/manual_fill/password_coordinator.h"
#include "base/metrics/user_metrics.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"
#include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h" #include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h"
...@@ -30,8 +29,7 @@ NSString* const PasswordDoneButtonAccessibilityIdentifier = ...@@ -30,8 +29,7 @@ NSString* const PasswordDoneButtonAccessibilityIdentifier =
@interface ManualFillPasswordCoordinator ()< @interface ManualFillPasswordCoordinator ()<
PasswordListDelegate, PasswordListDelegate,
UIViewControllerTransitioningDelegate, UIViewControllerTransitioningDelegate>
UIPopoverPresentationControllerDelegate>
// Fetches and filters the passwords for the view controller. // Fetches and filters the passwords for the view controller.
@property(nonatomic, strong) ManualFillPasswordMediator* passwordMediator; @property(nonatomic, strong) ManualFillPasswordMediator* passwordMediator;
...@@ -44,11 +42,6 @@ NSString* const PasswordDoneButtonAccessibilityIdentifier = ...@@ -44,11 +42,6 @@ NSString* const PasswordDoneButtonAccessibilityIdentifier =
// passwords. Owned by the view controllers hierarchy. // passwords. Owned by the view controllers hierarchy.
@property(nonatomic, weak) PasswordViewController* allPasswordsViewController; @property(nonatomic, weak) PasswordViewController* allPasswordsViewController;
// The object in charge of interacting with the web view. Used to fill the data
// in the forms.
@property(nonatomic, strong)
ManualFillInjectionHandler* manualFillInjectionHandler;
// Button presenting this coordinator in a popover. Used for continuation after // Button presenting this coordinator in a popover. Used for continuation after
// dismissing any presented view controller. iPad only. // dismissing any presented view controller. iPad only.
@property(nonatomic, weak) UIButton* presentingButton; @property(nonatomic, weak) UIButton* presentingButton;
...@@ -57,10 +50,10 @@ NSString* const PasswordDoneButtonAccessibilityIdentifier = ...@@ -57,10 +50,10 @@ NSString* const PasswordDoneButtonAccessibilityIdentifier =
@implementation ManualFillPasswordCoordinator @implementation ManualFillPasswordCoordinator
@synthesize allPasswordsViewController = _allPasswordsViewController; // Property tagged dynamic because it overrides super class delegate with and
@synthesize manualFillInjectionHandler = _manualFillInjectionHandler; // extension of the super delegate type (i.e. PasswordCoordinatorDelegate
@synthesize passwordMediator = _passwordMediator; // extends FallbackCoordinatorDelegate)
@synthesize passwordViewController = _passwordViewController; @dynamic delegate;
- (instancetype) - (instancetype)
initWithBaseViewController:(UIViewController*)viewController initWithBaseViewController:(UIViewController*)viewController
...@@ -68,12 +61,12 @@ initWithBaseViewController:(UIViewController*)viewController ...@@ -68,12 +61,12 @@ initWithBaseViewController:(UIViewController*)viewController
webStateList:(WebStateList*)webStateList webStateList:(WebStateList*)webStateList
injectionHandler:(ManualFillInjectionHandler*)injectionHandler { injectionHandler:(ManualFillInjectionHandler*)injectionHandler {
self = [super initWithBaseViewController:viewController self = [super initWithBaseViewController:viewController
browserState:browserState]; browserState:browserState
injectionHandler:injectionHandler];
if (self) { if (self) {
_passwordViewController = _passwordViewController =
[[PasswordViewController alloc] initWithSearchController:nil]; [[PasswordViewController alloc] initWithSearchController:nil];
_passwordViewController.contentInsetsAlwaysEqualToSafeArea = YES; _passwordViewController.contentInsetsAlwaysEqualToSafeArea = YES;
_manualFillInjectionHandler = injectionHandler;
auto passwordStore = IOSChromePasswordStoreFactory::GetForBrowserState( auto passwordStore = IOSChromePasswordStoreFactory::GetForBrowserState(
browserState, ServiceAccessType::EXPLICIT_ACCESS); browserState, ServiceAccessType::EXPLICIT_ACCESS);
...@@ -82,47 +75,20 @@ initWithBaseViewController:(UIViewController*)viewController ...@@ -82,47 +75,20 @@ initWithBaseViewController:(UIViewController*)viewController
passwordStore:passwordStore]; passwordStore:passwordStore];
_passwordMediator.consumer = _passwordViewController; _passwordMediator.consumer = _passwordViewController;
_passwordMediator.navigationDelegate = self; _passwordMediator.navigationDelegate = self;
_passwordMediator.contentDelegate = _manualFillInjectionHandler; _passwordMediator.contentDelegate = injectionHandler;
} }
return self; return self;
} }
- (void)stop { - (void)stop {
if (IsIPadIdiom() && self.passwordViewController.presentingViewController) { [super stop];
[self.passwordViewController dismissViewControllerAnimated:true
completion:nil];
} else {
[self.passwordViewController.view removeFromSuperview];
}
[self.allPasswordsViewController dismissViewControllerAnimated:YES [self.allPasswordsViewController dismissViewControllerAnimated:YES
completion:nil]; completion:nil];
} }
- (UIViewController*)viewController {
return self.passwordViewController;
}
- (void)presentFromButton:(UIButton*)button { - (void)presentFromButton:(UIButton*)button {
[super presentFromButton:button];
self.presentingButton = button; self.presentingButton = button;
self.passwordViewController.modalPresentationStyle =
UIModalPresentationPopover;
// The |button.window.rootViewController| is used in order to present above
// the keyboard. This way the popover will be dismissed on keyboard
// interaction and it won't be covered when the keyboard is near the top of
// the screen.
[button.window.rootViewController
presentViewController:self.passwordViewController
animated:YES
completion:nil];
UIPopoverPresentationController* popoverPresentationController =
self.passwordViewController.popoverPresentationController;
popoverPresentationController.sourceView = button;
popoverPresentationController.sourceRect = button.bounds;
popoverPresentationController.permittedArrowDirections =
UIPopoverArrowDirectionUp | UIMenuControllerArrowDown;
popoverPresentationController.delegate = self;
} }
#pragma mark - UIViewControllerTransitioningDelegate #pragma mark - UIViewControllerTransitioningDelegate
...@@ -171,6 +137,12 @@ animationControllerForDismissedController:(UIViewController*)dismissed { ...@@ -171,6 +137,12 @@ animationControllerForDismissedController:(UIViewController*)dismissed {
return animator; return animator;
} }
#pragma mark - FallbackCoordinator
- (UIViewController*)viewController {
return self.passwordViewController;
}
#pragma mark - PasswordListDelegate #pragma mark - PasswordListDelegate
- (void)openAllPasswordsList { - (void)openAllPasswordsList {
...@@ -226,24 +198,10 @@ animationControllerForDismissedController:(UIViewController*)dismissed { ...@@ -226,24 +198,10 @@ animationControllerForDismissedController:(UIViewController*)dismissed {
} }
- (void)openPasswordSettings { - (void)openPasswordSettings {
// On iPad, dismiss the popover before the settings are presented. __weak id<PasswordCoordinatorDelegate> delegate = self.delegate;
if (IsIPadIdiom() && self.passwordViewController.presentingViewController) { [self dismissIfNecessaryThenDoCompletion:^{
[self.passwordViewController [delegate openPasswordSettings];
dismissViewControllerAnimated:true }];
completion:^{
[self openPasswordSettings];
}];
return;
}
[self.delegate openPasswordSettings];
}
#pragma mark - UIPopoverPresentationControllerDelegate
- (void)popoverPresentationControllerDidDismissPopover:
(UIPopoverPresentationController*)popoverPresentationController {
base::RecordAction(base::UserMetricsAction("ManualFallback_ClosePopover"));
[self.delegate resetAccessoryView];
} }
@end @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