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 @@ ...@@ -50,7 +50,8 @@
self = [super initWithBaseViewController:viewController self = [super initWithBaseViewController:viewController
browserState:browserState]; browserState:browserState];
if (self) { if (self) {
_passwordViewController = [[PasswordViewController alloc] init]; _passwordViewController =
[[PasswordViewController alloc] initWithSearchController:nil];
_manualFillInjectionHandler = _manualFillInjectionHandler =
[[ManualFillInjectionHandler alloc] initWithWebStateList:webStateList]; [[ManualFillInjectionHandler alloc] initWithWebStateList:webStateList];
...@@ -80,8 +81,12 @@ ...@@ -80,8 +81,12 @@
#pragma mark - PasswordListDelegate #pragma mark - PasswordListDelegate
- (void)openAllPasswordsList { - (void)openAllPasswordsList {
PasswordViewController* allPasswordsViewController = UISearchController* searchController =
[[PasswordViewController alloc] init]; [[UISearchController alloc] initWithSearchResultsController:nil];
searchController.searchResultsUpdater = self.passwordMediator;
PasswordViewController* allPasswordsViewController = [
[PasswordViewController alloc] initWithSearchController:searchController];
self.passwordMediator.disableFilter = YES; self.passwordMediator.disableFilter = YES;
self.passwordMediator.consumer = allPasswordsViewController; self.passwordMediator.consumer = allPasswordsViewController;
...@@ -97,8 +102,9 @@ ...@@ -97,8 +102,9 @@
} }
- (void)dismissPresentedViewController { - (void)dismissPresentedViewController {
[self.allPasswordsViewController dismissViewControllerAnimated:YES [self.allPasswordsViewController.presentingViewController
completion:nil]; dismissViewControllerAnimated:YES
completion:nil];
} }
@end @end
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_PASSWORD_MEDIATOR_H_ #ifndef IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_PASSWORD_MEDIATOR_H_
#define 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" #include "base/memory/ref_counted.h"
...@@ -21,7 +21,7 @@ class WebStateList; ...@@ -21,7 +21,7 @@ class WebStateList;
// Object in charge of getting the passwords relevant for the manual fill // Object in charge of getting the passwords relevant for the manual fill
// passwords UI. // passwords UI.
@interface ManualFillPasswordMediator : NSObject @interface ManualFillPasswordMediator : NSObject<UISearchResultsUpdating>
// The consumer for passwords updates. Setting it will trigger the consumer // The consumer for passwords updates. Setting it will trigger the consumer
// methods with the current data. // methods with the current data.
......
...@@ -96,6 +96,26 @@ ...@@ -96,6 +96,26 @@
[self postCredentialsToConsumer]; [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 #pragma mark - Private
// Posts the credentials to the consumer. If filtered is |YES| it only post the // Posts the credentials to the consumer. If filtered is |YES| it only post the
......
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
@interface PasswordViewController @interface PasswordViewController
: ChromeTableViewController<ManualFillPasswordConsumer> : ChromeTableViewController<ManualFillPasswordConsumer>
- (instancetype)init NS_DESIGNATED_INITIALIZER; - (instancetype)initWithSearchController:(UISearchController*)searchController
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithTableViewStyle:(UITableViewStyle)style - (instancetype)initWithTableViewStyle:(UITableViewStyle)style
appBarStyle: appBarStyle:
......
...@@ -23,14 +23,28 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) { ...@@ -23,14 +23,28 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
}; };
} // namespace } // namespace
@interface PasswordViewController ()
// Search controller if any.
@property(nonatomic, strong) UISearchController* searchController;
@end
@implementation PasswordViewController @implementation PasswordViewController
- (instancetype)init { @synthesize searchController = _searchController;
return [super initWithTableViewStyle:UITableViewStylePlain
- (instancetype)initWithSearchController:(UISearchController*)searchController {
self = [super initWithTableViewStyle:UITableViewStylePlain
appBarStyle:ChromeTableViewControllerStyleNoAppBar]; appBarStyle:ChromeTableViewControllerStyleNoAppBar];
if (self) {
_searchController = searchController;
}
return self;
} }
- (void)viewDidLoad { - (void)viewDidLoad {
// Super's |viewDidLoad| uses |styler.tableViewBackgroundColor| so it needs to
// be set before.
self.styler.tableViewBackgroundColor = [UIColor whiteColor]; self.styler.tableViewBackgroundColor = [UIColor whiteColor];
[super viewDidLoad]; [super viewDidLoad];
...@@ -41,6 +55,15 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) { ...@@ -41,6 +55,15 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
self.tableView.estimatedRowHeight = 200; self.tableView.estimatedRowHeight = 200;
self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0); 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 = NSString* titleString =
l10n_util::GetNSString(IDS_IOS_MANUAL_FALLBACK_USE_OTHER_PASSWORD); l10n_util::GetNSString(IDS_IOS_MANUAL_FALLBACK_USE_OTHER_PASSWORD);
self.title = titleString; self.title = titleString;
...@@ -86,44 +109,29 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) { ...@@ -86,44 +109,29 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
} }
BOOL doesSectionExist = BOOL doesSectionExist =
[self.tableViewModel hasSectionForSectionIdentifier:sectionIdentifier]; [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 (!items.count) {
if (doesSectionExist) { if (doesSectionExist) {
NSInteger tableViewSection =
[self.tableViewModel sectionForSectionIdentifier:sectionIdentifier];
NSIndexSet* sectionIndexSet =
[NSIndexSet indexSetWithIndex:tableViewSection];
[self.tableViewModel removeSectionWithIdentifier:sectionIdentifier]; [self.tableViewModel removeSectionWithIdentifier:sectionIdentifier];
[self.tableView deleteSections:sectionIndexSet
withRowAnimation:UITableViewRowAnimationNone];
} }
return;
}
if (!doesSectionExist) {
if (sectionIdentifier == CredentialsSectionIdentifier) {
[self.tableViewModel
insertSectionWithIdentifier:CredentialsSectionIdentifier
atIndex:0];
} else {
[self.tableViewModel addSectionWithIdentifier: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 { } else {
[self.tableView insertSections:sectionIndexSet if (!doesSectionExist) {
withRowAnimation:UITableViewRowAnimationNone]; if (sectionIdentifier == CredentialsSectionIdentifier) {
[self.tableViewModel
insertSectionWithIdentifier:CredentialsSectionIdentifier
atIndex:0];
} else {
[self.tableViewModel addSectionWithIdentifier:sectionIdentifier];
}
}
[self.tableViewModel
deleteAllItemsFromSectionWithIdentifier:sectionIdentifier];
for (TableViewItem* item in items) {
[self.tableViewModel addItem:item
toSectionWithIdentifier:sectionIdentifier];
}
} }
[self.tableView reloadData];
} }
@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