| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/ui/cocoa/passwords/account_chooser_view_controller.h" | 5 #import "chrome/browser/ui/cocoa/passwords/account_chooser_view_controller.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h" | 10 #import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 } | 35 } |
| 36 @end | 36 @end |
| 37 | 37 |
| 38 @interface AccountChooserViewController() | 38 @interface AccountChooserViewController() |
| 39 - (void)onCancelClicked:(id)sender; | 39 - (void)onCancelClicked:(id)sender; |
| 40 + (NSArray*)credentialItemsFromBridge:(AccountChooserBridge*)bridge | 40 + (NSArray*)credentialItemsFromBridge:(AccountChooserBridge*)bridge |
| 41 delegate:(id<CredentialItemDelegate>)delegate; | 41 delegate:(id<CredentialItemDelegate>)delegate; |
| 42 @end | 42 @end |
| 43 | 43 |
| 44 @implementation AccountChooserViewController | 44 @implementation AccountChooserViewController |
| 45 @synthesize bridge = bridge_; |
| 45 | 46 |
| 46 - (id)initWithBridge:(AccountChooserBridge*)bridge { | 47 - (instancetype)initWithBridge:(AccountChooserBridge*)bridge { |
| 47 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager( | 48 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager( |
| 48 [[AccountAvatarFetcherManager alloc] | 49 [[AccountAvatarFetcherManager alloc] |
| 49 initWithRequestContext:bridge->GetRequestContext()]); | 50 initWithRequestContext:bridge->GetRequestContext()]); |
| 50 return [self initWithBridge:bridge avatarManager:avatarManager]; | 51 return [self initWithBridge:bridge avatarManager:avatarManager]; |
| 51 } | 52 } |
| 52 | 53 |
| 53 - (void)dealloc { | 54 - (void)dealloc { |
| 54 [credentialsView_ setDelegate:nil]; | 55 [credentialsView_ setDelegate:nil]; |
| 55 [credentialsView_ setDataSource:nil]; | 56 [credentialsView_ setDataSource:nil]; |
| 56 [super dealloc]; | 57 [super dealloc]; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 128 |
| 128 const CGFloat frameHeight = NSMaxY([titleView_ frame]) + kFramePadding; | 129 const CGFloat frameHeight = NSMaxY([titleView_ frame]) + kFramePadding; |
| 129 [view setFrame:NSMakeRect(0, 0, kDesiredBubbleWidth, frameHeight)]; | 130 [view setFrame:NSMakeRect(0, 0, kDesiredBubbleWidth, frameHeight)]; |
| 130 | 131 |
| 131 [self setView:view]; | 132 [self setView:view]; |
| 132 } | 133 } |
| 133 | 134 |
| 134 - (BOOL)textView:(NSTextView*)textView | 135 - (BOOL)textView:(NSTextView*)textView |
| 135 clickedOnLink:(id)link | 136 clickedOnLink:(id)link |
| 136 atIndex:(NSUInteger)charIndex { | 137 atIndex:(NSUInteger)charIndex { |
| 137 bridge_->GetDialogController()->OnSmartLockLinkClicked(); | 138 if (bridge_ && bridge_->GetDialogController()) |
| 139 bridge_->GetDialogController()->OnSmartLockLinkClicked(); |
| 138 return YES; | 140 return YES; |
| 139 } | 141 } |
| 140 | 142 |
| 141 - (void)onCancelClicked:(id)sender { | 143 - (void)onCancelClicked:(id)sender { |
| 142 bridge_->PerformClose(); | 144 if (bridge_) |
| 145 bridge_->PerformClose(); |
| 143 } | 146 } |
| 144 | 147 |
| 145 - (void)fetchAvatar:(const GURL&)avatarURL forView:(CredentialItemView*)view { | 148 - (void)fetchAvatar:(const GURL&)avatarURL forView:(CredentialItemView*)view { |
| 146 [avatarManager_ fetchAvatar:avatarURL forView:view]; | 149 [avatarManager_ fetchAvatar:avatarURL forView:view]; |
| 147 } | 150 } |
| 148 | 151 |
| 149 + (NSArray*)credentialItemsFromBridge:(AccountChooserBridge*)bridge | 152 + (NSArray*)credentialItemsFromBridge:(AccountChooserBridge*)bridge |
| 150 delegate:(id<CredentialItemDelegate>)delegate { | 153 delegate:(id<CredentialItemDelegate>)delegate { |
| 151 base::scoped_nsobject<NSMutableArray> items([[NSMutableArray alloc] init]); | 154 base::scoped_nsobject<NSMutableArray> items([[NSMutableArray alloc] init]); |
| 152 PasswordDialogController* controller = bridge->GetDialogController(); | 155 PasswordDialogController* controller = bridge->GetDialogController(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 - (NSCell*)tableView:(NSTableView*)tableView | 193 - (NSCell*)tableView:(NSTableView*)tableView |
| 191 dataCellForTableColumn:(NSTableColumn*)tableColumn | 194 dataCellForTableColumn:(NSTableColumn*)tableColumn |
| 192 row:(NSInteger)row { | 195 row:(NSInteger)row { |
| 193 return [[[CredentialItemCell alloc] | 196 return [[[CredentialItemCell alloc] |
| 194 initWithView:[credentialItems_.get() objectAtIndex:row]] autorelease]; | 197 initWithView:[credentialItems_.get() objectAtIndex:row]] autorelease]; |
| 195 } | 198 } |
| 196 | 199 |
| 197 - (void)tableViewSelectionDidChange:(NSNotification *)notification { | 200 - (void)tableViewSelectionDidChange:(NSNotification *)notification { |
| 198 CredentialItemView* item = | 201 CredentialItemView* item = |
| 199 [credentialItems_.get() objectAtIndex:[credentialsView_ selectedRow]]; | 202 [credentialItems_.get() objectAtIndex:[credentialsView_ selectedRow]]; |
| 200 bridge_->GetDialogController()->OnChooseCredentials(item.passwordForm, | 203 if (bridge_ && bridge_->GetDialogController()) { |
| 201 item.credentialType); | 204 bridge_->GetDialogController()->OnChooseCredentials(item.passwordForm, |
| 205 item.credentialType); |
| 206 } |
| 202 } | 207 } |
| 203 | 208 |
| 204 @end | 209 @end |
| 205 | 210 |
| 206 @implementation AccountChooserViewController(Testing) | 211 @implementation AccountChooserViewController(Testing) |
| 207 | 212 |
| 208 - (id)initWithBridge:(AccountChooserBridge*)bridge | 213 - (instancetype)initWithBridge:(AccountChooserBridge*)bridge |
| 209 avatarManager:(AccountAvatarFetcherManager*)avatarManager { | 214 avatarManager:(AccountAvatarFetcherManager*)avatarManager { |
| 210 DCHECK(bridge); | 215 DCHECK(bridge); |
| 211 if (self = [super initWithNibName:nil bundle:nil]) { | 216 if (self = [super initWithNibName:nil bundle:nil]) { |
| 212 bridge_ = bridge; | 217 bridge_ = bridge; |
| 213 avatarManager_.reset([avatarManager retain]); | 218 avatarManager_.reset([avatarManager retain]); |
| 214 } | 219 } |
| 215 return self; | 220 return self; |
| 216 } | 221 } |
| 217 | 222 |
| 218 - (NSButton*)cancelButton { | 223 - (NSButton*)cancelButton { |
| 219 return cancelButton_; | 224 return cancelButton_; |
| 220 } | 225 } |
| 221 | 226 |
| 222 - (NSTableView*)credentialsView { | 227 - (NSTableView*)credentialsView { |
| 223 return credentialsView_; | 228 return credentialsView_; |
| 224 } | 229 } |
| 225 | 230 |
| 226 - (NSTextView*)titleView { | 231 - (NSTextView*)titleView { |
| 227 return titleView_; | 232 return titleView_; |
| 228 } | 233 } |
| 229 | 234 |
| 230 @end | 235 @end |
| OLD | NEW |