autofill_field.h revision 7d214dfa174224b459660971e5b5cce2e06be02a
1// Copyright (c) 2010 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_BROWSER_AUTOFILL_AUTOFILL_FIELD_H_
6#define CHROME_BROWSER_AUTOFILL_AUTOFILL_FIELD_H_
7
8#include <string>
9
10#include "base/string16.h"
11#include "chrome/browser/autofill/field_types.h"
12#ifdef ANDROID
13#include "WebCoreSupport/autofill/FormFieldAndroid.h"
14#else
15#include "webkit/glue/form_field.h"
16#endif
17
18class AutoFillField : public webkit_glue::FormField {
19 public:
20  AutoFillField();
21  AutoFillField(const webkit_glue::FormField& field,
22                const string16& unique_name);
23
24  const string16& unique_name() const { return unique_name_; }
25
26  AutoFillFieldType heuristic_type() const { return heuristic_type_; }
27  AutoFillFieldType server_type() const { return server_type_; }
28  const FieldTypeSet& possible_types() const { return possible_types_; }
29
30  // Sets the heuristic type of this field, validating the input.
31  void set_heuristic_type(const AutoFillFieldType& type);
32  void set_server_type(const AutoFillFieldType& type) { server_type_ = type; }
33  void set_possible_types(const FieldTypeSet& possible_types) {
34    possible_types_ = possible_types;
35  }
36
37  // This function automatically chooses between server and heuristic autofill
38  // type, depending on the data available.
39  AutoFillFieldType type() const;
40
41  // Returns true if the value of this field is empty.
42  bool IsEmpty() const;
43
44  // The unique signature of this field, composed of the field name and the html
45  // input type in a 32-bit hash.
46  std::string FieldSignature() const;
47
48  // Returns true if the field type has been determined (without the text in the
49  // field).
50  bool IsFieldFillable() const;
51
52 private:
53  // The unique name of this field, generated by AutoFill.
54  string16 unique_name_;
55
56  // The type of the field, as determined by the AutoFill server.
57  AutoFillFieldType server_type_;
58
59  // The type of the field, as determined by the local heuristics.
60  AutoFillFieldType heuristic_type_;
61
62  // The set of possible types for this field.
63  FieldTypeSet possible_types_;
64
65  DISALLOW_COPY_AND_ASSIGN(AutoFillField);
66};
67
68#endif  // CHROME_BROWSER_AUTOFILL_AUTOFILL_FIELD_H_
69