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 if (!DO_NOTHING) |
Peter Kasting
2013/09/10 23:04:41
This isn't what you intended to write.
Plus, this
npentrel
2013/09/11 09:10:42
Done.
| |
58 ApplyChange(); | 57 ApplyChange(); |
59 } | 58 } |
60 | 59 |
61 int PasswordFormManager::GetActionsTaken() { | 60 int PasswordFormManager::GetActionsTaken() { |
62 return user_action_ + kUserActionMax * (manager_action_ + | 61 return user_action_ + kUserActionMax * (manager_action_ + |
63 kManagerActionMax * submit_result_); | 62 kManagerActionMax * submit_result_); |
64 }; | 63 }; |
65 | 64 |
66 // TODO(timsteele): use a hash of some sort in the future? | 65 // TODO(timsteele): use a hash of some sort in the future? |
67 bool PasswordFormManager::DoesManage(const PasswordForm& form, | 66 bool PasswordFormManager::DoesManage(const PasswordForm& form, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 after_scheme2, | 105 after_scheme2, |
107 observed_form_.origin.spec().end()) | 106 observed_form_.origin.spec().end()) |
108 != form.origin.spec().end(); | 107 != form.origin.spec().end(); |
109 } | 108 } |
110 return false; | 109 return false; |
111 } | 110 } |
112 return true; | 111 return true; |
113 } | 112 } |
114 | 113 |
115 void PasswordFormManager::ApplyChange() { | 114 void PasswordFormManager::ApplyChange() { |
116 DCHECK(!should_blacklist_password_ || !should_save_password_); | 115 if (password_action_ == SAVE) |
117 if (should_save_password_) | |
118 Save(); | 116 Save(); |
119 else if (should_blacklist_password_) | 117 else if (password_action_ == BLACKLIST) |
120 PermanentlyBlacklist(); | 118 PermanentlyBlacklist(); |
121 should_blacklist_password_ = false; | 119 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 } | 120 } |
134 | 121 |
135 bool PasswordFormManager::IsBlacklisted() { | 122 bool PasswordFormManager::IsBlacklisted() { |
136 DCHECK_EQ(state_, POST_MATCHING_PHASE); | 123 DCHECK_EQ(state_, POST_MATCHING_PHASE); |
137 if (preferred_match_ && preferred_match_->blacklisted_by_user) | 124 if (preferred_match_ && preferred_match_->blacklisted_by_user) |
138 return true; | 125 return true; |
139 return false; | 126 return false; |
140 } | 127 } |
141 | 128 |
142 void PasswordFormManager::PermanentlyBlacklist() { | 129 void PasswordFormManager::PermanentlyBlacklist() { |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 return true; | 540 return true; |
554 } | 541 } |
555 } | 542 } |
556 } | 543 } |
557 return false; | 544 return false; |
558 } | 545 } |
559 | 546 |
560 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { | 547 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { |
561 DCHECK_EQ(state_, MATCHING_PHASE); | 548 DCHECK_EQ(state_, MATCHING_PHASE); |
562 // For scoring of candidate login data: | 549 // For scoring of candidate login data: |
563 // The most important element that should match is the origin, followed by | 550 // The most important element that match is the origin, followed by |
Peter Kasting
2013/09/10 23:04:41
Why did you change this comment?
npentrel
2013/09/11 09:10:42
Done.
| |
564 // the action, the password name, the submit button name, and finally the | 551 // the action, the password name, the submit button name, and finally the |
565 // username input field name. | 552 // username input field name. |
566 // Exact origin match gives an addition of 64 (1 << 6) + # of matching url | 553 // Exact origin match gives an addition of 64 (1 << 6) + # of matching url |
567 // dirs. | 554 // dirs. |
568 // Partial match gives an addition of 32 (1 << 5) + # matching url dirs | 555 // Partial match gives an addition of 32 (1 << 5) + # matching url dirs |
569 // That way, a partial match cannot trump an exact match even if | 556 // That way, a partial match cannot trump an exact match even if |
570 // the partial one matches all other attributes (action, elements) (and | 557 // the partial one matches all other attributes (action, elements) (and |
571 // regardless of the matching depth in the URL path). | 558 // regardless of the matching depth in the URL path). |
572 // If public suffix origin match was not used, it gives an addition of | 559 // If public suffix origin match was not used, it gives an addition of |
573 // 16 (1 << 4). | 560 // 16 (1 << 4). |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 | 603 |
617 void PasswordFormManager::SubmitFailed() { | 604 void PasswordFormManager::SubmitFailed() { |
618 submit_result_ = kSubmitResultFailed; | 605 submit_result_ = kSubmitResultFailed; |
619 } | 606 } |
620 | 607 |
621 void PasswordFormManager::SendNotBlacklistedToRenderer() { | 608 void PasswordFormManager::SendNotBlacklistedToRenderer() { |
622 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); | 609 content::RenderViewHost* host = web_contents_->GetRenderViewHost(); |
623 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), | 610 host->Send(new AutofillMsg_FormNotBlacklisted(host->GetRoutingID(), |
624 observed_form_)); | 611 observed_form_)); |
625 } | 612 } |
OLD | NEW |