| Index: components/password_manager/core/browser/password_autofill_manager.cc
|
| diff --git a/components/password_manager/core/browser/password_autofill_manager.cc b/components/password_manager/core/browser/password_autofill_manager.cc
|
| index 01bf791bed010de8ddfda9ae442a1c79cb34dcd1..2d680b60a622d7d7f1fa8f4f1ed716c236792e61 100644
|
| --- a/components/password_manager/core/browser/password_autofill_manager.cc
|
| +++ b/components/password_manager/core/browser/password_autofill_manager.cc
|
| @@ -2,16 +2,59 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "components/password_manager/core/browser/password_autofill_manager.h"
|
| +
|
| +#include <vector>
|
| +
|
| #include "base/logging.h"
|
| +#include "base/strings/string16.h"
|
| +#include "base/strings/string_util.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| #include "components/autofill/core/browser/autofill_driver.h"
|
| #include "components/autofill/core/browser/popup_item_ids.h"
|
| #include "components/autofill/core/common/autofill_data_validation.h"
|
| -#include "components/password_manager/core/browser/password_autofill_manager.h"
|
| #include "components/password_manager/core/browser/password_manager_client.h"
|
| #include "components/password_manager/core/browser/password_manager_driver.h"
|
|
|
| namespace password_manager {
|
|
|
| +namespace {
|
| +
|
| +// This function attempts to fill |suggestions| and |realms| form |fill_data|
|
| +// based on |current_username|. Unless |show_all| is true, it only picks
|
| +// suggestions where the username has |current_username| as a prefix.
|
| +void GetSuggestions(const autofill::PasswordFormFillData& fill_data,
|
| + const base::string16& current_username,
|
| + std::vector<base::string16>* suggestions,
|
| + std::vector<base::string16>* realms,
|
| + bool show_all) {
|
| + if (show_all ||
|
| + StartsWith(
|
| + fill_data.basic_data.fields[0].value, current_username, false)) {
|
| + suggestions->push_back(fill_data.basic_data.fields[0].value);
|
| + realms->push_back(base::UTF8ToUTF16(fill_data.preferred_realm));
|
| + }
|
| +
|
| + for (const auto& login : fill_data.additional_logins) {
|
| + if (show_all || StartsWith(login.first, current_username, false)) {
|
| + suggestions->push_back(login.first);
|
| + realms->push_back(base::UTF8ToUTF16(login.second.realm));
|
| + }
|
| + }
|
| +
|
| + for (const auto& usernames : fill_data.other_possible_usernames) {
|
| + for (size_t i = 0; i < usernames.second.size(); ++i) {
|
| + if (show_all ||
|
| + StartsWith(usernames.second[i], current_username, false)) {
|
| + suggestions->push_back(usernames.second[i]);
|
| + realms->push_back(base::UTF8ToUTF16(usernames.first.realm));
|
| + }
|
| + }
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| ////////////////////////////////////////////////////////////////////////////////
|
| // PasswordAutofillManager, public:
|
|
|
| @@ -66,13 +109,22 @@ void PasswordAutofillManager::OnAddPasswordFormMapping(
|
|
|
| void PasswordAutofillManager::OnShowPasswordSuggestions(
|
| const autofill::FormFieldData& field,
|
| - const gfx::RectF& bounds,
|
| - const std::vector<base::string16>& suggestions,
|
| - const std::vector<base::string16>& realms) {
|
| - if (!autofill::IsValidString16Vector(suggestions) ||
|
| - !autofill::IsValidString16Vector(realms) ||
|
| - suggestions.size() != realms.size())
|
| + const base::string16& typed_username,
|
| + bool show_all,
|
| + const gfx::RectF& bounds) {
|
| + std::vector<base::string16> suggestions;
|
| + std::vector<base::string16> realms;
|
| + LoginToPasswordInfoMap::const_iterator fill_data_it =
|
| + login_to_password_info_.find(field);
|
| + if (fill_data_it == login_to_password_info_.end()) {
|
| + // TODO(vabr): After https://codereview.chromium.org/686653003/, the only
|
| + // way to get here should be a compromised renderer.
|
| + NOTREACHED();
|
| return;
|
| + }
|
| + GetSuggestions(fill_data_it->second, typed_username, &suggestions, &realms,
|
| + show_all);
|
| + DCHECK_EQ(suggestions.size(), realms.size());
|
|
|
| form_field_ = field;
|
|
|
|
|