| 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 3da2f9869cd77763a64524f4d7aa7753684c9432..a7b698a0b29ed1705a046a07d6457a664e6429e8 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
|
| @@ -458,10 +461,11 @@ void ForEachMatchingFormField(const WebFormElement& form_element,
|
| bool is_initiating_element = (*element == initiating_element);
|
|
|
| const WebInputElement* input_element = toWebInputElement(element);
|
| - if (IsTextInput(input_element)) {
|
| + if (IsAutofillableInputElement(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())
|
| + if (!is_initiating_element && IsTextInput(input_element) &&
|
| + !input_element->value().isEmpty())
|
| continue;
|
| }
|
|
|
| @@ -495,13 +499,16 @@ void FillFormField(WebKit::WebFormControlElement* field,
|
| // 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);
|
| }
|
| }
|
|
|
| @@ -516,6 +523,8 @@ void PreviewFormField(WebKit::WebFormControlElement* field,
|
|
|
| // Only preview input fields.
|
| WebInputElement* input_element = toWebInputElement(field);
|
| + // Don't preview checkboxes and radio buttons, as there is no provision for
|
| + // setSuggestedCheckedValue in WebInputElement.
|
| if (!IsTextInput(input_element))
|
| return;
|
|
|
| @@ -550,6 +559,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())
|
| @@ -577,7 +605,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;
|
| }
|
|
|
| @@ -609,11 +638,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));
|
| @@ -627,7 +660,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));
|
| @@ -704,7 +737,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;
|
|
|
| @@ -846,7 +880,7 @@ bool ClearPreviewedFormWithElement(const WebInputElement& element,
|
| for (size_t i = 0; i < control_elements.size(); ++i) {
|
| // Only text input elements can be previewed.
|
| WebInputElement* input_element = toWebInputElement(&control_elements[i]);
|
| - if (!IsTextInput(input_element))
|
| + if (!IsAutofillableInputElement(input_element))
|
| continue;
|
|
|
| // If the input element is not auto-filled, we did not preview it, so there
|
| @@ -892,7 +926,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())
|
|
|