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..04a4ce6ce5646ebcf78a6a1f3c5ea9673a98acbe 100644 |
--- a/chrome/renderer/autofill/form_autofill_util.cc |
+++ b/chrome/renderer/autofill/form_autofill_util.cc |
@@ -42,8 +42,10 @@ using WebKit::WebVector; |
namespace { |
using autofill::ExtractAutofillableElements; |
-using autofill::IsTextInput; |
+using autofill::IsAutofillableInputElement; |
+using autofill::IsCheckableElement; |
using autofill::IsSelectElement; |
+using autofill::IsTextInput; |
// The maximum length allowed for form data. |
const size_t kMaxDataLength = 1024; |
@@ -66,7 +68,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,13 +460,12 @@ void ForEachMatchingFormField(const WebFormElement& form_element, |
bool is_initiating_element = (*element == initiating_element); |
+ // Only autofill empty fields and the field that initiated the filling, |
+ // i.e. the field the user is currently editing and interacting with. |
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; |
- } |
+ if (!is_initiating_element && IsTextInput(input_element) && |
+ !input_element->value().isEmpty()) |
+ continue; |
if (!element->isEnabled() || element->isReadOnly() || |
(only_focusable_elements && !element->isFocusable())) |
@@ -496,13 +497,15 @@ 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(IsCheckableElement(input_element)); |
+ input_element->setChecked(data.is_checked, true); |
} |
} |
@@ -515,7 +518,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 +555,18 @@ bool IsSelectElement(const WebFormControlElement& element) { |
return element.formControlType() == ASCIIToUTF16("select-one"); |
} |
+bool IsCheckableElement(const WebInputElement* element) { |
+ if (!element) |
+ return false; |
+ |
+ return element->formControlType() == ASCIIToUTF16("checkbox") || |
Albert Bodenhamer
2013/01/08 17:12:57
There was some evidence that this function was the
Evan Stade
2013/01/08 21:18:55
ASCIIToUTF16 is cheap (it's just a copy, unlike UT
|
+ element->formControlType() == ASCIIToUTF16("radio"); |
+} |
+ |
+bool IsAutofillableInputElement(const WebInputElement* element) { |
+ return IsTextInput(element) || IsCheckableElement(element); |
+} |
+ |
const string16 GetFormIdentifier(const WebFormElement& form) { |
string16 identifier = form.name(); |
if (identifier.empty()) |
@@ -578,7 +594,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 +627,14 @@ void WebFormControlElementToFormField(const WebFormControlElement& element, |
return; |
const WebInputElement* input_element = toWebInputElement(&element); |
- if (IsTextInput(input_element)) { |
- field->max_length = input_element->maxLength(); |
+ if (IsAutofillableInputElement(input_element)) { |
+ if (IsTextInput(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(); |
+ field->is_checkable = IsCheckableElement(input_element); |
} else if (extract_mask & EXTRACT_OPTIONS) { |
// Set option strings on the field if available. |
DCHECK(IsSelectElement(element)); |
@@ -628,7 +648,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 +725,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 +928,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()) |
@@ -918,3 +939,4 @@ bool FormWithElementIsAutofilled(const WebInputElement& element) { |
} |
} // namespace autofill |
+ |