summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-21 19:53:23 +0000
committerjhawkins@chromium.org <jhawkins@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-21 19:53:23 +0000
commit41e342f3745b27ba8eeaa87187e3465de484c2a4 (patch)
tree450e86b869f04fe823e0a28465d7899ce0b9f590 /chrome
parente8cf47b31dde03bf5e14d10af9834eaf12cba3c5 (diff)
downloadchromium_src-41e342f3745b27ba8eeaa87187e3465de484c2a4.zip
chromium_src-41e342f3745b27ba8eeaa87187e3465de484c2a4.tar.gz
chromium_src-41e342f3745b27ba8eeaa87187e3465de484c2a4.tar.bz2
Fix for: State in small letters should be auto-filled from the profile.
BUG=38222 TEST=in the bug Patch by George Yakovleg <georgey@chromium.org> Review URL: http://codereview.chromium.org/2832064 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53234 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/autofill/autofill_manager.cc30
-rw-r--r--chrome/browser/autofill/autofill_manager.h7
-rw-r--r--chrome/common/render_messages.h4
-rw-r--r--chrome/renderer/form_manager.cc25
4 files changed, 65 insertions, 1 deletions
diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc
index d1c2950..127cc56 100644
--- a/chrome/browser/autofill/autofill_manager.cc
+++ b/chrome/browser/autofill/autofill_manager.cc
@@ -643,10 +643,38 @@ void AutoFillManager::FillFormField(const AutoFillProfile* profile,
if (type.subgroup() == AutoFillType::PHONE_NUMBER) {
FillPhoneNumberField(profile, field);
} else {
- field->set_value(profile->GetFieldText(type));
+ if (field->form_control_type() == ASCIIToUTF16("select-one"))
+ FillSelectOneField(profile, type, field);
+ else
+ field->set_value(profile->GetFieldText(type));
+ }
+}
+
+void AutoFillManager::FillSelectOneField(const AutoFillProfile* profile,
+ AutoFillType type,
+ webkit_glue::FormField* field) {
+ DCHECK(profile);
+ DCHECK(field);
+ DCHECK(field->form_control_type() == ASCIIToUTF16("select-one"));
+ string16 selected_string = profile->GetFieldText(type);
+ std::string ascii_value = UTF16ToASCII(selected_string);
+ for (size_t i = 0; i < field->option_strings().size(); ++i) {
+ if (profile->GetFieldText(type) == field->option_strings()[i]) {
+ // An exact match - use it.
+ selected_string = profile->GetFieldText(type);
+ break;
+ }
+ if (!base::strcasecmp(UTF16ToASCII(field->option_strings()[i]).c_str(),
+ ascii_value.c_str())) {
+ // A match, but not in the same case - save it for the case we won't
+ // find an exact match.
+ selected_string = field->option_strings()[i];
+ }
}
+ field->set_value(selected_string);
}
+
void AutoFillManager::FillPhoneNumberField(const AutoFillProfile* profile,
webkit_glue::FormField* field) {
// If we are filling a phone number, check to see if the size field
diff --git a/chrome/browser/autofill/autofill_manager.h b/chrome/browser/autofill/autofill_manager.h
index fe4d7bd..f6574d1 100644
--- a/chrome/browser/autofill/autofill_manager.h
+++ b/chrome/browser/autofill/autofill_manager.h
@@ -141,6 +141,13 @@ class AutoFillManager : public RenderViewHostDelegate::AutoFill,
AutoFillType type,
webkit_glue::FormField* field);
+ // Select matching data in the |field|. For now only fixes the cases of the
+ // wrong case, in the future should do extended matching (for example,
+ // Hawaii -> HI).
+ void FillSelectOneField(const AutoFillProfile* profile,
+ AutoFillType type,
+ webkit_glue::FormField* field);
+
// Set |field| argument's value for phone number based on contents of the
// |profile|.
void FillPhoneNumberField(const AutoFillProfile* profile,
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index 4889965..e1ec6b3 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -957,15 +957,18 @@ struct ParamTraits<webkit_glue::FormField> {
WriteParam(m, p.value());
WriteParam(m, p.form_control_type());
WriteParam(m, p.size());
+ WriteParam(m, p.option_strings());
}
static bool Read(const Message* m, void** iter, param_type* p) {
string16 label, name, value, form_control_type;
int size = 0;
+ std::vector<string16> options;
bool 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, &size);
+ result = result && ReadParam(m, iter, &options);
if (!result)
return false;
@@ -974,6 +977,7 @@ struct ParamTraits<webkit_glue::FormField> {
p->set_value(value);
p->set_form_control_type(form_control_type);
p->set_size(size);
+ p->set_option_strings(options);
return true;
}
static void Log(const param_type& p, std::wstring* l) {
diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc
index 0af0f4a..bfb9fe9 100644
--- a/chrome/renderer/form_manager.cc
+++ b/chrome/renderer/form_manager.cc
@@ -16,6 +16,7 @@
#include "third_party/WebKit/WebKit/chromium/public/WebLabelElement.h"
#include "third_party/WebKit/WebKit/chromium/public/WebNode.h"
#include "third_party/WebKit/WebKit/chromium/public/WebNodeList.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebOptionElement.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSelectElement.h"
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/WebKit/chromium/public/WebVector.h"
@@ -33,6 +34,7 @@ using WebKit::WebInputElement;
using WebKit::WebLabelElement;
using WebKit::WebNode;
using WebKit::WebNodeList;
+using WebKit::WebOptionElement;
using WebKit::WebSelectElement;
using WebKit::WebString;
using WebKit::WebVector;
@@ -213,6 +215,24 @@ string16 InferLabelFromDefinitionList(
return inferred_label;
}
+void GetOptionStringsFromElement(WebKit::WebFormControlElement element,
+ std::vector<string16>* option_strings) {
+ DCHECK(!element.isNull());
+ DCHECK(option_strings);
+ option_strings->clear();
+ if (element.formControlType() == ASCIIToUTF16("select-one")) {
+ WebSelectElement select_element = element.to<WebSelectElement>();
+
+ // For select-one elements copy option strings.
+ WebVector<WebElement> list_items = select_element.listItems();
+ option_strings->reserve(list_items.size());
+ for (size_t i = 0; i < list_items.size(); ++i) {
+ if (list_items[i].hasTagName("option"))
+ option_strings->push_back(list_items[i].to<WebOptionElement>().value());
+ }
+ }
+}
+
} // namespace
FormManager::FormManager() {
@@ -233,6 +253,11 @@ void FormManager::WebFormControlElementToFormField(
field->set_name(element.nameForAutofill());
field->set_form_control_type(element.formControlType());
+ // Set option strings on the field if available.
+ std::vector<string16> option_strings;
+ GetOptionStringsFromElement(element, &option_strings);
+ field->set_option_strings(option_strings);
+
if (element.formControlType() == WebString::fromUTF8("text")) {
const WebInputElement& input_element = element.toConst<WebInputElement>();
field->set_size(input_element.size());