OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_AUTOFILL_CONTENT_RENDERER_FORM_CACHE_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_FORM_CACHE_H_ |
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_FORM_CACHE_H_ | 6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_FORM_CACHE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "components/autofill/core/common/form_data.h" | |
13 | 14 |
14 namespace blink { | 15 namespace blink { |
15 class WebDocument; | 16 class WebDocument; |
16 class WebElement; | 17 class WebElement; |
17 class WebElementCollection; | 18 class WebElementCollection; |
18 class WebFormControlElement; | 19 class WebFormControlElement; |
19 class WebFrame; | 20 class WebFrame; |
20 class WebInputElement; | 21 class WebInputElement; |
21 class WebSelectElement; | 22 class WebSelectElement; |
22 } | 23 } |
23 | 24 |
24 namespace autofill { | 25 namespace autofill { |
25 | 26 |
26 struct FormData; | |
27 struct FormDataPredictions; | 27 struct FormDataPredictions; |
28 | 28 |
29 // Manages the forms in a RenderView. | 29 // Manages the forms in a single RenderFrame. |
30 class FormCache { | 30 class FormCache { |
31 public: | 31 public: |
32 FormCache(); | 32 FormCache(const blink::WebFrame& frame); |
vabr (Chromium)
2014/12/15 09:30:13
nit: explicit
Evan Stade
2014/12/15 18:41:34
Done.
| |
33 ~FormCache(); | 33 ~FormCache(); |
34 | 34 |
35 // Get all form control elements from |elements| that are not part of a form. | 35 // Get all form control elements from |elements| that are not part of a form. |
36 // If |fieldsets| is not NULL, also append the fieldsets encountered that are | 36 // If |fieldsets| is not NULL, also append the fieldsets encountered that are |
37 // not part of a form. | 37 // not part of a form. |
38 // Exposed for sharing with tests. | 38 // Exposed for sharing with tests. |
39 static std::vector<blink::WebFormControlElement> | 39 static std::vector<blink::WebFormControlElement> |
40 GetUnownedAutofillableFormFieldElements( | 40 GetUnownedAutofillableFormFieldElements( |
41 const blink::WebElementCollection& elements, | 41 const blink::WebElementCollection& elements, |
42 std::vector<blink::WebElement>* fieldsets); | 42 std::vector<blink::WebElement>* fieldsets); |
43 | 43 |
44 // Scans the DOM in |frame| extracting and storing forms that have not been | 44 // Scans the DOM in |frame_| extracting and storing forms that have not been |
45 // seen before. Returns the extracted forms. | 45 // seen before. Returns the extracted forms. |
46 std::vector<FormData> ExtractNewForms(const blink::WebFrame& frame); | 46 std::vector<FormData> ExtractNewForms(); |
47 | 47 |
48 // Resets the forms for the specified |frame|. | 48 // Resets the forms. |
49 void ResetFrame(const blink::WebFrame& frame); | 49 void Reset(); |
50 | 50 |
51 // Clears the values of all input elements in the form that contains | 51 // Clears the values of all input elements in the form that contains |
52 // |element|. Returns false if the form is not found. | 52 // |element|. Returns false if the form is not found. |
53 bool ClearFormWithElement(const blink::WebFormControlElement& element); | 53 bool ClearFormWithElement(const blink::WebFormControlElement& element); |
54 | 54 |
55 // For each field in the |form|, sets the field's placeholder text to the | 55 // For each field in the |form|, sets the field's placeholder text to the |
56 // field's overall predicted type. Also sets the title to include the field's | 56 // field's overall predicted type. Also sets the title to include the field's |
57 // heuristic type, server type, and signature; as well as the form's signature | 57 // heuristic type, server type, and signature; as well as the form's signature |
58 // and the experiment id for the server predictions. | 58 // and the experiment id for the server predictions. |
59 bool ShowPredictions(const FormDataPredictions& form); | 59 bool ShowPredictions(const FormDataPredictions& form); |
60 | 60 |
61 private: | 61 private: |
62 // Scans |control_elements| and returns the number of editable elements. | 62 // Scans |control_elements| and returns the number of editable elements. |
63 // Also remembers the initial <select> and <input> element states, and | 63 // Also remembers the initial <select> and <input> element states, and |
64 // logs warning messages for deprecated attribute if | 64 // logs warning messages for deprecated attribute if |
65 // |log_deprecation_messages| is set. | 65 // |log_deprecation_messages| is set. |
66 size_t ScanFormControlElements( | 66 size_t ScanFormControlElements( |
67 const std::vector<blink::WebFormControlElement>& control_elements, | 67 const std::vector<blink::WebFormControlElement>& control_elements, |
68 bool log_deprecation_messages); | 68 bool log_deprecation_messages); |
69 | 69 |
70 // The cached web frames and their corresponding synthetic FormData. | 70 // The frame this FormCache is associated with. |
71 const blink::WebFrame& frame_; | |
72 | |
73 // The cached forms. Used to prevent re-extraction of forms. | |
74 std::set<FormData> parsed_forms_; | |
75 | |
71 // The synthetic FormData is for all the fieldsets in the document without a | 76 // The synthetic FormData is for all the fieldsets in the document without a |
72 // form owner. | 77 // form owner. |
73 std::map<blink::WebDocument, FormData> documents_to_synthetic_form_map_; | 78 FormData synthetic_form_; |
74 | |
75 // The cached forms per frame. Used to prevent re-extraction of forms. | |
76 std::map<const blink::WebFrame*, std::set<FormData> > parsed_forms_; | |
77 | 79 |
78 // The cached initial values for <select> elements. | 80 // The cached initial values for <select> elements. |
79 std::map<const blink::WebSelectElement, base::string16> | 81 std::map<const blink::WebSelectElement, base::string16> |
80 initial_select_values_; | 82 initial_select_values_; |
81 | 83 |
82 // The cached initial values for checkable <input> elements. | 84 // The cached initial values for checkable <input> elements. |
83 std::map<const blink::WebInputElement, bool> initial_checked_state_; | 85 std::map<const blink::WebInputElement, bool> initial_checked_state_; |
84 | 86 |
85 DISALLOW_COPY_AND_ASSIGN(FormCache); | 87 DISALLOW_COPY_AND_ASSIGN(FormCache); |
86 }; | 88 }; |
87 | 89 |
88 } // namespace autofill | 90 } // namespace autofill |
89 | 91 |
90 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_FORM_CACHE_H_ | 92 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_FORM_CACHE_H_ |
OLD | NEW |