Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/password_manager/password_manager.h" | 5 #include "chrome/browser/password_manager/password_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
| 14 #include "chrome/browser/password_manager/password_form_manager.h" | 14 #include "chrome/browser/password_manager/password_form_manager.h" |
| 15 #include "chrome/browser/password_manager/password_manager_delegate.h" | 15 #include "chrome/browser/password_manager/password_manager_delegate.h" |
| 16 #include "chrome/browser/password_manager/password_manager_metrics_util.h" | 16 #include "chrome/browser/password_manager/password_manager_metrics_util.h" |
| 17 #include "chrome/browser/password_manager/password_store.h" | |
| 18 #include "chrome/browser/password_manager/password_store_factory.h" | |
| 17 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" | 20 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" |
| 19 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
| 21 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 22 #include "components/autofill/core/common/autofill_messages.h" | 24 #include "components/autofill/core/common/autofill_messages.h" |
| 23 #include "components/user_prefs/pref_registry_syncable.h" | 25 #include "components/user_prefs/pref_registry_syncable.h" |
| 24 #include "content/public/browser/navigation_details.h" | 26 #include "content/public/browser/navigation_details.h" |
| 25 #include "content/public/browser/user_metrics.h" | 27 #include "content/public/browser/user_metrics.h" |
| 26 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 | 258 |
| 257 bool PasswordManager::OnMessageReceived(const IPC::Message& message) { | 259 bool PasswordManager::OnMessageReceived(const IPC::Message& message) { |
| 258 bool handled = true; | 260 bool handled = true; |
| 259 IPC_BEGIN_MESSAGE_MAP(PasswordManager, message) | 261 IPC_BEGIN_MESSAGE_MAP(PasswordManager, message) |
| 260 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordFormsParsed, | 262 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordFormsParsed, |
| 261 OnPasswordFormsParsed) | 263 OnPasswordFormsParsed) |
| 262 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordFormsRendered, | 264 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordFormsRendered, |
| 263 OnPasswordFormsRendered) | 265 OnPasswordFormsRendered) |
| 264 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordFormSubmitted, | 266 IPC_MESSAGE_HANDLER(AutofillHostMsg_PasswordFormSubmitted, |
| 265 OnPasswordFormSubmitted) | 267 OnPasswordFormSubmitted) |
| 268 IPC_MESSAGE_HANDLER(AutofillHostMsg_RemovePasswordSuggestion, | |
| 269 OnRemovePasswordSuggestion) | |
| 266 IPC_MESSAGE_UNHANDLED(handled = false) | 270 IPC_MESSAGE_UNHANDLED(handled = false) |
| 267 IPC_END_MESSAGE_MAP() | 271 IPC_END_MESSAGE_MAP() |
| 268 return handled; | 272 return handled; |
| 269 } | 273 } |
| 270 | 274 |
| 271 void PasswordManager::OnPasswordFormSubmitted( | 275 void PasswordManager::OnPasswordFormSubmitted( |
| 272 const PasswordForm& password_form) { | 276 const PasswordForm& password_form) { |
| 273 ProvisionallySavePassword(password_form); | 277 ProvisionallySavePassword(password_form); |
| 274 for (size_t i = 0; i < submission_callbacks_.size(); ++i) { | 278 for (size_t i = 0; i < submission_callbacks_.size(); ++i) { |
| 275 submission_callbacks_[i].Run(password_form); | 279 submission_callbacks_[i].Run(password_form); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 295 new PasswordFormManager(delegate_->GetProfile(), | 299 new PasswordFormManager(delegate_->GetProfile(), |
| 296 this, | 300 this, |
| 297 web_contents(), | 301 web_contents(), |
| 298 *iter, | 302 *iter, |
| 299 ssl_valid); | 303 ssl_valid); |
| 300 pending_login_managers_.push_back(manager); | 304 pending_login_managers_.push_back(manager); |
| 301 manager->FetchMatchingLoginsFromPasswordStore(); | 305 manager->FetchMatchingLoginsFromPasswordStore(); |
| 302 } | 306 } |
| 303 } | 307 } |
| 304 | 308 |
| 309 void PasswordManager::OnRemovePasswordSuggestion( | |
| 310 const PasswordForm& password_form, | |
| 311 std::vector<PasswordForm> updated_password_forms) { | |
| 312 scoped_refptr<PasswordStore> password_store = | |
| 313 PasswordStoreFactory::GetForProfile(delegate_->GetProfile(), | |
| 314 Profile::EXPLICIT_ACCESS); | |
| 315 | |
| 316 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = | |
| 317 ManagePasswordsBubbleUIController::FromWebContents(web_contents()); | |
| 318 if (manage_passwords_bubble_ui_controller) { | |
| 319 manage_passwords_bubble_ui_controller->RemoveFromBestMatches(password_form); | |
| 320 } | |
| 321 | |
| 322 // Deleting the PasswordFormManager for the current |password_form| to avoid | |
| 323 // that we have two PasswordFormManager for it: | |
| 324 // AutofillHostMsg_PasswordFormsParsed is going to be recived in the near | |
|
vabr (Chromium)
2014/03/07 23:43:36
typos: recived, genrate
riadh.chtara
2014/03/14 17:16:08
Done.
| |
| 325 // future to update the current form and this is going to genrate a new | |
| 326 // PasswordFormManager | |
|
vabr (Chromium)
2014/03/07 23:43:36
Please end sentences with a full stop.
riadh.chtara
2014/03/14 17:16:08
Done.
| |
| 327 | |
| 328 std::vector<PasswordFormManager*> not_yet_updated; | |
| 329 bool removed = false; | |
| 330 for (ScopedVector<PasswordFormManager>::iterator iter = | |
| 331 pending_login_managers_.begin(); | |
| 332 iter != pending_login_managers_.end(); | |
| 333 iter++) { | |
|
vabr (Chromium)
2014/03/07 23:43:36
nit: prefer prefix increment ++iter to postfix ite
riadh.chtara
2014/03/14 17:16:08
Done.
| |
| 334 | |
| 335 if ((*iter)->DoesManage(password_form, | |
| 336 PasswordFormManager::ACTION_MATCH_REQUIRED)) { | |
| 337 if (!removed) { | |
| 338 (*iter)->RemoveAndUpdate(password_form.username_value); | |
| 339 removed = true; | |
| 340 } else { | |
| 341 (*iter)->Update(password_form.username_value); | |
| 342 } | |
| 343 } else { | |
| 344 not_yet_updated.push_back(*iter); | |
| 345 } | |
| 346 } | |
| 347 | |
| 348 if (removed) { | |
| 349 for (std::vector<PasswordFormManager*>::iterator pfm = | |
|
vabr (Chromium)
2014/03/07 23:43:36
Please do not use abbreviations like 'pfm' or 'pf'
riadh.chtara
2014/03/14 17:16:08
Done.
| |
| 350 not_yet_updated.begin(); | |
| 351 pfm != not_yet_updated.end(); | |
| 352 pfm++) { | |
| 353 for (std::vector<PasswordForm>::iterator pf = | |
| 354 updated_password_forms.begin(); | |
| 355 pf != updated_password_forms.end();) { | |
| 356 if ((*pfm) | |
| 357 ->DoesManage(*pf, PasswordFormManager::ACTION_MATCH_REQUIRED)) { | |
| 358 | |
| 359 (*pfm)->Update(password_form.username_value); | |
| 360 pf = updated_password_forms.erase(pf); | |
|
vabr (Chromium)
2014/03/07 23:43:36
Single element deleting in vector is most of the t
riadh.chtara
2014/03/14 17:16:08
Done.
| |
| 361 | |
|
vabr (Chromium)
2014/03/07 23:43:36
nit: remove blank line
riadh.chtara
2014/03/14 17:16:08
Done.
| |
| 362 } else { | |
| 363 pf++; | |
| 364 | |
| 365 } | |
| 366 | |
| 367 } | |
| 368 } | |
| 369 | |
| 370 } | |
| 371 } | |
| 372 | |
| 373 | |
| 305 bool PasswordManager::ShouldShowSavePasswordInfoBar() const { | 374 bool PasswordManager::ShouldShowSavePasswordInfoBar() const { |
| 306 return provisional_save_manager_->IsNewLogin() && | 375 return provisional_save_manager_->IsNewLogin() && |
| 307 !provisional_save_manager_->HasGeneratedPassword() && | 376 !provisional_save_manager_->HasGeneratedPassword() && |
| 308 !provisional_save_manager_->IsPendingCredentialsPublicSuffixMatch(); | 377 !provisional_save_manager_->IsPendingCredentialsPublicSuffixMatch(); |
| 309 } | 378 } |
| 310 | 379 |
| 311 void PasswordManager::OnPasswordFormsRendered( | 380 void PasswordManager::OnPasswordFormsRendered( |
| 312 const std::vector<PasswordForm>& visible_forms) { | 381 const std::vector<PasswordForm>& visible_forms) { |
| 313 if (!provisional_save_manager_.get()) | 382 if (!provisional_save_manager_.get()) |
| 314 return; | 383 return; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 } | 493 } |
| 425 | 494 |
| 426 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = | 495 ManagePasswordsBubbleUIController* manage_passwords_bubble_ui_controller = |
| 427 ManagePasswordsBubbleUIController::FromWebContents(web_contents()); | 496 ManagePasswordsBubbleUIController::FromWebContents(web_contents()); |
| 428 if (manage_passwords_bubble_ui_controller && | 497 if (manage_passwords_bubble_ui_controller && |
| 429 CommandLine::ForCurrentProcess()->HasSwitch( | 498 CommandLine::ForCurrentProcess()->HasSwitch( |
| 430 switches::kEnableSavePasswordBubble)) { | 499 switches::kEnableSavePasswordBubble)) { |
| 431 manage_passwords_bubble_ui_controller->OnPasswordAutofilled(best_matches); | 500 manage_passwords_bubble_ui_controller->OnPasswordAutofilled(best_matches); |
| 432 } | 501 } |
| 433 } | 502 } |
| OLD | NEW |