diff options
author | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-03 00:30:59 +0000 |
---|---|---|
committer | jhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-03 00:30:59 +0000 |
commit | b143821ab651df119648c0a201b6ab4bf616a500 (patch) | |
tree | bb9946d52d2d1937bbfc3d2de641a0fabca80c3f /chrome | |
parent | 89098b14454bd3e9ec38c98084e1e0488de67fb3 (diff) | |
download | chromium_src-b143821ab651df119648c0a201b6ab4bf616a500.zip chromium_src-b143821ab651df119648c0a201b6ab4bf616a500.tar.gz chromium_src-b143821ab651df119648c0a201b6ab4bf616a500.tar.bz2 |
AutoFill: Use the FormManager cache to send forms to the AutoFillManager.
Remove the FormFieldValues class and replace its usage with FormData.
BUG=38325,33032
TEST=none
Review URL: http://codereview.chromium.org/1606005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43555 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
23 files changed, 446 insertions, 411 deletions
diff --git a/chrome/browser/autocomplete_history_manager.cc b/chrome/browser/autocomplete_history_manager.cc index 280ea85..7626f9c 100644 --- a/chrome/browser/autocomplete_history_manager.cc +++ b/chrome/browser/autocomplete_history_manager.cc @@ -12,7 +12,9 @@ #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/pref_names.h" -#include "webkit/glue/form_field_values.h" +#include "webkit/glue/form_data.h" + +using webkit_glue::FormData; // Limit on the number of suggestions to appear in the pop-up menu under an // text input element in a form. @@ -48,8 +50,7 @@ Profile* AutocompleteHistoryManager::profile() { return tab_contents_->profile(); } -void AutocompleteHistoryManager::FormFieldValuesSubmitted( - const webkit_glue::FormFieldValues& form) { +void AutocompleteHistoryManager::FormSubmitted(const FormData& form) { StoreFormEntriesInWebDatabase(form); } @@ -101,7 +102,7 @@ void AutocompleteHistoryManager::OnWebDataServiceRequestDone( } void AutocompleteHistoryManager::StoreFormEntriesInWebDatabase( - const webkit_glue::FormFieldValues& form) { + const FormData& form) { if (!*form_autofill_enabled_) return; @@ -114,8 +115,8 @@ void AutocompleteHistoryManager::StoreFormEntriesInWebDatabase( // - text field std::vector<webkit_glue::FormField> values; for (std::vector<webkit_glue::FormField>::const_iterator iter = - form.elements.begin(); - iter != form.elements.end(); ++iter) { + form.fields.begin(); + iter != form.fields.end(); ++iter) { if (!iter->value().empty() && !iter->name().empty() && iter->form_control_type() == ASCIIToUTF16("text")) diff --git a/chrome/browser/autocomplete_history_manager.h b/chrome/browser/autocomplete_history_manager.h index 1d6966f..2f8fe5e 100644 --- a/chrome/browser/autocomplete_history_manager.h +++ b/chrome/browser/autocomplete_history_manager.h @@ -12,8 +12,8 @@ #include "chrome/browser/webdata/web_data_service.h" namespace webkit_glue { -class FormFieldValues; -} +struct FormData; +} // namespace webkit_glue class Profile; class TabContents; @@ -30,8 +30,7 @@ class AutocompleteHistoryManager Profile* profile(); // RenderViewHostDelegate::Autocomplete implementation. - virtual void FormFieldValuesSubmitted( - const webkit_glue::FormFieldValues& form); + virtual void FormSubmitted(const webkit_glue::FormData& form); virtual bool GetAutocompleteSuggestions(int query_id, const string16& name, const string16& prefix); @@ -44,7 +43,7 @@ class AutocompleteHistoryManager private: void CancelPendingQuery(); - void StoreFormEntriesInWebDatabase(const webkit_glue::FormFieldValues& form); + void StoreFormEntriesInWebDatabase(const webkit_glue::FormData& form); void SendSuggestions(const WDTypedResult* suggestions); TabContents* tab_contents_; diff --git a/chrome/browser/autofill/address_field_unittest.cc b/chrome/browser/autofill/address_field_unittest.cc index bbcbcf2..322e697 100644 --- a/chrome/browser/autofill/address_field_unittest.cc +++ b/chrome/browser/autofill/address_field_unittest.cc @@ -7,7 +7,7 @@ #include "chrome/browser/autofill/address_field.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" -#include "webkit/glue/form_field_values.h" +#include "webkit/glue/form_field.h" namespace { diff --git a/chrome/browser/autofill/autofill_download_unittest.cc b/chrome/browser/autofill/autofill_download_unittest.cc index e1df3b8..fe09261a 100644 --- a/chrome/browser/autofill/autofill_download_unittest.cc +++ b/chrome/browser/autofill/autofill_download_unittest.cc @@ -11,8 +11,9 @@ #include "net/url_request/url_request_status.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" -#include "webkit/glue/form_field_values.h" +#include "webkit/glue/form_data.h" +using webkit_glue::FormData; using WebKit::WebInputElement; // This tests AutoFillDownloadManager. AutoFillDownloadTestHelper implements @@ -99,52 +100,52 @@ TEST(AutoFillDownloadTest, QueryAndUploadTest) { TestURLFetcherFactory factory; URLFetcher::set_factory(&factory); - webkit_glue::FormFieldValues values; - values.method = ASCIIToUTF16("post"); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), - ASCIIToUTF16("username"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), - ASCIIToUTF16("email"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("email2"), - ASCIIToUTF16("email2"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), - ASCIIToUTF16("password"), - string16(), - ASCIIToUTF16("password"))); - values.elements.push_back(webkit_glue::FormField(string16(), - ASCIIToUTF16("Submit"), - string16(), - ASCIIToUTF16("submit"))); + FormData form; + form.method = ASCIIToUTF16("post"); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), + ASCIIToUTF16("username"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email"), + ASCIIToUTF16("email"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("email2"), + ASCIIToUTF16("email2"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), + ASCIIToUTF16("password"), + string16(), + ASCIIToUTF16("password"))); + form.fields.push_back(webkit_glue::FormField(string16(), + ASCIIToUTF16("Submit"), + string16(), + ASCIIToUTF16("submit"))); - FormStructure *form = new FormStructure(values); + FormStructure *form_structure = new FormStructure(form); ScopedVector<FormStructure> form_structures; - form_structures.push_back(form); + form_structures.push_back(form_structure); - values.elements.clear(); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("address"), - ASCIIToUTF16("address"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("address2"), - ASCIIToUTF16("address2"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("city"), - ASCIIToUTF16("address2"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(string16(), - ASCIIToUTF16("Submit"), - string16(), - ASCIIToUTF16("submit"))); - form = new FormStructure(values); - form_structures.push_back(form); + form.fields.clear(); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("address"), + ASCIIToUTF16("address"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("address2"), + ASCIIToUTF16("address2"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("city"), + ASCIIToUTF16("address2"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(string16(), + ASCIIToUTF16("Submit"), + string16(), + ASCIIToUTF16("submit"))); + form_structure = new FormStructure(form); + form_structures.push_back(form_structure); // Request with id 0. EXPECT_TRUE(helper.download_manager.StartQueryRequest(form_structures)); diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc index 5bed021..b651a97 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -19,7 +19,9 @@ #include "chrome/common/pref_names.h" #include "webkit/glue/form_data.h" #include "webkit/glue/form_field.h" -#include "webkit/glue/form_field_values.h" + +using webkit_glue::FormData; +using webkit_glue::FormField; namespace { // We only send a fraction of the forms to upload server. @@ -68,8 +70,7 @@ void AutoFillManager::RegisterUserPrefs(PrefService* prefs) { kAutoFillNegativeUploadRateDefaultValue); } -void AutoFillManager::FormFieldValuesSubmitted( - const webkit_glue::FormFieldValues& form) { +void AutoFillManager::FormSubmitted(const FormData& form) { if (!IsAutoFillEnabled()) return; @@ -95,29 +96,22 @@ void AutoFillManager::FormFieldValuesSubmitted( } } -void AutoFillManager::FormsSeen( - const std::vector<webkit_glue::FormFieldValues>& forms) { +void AutoFillManager::FormsSeen(const std::vector<FormData>& forms) { if (!IsAutoFillEnabled()) return; - for (std::vector<webkit_glue::FormFieldValues>::const_iterator iter = + for (std::vector<FormData>::const_iterator iter = forms.begin(); iter != forms.end(); ++iter) { FormStructure* form_structure = new FormStructure(*iter); DeterminePossibleFieldTypes(form_structure); form_structures_.push_back(form_structure); } - - // Only query the server for form data if the user has profile or - // credit card data set up. - if (!personal_data_->profiles().empty() || - !personal_data_->credit_cards().empty()) { - download_manager_.StartQueryRequest(form_structures_); - } + download_manager_.StartQueryRequest(form_structures_); } -bool AutoFillManager::GetAutoFillSuggestions( - int query_id, const webkit_glue::FormField& field) { +bool AutoFillManager::GetAutoFillSuggestions(int query_id, + const FormField& field) { if (!IsAutoFillEnabled()) return false; @@ -225,7 +219,7 @@ bool AutoFillManager::GetAutoFillSuggestions( } bool AutoFillManager::FillAutoFillFormData(int query_id, - const webkit_glue::FormData& form, + const FormData& form, const string16& name, const string16& label) { if (!IsAutoFillEnabled()) @@ -275,7 +269,7 @@ bool AutoFillManager::FillAutoFillFormData(int query_id, if (!profile && !credit_card) return false; - webkit_glue::FormData result = form; + FormData result = form; for (std::vector<FormStructure*>::const_iterator iter = form_structures_.begin(); iter != form_structures_.end(); ++iter) { diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h index d89d5da..b9eafbf 100644 --- a/chrome/browser/autofill/autofill_manager.h +++ b/chrome/browser/autofill/autofill_manager.h @@ -18,8 +18,7 @@ namespace webkit_glue { struct FormData; class FormField; -class FormFieldValues; -} +} // namespace webkit_glue class AutoFillInfoBarDelegate; class AutoFillProfile; @@ -45,10 +44,9 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill, static void RegisterUserPrefs(PrefService* prefs); // RenderViewHostDelegate::AutoFill implementation: - virtual void FormFieldValuesSubmitted( - const webkit_glue::FormFieldValues& form); + virtual void FormSubmitted(const webkit_glue::FormData& form); virtual void FormsSeen( - const std::vector<webkit_glue::FormFieldValues>& forms); + const std::vector<webkit_glue::FormData>& forms); virtual bool GetAutoFillSuggestions(int query_id, const webkit_glue::FormField& field); virtual bool FillAutoFillFormData(int query_id, diff --git a/chrome/browser/autofill/credit_card_field_unittest.cc b/chrome/browser/autofill/credit_card_field_unittest.cc index efadf7a..dbd9923 100644 --- a/chrome/browser/autofill/credit_card_field_unittest.cc +++ b/chrome/browser/autofill/credit_card_field_unittest.cc @@ -6,7 +6,7 @@ #include "base/scoped_vector.h" #include "chrome/browser/autofill/credit_card_field.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/glue/form_field_values.h" +#include "webkit/glue/form_field.h" namespace { diff --git a/chrome/browser/autofill/form_structure.cc b/chrome/browser/autofill/form_structure.cc index d0f2a71..bb91ec9 100644 --- a/chrome/browser/autofill/form_structure.cc +++ b/chrome/browser/autofill/form_structure.cc @@ -14,10 +14,8 @@ #include "third_party/libjingle/files/talk/xmllite/xmlelement.h" #include "webkit/glue/form_data.h" #include "webkit/glue/form_field.h" -#include "webkit/glue/form_field_values.h" using webkit_glue::FormData; -using webkit_glue::FormFieldValues; namespace { @@ -59,14 +57,14 @@ static std::string Hash64Bit(const std::string& str) { } // namespace -FormStructure::FormStructure(const FormFieldValues& values) - : form_name_(UTF16ToUTF8(values.form_name)), - source_url_(values.source_url), - target_url_(values.target_url) { +FormStructure::FormStructure(const FormData& form) + : form_name_(UTF16ToUTF8(form.name)), + source_url_(form.origin), + target_url_(form.action) { // Copy the form fields. std::vector<webkit_glue::FormField>::const_iterator field; - for (field = values.elements.begin(); - field != values.elements.end(); field++) { + for (field = form.fields.begin(); + field != form.fields.end(); field++) { // We currently only handle text and select fields. This prevents us from // thinking we can autofill other types of controls, e.g., password, hidden, // submit. @@ -87,7 +85,7 @@ FormStructure::FormStructure(const FormFieldValues& values) // Terminate the vector with a NULL item. fields_.push_back(NULL); - std::string method = UTF16ToUTF8(values.method); + std::string method = UTF16ToUTF8(form.method); if (method == kFormMethodPost) { method_ = POST; } else { diff --git a/chrome/browser/autofill/form_structure.h b/chrome/browser/autofill/form_structure.h index bb20885..4028117 100644 --- a/chrome/browser/autofill/form_structure.h +++ b/chrome/browser/autofill/form_structure.h @@ -20,7 +20,6 @@ namespace buzz { namespace webkit_glue { struct FormData; -class FormFieldValues; } // namespace webkit_glue enum RequestMethod { @@ -38,7 +37,7 @@ enum UploadRequired { // in the fields along with additional information needed by AutoFill. class FormStructure { public: - explicit FormStructure(const webkit_glue::FormFieldValues& values); + explicit FormStructure(const webkit_glue::FormData& form); // Encodes the XML upload request from this FormStructure. bool EncodeUploadRequest(bool auto_fill_used, diff --git a/chrome/browser/autofill/form_structure_unittest.cc b/chrome/browser/autofill/form_structure_unittest.cc index f528d24..cfc535a 100644 --- a/chrome/browser/autofill/form_structure_unittest.cc +++ b/chrome/browser/autofill/form_structure_unittest.cc @@ -8,28 +8,29 @@ #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" -#include "webkit/glue/form_field_values.h" +#include "webkit/glue/form_data.h" +using webkit_glue::FormData; using WebKit::WebInputElement; namespace { TEST(FormStructureTest, FieldCount) { - webkit_glue::FormFieldValues values; - values.method = ASCIIToUTF16("post"); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), - ASCIIToUTF16("username"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), - ASCIIToUTF16("password"), - string16(), - ASCIIToUTF16("password"))); - values.elements.push_back(webkit_glue::FormField(string16(), - ASCIIToUTF16("Submit"), - string16(), - ASCIIToUTF16("submit"))); - FormStructure form_structure(values); + FormData form; + form.method = ASCIIToUTF16("post"); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), + ASCIIToUTF16("username"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), + ASCIIToUTF16("password"), + string16(), + ASCIIToUTF16("password"))); + form.fields.push_back(webkit_glue::FormField(string16(), + ASCIIToUTF16("Submit"), + string16(), + ASCIIToUTF16("submit"))); + FormStructure form_structure(form); // Only text fields are counted. EXPECT_EQ(1U, form_structure.field_count()); @@ -37,96 +38,96 @@ TEST(FormStructureTest, FieldCount) { TEST(FormStructureTest, IsAutoFillable) { scoped_ptr<FormStructure> form_structure; - webkit_glue::FormFieldValues values; + FormData form; // We need at least three text fields to be auto-fillable. - values.method = ASCIIToUTF16("post"); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), - ASCIIToUTF16("username"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), - ASCIIToUTF16("password"), - string16(), - ASCIIToUTF16("password"))); - values.elements.push_back(webkit_glue::FormField(string16(), - ASCIIToUTF16("Submit"), - string16(), - ASCIIToUTF16("submit"))); - form_structure.reset(new FormStructure(values)); + form.method = ASCIIToUTF16("post"); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("username"), + ASCIIToUTF16("username"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("password"), + ASCIIToUTF16("password"), + string16(), + ASCIIToUTF16("password"))); + form.fields.push_back(webkit_glue::FormField(string16(), + ASCIIToUTF16("Submit"), + string16(), + ASCIIToUTF16("submit"))); + form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->IsAutoFillable()); // We now have three text fields. - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), - ASCIIToUTF16("firstname"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), - ASCIIToUTF16("lastname"), - string16(), - ASCIIToUTF16("text"))); - form_structure.reset(new FormStructure(values)); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), + ASCIIToUTF16("firstname"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), + ASCIIToUTF16("lastname"), + string16(), + ASCIIToUTF16("text"))); + form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); // The method must be 'post'. - values.method = ASCIIToUTF16("get"); - form_structure.reset(new FormStructure(values)); + form.method = ASCIIToUTF16("get"); + form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->IsAutoFillable()); // The target cannot include http(s)://*/search... - values.method = ASCIIToUTF16("post"); - values.target_url = GURL("http://google.com/search?q=hello"); - form_structure.reset(new FormStructure(values)); + form.method = ASCIIToUTF16("post"); + form.action = GURL("http://google.com/search?q=hello"); + form_structure.reset(new FormStructure(form)); EXPECT_FALSE(form_structure->IsAutoFillable()); // But search can be in the URL. - values.target_url = GURL("http://search.com/?q=hello"); - form_structure.reset(new FormStructure(values)); + form.action = GURL("http://search.com/?q=hello"); + form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); } TEST(FormStructureTest, HeuristicsContactInfo) { scoped_ptr<FormStructure> form_structure; - webkit_glue::FormFieldValues values; - - values.method = ASCIIToUTF16("post"); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), - ASCIIToUTF16("firstname"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), - ASCIIToUTF16("lastname"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), - ASCIIToUTF16("email"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), - ASCIIToUTF16("phone"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), - ASCIIToUTF16("fax"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), - ASCIIToUTF16("address"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("City"), - ASCIIToUTF16("city"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Zip code"), - ASCIIToUTF16("zipcode"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(string16(), - ASCIIToUTF16("Submit"), - string16(), - ASCIIToUTF16("submit"))); - form_structure.reset(new FormStructure(values)); + FormData form; + + form.method = ASCIIToUTF16("post"); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), + ASCIIToUTF16("firstname"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), + ASCIIToUTF16("lastname"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), + ASCIIToUTF16("email"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), + ASCIIToUTF16("phone"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), + ASCIIToUTF16("fax"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), + ASCIIToUTF16("address"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("City"), + ASCIIToUTF16("city"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Zip code"), + ASCIIToUTF16("zipcode"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(string16(), + ASCIIToUTF16("Submit"), + string16(), + ASCIIToUTF16("submit"))); + form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); // Expect the correct number of fields. @@ -173,60 +174,60 @@ TEST(FormStructureTest, HeuristicsContactInfo) { TEST(FormStructureTest, HeuristicsSample8) { scoped_ptr<FormStructure> form_structure; - webkit_glue::FormFieldValues values; + FormData form; - values.method = ASCIIToUTF16("post"); - values.elements.push_back( + form.method = ASCIIToUTF16("post"); + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Your First Name:"), ASCIIToUTF16("bill.first"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Your Last Name:"), ASCIIToUTF16("bill.last"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Street Address Line 1:"), ASCIIToUTF16("bill.street1"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Street Address Line 2:"), ASCIIToUTF16("bill.street2"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("City:"), ASCIIToUTF16("bill.city"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("State (U.S.):"), ASCIIToUTF16("bill.state"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Zip/Postal Code:"), ASCIIToUTF16("BillTo.PostalCode"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Country:"), ASCIIToUTF16("bill.country"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Phone Number:"), ASCIIToUTF16("BillTo.Phone"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), string16(), ASCIIToUTF16("submit"))); - form_structure.reset(new FormStructure(values)); + form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); // Check that heuristics are initialized as UNKNOWN_TYPE. @@ -272,47 +273,47 @@ TEST(FormStructureTest, HeuristicsSample8) { TEST(FormStructureTest, HeuristicsSample6) { scoped_ptr<FormStructure> form_structure; - webkit_glue::FormFieldValues values; + FormData form; - values.method = ASCIIToUTF16("post"); - values.elements.push_back( + form.method = ASCIIToUTF16("post"); + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("E-mail address"), ASCIIToUTF16("email"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Full name"), ASCIIToUTF16("name"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Company"), ASCIIToUTF16("company"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Address"), ASCIIToUTF16("address"), string16(), ASCIIToUTF16("text"))); - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("City"), ASCIIToUTF16("city"), string16(), ASCIIToUTF16("text"))); // TODO(jhawkins): Add state select control. - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(ASCIIToUTF16("Zip Code"), ASCIIToUTF16("Home.PostalCode"), string16(), ASCIIToUTF16("text"))); // TODO(jhawkins): Phone number. - values.elements.push_back( + form.fields.push_back( webkit_glue::FormField(string16(), ASCIIToUTF16("Submit"), ASCIIToUTF16("continue"), ASCIIToUTF16("submit"))); - form_structure.reset(new FormStructure(values)); + form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); // Check that heuristics are initialized as UNKNOWN_TYPE. @@ -354,46 +355,46 @@ TEST(FormStructureTest, HeuristicsSample6) { // that input element ids (or |name| fields) are missing. TEST(FormStructureTest, HeuristicsLabelsOnly) { scoped_ptr<FormStructure> form_structure; - webkit_glue::FormFieldValues values; - - values.method = ASCIIToUTF16("post"); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), - string16(), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), - string16(), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), - string16(), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), - string16(), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), - string16(), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), - string16(), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), - string16(), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Zip code"), - string16(), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(string16(), - ASCIIToUTF16("Submit"), - string16(), - ASCIIToUTF16("submit"))); - form_structure.reset(new FormStructure(values)); + FormData form; + + form.method = ASCIIToUTF16("post"); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"), + string16(), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"), + string16(), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("EMail"), + string16(), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Phone"), + string16(), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Fax"), + string16(), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), + string16(), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Address"), + string16(), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Zip code"), + string16(), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(string16(), + ASCIIToUTF16("Submit"), + string16(), + ASCIIToUTF16("submit"))); + form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); // Expect the correct number of fields. @@ -440,34 +441,34 @@ TEST(FormStructureTest, HeuristicsLabelsOnly) { TEST(FormStructureTest, HeuristicsCreditCardInfo) { scoped_ptr<FormStructure> form_structure; - webkit_glue::FormFieldValues values; + FormData form; - values.method = ASCIIToUTF16("post"); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Name on Card"), + form.method = ASCIIToUTF16("post"); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Name on Card"), ASCIIToUTF16("name on card"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Card Number"), ASCIIToUTF16("card_number"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Month"), ASCIIToUTF16("ccmonth"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Exp Year"), ASCIIToUTF16("ccyear"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Verification"), + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(ASCIIToUTF16("Verification"), ASCIIToUTF16("verification"), - string16(), - ASCIIToUTF16("text"))); - values.elements.push_back(webkit_glue::FormField(string16(), - ASCIIToUTF16("Submit"), - string16(), - ASCIIToUTF16("submit"))); - form_structure.reset(new FormStructure(values)); + string16(), + ASCIIToUTF16("text"))); + form.fields.push_back(webkit_glue::FormField(string16(), + ASCIIToUTF16("Submit"), + string16(), + ASCIIToUTF16("submit"))); + form_structure.reset(new FormStructure(form)); EXPECT_TRUE(form_structure->IsAutoFillable()); // Expect the correct number of fields. diff --git a/chrome/browser/autofill/phone_field_unittest.cc b/chrome/browser/autofill/phone_field_unittest.cc index e12e894..2a4c8c7 100644 --- a/chrome/browser/autofill/phone_field_unittest.cc +++ b/chrome/browser/autofill/phone_field_unittest.cc @@ -7,7 +7,7 @@ #include "chrome/browser/autofill/phone_field.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h" -#include "webkit/glue/form_field_values.h" +#include "webkit/glue/form_field.h" namespace { diff --git a/chrome/browser/chromeos/login/account_creation_view.cc b/chrome/browser/chromeos/login/account_creation_view.cc index 1de0634..1af6c06 100644 --- a/chrome/browser/chromeos/login/account_creation_view.cc +++ b/chrome/browser/chromeos/login/account_creation_view.cc @@ -15,7 +15,9 @@ #include "gfx/canvas.h" #include "ipc/ipc_message.h" #include "views/border.h" -#include "webkit/glue/form_field_values.h" +#include "webkit/glue/form_data.h" + +using webkit_glue::FormData; namespace chromeos { @@ -37,17 +39,16 @@ class AccountCreationTabContents : public TabContents, return this; } - virtual void FormFieldValuesSubmitted( - const webkit_glue::FormFieldValues& form) { - if (UTF16ToASCII(form.form_name) == kCreateAccountFormName) { + virtual void FormSubmitted(const FormData& form) { + if (UTF16ToASCII(form.name) == kCreateAccountFormName) { std::string user_name; std::string domain; - for (size_t i = 0; i < form.elements.size(); i++) { - std::string name = UTF16ToASCII(form.elements[i].name()); + for (size_t i = 0; i < form.fields.size(); i++) { + std::string name = UTF16ToASCII(form.fields[i].name()); if (name == kEmailFieldName) { - user_name = UTF16ToASCII(form.elements[i].value()); + user_name = UTF16ToASCII(form.fields[i].value()); } else if (name == kDomainFieldName) { - domain = UTF16ToASCII(form.elements[i].value()); + domain = UTF16ToASCII(form.fields[i].value()); } } if (!user_name.empty()) { @@ -59,8 +60,7 @@ class AccountCreationTabContents : public TabContents, } } - virtual void FormsSeen( - const std::vector<webkit_glue::FormFieldValues>& forms) { + virtual void FormsSeen(const std::vector<FormData>& forms) { } virtual bool GetAutoFillSuggestions( diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 9f70534..35bfec5 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -43,8 +43,8 @@ #include "net/base/net_util.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/WebKit/WebKit/chromium/public/WebFindOptions.h" +#include "webkit/glue/form_data.h" #include "webkit/glue/form_field.h" -#include "webkit/glue/form_field_values.h" #if defined(OS_WIN) // TODO(port): accessibility not yet implemented. See http://crbug.com/8288. @@ -52,7 +52,10 @@ #endif using base::TimeDelta; +using webkit_glue::FormData; +using webkit_glue::PasswordForm; using webkit_glue::PasswordFormDomManager; +using webkit_glue::WebApplicationInfo; using WebKit::WebConsoleMessage; using WebKit::WebDragOperation; using WebKit::WebDragOperationNone; @@ -767,8 +770,7 @@ void RenderViewHost::OnMessageReceived(const IPC::Message& msg) { OnMsgShowModalHTMLDialog) IPC_MESSAGE_HANDLER(ViewHostMsg_FormsSeen, OnMsgFormsSeen) IPC_MESSAGE_HANDLER(ViewHostMsg_PasswordFormsSeen, OnMsgPasswordFormsSeen) - IPC_MESSAGE_HANDLER(ViewHostMsg_FormFieldValuesSubmitted, - OnMsgFormFieldValuesSubmitted) + IPC_MESSAGE_HANDLER(ViewHostMsg_FormSubmitted, OnMsgFormSubmitted) IPC_MESSAGE_HANDLER(ViewHostMsg_StartDragging, OnMsgStartDragging) IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateDragCursor, OnUpdateDragCursor) IPC_MESSAGE_HANDLER(ViewHostMsg_TakeFocus, OnTakeFocus) @@ -1353,8 +1355,7 @@ void RenderViewHost::MediaPlayerActionAt(const gfx::Point& location, Send(new ViewMsg_MediaPlayerActionAt(routing_id(), location, action)); } -void RenderViewHost::OnMsgFormsSeen( - const std::vector<webkit_glue::FormFieldValues>& forms) { +void RenderViewHost::OnMsgFormsSeen(const std::vector<FormData>& forms) { RenderViewHostDelegate::AutoFill* autofill_delegate = delegate_->GetAutoFillDelegate(); if (autofill_delegate) @@ -1362,21 +1363,20 @@ void RenderViewHost::OnMsgFormsSeen( } void RenderViewHost::OnMsgPasswordFormsSeen( - const std::vector<webkit_glue::PasswordForm>& forms) { + const std::vector<PasswordForm>& forms) { delegate_->PasswordFormsSeen(forms); } -void RenderViewHost::OnMsgFormFieldValuesSubmitted( - const webkit_glue::FormFieldValues& form) { +void RenderViewHost::OnMsgFormSubmitted(const FormData& form) { RenderViewHostDelegate::Autocomplete* autocomplete_delegate = delegate_->GetAutocompleteDelegate(); if (autocomplete_delegate) - autocomplete_delegate->FormFieldValuesSubmitted(form); + autocomplete_delegate->FormSubmitted(form); RenderViewHostDelegate::AutoFill* autofill_delegate = delegate_->GetAutoFillDelegate(); if (autofill_delegate) - autofill_delegate->FormFieldValuesSubmitted(form); + autofill_delegate->FormSubmitted(form); } void RenderViewHost::OnMsgStartDragging( @@ -1516,8 +1516,7 @@ void RenderViewHost::OnReceivedSavableResourceLinksForCurrentPage( } void RenderViewHost::OnDidGetApplicationInfo( - int32 page_id, - const webkit_glue::WebApplicationInfo& info) { + int32 page_id, const WebApplicationInfo& info) { RenderViewHostDelegate::BrowserIntegration* integration_delegate = delegate_->GetBrowserIntegrationDelegate(); if (integration_delegate) @@ -1590,7 +1589,7 @@ void RenderViewHost::OnRemoveAutofillEntry(const string16& field_name, } void RenderViewHost::OnFillAutoFillFormData(int query_id, - const webkit_glue::FormData& form, + const FormData& form, const string16& name, const string16& label) { RenderViewHostDelegate::AutoFill* autofill_delegate = @@ -1619,7 +1618,7 @@ void RenderViewHost::AutocompleteSuggestionsReturned( } void RenderViewHost::AutoFillFormDataFilled(int query_id, - const webkit_glue::FormData& form) { + const FormData& form) { Send(new ViewMsg_AutoFillFormDataFilled(routing_id(), query_id, form)); } diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h index 045acee..3f8586d 100644 --- a/chrome/browser/renderer_host/render_view_host.h +++ b/chrome/browser/renderer_host/render_view_host.h @@ -19,7 +19,6 @@ #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" #include "third_party/WebKit/WebKit/chromium/public/WebTextDirection.h" -#include "webkit/glue/form_field_values.h" #include "webkit/glue/password_form_dom_manager.h" #include "webkit/glue/window_open_disposition.h" @@ -42,17 +41,17 @@ struct UserMetricsAction; namespace gfx { class Point; -} +} // namespace gfx namespace webkit_glue { +struct FormData; class FormField; -class FormFieldValues; struct WebApplicationInfo; -} +} // namespace webkit_glue namespace WebKit { struct WebMediaPlayerAction; -} +} // namespace WebKit class URLRequestContextGetter; @@ -542,10 +541,10 @@ class RenderViewHost : public RenderWidgetHost { const std::string& json_arguments, IPC::Message* reply_msg); void OnMsgFormsSeen( - const std::vector<webkit_glue::FormFieldValues>& forms); + const std::vector<webkit_glue::FormData>& forms); void OnMsgPasswordFormsSeen( const std::vector<webkit_glue::PasswordForm>& forms); - void OnMsgFormFieldValuesSubmitted(const webkit_glue::FormFieldValues& forms); + void OnMsgFormSubmitted(const webkit_glue::FormData& forms); void OnMsgStartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask operations_allowed, const SkBitmap& image, diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h index 332fd24..f522a6dc 100644 --- a/chrome/browser/renderer_host/render_view_host_delegate.h +++ b/chrome/browser/renderer_host/render_view_host_delegate.h @@ -61,7 +61,6 @@ class Message; namespace webkit_glue { struct FormData; class FormField; -class FormFieldValues; struct PasswordForm; struct WebApplicationInfo; } @@ -374,8 +373,7 @@ class RenderViewHostDelegate { class Autocomplete { public: // Forms fillable by Autocomplete have been detected in the page. - virtual void FormFieldValuesSubmitted( - const webkit_glue::FormFieldValues& form) = 0; + virtual void FormSubmitted(const webkit_glue::FormData& form) = 0; // Called to retrieve a list of suggestions from the web database given // the name of the field |field_name| and what the user has already typed @@ -401,13 +399,11 @@ class RenderViewHostDelegate { class AutoFill { public: // Called when the user submits a form. - virtual void FormFieldValuesSubmitted( - const webkit_glue::FormFieldValues& form) = 0; + virtual void FormSubmitted(const webkit_glue::FormData& form) = 0; // Called when the frame has finished loading and there are forms in the // frame. - virtual void FormsSeen( - const std::vector<webkit_glue::FormFieldValues>& forms) = 0; + virtual void FormsSeen(const std::vector<webkit_glue::FormData>& forms) = 0; // Called to retrieve a list of AutoFill suggestions from the web database // given the name of the field and what the user has already typed in the diff --git a/chrome/browser/renderer_host/render_widget_host_view_win.cc b/chrome/browser/renderer_host/render_widget_host_view_win.cc index 37c338a..d70b674 100644 --- a/chrome/browser/renderer_host/render_widget_host_view_win.cc +++ b/chrome/browser/renderer_host/render_widget_host_view_win.cc @@ -1459,7 +1459,7 @@ LRESULT RenderWidgetHostViewWin::OnMouseActivate(UINT, WPARAM, LPARAM, LRESULT RenderWidgetHostViewWin::OnGetObject(UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { LRESULT reference_result = static_cast<LRESULT>(0L); - // TODO(ctguil): http://crbug.com/25564 Disabling accessibility in the + // TODO(jcampan): http://b/issue?id=1432077 Disabling accessibility in the // renderer is a temporary work-around until that bug is fixed. if (!renderer_accessible_) return reference_result; diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 533d6fe..a2db04f 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -41,7 +41,6 @@ #include "webkit/glue/context_menu.h" #include "webkit/glue/form_data.h" #include "webkit/glue/form_field.h" -#include "webkit/glue/form_field_values.h" #include "webkit/glue/password_form.h" #include "webkit/glue/password_form_dom_manager.h" #include "webkit/glue/plugins/webplugin.h" @@ -994,46 +993,6 @@ struct ParamTraits<webkit_glue::FormField> { } }; -// Traits for FormFieldValues_Params structure to pack/unpack. -template <> -struct ParamTraits<webkit_glue::FormFieldValues> { - typedef webkit_glue::FormFieldValues param_type; - static void Write(Message* m, const param_type& p) { - WriteParam(m, p.form_name); - WriteParam(m, p.method); - WriteParam(m, p.source_url); - WriteParam(m, p.target_url); - WriteParam(m, p.elements.size()); - std::vector<webkit_glue::FormField>::const_iterator itr; - for (itr = p.elements.begin(); itr != p.elements.end(); itr++) - WriteParam(m, *itr); - } - static bool Read(const Message* m, void** iter, param_type* p) { - bool result = true; - result = result && - ReadParam(m, iter, &p->form_name) && - ReadParam(m, iter, &p->method) && - ReadParam(m, iter, &p->source_url) && - ReadParam(m, iter, &p->target_url); - size_t elements_size = 0; - result = result && ReadParam(m, iter, &elements_size); - if (!result) - return false; - - for (size_t i = 0; i < elements_size; i++) { - webkit_glue::FormField field; - if (!ReadParam(m, iter, &field)) - return false; - - p->elements.push_back(field); - } - return true; - } - static void Log(const param_type& p, std::wstring* l) { - l->append(L"<FormFieldValues>"); - } -}; - // Traits for ViewHostMsg_FrameNavigate_Params structure to pack/unpack. template <> struct ParamTraits<ViewHostMsg_FrameNavigate_Params> { diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index d7ea058..6a5f1ac 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -1435,7 +1435,7 @@ IPC_BEGIN_MESSAGES(ViewHost) // Notification that forms have been seen that are candidates for // filling/submitting by the AutoFillManager. IPC_MESSAGE_ROUTED1(ViewHostMsg_FormsSeen, - std::vector<webkit_glue::FormFieldValues> /* forms */) + std::vector<webkit_glue::FormData> /* forms */) // Notification that password forms have been seen that are candidates for // filling/submitting by the password manager. @@ -1443,8 +1443,8 @@ IPC_BEGIN_MESSAGES(ViewHost) std::vector<webkit_glue::PasswordForm> /* forms */) // Notification that a form has been submitted. The user hit the button. - IPC_MESSAGE_ROUTED1(ViewHostMsg_FormFieldValuesSubmitted, - webkit_glue::FormFieldValues /* form */) + IPC_MESSAGE_ROUTED1(ViewHostMsg_FormSubmitted, + webkit_glue::FormData /* form */) // Used to tell the parent the user started dragging in the content area. The // WebDropData struct contains contextual information about the pieces of the diff --git a/chrome/renderer/form_autocomplete_unittest.cc b/chrome/renderer/form_autocomplete_unittest.cc index 7371dc2..d0a591e 100644 --- a/chrome/renderer/form_autocomplete_unittest.cc +++ b/chrome/renderer/form_autocomplete_unittest.cc @@ -8,17 +8,18 @@ #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/WebKit/chromium/public/WebString.h" #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" +#include "webkit/glue/form_data.h" +using webkit_glue::FormData; using WebKit::WebCompositionCommand; using WebKit::WebFrame; using WebKit::WebString; using WebKit::WebTextDirection; using WebKit::WebURLError; -class FormAutocompleteTest : public RenderViewTest { -}; +typedef RenderViewTest FormAutocompleteTest; -// Tests that submitting a form generates a FormFieldValuesSubmitted message +// Tests that submitting a form generates a FormSubmitted message // with the form fields. TEST_F(FormAutocompleteTest, NormalFormSubmit) { // Load a form. @@ -30,24 +31,24 @@ TEST_F(FormAutocompleteTest, NormalFormSubmit) { ProcessPendingMessages(); const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( - ViewHostMsg_FormFieldValuesSubmitted::ID); + ViewHostMsg_FormSubmitted::ID); ASSERT_TRUE(message != NULL); - Tuple1<webkit_glue::FormFieldValues> form_fields; - ViewHostMsg_FormFieldValuesSubmitted::Read(message, &form_fields); - ASSERT_EQ(2U, form_fields.a.elements.size()); + Tuple1<FormData> forms; + ViewHostMsg_FormSubmitted::Read(message, &forms); + ASSERT_EQ(2U, forms.a.fields.size()); - webkit_glue::FormField& form_field = form_fields.a.elements[0]; + webkit_glue::FormField& form_field = forms.a.fields[0]; EXPECT_EQ(WebString("fname"), form_field.name()); EXPECT_EQ(WebString("Rick"), form_field.value()); - form_field = form_fields.a.elements[1]; + form_field = forms.a.fields[1]; EXPECT_EQ(WebString("lname"), form_field.name()); EXPECT_EQ(WebString("Deckard"), form_field.value()); } // Tests that submitting a form that has autocomplete="off" does not generate a -// FormFieldValuesSubmitted message. +// FormSubmitted message. TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { // Load a form. LoadHTML("<html><form id='myForm' autocomplete='off'>" @@ -59,9 +60,9 @@ TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { ExecuteJavaScript("document.getElementById('myForm').submit();"); ProcessPendingMessages(); - // No FormFieldValuesSubmitted message should have been sent. + // No FormSubmitted message should have been sent. EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching( - ViewHostMsg_FormFieldValuesSubmitted::ID)); + ViewHostMsg_FormSubmitted::ID)); } // Tests that fields with autocomplete off are not submitted. @@ -76,22 +77,22 @@ TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) { ExecuteJavaScript("document.getElementById('myForm').submit();"); ProcessPendingMessages(); - // No FormFieldValuesSubmitted message should have been sent. + // No FormSubmitted message should have been sent. const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( - ViewHostMsg_FormFieldValuesSubmitted::ID); + ViewHostMsg_FormSubmitted::ID); ASSERT_TRUE(message != NULL); - Tuple1<webkit_glue::FormFieldValues> form_fields; - ViewHostMsg_FormFieldValuesSubmitted::Read(message, &form_fields); - ASSERT_EQ(1U, form_fields.a.elements.size()); + Tuple1<FormData> forms; + ViewHostMsg_FormSubmitted::Read(message, &forms); + ASSERT_EQ(1U, forms.a.fields.size()); - webkit_glue::FormField& form_field = form_fields.a.elements[0]; + webkit_glue::FormField& form_field = forms.a.fields[0]; EXPECT_EQ(WebString("fname"), form_field.name()); EXPECT_EQ(WebString("Rick"), form_field.value()); } // Tests that submitting a form that has been dynamically set as autocomplete -// off does not generate a FormFieldValuesSubmitted message. +// off does not generate a FormSubmitted message. // http://crbug.com/36520 // TODO(jcampan): reenable when WebKit bug 35823 is fixed. TEST_F(FormAutocompleteTest, DISABLED_DynamicAutoCompleteOffFormSubmit) { @@ -113,8 +114,7 @@ TEST_F(FormAutocompleteTest, DISABLED_DynamicAutoCompleteOffFormSubmit) { ExecuteJavaScript("document.getElementById('myForm').submit();"); ProcessPendingMessages(); - // No FormFieldValuesSubmitted message should have been sent. + // No FormSubmitted message should have been sent. EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching( - ViewHostMsg_FormFieldValuesSubmitted::ID)); + ViewHostMsg_FormSubmitted::ID)); } - diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc index 0b88791..7c3fa73 100644 --- a/chrome/renderer/form_manager.cc +++ b/chrome/renderer/form_manager.cc @@ -36,6 +36,16 @@ using WebKit::WebSelectElement; using WebKit::WebString; using WebKit::WebVector; +namespace { + +// The number of fields required by AutoFill. Ideally we could send the forms +// to AutoFill no matter how many fields are in the forms; however, finding the +// label for each field is a costly operation and we can't spare the cycles if +// it's not necessary. +const size_t kRequiredAutoFillFields = 3; + +} // namespace + FormManager::FormManager() { } @@ -118,23 +128,87 @@ void FormManager::GetForms(RequirementsMask requirements, } } -bool FormManager::FindForm(const WebFormControlElement& element, +void FormManager::GetFormsInFrame(const WebFrame* frame, + RequirementsMask requirements, + std::vector<FormData>* forms) { + DCHECK(frame); + DCHECK(forms); + + WebFrameFormElementMap::iterator iter = form_elements_map_.find(frame); + if (iter == form_elements_map_.end()) + return; + + // TODO(jhawkins): Factor this out and use it here and in GetForms. + const std::vector<FormElement*>& form_elements = iter->second; + for (std::vector<FormElement*>::const_iterator form_iter = + form_elements.begin(); + form_iter != form_elements.end(); ++form_iter) { + FormElement* form_element = *form_iter; + + // We need at least |kRequiredAutoFillFields| fields before appending this + // form to |forms|. + if (form_element->control_elements.size() < kRequiredAutoFillFields) + continue; + + if (requirements & REQUIRE_AUTOCOMPLETE && + !form_element->form_element.autoComplete()) + continue; + + FormData form; + FormElementToFormData(frame, form_element, requirements, &form); + if (form.fields.size() >= kRequiredAutoFillFields) + forms->push_back(form); + } +} + +bool FormManager::FindForm(const WebFormElement& element, + RequirementsMask requirements, FormData* form) { DCHECK(form); - for (WebFrameFormElementMap::iterator iter = form_elements_map_.begin(); - iter != form_elements_map_.end(); ++iter) { - const WebFrame* frame = iter->first; + const WebFrame* frame = element.frame(); + if (!frame) + return false; - for (std::vector<FormElement*>::iterator form_iter = iter->second.begin(); - form_iter != iter->second.end(); ++form_iter) { - FormElement* form_element = *form_iter; + WebFrameFormElementMap::const_iterator frame_iter = + form_elements_map_.find(frame); + if (frame_iter == form_elements_map_.end()) + return false; - if (form_element->control_elements.find(element.nameForAutofill()) != - form_element->control_elements.end()) { - FormElementToFormData(frame, form_element, REQUIRE_NONE, form); - return true; - } + for (std::vector<FormElement*>::const_iterator iter = + frame_iter->second.begin(); + iter != frame_iter->second.end(); ++iter) { + if ((*iter)->form_element.name() != element.name()) + continue; + + return FormElementToFormData(frame, *iter, requirements, form); + } + + return false; +} + +bool FormManager::FindFormWithFormControlElement( + const WebFormControlElement& element, + RequirementsMask requirements, + FormData* form) { + DCHECK(form); + + const WebFrame* frame = element.frame(); + if (!frame) + return false; + + if (form_elements_map_.find(frame) == form_elements_map_.end()) + return false; + + const std::vector<FormElement*> forms = form_elements_map_[frame]; + for (std::vector<FormElement*>::const_iterator iter = forms.begin(); + iter != forms.end(); ++iter) { + const FormElement* form_element = *iter; + + if (form_element->control_elements.find(element.nameForAutofill()) != + form_element->control_elements.end()) { + FormElementToFormData(frame, form_element, requirements, form); + return true; } } @@ -203,10 +277,14 @@ void FormManager::Reset() { } // static -void FormManager::FormElementToFormData(const WebFrame* frame, +bool FormManager::FormElementToFormData(const WebFrame* frame, const FormElement* form_element, RequirementsMask requirements, FormData* form) { + if (requirements & REQUIRE_AUTOCOMPLETE && + !form_element->form_element.autoComplete()) + return false; + form->name = form_element->form_element.name(); form->method = form_element->form_element.method(); form->origin = frame->url(); @@ -238,6 +316,8 @@ void FormManager::FormElementToFormData(const WebFrame* frame, WebFormControlElementToFormField(control_element, &field); form->fields.push_back(field); } + + return true; } void FormManager::ResetFrame(const WebFrame* frame) { diff --git a/chrome/renderer/form_manager.h b/chrome/renderer/form_manager.h index d96e718..28b2d8d 100644 --- a/chrome/renderer/form_manager.h +++ b/chrome/renderer/form_manager.h @@ -46,10 +46,23 @@ class FormManager { void GetForms(RequirementsMask requirements, std::vector<webkit_glue::FormData>* forms); + // Returns a vector of forms in |frame| that match |requirements|. + void GetFormsInFrame(const WebKit::WebFrame* frame, + RequirementsMask requirements, + std::vector<webkit_glue::FormData>* forms); + + // Returns the cached FormData for |element|. Returns true if the form was + // found in the cache. + bool FindForm(const WebKit::WebFormElement& element, + RequirementsMask requirements, + webkit_glue::FormData* form); + // Finds the form that contains |element| and returns it in |form|. Returns // false if the form is not found. - bool FindForm(const WebKit::WebFormControlElement& element, - webkit_glue::FormData* form); + bool FindFormWithFormControlElement( + const WebKit::WebFormControlElement& element, + RequirementsMask requirements, + webkit_glue::FormData* form); // Fills the form represented by |form|. |form| should have the name set to // the name of the form to fill out, and the number of elements and values @@ -78,9 +91,10 @@ class FormManager { typedef std::map<const WebKit::WebFrame*, std::vector<FormElement*> > WebFrameFormElementMap; - // Converts a FormElement to FormData storage. + // Converts a FormElement to FormData storage. Returns false if the form does + // not meet all the requirements in the requirements mask. // TODO(jhawkins): Modify FormElement so we don't need |frame|. - static void FormElementToFormData(const WebKit::WebFrame* frame, + static bool FormElementToFormData(const WebKit::WebFrame* frame, const FormElement* form_element, RequirementsMask requirements, webkit_glue::FormData* form); diff --git a/chrome/renderer/form_manager_unittest.cc b/chrome/renderer/form_manager_unittest.cc index 213077e..256f58f 100644 --- a/chrome/renderer/form_manager_unittest.cc +++ b/chrome/renderer/form_manager_unittest.cc @@ -246,7 +246,8 @@ TEST_F(FormManagerTest, FindForm) { // Find the form and verify it's the correct form. FormData form; - EXPECT_TRUE(form_manager.FindForm(input_element, &form)); + EXPECT_TRUE(form_manager.FindFormWithFormControlElement( + input_element, FormManager::REQUIRE_NONE, &form)); EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); EXPECT_EQ(GURL(web_frame->url()), form.origin); EXPECT_EQ(GURL("http://buh.com"), form.action); @@ -295,7 +296,8 @@ TEST_F(FormManagerTest, FillForm) { // Find the form that contains the input element. FormData form; - EXPECT_TRUE(form_manager.FindForm(input_element, &form)); + EXPECT_TRUE(form_manager.FindFormWithFormControlElement( + input_element, FormManager::REQUIRE_NONE, &form)); EXPECT_EQ(ASCIIToUTF16("TestForm"), form.name); EXPECT_EQ(GURL(web_frame->url()), form.origin); EXPECT_EQ(GURL("http://buh.com"), form.action); @@ -325,7 +327,8 @@ TEST_F(FormManagerTest, FillForm) { // Find the newly-filled form that contains the input element. FormData form2; - EXPECT_TRUE(form_manager.FindForm(input_element, &form2)); + EXPECT_TRUE(form_manager.FindFormWithFormControlElement( + input_element, FormManager::REQUIRE_NONE, &form2)); EXPECT_EQ(ASCIIToUTF16("TestForm"), form2.name); EXPECT_EQ(GURL(web_frame->url()), form2.origin); EXPECT_EQ(GURL("http://buh.com"), form2.action); diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 64403b0..59a862a 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -78,6 +78,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebDocument.h" #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" #include "third_party/WebKit/WebKit/chromium/public/WebFileChooserParams.h" +#include "third_party/WebKit/WebKit/chromium/public/WebFormControlElement.h" #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" #include "third_party/WebKit/WebKit/chromium/public/WebHistoryItem.h" @@ -105,8 +106,8 @@ #include "webkit/appcache/web_application_cache_host_impl.h" #include "webkit/default_plugin/default_plugin_shared.h" #include "webkit/glue/dom_operations.h" +#include "webkit/glue/form_data.h" #include "webkit/glue/form_field.h" -#include "webkit/glue/form_field_values.h" #include "webkit/glue/glue_serialize.h" #include "webkit/glue/image_decoder.h" #include "webkit/glue/media/buffered_data_source.h" @@ -133,8 +134,8 @@ using appcache::WebApplicationCacheHostImpl; using base::Time; using base::TimeDelta; using webkit_glue::AltErrorPageResourceFetcher; +using webkit_glue::FormData; using webkit_glue::FormField; -using webkit_glue::FormFieldValues; using webkit_glue::ImageResourceFetcher; using webkit_glue::PasswordForm; using webkit_glue::PasswordFormDomManager; @@ -156,6 +157,7 @@ using WebKit::WebDragOperationsMask; using WebKit::WebEditingAction; using WebKit::WebFileChooserCompletion; using WebKit::WebFindOptions; +using WebKit::WebFormControlElement; using WebKit::WebFormElement; using WebKit::WebFrame; using WebKit::WebHistoryItem; @@ -1969,7 +1971,8 @@ void RenderView::didAcceptAutoFillSuggestion( webkit_glue::FormData form; const WebInputElement element = node.toConstElement<WebInputElement>(); - if (!form_manager_.FindForm(element, &form)) + if (!form_manager_.FindFormWithFormControlElement( + element, FormManager::REQUIRE_AUTOCOMPLETE, &form)) return; Send(new ViewHostMsg_FillAutoFillFormData( @@ -2303,6 +2306,7 @@ void RenderView::unableToImplementPolicyWithError( } void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) { + printf("willSubmitForm\n"); NavigationState* navigation_state = NavigationState::FromDataSource(frame->provisionalDataSource()); @@ -2317,12 +2321,10 @@ void RenderView::willSubmitForm(WebFrame* frame, const WebFormElement& form) { navigation_state->set_password_form_data( PasswordFormDomManager::CreatePasswordForm(form)); - if (form.autoComplete()) { - scoped_ptr<FormFieldValues> form_values(FormFieldValues::Create(form)); - if (form_values.get()) - Send(new ViewHostMsg_FormFieldValuesSubmitted(routing_id_, - *form_values)); - } + FormData form_data; + if (form_manager_.FindForm( + form, FormManager::REQUIRE_AUTOCOMPLETE, &form_data)) + Send(new ViewHostMsg_FormSubmitted(routing_id_, form_data)); } void RenderView::willPerformClientRedirect( @@ -4646,19 +4648,12 @@ void RenderView::focusAccessibilityObject( } void RenderView::SendForms(WebFrame* frame) { - WebVector<WebFormElement> web_forms; - frame->forms(web_forms); - - std::vector<FormFieldValues> forms; - for (size_t i = 0; i < web_forms.size(); ++i) { - const WebFormElement& web_form = web_forms[i]; - - if (web_form.autoComplete()) { - scoped_ptr<FormFieldValues> form(FormFieldValues::Create(web_form)); - if (form.get()) - forms.push_back(*form); - } - } + std::vector<FormData> forms; + FormManager::RequirementsMask requirements = + static_cast<FormManager::RequirementsMask>( + FormManager::REQUIRE_AUTOCOMPLETE | + FormManager::REQUIRE_ELEMENTS_ENABLED); + form_manager_.GetFormsInFrame(frame, requirements, &forms); if (!forms.empty()) Send(new ViewHostMsg_FormsSeen(routing_id_, forms)); @@ -4950,4 +4945,3 @@ bool RenderView::ShouldRouteNavigationToBrowser( } return false; } - |