| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #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" |
| 10 #include "components/password_manager/core/browser/log_manager.h" | 10 #include "components/password_manager/core/browser/log_manager.h" |
| 11 #include "components/password_manager/core/browser/password_form_manager.h" | 11 #include "components/password_manager/core/browser/password_form_manager.h" |
| 12 #include "components/password_manager/core/browser/password_manager.h" | 12 #include "components/password_manager/core/browser/password_manager.h" |
| 13 #include "components/password_manager/core/browser/password_manager_client.h" | 13 #include "components/password_manager/core/browser/password_manager_client.h" |
| 14 #include "components/password_manager/core/common/credential_manager_types.h" | |
| 15 | 14 |
| 16 using password_manager::PasswordFormManager; | 15 using password_manager::PasswordFormManager; |
| 17 using autofill::PasswordFormMap; | 16 using autofill::PasswordFormMap; |
| 18 | 17 |
| 19 namespace { | 18 namespace { |
| 20 | 19 |
| 21 // Returns a vector containing the values of a map. | 20 // Returns a vector containing the values of a map. |
| 22 template <typename Map> | 21 template <typename Map> |
| 23 std::vector<typename Map::mapped_type> MapToVector(const Map& map) { | 22 std::vector<typename Map::mapped_type> MapToVector(const Map& map) { |
| 24 std::vector<typename Map::mapped_type> ret; | 23 std::vector<typename Map::mapped_type> ret; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 origin_ = GURL(); | 200 origin_ = GURL(); |
| 202 SetState(password_manager::ui::INACTIVE_STATE); | 201 SetState(password_manager::ui::INACTIVE_STATE); |
| 203 } | 202 } |
| 204 | 203 |
| 205 void ManagePasswordsState::TransitionToState( | 204 void ManagePasswordsState::TransitionToState( |
| 206 password_manager::ui::State state) { | 205 password_manager::ui::State state) { |
| 207 DCHECK_NE(password_manager::ui::INACTIVE_STATE, state_); | 206 DCHECK_NE(password_manager::ui::INACTIVE_STATE, state_); |
| 208 DCHECK_EQ(password_manager::ui::MANAGE_STATE, state); | 207 DCHECK_EQ(password_manager::ui::MANAGE_STATE, state); |
| 209 if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { | 208 if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
| 210 if (!credentials_callback_.is_null()) { | 209 if (!credentials_callback_.is_null()) { |
| 211 credentials_callback_.Run(password_manager::CredentialInfo()); | 210 credentials_callback_.Run(nullptr); |
| 212 credentials_callback_.Reset(); | 211 credentials_callback_.Reset(); |
| 213 } | 212 } |
| 214 federated_credentials_forms_.clear(); | 213 federated_credentials_forms_.clear(); |
| 215 } | 214 } |
| 216 SetState(state); | 215 SetState(state); |
| 217 } | 216 } |
| 218 | 217 |
| 219 void ManagePasswordsState::ProcessLoginsChanged( | 218 void ManagePasswordsState::ProcessLoginsChanged( |
| 220 const password_manager::PasswordStoreChangeList& changes) { | 219 const password_manager::PasswordStoreChangeList& changes) { |
| 221 if (state() == password_manager::ui::INACTIVE_STATE) | 220 if (state() == password_manager::ui::INACTIVE_STATE) |
| 222 return; | 221 return; |
| 223 | 222 |
| 224 for (const password_manager::PasswordStoreChange& change : changes) { | 223 for (const password_manager::PasswordStoreChange& change : changes) { |
| 225 const autofill::PasswordForm& changed_form = change.form(); | 224 const autofill::PasswordForm& changed_form = change.form(); |
| 226 if (changed_form.blacklisted_by_user) | 225 if (changed_form.blacklisted_by_user) |
| 227 continue; | 226 continue; |
| 228 if (change.type() == password_manager::PasswordStoreChange::REMOVE) { | 227 if (change.type() == password_manager::PasswordStoreChange::REMOVE) { |
| 229 DeleteForm(changed_form); | 228 DeleteForm(changed_form); |
| 230 } else { | 229 } else { |
| 231 if (change.type() == password_manager::PasswordStoreChange::UPDATE) | 230 if (change.type() == password_manager::PasswordStoreChange::UPDATE) |
| 232 UpdateForm(changed_form); | 231 UpdateForm(changed_form); |
| 233 else | 232 else |
| 234 AddForm(changed_form); | 233 AddForm(changed_form); |
| 235 } | 234 } |
| 236 } | 235 } |
| 237 } | 236 } |
| 238 | 237 |
| 239 void ManagePasswordsState::ChooseCredential( | 238 void ManagePasswordsState::ChooseCredential( |
| 240 const autofill::PasswordForm& form, | 239 const autofill::PasswordForm* form) { |
| 241 password_manager::CredentialType credential_type) { | |
| 242 DCHECK_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, state()); | 240 DCHECK_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE, state()); |
| 243 DCHECK(!credentials_callback().is_null()); | 241 DCHECK(!credentials_callback().is_null()); |
| 244 | 242 |
| 245 // Here, |credential_type| refers to whether the credential was originally | 243 credentials_callback().Run(form); |
| 246 // passed into ::OnRequestCredentials as part of the |local_credentials| or | |
| 247 // |federated_credentials| lists (e.g. whether it is an existing credential | |
| 248 // saved for this origin, or whether we should synthesize a new | |
| 249 // FederatedCredential). | |
| 250 // | |
| 251 // If |credential_type| is federated, the credential MUST be returned as | |
| 252 // a FederatedCredential in order to prevent password information leaking | |
| 253 // cross-origin. | |
| 254 // | |
| 255 // If |credential_type| is local, the credential MIGHT be a PasswordCredential | |
| 256 // or it MIGHT be a FederatedCredential. We inspect the |federation_origin| | |
| 257 // field to determine which we should return. | |
| 258 // | |
| 259 // TODO(mkwst): Clean this up. It is confusing. | |
| 260 password_manager::CredentialType type_to_return; | |
| 261 if (credential_type == | |
| 262 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD && | |
| 263 form.federation_origin.unique()) { | |
| 264 type_to_return = password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD; | |
| 265 } else if (credential_type == | |
| 266 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY) { | |
| 267 type_to_return = password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY; | |
| 268 } else { | |
| 269 type_to_return = | |
| 270 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED; | |
| 271 } | |
| 272 password_manager::CredentialInfo info = | |
| 273 password_manager::CredentialInfo(form, type_to_return); | |
| 274 credentials_callback().Run(info); | |
| 275 set_credentials_callback(ManagePasswordsState::CredentialsCallback()); | 244 set_credentials_callback(ManagePasswordsState::CredentialsCallback()); |
| 276 } | 245 } |
| 277 | 246 |
| 278 void ManagePasswordsState::ClearData() { | 247 void ManagePasswordsState::ClearData() { |
| 279 form_manager_.reset(); | 248 form_manager_.reset(); |
| 280 current_forms_weak_.clear(); | 249 current_forms_weak_.clear(); |
| 281 local_credentials_forms_.clear(); | 250 local_credentials_forms_.clear(); |
| 282 federated_credentials_forms_.clear(); | 251 federated_credentials_forms_.clear(); |
| 283 credentials_callback_.Reset(); | 252 credentials_callback_.Reset(); |
| 284 } | 253 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 DCHECK(client_); | 298 DCHECK(client_); |
| 330 if (client_->GetLogManager()->IsLoggingActive()) { | 299 if (client_->GetLogManager()->IsLoggingActive()) { |
| 331 password_manager::BrowserSavePasswordProgressLogger logger( | 300 password_manager::BrowserSavePasswordProgressLogger logger( |
| 332 client_->GetLogManager()); | 301 client_->GetLogManager()); |
| 333 logger.LogNumber( | 302 logger.LogNumber( |
| 334 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE, | 303 autofill::SavePasswordProgressLogger::STRING_NEW_UI_STATE, |
| 335 state); | 304 state); |
| 336 } | 305 } |
| 337 state_ = state; | 306 state_ = state; |
| 338 } | 307 } |
| OLD | NEW |