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

[iOS][Credential-Provider] Credential list

Adds the skeleton for the credential list. As this is going to be the
main view controller it has a Coordinator to control all the
presentations as well as the mediator and the associated protocols.

In follow ups CLs the view controller will add a table view controller
and a search bar. The mediator will fetch the passwords, filter and
provide recommendations based on the service identifiers, as well as
validate the log in state before providing passwords.

Bug: 1045454
Change-Id: I5f539c489629d04ebd11a79f49b8b420a24ef1d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2094310
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751524}
parent b8d75335
......@@ -4,9 +4,28 @@
#import "ios/chrome/credential_provider_extension/credential_provider_view_controller.h"
#import "ios/chrome/credential_provider_extension/ui/credential_list_coordinator.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface CredentialProviderViewController ()
// List coordinator that shows the list of passwords when started.
@property(nonatomic, strong) CredentialListCoordinator* listCoordinator;
@end
@implementation CredentialProviderViewController
- (void)prepareCredentialListForServiceIdentifiers:
(NSArray<ASCredentialServiceIdentifier*>*)serviceIdentifiers {
self.listCoordinator = [[CredentialListCoordinator alloc]
initWithBaseViewController:self
context:self.extensionContext
serviceIdentifiers:serviceIdentifiers];
[self.listCoordinator start];
}
@end
......@@ -6,15 +6,27 @@ source_set("ui") {
sources = [
"consent_view_controller.h",
"consent_view_controller.mm",
"credential_list_consumer.h",
"credential_list_coordinator.h",
"credential_list_coordinator.mm",
"credential_list_mediator.h",
"credential_list_mediator.mm",
"credential_list_ui_handler.h",
"credential_list_view_controller.h",
"credential_list_view_controller.mm",
"empty_credentials_view_controller.h",
"empty_credentials_view_controller.mm",
"stale_credentials_view_controller.h",
"stale_credentials_view_controller.mm",
]
deps = [
"//ios/chrome/common/ui/colors",
"//ios/chrome/common/ui/confirmation_alert",
"//ios/chrome/credential_provider_extension/ui/resources",
]
libs = [ "UIKit.framework" ]
libs = [
"UIKit.framework",
"AuthenticationServices.framework",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
// Copyright 2020 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_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_CONSUMER_H_
#define IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_CONSUMER_H_
@class UIButton;
@protocol CredentialListConsumerDelegate <NSObject>
// Called when the user taps the cancel button in the navigation bar.
- (void)navigationCancelButtonWasPressed:(UIButton*)button;
@end
@protocol CredentialListConsumer <NSObject>
// The delegate for the actions in the consumer.
@property(nonatomic, weak) id<CredentialListConsumerDelegate> delegate;
@end
#endif // IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_CONSUMER_H_
// Copyright 2020 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_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_COORDINATOR_H_
#define IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_COORDINATOR_H_
#import <Foundation/Foundation.h>
@class ASCredentialServiceIdentifier;
@class ASCredentialProviderExtensionContext;
@class UIViewController;
// This feature presents a list of credentials for the user to choose.
@interface CredentialListCoordinator : NSObject
// Default initializer. When the coordinator is started it will present on
// |baseViewController|. |serviceIdentifiers| will be used to prioritize data,
// can be nil.
- (instancetype)
initWithBaseViewController:(UIViewController*)baseViewController
context:(ASCredentialProviderExtensionContext*)context
serviceIdentifiers:
(NSArray<ASCredentialServiceIdentifier*>*)serviceIdentifiers
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
// Starts the credential list.
- (void)start;
// Stops the credential list.
- (void)stop;
@end
#endif // IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_COORDINATOR_H_
// Copyright 2020 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/credential_provider_extension/ui/credential_list_coordinator.h"
#import <AuthenticationServices/AuthenticationServices.h>
#import <UIKit/UIKit.h>
#import "ios/chrome/common/ui/confirmation_alert/confirmation_alert_action_handler.h"
#import "ios/chrome/credential_provider_extension/ui/credential_list_mediator.h"
#import "ios/chrome/credential_provider_extension/ui/credential_list_ui_handler.h"
#import "ios/chrome/credential_provider_extension/ui/credential_list_view_controller.h"
#import "ios/chrome/credential_provider_extension/ui/empty_credentials_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface CredentialListCoordinator () <CredentialListUIHandler,
ConfirmationAlertActionHandler>
// Base view controller from where |viewController| is presented.
@property(nonatomic, weak) UIViewController* baseViewController;
// The view controller of this coordinator.
@property(nonatomic, strong) UINavigationController* viewController;
// The mediator of this coordinator.
@property(nonatomic, strong) CredentialListMediator* mediator;
// The extension context in which the credential list was started.
@property(nonatomic, weak) ASCredentialProviderExtensionContext* context;
// The service identifiers to prioritize in a match is found.
@property(nonatomic, strong)
NSArray<ASCredentialServiceIdentifier*>* serviceIdentifiers;
@end
@implementation CredentialListCoordinator
- (instancetype)
initWithBaseViewController:(UIViewController*)baseViewController
context:(ASCredentialProviderExtensionContext*)context
serviceIdentifiers:
(NSArray<ASCredentialServiceIdentifier*>*)serviceIdentifiers {
self = [super init];
if (self) {
_baseViewController = baseViewController;
_context = context;
_serviceIdentifiers = serviceIdentifiers;
}
return self;
}
- (void)start {
CredentialListViewController* credentialListViewController =
[[CredentialListViewController alloc] init];
self.mediator = [[CredentialListMediator alloc]
initWithConsumer:credentialListViewController
UIHandler:self
context:self.context
serviceIdentifiers:self.serviceIdentifiers];
self.viewController = [[UINavigationController alloc]
initWithRootViewController:credentialListViewController];
self.viewController.modalPresentationStyle =
UIModalPresentationCurrentContext;
[self.baseViewController presentViewController:self.viewController
animated:NO
completion:nil];
[self.mediator fetchCredentials];
}
- (void)stop {
[self.viewController.presentingViewController
dismissViewControllerAnimated:NO
completion:nil];
self.viewController = nil;
self.mediator = nil;
}
#pragma mark - CredentialListUIHandler
- (void)showEmptyCredentials {
EmptyCredentialsViewController* emptyCredentialsViewController =
[[EmptyCredentialsViewController alloc] init];
emptyCredentialsViewController.modalPresentationStyle =
UIModalPresentationOverCurrentContext;
emptyCredentialsViewController.actionHandler = self;
[self.viewController.navigationController
presentViewController:emptyCredentialsViewController
animated:NO
completion:nil];
}
#pragma mark - ConfirmationAlertActionHandler
- (void)confirmationAlertDone {
// Finish the extension. There is no recovery from the empty credentials
// state.
NSError* error =
[[NSError alloc] initWithDomain:ASExtensionErrorDomain
code:ASExtensionErrorCodeUserCanceled
userInfo:nil];
[self.context cancelRequestWithError:error];
}
- (void)confirmationAlertPrimaryAction {
// No-op.
}
- (void)confirmationAlertLearnMoreAction {
// No-op.
}
@end
// Copyright 2020 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_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_MEDIATOR_H_
#define IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_MEDIATOR_H_
#import <Foundation/Foundation.h>
@class ASCredentialServiceIdentifier;
@class ASCredentialProviderExtensionContext;
@protocol CredentialListConsumer;
@protocol CredentialListUIHandler;
// This mediator fetches and organizes the credentials for its consumer.
@interface CredentialListMediator : NSObject
// |serviceIdentifiers| will be used to prioritize data, can be nil.
- (instancetype)initWithConsumer:(id<CredentialListConsumer>)consumer
UIHandler:(id<CredentialListUIHandler>)UIHandler
context:(ASCredentialProviderExtensionContext*)context
serviceIdentifiers:
(NSArray<ASCredentialServiceIdentifier*>*)serviceIdentifiers
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
// Gets the available credentials and posts them to the consumer.
- (void)fetchCredentials;
@end
#endif // IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_MEDIATOR_H_
// Copyright 2020 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/credential_provider_extension/ui/credential_list_mediator.h"
#import <AuthenticationServices/AuthenticationServices.h>
#import "ios/chrome/credential_provider_extension/ui/credential_list_consumer.h"
#import "ios/chrome/credential_provider_extension/ui/credential_list_ui_handler.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface CredentialListMediator () <CredentialListConsumerDelegate>
// The UI Handler of the feature.
@property(nonatomic, weak) id<CredentialListUIHandler> UIHandler;
// The consumer for this mediator.
@property(nonatomic, weak) id<CredentialListConsumer> consumer;
// The service identifiers to be prioritized.
@property(nonatomic, strong)
NSArray<ASCredentialServiceIdentifier*>* serviceIdentifiers;
// The extension context in which the credential list was started.
@property(nonatomic, weak) ASCredentialProviderExtensionContext* context;
@end
@implementation CredentialListMediator
- (instancetype)initWithConsumer:(id<CredentialListConsumer>)consumer
UIHandler:(id<CredentialListUIHandler>)UIHandler
context:(ASCredentialProviderExtensionContext*)context
serviceIdentifiers:
(NSArray<ASCredentialServiceIdentifier*>*)serviceIdentifiers {
self = [super init];
if (self) {
_serviceIdentifiers = serviceIdentifiers ?: @[];
_UIHandler = UIHandler;
_consumer = consumer;
_consumer.delegate = self;
_context = context;
}
return self;
}
- (void)fetchCredentials {
// TODO(crbug.com/1045454): Implement this method. For now present the empty
// credentials screen all the time.
[self.UIHandler showEmptyCredentials];
}
#pragma mark - CredentialListConsumer
- (void)navigationCancelButtonWasPressed:(UIButton*)button {
NSError* error =
[[NSError alloc] initWithDomain:ASExtensionErrorDomain
code:ASExtensionErrorCodeUserCanceled
userInfo:nil];
[self.context cancelRequestWithError:error];
}
@end
// Copyright 2020 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_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_UI_HANDLER_H_
#define IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_UI_HANDLER_H_
// Handler for presenting UI components for the credential list.
@protocol CredentialListUIHandler <NSObject>
// Asks the presenter to display the empty credentials view.
- (void)showEmptyCredentials;
@end
#endif // IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_UI_HANDLER_H_
// Copyright 2020 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_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_VIEW_CONTROLLER_H_
#define IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/credential_provider_extension/ui/credential_list_consumer.h"
@interface CredentialListViewController
: UIViewController <CredentialListConsumer>
@end
#endif // IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_LIST_VIEW_CONTROLLER_H_
// Copyright 2020 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/credential_provider_extension/ui/credential_list_view_controller.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// TODO(crbug.com/1045454): Implement this view controller.
@implementation CredentialListViewController
@synthesize delegate;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorNamed:kBackgroundColor];
self.navigationItem.rightBarButtonItem = [self navigationCancelButton];
}
#pragma mark - Private
// Creates a cancel button for the navigation item.
- (UIBarButtonItem*)navigationCancelButton {
UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self.delegate
action:@selector(navigationCancelButtonWasPressed:)];
return cancelButton;
}
@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