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/common/autofill_data_validation.h" | 15 #include "components/autofill/core/common/autofill_data_validation.h" |
16 #include "components/password_manager/core/browser/password_manager_client.h" | 16 #include "components/password_manager/core/browser/password_manager_client.h" |
17 #include "components/password_manager/core/browser/password_manager_driver.h" | 17 #include "components/password_manager/core/browser/password_manager_driver.h" |
| 18 #include "components/strings/grit/components_strings.h" |
| 19 #include "ui/base/l10n/l10n_util.h" |
18 | 20 |
19 namespace password_manager { | 21 namespace password_manager { |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 // This function attempts to fill |suggestions| and |realms| form |fill_data| | 25 // This function attempts to fill |suggestions| and |realms| form |fill_data| |
24 // based on |current_username|. Unless |show_all| is true, it only picks | 26 // based on |current_username|. Unless |show_all| is true, it only picks |
25 // suggestions where the username has |current_username| as a prefix. | 27 // suggestions where the username has |current_username| as a prefix. |
26 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, | 28 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, |
27 const base::string16& current_username, | 29 const base::string16& current_username, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 if (!autofill::IsValidPasswordFormFillData(fill_data)) | 103 if (!autofill::IsValidPasswordFormFillData(fill_data)) |
102 return; | 104 return; |
103 | 105 |
104 login_to_password_info_[key] = fill_data; | 106 login_to_password_info_[key] = fill_data; |
105 } | 107 } |
106 | 108 |
107 void PasswordAutofillManager::OnShowPasswordSuggestions( | 109 void PasswordAutofillManager::OnShowPasswordSuggestions( |
108 int key, | 110 int key, |
109 base::i18n::TextDirection text_direction, | 111 base::i18n::TextDirection text_direction, |
110 const base::string16& typed_username, | 112 const base::string16& typed_username, |
111 bool show_all, | 113 int options, |
112 const gfx::RectF& bounds) { | 114 const gfx::RectF& bounds) { |
| 115 bool show_all = |
| 116 (options & autofill::ShowPasswordSuggestionsOptions::SHOW_ALL); |
| 117 bool is_password_field = |
| 118 (options & autofill::ShowPasswordSuggestionsOptions::IS_PASSWORD_FIELD); |
| 119 base::string16 title; |
| 120 if (is_password_field) { |
| 121 title = l10n_util::GetStringUTF16( |
| 122 IDS_AUTOFILL_PASSWORD_FIELD_SUGGESTIONS_TITLE); |
| 123 } |
| 124 |
113 std::vector<base::string16> suggestions; | 125 std::vector<base::string16> suggestions; |
114 std::vector<base::string16> realms; | 126 std::vector<base::string16> realms; |
115 LoginToPasswordInfoMap::const_iterator fill_data_it = | 127 LoginToPasswordInfoMap::const_iterator fill_data_it = |
116 login_to_password_info_.find(key); | 128 login_to_password_info_.find(key); |
117 if (fill_data_it == login_to_password_info_.end()) { | 129 if (fill_data_it == login_to_password_info_.end()) { |
118 // Probably a compromised renderer. | 130 // Probably a compromised renderer. |
119 NOTREACHED(); | 131 NOTREACHED(); |
120 return; | 132 return; |
121 } | 133 } |
122 GetSuggestions(fill_data_it->second, typed_username, &suggestions, &realms, | 134 GetSuggestions(fill_data_it->second, typed_username, &suggestions, &realms, |
123 show_all); | 135 show_all); |
124 DCHECK_EQ(suggestions.size(), realms.size()); | 136 DCHECK_EQ(suggestions.size(), realms.size()); |
125 | 137 |
126 form_data_key_ = key; | 138 form_data_key_ = key; |
127 | 139 |
128 if (suggestions.empty()) { | 140 if (suggestions.empty()) { |
129 autofill_client_->HideAutofillPopup(); | 141 autofill_client_->HideAutofillPopup(); |
130 return; | 142 return; |
131 } | 143 } |
132 | 144 |
133 std::vector<base::string16> empty(suggestions.size()); | 145 std::vector<base::string16> empty(suggestions.size()); |
134 std::vector<int> password_ids(suggestions.size(), | 146 std::vector<int> password_ids(suggestions.size(), |
135 autofill::POPUP_ITEM_ID_PASSWORD_ENTRY); | 147 autofill::POPUP_ITEM_ID_PASSWORD_ENTRY); |
| 148 if (!title.empty()) { |
| 149 suggestions.insert(suggestions.begin(), title); |
| 150 realms.insert(realms.begin(), base::string16()); |
| 151 empty.insert(empty.begin(), base::string16()); |
| 152 password_ids.insert(password_ids.begin(), autofill::POPUP_ITEM_ID_TITLE); |
| 153 } |
136 autofill_client_->ShowAutofillPopup(bounds, | 154 autofill_client_->ShowAutofillPopup(bounds, |
137 text_direction, | 155 text_direction, |
138 suggestions, | 156 suggestions, |
139 realms, | 157 realms, |
140 empty, | 158 empty, |
141 password_ids, | 159 password_ids, |
142 weak_ptr_factory_.GetWeakPtr()); | 160 weak_ptr_factory_.GetWeakPtr()); |
143 } | 161 } |
144 | 162 |
145 void PasswordAutofillManager::Reset() { | 163 void PasswordAutofillManager::Reset() { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 autofill::PasswordFormFillData* found_password) { | 254 autofill::PasswordFormFillData* found_password) { |
237 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); | 255 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); |
238 if (iter == login_to_password_info_.end()) | 256 if (iter == login_to_password_info_.end()) |
239 return false; | 257 return false; |
240 | 258 |
241 *found_password = iter->second; | 259 *found_password = iter->second; |
242 return true; | 260 return true; |
243 } | 261 } |
244 | 262 |
245 } // namespace password_manager | 263 } // namespace password_manager |
OLD | NEW |