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 22 matching lines...) Expand all Loading... |
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), | 43 password_action_(DO_NOTHING) { |
44 should_blacklist_password_(false) { | |
45 DCHECK(profile_); | 44 DCHECK(profile_); |
46 if (observed_form_.origin.is_valid()) | 45 if (observed_form_.origin.is_valid()) |
47 base::SplitString(observed_form_.origin.path(), '/', &form_path_tokens_); | 46 base::SplitString(observed_form_.origin.path(), '/', &form_path_tokens_); |
48 observed_form_.ssl_valid = ssl_valid; | 47 observed_form_.ssl_valid = ssl_valid; |
49 } | 48 } |
50 | 49 |
51 PasswordFormManager::~PasswordFormManager() { | 50 PasswordFormManager::~PasswordFormManager() { |
52 UMA_HISTOGRAM_ENUMERATION("PasswordManager.ActionsTaken", | 51 UMA_HISTOGRAM_ENUMERATION("PasswordManager.ActionsTaken", |
53 GetActionsTaken(), | 52 GetActionsTaken(), |
54 kMaxNumActionsTaken); | 53 kMaxNumActionsTaken); |
55 // In case the tab is closed before the next navigation occurs this will | 54 // In case the tab is closed before the next navigation occurs this will |
56 // apply outstanding changes. | 55 // apply outstanding changes. |
57 if (should_save_password_ || should_blacklist_password_) | 56 ApplyChange(); |
58 ApplyChange(); | |
59 } | 57 } |
60 | 58 |
61 int PasswordFormManager::GetActionsTaken() { | 59 int PasswordFormManager::GetActionsTaken() { |
62 return user_action_ + kUserActionMax * (manager_action_ + | 60 return user_action_ + kUserActionMax * (manager_action_ + |
63 kManagerActionMax * submit_result_); | 61 kManagerActionMax * submit_result_); |
64 }; | 62 }; |
65 | 63 |
66 // TODO(timsteele): use a hash of some sort in the future? | 64 // TODO(timsteele): use a hash of some sort in the future? |
67 bool PasswordFormManager::DoesManage(const PasswordForm& form, | 65 bool PasswordFormManager::DoesManage(const PasswordForm& form, |
68 ActionMatch action_match) const { | 66 ActionMatch action_match) const { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 after_scheme2, | 104 after_scheme2, |
107 observed_form_.origin.spec().end()) | 105 observed_form_.origin.spec().end()) |
108 != form.origin.spec().end(); | 106 != form.origin.spec().end(); |
109 } | 107 } |
110 return false; | 108 return false; |
111 } | 109 } |
112 return true; | 110 return true; |
113 } | 111 } |
114 | 112 |
115 void PasswordFormManager::ApplyChange() { | 113 void PasswordFormManager::ApplyChange() { |
116 DCHECK(!should_blacklist_password_ || !should_save_password_); | 114 if (password_action_ == SAVE) |
117 if (should_save_password_) | |
118 Save(); | 115 Save(); |
119 else if (should_blacklist_password_) | 116 else if (password_action_ == BLACKLIST) |
120 PermanentlyBlacklist(); | 117 PermanentlyBlacklist(); |
121 should_blacklist_password_ = false; | 118 password_action_ = DO_NOTHING; |
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 } | 119 } |
134 | 120 |
135 bool PasswordFormManager::IsBlacklisted() { | 121 bool PasswordFormManager::IsBlacklisted() { |
136 DCHECK_EQ(state_, POST_MATCHING_PHASE); | 122 DCHECK_EQ(state_, POST_MATCHING_PHASE); |
137 if (preferred_match_ && preferred_match_->blacklisted_by_user) | 123 if (preferred_match_ && preferred_match_->blacklisted_by_user) |
138 return true; | 124 return true; |
139 return false; | 125 return false; |
140 } | 126 } |
141 | 127 |
142 void PasswordFormManager::PermanentlyBlacklist() { | 128 void PasswordFormManager::PermanentlyBlacklist() { |
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 | 602 |
617 void PasswordFormManager::SubmitFailed() { | 603 void PasswordFormManager::SubmitFailed() { |
618 submit_result_ = kSubmitResultFailed; | 604 submit_result_ = kSubmitResultFailed; |
619 } | 605 } |
620 | 606 |
621 void PasswordFormManager::SendNotBlacklistedToRenderer() { | 607 void PasswordFormManager::SendNotBlacklistedToRenderer() { |
622 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); | 608 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); |
623 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), | 609 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), |
624 observed_form_)); | 610 observed_form_)); |
625 } | 611 } |
OLD | NEW |