summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-15 23:51:24 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-15 23:51:24 +0000
commit45c6e53a2c50e19a3f79fcc6f05914793ed93de6 (patch)
treee4f0c22f63fe5197938dc868f00c7d6a8e2ea8a6
parentcffa2055808bf2149ce48118dcacde477b7ead60 (diff)
downloadchromium_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
-rw-r--r--chrome/browser/autofill/autofill_manager.cc12
-rw-r--r--chrome/browser/autofill/autofill_manager.h3
-rw-r--r--chrome/browser/autofill/form_structure.cc5
-rw-r--r--chrome/browser/autofill/form_structure.h7
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc4
-rw-r--r--chrome/browser/renderer_host/render_view_host.h4
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h4
-rw-r--r--chrome/common/render_messages.h12
-rw-r--r--chrome/common/render_messages_internal.h6
-rw-r--r--chrome/renderer/form_manager.cc30
-rw-r--r--chrome/renderer/form_manager.h10
-rw-r--r--chrome/renderer/form_manager_unittest.cc284
-rw-r--r--chrome/renderer/render_view.cc8
-rw-r--r--chrome/renderer/render_view.h3
-rw-r--r--webkit/glue/dom_operations.cc14
-rw-r--r--webkit/glue/form_data.h15
-rw-r--r--webkit/glue/form_field.cc30
-rw-r--r--webkit/glue/form_field.h8
-rw-r--r--webkit/glue/password_form_dom_manager.cc19
-rw-r--r--webkit/glue/webpasswordautocompletelistener_impl.cc14
-rw-r--r--webkit/glue/webpasswordautocompletelistener_unittest.cc18
21 files changed, 280 insertions, 230 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index d49dd4c..ee44c75 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -154,7 +154,7 @@ bool AutoFillManager::GetAutoFillSuggestions(
}
bool AutoFillManager::FillAutoFillFormData(int query_id,
- const FormData& form,
+ const webkit_glue::FormData& form,
const string16& name,
const string16& label) {
if (!IsAutoFillEnabled())
@@ -185,7 +185,7 @@ bool AutoFillManager::FillAutoFillFormData(int query_id,
if (!profile)
return false;
- FormData result = form;
+ webkit_glue::FormData result = form;
for (std::vector<FormStructure*>::const_iterator iter =
form_structures_.begin();
iter != form_structures_.end(); ++iter) {
@@ -196,10 +196,10 @@ bool AutoFillManager::FillAutoFillFormData(int query_id,
for (size_t i = 0; i < form_structure->field_count(); ++i) {
const AutoFillField* field = form_structure->field(i);
- for (size_t j = 0; j < result.values.size(); ++j) {
- if (field->name() == result.elements[j]) {
- result.values[j] =
- profile->GetFieldText(AutoFillType(field->heuristic_type()));
+ for (size_t j = 0; j < result.fields.size(); ++j) {
+ if (field->name() == result.fields[j].name()) {
+ result.fields[j].set_value(
+ profile->GetFieldText(AutoFillType(field->heuristic_type())));
break;
}
}
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index ecc72d9..fa4593e 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -14,6 +14,7 @@
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
namespace webkit_glue {
+struct FormData;
class FormField;
class FormFieldValues;
}
@@ -48,7 +49,7 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
virtual bool GetAutoFillSuggestions(int query_id,
const webkit_glue::FormField& field);
virtual bool FillAutoFillFormData(int query_id,
- const FormData& form,
+ const webkit_glue::FormData& form,
const string16& name,
const string16& label);
diff --git a/chrome/browser/autofill/form_structure.cc b/chrome/browser/autofill/form_structure.cc
index a93910c..4841da8 100644
--- a/chrome/browser/autofill/form_structure.cc
+++ b/chrome/browser/autofill/form_structure.cc
@@ -16,6 +16,9 @@
#include "webkit/glue/form_field.h"
#include "webkit/glue/form_field_values.h"
+using webkit_glue::FormData;
+using webkit_glue::FormFieldValues;
+
namespace {
const char* kFormMethodPost = "post";
@@ -55,7 +58,7 @@ static std::string Hash64Bit(const std::string& str) {
} // namespace
-FormStructure::FormStructure(const webkit_glue::FormFieldValues& values)
+FormStructure::FormStructure(const FormFieldValues& values)
: form_name_(UTF16ToUTF8(values.form_name)),
source_url_(values.source_url),
target_url_(values.target_url) {
diff --git a/chrome/browser/autofill/form_structure.h b/chrome/browser/autofill/form_structure.h
index d91882b..6c41203 100644
--- a/chrome/browser/autofill/form_structure.h
+++ b/chrome/browser/autofill/form_structure.h
@@ -14,9 +14,8 @@
#include "chrome/browser/autofill/field_types.h"
#include "googleurl/src/gurl.h"
-struct FormData;
-
namespace webkit_glue {
+struct FormData;
class FormFieldValues;
}
@@ -60,8 +59,8 @@ class FormStructure {
return fields_.end();
}
- bool operator==(const FormData& form) const;
- bool operator!=(const FormData& form) const;
+ bool operator==(const webkit_glue::FormData& form) const;
+ bool operator!=(const webkit_glue::FormData& form) const;
private:
// Associates the field with the heuristic type for each of the field views.
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index 6cfd4f8..354acaf 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -1608,7 +1608,7 @@ void RenderViewHost::OnRemoveAutofillEntry(const string16& field_name,
}
void RenderViewHost::OnFillAutoFillFormData(int query_id,
- const FormData& form,
+ const webkit_glue::FormData& form,
const string16& name,
const string16& label) {
RenderViewHostDelegate::AutoFill* autofill_delegate =
@@ -1637,7 +1637,7 @@ void RenderViewHost::AutocompleteSuggestionsReturned(
}
void RenderViewHost::AutoFillFormDataFilled(int query_id,
- const FormData& form) {
+ const webkit_glue::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 4059bec..27fb3ff 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -398,7 +398,7 @@ class RenderViewHost : public RenderWidgetHost {
int default_suggestion_index);
// Called by the AutoFillManager when the FormData has been filled out.
- void AutoFillFormDataFilled(int query_id, const FormData& form);
+ void AutoFillFormDataFilled(int query_id, const webkit_glue::FormData& form);
// Notifies the Renderer that a move or resize of its containing window has
// started (this is used to hide the autocomplete popups if any).
@@ -590,7 +590,7 @@ class RenderViewHost : public RenderWidgetHost {
void OnRemoveAutofillEntry(const string16& field_name,
const string16& value);
void OnFillAutoFillFormData(int query_id,
- const FormData& form,
+ const webkit_glue::FormData& form,
const string16& name,
const string16& label);
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index d908e1f..535bb1f 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -19,7 +19,6 @@
struct BookmarkDragData;
struct ContextMenuParams;
class FilePath;
-struct FormData;
class GURL;
struct NativeWebKeyboardEvent;
class NavigationEntry;
@@ -54,6 +53,7 @@ class Message;
}
namespace webkit_glue {
+struct FormData;
class FormField;
class FormFieldValues;
struct PasswordForm;
@@ -411,7 +411,7 @@ class RenderViewHostDelegate {
// matches the |name|, |label| key. Returns true to indicate that
// RenderViewHost::AutoFillFormDataFilled has been called.
virtual bool FillAutoFillFormData(int query_id,
- const FormData& form,
+ const webkit_glue::FormData& form,
const string16& name,
const string16& label) = 0;
};
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index d032520..eae961a 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -1555,24 +1555,20 @@ struct ParamTraits<SyncLoadResult> {
// Traits for FormData structure to pack/unpack.
template <>
-struct ParamTraits<FormData> {
- typedef FormData param_type;
+struct ParamTraits<webkit_glue::FormData> {
+ typedef webkit_glue::FormData param_type;
static void Write(Message* m, const param_type& p) {
WriteParam(m, p.name);
WriteParam(m, p.origin);
WriteParam(m, p.action);
- WriteParam(m, p.labels);
- WriteParam(m, p.elements);
- WriteParam(m, p.values);
+ WriteParam(m, p.fields);
}
static bool Read(const Message* m, void** iter, param_type* p) {
return
ReadParam(m, iter, &p->name) &&
ReadParam(m, iter, &p->origin) &&
ReadParam(m, iter, &p->action) &&
- ReadParam(m, iter, &p->labels) &&
- ReadParam(m, iter, &p->elements) &&
- ReadParam(m, iter, &p->values);
+ ReadParam(m, iter, &p->fields);
}
static void Log(const param_type& p, std::wstring* l) {
l->append(L"<FormData>");
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index fbbd9d5..8fd3b9d 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -395,7 +395,7 @@ IPC_BEGIN_MESSAGES(View)
// Fill a form with data and optionally submit it
IPC_MESSAGE_ROUTED1(ViewMsg_FormFill,
- FormData /* form */)
+ webkit_glue::FormData /* form */)
// Fill a password form and prepare field autocomplete for multiple
// matching logins.
@@ -646,7 +646,7 @@ IPC_BEGIN_MESSAGES(View)
// AutoFill form data.
IPC_MESSAGE_ROUTED2(ViewMsg_AutoFillFormDataFilled,
int /* id of the request message */,
- FormData /* form data */)
+ webkit_glue::FormData /* form data */)
// Sent by the Browser process to alert a window about whether a blocked
// popup notification is visible. The renderer assumes every new window is a
@@ -1807,7 +1807,7 @@ IPC_BEGIN_MESSAGES(ViewHost)
// profile data.
IPC_MESSAGE_ROUTED4(ViewHostMsg_FillAutoFillFormData,
int /* id of this message */,
- FormData /* the form */,
+ webkit_glue::FormData /* the form */,
string16 /* profile name */,
string16 /* profile label */)
diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc
index 5067fe3..246c448 100644
--- a/chrome/renderer/form_manager.cc
+++ b/chrome/renderer/form_manager.cc
@@ -26,6 +26,8 @@ using WebKit::WebNode;
using WebKit::WebNodeList;
using WebKit::WebString;
using WebKit::WebVector;
+using webkit_glue::FormData;
+using webkit_glue::FormField;
FormManager::FormManager() {
}
@@ -83,7 +85,8 @@ void FormManager::GetForms(std::vector<FormData>* forms,
}
}
-bool FormManager::FindForm(const WebInputElement& element, FormData* form) {
+bool FormManager::FindForm(const WebInputElement& element,
+ FormData* form) {
// Frame loop.
for (WebFrameFormElementMap::iterator iter = form_elements_map_.begin();
iter != form_elements_map_.end(); ++iter) {
@@ -122,7 +125,7 @@ bool FormManager::FillForm(const FormData& form) {
// evaluate to |true| for some reason TBD, so forcing to string16.
string16 element_name((*form_iter)->form_element.name());
if (element_name == form.name &&
- (*form_iter)->input_elements.size() == form.elements.size()) {
+ (*form_iter)->input_elements.size() == form.fields.size()) {
form_element = *form_iter;
break;
}
@@ -132,18 +135,17 @@ bool FormManager::FillForm(const FormData& form) {
if (!form_element)
return false;
- DCHECK(form_element->input_elements.size() == form.elements.size());
- DCHECK(form.elements.size() == form.values.size());
+ DCHECK(form_element->input_elements.size() == form.fields.size());
size_t i = 0;
for (FormInputElementMap::iterator iter =
form_element->input_elements.begin();
iter != form_element->input_elements.end(); ++iter, ++i) {
- DCHECK_EQ(form.elements[i], iter->second.nameForAutofill());
+ DCHECK_EQ(form.fields[i].name(), iter->second.nameForAutofill());
- if (!form.values[i].empty() &&
+ if (!form.fields[i].value().empty() &&
iter->second.inputType() != WebInputElement::Submit) {
- iter->second.setValue(form.values[i]);
+ iter->second.setValue(form.fields[i].value());
iter->second.setAutofilled(true);
}
}
@@ -194,9 +196,17 @@ void FormManager::FormElementToFormData(WebFrame* frame,
!input_element.isEnabledFormControl())
continue;
- form->labels.push_back(LabelForElement(input_element));
- form->elements.push_back(input_element.nameForAutofill());
- form->values.push_back(input_element.value());
+ string16 label = LabelForElement(input_element);
+ string16 name = input_element.nameForAutofill();
+ string16 value = input_element.value();
+ string16 form_control_type = input_element.formControlType();
+ WebInputElement::InputType input_type = input_element.inputType();
+ FormField field = FormField(label,
+ name,
+ value,
+ form_control_type,
+ input_type);
+ form->fields.push_back(field);
}
}
diff --git a/chrome/renderer/form_manager.h b/chrome/renderer/form_manager.h
index 9e7abf8..a6805b2 100644
--- a/chrome/renderer/form_manager.h
+++ b/chrome/renderer/form_manager.h
@@ -34,18 +34,20 @@ class FormManager {
void ExtractForms(WebKit::WebFrame* frame);
// Returns a vector of forms that match |requirements|.
- void GetForms(std::vector<FormData>* forms, RequirementsMask requirements);
+ void GetForms(std::vector<webkit_glue::FormData>* forms,
+ RequirementsMask requirements);
// Finds the form that contains |input_element| and returns it in |form|.
// Returns false if the form is not found.
- bool FindForm(const WebKit::WebInputElement& input_element, FormData* form);
+ bool FindForm(const WebKit::WebInputElement& input_element,
+ 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
// must match the number of stored elements in the form.
// TODO(jhawkins): Is matching on name alone good enough? It's possible to
// store multiple forms with the same names from different frames.
- bool FillForm(const FormData& form);
+ bool FillForm(const webkit_glue::FormData& form);
// Resets the stored set of forms.
void Reset();
@@ -73,7 +75,7 @@ class FormManager {
void FormElementToFormData(WebKit::WebFrame* frame,
const FormElement* form_element,
RequirementsMask requirements,
- FormData* form);
+ webkit_glue::FormData* form);
// Returns the corresponding label for |element|.
static string16 LabelForElement(const WebKit::WebInputElement& element);
diff --git a/chrome/renderer/form_manager_unittest.cc b/chrome/renderer/form_manager_unittest.cc
index d819096..418afd8 100644
--- a/chrome/renderer/form_manager_unittest.cc
+++ b/chrome/renderer/form_manager_unittest.cc
@@ -9,12 +9,16 @@
#include "third_party/WebKit/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
+#include "webkit/glue/form_data.h"
using WebKit::WebElement;
using WebKit::WebFrame;
using WebKit::WebInputElement;
using WebKit::WebString;
+using webkit_glue::FormData;
+using webkit_glue::FormField;
+
class FormManagerTest : public RenderViewTest {
public:
FormManagerTest() {}
@@ -42,23 +46,23 @@ TEST_F(FormManagerTest, ExtractForms) {
EXPECT_EQ(GURL(web_frame->url()), form.origin);
EXPECT_EQ(GURL("http://cnn.com"), form.action);
- const std::vector<string16>& labels = form.labels;
- ASSERT_EQ(3U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- EXPECT_EQ(string16(), labels[1]);
- EXPECT_EQ(string16(), labels[2]);
-
- const std::vector<string16>& elements = form.elements;
- ASSERT_EQ(3U, elements.size());
- EXPECT_EQ(ASCIIToUTF16("firstname"), elements[0]);
- EXPECT_EQ(ASCIIToUTF16("lastname"), elements[1]);
- EXPECT_EQ(ASCIIToUTF16("reply-send"), elements[2]);
-
- const std::vector<string16>& values = form.values;
- ASSERT_EQ(3U, values.size());
- EXPECT_EQ(ASCIIToUTF16("John"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Smith"), values[1]);
- EXPECT_EQ(ASCIIToUTF16("Send"), values[2]);
+ const std::vector<FormField>& fields = form.fields;
+ ASSERT_EQ(3U, fields.size());
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("John"),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields[0]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Smith"),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields[1]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ ASCIIToUTF16("Send"),
+ ASCIIToUTF16("submit"),
+ WebInputElement::Submit), fields[2]);
}
TEST_F(FormManagerTest, ExtractMultipleForms) {
@@ -87,20 +91,18 @@ TEST_F(FormManagerTest, ExtractMultipleForms) {
EXPECT_EQ(GURL(web_frame->url()), form.origin);
EXPECT_EQ(GURL("http://cnn.com"), form.action);
- const std::vector<string16>& labels = form.labels;
- ASSERT_EQ(2U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- EXPECT_EQ(string16(), labels[1]);
-
- const std::vector<string16>& elements = form.elements;
- ASSERT_EQ(2U, elements.size());
- EXPECT_EQ(ASCIIToUTF16("firstname"), elements[0]);
- EXPECT_EQ(ASCIIToUTF16("reply-send"), elements[1]);
-
- const std::vector<string16>& values = form.values;
- ASSERT_EQ(2U, values.size());
- EXPECT_EQ(ASCIIToUTF16("John"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Send"), values[1]);
+ const std::vector<FormField>& fields = form.fields;
+ ASSERT_EQ(2U, fields.size());
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("John"),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields[0]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ ASCIIToUTF16("Send"),
+ ASCIIToUTF16("submit"),
+ WebInputElement::Submit), fields[1]);
// Second form.
const FormData& form2 = forms[1];
@@ -108,20 +110,18 @@ TEST_F(FormManagerTest, ExtractMultipleForms) {
EXPECT_EQ(GURL(web_frame->url()), form2.origin);
EXPECT_EQ(GURL("http://zoo.com"), form2.action);
- const std::vector<string16>& labels2 = form2.labels;
- ASSERT_EQ(2U, labels2.size());
- EXPECT_EQ(string16(), labels2[0]);
- EXPECT_EQ(string16(), labels2[1]);
-
- const std::vector<string16>& elements2 = form2.elements;
- ASSERT_EQ(2U, elements2.size());
- EXPECT_EQ(ASCIIToUTF16("lastname"), elements2[0]);
- EXPECT_EQ(ASCIIToUTF16("second"), elements2[1]);
-
- const std::vector<string16>& values2 = form2.values;
- ASSERT_EQ(2U, values2.size());
- EXPECT_EQ(ASCIIToUTF16("Smith"), values2[0]);
- EXPECT_EQ(ASCIIToUTF16("Submit"), values2[1]);
+ const std::vector<FormField>& fields2 = form2.fields;
+ ASSERT_EQ(2U, fields2.size());
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Smith"),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields2[0]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("second"),
+ ASCIIToUTF16("Submit"),
+ ASCIIToUTF16("submit"),
+ WebInputElement::Submit), fields2[1]);
}
TEST_F(FormManagerTest, GetFormsAutocomplete) {
@@ -171,20 +171,18 @@ TEST_F(FormManagerTest, GetFormsAutocomplete) {
EXPECT_EQ(GURL(web_frame->url()), form.origin);
EXPECT_EQ(GURL("http://abc.com"), form.action);
- const std::vector<string16>& labels = form.labels;
- ASSERT_EQ(2U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- EXPECT_EQ(string16(), labels[1]);
-
- const std::vector<string16>& elements = form.elements;
- ASSERT_EQ(2U, elements.size());
- EXPECT_EQ(ASCIIToUTF16("lastname"), elements[0]);
- EXPECT_EQ(ASCIIToUTF16("reply"), elements[1]);
-
- const std::vector<string16>& values = form.values;
- ASSERT_EQ(2U, values.size());
- EXPECT_EQ(ASCIIToUTF16("Smith"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Send"), values[1]);
+ const std::vector<FormField>& fields = form.fields;
+ ASSERT_EQ(2U, fields.size());
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Smith"),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields[0]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("reply"),
+ ASCIIToUTF16("Send"),
+ ASCIIToUTF16("submit"),
+ WebInputElement::Submit), fields[1]);
}
TEST_F(FormManagerTest, GetFormsElementsEnabled) {
@@ -210,20 +208,18 @@ TEST_F(FormManagerTest, GetFormsElementsEnabled) {
EXPECT_EQ(GURL(web_frame->url()), form.origin);
EXPECT_EQ(GURL("http://xyz.com"), form.action);
- const std::vector<string16>& labels = form.labels;
- ASSERT_EQ(2U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- EXPECT_EQ(string16(), labels[1]);
-
- const std::vector<string16>& elements = form.elements;
- ASSERT_EQ(2U, elements.size());
- EXPECT_EQ(ASCIIToUTF16("lastname"), elements[0]);
- EXPECT_EQ(ASCIIToUTF16("submit"), elements[1]);
-
- const std::vector<string16>& values = form.values;
- ASSERT_EQ(2U, values.size());
- EXPECT_EQ(ASCIIToUTF16("Smith"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Send"), values[1]);
+ const std::vector<FormField>& fields = form.fields;
+ ASSERT_EQ(2U, fields.size());
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Smith"),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields[0]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("submit"),
+ ASCIIToUTF16("Send"),
+ ASCIIToUTF16("submit"),
+ WebInputElement::Submit), fields[1]);
}
TEST_F(FormManagerTest, FindForm) {
@@ -256,23 +252,23 @@ TEST_F(FormManagerTest, FindForm) {
EXPECT_EQ(GURL(web_frame->url()), form.origin);
EXPECT_EQ(GURL("http://buh.com"), form.action);
- const std::vector<string16>& labels = form.labels;
- ASSERT_EQ(3U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- EXPECT_EQ(string16(), labels[1]);
- EXPECT_EQ(string16(), labels[2]);
-
- const std::vector<string16>& elements = form.elements;
- ASSERT_EQ(3U, elements.size());
- EXPECT_EQ(ASCIIToUTF16("firstname"), elements[0]);
- EXPECT_EQ(ASCIIToUTF16("lastname"), elements[1]);
- EXPECT_EQ(ASCIIToUTF16("reply-send"), elements[2]);
-
- const std::vector<string16>& values = form.values;
- ASSERT_EQ(3U, values.size());
- EXPECT_EQ(ASCIIToUTF16("John"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Smith"), values[1]);
- EXPECT_EQ(ASCIIToUTF16("Send"), values[2]);
+ const std::vector<FormField>& fields = form.fields;
+ ASSERT_EQ(3U, fields.size());
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("John"),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields[0]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Smith"),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields[1]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ ASCIIToUTF16("Send"),
+ ASCIIToUTF16("submit"),
+ WebInputElement::Submit), fields[2]);
}
TEST_F(FormManagerTest, FillForm) {
@@ -305,28 +301,27 @@ TEST_F(FormManagerTest, FillForm) {
EXPECT_EQ(GURL(web_frame->url()), form.origin);
EXPECT_EQ(GURL("http://buh.com"), form.action);
- const std::vector<string16>& labels = form.labels;
- ASSERT_EQ(3U, labels.size());
- EXPECT_EQ(string16(), labels[0]);
- EXPECT_EQ(string16(), labels[1]);
- EXPECT_EQ(string16(), labels[2]);
-
- const std::vector<string16>& elements = form.elements;
- ASSERT_EQ(3U, elements.size());
- EXPECT_EQ(ASCIIToUTF16("firstname"), elements[0]);
- EXPECT_EQ(ASCIIToUTF16("lastname"), elements[1]);
- EXPECT_EQ(ASCIIToUTF16("reply-send"), elements[2]);
-
- // Verify that the text fields have no values.
- const std::vector<string16>& values = form.values;
- ASSERT_EQ(3U, values.size());
- EXPECT_EQ(string16(), values[0]);
- EXPECT_EQ(string16(), values[1]);
- EXPECT_EQ(ASCIIToUTF16("Send"), values[2]);
+ const std::vector<FormField>& fields = form.fields;
+ ASSERT_EQ(3U, fields.size());
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("firstname"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields[0]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ string16(),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields[1]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ ASCIIToUTF16("Send"),
+ ASCIIToUTF16("submit"),
+ WebInputElement::Submit), fields[2]);
// Fill the form.
- form.values[0] = ASCIIToUTF16("Wyatt");
- form.values[1] = ASCIIToUTF16("Earp");
+ form.fields[0].set_value(ASCIIToUTF16("Wyatt"));
+ form.fields[1].set_value(ASCIIToUTF16("Earp"));
EXPECT_TRUE(form_manager.FillForm(form));
// Find the newly-filled form that contains the input element.
@@ -336,24 +331,23 @@ TEST_F(FormManagerTest, FillForm) {
EXPECT_EQ(GURL(web_frame->url()), form2.origin);
EXPECT_EQ(GURL("http://buh.com"), form2.action);
- const std::vector<string16>& labels2 = form2.labels;
- ASSERT_EQ(3U, labels2.size());
- EXPECT_EQ(string16(), labels2[0]);
- EXPECT_EQ(string16(), labels2[1]);
- EXPECT_EQ(string16(), labels2[2]);
-
- const std::vector<string16>& elements2 = form2.elements;
- ASSERT_EQ(3U, elements2.size());
- EXPECT_EQ(ASCIIToUTF16("firstname"), elements2[0]);
- EXPECT_EQ(ASCIIToUTF16("lastname"), elements2[1]);
- EXPECT_EQ(ASCIIToUTF16("reply-send"), elements2[2]);
-
- // Verify that the text fields have no values.
- const std::vector<string16>& values2 = form2.values;
- ASSERT_EQ(3U, values2.size());
- EXPECT_EQ(ASCIIToUTF16("Wyatt"), values2[0]);
- EXPECT_EQ(ASCIIToUTF16("Earp"), values2[1]);
- EXPECT_EQ(ASCIIToUTF16("Send"), values2[2]);
+ const std::vector<FormField>& fields2 = form2.fields;
+ ASSERT_EQ(3U, fields2.size());
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("Wyatt"),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields2[0]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Earp"),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields2[1]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ ASCIIToUTF16("Send"),
+ ASCIIToUTF16("submit"),
+ WebInputElement::Submit), fields2[2]);
}
TEST_F(FormManagerTest, Reset) {
@@ -405,21 +399,21 @@ TEST_F(FormManagerTest, Labels) {
EXPECT_EQ(GURL(web_frame->url()), form.origin);
EXPECT_EQ(GURL("http://cnn.com"), form.action);
- const std::vector<string16>& labels = form.labels;
- ASSERT_EQ(3U, labels.size());
- EXPECT_EQ(ASCIIToUTF16("First name:"), labels[0]);
- EXPECT_EQ(ASCIIToUTF16("Last name:"), labels[1]);
- EXPECT_EQ(string16(), labels[2]);
-
- const std::vector<string16>& elements = form.elements;
- ASSERT_EQ(3U, elements.size());
- EXPECT_EQ(ASCIIToUTF16("firstname"), elements[0]);
- EXPECT_EQ(ASCIIToUTF16("lastname"), elements[1]);
- EXPECT_EQ(ASCIIToUTF16("reply-send"), elements[2]);
-
- const std::vector<string16>& values = form.values;
- ASSERT_EQ(3U, values.size());
- EXPECT_EQ(ASCIIToUTF16("John"), values[0]);
- EXPECT_EQ(ASCIIToUTF16("Smith"), values[1]);
- EXPECT_EQ(ASCIIToUTF16("Send"), values[2]);
+ const std::vector<FormField>& fields = form.fields;
+ ASSERT_EQ(3U, fields.size());
+ EXPECT_EQ(FormField(ASCIIToUTF16("First name:"),
+ ASCIIToUTF16("firstname"),
+ ASCIIToUTF16("John"),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields[0]);
+ EXPECT_EQ(FormField(ASCIIToUTF16("Last name:"),
+ ASCIIToUTF16("lastname"),
+ ASCIIToUTF16("Smith"),
+ ASCIIToUTF16("text"),
+ WebInputElement::Text), fields[1]);
+ EXPECT_EQ(FormField(string16(),
+ ASCIIToUTF16("reply-send"),
+ ASCIIToUTF16("Send"),
+ ASCIIToUTF16("submit"),
+ WebInputElement::Submit), fields[2]);
}
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 64fe3d7..4efea99 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -1460,7 +1460,8 @@ void RenderView::OnAutocompleteSuggestionsReturned(
autofill_query_node_.reset();
}
-void RenderView::OnAutoFillFormDataFilled(int query_id, const FormData& form) {
+void RenderView::OnAutoFillFormDataFilled(int query_id,
+ const webkit_glue::FormData& form) {
if (query_id != autofill_query_id_)
return;
@@ -1984,7 +1985,7 @@ void RenderView::didAcceptAutoFillSuggestion(
static int query_counter = 0;
autofill_query_id_ = query_counter++;
- FormData form;
+ webkit_glue::FormData form;
const WebInputElement element = node.toConstElement<WebInputElement>();
if (!form_manager_.FindForm(element, &form))
return;
@@ -3949,8 +3950,7 @@ void RenderView::OnResize(const gfx::Size& new_size,
// either width or height, allow scroll bars.
bool allow_scrollbars = (
disable_scrollbars_size_limit_.width() <= new_size.width() ||
- disable_scrollbars_size_limit_.height() <= new_size.height()
- );
+ disable_scrollbars_size_limit_.height() <= new_size.height());
webview()->mainFrame()->setCanHaveScrollbars(allow_scrollbars);
}
}
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 66ff242..4478354 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -737,7 +737,8 @@ class RenderView : public RenderWidget,
int default_suggestions_index);
// Notification that we have received AutoFill form data.
- void OnAutoFillFormDataFilled(int query_id, const FormData& form);
+ void OnAutoFillFormDataFilled(int query_id,
+ const webkit_glue::FormData& form);
// Message that the popup notification has been shown or hidden.
void OnPopupNotificationVisibilityChanged(bool visible);
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();
}