summaryrefslogtreecommitdiffstats
path: root/components/autofill
diff options
context:
space:
mode:
authorvabr <vabr@chromium.org>2014-10-31 02:36:06 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-31 09:36:21 +0000
commit86cc798cc2947dd88aa73505d716f93538dffa5b (patch)
tree9f062f05f5231c4b313b500c58419ce17fb8bceb /components/autofill
parenta52fbd252fdaea6395a31e6336608c3b26794aaa (diff)
downloadchromium_src-86cc798cc2947dd88aa73505d716f93538dffa5b.zip
chromium_src-86cc798cc2947dd88aa73505d716f93538dffa5b.tar.gz
chromium_src-86cc798cc2947dd88aa73505d716f93538dffa5b.tar.bz2
Do not haul suggestions back to browser in AutofillHostMsg_ShowPasswordSuggestions
Currently, PasswordAutofillAgent (in renderer) prepares password autofill suggestions for PasswordAutofillManager (in browser) and sends them via IPC. But the manager has the data to generate the suggestions itself, so this CL makes it derive the suggestions from that data instead of hauling it through IPC. This CL also adds one more test case to the PasswordAutofillManager unittest, to compensate for the coverage lost in the PasswordAutofillAgent browsertest by moving some logic out of the agent to the manager. BUG=400186, 377422, 118601 Review URL: https://codereview.chromium.org/688633004 Cr-Commit-Position: refs/heads/master@{#302245}
Diffstat (limited to 'components/autofill')
-rw-r--r--components/autofill/content/common/autofill_messages.h9
-rw-r--r--components/autofill/content/renderer/password_autofill_agent.cc81
2 files changed, 41 insertions, 49 deletions
diff --git a/components/autofill/content/common/autofill_messages.h b/components/autofill/content/common/autofill_messages.h
index 25d8277..e339a64 100644
--- a/components/autofill/content/common/autofill_messages.h
+++ b/components/autofill/content/common/autofill_messages.h
@@ -285,13 +285,12 @@ IPC_MESSAGE_ROUTED2(AutofillHostMsg_AddPasswordFormMapping,
autofill::FormFieldData, /* the user name field */
autofill::PasswordFormFillData /* password pairings */)
-// Instruct the browser to show a popup with the following suggestions from the
-// password manager.
+// Instruct the browser to show a popup with suggestions for the form field.
IPC_MESSAGE_ROUTED4(AutofillHostMsg_ShowPasswordSuggestions,
autofill::FormFieldData /* the form field */,
- gfx::RectF /* input field bounds, window-relative */,
- std::vector<base::string16> /* suggestions */,
- std::vector<base::string16> /* realms */)
+ base::string16 /* username typed by user */,
+ bool /* show all suggestions */,
+ gfx::RectF /* input field bounds, window-relative */)
// Inform browser of data list values for the curent field.
IPC_MESSAGE_ROUTED2(AutofillHostMsg_SetDataList,
diff --git a/components/autofill/content/renderer/password_autofill_agent.cc b/components/autofill/content/renderer/password_autofill_agent.cc
index c598692..f2882c9 100644
--- a/components/autofill/content/renderer/password_autofill_agent.cc
+++ b/components/autofill/content/renderer/password_autofill_agent.cc
@@ -240,45 +240,41 @@ bool FillDataContainsUsername(const PasswordFormFillData& fill_data) {
return !fill_data.basic_data.fields[0].name.empty();
}
-// This function attempts to fill |suggestions| and |realms| form |fill_data|
-// based on |current_username|. Returns true when |suggestions| gets filled
-// from |fill_data.other_possible_usernames|, else returns false.
-bool GetSuggestions(const PasswordFormFillData& fill_data,
- const base::string16& current_username,
- std::vector<base::string16>* suggestions,
- std::vector<base::string16>* realms,
- bool show_all) {
- bool other_possible_username_shown = false;
- 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));
+// Sets |suggestions_present| to true if there are any suggestions to be derived
+// from |fill_data|. Unless |show_all| is true, only considers suggestions with
+// usernames having |current_username| as a prefix. Returns true if a username
+// from the |fill_data.other_possible_usernames| would be included in the
+// suggestions.
+bool GetSuggestionsStats(const PasswordFormFillData& fill_data,
+ const base::string16& current_username,
+ bool show_all,
+ bool* suggestions_present) {
+ *suggestions_present = false;
+
+ 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_present = true;
+ return true;
+ }
+ }
}
- for (PasswordFormFillData::LoginCollection::const_iterator iter =
- fill_data.additional_logins.begin();
- iter != fill_data.additional_logins.end();
- ++iter) {
- if (show_all || StartsWith(iter->first, current_username, false)) {
- suggestions->push_back(iter->first);
- realms->push_back(base::UTF8ToUTF16(iter->second.realm));
- }
+ if (show_all || StartsWith(fill_data.basic_data.fields[0].value,
+ current_username, false)) {
+ *suggestions_present = true;
+ return false;
}
- for (PasswordFormFillData::UsernamesCollection::const_iterator iter =
- fill_data.other_possible_usernames.begin();
- iter != fill_data.other_possible_usernames.end();
- ++iter) {
- for (size_t i = 0; i < iter->second.size(); ++i) {
- if (show_all || StartsWith(iter->second[i], current_username, false)) {
- other_possible_username_shown = true;
- suggestions->push_back(iter->second[i]);
- realms->push_back(base::UTF8ToUTF16(iter->first.realm));
- }
+ for (const auto& login : fill_data.additional_logins) {
+ if (show_all || StartsWith(login.first, current_username, false)) {
+ *suggestions_present = true;
+ return false;
}
}
- return other_possible_username_shown;
+
+ return false;
}
// This function attempts to fill |username_element| and |password_element|
@@ -1108,15 +1104,6 @@ bool PasswordAutofillAgent::ShowSuggestionPopup(
if (!webview)
return false;
- std::vector<base::string16> suggestions;
- std::vector<base::string16> realms;
- if (GetSuggestions(
- fill_data, user_input.value(), &suggestions, &realms, show_all)) {
- usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN;
- }
-
- DCHECK_EQ(suggestions.size(), realms.size());
-
FormData form;
FormFieldData field;
FindFormAndFieldForFormControlElement(
@@ -1131,8 +1118,14 @@ bool PasswordAutofillAgent::ShowSuggestionPopup(
bounding_box.width() * scale,
bounding_box.height() * scale);
Send(new AutofillHostMsg_ShowPasswordSuggestions(
- routing_id(), field, bounding_box_scaled, suggestions, realms));
- return !suggestions.empty();
+ routing_id(), field, user_input.value(), show_all, bounding_box_scaled));
+
+ bool suggestions_present = false;
+ if (GetSuggestionsStats(fill_data, user_input.value(), show_all,
+ &suggestions_present)) {
+ usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN;
+ }
+ return suggestions_present;
}
void PasswordAutofillAgent::PerformInlineAutocomplete(