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 explicit FormCache(const blink::WebFrame& frame); |
33 ~FormCache(); | 33 ~FormCache(); |
34 | 34 |
35 // Scans the DOM in |frame| extracting and storing forms that have not been | 35 // Scans the DOM in |frame_| extracting and storing forms that have not been |
36 // seen before. Returns the extracted forms. | 36 // seen before. Returns the extracted forms. |
37 std::vector<FormData> ExtractNewForms(const blink::WebFrame& frame); | 37 std::vector<FormData> ExtractNewForms(); |
38 | 38 |
39 // Resets the forms for the specified |frame|. | 39 // Resets the forms. |
40 void ResetFrame(const blink::WebFrame& frame); | 40 void Reset(); |
41 | 41 |
42 // Clears the values of all input elements in the form that contains | 42 // Clears the values of all input elements in the form that contains |
43 // |element|. Returns false if the form is not found. | 43 // |element|. Returns false if the form is not found. |
44 bool ClearFormWithElement(const blink::WebFormControlElement& element); | 44 bool ClearFormWithElement(const blink::WebFormControlElement& element); |
45 | 45 |
46 // For each field in the |form|, sets the field's placeholder text to the | 46 // For each field in the |form|, sets the field's placeholder text to the |
47 // field's overall predicted type. Also sets the title to include the field's | 47 // field's overall predicted type. Also sets the title to include the field's |
48 // heuristic type, server type, and signature; as well as the form's signature | 48 // heuristic type, server type, and signature; as well as the form's signature |
49 // and the experiment id for the server predictions. | 49 // and the experiment id for the server predictions. |
50 bool ShowPredictions(const FormDataPredictions& form); | 50 bool ShowPredictions(const FormDataPredictions& form); |
51 | 51 |
52 private: | 52 private: |
53 // Scans |control_elements| and returns the number of editable elements. | 53 // Scans |control_elements| and returns the number of editable elements. |
54 // Also remembers the initial <select> and <input> element states, and | 54 // Also remembers the initial <select> and <input> element states, and |
55 // logs warning messages for deprecated attribute if | 55 // logs warning messages for deprecated attribute if |
56 // |log_deprecation_messages| is set. | 56 // |log_deprecation_messages| is set. |
57 size_t ScanFormControlElements( | 57 size_t ScanFormControlElements( |
58 const std::vector<blink::WebFormControlElement>& control_elements, | 58 const std::vector<blink::WebFormControlElement>& control_elements, |
59 bool log_deprecation_messages); | 59 bool log_deprecation_messages); |
60 | 60 |
61 // The cached web frames and their corresponding synthetic FormData. | 61 // The frame this FormCache is associated with. |
| 62 const blink::WebFrame& frame_; |
| 63 |
| 64 // The cached forms. Used to prevent re-extraction of forms. |
| 65 std::set<FormData> parsed_forms_; |
| 66 |
62 // The synthetic FormData is for all the fieldsets in the document without a | 67 // The synthetic FormData is for all the fieldsets in the document without a |
63 // form owner. | 68 // form owner. |
64 std::map<blink::WebDocument, FormData> documents_to_synthetic_form_map_; | 69 FormData synthetic_form_; |
65 | |
66 // The cached forms per frame. Used to prevent re-extraction of forms. | |
67 std::map<const blink::WebFrame*, std::set<FormData> > parsed_forms_; | |
68 | 70 |
69 // The cached initial values for <select> elements. | 71 // The cached initial values for <select> elements. |
70 std::map<const blink::WebSelectElement, base::string16> | 72 std::map<const blink::WebSelectElement, base::string16> |
71 initial_select_values_; | 73 initial_select_values_; |
72 | 74 |
73 // The cached initial values for checkable <input> elements. | 75 // The cached initial values for checkable <input> elements. |
74 std::map<const blink::WebInputElement, bool> initial_checked_state_; | 76 std::map<const blink::WebInputElement, bool> initial_checked_state_; |
75 | 77 |
76 DISALLOW_COPY_AND_ASSIGN(FormCache); | 78 DISALLOW_COPY_AND_ASSIGN(FormCache); |
77 }; | 79 }; |
78 | 80 |
79 } // namespace autofill | 81 } // namespace autofill |
80 | 82 |
81 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_FORM_CACHE_H_ | 83 #endif // COMPONENTS_AUTOFILL_CONTENT_RENDERER_FORM_CACHE_H_ |
OLD | NEW |