summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/form_field_history_manager.h4
-rw-r--r--chrome/browser/webdata/web_data_service.cc11
-rw-r--r--chrome/browser/webdata/web_data_service.h7
-rw-r--r--chrome/browser/webdata/web_database.cc22
-rw-r--r--chrome/browser/webdata/web_database.h19
-rw-r--r--chrome/browser/webdata/web_database_unittest.cc56
-rw-r--r--chrome/common/render_messages.h14
-rw-r--r--webkit/glue/form_field.cc21
-rw-r--r--webkit/glue/form_field.h41
-rw-r--r--webkit/glue/form_field_values.cc6
-rw-r--r--webkit/glue/form_field_values.h20
-rw-r--r--webkit/webkit.gyp2
12 files changed, 141 insertions, 82 deletions
diff --git a/chrome/browser/form_field_history_manager.h b/chrome/browser/form_field_history_manager.h
index edab543..3672253 100644
--- a/chrome/browser/form_field_history_manager.h
+++ b/chrome/browser/form_field_history_manager.h
@@ -18,8 +18,8 @@ class FormFieldValues;
class Profile;
class TabContents;
-// Per-tab autofill manager. Handles receiving form data from the renderer and
-// the storing and retrieving of form data through WebDataService.
+// Per-tab form field history manager. Handles receiving form data from the
+// renderer and the storing and retrieving of form data through WebDataService.
class FormFieldHistoryManager : public RenderViewHostDelegate::FormFieldHistory,
public WebDataServiceConsumer {
public:
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
index cc52def..32e194e 100644
--- a/chrome/browser/webdata/web_data_service.cc
+++ b/chrome/browser/webdata/web_data_service.cc
@@ -9,7 +9,6 @@
#include "base/scoped_ptr.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/common/chrome_constants.h"
-#include "webkit/glue/form_field_values.h"
#include "webkit/glue/password_form.h"
////////////////////////////////////////////////////////////////////////////////
@@ -19,7 +18,7 @@
////////////////////////////////////////////////////////////////////////////////
using base::Time;
-using webkit_glue::FormFieldValues;
+using webkit_glue::FormField;
using webkit_glue::PasswordForm;
WebDataService::WebDataService() : thread_(NULL),
@@ -115,9 +114,9 @@ void WebDataService::CancelRequest(Handle h) {
}
void WebDataService::AddFormFieldValues(
- const std::vector<FormFieldValues::Element>& element) {
- GenericRequest<std::vector<FormFieldValues::Element> >* request =
- new GenericRequest<std::vector<FormFieldValues::Element> >(
+ const std::vector<FormField>& element) {
+ GenericRequest<std::vector<FormField> >* request =
+ new GenericRequest<std::vector<FormField> >(
this, GetNextRequestHandle(), NULL, element);
RegisterRequest(request);
ScheduleTask(NewRunnableMethod(this,
@@ -573,7 +572,7 @@ void WebDataService::GetBlacklistLoginsImpl(WebDataRequest* request) {
////////////////////////////////////////////////////////////////////////////////
void WebDataService::AddFormFieldValuesImpl(
- GenericRequest<std::vector<FormFieldValues::Element> >* request) {
+ GenericRequest<std::vector<FormField> >* request) {
if (db_ && !request->IsCancelled()) {
if (db_->AddFormFieldValues(request->GetArgument()))
ScheduleCommit();
diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h
index 7226122..6794030 100644
--- a/chrome/browser/webdata/web_data_service.h
+++ b/chrome/browser/webdata/web_data_service.h
@@ -15,7 +15,7 @@
#include "base/scoped_vector.h"
#include "base/thread.h"
#include "chrome/browser/webdata/web_database.h"
-#include "webkit/glue/form_field_values.h"
+#include "webkit/glue/form_field.h"
#if defined(OS_WIN)
struct IE7PasswordInfo;
@@ -376,7 +376,7 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> {
// Schedules a task to add form elements to the web database.
void AddFormFieldValues(
- const std::vector<webkit_glue::FormFieldValues::Element>& elements);
+ const std::vector<webkit_glue::FormField>& elements);
// Initiates the request for a vector of values which have been entered in
// form input fields named |name|. The method OnWebDataServiceRequestDone of
@@ -465,8 +465,7 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> {
//
//////////////////////////////////////////////////////////////////////////////
void AddFormFieldValuesImpl(
- GenericRequest<std::vector<webkit_glue::FormFieldValues::Element> >*
- request);
+ GenericRequest<std::vector<webkit_glue::FormField> >* request);
void GetFormValuesForElementNameImpl(WebDataRequest* request,
const string16& name, const string16& prefix, int limit);
void RemoveFormElementsAddedBetweenImpl(
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index e163f56..ffe484c 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -27,6 +27,7 @@
// http://code.google.com/p/chromium/issues/detail?id=8205 (Linux)
#include "chrome/browser/password_manager/encryptor.h"
+using webkit_glue::FormField;
using webkit_glue::PasswordForm;
////////////////////////////////////////////////////////////////////////////////
@@ -99,7 +100,6 @@ using webkit_glue::PasswordForm;
////////////////////////////////////////////////////////////////////////////////
using base::Time;
-using webkit_glue::FormFieldValues;
// Current version number.
static const int kCurrentVersionNumber = 22;
@@ -803,9 +803,9 @@ bool WebDatabase::GetAllLogins(std::vector<PasswordForm*>* forms,
}
bool WebDatabase::AddFormFieldValues(
- const std::vector<FormFieldValues::Element>& elements) {
+ const std::vector<FormField>& elements) {
bool result = true;
- for (std::vector<FormFieldValues::Element>::const_iterator
+ for (std::vector<FormField>::const_iterator
itr = elements.begin();
itr != elements.end();
itr++) {
@@ -837,7 +837,7 @@ bool WebDatabase::ClearAutofillEmptyValueElements() {
}
bool WebDatabase::GetIDAndCountOfFormElement(
- const FormFieldValues::Element& element,
+ const FormField& element,
int64* pair_id,
int* count) {
sql::Statement s(db_.GetUniqueStatement(
@@ -848,8 +848,8 @@ bool WebDatabase::GetIDAndCountOfFormElement(
return false;
}
- s.BindString(0, UTF16ToUTF8(element.name));
- s.BindString(1, UTF16ToUTF8(element.value));
+ s.BindString(0, UTF16ToUTF8(element.name()));
+ s.BindString(1, UTF16ToUTF8(element.value()));
*count = 0;
@@ -878,7 +878,7 @@ bool WebDatabase::GetCountOfFormElement(int64 pair_id, int* count) {
return false;
}
-bool WebDatabase::InsertFormElement(const FormFieldValues::Element& element,
+bool WebDatabase::InsertFormElement(const FormField& element,
int64* pair_id) {
sql::Statement s(db_.GetUniqueStatement(
"INSERT INTO autofill (name, value, value_lower) VALUES (?,?,?)"));
@@ -887,9 +887,9 @@ bool WebDatabase::InsertFormElement(const FormFieldValues::Element& element,
return false;
}
- s.BindString(0, UTF16ToUTF8(element.name));
- s.BindString(1, UTF16ToUTF8(element.value));
- s.BindString(2, UTF16ToUTF8(l10n_util::ToLower(element.value)));
+ s.BindString(0, UTF16ToUTF8(element.name()));
+ s.BindString(1, UTF16ToUTF8(element.value()));
+ s.BindString(2, UTF16ToUTF8(l10n_util::ToLower(element.value())));
if (!s.Run()) {
NOTREACHED();
@@ -939,7 +939,7 @@ bool WebDatabase::SetCountOfFormElement(int64 pair_id, int count) {
return true;
}
-bool WebDatabase::AddFormFieldValue(const FormFieldValues::Element& element) {
+bool WebDatabase::AddFormFieldValue(const FormField& element) {
int count = 0;
int64 pair_id;
diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h
index cc73e9b..32abb4b 100644
--- a/chrome/browser/webdata/web_database.h
+++ b/chrome/browser/webdata/web_database.h
@@ -14,7 +14,7 @@
#include "chrome/browser/search_engines/template_url.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
-#include "webkit/glue/form_field_values.h"
+#include "webkit/glue/form_field.h"
class FilePath;
@@ -132,12 +132,10 @@ class WebDatabase {
// Records the form elements in |elements| in the database in the autofill
// table.
- bool AddFormFieldValues(
- const std::vector<webkit_glue::FormFieldValues::Element>& elements);
+ bool AddFormFieldValues(const std::vector<webkit_glue::FormField>& elements);
// Records a single form element in in the database in the autofill table.
- bool AddFormFieldValue(
- const webkit_glue::FormFieldValues::Element& element);
+ bool AddFormFieldValue(const webkit_glue::FormField& element);
// Retrieves a vector of all values which have been recorded in the autofill
// table as the value in a form element with name |name| and which start with
@@ -167,10 +165,9 @@ class WebDatabase {
// Gets the pair_id and count entries from name and value specified in
// |element|. Sets *count to 0 if there is no such row in the table.
- bool GetIDAndCountOfFormElement(
- const webkit_glue::FormFieldValues::Element& element,
- int64* pair_id,
- int* count);
+ bool GetIDAndCountOfFormElement(const webkit_glue::FormField& element,
+ int64* pair_id,
+ int* count);
// Gets the count only given the pair_id.
bool GetCountOfFormElement(int64 pair_id, int* count);
@@ -180,9 +177,7 @@ class WebDatabase {
// Adds a new row to the autofill table with name and value given in
// |element|. Sets *pair_id to the pair_id of the new row.
- bool InsertFormElement(
- const webkit_glue::FormFieldValues::Element& element,
- int64* pair_id);
+ bool InsertFormElement(const webkit_glue::FormField& element, int64* pair_id);
// Adds a new row to the autofill_dates table.
bool InsertPairIDAndDate(int64 pair_id, base::Time date_created);
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc
index f6ac53b..2e043f4 100644
--- a/chrome/browser/webdata/web_database_unittest.cc
+++ b/chrome/browser/webdata/web_database_unittest.cc
@@ -13,12 +13,12 @@
#include "chrome/common/chrome_paths.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/glue/form_field_values.h"
+#include "webkit/glue/form_field.h"
#include "webkit/glue/password_form.h"
using base::Time;
using base::TimeDelta;
-using webkit_glue::FormFieldValues;
+using webkit_glue::FormField;
using webkit_glue::PasswordForm;
class WebDatabaseTest : public testing::Test {
@@ -392,23 +392,27 @@ TEST_F(WebDatabaseTest, Autofill) {
// Simulate the submission of a handful of entries in a field called "Name",
// some more often than others.
EXPECT_TRUE(db.AddFormFieldValue(
- FormFieldValues::Element(ASCIIToUTF16("Name"),
- ASCIIToUTF16("Superman"))));
+ FormField(NULL,
+ ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Superman"))));
std::vector<string16> v;
for (int i = 0; i < 5; i++) {
EXPECT_TRUE(db.AddFormFieldValue(
- FormFieldValues::Element(ASCIIToUTF16("Name"),
- ASCIIToUTF16("Clark Kent"))));
+ FormField(NULL,
+ ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Clark Kent"))));
}
for (int i = 0; i < 3; i++) {
EXPECT_TRUE(db.AddFormFieldValue(
- FormFieldValues::Element(ASCIIToUTF16("Name"),
- ASCIIToUTF16("Clark Sutter"))));
+ FormField(NULL,
+ ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Clark Sutter"))));
}
for (int i = 0; i < 2; i++) {
EXPECT_TRUE(db.AddFormFieldValue(
- FormFieldValues::Element(ASCIIToUTF16("Favorite Color"),
- ASCIIToUTF16("Green"))));
+ FormField(NULL,
+ ASCIIToUTF16("Favorite Color"),
+ ASCIIToUTF16("Green"))));
}
int count = 0;
@@ -417,8 +421,7 @@ TEST_F(WebDatabaseTest, Autofill) {
// We have added the name Clark Kent 5 times, so count should be 5 and pair_id
// should be somthing non-zero.
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
- FormFieldValues::Element(ASCIIToUTF16("Name"),
- ASCIIToUTF16("Clark Kent")),
+ FormField(NULL, ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")),
&pair_id, &count));
EXPECT_EQ(5, count);
EXPECT_NE(0, pair_id);
@@ -426,14 +429,12 @@ TEST_F(WebDatabaseTest, Autofill) {
// Storing in the data base should be case sensitive, so there should be no
// database entry for clark kent lowercase.
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
- FormFieldValues::Element(ASCIIToUTF16("Name"),
- ASCIIToUTF16("clark kent")),
+ FormField(NULL, ASCIIToUTF16("Name"), ASCIIToUTF16("clark kent")),
&pair_id, &count));
EXPECT_EQ(0, count);
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
- FormFieldValues::Element(ASCIIToUTF16("Favorite Color"),
- ASCIIToUTF16("Green")),
+ FormField(NULL, ASCIIToUTF16("Favorite Color"), ASCIIToUTF16("Green")),
&pair_id, &count));
EXPECT_EQ(2, count);
@@ -474,8 +475,7 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_TRUE(db.RemoveFormElementsAddedBetween(t1, Time()));
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
- FormFieldValues::Element(ASCIIToUTF16("Name"),
- ASCIIToUTF16("Clark Kent")),
+ FormField(NULL, ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")),
&pair_id, &count));
EXPECT_EQ(0, count);
@@ -485,14 +485,18 @@ TEST_F(WebDatabaseTest, Autofill) {
// Now add some values with empty strings.
const string16 kValue = ASCIIToUTF16(" toto ");
- EXPECT_TRUE(db.AddFormFieldValue(
- FormFieldValues::Element(ASCIIToUTF16("blank"), string16())));
- EXPECT_TRUE(db.AddFormFieldValue(
- FormFieldValues::Element(ASCIIToUTF16("blank"), ASCIIToUTF16(" "))));
- EXPECT_TRUE(db.AddFormFieldValue(
- FormFieldValues::Element(ASCIIToUTF16("blank"), ASCIIToUTF16(" "))));
- EXPECT_TRUE(db.AddFormFieldValue(
- FormFieldValues::Element(ASCIIToUTF16("blank"), kValue)));
+ EXPECT_TRUE(db.AddFormFieldValue(FormField(NULL,
+ ASCIIToUTF16("blank"),
+ string16())));
+ EXPECT_TRUE(db.AddFormFieldValue(FormField(NULL,
+ ASCIIToUTF16("blank"),
+ ASCIIToUTF16(" "))));
+ EXPECT_TRUE(db.AddFormFieldValue(FormField(NULL,
+ ASCIIToUTF16("blank"),
+ ASCIIToUTF16(" "))));
+ EXPECT_TRUE(db.AddFormFieldValue(FormField(NULL,
+ ASCIIToUTF16("blank"),
+ kValue)));
// They should be stored normally as the DB layer does not check for empty
// values.
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 0ef796c..dfb7c09 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -14,6 +14,7 @@
#include "base/basictypes.h"
#include "base/ref_counted.h"
#include "base/shared_memory.h"
+#include "base/string16.h"
#include "chrome/browser/renderer_host/resource_handler.h"
#include "chrome/common/common_param_traits.h"
#include "chrome/common/css_colors.h"
@@ -36,6 +37,7 @@
#include "webkit/appcache/appcache_interfaces.h"
#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"
@@ -738,10 +740,10 @@ struct ParamTraits<webkit_glue::FormFieldValues> {
typedef webkit_glue::FormFieldValues param_type;
static void Write(Message* m, const param_type& p) {
WriteParam(m, p.elements.size());
- std::vector<webkit_glue::FormFieldValues::Element>::const_iterator itr;
+ std::vector<webkit_glue::FormField>::const_iterator itr;
for (itr = p.elements.begin(); itr != p.elements.end(); itr++) {
- WriteParam(m, itr->name);
- WriteParam(m, itr->value);
+ WriteParam(m, itr->name());
+ WriteParam(m, itr->value());
}
}
static bool Read(const Message* m, void** iter, param_type* p) {
@@ -750,8 +752,10 @@ struct ParamTraits<webkit_glue::FormFieldValues> {
result = result && ReadParam(m, iter, &elements_size);
p->elements.resize(elements_size);
for (size_t i = 0; i < elements_size; i++) {
- result = result && ReadParam(m, iter, &(p->elements[i].name));
- result = result && ReadParam(m, iter, &(p->elements[i].value));
+ string16 name = p->elements[i].name();
+ string16 value = p->elements[i].value();
+ result = result && ReadParam(m, iter, &name);
+ result = result && ReadParam(m, iter, &value);
}
return result;
}
diff --git a/webkit/glue/form_field.cc b/webkit/glue/form_field.cc
new file mode 100644
index 0000000..76992f5
--- /dev/null
+++ b/webkit/glue/form_field.cc
@@ -0,0 +1,21 @@
+// Copyright (c) 2009 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"
+
+namespace webkit_glue {
+
+FormField::FormField()
+ : element_(NULL) {
+}
+
+FormField::FormField(WebCore::HTMLFormControlElement* element,
+ const string16& name,
+ const string16& value)
+ : element_(element),
+ name_(name),
+ value_(value) {
+}
+
+} // namespace webkit_glue
diff --git a/webkit/glue/form_field.h b/webkit/glue/form_field.h
new file mode 100644
index 0000000..3871881
--- /dev/null
+++ b/webkit/glue/form_field.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2009 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.
+
+#ifndef WEBKIT_GLUE_FORM_FIELD_H_
+#define WEBKIT_GLUE_FORM_FIELD_H_
+
+#include "base/string16.h"
+
+namespace WebCore {
+class HTMLFormControlElement;
+}
+
+namespace webkit_glue {
+
+// Stores information about a field in a form.
+class FormField {
+ public:
+ FormField();
+ FormField(WebCore::HTMLFormControlElement* element,
+ const string16& name,
+ const string16& value);
+
+ WebCore::HTMLFormControlElement* element() const { return element_; }
+ string16 name() const { return name_; }
+ string16 value() const { return value_; }
+
+ void set_element(WebCore::HTMLFormControlElement* element) {
+ element_ = element;
+ }
+ void set_value(const string16& value) { value_ = value; }
+
+ private:
+ WebCore::HTMLFormControlElement* element_;
+ string16 name_;
+ string16 value_;
+};
+
+} // namespace webkit_glue
+
+#endif // WEBKIT_GLUE_FORM_FIELD_H_
diff --git a/webkit/glue/form_field_values.cc b/webkit/glue/form_field_values.cc
index 3a57fad..3afdedd 100644
--- a/webkit/glue/form_field_values.cc
+++ b/webkit/glue/form_field_values.cc
@@ -12,6 +12,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/string16.h"
#include "base/string_util.h"
#include "webkit/api/public/WebForm.h"
#include "webkit/glue/form_field_values.h"
@@ -64,12 +65,11 @@ FormFieldValues* FormFieldValues::Create(const WebForm& webform) {
if (value.length() == 0)
continue;
- string16 name = StringToString16(
- WebKit::nameOfInputElement(input_element));
+ string16 name = StringToString16(WebKit::nameOfInputElement(input_element));
if (name.length() == 0)
continue; // If we have no name, there is nothing to store.
- result->elements.push_back(FormFieldValues::Element(name, value));
+ result->elements.push_back(FormField(form_element, name, value));
}
return result;
diff --git a/webkit/glue/form_field_values.h b/webkit/glue/form_field_values.h
index 7b7ee69..5c2ea62c 100644
--- a/webkit/glue/form_field_values.h
+++ b/webkit/glue/form_field_values.h
@@ -5,9 +5,14 @@
#ifndef WEBKIT_GLUE_FORM_FIELD_VALUES_H_
#define WEBKIT_GLUE_FORM_FIELD_VALUES_H_
-#include <string>
#include <vector>
+#include "webkit/glue/form_field.h"
+
+namespace WebCore {
+class HTMLInputElement;
+}
+
namespace WebKit {
class WebForm;
}
@@ -18,21 +23,10 @@ namespace webkit_glue {
// values entered in the fields.
class FormFieldValues {
public:
- // Struct for storing name/value pairs.
- struct Element {
- Element() {}
- Element(const string16& in_name, const string16& in_value) {
- name = in_name;
- value = in_value;
- }
- string16 name;
- string16 value;
- };
-
static FormFieldValues* Create(const WebKit::WebForm& form);
// A vector of all the input fields in the form.
- std::vector<Element> elements;
+ std::vector<FormField> elements;
};
} // namespace webkit_glue
diff --git a/webkit/webkit.gyp b/webkit/webkit.gyp
index 82a713f..f7846c6 100644
--- a/webkit/webkit.gyp
+++ b/webkit/webkit.gyp
@@ -574,6 +574,8 @@
'glue/entity_map.cc',
'glue/entity_map.h',
'glue/form_data.h',
+ 'glue/form_field.cc',
+ 'glue/form_field.h',
'glue/form_field_values.cc',
'glue/form_field_values.h',
'glue/ftp_directory_listing_response_delegate.cc',