diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-15 23:51:24 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-15 23:51:24 +0000 |
commit | 45c6e53a2c50e19a3f79fcc6f05914793ed93de6 (patch) | |
tree | e4f0c22f63fe5197938dc868f00c7d6a8e2ea8a6 /webkit/glue | |
parent | cffa2055808bf2149ce48118dcacde477b7ead60 (diff) | |
download | chromium_src-45c6e53a2c50e19a3f79fcc6f05914793ed93de6.zip chromium_src-45c6e53a2c50e19a3f79fcc6f05914793ed93de6.tar.gz chromium_src-45c6e53a2c50e19a3f79fcc6f05914793ed93de6.tar.bz2 |
FormFieldValues -> FormData consolidation: Use webkit_glue::FormField to store field data in FormData instead of storing the field data separately in the struct.
BUG=33032
TEST=none
Review URL: http://codereview.chromium.org/847002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41658 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r-- | webkit/glue/dom_operations.cc | 14 | ||||
-rw-r--r-- | webkit/glue/form_data.h | 15 | ||||
-rw-r--r-- | webkit/glue/form_field.cc | 30 | ||||
-rw-r--r-- | webkit/glue/form_field.h | 8 | ||||
-rw-r--r-- | webkit/glue/password_form_dom_manager.cc | 19 | ||||
-rw-r--r-- | webkit/glue/webpasswordautocompletelistener_impl.cc | 14 | ||||
-rw-r--r-- | webkit/glue/webpasswordautocompletelistener_unittest.cc | 18 |
7 files changed, 81 insertions, 37 deletions
diff --git a/webkit/glue/dom_operations.cc b/webkit/glue/dom_operations.cc index 9996675..f42270d 100644 --- a/webkit/glue/dom_operations.cc +++ b/webkit/glue/dom_operations.cc @@ -175,8 +175,8 @@ static bool FillFormImpl(FormElements* fe, const FormData& data) { return false; std::map<string16, string16> data_map; - for (unsigned int i = 0; i < data.elements.size(); i++) { - data_map[data.elements[i]] = data.values[i]; + for (size_t i = 0; i < data.fields.size(); i++) { + data_map[data.fields[i].name()] = data.fields[i].value(); } for (FormInputElementMap::iterator it = fe->input_elements.begin(); @@ -199,9 +199,9 @@ static bool FindFormInputElements(WebFormElement* fe, // 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. - for (size_t j = 0; j < data.elements.size(); j++) { + for (size_t j = 0; j < data.fields.size(); j++) { WebVector<WebNode> temp_elements; - fe->getNamedElements(data.elements[j], temp_elements); + fe->getNamedElements(data.fields[j].name(), temp_elements); if (temp_elements.isEmpty()) { // We didn't find a required element. This is not the right form. // Make sure no input elements from a partially matched form @@ -215,7 +215,7 @@ static bool FindFormInputElements(WebFormElement* fe, // one suffices and if some function needs to deal with multiple // matching elements it can get at them through the FormElement*. // Note: This assignment adds a reference to the InputElement. - result->input_elements[data.elements[j]] = + result->input_elements[data.fields[j].name()] = temp_elements[0].toElement<WebInputElement>(); } return true; @@ -286,12 +286,12 @@ void FillPasswordForm(WebView* view, // Attach autocomplete listener to enable selecting alternate logins. // First, get pointers to username element. WebInputElement username_element = - form_elements->input_elements[data.basic_data.elements[0]]; + form_elements->input_elements[data.basic_data.fields[0].name()]; // Get pointer to password element. (We currently only support single // password forms). WebInputElement password_element = - form_elements->input_elements[data.basic_data.elements[1]]; + form_elements->input_elements[data.basic_data.fields[1].name()]; username_element.frame()->registerPasswordListener( username_element, diff --git a/webkit/glue/form_data.h b/webkit/glue/form_data.h index aab222e..5309a2e 100644 --- a/webkit/glue/form_data.h +++ b/webkit/glue/form_data.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,6 +8,9 @@ #include <vector> #include "googleurl/src/gurl.h" +#include "webkit/glue/form_field.h" + +namespace webkit_glue { // Holds information about a form to be filled and/or submitted. struct FormData { @@ -17,12 +20,10 @@ struct FormData { GURL origin; // The action target of the form GURL action; - // A vector of element labels. - std::vector<string16> labels; - // A vector of element names. - std::vector<string16> elements; - // A vector of element values. - std::vector<string16> values; + // A vector of all the input fields in the form. + std::vector<FormField> fields; }; +} // namespace webkit_glue + #endif // WEBKIT_GLUE_FORM_DATA_H__ diff --git a/webkit/glue/form_field.cc b/webkit/glue/form_field.cc index 56f057f..721b3a7 100644 --- a/webkit/glue/form_field.cc +++ b/webkit/glue/form_field.cc @@ -1,10 +1,11 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "webkit/glue/form_field.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" using WebKit::WebInputElement; @@ -39,13 +40,30 @@ FormField::FormField(const string16& label, input_type_(input_type) { } -bool FormField::operator!=(const FormField& field) { +bool FormField::operator==(const FormField& field) const { // A FormField stores a value, but the value is not part of the identity of // the field, so we don't want to compare the values. - return (label_ != field.label_ || - name_ != field.name_ || - form_control_type_ != field.form_control_type_ || - input_type_ != field.input_type_); + return (label_ == field.label_ && + name_ == field.name_ && + form_control_type_ == field.form_control_type_ && + input_type_ == field.input_type_); +} + +bool FormField::operator!=(const FormField& field) const { + return !operator==(field); +} + +std::ostream& operator<<(std::ostream& os, const FormField& field) { + return os + << UTF16ToUTF8(field.label()) + << " " + << UTF16ToUTF8(field.name()) + << " " + << UTF16ToUTF8(field.value()) + << " " + << UTF16ToUTF8(field.form_control_type()) + << " " + << field.input_type(); } } // namespace webkit_glue diff --git a/webkit/glue/form_field.h b/webkit/glue/form_field.h index 88e3ed9..d6447fa 100644 --- a/webkit/glue/form_field.h +++ b/webkit/glue/form_field.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -37,7 +37,8 @@ class FormField { input_type_ = input_type; } - bool operator!=(const FormField& field); + bool operator==(const FormField& field) const; + bool operator!=(const FormField& field) const; private: string16 label_; @@ -47,6 +48,9 @@ class FormField { WebKit::WebInputElement::InputType input_type_; }; +// So we can compare FormFields with EXPECT_EQ(). +std::ostream& operator<<(std::ostream& os, const FormField& profile); + } // namespace webkit_glue #endif // WEBKIT_GLUE_FORM_FIELD_H_ diff --git a/webkit/glue/password_form_dom_manager.cc b/webkit/glue/password_form_dom_manager.cc index e46560c..8dd8df4 100644 --- a/webkit/glue/password_form_dom_manager.cc +++ b/webkit/glue/password_form_dom_manager.cc @@ -5,9 +5,12 @@ #include "webkit/glue/password_form_dom_manager.h" #include "base/logging.h" +#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" #include "third_party/WebKit/WebKit/chromium/public/WebPasswordFormData.h" +#include "webkit/glue/form_field.h" using WebKit::WebFormElement; +using WebKit::WebInputElement; using WebKit::WebPasswordFormData; namespace webkit_glue { @@ -31,10 +34,18 @@ void PasswordFormDomManager::InitFillData( // Fill basic form data. result->basic_data.origin = form_on_page.origin; result->basic_data.action = form_on_page.action; - result->basic_data.elements.push_back(form_on_page.username_element); - result->basic_data.values.push_back(preferred_match->username_value); - result->basic_data.elements.push_back(form_on_page.password_element); - result->basic_data.values.push_back(preferred_match->password_value); + result->basic_data.fields.push_back( + FormField(string16(), + form_on_page.username_element, + preferred_match->username_value, + string16(), + WebInputElement::Text)); + result->basic_data.fields.push_back( + FormField(string16(), + form_on_page.password_element, + preferred_match->password_value, + string16(), + WebInputElement::Password)); result->wait_for_username = wait_for_username_before_autofill; // Copy additional username/value pairs. diff --git a/webkit/glue/webpasswordautocompletelistener_impl.cc b/webkit/glue/webpasswordautocompletelistener_impl.cc index ed524f7..3415a22 100644 --- a/webkit/glue/webpasswordautocompletelistener_impl.cc +++ b/webkit/glue/webpasswordautocompletelistener_impl.cc @@ -73,9 +73,9 @@ void WebPasswordAutocompleteListenerImpl::didBlurInputElement( string16 user_input16 = user_input; // Set the password field to match the current username. - if (data_.basic_data.values[0] == user_input16) { + if (data_.basic_data.fields[0].value() == user_input16) { // Preferred username/login is selected. - password_delegate_->SetValue(data_.basic_data.values[1]); + password_delegate_->SetValue(data_.basic_data.fields[1].value()); } else if (data_.additional_logins.find(user_input16) != data_.additional_logins.end()) { // One of the extra username/logins is selected. @@ -113,8 +113,8 @@ void WebPasswordAutocompleteListenerImpl::performInlineAutocomplete( // conversions (see SetValue) on each successful call to // OnInlineAutocompleteNeeded. if (TryToMatch(user_input16, - data_.basic_data.values[0], - data_.basic_data.values[1])) { + data_.basic_data.fields[0].value(), + data_.basic_data.fields[1].value())) { return; } @@ -145,8 +145,8 @@ bool WebPasswordAutocompleteListenerImpl::TryToMatch(const string16& input, void WebPasswordAutocompleteListenerImpl::GetSuggestions( const string16& input, std::vector<string16>* suggestions) { - if (StartsWith(data_.basic_data.values[0], input, false)) - suggestions->push_back(data_.basic_data.values[0]); + if (StartsWith(data_.basic_data.fields[0].value(), input, false)) + suggestions->push_back(data_.basic_data.fields[0].value()); for (PasswordFormDomManager::LoginCollection::iterator it = data_.additional_logins.begin(); @@ -157,4 +157,4 @@ void WebPasswordAutocompleteListenerImpl::GetSuggestions( } } -} // webkit_glue +} // namespace webkit_glue diff --git a/webkit/glue/webpasswordautocompletelistener_unittest.cc b/webkit/glue/webpasswordautocompletelistener_unittest.cc index e432e42..eb7aab8 100644 --- a/webkit/glue/webpasswordautocompletelistener_unittest.cc +++ b/webkit/glue/webpasswordautocompletelistener_unittest.cc @@ -9,13 +9,15 @@ #include <string> #include "base/string_util.h" -#include "webkit/glue/webpasswordautocompletelistener_impl.h" #include "testing/gtest/include/gtest/gtest.h" +#include "webkit/glue/form_field.h" +#include "webkit/glue/webpasswordautocompletelistener_impl.h" using WebKit::WebString; -using webkit_glue::WebPasswordAutocompleteListenerImpl; +using webkit_glue::FormField; using webkit_glue::PasswordFormDomManager; using webkit_glue::WebInputElementDelegate; +using webkit_glue::WebPasswordAutocompleteListenerImpl; class TestWebInputElementDelegate : public WebInputElementDelegate { public: @@ -92,8 +94,16 @@ class PasswordManagerAutocompleteTests : public testing::Test { password1_ = ASCIIToUTF16("password"); username2_ = ASCIIToUTF16("bob"); password2_ = ASCIIToUTF16("bobsyouruncle"); - data_.basic_data.values.push_back(username1_); - data_.basic_data.values.push_back(password1_); + data_.basic_data.fields.push_back(FormField(string16(), + string16(), + username1_, + string16(), + WebInputElement::Text)); + data_.basic_data.fields.push_back(FormField(string16(), + string16(), + password1_, + string16(), + WebInputElement::Text)); data_.additional_logins[username2_] = password2_; testing::Test::SetUp(); } |