address_field.h revision 3240926e260ce088908e02ac07a6cf7b0c0cbf44
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 17namespace autofill { 18 19class AutofillField; 20class AutofillScanner; 21 22class 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, ParseCity); 43 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseState); 44 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseZip); 45 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseStateAndZipOneLabel); 46 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseCountry); 47 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseTwoLineAddressMissingLabel); 48 FRIEND_TEST_ALL_PREFIXES(AddressFieldTest, ParseCompany); 49 50 AddressField(); 51 52 static bool ParseCompany(AutofillScanner* scanner, 53 AddressField* address_field); 54 static bool ParseAddressLines(AutofillScanner* scanner, 55 AddressField* address_field); 56 static bool ParseCountry(AutofillScanner* scanner, 57 AddressField* address_field); 58 static bool ParseZipCode(AutofillScanner* scanner, 59 AddressField* address_field); 60 static bool ParseCity(AutofillScanner* scanner, 61 AddressField* address_field); 62 static bool ParseState(AutofillScanner* scanner, 63 AddressField* address_field); 64 65 // Looks for an address type in the given text, which the caller must 66 // convert to lowercase. 67 static AddressType AddressTypeFromText(const base::string16& text); 68 69 // Tries to determine the billing/shipping type of this address. 70 AddressType FindType() const; 71 72 const AutofillField* company_; // optional 73 const AutofillField* address1_; 74 const AutofillField* address2_; // optional 75 const AutofillField* city_; 76 const AutofillField* state_; // optional 77 const AutofillField* zip_; 78 const AutofillField* zip4_; // optional ZIP+4; we don't fill this yet 79 const AutofillField* country_; // optional 80 81 AddressType type_; 82 83 DISALLOW_COPY_AND_ASSIGN(AddressField); 84}; 85 86} // namespace autofill 87 88#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_ADDRESS_FIELD_H_ 89