summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/renderer/form_manager.cc32
-rw-r--r--chrome/renderer/form_manager.h8
-rw-r--r--chrome/renderer/render_view.cc6
3 files changed, 27 insertions, 19 deletions
diff --git a/chrome/renderer/form_manager.cc b/chrome/renderer/form_manager.cc
index 0d202ab..3c1fdc2 100644
--- a/chrome/renderer/form_manager.cc
+++ b/chrome/renderer/form_manager.cc
@@ -99,6 +99,22 @@ void FormManager::WebFormControlElementToFormField(
}
// static
+string16 FormManager::LabelForElement(const WebFormControlElement& element) {
+ WebNodeList labels = element.document().getElementsByTagName("label");
+ for (unsigned i = 0; i < labels.length(); ++i) {
+ WebElement e = labels.item(i).toElement<WebElement>();
+ if (e.hasTagName("label")) {
+ WebLabelElement label = e.toElement<WebLabelElement>();
+ if (label.correspondingControl() == element)
+ return GetChildText(label);
+ }
+ }
+
+ // Infer the label from context if not found in label element.
+ return FormManager::InferLabelForElement(element);
+}
+
+// static
bool FormManager::WebFormElementToFormData(const WebFormElement& element,
RequirementsMask requirements,
bool get_values,
@@ -472,22 +488,6 @@ void FormManager::ResetFrame(const WebFrame* frame) {
}
// static
-string16 FormManager::LabelForElement(const WebFormControlElement& element) {
- WebNodeList labels = element.document().getElementsByTagName("label");
- for (unsigned i = 0; i < labels.length(); ++i) {
- WebElement e = labels.item(i).toElement<WebElement>();
- if (e.hasTagName("label")) {
- WebLabelElement label = e.toElement<WebLabelElement>();
- if (label.correspondingControl() == element)
- return GetChildText(label);
- }
- }
-
- // Infer the label from context if not found in label element.
- return FormManager::InferLabelForElement(element);
-}
-
-// static
string16 FormManager::InferLabelForElement(
const WebFormControlElement& element) {
string16 inferred_label;
diff --git a/chrome/renderer/form_manager.h b/chrome/renderer/form_manager.h
index c35da84..c35d780 100644
--- a/chrome/renderer/form_manager.h
+++ b/chrome/renderer/form_manager.h
@@ -41,6 +41,11 @@ class FormManager {
bool get_value,
webkit_glue::FormField* field);
+ // Returns the corresponding label for |element|. WARNING: This method can
+ // potentially be very slow. Do not use during any code paths where the page
+ // is loading.
+ static string16 LabelForElement(const WebKit::WebFormControlElement& element);
+
// Fills out a FormData object from a given WebFormElement. If |get_values|
// is true, the fields in |form| will have the values filled out. Returns
// true if |form| is filled out; it's possible that |element| won't meet the
@@ -114,9 +119,6 @@ class FormManager {
// Resets the forms for the specified |frame|.
void ResetFrame(const WebKit::WebFrame* frame);
- // Returns the corresponding label for |element|.
- static string16 LabelForElement(const WebKit::WebFormControlElement& element);
-
// Infers corresponding label for |element| from surrounding context in the
// DOM. Contents of preceeding <p> tag or preceeding text element found in
// the form.
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 39e6ec6..d7f350a 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -1973,6 +1973,12 @@ void RenderView::queryAutofillSuggestions(const WebNode& node,
webkit_glue::FormField field;
FormManager::WebFormControlElementToFormField(element, true, &field);
+ // WebFormControlElementToFormField does not scrape the DOM for the field
+ // label, so find the label here.
+ // TODO(jhawkins): Add form and field identities so we can use the cached form
+ // data in FormManager.
+ field.set_label(FormManager::LabelForElement(element));
+
Send(new ViewHostMsg_QueryFormFieldAutofill(
routing_id_, autofill_query_id_, field));
}