Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: ios/chrome/browser/passwords/update_password_infobar_controller.mm

Issue 2106413003: UpdatePasswordInfoBarController for update password UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@update_delegate
Patch Set: Formatting Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/passwords/update_password_infobar_controller.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/passwords/update_password_infobar_controller.mm
diff --git a/ios/chrome/browser/passwords/update_password_infobar_controller.mm b/ios/chrome/browser/passwords/update_password_infobar_controller.mm
new file mode 100644
index 0000000000000000000000000000000000000000..cb9e12cc26a1d418e5b455ba337ec849e005c786
--- /dev/null
+++ b/ios/chrome/browser/passwords/update_password_infobar_controller.mm
@@ -0,0 +1,119 @@
+// Copyright 2016 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/browser/passwords/update_password_infobar_controller.h"
+
+#include "base/strings/string_util.h"
+#include "base/strings/sys_string_conversions.h"
+#include "ios/chrome/browser/infobars/confirm_infobar_controller+protected.h"
+#import "ios/chrome/browser/infobars/infobar_picker_controller.h"
+#import "ios/chrome/browser/infobars/infobar_picker_coordinator.h"
+#include "ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delegate.h"
+#import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h"
+
+namespace {
+// Tag for the account link in the info bar message. Set to 10 to avoid conflict
+// with tags from superclasses.
vabr (Chromium) 2016/06/30 13:31:48 Just wondering: is this based on the fact that eve
Jackie Quinn 2016/06/30 13:52:50 ConfirmInfoBarController uses 1-4 in its enum for
vabr (Chromium) 2016/06/30 15:11:27 Thanks for explaining. Optionally, you could squee
+NSUInteger kAccountTag = 10;
+}
+
+@interface UpdatePasswordInfoBarController ()<InfoBarPickerControllerDelegate> {
+ IOSChromeUpdatePasswordInfoBarDelegate* _delegate; // weak
vabr (Chromium) 2016/06/30 13:31:48 https://docs.google.com/document/d/1AXwleU_zbOLB_o
Jackie Quinn 2016/06/30 13:52:50 Ah good call! Done.
Jackie Quinn 2016/06/30 14:29:59 ... nevermind. IOSChromeUpdatePasswordInfoBarDeleg
vabr (Chromium) 2016/06/30 15:11:27 Sorry! :)
+ // Coordinator for presenting and dismissing the picker view for choosing
+ // the account for which to update password.
+ base::scoped_nsobject<InfoBarPickerCoordinator> _pickerCoordinator;
+ // Array of accounts that the password might be updated for.
+ base::scoped_nsobject<NSArray<NSString*>> _accounts;
+}
+// Action for when the "Done" button is pressed on the displayed picker view.
+- (void)pickerDonePressed;
+// Action for when the "Cancel" button is pressed on the displayed picker view.
+- (void)pickerCancelPressed;
+@end
+
+@implementation UpdatePasswordInfoBarController
+
+- (base::scoped_nsobject<UIView<InfoBarViewProtocol>>)
+viewForDelegate:(IOSChromeUpdatePasswordInfoBarDelegate*)delegate
+ frame:(CGRect)frame {
+ _delegate = delegate;
+ return [super viewForDelegate:delegate frame:frame];
+}
+
+- (void)updateInfobarLabel:(UIView<InfoBarViewProtocol>*)view {
+ [super updateInfobarLabel:view];
+
+ // Get the message text with current links marked.
+ base::string16 messageText = base::SysNSStringToUTF16(view.markedLabel);
+ // If there are multiple possible credentials, turn the account string into a
+ // link.
+ if (_delegate->ShowMultipleAccounts()) {
+ base::string16 usernameLink = base::SysNSStringToUTF16([[view class]
+ stringAsLink:base::SysUTF16ToNSString(_delegate->selected_account())
+ tag:kAccountTag]);
+ base::ReplaceFirstSubstringAfterOffset(
+ &messageText, 0, _delegate->selected_account(), usernameLink);
+ }
+
+ [view addLabel:base::SysUTF16ToNSString(messageText)
+ target:self
+ action:@selector(infobarLinkDidPress:)];
+}
+
+- (void)infobarLinkDidPress:(NSNumber*)tag {
+ [super infobarLinkDidPress:tag];
+ if ([tag unsignedIntegerValue] != kAccountTag)
+ return;
+
+ _accounts.reset([_delegate->GetAccounts() copy]);
+ if (!_pickerCoordinator) {
+ UIViewController* baseViewController =
+ [[UIApplication sharedApplication] keyWindow].rootViewController;
+ _pickerCoordinator.reset([[InfoBarPickerCoordinator alloc]
+ initWithBaseViewController:baseViewController]);
+ InfoBarPickerController* pickerController =
+ [_pickerCoordinator infoBarPickerController];
+ pickerController.delegate = self;
+ [pickerController setDoneTarget:self action:@selector(pickerDonePressed)];
+ [pickerController setCancelTarget:self
+ action:@selector(pickerCancelPressed)];
+ }
+ [_pickerCoordinator start];
+}
+
+#pragma mark InfoBarPickerControllerDelegate
+
+- (NSString*)infoBarPickerController:(InfoBarPickerController*)controller
+ textForRow:(NSInteger)row {
+ return _accounts[row];
+}
+
+- (NSInteger)infoBarPickerControllerNumberOfRows:
+ (InfoBarPickerController*)controller {
+ return [_accounts count];
+}
+
+- (NSInteger)infoBarPickerControllerInitialRow:
+ (InfoBarPickerController*)controller {
+ return [_accounts
+ indexOfObject:base::SysUTF16ToNSString(_delegate->selected_account())];
+}
+
+#pragma mark Private methods
+
+- (void)pickerDonePressed {
+ NSInteger selectedRow =
+ [[_pickerCoordinator infoBarPickerController].pickerView
+ selectedRowInComponent:0];
+ _delegate->set_selected_account(
+ base::SysNSStringToUTF16(_accounts[selectedRow]));
+ [self updateInfobarLabel:self.view];
+ [_pickerCoordinator stop];
+}
+
+- (void)pickerCancelPressed {
+ [_pickerCoordinator stop];
+}
+
+@end
« no previous file with comments | « ios/chrome/browser/passwords/update_password_infobar_controller.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698