- add sources.
[platform/framework/web/crosswalk.git] / src / components / autofill / core / browser / address_field.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_CORE_BROWSER_ADDRESS_FIELD_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_FIELD_H_
7
8 #include <vector>
9
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
13 #include "base/strings/string16.h"
14 #include "components/autofill/core/browser/autofill_type.h"
15 #include "components/autofill/core/browser/form_field.h"
16
17 namespace autofill {
18
19 class AutofillField;
20 class AutofillScanner;
21
22 class AddressField : public FormField {
23  public:
24   static FormField* Parse(AutofillScanner* scanner);
25
26  protected:
27   // FormField:
28   virtual bool ClassifyField(ServerFieldTypeMap* map) const OVERRIDE;
29
30  private:
31   enum AddressType {
32     kGenericAddress = 0,
33     kBillingAddress,
34     kShippingAddress
35   };
36
37   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseOneLineAddress);
38   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseOneLineAddressBilling);
39   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseOneLineAddressShipping);
40   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseTwoLineAddress);
41   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseThreeLineAddress);
42   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseStreetAddressFromTextArea);
43   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseCity);
44   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseState);
45   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseZip);
46   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseStateAndZipOneLabel);
47   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseCountry);
48   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseTwoLineAddressMissingLabel);
49   FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseCompany);
50
51   AddressField();
52
53   static bool ParseCompany(AutofillScanner* scanner,
54                            AddressField* address_field);
55   static bool ParseAddressLines(AutofillScanner* scanner,
56                                 AddressField* address_field);
57   static bool ParseCountry(AutofillScanner* scanner,
58                            AddressField* address_field);
59   static bool ParseZipCode(AutofillScanner* scanner,
60                            AddressField* address_field);
61   static bool ParseCity(AutofillScanner* scanner,
62                         AddressField* address_field);
63   static bool ParseState(AutofillScanner* scanner,
64                          AddressField* address_field);
65
66   // Looks for an address type in the given text, which the caller must
67   // convert to lowercase.
68   static AddressType AddressTypeFromText(const base::string16& text);
69
70   // Tries to determine the billing/shipping type of this address.
71   AddressType FindType() const;
72
73   const AutofillField* company_;   // optional
74   const AutofillField* address1_;
75   const AutofillField* address2_;  // optional
76   const AutofillField* city_;
77   const AutofillField* state_;     // optional
78   const AutofillField* zip_;
79   const AutofillField* zip4_;      // optional ZIP+4; we don't fill this yet
80   const AutofillField* country_;   // optional
81
82   AddressType type_;
83
84   DISALLOW_COPY_AND_ASSIGN(AddressField);
85 };
86
87 }  // namespace autofill
88
89 #endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_FIELD_H_