| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_RENDERER_AUTOFILL_FORM_AUTOFILL_UTIL_H_ | |
| 6 #define CHROME_RENDERER_AUTOFILL_FORM_AUTOFILL_UTIL_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/string16.h" | |
| 11 | |
| 12 struct FormData; | |
| 13 struct FormFieldData; | |
| 14 | |
| 15 namespace WebKit { | |
| 16 class WebDocument; | |
| 17 class WebFormElement; | |
| 18 class WebFormControlElement; | |
| 19 class WebInputElement; | |
| 20 } | |
| 21 | |
| 22 namespace autofill { | |
| 23 | |
| 24 struct WebElementDescriptor; | |
| 25 | |
| 26 // A bit field mask for form or form element requirements. | |
| 27 enum RequirementsMask { | |
| 28 REQUIRE_NONE = 0, // No requirements. | |
| 29 REQUIRE_AUTOCOMPLETE = 1, // Require that autocomplete != off. | |
| 30 }; | |
| 31 | |
| 32 // A bit field mask to extract data from WebFormControlElement. | |
| 33 enum ExtractMask { | |
| 34 EXTRACT_NONE = 0, | |
| 35 EXTRACT_VALUE = 1 << 0, // Extract value from WebFormControlElement. | |
| 36 EXTRACT_OPTION_TEXT = 1 << 1, // Extract option text from | |
| 37 // WebFormSelectElement. Only valid when | |
| 38 // |EXTRACT_VALUE| is set. | |
| 39 // This is used for form submission where | |
| 40 // human readable value is captured. | |
| 41 EXTRACT_OPTIONS = 1 << 2, // Extract options from | |
| 42 // WebFormControlElement. | |
| 43 }; | |
| 44 | |
| 45 // The maximum number of form fields we are willing to parse, due to | |
| 46 // computational costs. Several examples of forms with lots of fields that are | |
| 47 // not relevant to Autofill: (1) the Netflix queue; (2) the Amazon wishlist; | |
| 48 // (3) router configuration pages; and (4) other configuration pages, e.g. for | |
| 49 // Google code project settings. | |
| 50 extern const size_t kMaxParseableFields; | |
| 51 | |
| 52 // Returns true if |element| is a text input element. | |
| 53 bool IsTextInput(const WebKit::WebInputElement* element); | |
| 54 | |
| 55 // Returns true if |element| is a select element. | |
| 56 bool IsSelectElement(const WebKit::WebFormControlElement& element); | |
| 57 | |
| 58 // Returns true if |element| is a checkbox or a radio button element. | |
| 59 bool IsCheckableElement(const WebKit::WebInputElement* element); | |
| 60 | |
| 61 // Returns true if |element| is one of the input element types that can be | |
| 62 // autofilled. {Text, Radiobutton, Checkbox}. | |
| 63 bool IsAutofillableInputElement(const WebKit::WebInputElement* element); | |
| 64 | |
| 65 // Returns the form's |name| attribute if non-empty; otherwise the form's |id| | |
| 66 // attribute. | |
| 67 const string16 GetFormIdentifier(const WebKit::WebFormElement& form); | |
| 68 | |
| 69 // Returns true if the element specified by |click_element| was successfully | |
| 70 // clicked. | |
| 71 bool ClickElement(const WebKit::WebDocument& document, | |
| 72 const WebElementDescriptor& element_descriptor); | |
| 73 | |
| 74 // Fills |autofillable_elements| with all the auto-fillable form control | |
| 75 // elements in |form_element|. | |
| 76 void ExtractAutofillableElements( | |
| 77 const WebKit::WebFormElement& form_element, | |
| 78 RequirementsMask requirements, | |
| 79 std::vector<WebKit::WebFormControlElement>* autofillable_elements); | |
| 80 | |
| 81 // Fills out a FormField object from a given WebFormControlElement. | |
| 82 // |extract_mask|: See the enum ExtractMask above for details. | |
| 83 void WebFormControlElementToFormField( | |
| 84 const WebKit::WebFormControlElement& element, | |
| 85 ExtractMask extract_mask, | |
| 86 FormFieldData* field); | |
| 87 | |
| 88 // Fills |form| with the FormData object corresponding to the |form_element|. | |
| 89 // If |field| is non-NULL, also fills |field| with the FormField object | |
| 90 // corresponding to the |form_control_element|. | |
| 91 // |extract_mask| controls what data is extracted. | |
| 92 // Returns true if |form| is filled out; it's possible that the |form_element| | |
| 93 // won't meet the |requirements|. Also returns false if there are no fields or | |
| 94 // too many fields in the |form|. | |
| 95 bool WebFormElementToFormData( | |
| 96 const WebKit::WebFormElement& form_element, | |
| 97 const WebKit::WebFormControlElement& form_control_element, | |
| 98 RequirementsMask requirements, | |
| 99 ExtractMask extract_mask, | |
| 100 FormData* form, | |
| 101 FormFieldData* field); | |
| 102 | |
| 103 // Finds the form that contains |element| and returns it in |form|. Fills | |
| 104 // |field| with the |FormField| representation for element. | |
| 105 // Returns false if the form is not found or cannot be serialized. | |
| 106 bool FindFormAndFieldForInputElement(const WebKit::WebInputElement& element, | |
| 107 FormData* form, | |
| 108 FormFieldData* field, | |
| 109 RequirementsMask requirements); | |
| 110 | |
| 111 // Fills the form represented by |form|. |element| is the input element that | |
| 112 // initiated the auto-fill process. | |
| 113 void FillForm(const FormData& form, | |
| 114 const WebKit::WebInputElement& element); | |
| 115 | |
| 116 // Fills focusable and non-focusable form control elements within |form_element| | |
| 117 // with field data from |form_data|. | |
| 118 void FillFormIncludingNonFocusableElements( | |
| 119 const FormData& form_data, | |
| 120 const WebKit::WebFormElement& form_element); | |
| 121 | |
| 122 // Previews the form represented by |form|. |element| is the input element that | |
| 123 // initiated the preview process. | |
| 124 void PreviewForm(const FormData& form, | |
| 125 const WebKit::WebInputElement& element); | |
| 126 | |
| 127 // Clears the placeholder values and the auto-filled background for any fields | |
| 128 // in the form containing |node| that have been previewed. Resets the | |
| 129 // autofilled state of |node| to |was_autofilled|. Returns false if the form is | |
| 130 // not found. | |
| 131 bool ClearPreviewedFormWithElement(const WebKit::WebInputElement& element, | |
| 132 bool was_autofilled); | |
| 133 | |
| 134 // Returns true if |form| has any auto-filled fields. | |
| 135 bool FormWithElementIsAutofilled(const WebKit::WebInputElement& element); | |
| 136 | |
| 137 } // namespace autofill | |
| 138 | |
| 139 #endif // CHROME_RENDERER_AUTOFILL_FORM_AUTOFILL_UTIL_H_ | |
| OLD | NEW |