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 @@
#import "ios/chrome/browser/ui/autofill/manual_fill/fallback_coordinator.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/sys_string_conversions.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/autofill/ios/browser/autofill_driver_ios.h"
#include "components/keyed_service/core/service_access_type.h"
......@@ -77,8 +77,8 @@ initWithBaseViewController:(UIViewController*)viewController
- (void)stop {
[super stop];
if (![self dismissIfNecessaryThenDoCompletion:nil]) {
// TODO(crbug.com/845472): merge with password coordinator and explain why
// we remove from super view when we can't dismiss.
// dismissIfNecessaryThenDoCompletion dismisses, via the UIKit API, only
// for popovers (iPads). For iPhones we need to remove the view.
[self.viewController.view removeFromSuperview];
}
}
......@@ -87,6 +87,7 @@ initWithBaseViewController:(UIViewController*)viewController
- (void)popoverPresentationControllerDidDismissPopover:
(UIPopoverPresentationController*)popoverPresentationController {
base::RecordAction(base::UserMetricsAction("ManualFallback_ClosePopover"));
[self.delegate resetAccessoryView];
}
......
......@@ -5,9 +5,8 @@
#ifndef 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;
namespace manual_fill {
......@@ -17,10 +16,7 @@ extern NSString* const PasswordDoneButtonAccessibilityIdentifier;
} // namespace manual_fill
// Delegate for the coordinator actions.
@protocol PasswordCoordinatorDelegate<NSObject>
// Resets the accessory view.
- (void)resetAccessoryView;
@protocol PasswordCoordinatorDelegate<FallbackCoordinatorDelegate>
// Opens the passwords settings.
- (void)openPasswordSettings;
......@@ -30,12 +26,10 @@ extern NSString* const PasswordDoneButtonAccessibilityIdentifier;
// 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
// state.
@interface ManualFillPasswordCoordinator : ChromeCoordinator
// The view controller of this coordinator.
@property(nonatomic, readonly) UIViewController* viewController;
@interface ManualFillPasswordCoordinator : FallbackCoordinator
// 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;
// Creates a coordinator that uses a |viewController|, |browserState|,
......@@ -44,12 +38,15 @@ extern NSString* const PasswordDoneButtonAccessibilityIdentifier;
initWithBaseViewController:(UIViewController*)viewController
browserState:(ios::ChromeBrowserState*)browserState
webStateList:(WebStateList*)webStateList
injectionHandler:(ManualFillInjectionHandler*)injectionHandler;
injectionHandler:(ManualFillInjectionHandler*)injectionHandler
NS_DESIGNATED_INITIALIZER;
// Unavailable, use -initWithBaseViewController:browserState:webStateList:.
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browserState:
(ios::ChromeBrowserState*)browserState
// Unavailable, use
// -initWithBaseViewController:browserState:webStateList:injectionHandler:.
- (instancetype)
initWithBaseViewController:(UIViewController*)viewController
browserState:(ios::ChromeBrowserState*)browserState
injectionHandler:(ManualFillInjectionHandler*)injectionHandler
NS_UNAVAILABLE;
// Presents the password view controller as a popover from the passed button.
......
......@@ -4,7 +4,6 @@
#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/password_manager/core/browser/password_store.h"
#include "ios/chrome/browser/passwords/ios_chrome_password_store_factory.h"
......@@ -30,8 +29,7 @@ NSString* const PasswordDoneButtonAccessibilityIdentifier =
@interface ManualFillPasswordCoordinator ()<
PasswordListDelegate,
UIViewControllerTransitioningDelegate,
UIPopoverPresentationControllerDelegate>
UIViewControllerTransitioningDelegate>
// Fetches and filters the passwords for the view controller.
@property(nonatomic, strong) ManualFillPasswordMediator* passwordMediator;
......@@ -44,11 +42,6 @@ NSString* const PasswordDoneButtonAccessibilityIdentifier =
// passwords. Owned by the view controllers hierarchy.
@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
// dismissing any presented view controller. iPad only.
@property(nonatomic, weak) UIButton* presentingButton;
......@@ -57,10 +50,10 @@ NSString* const PasswordDoneButtonAccessibilityIdentifier =
@implementation ManualFillPasswordCoordinator
@synthesize allPasswordsViewController = _allPasswordsViewController;
@synthesize manualFillInjectionHandler = _manualFillInjectionHandler;
@synthesize passwordMediator = _passwordMediator;
@synthesize passwordViewController = _passwordViewController;
// Property tagged dynamic because it overrides super class delegate with and
// extension of the super delegate type (i.e. PasswordCoordinatorDelegate
// extends FallbackCoordinatorDelegate)
@dynamic delegate;
- (instancetype)
initWithBaseViewController:(UIViewController*)viewController
......@@ -68,12 +61,12 @@ initWithBaseViewController:(UIViewController*)viewController
webStateList:(WebStateList*)webStateList
injectionHandler:(ManualFillInjectionHandler*)injectionHandler {
self = [super initWithBaseViewController:viewController
browserState:browserState];
browserState:browserState
injectionHandler:injectionHandler];
if (self) {
_passwordViewController =
[[PasswordViewController alloc] initWithSearchController:nil];
_passwordViewController.contentInsetsAlwaysEqualToSafeArea = YES;
_manualFillInjectionHandler = injectionHandler;
auto passwordStore = IOSChromePasswordStoreFactory::GetForBrowserState(
browserState, ServiceAccessType::EXPLICIT_ACCESS);
......@@ -82,47 +75,20 @@ initWithBaseViewController:(UIViewController*)viewController
passwordStore:passwordStore];
_passwordMediator.consumer = _passwordViewController;
_passwordMediator.navigationDelegate = self;
_passwordMediator.contentDelegate = _manualFillInjectionHandler;
_passwordMediator.contentDelegate = injectionHandler;
}
return self;
}
- (void)stop {
if (IsIPadIdiom() && self.passwordViewController.presentingViewController) {
[self.passwordViewController dismissViewControllerAnimated:true
completion:nil];
} else {
[self.passwordViewController.view removeFromSuperview];
}
[super stop];
[self.allPasswordsViewController dismissViewControllerAnimated:YES
completion:nil];
}
- (UIViewController*)viewController {
return self.passwordViewController;
}
- (void)presentFromButton:(UIButton*)button {
[super presentFromButton: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
......@@ -171,6 +137,12 @@ animationControllerForDismissedController:(UIViewController*)dismissed {
return animator;
}
#pragma mark - FallbackCoordinator
- (UIViewController*)viewController {
return self.passwordViewController;
}
#pragma mark - PasswordListDelegate
- (void)openAllPasswordsList {
......@@ -226,24 +198,10 @@ animationControllerForDismissedController:(UIViewController*)dismissed {
}
- (void)openPasswordSettings {
// On iPad, dismiss the popover before the settings are presented.
if (IsIPadIdiom() && self.passwordViewController.presentingViewController) {
[self.passwordViewController
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];
__weak id<PasswordCoordinatorDelegate> delegate = self.delegate;
[self dismissIfNecessaryThenDoCompletion:^{
[delegate openPasswordSettings];
}];
}
@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