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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.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 "components/autofill/core/browser/autofill_driver.h" | 13 #include "components/autofill/core/browser/autofill_driver.h" |
14 #include "components/autofill/core/browser/popup_item_ids.h" | 14 #include "components/autofill/core/browser/popup_item_ids.h" |
15 #include "components/autofill/core/browser/suggestion.h" | 15 #include "components/autofill/core/browser/suggestion.h" |
16 #include "components/autofill/core/common/autofill_constants.h" | 16 #include "components/autofill/core/common/autofill_constants.h" |
17 #include "components/autofill/core/common/autofill_data_validation.h" | 17 #include "components/autofill/core/common/autofill_data_validation.h" |
18 #include "components/autofill/core/common/autofill_util.h" | |
18 #include "components/password_manager/core/browser/affiliation_utils.h" | 19 #include "components/password_manager/core/browser/affiliation_utils.h" |
19 #include "components/password_manager/core/browser/password_manager_driver.h" | 20 #include "components/password_manager/core/browser/password_manager_driver.h" |
20 #include "components/strings/grit/components_strings.h" | 21 #include "components/strings/grit/components_strings.h" |
21 #include "grit/components_strings.h" | 22 #include "grit/components_strings.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 | 24 |
24 namespace password_manager { | 25 namespace password_manager { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
(...skipping 22 matching lines...) Expand all Loading... | |
50 base::string16 GetHumanReadableRealm(const std::string& signon_realm) { | 51 base::string16 GetHumanReadableRealm(const std::string& signon_realm) { |
51 // For Android application realms, remove the hash component. Otherwise, make | 52 // For Android application realms, remove the hash component. Otherwise, make |
52 // no changes. | 53 // no changes. |
53 FacetURI maybe_facet_uri(FacetURI::FromPotentiallyInvalidSpec(signon_realm)); | 54 FacetURI maybe_facet_uri(FacetURI::FromPotentiallyInvalidSpec(signon_realm)); |
54 if (maybe_facet_uri.IsValidAndroidFacetURI()) | 55 if (maybe_facet_uri.IsValidAndroidFacetURI()) |
55 return base::UTF8ToUTF16("android://" + | 56 return base::UTF8ToUTF16("android://" + |
56 maybe_facet_uri.android_package_name() + "/"); | 57 maybe_facet_uri.android_package_name() + "/"); |
57 return base::UTF8ToUTF16(signon_realm); | 58 return base::UTF8ToUTF16(signon_realm); |
58 } | 59 } |
59 | 60 |
61 // Returns |true| if |kEnableSuggestionsWithSubstringMatch| command line switch | |
62 // is on and |field_contents| matches substring token within |field_suggestion| | |
vabr (Chromium)
2015/03/24 13:32:28
Now the vague part is "matches" (no indication of
Pritam Nikam
2015/03/25 14:25:27
Done.
| |
63 // delimited by characters ' ', '.', ',', '-', '_' and '@'; otherwise |false|. | |
64 bool DoesSuggestionsSubstringMatchContents( | |
65 const base::string16& field_suggestion, | |
66 const base::string16& field_contents) { | |
67 return autofill::IsFeatureSubstringMatchEnabled() && | |
68 autofill::HasTokenStartsWith(field_suggestion, field_contents); | |
69 } | |
70 | |
60 // This function attempts to fill |suggestions| and |realms| form |fill_data| | 71 // This function attempts to fill |suggestions| and |realms| form |fill_data| |
61 // based on |current_username|. Unless |show_all| is true, it only picks | 72 // based on |current_username|. Unless |show_all| is true, it only picks |
62 // suggestions where the username has |current_username| as a prefix. | 73 // suggestions where the username has |current_username| as a substring. |
63 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, | 74 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, |
64 const base::string16& current_username, | 75 const base::string16& current_username, |
65 std::vector<autofill::Suggestion>* suggestions, | 76 std::vector<autofill::Suggestion>* suggestions, |
66 bool show_all) { | 77 bool show_all) { |
78 std::vector<autofill::Suggestion> substring_matched_suggestions; | |
67 if (show_all || | 79 if (show_all || |
68 StartsWith(fill_data.username_field.value, current_username, false)) { | 80 StartsWith(fill_data.username_field.value, current_username, false)) { |
69 autofill::Suggestion suggestion( | 81 autofill::Suggestion suggestion( |
70 ReplaceEmptyUsername(fill_data.username_field.value)); | 82 ReplaceEmptyUsername(fill_data.username_field.value)); |
71 suggestion.label = GetHumanReadableRealm(fill_data.preferred_realm); | 83 suggestion.label = GetHumanReadableRealm(fill_data.preferred_realm); |
72 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | 84 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; |
73 suggestions->push_back(suggestion); | 85 suggestions->push_back(suggestion); |
86 } else if (DoesSuggestionsSubstringMatchContents( | |
87 fill_data.username_field.value, current_username)) { | |
88 autofill::Suggestion suggestion( | |
vabr (Chromium)
2015/03/24 13:32:28
I am a bit concerned about the code duplication. I
Pritam Nikam
2015/03/25 14:25:26
Done.
| |
89 ReplaceEmptyUsername(fill_data.username_field.value)); | |
90 suggestion.label = GetHumanReadableRealm(fill_data.preferred_realm); | |
91 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | |
92 substring_matched_suggestions.push_back(suggestion); | |
74 } | 93 } |
75 | 94 |
76 for (const auto& login : fill_data.additional_logins) { | 95 for (const auto& login : fill_data.additional_logins) { |
77 if (show_all || StartsWith(login.first, current_username, false)) { | 96 if (show_all || StartsWith(login.first, current_username, false)) { |
78 autofill::Suggestion suggestion(ReplaceEmptyUsername(login.first)); | 97 autofill::Suggestion suggestion(ReplaceEmptyUsername(login.first)); |
79 suggestion.label = GetHumanReadableRealm(login.second.realm); | 98 suggestion.label = GetHumanReadableRealm(login.second.realm); |
80 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | 99 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; |
81 suggestions->push_back(suggestion); | 100 suggestions->push_back(suggestion); |
101 } else if (DoesSuggestionsSubstringMatchContents(login.first, | |
102 current_username)) { | |
103 autofill::Suggestion suggestion(ReplaceEmptyUsername(login.first)); | |
104 suggestion.label = GetHumanReadableRealm(login.second.realm); | |
105 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | |
106 substring_matched_suggestions.push_back(suggestion); | |
82 } | 107 } |
83 } | 108 } |
84 | 109 |
85 for (const auto& usernames : fill_data.other_possible_usernames) { | 110 for (const auto& usernames : fill_data.other_possible_usernames) { |
86 for (size_t i = 0; i < usernames.second.size(); ++i) { | 111 for (size_t i = 0; i < usernames.second.size(); ++i) { |
87 if (show_all || | 112 if (show_all || |
88 StartsWith(usernames.second[i], current_username, false)) { | 113 StartsWith(usernames.second[i], current_username, false)) { |
89 autofill::Suggestion suggestion( | 114 autofill::Suggestion suggestion( |
90 ReplaceEmptyUsername(usernames.second[i])); | 115 ReplaceEmptyUsername(usernames.second[i])); |
91 suggestion.label = GetHumanReadableRealm(usernames.first.realm); | 116 suggestion.label = GetHumanReadableRealm(usernames.first.realm); |
92 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | 117 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; |
93 suggestions->push_back(suggestion); | 118 suggestions->push_back(suggestion); |
119 } else if (DoesSuggestionsSubstringMatchContents(usernames.second[i], | |
120 current_username)) { | |
121 autofill::Suggestion suggestion( | |
122 ReplaceEmptyUsername(usernames.second[i])); | |
123 suggestion.label = GetHumanReadableRealm(usernames.first.realm); | |
124 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | |
125 substring_matched_suggestions.push_back(suggestion); | |
94 } | 126 } |
95 } | 127 } |
96 } | 128 } |
129 | |
130 // Now append usernames having substring matching. | |
131 for (const auto& suggestion : substring_matched_suggestions) { | |
132 suggestions->push_back(suggestion); | |
133 } | |
97 } | 134 } |
98 | 135 |
99 } // namespace | 136 } // namespace |
100 | 137 |
101 //////////////////////////////////////////////////////////////////////////////// | 138 //////////////////////////////////////////////////////////////////////////////// |
102 // PasswordAutofillManager, public: | 139 // PasswordAutofillManager, public: |
103 | 140 |
104 PasswordAutofillManager::PasswordAutofillManager( | 141 PasswordAutofillManager::PasswordAutofillManager( |
105 PasswordManagerDriver* password_manager_driver, | 142 PasswordManagerDriver* password_manager_driver, |
106 autofill::AutofillClient* autofill_client) | 143 autofill::AutofillClient* autofill_client) |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 autofill::PasswordFormFillData* found_password) { | 313 autofill::PasswordFormFillData* found_password) { |
277 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); | 314 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); |
278 if (iter == login_to_password_info_.end()) | 315 if (iter == login_to_password_info_.end()) |
279 return false; | 316 return false; |
280 | 317 |
281 *found_password = iter->second; | 318 *found_password = iter->second; |
282 return true; | 319 return true; |
283 } | 320 } |
284 | 321 |
285 } // namespace password_manager | 322 } // namespace password_manager |
OLD | NEW |