Commit 23afbd28 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] Add skeleton for cpe credential details vc

Bug: 1052143
Change-Id: I1838e127921240e6052c4f2370ea4e0e46ae3d51
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2137389
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756987}
parent f17c5e6f
...@@ -6,6 +6,9 @@ source_set("ui") { ...@@ -6,6 +6,9 @@ source_set("ui") {
sources = [ sources = [
"consent_view_controller.h", "consent_view_controller.h",
"consent_view_controller.mm", "consent_view_controller.mm",
"credential_details_consumer.h",
"credential_details_view_controller.h",
"credential_details_view_controller.mm",
"credential_list_consumer.h", "credential_list_consumer.h",
"credential_list_coordinator.h", "credential_list_coordinator.h",
"credential_list_coordinator.mm", "credential_list_coordinator.mm",
......
// 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_DETAILS_CONSUMER_H_
#define IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_DETAILS_CONSUMER_H_
#include "ios/chrome/common/credential_provider/credential.h"
@class UIButton;
@protocol CredentialDetailsConsumerDelegate <NSObject>
// Called when the user taps the cancel button in the navigation bar.
- (void)navigationCancelButtonWasPressed:(UIButton*)button;
// Called when the user requests a clear view of the password. The delegate
// should complete with the clear password or nil in case of failure or
// deny by user.
- (void)unlockPasswordForCredential:(id<Credential>)credential
completionHandler:(void (^)(NSString*))completionHandler;
@end
@protocol CredentialDetailsConsumer <NSObject>
// The delegate for the actions in the consumer.
@property(nonatomic, weak) id<CredentialDetailsConsumerDelegate> delegate;
// Tells the consumer to show the |credential| details.
- (void)presentCredential:(id<Credential>)credential;
@end
#endif // IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_DETAILS_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_DETAILS_VIEW_CONTROLLER_H_
#define IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_DETAILS_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/credential_provider_extension/ui/credential_details_consumer.h"
// View controller for credential details. Similar to chrome settings password
// details (i/c/b/u/s/p/password_details_table_view_controller).
@interface CredentialDetailsViewController
: UITableViewController <CredentialDetailsConsumer>
@end
#endif // IOS_CHROME_CREDENTIAL_PROVIDER_EXTENSION_UI_CREDENTIAL_DETAILS_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_details_view_controller.h"
#import "base/mac/foundation_util.h"
#import "ios/chrome/common/credential_provider/credential.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
@interface CredentialDetailsViewController () <UITableViewDataSource>
// Current credential.
@property(nonatomic, weak) id<Credential> credential;
@end
@implementation CredentialDetailsViewController
@synthesize delegate;
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorNamed:kBackgroundColor];
self.navigationItem.rightBarButtonItem = [self navigationCancelButton];
}
#pragma mark - CredentialDetailsConsumer
- (void)presentCredential:(id<Credential>)credential {
self.credential = credential;
[self.tableView reloadData];
}
#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
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
// Called when the user is filtering results through search. // Called when the user is filtering results through search.
- (void)updateResultsWithFilter:(NSString*)filter; - (void)updateResultsWithFilter:(NSString*)filter;
// Called when user wants to see details for the given credential.
- (void)showDetailsForCredential:(id<Credential>)credential;
@end @end
@protocol CredentialListConsumer <NSObject> @protocol CredentialListConsumer <NSObject>
......
...@@ -68,4 +68,8 @@ ...@@ -68,4 +68,8 @@
// TODO(crbug.com/1045454): Implement this method. // TODO(crbug.com/1045454): Implement this method.
} }
- (void)showDetailsForCredential:(id<Credential>)credential {
// TODO(crbug.com/1052143): Implement this method.
}
@end @end
...@@ -156,13 +156,8 @@ UIImage* GetFallbackImageWithStringAndColor(NSString* string) { ...@@ -156,13 +156,8 @@ UIImage* GetFallbackImageWithStringAndColor(NSString* string) {
reuseIdentifier:kCellIdentifier]; reuseIdentifier:kCellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDetailButton; cell.accessoryType = UITableViewCellAccessoryDetailButton;
} }
id<Credential> credential;
if ([self isSuggestedPasswordSection:indexPath.section]) {
credential = self.suggestedPasswords[indexPath.row];
} else {
credential = self.allPasswords[indexPath.row];
}
id<Credential> credential = [self credentialForIndexPath:indexPath];
cell.imageView.image = GetFallbackImageWithStringAndColor(credential.user); cell.imageView.image = GetFallbackImageWithStringAndColor(credential.user);
cell.imageView.contentMode = UIViewContentModeScaleAspectFit; cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
cell.textLabel.text = credential.user; cell.textLabel.text = credential.user;
...@@ -184,6 +179,12 @@ UIImage* GetFallbackImageWithStringAndColor(NSString* string) { ...@@ -184,6 +179,12 @@ UIImage* GetFallbackImageWithStringAndColor(NSString* string) {
return view; return view;
} }
- (void)tableView:(UITableView*)tableView
accessoryButtonTappedForRowWithIndexPath:(NSIndexPath*)indexPath {
id<Credential> credential = [self credentialForIndexPath:indexPath];
[self.delegate showDetailsForCredential:credential];
}
#pragma mark - UISearchResultsUpdating #pragma mark - UISearchResultsUpdating
- (void)updateSearchResultsForSearchController: - (void)updateSearchResultsForSearchController:
...@@ -227,4 +228,12 @@ UIImage* GetFallbackImageWithStringAndColor(NSString* string) { ...@@ -227,4 +228,12 @@ UIImage* GetFallbackImageWithStringAndColor(NSString* string) {
} }
} }
- (id<Credential>)credentialForIndexPath:(NSIndexPath*)indexPath {
if ([self isSuggestedPasswordSection:indexPath.section]) {
return self.suggestedPasswords[indexPath.row];
} else {
return self.allPasswords[indexPath.row];
}
}
@end @end
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/common/credential_provider/credential.h" #import "ios/chrome/common/credential_provider/credential.h"
#import "ios/chrome/credential_provider_extension/ui/credential_details_consumer.h"
#import "ios/chrome/credential_provider_extension/ui/credential_details_view_controller.h"
#import "ios/chrome/credential_provider_extension/ui/credential_list_consumer.h" #import "ios/chrome/credential_provider_extension/ui/credential_list_consumer.h"
#import "ios/chrome/credential_provider_extension/ui/credential_list_view_controller.h" #import "ios/chrome/credential_provider_extension/ui/credential_list_view_controller.h"
...@@ -56,8 +58,11 @@ NSArray<id<Credential>>* allPasswords = @[ ...@@ -56,8 +58,11 @@ NSArray<id<Credential>>* allPasswords = @[
]; ];
} }
@interface SCCredentialListCoordinator () <CredentialListConsumerDelegate> @interface SCCredentialListCoordinator () <CredentialDetailsConsumerDelegate,
CredentialListConsumerDelegate>
@property(nonatomic, strong) CredentialListViewController* viewController; @property(nonatomic, strong) CredentialListViewController* viewController;
@property(nonatomic, strong)
CredentialDetailsViewController* detailsViewController;
@end @end
@implementation SCCredentialListCoordinator @implementation SCCredentialListCoordinator
...@@ -66,11 +71,15 @@ NSArray<id<Credential>>* allPasswords = @[ ...@@ -66,11 +71,15 @@ NSArray<id<Credential>>* allPasswords = @[
- (void)start { - (void)start {
self.viewController = [[CredentialListViewController alloc] init]; self.viewController = [[CredentialListViewController alloc] init];
self.viewController.title = @"Autofill Chrome Password"; self.viewController.title = @"CPE Passwords";
self.viewController.delegate = self; self.viewController.delegate = self;
[self.baseViewController setHidesBarsOnSwipe:NO]; [self.baseViewController setHidesBarsOnSwipe:NO];
[self.baseViewController pushViewController:self.viewController animated:YES]; [self.baseViewController pushViewController:self.viewController animated:YES];
self.detailsViewController = [[CredentialDetailsViewController alloc] init];
self.detailsViewController.title = @"CPE Password Details";
self.detailsViewController.delegate = self;
[self.viewController presentSuggestedPasswords:suggestedPasswords [self.viewController presentSuggestedPasswords:suggestedPasswords
allPasswords:allPasswords]; allPasswords:allPasswords];
} }
...@@ -101,4 +110,17 @@ NSArray<id<Credential>>* allPasswords = @[ ...@@ -101,4 +110,17 @@ NSArray<id<Credential>>* allPasswords = @[
[self.viewController presentSuggestedPasswords:suggested allPasswords:all]; [self.viewController presentSuggestedPasswords:suggested allPasswords:all];
} }
#pragma mark - CredentialDetailsConsumerDelegate
- (void)unlockPasswordForCredential:(id<Credential>)credential
completionHandler:(void (^)(NSString*))completionHandler {
completionHandler(@"DreamOn");
}
- (void)showDetailsForCredential:(id<Credential>)credential {
[self.detailsViewController presentCredential:credential];
[self.baseViewController pushViewController:self.detailsViewController
animated:YES];
}
@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