summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 03:06:54 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 03:06:54 +0000
commitfb856c7c3b8ed71b0d15cbe08ef4ca35eb79abd3 (patch)
tree37bdfc77e78080fe596f556a5761f6d16188eb5d
parent3242bbfed6822cc22d8154a80c34c3127e692032 (diff)
downloadchromium_src-fb856c7c3b8ed71b0d15cbe08ef4ca35eb79abd3.zip
chromium_src-fb856c7c3b8ed71b0d15cbe08ef4ca35eb79abd3.tar.gz
chromium_src-fb856c7c3b8ed71b0d15cbe08ef4ca35eb79abd3.tar.bz2
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.
BUG=none TEST=none Review URL: http://codereview.chromium.org/602008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38570 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, 113 insertions, 61 deletions
diff --git a/chrome/browser/autofill/autofill_field.cc b/chrome/browser/autofill/autofill_field.cc
index e48d0a4..68dc91e 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(html_input_type());
+ std::string type = UTF16ToUTF8(form_control_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 861b8f0..869c0a3 100644
--- a/chrome/browser/form_field_history_manager.cc
+++ b/chrome/browser/form_field_history_manager.cc
@@ -114,6 +114,22 @@ 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 c19fee8..34092b8 100644
--- a/chrome/browser/webdata/web_data_service_unittest.cc
+++ b/chrome/browser/webdata/web_data_service_unittest.cc
@@ -24,6 +24,7 @@
#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;
@@ -105,7 +106,11 @@ class WebDataServiceTest : public testing::Test {
const string16& value,
std::vector<webkit_glue::FormField>* form_fields) {
form_fields->push_back(
- webkit_glue::FormField(string16(), name, string16(), value));
+ webkit_glue::FormField(string16(),
+ name,
+ value,
+ string16(),
+ WebKit::WebInputElement::Text));
}
MessageLoopForUI message_loop_;
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc
index 1b950c8..8064ef4 100644
--- a/chrome/browser/webdata/web_database_unittest.cc
+++ b/chrome/browser/webdata/web_database_unittest.cc
@@ -21,6 +21,7 @@
#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"
@@ -427,32 +428,36 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_TRUE(db.AddFormFieldValue(
FormField(string16(),
ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Superman"),
string16(),
- ASCIIToUTF16("Superman")),
+ WebKit::WebInputElement::Text),
&changes));
std::vector<string16> v;
for (int i = 0; i < 5; i++) {
EXPECT_TRUE(db.AddFormFieldValue(
FormField(string16(),
ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Clark Kent"),
string16(),
- ASCIIToUTF16("Clark Kent")),
+ WebKit::WebInputElement::Text),
&changes));
}
for (int i = 0; i < 3; i++) {
EXPECT_TRUE(db.AddFormFieldValue(
FormField(string16(),
ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Clark Sutter"),
string16(),
- ASCIIToUTF16("Clark Sutter")),
+ WebKit::WebInputElement::Text),
&changes));
}
for (int i = 0; i < 2; i++) {
EXPECT_TRUE(db.AddFormFieldValue(
FormField(string16(),
ASCIIToUTF16("Favorite Color"),
+ ASCIIToUTF16("Green"),
string16(),
- ASCIIToUTF16("Green")),
+ WebKit::WebInputElement::Text),
&changes));
}
@@ -464,8 +469,9 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
FormField(string16(),
ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Clark Kent"),
string16(),
- ASCIIToUTF16("Clark Kent")),
+ WebKit::WebInputElement::Text),
&pair_id, &count));
EXPECT_EQ(5, count);
EXPECT_NE(0, pair_id);
@@ -475,16 +481,18 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
FormField(string16(),
ASCIIToUTF16("Name"),
+ ASCIIToUTF16("clark kent"),
string16(),
- ASCIIToUTF16("clark kent")),
+ WebKit::WebInputElement::Text),
&pair_id, &count));
EXPECT_EQ(0, count);
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
FormField(string16(),
ASCIIToUTF16("Favorite Color"),
+ ASCIIToUTF16("Green"),
string16(),
- ASCIIToUTF16("Green")),
+ WebKit::WebInputElement::Text),
&pair_id, &count));
EXPECT_EQ(2, count);
@@ -547,8 +555,9 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
FormField(string16(),
ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Clark Kent"),
string16(),
- ASCIIToUTF16("Clark Kent")),
+ WebKit::WebInputElement::Text),
&pair_id, &count));
EXPECT_EQ(0, count);
@@ -561,22 +570,26 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(),
ASCIIToUTF16("blank"),
string16(),
- string16()),
+ string16(),
+ WebKit::WebInputElement::Text),
&changes));
EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(),
ASCIIToUTF16("blank"),
+ ASCIIToUTF16(" "),
string16(),
- ASCIIToUTF16(" ")),
+ WebKit::WebInputElement::Text),
&changes));
EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(),
ASCIIToUTF16("blank"),
+ ASCIIToUTF16(" "),
string16(),
- ASCIIToUTF16(" ")),
+ WebKit::WebInputElement::Text),
&changes));
EXPECT_TRUE(db.AddFormFieldValue(FormField(string16(),
ASCIIToUTF16("blank"),
+ kValue,
string16(),
- kValue),
+ WebKit::WebInputElement::Text),
&changes));
// They should be stored normally as the DB layer does not check for empty
@@ -609,15 +622,17 @@ TEST_F(WebDatabaseTest, Autofill_RemoveBetweenChanges) {
EXPECT_TRUE(db.AddFormFieldValueTime(
FormField(string16(),
ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Superman"),
string16(),
- ASCIIToUTF16("Superman")),
+ WebKit::WebInputElement::Text),
&changes,
t1));
EXPECT_TRUE(db.AddFormFieldValueTime(
FormField(string16(),
ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Superman"),
string16(),
- ASCIIToUTF16("Superman")),
+ WebKit::WebInputElement::Text),
&changes,
t2));
@@ -650,8 +665,9 @@ TEST_F(WebDatabaseTest, Autofill_AddChanges) {
EXPECT_TRUE(db.AddFormFieldValueTime(
FormField(string16(),
ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Superman"),
string16(),
- ASCIIToUTF16("Superman")),
+ WebKit::WebInputElement::Text),
&changes,
t1));
ASSERT_EQ(1U, changes.size());
@@ -664,8 +680,9 @@ TEST_F(WebDatabaseTest, Autofill_AddChanges) {
EXPECT_TRUE(db.AddFormFieldValueTime(
FormField(string16(),
ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Superman"),
string16(),
- ASCIIToUTF16("Superman")),
+ WebKit::WebInputElement::Text),
&changes,
t2));
ASSERT_EQ(1U, changes.size());
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 8c2eaed..cd6dd75 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,8 +912,9 @@ 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) {
@@ -925,15 +926,24 @@ 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, type, value;
+ string16 label, name, value, form_control_type;
+ int type;
result = result && ReadParam(m, iter, &label);
result = result && ReadParam(m, iter, &name);
- result = result && ReadParam(m, iter, &type);
result = result && ReadParam(m, iter, &value);
- if (result)
+ 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);
p->elements.push_back(
- webkit_glue::FormField(label, name, type, value));
+ webkit_glue::FormField(label, name, value,
+ form_control_type, input_type));
+ }
}
return result;
}
diff --git a/webkit/glue/form_field.cc b/webkit/glue/form_field.cc
index a87644f..4d95cb8 100644
--- a/webkit/glue/form_field.cc
+++ b/webkit/glue/form_field.cc
@@ -4,19 +4,39 @@
#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& html_input_type,
- const string16& value)
+ const string16& value,
+ const string16& form_control_type,
+ WebInputElement::InputType input_type)
: label_(label),
name_(name),
- html_input_type_(html_input_type),
- value_(value) {
+ value_(value),
+ form_control_type_(form_control_type),
+ input_type_(input_type) {
}
} // namespace webkit_glue
diff --git a/webkit/glue/form_field.h b/webkit/glue/form_field.h
index 9711c38..dfaf9ce 100644
--- a/webkit/glue/form_field.h
+++ b/webkit/glue/form_field.h
@@ -6,6 +6,7 @@
#define WEBKIT_GLUE_FORM_FIELD_H_
#include "base/string16.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
namespace webkit_glue {
@@ -13,23 +14,27 @@ namespace webkit_glue {
class FormField {
public:
FormField();
+ explicit FormField(const WebKit::WebInputElement& input_element);
FormField(const string16& label,
const string16& name,
- const string16& html_input_type,
- const string16& value);
+ const string16& value,
+ const string16& form_control_type,
+ WebKit::WebInputElement::InputType input_type);
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 6118889..00f3984 100644
--- a/webkit/glue/form_field_values.cc
+++ b/webkit/glue/form_field_values.cc
@@ -5,13 +5,16 @@
#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 namespace WebKit;
+using WebKit::WebFormElement;
+using WebKit::WebFrame;
+using WebKit::WebInputElement;
+using WebKit::WebVector;
+
namespace webkit_glue {
FormFieldValues* FormFieldValues::Create(const WebFormElement& form) {
@@ -33,38 +36,14 @@ FormFieldValues* FormFieldValues::Create(const WebFormElement& form) {
return result;
}
-void FormFieldValues::ExtractFormFieldValues(
- const WebKit::WebFormElement& form) {
-
+void FormFieldValues::ExtractFormFieldValues(const 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())
- 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));
+ if (input_element.isEnabledFormControl())
+ elements.push_back(FormField(input_element));
}
}