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