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 "chrome/browser/password_manager/chrome_password_manager_client.h" | |
7 #include "components/password_manager/content/common/credential_manager_types.h" | 8 #include "components/password_manager/content/common/credential_manager_types.h" |
8 #include "components/password_manager/core/browser/browser_save_password_progres s_logger.h" | 9 #include "components/password_manager/core/browser/browser_save_password_progres s_logger.h" |
9 #include "components/password_manager/core/browser/password_form_manager.h" | 10 #include "components/password_manager/core/browser/password_form_manager.h" |
10 #include "components/password_manager/core/browser/password_manager_client.h" | |
11 | 11 |
12 using password_manager::PasswordFormManager; | 12 using password_manager::PasswordFormManager; |
13 using autofill::PasswordFormMap; | 13 using autofill::PasswordFormMap; |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // Converts the map with pointers or const pointers to the vector of const | 17 // Converts the map with pointers or const pointers to the vector of const |
18 // pointers. | 18 // pointers. |
19 template <typename T> | 19 template <typename T> |
20 std::vector<const T*> MapToVector( | 20 std::vector<const T*> MapToVector( |
(...skipping 56 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. | |
89 template <class Vector> | |
90 void InsertFormToVector(const autofill::PasswordForm* form, | |
91 Vector* forms) { | |
92 typename Vector::iterator it = form->blacklisted_by_user ? forms->begin() | |
93 : forms->end(); | |
94 forms->insert(it, form); | |
95 } | |
96 | |
87 } // namespace | 97 } // namespace |
88 | 98 |
89 ManagePasswordsState::ManagePasswordsState() | 99 ManagePasswordsState::ManagePasswordsState() |
90 : state_(password_manager::ui::INACTIVE_STATE), | 100 : state_(password_manager::ui::INACTIVE_STATE), |
91 client_(nullptr) { | 101 web_contents_(nullptr) { |
92 } | 102 } |
93 | 103 |
94 ManagePasswordsState::~ManagePasswordsState() {} | 104 ManagePasswordsState::~ManagePasswordsState() {} |
95 | 105 |
96 void ManagePasswordsState::OnPendingPassword( | 106 void ManagePasswordsState::OnPendingPassword( |
97 scoped_ptr<password_manager::PasswordFormManager> form_manager) { | 107 scoped_ptr<password_manager::PasswordFormManager> form_manager) { |
98 ClearData(); | 108 ClearData(); |
99 form_manager_ = form_manager.Pass(); | 109 form_manager_ = form_manager.Pass(); |
100 current_forms_weak_ = MapToVector(form_manager_->best_matches()); | 110 current_forms_weak_ = MapToVector(form_manager_->best_matches()); |
101 origin_ = form_manager_->pending_credentials().origin; | 111 origin_ = form_manager_->pending_credentials().origin; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 SetState(password_manager::ui::MANAGE_STATE); | 161 SetState(password_manager::ui::MANAGE_STATE); |
152 } | 162 } |
153 } | 163 } |
154 | 164 |
155 void ManagePasswordsState::OnBlacklistBlockedAutofill( | 165 void ManagePasswordsState::OnBlacklistBlockedAutofill( |
156 const autofill::PasswordFormMap& password_form_map) { | 166 const autofill::PasswordFormMap& password_form_map) { |
157 DCHECK(!password_form_map.empty()); | 167 DCHECK(!password_form_map.empty()); |
158 ClearData(); | 168 ClearData(); |
159 local_credentials_forms_ = DeepCopyMapToVector(password_form_map); | 169 local_credentials_forms_ = DeepCopyMapToVector(password_form_map); |
160 origin_ = local_credentials_forms_.front()->origin; | 170 origin_ = local_credentials_forms_.front()->origin; |
171 DCHECK(local_credentials_forms_.front()->blacklisted_by_user); | |
vabr (Chromium)
2015/03/17 09:25:57
Why is this important?
vasilii
2015/03/17 10:49:48
If you look at the current code in ManagePasswords
vabr (Chromium)
2015/03/17 11:55:13
Thanks for explaining. I added some further commen
| |
161 SetState(password_manager::ui::BLACKLIST_STATE); | 172 SetState(password_manager::ui::BLACKLIST_STATE); |
162 } | 173 } |
163 | 174 |
164 void ManagePasswordsState::OnInactive() { | 175 void ManagePasswordsState::OnInactive() { |
165 ClearData(); | 176 ClearData(); |
166 origin_ = GURL(); | 177 origin_ = GURL(); |
167 SetState(password_manager::ui::INACTIVE_STATE); | 178 SetState(password_manager::ui::INACTIVE_STATE); |
168 } | 179 } |
169 | 180 |
170 void ManagePasswordsState::TransitionToState( | 181 void ManagePasswordsState::TransitionToState( |
171 password_manager::ui::State state) { | 182 password_manager::ui::State state) { |
172 DCHECK_NE(password_manager::ui::INACTIVE_STATE, state_); | 183 DCHECK_NE(password_manager::ui::INACTIVE_STATE, state_); |
173 DCHECK(state == password_manager::ui::BLACKLIST_STATE || | 184 DCHECK(state == password_manager::ui::BLACKLIST_STATE || |
174 state == password_manager::ui::MANAGE_STATE); | 185 state == password_manager::ui::MANAGE_STATE); |
175 if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE && | 186 if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
176 !credentials_callback_.is_null()) { | 187 if (!credentials_callback_.is_null()) { |
177 credentials_callback_.Run(password_manager::CredentialInfo()); | 188 credentials_callback_.Run(password_manager::CredentialInfo()); |
178 credentials_callback_.Reset(); | 189 credentials_callback_.Reset(); |
190 } | |
191 federated_credentials_forms_.clear(); | |
179 } | 192 } |
180 SetState(state); | 193 SetState(state); |
181 } | 194 } |
182 | 195 |
183 void ManagePasswordsState::ProcessLoginsChanged( | 196 void ManagePasswordsState::ProcessLoginsChanged( |
184 const password_manager::PasswordStoreChangeList& changes) { | 197 const password_manager::PasswordStoreChangeList& changes) { |
185 if (state() == password_manager::ui::INACTIVE_STATE) | 198 if (state() == password_manager::ui::INACTIVE_STATE) |
186 return; | 199 return; |
187 | 200 |
188 for (const password_manager::PasswordStoreChange& change : changes) { | 201 for (const password_manager::PasswordStoreChange& change : changes) { |
(...skipping 24 matching lines...) Expand all Loading... | |
213 local_credentials_forms_.clear(); | 226 local_credentials_forms_.clear(); |
214 federated_credentials_forms_.clear(); | 227 federated_credentials_forms_.clear(); |
215 credentials_callback_.Reset(); | 228 credentials_callback_.Reset(); |
216 } | 229 } |
217 | 230 |
218 void ManagePasswordsState::AddForm(const autofill::PasswordForm& form) { | 231 void ManagePasswordsState::AddForm(const autofill::PasswordForm& form) { |
219 if (form.origin != origin_) | 232 if (form.origin != origin_) |
220 return; | 233 return; |
221 if (UpdateForm(form)) | 234 if (UpdateForm(form)) |
222 return; | 235 return; |
223 local_credentials_forms_.push_back(new autofill::PasswordForm(form)); | 236 if (form_manager_) { |
224 if (form_manager_) | 237 local_credentials_forms_.push_back(new autofill::PasswordForm(form)); |
225 current_forms_weak_.push_back(local_credentials_forms_.back()); | 238 InsertFormToVector(local_credentials_forms_.back(), ¤t_forms_weak_); |
239 } else { | |
240 InsertFormToVector(new autofill::PasswordForm(form), | |
241 &local_credentials_forms_); | |
242 } | |
226 } | 243 } |
227 | 244 |
228 bool ManagePasswordsState::UpdateForm(const autofill::PasswordForm& form) { | 245 bool ManagePasswordsState::UpdateForm(const autofill::PasswordForm& form) { |
229 if (form_manager_) { | 246 if (form_manager_) { |
230 // |current_forms_weak_| contains the list of current passwords. | 247 // |current_forms_weak_| contains the list of current passwords. |
231 std::vector<const autofill::PasswordForm*>::iterator it = std::find_if( | 248 std::vector<const autofill::PasswordForm*>::iterator it = std::find_if( |
232 current_forms_weak_.begin(), current_forms_weak_.end(), | 249 current_forms_weak_.begin(), current_forms_weak_.end(), |
233 [&form](const autofill::PasswordForm* current_form) { | 250 [&form](const autofill::PasswordForm* current_form) { |
234 return IsEqualUniqueKey(form, *current_form); | 251 return IsEqualUniqueKey(form, *current_form); |
235 }); | 252 }); |
(...skipping 12 matching lines...) Expand all Loading... | |
248 return false; | 265 return false; |
249 } | 266 } |
250 | 267 |
251 void ManagePasswordsState::DeleteForm(const autofill::PasswordForm& form) { | 268 void ManagePasswordsState::DeleteForm(const autofill::PasswordForm& form) { |
252 RemoveFormFromVector(form, ¤t_forms_weak_); | 269 RemoveFormFromVector(form, ¤t_forms_weak_); |
253 RemoveFormFromVector(form, &local_credentials_forms_); | 270 RemoveFormFromVector(form, &local_credentials_forms_); |
254 RemoveFormFromVector(form, &federated_credentials_forms_); | 271 RemoveFormFromVector(form, &federated_credentials_forms_); |
255 } | 272 } |
256 | 273 |
257 void ManagePasswordsState::SetState(password_manager::ui::State state) { | 274 void ManagePasswordsState::SetState(password_manager::ui::State state) { |
258 if (client_ && client_->IsLoggingActive()) { | 275 password_manager::PasswordManagerClient* client = |
vabr (Chromium)
2015/03/17 09:25:57
Why the change from getting the client directly to
vasilii
2015/03/17 10:49:48
I changed it back so the tests set it too.
| |
259 password_manager::BrowserSavePasswordProgressLogger logger(client_); | 276 web_contents_ ? |
277 ChromePasswordManagerClient::FromWebContents(web_contents_) : nullptr; | |
278 // |client| might be NULL in tests. | |
279 if (client && client->IsLoggingActive()) { | |
280 password_manager::BrowserSavePasswordProgressLogger logger(client); | |
260 logger.LogNumber( | 281 logger.LogNumber( |
261 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE, | 282 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE, |
262 state); | 283 state); |
263 } | 284 } |
264 state_ = state; | 285 state_ = state; |
265 } | 286 } |
OLD | NEW |