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

Side by Side Diff: ios/chrome/browser/passwords/update_password_infobar_controller.mm

Issue 2933873002: [ObjC ARC] Converts ios/chrome/browser/passwords:passwords to ARC. (Closed)
Patch Set: fix names and nil assignments. Created 3 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 unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/passwords/password_generation_offer_view.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/passwords/update_password_infobar_controller.h" 5 #import "ios/chrome/browser/passwords/update_password_infobar_controller.h"
6 6
7 #include "base/ios/weak_nsobject.h"
8 #import "base/mac/objc_property_releaser.h"
9 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
10 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
11 #include "ios/chrome/browser/infobars/confirm_infobar_controller+protected.h" 9 #include "ios/chrome/browser/infobars/confirm_infobar_controller+protected.h"
12 #include "ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delega te.h" 10 #include "ios/chrome/browser/passwords/ios_chrome_update_password_infobar_delega te.h"
13 #import "ios/chrome/browser/ui/elements/selector_coordinator.h" 11 #import "ios/chrome/browser/ui/elements/selector_coordinator.h"
14 #import "ios/chrome/browser/ui/infobars/infobar_view.h" 12 #import "ios/chrome/browser/ui/infobars/infobar_view.h"
15 13
14 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support."
16 #endif
17
16 namespace { 18 namespace {
17 // Tag for the account link in the info bar message. Set to 10 to avoid conflict 19 // Tag for the account link in the info bar message. Set to 10 to avoid conflict
18 // with tags from superclass ConfirmInfoBarController, which uses tags 1-4. 20 // with tags from superclass ConfirmInfoBarController, which uses tags 1-4.
19 NSUInteger kAccountTag = 10; 21 NSUInteger kAccountTag = 10;
20 } 22 }
21 23
22 @interface UpdatePasswordInfoBarController ()<SelectorCoordinatorDelegate> { 24 @interface UpdatePasswordInfoBarController ()<SelectorCoordinatorDelegate> {
23 base::mac::ObjCPropertyReleaser
24 _propertyReleaser_UpdatePasswordInfoBarController;
25 IOSChromeUpdatePasswordInfoBarDelegate* _delegate; 25 IOSChromeUpdatePasswordInfoBarDelegate* _delegate;
26 } 26 }
27 @property(nonatomic, retain) SelectorCoordinator* selectorCoordinator; 27 @property(nonatomic, strong) SelectorCoordinator* selectorCoordinator;
28 @end 28 @end
29 29
30 @implementation UpdatePasswordInfoBarController 30 @implementation UpdatePasswordInfoBarController
31 31
32 @synthesize selectorCoordinator = _selectorCoordinator; 32 @synthesize selectorCoordinator = _selectorCoordinator;
33 33
34 - (instancetype)initWithDelegate:(InfoBarViewDelegate*)delegate {
35 self = [super initWithDelegate:delegate];
36 if (self) {
37 _propertyReleaser_UpdatePasswordInfoBarController.Init(
38 self, [UpdatePasswordInfoBarController class]);
39 }
40 return self;
41 }
42
43 - (InfoBarView*)viewForDelegate: 34 - (InfoBarView*)viewForDelegate:
44 (IOSChromeUpdatePasswordInfoBarDelegate*)delegate 35 (IOSChromeUpdatePasswordInfoBarDelegate*)delegate
45 frame:(CGRect)frame { 36 frame:(CGRect)frame {
46 _delegate = delegate; 37 _delegate = delegate;
47 return [super viewForDelegate:delegate frame:frame]; 38 return [super viewForDelegate:delegate frame:frame];
48 } 39 }
49 40
50 - (void)updateInfobarLabel:(InfoBarView*)view { 41 - (void)updateInfobarLabel:(InfoBarView*)view {
51 [super updateInfobarLabel:view]; 42 [super updateInfobarLabel:view];
52 43
53 // Get the message text with current links marked. 44 // Get the message text with current links marked.
54 base::string16 messageText = base::SysNSStringToUTF16(view.markedLabel); 45 base::string16 messageText = base::SysNSStringToUTF16(view.markedLabel);
55 // If there are multiple possible credentials, turn the account string into a 46 // If there are multiple possible credentials, turn the account string into a
56 // link. 47 // link.
57 if (_delegate->ShowMultipleAccounts()) { 48 if (_delegate->ShowMultipleAccounts()) {
58 base::string16 usernameLink = base::SysNSStringToUTF16([[view class] 49 base::string16 usernameLink = base::SysNSStringToUTF16([[view class]
59 stringAsLink:base::SysUTF16ToNSString(_delegate->selected_account()) 50 stringAsLink:base::SysUTF16ToNSString(_delegate->selected_account())
60 tag:kAccountTag]); 51 tag:kAccountTag]);
61 base::ReplaceFirstSubstringAfterOffset( 52 base::ReplaceFirstSubstringAfterOffset(
62 &messageText, 0, _delegate->selected_account(), usernameLink); 53 &messageText, 0, _delegate->selected_account(), usernameLink);
63 } 54 }
64 55
65 base::WeakNSObject<UpdatePasswordInfoBarController> weakSelf(self); 56 __weak UpdatePasswordInfoBarController* weakSelf = self;
66 [view addLabel:base::SysUTF16ToNSString(messageText) 57 [view addLabel:base::SysUTF16ToNSString(messageText)
67 action:^(NSUInteger tag) { 58 action:^(NSUInteger tag) {
68 [weakSelf infobarLinkDidPress:tag]; 59 [weakSelf infobarLinkDidPress:tag];
69 }]; 60 }];
70 } 61 }
71 62
72 - (void)infobarLinkDidPress:(NSUInteger)tag { 63 - (void)infobarLinkDidPress:(NSUInteger)tag {
73 [super infobarLinkDidPress:tag]; 64 [super infobarLinkDidPress:tag];
74 if (tag != kAccountTag) 65 if (tag != kAccountTag)
75 return; 66 return;
76 67
77 UIViewController* baseViewController = 68 UIViewController* baseViewController =
78 [[UIApplication sharedApplication] keyWindow].rootViewController; 69 [[UIApplication sharedApplication] keyWindow].rootViewController;
79 self.selectorCoordinator = [[[SelectorCoordinator alloc] 70 self.selectorCoordinator = [[SelectorCoordinator alloc]
80 initWithBaseViewController:baseViewController] autorelease]; 71 initWithBaseViewController:baseViewController];
81 self.selectorCoordinator.delegate = self; 72 self.selectorCoordinator.delegate = self;
82 self.selectorCoordinator.options = 73 self.selectorCoordinator.options =
83 [NSOrderedSet orderedSetWithArray:_delegate->GetAccounts()]; 74 [NSOrderedSet orderedSetWithArray:_delegate->GetAccounts()];
84 self.selectorCoordinator.defaultOption = 75 self.selectorCoordinator.defaultOption =
85 base::SysUTF16ToNSString(_delegate->selected_account()); 76 base::SysUTF16ToNSString(_delegate->selected_account());
86 [self.selectorCoordinator start]; 77 [self.selectorCoordinator start];
87 } 78 }
88 79
89 #pragma mark SelectorCoordinatorDelegate 80 #pragma mark SelectorCoordinatorDelegate
90 81
91 - (void)selectorCoordinator:(SelectorCoordinator*)coordinator 82 - (void)selectorCoordinator:(SelectorCoordinator*)coordinator
92 didCompleteWithSelection:(NSString*)selection { 83 didCompleteWithSelection:(NSString*)selection {
93 _delegate->set_selected_account(base::SysNSStringToUTF16(selection)); 84 _delegate->set_selected_account(base::SysNSStringToUTF16(selection));
94 [self updateInfobarLabel:self.view]; 85 [self updateInfobarLabel:self.view];
95 } 86 }
96 87
97 @end 88 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/passwords/password_generation_offer_view.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698