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

[iOS][MF] Adds password search to all passwords

This adds a search header for all passwords in manual fallback.

Bug: 878388
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I8b9516c42d491aed7a8a008a154b999102f11d1a
Reviewed-on: https://chromium-review.googlesource.com/1210504
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590244}
parent 87036e9b
......@@ -50,7 +50,8 @@
self = [super initWithBaseViewController:viewController
browserState:browserState];
if (self) {
_passwordViewController = [[PasswordViewController alloc] init];
_passwordViewController =
[[PasswordViewController alloc] initWithSearchController:nil];
_manualFillInjectionHandler =
[[ManualFillInjectionHandler alloc] initWithWebStateList:webStateList];
......@@ -80,8 +81,12 @@
#pragma mark - PasswordListDelegate
- (void)openAllPasswordsList {
PasswordViewController* allPasswordsViewController =
[[PasswordViewController alloc] init];
UISearchController* searchController =
[[UISearchController alloc] initWithSearchResultsController:nil];
searchController.searchResultsUpdater = self.passwordMediator;
PasswordViewController* allPasswordsViewController = [
[PasswordViewController alloc] initWithSearchController:searchController];
self.passwordMediator.disableFilter = YES;
self.passwordMediator.consumer = allPasswordsViewController;
......@@ -97,7 +102,8 @@
}
- (void)dismissPresentedViewController {
[self.allPasswordsViewController dismissViewControllerAnimated:YES
[self.allPasswordsViewController.presentingViewController
dismissViewControllerAnimated:YES
completion:nil];
}
......
......@@ -5,7 +5,7 @@
#ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_PASSWORD_MEDIATOR_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_PASSWORD_MEDIATOR_H_
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#include "base/memory/ref_counted.h"
......@@ -21,7 +21,7 @@ class WebStateList;
// Object in charge of getting the passwords relevant for the manual fill
// passwords UI.
@interface ManualFillPasswordMediator : NSObject
@interface ManualFillPasswordMediator : NSObject<UISearchResultsUpdating>
// The consumer for passwords updates. Setting it will trigger the consumer
// methods with the current data.
......
......@@ -96,6 +96,26 @@
[self postCredentialsToConsumer];
}
#pragma mark - UISearchResultsUpdating
- (void)updateSearchResultsForSearchController:
(UISearchController*)searchController {
NSString* searchText = searchController.searchBar.text;
if (!searchText.length) {
auto credentials = [self createItemsForCredentials:self.credentials];
[self.consumer presentCredentials:credentials];
return;
}
NSPredicate* predicate = [NSPredicate
predicateWithFormat:@"host CONTAINS[cd] %@ OR username CONTAINS[cd] %@",
searchText, searchText];
NSArray* filteredCredentials =
[self.credentials filteredArrayUsingPredicate:predicate];
auto credentials = [self createItemsForCredentials:filteredCredentials];
[self.consumer presentCredentials:credentials];
}
#pragma mark - Private
// Posts the credentials to the consumer. If filtered is |YES| it only post the
......
......@@ -14,7 +14,8 @@
@interface PasswordViewController
: ChromeTableViewController<ManualFillPasswordConsumer>
- (instancetype)init NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithSearchController:(UISearchController*)searchController
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithTableViewStyle:(UITableViewStyle)style
appBarStyle:
......
......@@ -23,14 +23,28 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
};
} // namespace
@interface PasswordViewController ()
// Search controller if any.
@property(nonatomic, strong) UISearchController* searchController;
@end
@implementation PasswordViewController
- (instancetype)init {
return [super initWithTableViewStyle:UITableViewStylePlain
@synthesize searchController = _searchController;
- (instancetype)initWithSearchController:(UISearchController*)searchController {
self = [super initWithTableViewStyle:UITableViewStylePlain
appBarStyle:ChromeTableViewControllerStyleNoAppBar];
if (self) {
_searchController = searchController;
}
return self;
}
- (void)viewDidLoad {
// Super's |viewDidLoad| uses |styler.tableViewBackgroundColor| so it needs to
// be set before.
self.styler.tableViewBackgroundColor = [UIColor whiteColor];
[super viewDidLoad];
......@@ -41,6 +55,15 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
self.tableView.estimatedRowHeight = 200;
self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
self.definesPresentationContext = YES;
self.searchController.searchBar.backgroundColor = [UIColor clearColor];
self.searchController.obscuresBackgroundDuringPresentation = NO;
if (@available(iOS 11, *)) {
self.navigationItem.searchController = self.searchController;
self.navigationItem.hidesSearchBarWhenScrolling = NO;
} else {
self.tableView.tableHeaderView = self.searchController.searchBar;
}
NSString* titleString =
l10n_util::GetNSString(IDS_IOS_MANUAL_FALLBACK_USE_OTHER_PASSWORD);
self.title = titleString;
......@@ -86,20 +109,12 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
}
BOOL doesSectionExist =
[self.tableViewModel hasSectionForSectionIdentifier:sectionIdentifier];
// If there are no passed credentials, remove section if exist and return.
// If there are no passed credentials, remove section if exist.
if (!items.count) {
if (doesSectionExist) {
NSInteger tableViewSection =
[self.tableViewModel sectionForSectionIdentifier:sectionIdentifier];
NSIndexSet* sectionIndexSet =
[NSIndexSet indexSetWithIndex:tableViewSection];
[self.tableViewModel removeSectionWithIdentifier:sectionIdentifier];
[self.tableView deleteSections:sectionIndexSet
withRowAnimation:UITableViewRowAnimationNone];
}
return;
}
} else {
if (!doesSectionExist) {
if (sectionIdentifier == CredentialsSectionIdentifier) {
[self.tableViewModel
......@@ -109,21 +124,14 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
[self.tableViewModel addSectionWithIdentifier:sectionIdentifier];
}
}
[self.tableViewModel
deleteAllItemsFromSectionWithIdentifier:sectionIdentifier];
for (TableViewItem* item in items) {
[self.tableViewModel addItem:item
toSectionWithIdentifier:sectionIdentifier];
}
NSInteger tableViewSection =
[self.tableViewModel sectionForSectionIdentifier:sectionIdentifier];
NSIndexSet* sectionIndexSet = [NSIndexSet indexSetWithIndex:tableViewSection];
if (doesSectionExist) {
[self.tableView reloadSections:sectionIndexSet
withRowAnimation:UITableViewRowAnimationNone];
} else {
[self.tableView insertSections:sectionIndexSet
withRowAnimation:UITableViewRowAnimationNone];
}
[self.tableView reloadData];
}
@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