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 #include "chrome/browser/ui/passwords/manage_passwords_state.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_state.h" |
6 | 6 |
7 #include "components/password_manager/content/common/credential_manager_types.h" | 7 #include "components/password_manager/content/common/credential_manager_types.h" |
8 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" | 8 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" |
9 #include "components/password_manager/core/browser/password_form_manager.h" | 9 #include "components/password_manager/core/browser/password_form_manager.h" |
10 #include "components/password_manager/core/browser/password_manager_client.h" | 10 #include "components/password_manager/core/browser/password_manager_client.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 Vector* forms) { | 77 Vector* forms) { |
78 typename Vector::iterator it = std::find_if( | 78 typename Vector::iterator it = std::find_if( |
79 forms->begin(), forms->end(), | 79 forms->begin(), forms->end(), |
80 [&form_to_delete](const autofill::PasswordForm* form) { | 80 [&form_to_delete](const autofill::PasswordForm* form) { |
81 return IsEqualUniqueKey(*form, form_to_delete); | 81 return IsEqualUniqueKey(*form, form_to_delete); |
82 }); | 82 }); |
83 if (it != forms->end()) | 83 if (it != forms->end()) |
84 forms->erase(it); | 84 forms->erase(it); |
85 } | 85 } |
86 | 86 |
| 87 // Inserts |form| to the beginning of |forms| if it's blacklisted or to the end |
| 88 // otherwise. UnblacklistSite() expects the first saved password to be the |
| 89 // blacklisted credential. |
| 90 template <class Vector> |
| 91 void InsertFormToVector(const autofill::PasswordForm* form, |
| 92 Vector* forms) { |
| 93 typename Vector::iterator it = form->blacklisted_by_user ? forms->begin() |
| 94 : forms->end(); |
| 95 forms->insert(it, form); |
| 96 } |
| 97 |
87 } // namespace | 98 } // namespace |
88 | 99 |
89 ManagePasswordsState::ManagePasswordsState() | 100 ManagePasswordsState::ManagePasswordsState() |
90 : state_(password_manager::ui::INACTIVE_STATE), | 101 : state_(password_manager::ui::INACTIVE_STATE), |
91 client_(nullptr) { | 102 client_(nullptr) { |
92 } | 103 } |
93 | 104 |
94 ManagePasswordsState::~ManagePasswordsState() {} | 105 ManagePasswordsState::~ManagePasswordsState() {} |
95 | 106 |
96 void ManagePasswordsState::OnPendingPassword( | 107 void ManagePasswordsState::OnPendingPassword( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 SetState(password_manager::ui::MANAGE_STATE); | 162 SetState(password_manager::ui::MANAGE_STATE); |
152 } | 163 } |
153 } | 164 } |
154 | 165 |
155 void ManagePasswordsState::OnBlacklistBlockedAutofill( | 166 void ManagePasswordsState::OnBlacklistBlockedAutofill( |
156 const autofill::PasswordFormMap& password_form_map) { | 167 const autofill::PasswordFormMap& password_form_map) { |
157 DCHECK(!password_form_map.empty()); | 168 DCHECK(!password_form_map.empty()); |
158 ClearData(); | 169 ClearData(); |
159 local_credentials_forms_ = DeepCopyMapToVector(password_form_map); | 170 local_credentials_forms_ = DeepCopyMapToVector(password_form_map); |
160 origin_ = local_credentials_forms_.front()->origin; | 171 origin_ = local_credentials_forms_.front()->origin; |
| 172 DCHECK(local_credentials_forms_.front()->blacklisted_by_user); |
161 SetState(password_manager::ui::BLACKLIST_STATE); | 173 SetState(password_manager::ui::BLACKLIST_STATE); |
162 } | 174 } |
163 | 175 |
164 void ManagePasswordsState::OnInactive() { | 176 void ManagePasswordsState::OnInactive() { |
165 ClearData(); | 177 ClearData(); |
166 origin_ = GURL(); | 178 origin_ = GURL(); |
167 SetState(password_manager::ui::INACTIVE_STATE); | 179 SetState(password_manager::ui::INACTIVE_STATE); |
168 } | 180 } |
169 | 181 |
170 void ManagePasswordsState::TransitionToState( | 182 void ManagePasswordsState::TransitionToState( |
171 password_manager::ui::State state) { | 183 password_manager::ui::State state) { |
172 DCHECK_NE(password_manager::ui::INACTIVE_STATE, state_); | 184 DCHECK_NE(password_manager::ui::INACTIVE_STATE, state_); |
173 DCHECK(state == password_manager::ui::BLACKLIST_STATE || | 185 DCHECK(state == password_manager::ui::BLACKLIST_STATE || |
174 state == password_manager::ui::MANAGE_STATE); | 186 state == password_manager::ui::MANAGE_STATE); |
175 if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE && | 187 if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
176 !credentials_callback_.is_null()) { | 188 if (!credentials_callback_.is_null()) { |
177 credentials_callback_.Run(password_manager::CredentialInfo()); | 189 credentials_callback_.Run(password_manager::CredentialInfo()); |
178 credentials_callback_.Reset(); | 190 credentials_callback_.Reset(); |
| 191 } |
| 192 federated_credentials_forms_.clear(); |
179 } | 193 } |
180 SetState(state); | 194 SetState(state); |
181 } | 195 } |
182 | 196 |
183 void ManagePasswordsState::ProcessLoginsChanged( | 197 void ManagePasswordsState::ProcessLoginsChanged( |
184 const password_manager::PasswordStoreChangeList& changes) { | 198 const password_manager::PasswordStoreChangeList& changes) { |
185 if (state() == password_manager::ui::INACTIVE_STATE) | 199 if (state() == password_manager::ui::INACTIVE_STATE) |
186 return; | 200 return; |
187 | 201 |
188 for (const password_manager::PasswordStoreChange& change : changes) { | 202 for (const password_manager::PasswordStoreChange& change : changes) { |
(...skipping 24 matching lines...) Expand all Loading... |
213 local_credentials_forms_.clear(); | 227 local_credentials_forms_.clear(); |
214 federated_credentials_forms_.clear(); | 228 federated_credentials_forms_.clear(); |
215 credentials_callback_.Reset(); | 229 credentials_callback_.Reset(); |
216 } | 230 } |
217 | 231 |
218 void ManagePasswordsState::AddForm(const autofill::PasswordForm& form) { | 232 void ManagePasswordsState::AddForm(const autofill::PasswordForm& form) { |
219 if (form.origin != origin_) | 233 if (form.origin != origin_) |
220 return; | 234 return; |
221 if (UpdateForm(form)) | 235 if (UpdateForm(form)) |
222 return; | 236 return; |
223 local_credentials_forms_.push_back(new autofill::PasswordForm(form)); | 237 if (form_manager_) { |
224 if (form_manager_) | 238 local_credentials_forms_.push_back(new autofill::PasswordForm(form)); |
225 current_forms_weak_.push_back(local_credentials_forms_.back()); | 239 InsertFormToVector(local_credentials_forms_.back(), ¤t_forms_weak_); |
| 240 } else { |
| 241 InsertFormToVector(new autofill::PasswordForm(form), |
| 242 &local_credentials_forms_); |
| 243 } |
226 } | 244 } |
227 | 245 |
228 bool ManagePasswordsState::UpdateForm(const autofill::PasswordForm& form) { | 246 bool ManagePasswordsState::UpdateForm(const autofill::PasswordForm& form) { |
229 if (form_manager_) { | 247 if (form_manager_) { |
230 // |current_forms_weak_| contains the list of current passwords. | 248 // |current_forms_weak_| contains the list of current passwords. |
231 std::vector<const autofill::PasswordForm*>::iterator it = std::find_if( | 249 std::vector<const autofill::PasswordForm*>::iterator it = std::find_if( |
232 current_forms_weak_.begin(), current_forms_weak_.end(), | 250 current_forms_weak_.begin(), current_forms_weak_.end(), |
233 [&form](const autofill::PasswordForm* current_form) { | 251 [&form](const autofill::PasswordForm* current_form) { |
234 return IsEqualUniqueKey(form, *current_form); | 252 return IsEqualUniqueKey(form, *current_form); |
235 }); | 253 }); |
(...skipping 12 matching lines...) Expand all Loading... |
248 return false; | 266 return false; |
249 } | 267 } |
250 | 268 |
251 void ManagePasswordsState::DeleteForm(const autofill::PasswordForm& form) { | 269 void ManagePasswordsState::DeleteForm(const autofill::PasswordForm& form) { |
252 RemoveFormFromVector(form, ¤t_forms_weak_); | 270 RemoveFormFromVector(form, ¤t_forms_weak_); |
253 RemoveFormFromVector(form, &local_credentials_forms_); | 271 RemoveFormFromVector(form, &local_credentials_forms_); |
254 RemoveFormFromVector(form, &federated_credentials_forms_); | 272 RemoveFormFromVector(form, &federated_credentials_forms_); |
255 } | 273 } |
256 | 274 |
257 void ManagePasswordsState::SetState(password_manager::ui::State state) { | 275 void ManagePasswordsState::SetState(password_manager::ui::State state) { |
258 if (client_ && client_->IsLoggingActive()) { | 276 DCHECK(client_); |
| 277 if (client_->IsLoggingActive()) { |
259 password_manager::BrowserSavePasswordProgressLogger logger(client_); | 278 password_manager::BrowserSavePasswordProgressLogger logger(client_); |
260 logger.LogNumber( | 279 logger.LogNumber( |
261 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE, | 280 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE, |
262 state); | 281 state); |
263 } | 282 } |
264 state_ = state; | 283 state_ = state; |
265 } | 284 } |
OLD | NEW |