OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/password_manager/core/browser/password_autofill_manager.h" | 5 #include "components/password_manager/core/browser/password_autofill_manager.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "components/autofill/core/browser/autofill_driver.h" | 15 #include "components/autofill/core/browser/autofill_driver.h" |
16 #include "components/autofill/core/browser/popup_item_ids.h" | 16 #include "components/autofill/core/browser/popup_item_ids.h" |
17 #include "components/autofill/core/browser/suggestion.h" | 17 #include "components/autofill/core/browser/suggestion.h" |
18 #include "components/autofill/core/common/autofill_constants.h" | 18 #include "components/autofill/core/common/autofill_constants.h" |
19 #include "components/autofill/core/common/autofill_data_validation.h" | 19 #include "components/autofill/core/common/autofill_data_validation.h" |
20 #include "components/autofill/core/common/autofill_util.h" | |
20 #include "components/password_manager/core/browser/affiliation_utils.h" | 21 #include "components/password_manager/core/browser/affiliation_utils.h" |
21 #include "components/password_manager/core/browser/password_manager_driver.h" | 22 #include "components/password_manager/core/browser/password_manager_driver.h" |
22 #include "components/password_manager/core/browser/password_manager_metrics_util .h" | 23 #include "components/password_manager/core/browser/password_manager_metrics_util .h" |
23 #include "components/strings/grit/components_strings.h" | 24 #include "components/strings/grit/components_strings.h" |
24 #include "grit/components_strings.h" | 25 #include "grit/components_strings.h" |
25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
26 | 27 |
27 namespace password_manager { | 28 namespace password_manager { |
28 | 29 |
29 namespace { | 30 namespace { |
(...skipping 23 matching lines...) Expand all Loading... | |
53 base::string16 GetHumanReadableRealm(const std::string& signon_realm) { | 54 base::string16 GetHumanReadableRealm(const std::string& signon_realm) { |
54 // For Android application realms, remove the hash component. Otherwise, make | 55 // For Android application realms, remove the hash component. Otherwise, make |
55 // no changes. | 56 // no changes. |
56 FacetURI maybe_facet_uri(FacetURI::FromPotentiallyInvalidSpec(signon_realm)); | 57 FacetURI maybe_facet_uri(FacetURI::FromPotentiallyInvalidSpec(signon_realm)); |
57 if (maybe_facet_uri.IsValidAndroidFacetURI()) | 58 if (maybe_facet_uri.IsValidAndroidFacetURI()) |
58 return base::UTF8ToUTF16("android://" + | 59 return base::UTF8ToUTF16("android://" + |
59 maybe_facet_uri.android_package_name() + "/"); | 60 maybe_facet_uri.android_package_name() + "/"); |
60 return base::UTF8ToUTF16(signon_realm); | 61 return base::UTF8ToUTF16(signon_realm); |
61 } | 62 } |
62 | 63 |
64 // If |field_suggestion| matches |field_content|, creates a Suggestion out of it | |
65 // and appends to |suggestions|. | |
66 void AppendSuggestionIfMatching( | |
67 const base::string16& field_suggestion, | |
68 const base::string16& field_contents, | |
69 const std::string& signon_realm, | |
70 bool show_all, | |
71 std::vector<autofill::Suggestion>* suggestions) { | |
72 base::string16 lower_suggestion = base::i18n::ToLower(field_suggestion); | |
73 base::string16 lower_contents = base::i18n::ToLower(field_contents); | |
74 bool prefix_matched_suggestion = | |
75 show_all || base::StartsWith(lower_suggestion, lower_contents, true); | |
please use gerrit instead
2015/07/06 20:15:18
The last parameter to base::StartsWith() is enum,
Pritam Nikam
2015/07/07 16:18:32
Done.
| |
76 if (prefix_matched_suggestion || | |
77 autofill::ContainsTokenThatStartsWith(lower_suggestion, lower_contents, | |
78 true)) { | |
79 autofill::Suggestion suggestion(ReplaceEmptyUsername(field_suggestion)); | |
80 suggestion.label = GetHumanReadableRealm(signon_realm); | |
81 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | |
82 suggestion.match = prefix_matched_suggestion | |
83 ? autofill::Suggestion::PREFIX_MATCH | |
84 : autofill::Suggestion::SUBSTRING_MATCH; | |
85 suggestions->push_back(suggestion); | |
86 } | |
87 } | |
88 | |
63 // This function attempts to fill |suggestions| and |realms| form |fill_data| | 89 // This function attempts to fill |suggestions| and |realms| form |fill_data| |
64 // based on |current_username|. Unless |show_all| is true, it only picks | 90 // based on |current_username|. Unless |show_all| is true, it only picks |
65 // suggestions where the username has |current_username| as a prefix. | 91 // suggestions where the username has |current_username| as a prefix. |
66 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, | 92 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, |
67 const base::string16& current_username, | 93 const base::string16& current_username, |
68 std::vector<autofill::Suggestion>* suggestions, | 94 std::vector<autofill::Suggestion>* suggestions, |
69 bool show_all) { | 95 bool show_all) { |
70 base::string16 lower_username = base::i18n::ToLower(current_username); | 96 AppendSuggestionIfMatching(fill_data.username_field.value, current_username, |
71 | 97 fill_data.preferred_realm, show_all, suggestions); |
72 if (show_all || | |
73 base::StartsWith(base::i18n::ToLower(fill_data.username_field.value), | |
74 lower_username, base::CompareCase::SENSITIVE)) { | |
75 autofill::Suggestion suggestion( | |
76 ReplaceEmptyUsername(fill_data.username_field.value)); | |
77 suggestion.label = GetHumanReadableRealm(fill_data.preferred_realm); | |
78 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | |
79 suggestions->push_back(suggestion); | |
80 } | |
81 | 98 |
82 for (const auto& login : fill_data.additional_logins) { | 99 for (const auto& login : fill_data.additional_logins) { |
83 if (show_all || | 100 AppendSuggestionIfMatching(login.first, current_username, |
84 base::StartsWith(base::i18n::ToLower(login.first), lower_username, | 101 login.second.realm, show_all, suggestions); |
85 base::CompareCase::SENSITIVE)) { | |
86 autofill::Suggestion suggestion(ReplaceEmptyUsername(login.first)); | |
87 suggestion.label = GetHumanReadableRealm(login.second.realm); | |
88 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | |
89 suggestions->push_back(suggestion); | |
90 } | |
91 } | 102 } |
92 | 103 |
93 for (const auto& usernames : fill_data.other_possible_usernames) { | 104 for (const auto& usernames : fill_data.other_possible_usernames) { |
94 for (size_t i = 0; i < usernames.second.size(); ++i) { | 105 for (size_t i = 0; i < usernames.second.size(); ++i) { |
95 if (show_all || | 106 AppendSuggestionIfMatching(usernames.second[i], current_username, |
96 base::StartsWith(base::i18n::ToLower(usernames.second[i]), | 107 usernames.first.realm, show_all, suggestions); |
97 lower_username, base::CompareCase::SENSITIVE)) { | |
98 autofill::Suggestion suggestion( | |
99 ReplaceEmptyUsername(usernames.second[i])); | |
100 suggestion.label = GetHumanReadableRealm(usernames.first.realm); | |
101 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | |
102 suggestions->push_back(suggestion); | |
103 } | |
104 } | 108 } |
105 } | 109 } |
110 | |
111 // Prefix matches should precede other token matches. | |
112 if (autofill::IsFeatureSubstringMatchEnabled()) { | |
113 std::sort(suggestions->begin(), suggestions->end(), | |
114 [](const autofill::Suggestion& a, const autofill::Suggestion& b) { | |
115 return a.match < b.match; | |
116 }); | |
117 } | |
106 } | 118 } |
107 | 119 |
108 } // namespace | 120 } // namespace |
109 | 121 |
110 //////////////////////////////////////////////////////////////////////////////// | 122 //////////////////////////////////////////////////////////////////////////////// |
111 // PasswordAutofillManager, public: | 123 // PasswordAutofillManager, public: |
112 | 124 |
113 PasswordAutofillManager::PasswordAutofillManager( | 125 PasswordAutofillManager::PasswordAutofillManager( |
114 PasswordManagerDriver* password_manager_driver, | 126 PasswordManagerDriver* password_manager_driver, |
115 autofill::AutofillClient* autofill_client) | 127 autofill::AutofillClient* autofill_client) |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 autofill::PasswordFormFillData* found_password) { | 317 autofill::PasswordFormFillData* found_password) { |
306 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); | 318 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); |
307 if (iter == login_to_password_info_.end()) | 319 if (iter == login_to_password_info_.end()) |
308 return false; | 320 return false; |
309 | 321 |
310 *found_password = iter->second; | 322 *found_password = iter->second; |
311 return true; | 323 return true; |
312 } | 324 } |
313 | 325 |
314 } // namespace password_manager | 326 } // namespace password_manager |
OLD | NEW |