summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 03:59:11 +0000
committertony@chromium.org <tony@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 03:59:11 +0000
commita151aa05cb2beecdb9f92a108ff78fa11ea9ce2e (patch)
treea58db79ec08d6fc45827106bc9aa2c5e2434ac52
parent56aaac0fa20bf3033f12f71a920431db1c7f0cc5 (diff)
downloadchromium_src-a151aa05cb2beecdb9f92a108ff78fa11ea9ce2e.zip
chromium_src-a151aa05cb2beecdb9f92a108ff78fa11ea9ce2e.tar.gz
chromium_src-a151aa05cb2beecdb9f92a108ff78fa11ea9ce2e.tar.bz2
Revert "Move conditions of FormFields creation to FormFieldHistoryManager;
AutoFill does not have the same conditions. This required manipulating the FormField data structure to add necessary field data." This reverts commit r38570. TBR=jhawkins Review URL: http://codereview.chromium.org/602014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38573 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autofill/autofill_field.cc2
-rw-r--r--chrome/browser/form_field_history_manager.cc16
-rw-r--r--chrome/browser/webdata/web_data_service_unittest.cc7
-rw-r--r--chrome/browser/webdata/web_database_unittest.cc49
-rw-r--r--chrome/common/render_messages.h22
-rw-r--r--webkit/glue/form_field.cc28
-rw-r--r--webkit/glue/form_field.h13
-rw-r--r--webkit/glue/form_field_values.cc37
8 files changed, 61 insertions, 113 deletions
diff --git a/chrome/browser/autofill/autofill_field.cc b/chrome/browser/autofill/autofill_field.cc
index 68dc91e..e48d0a4 100644
--- a/chrome/browser/autofill/autofill_field.cc
+++ b/chrome/browser/autofill/autofill_field.cc
@@ -51,7 +51,7 @@ bool AutoFillField::IsEmpty() const {
std::string AutoFillField::FieldSignature() const {
std::string field_name = UTF16ToUTF8(name());
- std::string type = UTF16ToUTF8(form_control_type());
+ std::string type = UTF16ToUTF8(html_input_type());
std::string field_string = field_name + "&" + type;
return Hash32Bit(field_string);
}
diff --git a/chrome/browser/form_field_history_manager.cc b/chrome/browser/form_field_history_manager.cc
index 869c0a3..861b8f0 100644
--- a/chrome/browser/form_field_history_manager.cc
+++ b/chrome/browser/form_field_history_manager.cc
@@ -114,22 +114,6 @@ void FormFieldHistoryManager::StoreFormEntriesInWebDatabase(
if (profile()->IsOffTheRecord())
return;
- // We put the following restriction on stored FormFields:
- // - input_type() == WebInputElement::Text
- // - non-empty name
- // - non-empty value
- // - non-empty form_control_type()
- std::vector<webkit_glue::FormField> values;
- for (std::vector<webkit_glue::FormField>::const_iterator iter =
- form.elements.begin();
- iter != form.elements.end(); ++iter) {
- if (iter->input_type() == WebKit::WebInputElement::Text &&
- !iter->value().empty() &&
- !iter->name().empty() &&
- !iter->form_control_type().empty())
- values.push_back(*iter);
- }
-
profile()->GetWebDataService(Profile::EXPLICIT_ACCESS)->
AddFormFieldValues(form.elements);
}
diff --git a/chrome/browser/webdata/web_data_service_unittest.cc b/chrome/browser/webdata/web_data_service_unittest.cc
index 34092b8..c19fee8 100644
--- a/chrome/browser/webdata/web_data_service_unittest.cc
+++ b/chrome/browser/webdata/web_data_service_unittest.cc
@@ -24,7 +24,6 @@
#include "chrome/common/notification_type.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
#include "webkit/glue/form_field.h"
using base::Time;
@@ -106,11 +105,7 @@ class WebDataServiceTest : public testing::Test {
const string16& value,
std::vector<webkit_glue::FormField>* form_fields) {
form_fields->push_back(
- webkit_glue::FormField(string16(),
- name,
- value,
- string16(),
- WebKit::WebInputElement::Text));
+ webkit_glue::FormField(string16(), name, string16(), value));
}
MessageLoopForUI message_loop_;
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc
index 8064ef4..1b950c8 100644
--- a/chrome/browser/webdata/web_database_unittest.cc
+++ b/chrome/browser/webdata/web_database_unittest.cc
@@ -21,7 +21,6 @@
#include "chrome/common/chrome_paths.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
#include "webkit/glue/form_field.h"
#include "webkit/glue/password_form.h"
@@ -428,36 +427,32 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_TRUE(db.AddFormFieldValue(
FormField(string16(),
ASCIIToUTF16("Name"),
- ASCIIToUTF16("Superman"),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16("Superman")),
&changes));
std::vector<string16> v;
for (int i = 0; i < 5; i++) {
EXPECT_TRUE(db.AddFormFieldValue(
FormField(string16(),
ASCIIToUTF16("Name"),
- ASCIIToUTF16("Clark Kent"),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16("Clark Kent")),
&changes));
}
for (int i = 0; i < 3; i++) {
EXPECT_TRUE(db.AddFormFieldValue(
FormField(string16(),
ASCIIToUTF16("Name"),
- ASCIIToUTF16("Clark Sutter"),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16("Clark Sutter")),
&changes));
}
for (int i = 0; i < 2; i++) {
EXPECT_TRUE(db.AddFormFieldValue(
FormField(string16(),
ASCIIToUTF16("Favorite Color"),
- ASCIIToUTF16("Green"),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16("Green")),
&changes));
}
@@ -469,9 +464,8 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
FormField(string16(),
ASCIIToUTF16("Name"),
- ASCIIToUTF16("Clark Kent"),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16("Clark Kent")),
&pair_id, &count));
EXPECT_EQ(5, count);
EXPECT_NE(0, pair_id);
@@ -481,18 +475,16 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
FormField(string16(),
ASCIIToUTF16("Name"),
- ASCIIToUTF16("clark kent"),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16("clark kent")),
&pair_id, &count));
EXPECT_EQ(0, count);
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
FormField(string16(),
ASCIIToUTF16("Favorite Color"),
- ASCIIToUTF16("Green"),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16("Green")),
&pair_id, &count));
EXPECT_EQ(2, count);
@@ -555,9 +547,8 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
FormField(string16(),
ASCIIToUTF16("Name"),
- ASCIIToUTF16("Clark Kent"),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16("Clark Kent")),
&pair_id, &count));
EXPECT_EQ(0, count);
@@ -570,26 +561,22 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(),
ASCIIToUTF16("blank"),
string16(),
- string16(),
- WebKit::WebInputElement::Text),
+ string16()),
&changes));
EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(),
ASCIIToUTF16("blank"),
- ASCIIToUTF16(" "),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16(" ")),
&changes));
EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(),
ASCIIToUTF16("blank"),
- ASCIIToUTF16(" "),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16(" ")),
&changes));
EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(),
ASCIIToUTF16("blank"),
- kValue,
string16(),
- WebKit::WebInputElement::Text),
+ kValue),
&changes));
// They should be stored normally as the DB layer does not check for empty
@@ -622,17 +609,15 @@ TEST_F(WebDatabaseTest, Autofill_RemoveBetweenChanges) {
EXPECT_TRUE(db.AddFormFieldValueTime(
FormField(string16(),
ASCIIToUTF16("Name"),
- ASCIIToUTF16("Superman"),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16("Superman")),
&changes,
t1));
EXPECT_TRUE(db.AddFormFieldValueTime(
FormField(string16(),
ASCIIToUTF16("Name"),
- ASCIIToUTF16("Superman"),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16("Superman")),
&changes,
t2));
@@ -665,9 +650,8 @@ TEST_F(WebDatabaseTest, Autofill_AddChanges) {
EXPECT_TRUE(db.AddFormFieldValueTime(
FormField(string16(),
ASCIIToUTF16("Name"),
- ASCIIToUTF16("Superman"),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16("Superman")),
&changes,
t1));
ASSERT_EQ(1U, changes.size());
@@ -680,9 +664,8 @@ TEST_F(WebDatabaseTest, Autofill_AddChanges) {
EXPECT_TRUE(db.AddFormFieldValueTime(
FormField(string16(),
ASCIIToUTF16("Name"),
- ASCIIToUTF16("Superman"),
string16(),
- WebKit::WebInputElement::Text),
+ ASCIIToUTF16("Superman")),
&changes,
t2));
ASSERT_EQ(1U, changes.size());
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index cd6dd75..8c2eaed 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -503,7 +503,7 @@ struct ViewMsg_DOMStorageEvent_Params {
// Allows an extension to execute code in a tab.
struct ViewMsg_ExecuteCode_Params {
- ViewMsg_ExecuteCode_Params() {}
+ ViewMsg_ExecuteCode_Params(){}
ViewMsg_ExecuteCode_Params(int request_id, const std::string& extension_id,
const std::vector<URLPattern>& host_permissions,
bool is_javascript, const std::string& code,
@@ -912,9 +912,8 @@ struct ParamTraits<webkit_glue::FormFieldValues> {
for (itr = p.elements.begin(); itr != p.elements.end(); itr++) {
WriteParam(m, itr->label());
WriteParam(m, itr->name());
+ WriteParam(m, itr->html_input_type());
WriteParam(m, itr->value());
- WriteParam(m, itr->form_control_type());
- WriteParam(m, static_cast<int>(itr->input_type()));
}
}
static bool Read(const Message* m, void** iter, param_type* p) {
@@ -926,24 +925,15 @@ struct ParamTraits<webkit_glue::FormFieldValues> {
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++) {
- string16 label, name, value, form_control_type;
- int type;
+ string16 label, name, type, value;
result = result && ReadParam(m, iter, &label);
result = result && ReadParam(m, iter, &name);
- result = result && ReadParam(m, iter, &value);
- result = result && ReadParam(m, iter, &form_control_type);
result = result && ReadParam(m, iter, &type);
- if (result) {
- WebKit::WebInputElement::InputType input_type =
- static_cast<WebKit::WebInputElement::InputType>(type);
+ result = result && ReadParam(m, iter, &value);
+ if (result)
p->elements.push_back(
- webkit_glue::FormField(label, name, value,
- form_control_type, input_type));
- }
+ webkit_glue::FormField(label, name, type, value));
}
return result;
}
diff --git a/webkit/glue/form_field.cc b/webkit/glue/form_field.cc
index 4d95cb8..a87644f 100644
--- a/webkit/glue/form_field.cc
+++ b/webkit/glue/form_field.cc
@@ -4,39 +4,19 @@
#include "webkit/glue/form_field.h"
-#include "base/string_util.h"
-
-using WebKit::WebInputElement;
-
namespace webkit_glue {
FormField::FormField() {
}
-FormField::FormField(const WebInputElement& input_element) {
- name_ = input_element.nameForAutofill();
-
- // TODO(jhawkins): Extract the field label. For now we just use the field
- // name.
- label_ = name_;
-
- value_ = input_element.value();
- TrimWhitespace(value_, TRIM_LEADING, &value_);
-
- form_control_type_ = input_element.formControlType();
- input_type_ = input_element.inputType();
-}
-
FormField::FormField(const string16& label,
const string16& name,
- const string16& value,
- const string16& form_control_type,
- WebInputElement::InputType input_type)
+ const string16& html_input_type,
+ const string16& value)
: label_(label),
name_(name),
- value_(value),
- form_control_type_(form_control_type),
- input_type_(input_type) {
+ html_input_type_(html_input_type),
+ value_(value) {
}
} // namespace webkit_glue
diff --git a/webkit/glue/form_field.h b/webkit/glue/form_field.h
index dfaf9ce..9711c38 100644
--- a/webkit/glue/form_field.h
+++ b/webkit/glue/form_field.h
@@ -6,7 +6,6 @@
#define WEBKIT_GLUE_FORM_FIELD_H_
#include "base/string16.h"
-#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
namespace webkit_glue {
@@ -14,27 +13,23 @@ namespace webkit_glue {
class FormField {
public:
FormField();
- explicit FormField(const WebKit::WebInputElement& input_element);
FormField(const string16& label,
const string16& name,
- const string16& value,
- const string16& form_control_type,
- WebKit::WebInputElement::InputType input_type);
+ const string16& html_input_type,
+ const string16& value);
string16 label() const { return label_; }
string16 name() const { return name_; }
+ string16 html_input_type() const { return html_input_type_; }
string16 value() const { return value_; }
- string16 form_control_type() const { return form_control_type_; }
- WebKit::WebInputElement::InputType input_type() const { return input_type_; }
void set_value(const string16& value) { value_ = value; }
private:
string16 label_;
string16 name_;
+ string16 html_input_type_;
string16 value_;
- string16 form_control_type_;
- WebKit::WebInputElement::InputType input_type_;
};
} // namespace webkit_glue
diff --git a/webkit/glue/form_field_values.cc b/webkit/glue/form_field_values.cc
index 00f3984..6118889 100644
--- a/webkit/glue/form_field_values.cc
+++ b/webkit/glue/form_field_values.cc
@@ -5,16 +5,13 @@
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/string16.h"
+#include "base/string_util.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h"
#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
#include "webkit/glue/form_field_values.h"
-using WebKit::WebFormElement;
-using WebKit::WebFrame;
-using WebKit::WebInputElement;
-using WebKit::WebVector;
-
+using namespace WebKit;
namespace webkit_glue {
FormFieldValues* FormFieldValues::Create(const WebFormElement& form) {
@@ -36,14 +33,38 @@ FormFieldValues* FormFieldValues::Create(const WebFormElement& form) {
return result;
}
-void FormFieldValues::ExtractFormFieldValues(const WebFormElement& form) {
+void FormFieldValues::ExtractFormFieldValues(
+ const WebKit::WebFormElement& form) {
+
WebVector<WebInputElement> input_elements;
form.getInputElements(input_elements);
for (size_t i = 0; i < input_elements.size(); i++) {
const WebInputElement& input_element = input_elements[i];
- if (input_element.isEnabledFormControl())
- elements.push_back(FormField(input_element));
+ if (!input_element.isEnabledFormControl())
+ continue;
+
+ // Ignore all input types except TEXT.
+ if (input_element.inputType() != WebInputElement::Text)
+ continue;
+
+ // For each TEXT input field, store the name and value
+ string16 value = input_element.value();
+ TrimWhitespace(value, TRIM_LEADING, &value);
+ if (value.empty())
+ continue;
+
+ string16 name = input_element.nameForAutofill();
+ if (name.empty())
+ continue; // If we have no name, there is nothing to store.
+
+ string16 type = input_element.formControlType();
+ if (type.empty())
+ continue;
+
+ // TODO(jhawkins): Extract the field label. For now we just use the field
+ // name.
+ elements.push_back(FormField(name, name, type, value));
}
}