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_form_manager.h" | 5 #include "chrome/browser/password_manager/password_form_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 observed_form_(observed_form), | 32 observed_form_(observed_form), |
| 33 is_new_login_(true), | 33 is_new_login_(true), |
| 34 has_generated_password_(false), | 34 has_generated_password_(false), |
| 35 password_manager_(password_manager), | 35 password_manager_(password_manager), |
| 36 preferred_match_(NULL), | 36 preferred_match_(NULL), |
| 37 state_(PRE_MATCHING_PHASE), | 37 state_(PRE_MATCHING_PHASE), |
| 38 profile_(profile), | 38 profile_(profile), |
| 39 web_contents_(web_contents), | 39 web_contents_(web_contents), |
| 40 manager_action_(kManagerActionNone), | 40 manager_action_(kManagerActionNone), |
| 41 user_action_(kUserActionNone), | 41 user_action_(kUserActionNone), |
| 42 submit_result_(kSubmitResultNotSubmitted) { | 42 submit_result_(kSubmitResultNotSubmitted), |
| 43 should_save_password_(false), | |
| 44 should_blacklist_password_(false) { | |
| 43 DCHECK(profile_); | 45 DCHECK(profile_); |
| 44 if (observed_form_.origin.is_valid()) | 46 if (observed_form_.origin.is_valid()) |
| 45 base::SplitString(observed_form_.origin.path(), '/', &form_path_tokens_); | 47 base::SplitString(observed_form_.origin.path(), '/', &form_path_tokens_); |
| 46 observed_form_.ssl_valid = ssl_valid; | 48 observed_form_.ssl_valid = ssl_valid; |
| 47 } | 49 } |
| 48 | 50 |
| 49 PasswordFormManager::~PasswordFormManager() { | 51 PasswordFormManager::~PasswordFormManager() { |
| 50 UMA_HISTOGRAM_ENUMERATION("PasswordManager.ActionsTaken", | 52 UMA_HISTOGRAM_ENUMERATION("PasswordManager.ActionsTaken", |
| 51 GetActionsTaken(), | 53 GetActionsTaken(), |
| 52 kMaxNumActionsTaken); | 54 kMaxNumActionsTaken); |
| 55 // In case the tab is closed before the next navigation occurs this will | |
| 56 // apply outstanding changes. | |
| 57 if (should_save_password_ || should_blacklist_password_) | |
| 58 ApplyChange(); | |
| 53 } | 59 } |
| 54 | 60 |
| 55 int PasswordFormManager::GetActionsTaken() { | 61 int PasswordFormManager::GetActionsTaken() { |
| 56 return user_action_ + kUserActionMax * (manager_action_ + | 62 return user_action_ + kUserActionMax * (manager_action_ + |
| 57 kManagerActionMax * submit_result_); | 63 kManagerActionMax * submit_result_); |
| 58 }; | 64 }; |
| 59 | 65 |
| 60 // TODO(timsteele): use a hash of some sort in the future? | 66 // TODO(timsteele): use a hash of some sort in the future? |
| 61 bool PasswordFormManager::DoesManage(const PasswordForm& form, | 67 bool PasswordFormManager::DoesManage(const PasswordForm& form, |
| 62 ActionMatch action_match) const { | 68 ActionMatch action_match) const { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 form.origin.spec().end(), | 105 form.origin.spec().end(), |
| 100 after_scheme2, | 106 after_scheme2, |
| 101 observed_form_.origin.spec().end()) | 107 observed_form_.origin.spec().end()) |
| 102 != form.origin.spec().end(); | 108 != form.origin.spec().end(); |
| 103 } | 109 } |
| 104 return false; | 110 return false; |
| 105 } | 111 } |
| 106 return true; | 112 return true; |
| 107 } | 113 } |
| 108 | 114 |
| 115 void PasswordFormManager::ApplyChange() { | |
| 116 DCHECK(!should_blacklist_password_ || !should_save_password_); | |
|
Peter Kasting
2013/09/09 18:19:02
Nit: Given that these two bools are not set to tru
npentrel
2013/09/09 22:08:34
Done.
| |
| 117 if (should_save_password_) | |
| 118 Save(); | |
| 119 else if (should_blacklist_password_) | |
| 120 PermanentlyBlacklist(); | |
| 121 should_blacklist_password_ = false; | |
| 122 should_save_password_ = false; | |
| 123 } | |
| 124 | |
| 125 void PasswordFormManager::SavePassword() { | |
| 126 should_blacklist_password_ = false; | |
| 127 should_save_password_ = true; | |
| 128 } | |
| 129 | |
| 130 void PasswordFormManager::BlacklistPassword() { | |
| 131 should_save_password_ = false; | |
| 132 should_blacklist_password_ = true; | |
| 133 } | |
| 134 | |
| 109 bool PasswordFormManager::IsBlacklisted() { | 135 bool PasswordFormManager::IsBlacklisted() { |
| 110 DCHECK_EQ(state_, POST_MATCHING_PHASE); | 136 DCHECK_EQ(state_, POST_MATCHING_PHASE); |
| 111 if (preferred_match_ && preferred_match_->blacklisted_by_user) | 137 if (preferred_match_ && preferred_match_->blacklisted_by_user) |
| 112 return true; | 138 return true; |
| 113 return false; | 139 return false; |
| 114 } | 140 } |
| 115 | 141 |
| 116 void PasswordFormManager::PermanentlyBlacklist() { | 142 void PasswordFormManager::PermanentlyBlacklist() { |
| 117 DCHECK_EQ(state_, POST_MATCHING_PHASE); | 143 DCHECK_EQ(state_, POST_MATCHING_PHASE); |
| 118 | 144 |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 | 616 |
| 591 void PasswordFormManager::SubmitFailed() { | 617 void PasswordFormManager::SubmitFailed() { |
| 592 submit_result_ = kSubmitResultFailed; | 618 submit_result_ = kSubmitResultFailed; |
| 593 } | 619 } |
| 594 | 620 |
| 595 void PasswordFormManager::SendNotBlacklistedToRenderer() { | 621 void PasswordFormManager::SendNotBlacklistedToRenderer() { |
| 596 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); | 622 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); |
| 597 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), | 623 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), |
| 598 observed_form_)); | 624 observed_form_)); |
| 599 } | 625 } |
| OLD | NEW |