Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / components / autofill / content / renderer / form_cache.h
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_AUTOFILL_CONTENT_RENDERER_FORM_CACHE_H_
6 #define COMPONENTS_AUTOFILL_CONTENT_RENDERER_FORM_CACHE_H_
7
8 #include <map>
9 #include <set>
10 #include <vector>
11
12 #include "base/strings/string16.h"
13
14 namespace blink {
15 class WebDocument;
16 class WebFormControlElement;
17 class WebFrame;
18 class WebInputElement;
19 class WebSelectElement;
20 }
21
22 namespace autofill {
23
24 struct FormData;
25 struct FormDataPredictions;
26
27 // Manages the forms in a RenderView.
28 class FormCache {
29  public:
30   FormCache();
31   ~FormCache();
32
33   // Scans the DOM in |frame| extracting and storing forms that have not been
34   // seen before. Returns the extracted forms.
35   std::vector<FormData> ExtractNewForms(const blink::WebFrame& frame);
36
37   // Resets the forms for the specified |frame|.
38   void ResetFrame(const blink::WebFrame& frame);
39
40   // Clears the values of all input elements in the form that contains
41   // |element|.  Returns false if the form is not found.
42   bool ClearFormWithElement(const blink::WebFormControlElement& element);
43
44   // For each field in the |form|, sets the field's placeholder text to the
45   // field's overall predicted type.  Also sets the title to include the field's
46   // heuristic type, server type, and signature; as well as the form's signature
47   // and the experiment id for the server predictions.
48   bool ShowPredictions(const FormDataPredictions& form);
49
50  private:
51   // Scans |control_elements| and returns the number of editable elements.
52   // Also remembers the initial <select> and <input> element states, and
53   // logs warning messages for deprecated attribute if
54   // |log_deprecation_messages| is set.
55   size_t ScanFormControlElements(
56       const std::vector<blink::WebFormControlElement>& control_elements,
57       bool log_deprecation_messages);
58
59   // The cached web frames.
60   std::set<blink::WebDocument> web_documents_;
61
62   // The cached forms per frame. Used to prevent re-extraction of forms.
63   std::map<const blink::WebFrame*, std::set<FormData> > parsed_forms_;
64
65   // The cached initial values for <select> elements.
66   std::map<const blink::WebSelectElement, base::string16>
67       initial_select_values_;
68
69   // The cached initial values for checkable <input> elements.
70   std::map<const blink::WebInputElement, bool> initial_checked_state_;
71
72   DISALLOW_COPY_AND_ASSIGN(FormCache);
73 };
74
75 }  // namespace autofill
76
77 #endif  // COMPONENTS_AUTOFILL_CONTENT_RENDERER_FORM_CACHE_H_