Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Unified Diff: components/password_manager/core/browser/password_autofill_manager.cc

Issue 772253003: Create an autofill Suggestion class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 f4cbc235df7e2984edc017e2d128b533738f2458..6f29e0a345514e5aa65c9df5983932e838e583c2 100644
--- a/components/password_manager/core/browser/password_autofill_manager.cc
+++ b/components/password_manager/core/browser/password_autofill_manager.cc
@@ -12,6 +12,7 @@
#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/browser/suggestion.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_data_validation.h"
#include "components/password_manager/core/browser/password_manager_client.h"
@@ -28,19 +29,22 @@ namespace {
// 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,
+ std::vector<autofill::Suggestion>* suggestions,
bool show_all) {
if (show_all ||
StartsWith(fill_data.username_field.value, current_username, false)) {
- suggestions->push_back(fill_data.username_field.value);
- realms->push_back(base::UTF8ToUTF16(fill_data.preferred_realm));
+ autofill::Suggestion suggestion(fill_data.username_field.value);
+ suggestion.label = base::UTF8ToUTF16(fill_data.preferred_realm);
+ suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
+ suggestions->push_back(suggestion);
}
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));
+ autofill::Suggestion suggestion(login.first);
+ suggestion.label = base::UTF8ToUTF16(login.second.realm);
+ suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
+ suggestions->push_back(suggestion);
}
}
@@ -48,8 +52,10 @@ void GetSuggestions(const autofill::PasswordFormFillData& fill_data,
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));
+ autofill::Suggestion suggestion(usernames.second[i]);
+ suggestion.label = base::UTF8ToUTF16(usernames.first.realm);
+ suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
+ suggestions->push_back(suggestion);
}
}
}
@@ -113,8 +119,7 @@ void PasswordAutofillManager::OnShowPasswordSuggestions(
const base::string16& typed_username,
int options,
const gfx::RectF& bounds) {
- std::vector<base::string16> suggestions;
- std::vector<base::string16> realms;
+ std::vector<autofill::Suggestion> suggestions;
LoginToPasswordInfoMap::const_iterator fill_data_it =
login_to_password_info_.find(key);
if (fill_data_it == login_to_password_info_.end()) {
@@ -122,9 +127,8 @@ void PasswordAutofillManager::OnShowPasswordSuggestions(
NOTREACHED();
return;
}
- GetSuggestions(fill_data_it->second, typed_username, &suggestions, &realms,
+ GetSuggestions(fill_data_it->second, typed_username, &suggestions,
options & autofill::SHOW_ALL);
- DCHECK_EQ(suggestions.size(), realms.size());
form_data_key_ = key;
@@ -133,23 +137,15 @@ void PasswordAutofillManager::OnShowPasswordSuggestions(
return;
}
- std::vector<base::string16> empty(suggestions.size());
- std::vector<int> password_ids(suggestions.size(),
- autofill::POPUP_ITEM_ID_PASSWORD_ENTRY);
if (options & autofill::IS_PASSWORD_FIELD) {
- base::string16 password_field_suggestions_title = l10n_util::GetStringUTF16(
- IDS_AUTOFILL_PASSWORD_FIELD_SUGGESTIONS_TITLE);
- suggestions.insert(suggestions.begin(), password_field_suggestions_title);
- realms.insert(realms.begin(), base::string16());
- empty.insert(empty.begin(), base::string16());
- password_ids.insert(password_ids.begin(), autofill::POPUP_ITEM_ID_TITLE);
+ autofill::Suggestion password_field_suggestions(l10n_util::GetStringUTF16(
+ IDS_AUTOFILL_PASSWORD_FIELD_SUGGESTIONS_TITLE));
+ password_field_suggestions.frontend_id = autofill::POPUP_ITEM_ID_TITLE;
+ suggestions.insert(suggestions.begin(), password_field_suggestions);
}
autofill_client_->ShowAutofillPopup(bounds,
text_direction,
suggestions,
- realms,
- empty,
- password_ids,
weak_ptr_factory_.GetWeakPtr());
}

Powered by Google App Engine
This is Rietveld 408576698