| Index: chrome/renderer/autofill/form_autofill_util.cc
|
| diff --git a/chrome/renderer/autofill/form_autofill_util.cc b/chrome/renderer/autofill/form_autofill_util.cc
|
| index e875233c8735545d1d43dd50c5c325525935d32e..23c5866d26072f221b822875bf8bfebc261ce8d9 100644
|
| --- a/chrome/renderer/autofill/form_autofill_util.cc
|
| +++ b/chrome/renderer/autofill/form_autofill_util.cc
|
| @@ -42,8 +42,11 @@ using WebKit::WebVector;
|
| namespace {
|
|
|
| using autofill::ExtractAutofillableElements;
|
| -using autofill::IsTextInput;
|
| +using autofill::IsAutofillableInputElement;
|
| +using autofill::IsCheckboxElement;
|
| +using autofill::IsRadioButtonElement;
|
| using autofill::IsSelectElement;
|
| +using autofill::IsTextInput;
|
|
|
| // The maximum length allowed for form data.
|
| const size_t kMaxDataLength = 1024;
|
| @@ -66,7 +69,7 @@ bool HasTagName(const WebNode& node, const WebKit::WebString& tag) {
|
|
|
| bool IsAutofillableElement(const WebFormControlElement& element) {
|
| const WebInputElement* input_element = toWebInputElement(&element);
|
| - return IsTextInput(input_element) || IsSelectElement(element);
|
| + return IsAutofillableInputElement(input_element) || IsSelectElement(element);
|
| }
|
|
|
| // Appends |suffix| to |prefix| so that any intermediary whitespace is collapsed
|
| @@ -459,12 +462,11 @@ void ForEachMatchingFormField(const WebFormElement& form_element,
|
| bool is_initiating_element = (*element == initiating_element);
|
|
|
| const WebInputElement* input_element = toWebInputElement(element);
|
| - if (IsTextInput(input_element)) {
|
| - // Only autofill empty fields and the field that initiated the filling,
|
| - // i.e. the field the user is currently editing and interacting with.
|
| - if (!is_initiating_element && !input_element->value().isEmpty())
|
| - continue;
|
| - }
|
| + // Only autofill empty fields and the field that initiated the filling,
|
| + // i.e. the field the user is currently editing and interacting with.
|
| + if (!is_initiating_element && IsTextInput(input_element) &&
|
| + !input_element->value().isEmpty())
|
| + continue;
|
|
|
| if (!element->isEnabled() || element->isReadOnly() ||
|
| (only_focusable_elements && !element->isFocusable()))
|
| @@ -496,13 +498,16 @@ void FillFormField(const FormFieldData& data,
|
| // Clear the current IME composition (the underline), if there is one.
|
| input_element->document().frame()->unmarkText();
|
| }
|
| - } else {
|
| - DCHECK(IsSelectElement(*field));
|
| + } else if (IsSelectElement(*field)) {
|
| WebSelectElement select_element = field->to<WebSelectElement>();
|
| if (select_element.value() != data.value) {
|
| select_element.setValue(data.value);
|
| select_element.dispatchFormControlChangeEvent();
|
| }
|
| + } else {
|
| + DCHECK(IsRadioButtonElement(input_element) ||
|
| + IsCheckboxElement(input_element));
|
| + input_element->setChecked(data.is_checked, true);
|
| }
|
| }
|
|
|
| @@ -515,7 +520,8 @@ void PreviewFormField(const FormFieldData& data,
|
| if (data.value.empty())
|
| return;
|
|
|
| - // Only preview input fields.
|
| + // Only preview input fields. Excludes checkboxes and radio buttons, as there
|
| + // is no provision for setSuggestedCheckedValue in WebInputElement.
|
| WebInputElement* input_element = toWebInputElement(field);
|
| if (!IsTextInput(input_element))
|
| return;
|
| @@ -551,6 +557,25 @@ bool IsSelectElement(const WebFormControlElement& element) {
|
| return element.formControlType() == ASCIIToUTF16("select-one");
|
| }
|
|
|
| +bool IsCheckboxElement(const WebInputElement* element) {
|
| + if (!element)
|
| + return false;
|
| +
|
| + return element->formControlType() == ASCIIToUTF16("checkbox");
|
| +}
|
| +
|
| +bool IsRadioButtonElement(const WebInputElement* element) {
|
| + if (!element)
|
| + return false;
|
| +
|
| + return element->formControlType() == ASCIIToUTF16("radio");
|
| +}
|
| +
|
| +bool IsAutofillableInputElement(const WebInputElement* element) {
|
| + return IsTextInput(element) || IsCheckboxElement(element) ||
|
| + IsRadioButtonElement(element);
|
| +}
|
| +
|
| const string16 GetFormIdentifier(const WebFormElement& form) {
|
| string16 identifier = form.name();
|
| if (identifier.empty())
|
| @@ -578,7 +603,8 @@ void ExtractAutofillableElements(
|
| // TODO(jhawkins): WebKit currently doesn't handle the autocomplete
|
| // attribute for select control elements, but it probably should.
|
| WebInputElement* input_element = toWebInputElement(&control_elements[i]);
|
| - if (IsTextInput(input_element) && !input_element->autoComplete())
|
| + if (IsAutofillableInputElement(input_element) &&
|
| + !input_element->autoComplete())
|
| continue;
|
| }
|
|
|
| @@ -610,11 +636,15 @@ void WebFormControlElementToFormField(const WebFormControlElement& element,
|
| return;
|
|
|
| const WebInputElement* input_element = toWebInputElement(&element);
|
| - if (IsTextInput(input_element)) {
|
| + if (IsAutofillableInputElement(input_element)) {
|
| field->max_length = input_element->maxLength();
|
| field->is_autofilled = input_element->isAutofilled();
|
| field->is_focusable = input_element->isFocusable();
|
| field->should_autocomplete = input_element->autoComplete();
|
| + if (IsRadioButtonElement(input_element) ||
|
| + IsCheckboxElement(input_element)) {
|
| + field->is_checkable = true;
|
| + }
|
| } else if (extract_mask & EXTRACT_OPTIONS) {
|
| // Set option strings on the field if available.
|
| DCHECK(IsSelectElement(element));
|
| @@ -628,7 +658,7 @@ void WebFormControlElementToFormField(const WebFormControlElement& element,
|
| return;
|
|
|
| string16 value;
|
| - if (IsTextInput(input_element)) {
|
| + if (IsAutofillableInputElement(input_element)) {
|
| value = input_element->value();
|
| } else {
|
| DCHECK(IsSelectElement(element));
|
| @@ -705,7 +735,8 @@ bool WebFormElementToFormData(
|
| continue;
|
|
|
| const WebInputElement* input_element = toWebInputElement(&control_element);
|
| - if (requirements & REQUIRE_AUTOCOMPLETE && IsTextInput(input_element) &&
|
| + if (requirements & REQUIRE_AUTOCOMPLETE &&
|
| + IsAutofillableInputElement(input_element) &&
|
| !input_element->autoComplete())
|
| continue;
|
|
|
| @@ -907,7 +938,7 @@ bool FormWithElementIsAutofilled(const WebInputElement& element) {
|
| &control_elements);
|
| for (size_t i = 0; i < control_elements.size(); ++i) {
|
| WebInputElement* input_element = toWebInputElement(&control_elements[i]);
|
| - if (!IsTextInput(input_element))
|
| + if (!IsAutofillableInputElement(input_element))
|
| continue;
|
|
|
| if (input_element->isAutofilled())
|
|
|