| 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/common/autofill_constants.h" | 16 #include "components/autofill/core/common/autofill_constants.h" |
| 16 #include "components/autofill/core/common/autofill_data_validation.h" | 17 #include "components/autofill/core/common/autofill_data_validation.h" |
| 17 #include "components/password_manager/core/browser/password_manager_client.h" | 18 #include "components/password_manager/core/browser/password_manager_client.h" |
| 18 #include "components/password_manager/core/browser/password_manager_driver.h" | 19 #include "components/password_manager/core/browser/password_manager_driver.h" |
| 19 #include "components/strings/grit/components_strings.h" | 20 #include "components/strings/grit/components_strings.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 21 | 22 |
| 22 namespace password_manager { | 23 namespace password_manager { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 // This function attempts to fill |suggestions| and |realms| form |fill_data| | 27 // This function attempts to fill |suggestions| and |realms| form |fill_data| |
| 27 // based on |current_username|. Unless |show_all| is true, it only picks | 28 // based on |current_username|. Unless |show_all| is true, it only picks |
| 28 // suggestions where the username has |current_username| as a prefix. | 29 // suggestions where the username has |current_username| as a prefix. |
| 29 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, | 30 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, |
| 30 const base::string16& current_username, | 31 const base::string16& current_username, |
| 31 std::vector<base::string16>* suggestions, | 32 std::vector<autofill::Suggestion>* suggestions, |
| 32 std::vector<base::string16>* realms, | |
| 33 bool show_all) { | 33 bool show_all) { |
| 34 if (show_all || | 34 if (show_all || |
| 35 StartsWith(fill_data.username_field.value, current_username, false)) { | 35 StartsWith(fill_data.username_field.value, current_username, false)) { |
| 36 suggestions->push_back(fill_data.username_field.value); | 36 autofill::Suggestion suggestion(fill_data.username_field.value); |
| 37 realms->push_back(base::UTF8ToUTF16(fill_data.preferred_realm)); | 37 suggestion.label = base::UTF8ToUTF16(fill_data.preferred_realm); |
| 38 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; |
| 39 suggestions->push_back(suggestion); |
| 38 } | 40 } |
| 39 | 41 |
| 40 for (const auto& login : fill_data.additional_logins) { | 42 for (const auto& login : fill_data.additional_logins) { |
| 41 if (show_all || StartsWith(login.first, current_username, false)) { | 43 if (show_all || StartsWith(login.first, current_username, false)) { |
| 42 suggestions->push_back(login.first); | 44 autofill::Suggestion suggestion(login.first); |
| 43 realms->push_back(base::UTF8ToUTF16(login.second.realm)); | 45 suggestion.label = base::UTF8ToUTF16(login.second.realm); |
| 46 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; |
| 47 suggestions->push_back(suggestion); |
| 44 } | 48 } |
| 45 } | 49 } |
| 46 | 50 |
| 47 for (const auto& usernames : fill_data.other_possible_usernames) { | 51 for (const auto& usernames : fill_data.other_possible_usernames) { |
| 48 for (size_t i = 0; i < usernames.second.size(); ++i) { | 52 for (size_t i = 0; i < usernames.second.size(); ++i) { |
| 49 if (show_all || | 53 if (show_all || |
| 50 StartsWith(usernames.second[i], current_username, false)) { | 54 StartsWith(usernames.second[i], current_username, false)) { |
| 51 suggestions->push_back(usernames.second[i]); | 55 autofill::Suggestion suggestion(usernames.second[i]); |
| 52 realms->push_back(base::UTF8ToUTF16(usernames.first.realm)); | 56 suggestion.label = base::UTF8ToUTF16(usernames.first.realm); |
| 57 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY; |
| 58 suggestions->push_back(suggestion); |
| 53 } | 59 } |
| 54 } | 60 } |
| 55 } | 61 } |
| 56 } | 62 } |
| 57 | 63 |
| 58 } // namespace | 64 } // namespace |
| 59 | 65 |
| 60 //////////////////////////////////////////////////////////////////////////////// | 66 //////////////////////////////////////////////////////////////////////////////// |
| 61 // PasswordAutofillManager, public: | 67 // PasswordAutofillManager, public: |
| 62 | 68 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 112 |
| 107 login_to_password_info_[key] = fill_data; | 113 login_to_password_info_[key] = fill_data; |
| 108 } | 114 } |
| 109 | 115 |
| 110 void PasswordAutofillManager::OnShowPasswordSuggestions( | 116 void PasswordAutofillManager::OnShowPasswordSuggestions( |
| 111 int key, | 117 int key, |
| 112 base::i18n::TextDirection text_direction, | 118 base::i18n::TextDirection text_direction, |
| 113 const base::string16& typed_username, | 119 const base::string16& typed_username, |
| 114 int options, | 120 int options, |
| 115 const gfx::RectF& bounds) { | 121 const gfx::RectF& bounds) { |
| 116 std::vector<base::string16> suggestions; | 122 std::vector<autofill::Suggestion> suggestions; |
| 117 std::vector<base::string16> realms; | |
| 118 LoginToPasswordInfoMap::const_iterator fill_data_it = | 123 LoginToPasswordInfoMap::const_iterator fill_data_it = |
| 119 login_to_password_info_.find(key); | 124 login_to_password_info_.find(key); |
| 120 if (fill_data_it == login_to_password_info_.end()) { | 125 if (fill_data_it == login_to_password_info_.end()) { |
| 121 // Probably a compromised renderer. | 126 // Probably a compromised renderer. |
| 122 NOTREACHED(); | 127 NOTREACHED(); |
| 123 return; | 128 return; |
| 124 } | 129 } |
| 125 GetSuggestions(fill_data_it->second, typed_username, &suggestions, &realms, | 130 GetSuggestions(fill_data_it->second, typed_username, &suggestions, |
| 126 options & autofill::SHOW_ALL); | 131 options & autofill::SHOW_ALL); |
| 127 DCHECK_EQ(suggestions.size(), realms.size()); | |
| 128 | 132 |
| 129 form_data_key_ = key; | 133 form_data_key_ = key; |
| 130 | 134 |
| 131 if (suggestions.empty()) { | 135 if (suggestions.empty()) { |
| 132 autofill_client_->HideAutofillPopup(); | 136 autofill_client_->HideAutofillPopup(); |
| 133 return; | 137 return; |
| 134 } | 138 } |
| 135 | 139 |
| 136 std::vector<base::string16> empty(suggestions.size()); | |
| 137 std::vector<int> password_ids(suggestions.size(), | |
| 138 autofill::POPUP_ITEM_ID_PASSWORD_ENTRY); | |
| 139 if (options & autofill::IS_PASSWORD_FIELD) { | 140 if (options & autofill::IS_PASSWORD_FIELD) { |
| 140 base::string16 password_field_suggestions_title = l10n_util::GetStringUTF16( | 141 autofill::Suggestion password_field_suggestions(l10n_util::GetStringUTF16( |
| 141 IDS_AUTOFILL_PASSWORD_FIELD_SUGGESTIONS_TITLE); | 142 IDS_AUTOFILL_PASSWORD_FIELD_SUGGESTIONS_TITLE)); |
| 142 suggestions.insert(suggestions.begin(), password_field_suggestions_title); | 143 password_field_suggestions.frontend_id = autofill::POPUP_ITEM_ID_TITLE; |
| 143 realms.insert(realms.begin(), base::string16()); | 144 suggestions.insert(suggestions.begin(), password_field_suggestions); |
| 144 empty.insert(empty.begin(), base::string16()); | |
| 145 password_ids.insert(password_ids.begin(), autofill::POPUP_ITEM_ID_TITLE); | |
| 146 } | 145 } |
| 147 autofill_client_->ShowAutofillPopup(bounds, | 146 autofill_client_->ShowAutofillPopup(bounds, |
| 148 text_direction, | 147 text_direction, |
| 149 suggestions, | 148 suggestions, |
| 150 realms, | |
| 151 empty, | |
| 152 password_ids, | |
| 153 weak_ptr_factory_.GetWeakPtr()); | 149 weak_ptr_factory_.GetWeakPtr()); |
| 154 } | 150 } |
| 155 | 151 |
| 156 void PasswordAutofillManager::Reset() { | 152 void PasswordAutofillManager::Reset() { |
| 157 login_to_password_info_.clear(); | 153 login_to_password_info_.clear(); |
| 158 } | 154 } |
| 159 | 155 |
| 160 bool PasswordAutofillManager::FillSuggestionForTest( | 156 bool PasswordAutofillManager::FillSuggestionForTest( |
| 161 int key, | 157 int key, |
| 162 const base::string16& username) { | 158 const base::string16& username) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 autofill::PasswordFormFillData* found_password) { | 242 autofill::PasswordFormFillData* found_password) { |
| 247 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); | 243 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); |
| 248 if (iter == login_to_password_info_.end()) | 244 if (iter == login_to_password_info_.end()) |
| 249 return false; | 245 return false; |
| 250 | 246 |
| 251 *found_password = iter->second; | 247 *found_password = iter->second; |
| 252 return true; | 248 return true; |
| 253 } | 249 } |
| 254 | 250 |
| 255 } // namespace password_manager | 251 } // namespace password_manager |
| OLD | NEW |