summaryrefslogtreecommitdiffstats
path: root/components/autofill
diff options
context:
space:
mode:
authorpritam.nikam <pritam.nikam@samsung.com>2014-11-10 23:44:22 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-11 07:45:04 +0000
commit0acc7f6e27371b58110c5a273de2784c068d1ad8 (patch)
tree799574dc5eefd960092fd9586168c1a0d54437d9 /components/autofill
parent878dca3cca9b96886ddb4233adb5c7fca779fbcc (diff)
downloadchromium_src-0acc7f6e27371b58110c5a273de2784c068d1ad8.zip
chromium_src-0acc7f6e27371b58110c5a273de2784c068d1ad8.tar.gz
chromium_src-0acc7f6e27371b58110c5a273de2784c068d1ad8.tar.bz2
[Password manager] Replace the FormFieldData vector from autofill::FormData with named-fields (Clean-up).
BUG=417295 Review URL: https://codereview.chromium.org/614023002 Cr-Commit-Position: refs/heads/master@{#303603}
Diffstat (limited to 'components/autofill')
-rw-r--r--components/autofill/content/common/autofill_messages.h7
-rw-r--r--components/autofill/content/renderer/password_autofill_agent.cc48
-rw-r--r--components/autofill/core/common/autofill_data_validation.cc7
-rw-r--r--components/autofill/core/common/password_form_fill_data.cc14
-rw-r--r--components/autofill/core/common/password_form_fill_data.h19
5 files changed, 54 insertions, 41 deletions
diff --git a/components/autofill/content/common/autofill_messages.h b/components/autofill/content/common/autofill_messages.h
index 57b6a9a..cd5cd1e 100644
--- a/components/autofill/content/common/autofill_messages.h
+++ b/components/autofill/content/common/autofill_messages.h
@@ -77,7 +77,12 @@ IPC_STRUCT_TRAITS_BEGIN(autofill::UsernamesCollectionKey)
IPC_STRUCT_TRAITS_END()
IPC_STRUCT_TRAITS_BEGIN(autofill::PasswordFormFillData)
- IPC_STRUCT_TRAITS_MEMBER(basic_data)
+ IPC_STRUCT_TRAITS_MEMBER(name)
+ IPC_STRUCT_TRAITS_MEMBER(origin)
+ IPC_STRUCT_TRAITS_MEMBER(action)
+ IPC_STRUCT_TRAITS_MEMBER(user_submitted)
+ IPC_STRUCT_TRAITS_MEMBER(username_field)
+ IPC_STRUCT_TRAITS_MEMBER(password_field)
IPC_STRUCT_TRAITS_MEMBER(preferred_realm)
IPC_STRUCT_TRAITS_MEMBER(additional_logins)
IPC_STRUCT_TRAITS_MEMBER(other_possible_usernames)
diff --git a/components/autofill/content/renderer/password_autofill_agent.cc b/components/autofill/content/renderer/password_autofill_agent.cc
index 2dc195e..cc24a9d 100644
--- a/components/autofill/content/renderer/password_autofill_agent.cc
+++ b/components/autofill/content/renderer/password_autofill_agent.cc
@@ -61,6 +61,10 @@ struct FormElements {
typedef std::vector<FormElements*> FormElementsList;
+bool FillDataContainsUsername(const PasswordFormFillData& fill_data) {
+ return !fill_data.username_field.name.empty();
+}
+
// Utility function to find the unique entry of the |form_element| for the
// specified input |field|. On successful find, adds it to |result| and returns
// |true|. Otherwise clears the references from each |HTMLInputElement| from
@@ -118,25 +122,16 @@ bool FindFormInputElement(blink::WebFormElement* form_element,
// Helper to search the given form element for the specified input elements in
// |data|, and add results to |result|.
bool FindFormInputElements(blink::WebFormElement* form_element,
- const FormData& data,
+ const PasswordFormFillData& data,
FormElements* result) {
- const bool username_is_present = !data.fields[0].name.empty();
-
- // Loop through the list of elements we need to find on the form in order to
- // autofill it. If we don't find any one of them, abort processing this
- // form; it can't be the right one.
- // First field is the username, skip it if not present.
- for (size_t j = (username_is_present ? 0 : 1); j < data.fields.size(); ++j) {
- if (!FindFormInputElement(form_element, data.fields[j], result))
- return false;
- }
-
- return true;
+ return FindFormInputElement(form_element, data.password_field, result) &&
+ (!FillDataContainsUsername(data) ||
+ FindFormInputElement(form_element, data.username_field, result));
}
// Helper to locate form elements identified by |data|.
void FindFormElements(blink::WebView* view,
- const FormData& data,
+ const PasswordFormFillData& data,
FormElementsList* results) {
DCHECK(view);
DCHECK(results);
@@ -244,10 +239,6 @@ void LogHTMLForm(SavePasswordProgressLogger* logger,
GURL(form.action().utf8()));
}
-bool FillDataContainsUsername(const PasswordFormFillData& fill_data) {
- return !fill_data.basic_data.fields[0].name.empty();
-}
-
// 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
@@ -269,8 +260,8 @@ bool GetSuggestionsStats(const PasswordFormFillData& fill_data,
}
}
- if (show_all || StartsWith(fill_data.basic_data.fields[0].value,
- current_username, false)) {
+ if (show_all ||
+ StartsWith(fill_data.username_field.value, current_username, false)) {
*suggestions_present = true;
return false;
}
@@ -312,11 +303,10 @@ bool FillUserNameAndPassword(
base::string16 password;
// Look for any suitable matches to current field text.
- if (DoUsernamesMatch(fill_data.basic_data.fields[0].value,
- current_username,
+ if (DoUsernamesMatch(fill_data.username_field.value, current_username,
exact_username_match)) {
- username = fill_data.basic_data.fields[0].value;
- password = fill_data.basic_data.fields[1].value;
+ username = fill_data.username_field.value;
+ password = fill_data.password_field.value;
} else {
// Scan additional logins for a match.
PasswordFormFillData::LoginCollection::const_iterator iter;
@@ -412,7 +402,7 @@ bool FillFormOnPasswordRecieved(
IsElementAutocompletable(username_element) &&
username_element.value().isEmpty()) {
// TODO(tkent): Check maxlength and pattern.
- username_element.setValue(fill_data.basic_data.fields[0].value, true);
+ username_element.setValue(fill_data.username_field.value, true);
}
// Fill if we have an exact match for the username. Note that this sets
@@ -1027,7 +1017,7 @@ void PasswordAutofillAgent::OnFillPasswordForm(
FormElementsList forms;
// We own the FormElements* in forms.
- FindFormElements(render_view()->GetWebView(), form_data.basic_data, &forms);
+ FindFormElements(render_view()->GetWebView(), form_data, &forms);
FormElementsList::iterator iter;
for (iter = forms.begin(); iter != forms.end(); ++iter) {
scoped_ptr<FormElements> form_elements(*iter);
@@ -1039,17 +1029,17 @@ void PasswordAutofillAgent::OnFillPasswordForm(
bool form_contains_username_field = FillDataContainsUsername(form_data);
if (form_contains_username_field) {
username_element =
- form_elements->input_elements[form_data.basic_data.fields[0].name];
+ form_elements->input_elements[form_data.username_field.name];
}
// No password field, bail out.
- if (form_data.basic_data.fields[1].name.empty())
+ if (form_data.password_field.name.empty())
break;
// Get pointer to password element. (We currently only support single
// password forms).
password_element =
- form_elements->input_elements[form_data.basic_data.fields[1].name];
+ form_elements->input_elements[form_data.password_field.name];
// If wait_for_username is true, we don't want to initially fill the form
// until the user types in a valid username.
diff --git a/components/autofill/core/common/autofill_data_validation.cc b/components/autofill/core/common/autofill_data_validation.cc
index c8f6584..578cc04 100644
--- a/components/autofill/core/common/autofill_data_validation.cc
+++ b/components/autofill/core/common/autofill_data_validation.cc
@@ -59,9 +59,12 @@ bool IsValidFormData(const FormData& form) {
}
bool IsValidPasswordFormFillData(const PasswordFormFillData& form) {
- if (!IsValidFormData(form.basic_data) ||
- !IsValidString(form.preferred_realm))
+ if (!IsValidString16(form.name) || !IsValidGURL(form.origin) ||
+ !IsValidGURL(form.action) || !IsValidFormFieldData(form.username_field) ||
+ !IsValidFormFieldData(form.password_field) ||
+ !IsValidString(form.preferred_realm)) {
return false;
+ }
for (PasswordFormFillData::LoginCollection::const_iterator it =
form.additional_logins.begin();
diff --git a/components/autofill/core/common/password_form_fill_data.cc b/components/autofill/core/common/password_form_fill_data.cc
index ffc3db7..714e8f5 100644
--- a/components/autofill/core/common/password_form_fill_data.cc
+++ b/components/autofill/core/common/password_form_fill_data.cc
@@ -22,7 +22,8 @@ bool UsernamesCollectionKey::operator<(
return realm < other.realm;
}
-PasswordFormFillData::PasswordFormFillData() : wait_for_username(false) {
+PasswordFormFillData::PasswordFormFillData()
+ : user_submitted(false), wait_for_username(false) {
}
PasswordFormFillData::~PasswordFormFillData() {
@@ -47,11 +48,12 @@ void InitPasswordFormFillData(
password_field.form_control_type = "password";
// Fill basic form data.
- result->basic_data.name = form_on_page.form_data.name;
- result->basic_data.origin = form_on_page.origin;
- result->basic_data.action = form_on_page.action;
- result->basic_data.fields.push_back(username_field);
- result->basic_data.fields.push_back(password_field);
+ result->name = form_on_page.form_data.name;
+ result->origin = form_on_page.origin;
+ result->action = form_on_page.action;
+ result->user_submitted = form_on_page.form_data.user_submitted;
+ result->username_field = username_field;
+ result->password_field = password_field;
result->wait_for_username = wait_for_username_before_autofill;
result->preferred_realm = preferred_match->original_signon_realm;
diff --git a/components/autofill/core/common/password_form_fill_data.h b/components/autofill/core/common/password_form_fill_data.h
index 14c4759..31333d2 100644
--- a/components/autofill/core/common/password_form_fill_data.h
+++ b/components/autofill/core/common/password_form_fill_data.h
@@ -39,9 +39,22 @@ struct PasswordFormFillData {
typedef std::map<UsernamesCollectionKey,
std::vector<base::string16> > UsernamesCollection;
- // Identifies the HTML form on the page and preferred username/password for
- // login.
- FormData basic_data;
+ // The name of the form.
+ base::string16 name;
+
+ // An origin is (scheme, host, port, path and fragment identifier) only; it is
+ // just exactly a URL with the query string removed.
+ GURL origin;
+
+ // The action target of the form.
+ GURL action;
+
+ // True if this form was submitted by a user gesture and not javascript.
+ bool user_submitted;
+
+ // Username and password input fields in the form.
+ FormFieldData username_field;
+ FormFieldData password_field;
// The signon realm of the preferred user/pass pair.
std::string preferred_realm;