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

Side by Side Diff: chrome/browser/ui/cocoa/passwords/credentials_selection_view.mm

Issue 2253233005: Change ScopedVector to vector<unique_ptr> in the password's UI code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: android+ Created 4 years, 4 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
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/credentials_selection_view.h" 5 #import "chrome/browser/ui/cocoa/passwords/credentials_selection_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "chrome/browser/ui/chrome_style.h" 9 #include "chrome/browser/ui/chrome_style.h"
10 #import "chrome/browser/ui/cocoa/bubble_combobox.h" 10 #import "chrome/browser/ui/cocoa/bubble_combobox.h"
11 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h" 11 #import "chrome/browser/ui/cocoa/passwords/passwords_bubble_utils.h"
12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
13 #include "ui/base/models/simple_combobox_model.h" 13 #include "ui/base/models/simple_combobox_model.h"
14 14
15 namespace { 15 namespace {
16 16
17 NSPopUpButton* CreateUsernamesPopUpButton( 17 NSPopUpButton* CreateUsernamesPopUpButton(
18 const std::vector<const autofill::PasswordForm*>& forms, 18 const std::vector<autofill::PasswordForm>& forms,
19 const base::string16& best_matched_username) { 19 const base::string16& best_matched_username) {
20 DCHECK(!forms.empty()); 20 DCHECK(!forms.empty());
21 std::vector<base::string16> usernames; 21 std::vector<base::string16> usernames;
22 size_t best_matched_username_index = forms.size(); 22 size_t best_matched_username_index = forms.size();
23 size_t preffered_form_index = forms.size(); 23 size_t preffered_form_index = forms.size();
24 24
25 for (size_t index = 0; index < forms.size(); ++index) { 25 for (size_t index = 0; index < forms.size(); ++index) {
26 usernames.push_back(forms[index]->username_value); 26 usernames.push_back(forms[index].username_value);
27 if (forms[index]->username_value == best_matched_username) { 27 if (forms[index].username_value == best_matched_username) {
28 best_matched_username_index = index; 28 best_matched_username_index = index;
29 } 29 }
30 if (forms[index]->preferred) { 30 if (forms[index].preferred) {
31 preffered_form_index = index; 31 preffered_form_index = index;
32 } 32 }
33 } 33 }
34 34
35 ui::SimpleComboboxModel model(usernames); 35 ui::SimpleComboboxModel model(usernames);
36 base::scoped_nsobject<NSPopUpButton> button([[BubbleCombobox alloc] 36 base::scoped_nsobject<NSPopUpButton> button([[BubbleCombobox alloc]
37 initWithFrame:NSZeroRect 37 initWithFrame:NSZeroRect
38 pullsDown:NO 38 pullsDown:NO
39 model:&model]); 39 model:&model]);
40 [button setFont:LabelFont()]; 40 [button setFont:LabelFont()];
(...skipping 13 matching lines...) Expand all
54 } // namespace 54 } // namespace
55 55
56 @implementation CredentialsSelectionView 56 @implementation CredentialsSelectionView
57 57
58 - (id)initWithModel:(ManagePasswordsBubbleModel*)model { 58 - (id)initWithModel:(ManagePasswordsBubbleModel*)model {
59 if ((self = [super init])) { 59 if ((self = [super init])) {
60 model_ = model; 60 model_ = model;
61 61
62 // Create the pop up button with usernames and the password field. 62 // Create the pop up button with usernames and the password field.
63 usernamePopUpButton_.reset([CreateUsernamesPopUpButton( 63 usernamePopUpButton_.reset([CreateUsernamesPopUpButton(
64 model_->local_credentials().get(), 64 model_->local_credentials(),
65 model_->pending_password().username_value) retain]); 65 model_->pending_password().username_value) retain]);
66 passwordField_.reset( 66 passwordField_.reset(
67 [PasswordLabel(model_->pending_password().password_value) retain]); 67 [PasswordLabel(model_->pending_password().password_value) retain]);
68 68
69 // Calculate desired widths of username and password. 69 // Calculate desired widths of username and password.
70 CGFloat firstWidth = NSMaxX([usernamePopUpButton_ frame]); 70 CGFloat firstWidth = NSMaxX([usernamePopUpButton_ frame]);
71 CGFloat secondWidth = NSMaxX([passwordField_ frame]); 71 CGFloat secondWidth = NSMaxX([passwordField_ frame]);
72 std::pair<CGFloat, CGFloat> sizes = GetResizedColumns( 72 std::pair<CGFloat, CGFloat> sizes = GetResizedColumns(
73 kDesiredRowWidth, std::make_pair(firstWidth, secondWidth)); 73 kDesiredRowWidth, std::make_pair(firstWidth, secondWidth));
74 CGFloat curX = 0; 74 CGFloat curX = 0;
(...skipping 29 matching lines...) Expand all
104 104
105 // Update the frame. 105 // Update the frame.
106 [self setFrameSize:NSMakeSize(kDesiredRowWidth, curY)]; 106 [self setFrameSize:NSMakeSize(kDesiredRowWidth, curY)];
107 } 107 }
108 return self; 108 return self;
109 } 109 }
110 110
111 - (const autofill::PasswordForm*)getSelectedCredentials { 111 - (const autofill::PasswordForm*)getSelectedCredentials {
112 int selected_index = [usernamePopUpButton_ indexOfSelectedItem]; 112 int selected_index = [usernamePopUpButton_ indexOfSelectedItem];
113 CHECK(selected_index >= 0); 113 CHECK(selected_index >= 0);
114 return model_->local_credentials()[selected_index]; 114 return &model_->local_credentials()[selected_index];
115 } 115 }
116 116
117 @end 117 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698