diff options
Diffstat (limited to 'chrome/renderer/autofill/form_manager.h')
-rw-r--r-- | chrome/renderer/autofill/form_manager.h | 118 |
1 files changed, 55 insertions, 63 deletions
diff --git a/chrome/renderer/autofill/form_manager.h b/chrome/renderer/autofill/form_manager.h index b32dcb5..cc8f570 100644 --- a/chrome/renderer/autofill/form_manager.h +++ b/chrome/renderer/autofill/form_manager.h @@ -7,6 +7,7 @@ #pragma once #include <map> +#include <set> #include <vector> #include "base/callback_old.h" @@ -23,6 +24,8 @@ struct FormField; namespace WebKit { class WebFormControlElement; class WebFrame; +class WebInputElement; +class WebSelectElement; } // namespace WebKit namespace autofill { @@ -61,86 +64,75 @@ class FormManager { ExtractMask extract_mask, 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. - // TODO(isherman): Refactor autofill_agent.cc not to require this method to be - // exposed. - 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. If - // |get_options| is true, the fields in |form will have select options filled - // out. Returns true if |form| is filled out; it's possible that |element| - // won't meet the requirements in |requirements|. This also returns false if - // there are no fields in |form|. - static bool WebFormElementToFormData(const WebKit::WebFormElement& element, - RequirementsMask requirements, - ExtractMask extract_mask, - webkit_glue::FormData* form); - - // Scans the DOM in |frame| extracting and storing forms. - // Returns a vector of the extracted forms. - void ExtractForms(const WebKit::WebFrame* frame, - std::vector<webkit_glue::FormData>* forms); + // Fills |form| with the FormData object corresponding to the |form_element|. + // If |field| is non-NULL, also fills |field| with the FormField object + // corresponding to the |form_control_element|. + // |extract_mask| controls what data is extracted. + // Returns true if |form| is filled out; it's possible that the |form_element| + // won't meet the |requirements|. Also returns false if there are no fields + // in the |form|. + static bool WebFormElementToFormData( + const WebKit::WebFormElement& form_element, + const WebKit::WebFormControlElement& form_control_element, + RequirementsMask requirements, + ExtractMask extract_mask, + webkit_glue::FormData* form, + webkit_glue::FormField* field); - // Finds the form that contains |element| and returns it in |form|. Returns - // false if the form is not found. - bool FindFormWithFormControlElement( + // Finds the form that contains |element| and returns it in |form|. Fills + // |field| with the |FormField| representation for element. + // Returns false if the form is not found. + static bool FindFormAndFieldForFormControlElement( const WebKit::WebFormControlElement& element, - webkit_glue::FormData* form); + webkit_glue::FormData* form, + webkit_glue::FormField* field); - // Fills the form represented by |form|. |node| is the input element that + // Fills the form represented by |form|. |element| is the input element that // initiated the auto-fill process. - void FillForm(const webkit_glue::FormData& form, const WebKit::WebNode& node); - - // Previews the form represented by |form|. |node| is the input element that - // initiated the preview process. - void PreviewForm(const webkit_glue::FormData& form, - const WebKit::WebNode &node); - - // For each field in the |form|, sets the field's placeholder text to the - // field's overall predicted type. Also sets the title to include the field's - // heuristic type, server type, and signature; as well as the form's signature - // and the experiment id for the server predictions. - bool ShowPredictions(const webkit_glue::FormDataPredictions& form); + static void FillForm(const webkit_glue::FormData& form, + const WebKit::WebInputElement& element); - // Clears the values of all input elements in the form that contains |node|. - // Returns false if the form is not found. - bool ClearFormWithNode(const WebKit::WebNode& node); + // Previews the form represented by |form|. |element| is the input element + // that initiated the preview process. + static void PreviewForm(const webkit_glue::FormData& form, + const WebKit::WebInputElement& element); // Clears the placeholder values and the auto-filled background for any fields // in the form containing |node| that have been previewed. Resets the // autofilled state of |node| to |was_autofilled|. Returns false if the form // is not found. - bool ClearPreviewedFormWithNode(const WebKit::WebNode& node, - bool was_autofilled); - - // Resets the forms for the specified |frame|. - void ResetFrame(const WebKit::WebFrame* frame); + static bool ClearPreviewedFormWithElement( + const WebKit::WebInputElement& element, + bool was_autofilled); // Returns true if |form| has any auto-filled fields. - bool FormWithNodeIsAutofilled(const WebKit::WebNode& node); + static bool FormWithElementIsAutofilled( + const WebKit::WebInputElement& element); - private: - // Stores the WebFormElement and the form control elements for a form. - // Original form values are stored so when we clear a form we can reset - // <select> elements to their original value. - struct FormElement; + // Scans the DOM in |frame| extracting and storing forms. + // Returns a vector of the extracted forms. + void ExtractForms(const WebKit::WebFrame& frame, + std::vector<webkit_glue::FormData>* forms); - // Type for cache of FormElement objects. - typedef ScopedVector<FormElement> FormElementList; + // Resets the forms for the specified |frame|. + void ResetFrame(const WebKit::WebFrame& frame); - // Finds the cached FormElement that contains |node|. - bool FindCachedFormElementWithNode(const WebKit::WebNode& node, - FormElement** form_element); + // Clears the values of all input elements in the form that contains + // |element|. Returns false if the form is not found. + bool ClearFormWithElement(const WebKit::WebInputElement& element); - // Uses the data in |form| to find the cached FormElement. - bool FindCachedFormElement(const webkit_glue::FormData& form, - FormElement** form_element); + // For each field in the |form|, sets the field's placeholder text to the + // field's overall predicted type. Also sets the title to include the field's + // heuristic type, server type, and signature; as well as the form's signature + // and the experiment id for the server predictions. + bool ShowPredictions(const webkit_glue::FormDataPredictions& form); + + private: + // The cached web frames. + std::set<const WebKit::WebFrame*> web_frames_; - // The cached FormElement objects. - FormElementList form_elements_; + // The cached initial values for <select> elements. + std::map<const WebKit::WebSelectElement, string16> initial_select_values_; DISALLOW_COPY_AND_ASSIGN(FormManager); }; |