summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/form_structure.cc
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-09 22:56:34 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-09 22:56:34 +0000
commitcf28ec5f4f485d4758de3817cd116e47fdc3edeb (patch)
treee69ea0cac56aaabe71901a1f2bce2e33061dc88a /chrome/browser/autofill/form_structure.cc
parent5b6699d3ed74c9382c5f9a2aa8c8f2500900c7f8 (diff)
downloadchromium_src-cf28ec5f4f485d4758de3817cd116e47fdc3edeb.zip
chromium_src-cf28ec5f4f485d4758de3817cd116e47fdc3edeb.tar.gz
chromium_src-cf28ec5f4f485d4758de3817cd116e47fdc3edeb.tar.bz2
AutoFill: Fill the default profile when the AutoFill accelerator combo is pressed (ctrl-shift-a).
BUG=39491 TEST=none Review URL: http://codereview.chromium.org/1521020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/form_structure.cc')
-rw-r--r--chrome/browser/autofill/form_structure.cc51
1 files changed, 36 insertions, 15 deletions
diff --git a/chrome/browser/autofill/form_structure.cc b/chrome/browser/autofill/form_structure.cc
index bb91ec9..0c28609 100644
--- a/chrome/browser/autofill/form_structure.cc
+++ b/chrome/browser/autofill/form_structure.cc
@@ -12,7 +12,6 @@
#include "chrome/browser/autofill/field_types.h"
#include "chrome/browser/autofill/form_field.h"
#include "third_party/libjingle/files/talk/xmllite/xmlelement.h"
-#include "webkit/glue/form_data.h"
#include "webkit/glue/form_field.h"
using webkit_glue::FormData;
@@ -60,22 +59,24 @@ static std::string Hash64Bit(const std::string& str) {
FormStructure::FormStructure(const FormData& form)
: form_name_(UTF16ToUTF8(form.name)),
source_url_(form.origin),
- target_url_(form.action) {
+ target_url_(form.action),
+ autofill_count_(0) {
// Copy the form fields.
std::vector<webkit_glue::FormField>::const_iterator 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.
- if (!LowerCaseEqualsASCII(field->form_control_type(), kControlTypeText) &&
- !LowerCaseEqualsASCII(field->form_control_type(), kControlTypeSelect))
- continue;
-
- // Add all form fields (including with empty names) to signature.
- // This is a requirement for AutoFill servers.
- form_signature_field_names_.append("&");
- form_signature_field_names_.append(UTF16ToUTF8(field->name()));
+ // We currently only handle text and select fields; however, we need to
+ // store all fields in order to match the fields stored in the FormManager.
+ // We don't append other field types to the form signature though in order
+ // to match the form signature of the AutoFill servers.
+ if (LowerCaseEqualsASCII(field->form_control_type(), kControlTypeText) ||
+ LowerCaseEqualsASCII(field->form_control_type(), kControlTypeSelect)) {
+ // Add all supported form fields (including with empty names) to
+ // signature. This is a requirement for AutoFill servers.
+ form_signature_field_names_.append("&");
+ form_signature_field_names_.append(UTF16ToUTF8(field->name()));
+ ++autofill_count_;
+ }
// Generate a unique name for this field by appending a counter to the name.
string16 unique_name = field->name() + IntToString16(fields_.size() + 1);
@@ -198,7 +199,7 @@ std::string FormStructure::FormSignature() const {
}
bool FormStructure::IsAutoFillable() const {
- if (field_count() < kRequiredFillableFields)
+ if (autofill_count() < kRequiredFillableFields)
return false;
// Rule out http(s)://*/search?...
@@ -230,6 +231,27 @@ size_t FormStructure::field_count() const {
return (field_size == 0) ? 0 : field_size - 1;
}
+FormData FormStructure::ConvertToFormData() const {
+ FormData form;
+ form.name = UTF8ToUTF16(form_name_);
+ form.origin = source_url_;
+ form.action = target_url_;
+
+ if (method_ == GET)
+ form.method = ASCIIToUTF16("GET");
+ else if (method_ == POST)
+ form.method = ASCIIToUTF16("POST");
+ else
+ NOTREACHED();
+
+ for (std::vector<AutoFillField*>::const_iterator iter = fields_.begin();
+ iter != fields_.end() && *iter; ++iter) {
+ form.fields.push_back(static_cast<webkit_glue::FormField>(**iter));
+ }
+
+ return form;
+}
+
bool FormStructure::operator==(const FormData& form) const {
// TODO(jhawkins): Is this enough to differentiate a form?
if (UTF8ToUTF16(form_name_) == form.name &&
@@ -289,4 +311,3 @@ bool FormStructure::EncodeFormRequest(
}
return true;
}
-