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

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_bubble_model.cc

Issue 1001553005: New "Save password" bubble for the Credential Manager API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 5 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/password_manager/password_store_factory.h" 9 #include "chrome/browser/password_manager/password_store_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 } 50 }
51 51
52 void RecordExperimentStatistics(content::WebContents* web_contents, 52 void RecordExperimentStatistics(content::WebContents* web_contents,
53 metrics_util::UIDismissalReason reason) { 53 metrics_util::UIDismissalReason reason) {
54 Profile* profile = GetProfileFromWebContents(web_contents); 54 Profile* profile = GetProfileFromWebContents(web_contents);
55 if (!profile) 55 if (!profile)
56 return; 56 return;
57 password_bubble_experiment::RecordBubbleClosed(profile->GetPrefs(), reason); 57 password_bubble_experiment::RecordBubbleClosed(profile->GetPrefs(), reason);
58 } 58 }
59 59
60 base::string16 PendingStateTitleBasedOnSavePasswordPref(
61 bool never_save_passwords) {
62 return l10n_util::GetStringUTF16(
63 never_save_passwords ? IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE
64 : IDS_SAVE_PASSWORD);
65 }
66
67 ScopedVector<const autofill::PasswordForm> DeepCopyForms( 60 ScopedVector<const autofill::PasswordForm> DeepCopyForms(
68 const std::vector<const autofill::PasswordForm*>& forms) { 61 const std::vector<const autofill::PasswordForm*>& forms) {
69 ScopedVector<const autofill::PasswordForm> result; 62 ScopedVector<const autofill::PasswordForm> result;
70 result.reserve(forms.size()); 63 result.reserve(forms.size());
71 std::transform(forms.begin(), forms.end(), std::back_inserter(result), 64 std::transform(forms.begin(), forms.end(), std::back_inserter(result),
72 [](const autofill::PasswordForm* form) { 65 [](const autofill::PasswordForm* form) {
73 return new autofill::PasswordForm(*form); 66 return new autofill::PasswordForm(*form);
74 }); 67 });
75 return result.Pass(); 68 return result.Pass();
76 } 69 }
(...skipping 19 matching lines...) Expand all
96 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { 89 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) {
97 local_credentials_ = DeepCopyForms(controller->GetCurrentForms()); 90 local_credentials_ = DeepCopyForms(controller->GetCurrentForms());
98 federated_credentials_ = DeepCopyForms(controller->GetFederatedForms()); 91 federated_credentials_ = DeepCopyForms(controller->GetFederatedForms());
99 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { 92 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) {
100 pending_password_ = *controller->GetCurrentForms()[0]; 93 pending_password_ = *controller->GetCurrentForms()[0];
101 } else { 94 } else {
102 local_credentials_ = DeepCopyForms(controller->GetCurrentForms()); 95 local_credentials_ = DeepCopyForms(controller->GetCurrentForms());
103 } 96 }
104 97
105 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE) { 98 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE) {
106 title_ = PendingStateTitleBasedOnSavePasswordPref(never_save_passwords_); 99 title_ = PendingStateTitleBasedOnSavePasswordPref();
107 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { 100 } else if (state_ == password_manager::ui::BLACKLIST_STATE) {
108 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); 101 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE);
109 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { 102 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) {
110 title_ = 103 title_ =
111 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); 104 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE);
112 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { 105 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) {
113 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); 106 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE);
114 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { 107 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) {
115 // There is no title. 108 // There is no title.
116 } else { 109 } else {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 183
191 void ManagePasswordsBubbleModel::OnNopeClicked() { 184 void ManagePasswordsBubbleModel::OnNopeClicked() {
192 dismissal_reason_ = metrics_util::CLICKED_NOPE; 185 dismissal_reason_ = metrics_util::CLICKED_NOPE;
193 RecordExperimentStatistics(web_contents(), dismissal_reason_); 186 RecordExperimentStatistics(web_contents(), dismissal_reason_);
194 if (state_ != password_manager::ui::CREDENTIAL_REQUEST_STATE) 187 if (state_ != password_manager::ui::CREDENTIAL_REQUEST_STATE)
195 state_ = password_manager::ui::PENDING_PASSWORD_STATE; 188 state_ = password_manager::ui::PENDING_PASSWORD_STATE;
196 } 189 }
197 190
198 void ManagePasswordsBubbleModel::OnConfirmationForNeverForThisSite() { 191 void ManagePasswordsBubbleModel::OnConfirmationForNeverForThisSite() {
199 never_save_passwords_ = true; 192 never_save_passwords_ = true;
200 title_ = PendingStateTitleBasedOnSavePasswordPref(never_save_passwords_); 193 title_ = PendingStateTitleBasedOnSavePasswordPref();
201 } 194 }
202 195
203 void ManagePasswordsBubbleModel::OnUndoNeverForThisSite() { 196 void ManagePasswordsBubbleModel::OnUndoNeverForThisSite() {
204 never_save_passwords_ = false; 197 never_save_passwords_ = false;
205 title_ = PendingStateTitleBasedOnSavePasswordPref(never_save_passwords_); 198 title_ = PendingStateTitleBasedOnSavePasswordPref();
206 } 199 }
207 200
208 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { 201 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() {
209 dismissal_reason_ = metrics_util::CLICKED_NEVER; 202 dismissal_reason_ = metrics_util::CLICKED_NEVER;
210 RecordExperimentStatistics(web_contents(), dismissal_reason_); 203 RecordExperimentStatistics(web_contents(), dismissal_reason_);
211 ManagePasswordsUIController* manage_passwords_ui_controller = 204 ManagePasswordsUIController* manage_passwords_ui_controller =
212 ManagePasswordsUIController::FromWebContents(web_contents()); 205 ManagePasswordsUIController::FromWebContents(web_contents());
213 manage_passwords_ui_controller->NeverSavePassword(); 206 manage_passwords_ui_controller->NeverSavePassword();
214 state_ = password_manager::ui::BLACKLIST_STATE; 207 state_ = password_manager::ui::BLACKLIST_STATE;
215 } 208 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 292
300 // static 293 // static
301 int ManagePasswordsBubbleModel::UsernameFieldWidth() { 294 int ManagePasswordsBubbleModel::UsernameFieldWidth() {
302 return GetFieldWidth(USERNAME_FIELD); 295 return GetFieldWidth(USERNAME_FIELD);
303 } 296 }
304 297
305 // static 298 // static
306 int ManagePasswordsBubbleModel::PasswordFieldWidth() { 299 int ManagePasswordsBubbleModel::PasswordFieldWidth() {
307 return GetFieldWidth(PASSWORD_FIELD); 300 return GetFieldWidth(PASSWORD_FIELD);
308 } 301 }
302
303 base::string16
304 ManagePasswordsBubbleModel::PendingStateTitleBasedOnSavePasswordPref() const {
305 int message_id = 0;
306 if (never_save_passwords_)
307 message_id = IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE;
308 else if (IsNewUIActive())
309 message_id = IDS_PASSWORD_MANAGER_SAVE_PASSWORD_SMART_LOCK_PROMPT;
310 else
311 message_id = IDS_SAVE_PASSWORD;
312 return l10n_util::GetStringUTF16(message_id);
313 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698