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

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

Issue 688633004: Do not haul suggestions back to browser in AutofillHostMsg_ShowPasswordSuggestions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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 01bf791bed010de8ddfda9ae442a1c79cb34dcd1..3517433edaba572b49d6d1cd295d8e8d7a80e4ea 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,9 +109,18 @@ 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) {
+ 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 =
Garrett Casto 2014/10/30 22:33:29 nit: Normally iterators are named in such a way th
vabr (Chromium) 2014/10/31 08:54:12 Done.
+ login_to_password_info_.find(field);
+ DCHECK(fill_data != login_to_password_info_.end());
+ GetSuggestions(fill_data->second, typed_username, &suggestions, &realms,
+ show_all);
+ DCHECK_EQ(suggestions.size(), realms.size());
+
if (!autofill::IsValidString16Vector(suggestions) ||
!autofill::IsValidString16Vector(realms) ||
suggestions.size() != realms.size())

Powered by Google App Engine
This is Rietveld 408576698