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..0502ae3a46cd652bf89447539864932f6c7777c0 100644 |
--- a/chrome/renderer/autofill/form_autofill_util.cc |
+++ b/chrome/renderer/autofill/form_autofill_util.cc |
@@ -44,6 +44,9 @@ namespace { |
using autofill::ExtractAutofillableElements; |
using autofill::IsTextInput; |
using autofill::IsSelectElement; |
+using autofill::REQUIRE_AUTOCOMPLETE; |
+using autofill::REQUIRE_FOCUSABLE; |
+using autofill::RequirementsMask; |
Ilya Sherman
2012/11/30 04:04:54
Do these lines actually compile? I didn't think t
Dan Beam
2012/11/30 04:13:33
Yes, at least with g++.
|
// The maximum length allowed for form data. |
const size_t kMaxDataLength = 1024; |
@@ -413,19 +416,19 @@ void GetOptionStringsFromElement(const WebSelectElement& select_element, |
} |
// The callback type used by |ForEachMatchingFormField()|. |
-typedef void (*Callback)(WebKit::WebFormControlElement*, |
- const FormFieldData*, |
- bool); |
+typedef void (*Callback)(const FormFieldData&, |
+ bool, /* is_initiating_element */ |
+ WebKit::WebFormControlElement*); |
// For each autofillable field in |data| that matches a field in the |form|, |
// the |callback| is invoked with the corresponding |form| field data. |
void ForEachMatchingFormField(const WebFormElement& form_element, |
const WebElement& initiating_element, |
const FormData& data, |
+ RequirementsMask requirements, |
Callback callback) { |
std::vector<WebFormControlElement> control_elements; |
- ExtractAutofillableElements(form_element, autofill::REQUIRE_AUTOCOMPLETE, |
- &control_elements); |
+ ExtractAutofillableElements(form_element, requirements, &control_elements); |
if (control_elements.size() != data.fields.size()) { |
// This case should be reachable only for pathological websites, which add |
@@ -466,20 +469,20 @@ void ForEachMatchingFormField(const WebFormElement& form_element, |
} |
if (!element->isEnabled() || element->isReadOnly() || |
- !element->isFocusable()) |
+ (requirements & REQUIRE_FOCUSABLE && !element->isFocusable())) |
continue; |
- callback(element, &data.fields[i], is_initiating_element); |
+ callback(data.fields[i], is_initiating_element, element); |
} |
} |
// Sets the |field|'s value to the value in |data|. |
// Also sets the "autofilled" attribute, causing the background to be yellow. |
-void FillFormField(WebKit::WebFormControlElement* field, |
- const FormFieldData* data, |
- bool is_initiating_node) { |
+void FillFormField(const FormFieldData& data, |
+ bool is_initiating_node, |
+ WebKit::WebFormControlElement* field) { |
// Nothing to fill. |
- if (data->value.empty()) |
+ if (data.value.empty()) |
return; |
WebInputElement* input_element = toWebInputElement(field); |
@@ -487,7 +490,7 @@ void FillFormField(WebKit::WebFormControlElement* field, |
// If the maxlength attribute contains a negative value, maxLength() |
// returns the default maxlength value. |
input_element->setValue( |
- data->value.substr(0, input_element->maxLength()), true); |
+ data.value.substr(0, input_element->maxLength()), true); |
input_element->setAutofilled(true); |
if (is_initiating_node) { |
int length = input_element->value().length(); |
@@ -498,8 +501,8 @@ void FillFormField(WebKit::WebFormControlElement* field, |
} else { |
DCHECK(IsSelectElement(*field)); |
WebSelectElement select_element = field->to<WebSelectElement>(); |
- if (select_element.value() != data->value) { |
- select_element.setValue(data->value); |
+ if (select_element.value() != data.value) { |
+ select_element.setValue(data.value); |
select_element.dispatchFormControlChangeEvent(); |
} |
} |
@@ -507,11 +510,11 @@ void FillFormField(WebKit::WebFormControlElement* field, |
// Sets the |field|'s "suggested" (non JS visible) value to the value in |data|. |
// Also sets the "autofilled" attribute, causing the background to be yellow. |
-void PreviewFormField(WebKit::WebFormControlElement* field, |
- const FormFieldData* data, |
- bool is_initiating_node) { |
+void PreviewFormField(const FormFieldData& data, |
+ bool is_initiating_node, |
+ WebKit::WebFormControlElement* field) { |
// Nothing to preview. |
- if (data->value.empty()) |
+ if (data.value.empty()) |
return; |
// Only preview input fields. |
@@ -522,7 +525,7 @@ void PreviewFormField(WebKit::WebFormControlElement* field, |
// If the maxlength attribute contains a negative value, maxLength() |
// returns the default maxlength value. |
input_element->setSuggestedValue( |
- data->value.substr(0, input_element->maxLength())); |
+ data.value.substr(0, input_element->maxLength())); |
input_element->setAutofilled(true); |
if (is_initiating_node) { |
// Select the part of the text that the user didn't type. |
@@ -817,9 +820,24 @@ void FillForm(const FormData& form, const WebInputElement& element) { |
if (form_element.isNull()) |
return; |
+ RequirementsMask requirements = |
+ static_cast<RequirementsMask>(REQUIRE_AUTOCOMPLETE | REQUIRE_FOCUSABLE); |
ForEachMatchingFormField(form_element, |
element, |
form, |
+ requirements, |
+ &FillFormField); |
+} |
+ |
+void FillFormAndNonFocusableElements(const FormData& form_data, |
+ const WebFormElement& form_element) { |
+ if (form_element.isNull()) |
+ return; |
+ |
+ ForEachMatchingFormField(form_element, |
+ WebInputElement(), |
+ form_data, |
+ REQUIRE_AUTOCOMPLETE, |
&FillFormField); |
} |
@@ -828,9 +846,12 @@ void PreviewForm(const FormData& form, const WebInputElement& element) { |
if (form_element.isNull()) |
return; |
+ RequirementsMask requirements = |
+ static_cast<RequirementsMask>(REQUIRE_AUTOCOMPLETE | REQUIRE_FOCUSABLE); |
ForEachMatchingFormField(form_element, |
element, |
form, |
+ requirements, |
&PreviewFormField); |
} |