Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_RENDERER_FORM_MANAGER_H_ | 5 #ifndef CHROME_RENDERER_FORM_MANAGER_H_ |
| 6 #define CHROME_RENDERER_FORM_MANAGER_H_ | 6 #define CHROME_RENDERER_FORM_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/callback.h" | |
| 11 #include "base/string16.h" | 12 #include "base/string16.h" |
| 12 #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" | 13 #include "third_party/WebKit/WebKit/chromium/public/WebFormElement.h" |
| 13 | 14 |
| 14 namespace webkit_glue { | 15 namespace webkit_glue { |
| 15 struct FormData; | 16 struct FormData; |
| 16 class FormField; | 17 class FormField; |
| 17 } // namespace webkit_glue | 18 } // namespace webkit_glue |
| 18 | 19 |
| 19 namespace WebKit { | 20 namespace WebKit { |
| 20 class WebFormControlElement; | 21 class WebFormControlElement; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 struct FormElement { | 105 struct FormElement { |
| 105 WebKit::WebFormElement form_element; | 106 WebKit::WebFormElement form_element; |
| 106 std::vector<WebKit::WebFormControlElement> control_elements; | 107 std::vector<WebKit::WebFormControlElement> control_elements; |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 // A map of vectors of FormElements keyed by the WebFrame containing each | 110 // A map of vectors of FormElements keyed by the WebFrame containing each |
| 110 // form. | 111 // form. |
| 111 typedef std::map<const WebKit::WebFrame*, std::vector<FormElement*> > | 112 typedef std::map<const WebKit::WebFrame*, std::vector<FormElement*> > |
| 112 WebFrameFormElementMap; | 113 WebFrameFormElementMap; |
| 113 | 114 |
| 115 // The callback type used by ForEachMatchingFormField(). | |
| 116 typedef Callback2<WebKit::WebFormControlElement*, | |
| 117 const webkit_glue::FormField*>::Type Callback; | |
| 118 | |
| 114 // Converts a FormElement to FormData storage. Returns false if the form does | 119 // Converts a FormElement to FormData storage. Returns false if the form does |
| 115 // not meet all the requirements in the requirements mask. | 120 // not meet all the requirements in the requirements mask. |
| 116 // TODO(jhawkins): Modify FormElement so we don't need |frame|. | 121 // TODO(jhawkins): Modify FormElement so we don't need |frame|. |
| 117 static bool FormElementToFormData(const WebKit::WebFrame* frame, | 122 static bool FormElementToFormData(const WebKit::WebFrame* frame, |
| 118 const FormElement* form_element, | 123 const FormElement* form_element, |
| 119 RequirementsMask requirements, | 124 RequirementsMask requirements, |
| 120 webkit_glue::FormData* form); | 125 webkit_glue::FormData* form); |
| 121 | 126 |
| 122 // Infers corresponding label for |element| from surrounding context in the | 127 // Infers corresponding label for |element| from surrounding context in the |
| 123 // DOM. Contents of preceeding <p> tag or preceeding text element found in | 128 // DOM. Contents of preceding <p> tag or preceding text element found in |
| 124 // the form. | 129 // the form. |
| 125 static string16 InferLabelForElement( | 130 static string16 InferLabelForElement( |
| 126 const WebKit::WebFormControlElement& element); | 131 const WebKit::WebFormControlElement& element); |
| 127 | 132 |
| 133 // Uses the data in |form| to find the cached FormElement. | |
| 134 bool FindCachedFormElement(const webkit_glue::FormData& form, | |
| 135 FormElement** form_element); | |
| 136 | |
| 137 // For each field in |form| that matches the corresponding field in the cached | |
| 138 // FormElement, |callback| is called with the actual WebFormControlElement and | |
| 139 // the FormField data from |form|. This method owns |callback|. | |
| 140 void ForEachMatchingFormField(FormElement* form, | |
| 141 const webkit_glue::FormData& data, | |
| 142 Callback* callback); | |
|
dhollowa
2010/05/28 02:07:07
Curious, why the need to parameterize the callback
James Hawkins
2010/05/28 02:17:27
You seem to have forgotten the CL this code came f
| |
| 143 | |
| 144 // A ForEachMatchingFormField() callback that sets |field|'s value using the | |
| 145 // value in |data|. | |
| 146 void FillFormField(WebKit::WebFormControlElement* field, | |
| 147 const webkit_glue::FormField* data); | |
| 148 | |
| 128 // The map of form elements. | 149 // The map of form elements. |
| 129 WebFrameFormElementMap form_elements_map_; | 150 WebFrameFormElementMap form_elements_map_; |
| 130 | 151 |
| 131 DISALLOW_COPY_AND_ASSIGN(FormManager); | 152 DISALLOW_COPY_AND_ASSIGN(FormManager); |
| 132 }; | 153 }; |
| 133 | 154 |
| 134 #endif // CHROME_RENDERER_FORM_MANAGER_H_ | 155 #endif // CHROME_RENDERER_FORM_MANAGER_H_ |
| OLD | NEW |