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 // Use this to check if a given suggestion matches the current contents of a | |
62 // field. | |
63 bool DoesSuggestionMatchContents(const base::string16& field_suggestion, | |
64 const base::string16& field_contents) { | |
65 return StartsWith(field_suggestion, field_contents, false) || | |
vabr (Chromium)
2015/03/30 14:51:04
Looking at the definition of IsContentsPrefixOfSug
Pritam Nikam
2015/03/30 17:35:48
IMO, substring matching is still behind "enable-su
vabr (Chromium)
2015/03/31 09:38:07
Acknowledged.
(Also now it is needed also behind t
| |
66 (autofill::IsFeatureSubstringMatchEnabled() && | |
67 autofill::IsContentsPrefixOfSuggestionToken(field_suggestion, | |
68 field_contents, false)); | |
69 } | |
70 | |
71 // If |field_suggestion| matches |field_content|, creates a Suggestion out of it | |
72 // and appends to |suggestions|. | |
73 void AppendSuggestionIfMatching( | |
74 const base::string16& field_suggestion, | |
75 const base::string16& field_contents, | |
76 const std::string& signon_realm, | |
77 bool show_all, | |
78 std::vector<autofill::Suggestion>* suggestions) { | |
79 if (show_all || | |
80 DoesSuggestionMatchContents(field_suggestion, field_contents)) { | |
81 autofill::Suggestion suggestion(ReplaceEmptyUsername(field_suggestion)); | |
82 suggestion.label = GetHumanReadableRealm(signon_realm); | |
83 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | |
84 suggestions->push_back(suggestion); | |
85 } | |
86 } | |
87 | |
60 // This function attempts to fill |suggestions| and |realms| form |fill_data| | 88 // This function attempts to fill |suggestions| and |realms| form |fill_data| |
61 // based on |current_username|. Unless |show_all| is true, it only picks | 89 // based on |current_username|. Unless |show_all| is true, it only picks |
62 // suggestions where the username has |current_username| as a prefix. | 90 // suggestions where the username matches |current_username|. |
63 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, | 91 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, |
64 const base::string16& current_username, | 92 const base::string16& current_username, |
65 std::vector<autofill::Suggestion>* suggestions, | 93 std::vector<autofill::Suggestion>* suggestions, |
66 bool show_all) { | 94 bool show_all) { |
67 if (show_all || | 95 AppendSuggestionIfMatching(fill_data.username_field.value, current_username, |
68 StartsWith(fill_data.username_field.value, current_username, false)) { | 96 fill_data.preferred_realm, show_all, suggestions); |
69 autofill::Suggestion suggestion( | |
70 ReplaceEmptyUsername(fill_data.username_field.value)); | |
71 suggestion.label = GetHumanReadableRealm(fill_data.preferred_realm); | |
72 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | |
73 suggestions->push_back(suggestion); | |
74 } | |
75 | 97 |
76 for (const auto& login : fill_data.additional_logins) { | 98 for (const auto& login : fill_data.additional_logins) { |
77 if (show_all || StartsWith(login.first, current_username, false)) { | 99 AppendSuggestionIfMatching(login.first, current_username, |
78 autofill::Suggestion suggestion(ReplaceEmptyUsername(login.first)); | 100 login.second.realm, show_all, suggestions); |
79 suggestion.label = GetHumanReadableRealm(login.second.realm); | |
80 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | |
81 suggestions->push_back(suggestion); | |
82 } | |
83 } | 101 } |
84 | 102 |
85 for (const auto& usernames : fill_data.other_possible_usernames) { | 103 for (const auto& usernames : fill_data.other_possible_usernames) { |
86 for (size_t i = 0; i < usernames.second.size(); ++i) { | 104 for (size_t i = 0; i < usernames.second.size(); ++i) { |
87 if (show_all || | 105 AppendSuggestionIfMatching(usernames.second[i], current_username, |
88 StartsWith(usernames.second[i], current_username, false)) { | 106 usernames.first.realm, show_all, suggestions); |
89 autofill::Suggestion suggestion( | |
90 ReplaceEmptyUsername(usernames.second[i])); | |
91 suggestion.label = GetHumanReadableRealm(usernames.first.realm); | |
92 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; | |
93 suggestions->push_back(suggestion); | |
94 } | |
95 } | 107 } |
96 } | 108 } |
97 } | 109 } |
98 | 110 |
99 } // namespace | 111 } // namespace |
100 | 112 |
101 //////////////////////////////////////////////////////////////////////////////// | 113 //////////////////////////////////////////////////////////////////////////////// |
102 // PasswordAutofillManager, public: | 114 // PasswordAutofillManager, public: |
103 | 115 |
104 PasswordAutofillManager::PasswordAutofillManager( | 116 PasswordAutofillManager::PasswordAutofillManager( |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 autofill::PasswordFormFillData* found_password) { | 288 autofill::PasswordFormFillData* found_password) { |
277 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); | 289 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); |
278 if (iter == login_to_password_info_.end()) | 290 if (iter == login_to_password_info_.end()) |
279 return false; | 291 return false; |
280 | 292 |
281 *found_password = iter->second; | 293 *found_password = iter->second; |
282 return true; | 294 return true; |
283 } | 295 } |
284 | 296 |
285 } // namespace password_manager | 297 } // namespace password_manager |
OLD | NEW |