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

Side by Side 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: remove //weak Created 4 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/passwords/update_password_infobar_controller.h"
6
7 #include "base/strings/string_util.h"
8 #include "base/strings/sys_string_conversions.h"
9 #include "ios/chrome/browser/infobars/confirm_infobar_controller+protected.h"
10 #include "ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delega te.h"
11 #import "ios/chrome/browser/ui/elements/selector_coordinator.h"
12 #import "ios/public/provider/chrome/browser/ui/infobar_view_protocol.h"
13
14 namespace {
15 // Tag for the account link in the info bar message. Set to 10 to avoid conflict
16 // with tags from superclass ConfirmInfoBarController, which uses tags 1-4.
17 NSUInteger kAccountTag = 10;
18 }
19
20 @interface UpdatePasswordInfoBarController ()<SelectorCoordinatorDelegate> {
21 IOSChromeUpdatePasswordInfoBarDelegate* _delegate;
22 }
23 @end
24
25 @implementation UpdatePasswordInfoBarController
26
27 - (base::scoped_nsobject<UIView<InfoBarViewProtocol>>)
28 viewForDelegate:(IOSChromeUpdatePasswordInfoBarDelegate*)delegate
29 frame:(CGRect)frame {
30 _delegate = delegate;
31 return [super viewForDelegate:delegate frame:frame];
32 }
33
34 - (void)updateInfobarLabel:(UIView<InfoBarViewProtocol>*)view {
35 [super updateInfobarLabel:view];
36
37 // Get the message text with current links marked.
38 base::string16 messageText = base::SysNSStringToUTF16(view.markedLabel);
39 // If there are multiple possible credentials, turn the account string into a
40 // link.
41 if (_delegate->ShowMultipleAccounts()) {
42 base::string16 usernameLink = base::SysNSStringToUTF16([[view class]
43 stringAsLink:base::SysUTF16ToNSString(_delegate->selected_account())
44 tag:kAccountTag]);
45 base::ReplaceFirstSubstringAfterOffset(
46 &messageText, 0, _delegate->selected_account(), usernameLink);
47 }
48
49 [view addLabel:base::SysUTF16ToNSString(messageText)
50 target:self
51 action:@selector(infobarLinkDidPress:)];
52 }
53
54 - (void)infobarLinkDidPress:(NSNumber*)tag {
55 [super infobarLinkDidPress:tag];
56 if ([tag unsignedIntegerValue] != kAccountTag)
57 return;
58
59 UIViewController* baseViewController =
60 [[UIApplication sharedApplication] keyWindow].rootViewController;
61 SelectorCoordinator* selectorCoordinator = [[[SelectorCoordinator alloc]
62 initWithBaseViewController:baseViewController] autorelease];
63 selectorCoordinator.delegate = self;
64 selectorCoordinator.options = [_delegate->GetAccounts() copy];
65 selectorCoordinator.defaultOption =
66 base::SysUTF16ToNSString(_delegate->selected_account());
67 [selectorCoordinator start];
68 }
69
70 #pragma mark SelectorCoordinatorDelegate
71
72 - (void)selectorCoordinator:(SelectorCoordinator*)coordinator
73 didCompleteWithSelection:(NSString*)selection {
74 _delegate->set_selected_account(base::SysNSStringToUTF16(selection));
75 }
76
77 @end
OLDNEW
« 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