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