| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #import "chrome/browser/ui/cocoa/passwords/auto_signin_view_controller.h" | 7 #import "chrome/browser/ui/cocoa/passwords/auto_signin_view_controller.h" |
| 8 | 8 |
| 9 #include "base/mac/bind_objc_block.h" | 9 #include "base/mac/bind_objc_block.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "base/timer/timer.h" | 11 #include "base/timer/timer.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/chrome_style.h" | 13 #include "chrome/browser/ui/chrome_style.h" |
| 14 #import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h" | 14 #import "chrome/browser/ui/cocoa/passwords/account_avatar_fetcher_manager.h" |
| 15 #import "chrome/browser/ui/cocoa/passwords/credential_item_view.h" | 15 #import "chrome/browser/ui/cocoa/passwords/credential_item_view.h" |
| 16 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" | 16 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" |
| 17 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 17 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
| 18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 19 #include "skia/ext/skia_utils_mac.h" | 19 #include "skia/ext/skia_utils_mac.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/gfx/font_list.h" | 22 #include "ui/gfx/font_list.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 const int kAutoSigninToastTimeoutSeconds = 3; | 25 const int kAutoSigninToastTimeoutSeconds = 3; |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 @interface ManagePasswordsBubbleAutoSigninViewController () < | 28 @interface AutoSigninViewController ()<CredentialItemDelegate> |
| 29 CredentialItemDelegate> | 29 - (instancetype) |
| 30 - (id)initWithModel:(ManagePasswordsBubbleModel*)model | 30 initWithAvatarManager:(AccountAvatarFetcherManager*)avatarManager |
| 31 avatarManager:(AccountAvatarFetcherManager*)avatarManager | 31 delegate:(id<BasePasswordsContentViewDelegate>)delegate; |
| 32 delegate:(id<ManagePasswordsBubbleContentViewDelegate>)delegate; | |
| 33 @end | 32 @end |
| 34 | 33 |
| 35 @implementation ManagePasswordsBubbleAutoSigninViewController | 34 @implementation AutoSigninViewController |
| 36 | 35 |
| 37 - (id)initWithModel:(ManagePasswordsBubbleModel*)model | 36 - (instancetype)initWithDelegate: |
| 38 delegate:(id<ManagePasswordsBubbleContentViewDelegate>)delegate { | 37 (id<BasePasswordsContentViewDelegate>)delegate { |
| 38 auto request_context = delegate.model->GetProfile()->GetRequestContext(); |
| 39 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager( | 39 base::scoped_nsobject<AccountAvatarFetcherManager> avatarManager( |
| 40 [[AccountAvatarFetcherManager alloc] | 40 [[AccountAvatarFetcherManager alloc] |
| 41 initWithRequestContext:model->GetProfile()->GetRequestContext()]); | 41 initWithRequestContext:request_context]); |
| 42 return | 42 return [self initWithAvatarManager:avatarManager delegate:delegate]; |
| 43 [self initWithModel:model avatarManager:avatarManager delegate:delegate]; | |
| 44 } | 43 } |
| 45 | 44 |
| 46 - (id)initWithModel:(ManagePasswordsBubbleModel*)model | 45 - (instancetype) |
| 47 avatarManager:(AccountAvatarFetcherManager*)avatarManager | 46 initWithAvatarManager:(AccountAvatarFetcherManager*)avatarManager |
| 48 delegate:(id<ManagePasswordsBubbleContentViewDelegate>)delegate { | 47 delegate:(id<BasePasswordsContentViewDelegate>)delegate { |
| 49 if ((self = [super initWithDelegate:delegate])) { | 48 if ((self = [super initWithDelegate:delegate])) { |
| 50 model_ = model; | |
| 51 avatarManager_.reset([avatarManager retain]); | 49 avatarManager_.reset([avatarManager retain]); |
| 52 credentialView_.reset([[CredentialItemView alloc] | 50 credentialView_.reset([[CredentialItemView alloc] |
| 53 initWithPasswordForm:model->pending_password() | 51 initWithPasswordForm:delegate.model->pending_password() |
| 54 credentialType:password_manager::CredentialType:: | 52 credentialType:password_manager::CredentialType:: |
| 55 CREDENTIAL_TYPE_PASSWORD | 53 CREDENTIAL_TYPE_PASSWORD |
| 56 style:password_manager_mac::CredentialItemStyle:: | 54 style:password_manager_mac::CredentialItemStyle:: |
| 57 AUTO_SIGNIN | 55 AUTO_SIGNIN |
| 58 delegate:self]); | 56 delegate:self]); |
| 59 timer_.reset(new base::Timer(false, false)); | 57 timer_.reset(new base::Timer(false, false)); |
| 60 __block ManagePasswordsBubbleAutoSigninViewController* weakSelf = self; | 58 __block AutoSigninViewController* weakSelf = self; |
| 61 timer_->Start(FROM_HERE, | 59 timer_->Start(FROM_HERE, |
| 62 base::TimeDelta::FromSeconds(kAutoSigninToastTimeoutSeconds), | 60 base::TimeDelta::FromSeconds(kAutoSigninToastTimeoutSeconds), |
| 63 base::BindBlock(^{ | 61 base::BindBlock(^{ |
| 64 // |weakSelf| is still valid. Otherwise the timer would have | 62 // |weakSelf| is still valid. Otherwise the timer would have |
| 65 // stopped when it was deleted by [self dealloc]. | 63 // stopped when it was deleted by [self dealloc]. |
| 66 [weakSelf->delegate_ viewShouldDismiss]; | 64 [weakSelf.delegate viewShouldDismiss]; |
| 67 })); | 65 })); |
| 68 } | 66 } |
| 69 return self; | 67 return self; |
| 70 } | 68 } |
| 71 | 69 |
| 72 - (void)fetchAvatar:(const GURL&)avatarURL forView:(CredentialItemView*)view { | 70 - (void)fetchAvatar:(const GURL&)avatarURL forView:(CredentialItemView*)view { |
| 73 [avatarManager_ fetchAvatar:avatarURL forView:view]; | 71 [avatarManager_ fetchAvatar:avatarURL forView:view]; |
| 74 } | 72 } |
| 75 | 73 |
| 76 - (void)loadView { | 74 - (void)loadView { |
| 77 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); | 75 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); |
| 78 const CGFloat kPadding = kFramePadding; | 76 const CGFloat kPadding = kFramePadding; |
| 79 [view setFrameSize:NSMakeSize( | 77 [view setFrameSize:NSMakeSize( |
| 80 2 * kPadding + NSWidth([credentialView_ frame]), | 78 2 * kPadding + NSWidth([credentialView_ frame]), |
| 81 2 * kPadding + NSHeight([credentialView_ frame]))]; | 79 2 * kPadding + NSHeight([credentialView_ frame]))]; |
| 82 [view addSubview:credentialView_]; | 80 [view addSubview:credentialView_]; |
| 83 [credentialView_ setFrameOrigin:NSMakePoint(kPadding, kPadding)]; | 81 [credentialView_ setFrameOrigin:NSMakePoint(kPadding, kPadding)]; |
| 84 [self setView:view]; | 82 [self setView:view]; |
| 85 } | 83 } |
| 86 | 84 |
| 87 @end | 85 @end |
| OLD | NEW |