| OLD | NEW |
| (Empty) | |
| 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 #include "chrome/browser/autofill/autofill_ecml.h" |
| 6 |
| 7 #include "base/basictypes.h" |
| 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/autofill/autofill_field.h" |
| 11 |
| 12 // Field names from the ECML specification; see RFC 3106. We've |
| 13 // made these names lowercase since we convert labels and field names to |
| 14 // lowercase before searching. |
| 15 |
| 16 // Shipping fields. |
| 17 const char kEcmlShipToTitle[] = "ecom_shipto_postal_name_prefix"; |
| 18 const char kEcmlShipToFirstName[] = "ecom_shipto_postal_name_first"; |
| 19 const char kEcmlShipToMiddleName[] = "ecom_shipto_postal_name_middle"; |
| 20 const char kEcmlShipToLastName[] = "ecom_shipto_postal_name_last"; |
| 21 const char kEcmlShipToNameSuffix[] = "ecom_shipto_postal_name_suffix"; |
| 22 const char kEcmlShipToCompanyName[] = "ecom_shipto_postal_company"; |
| 23 const char kEcmlShipToAddress1[] = "ecom_shipto_postal_street_line1"; |
| 24 const char kEcmlShipToAddress2[] = "ecom_shipto_postal_street_line2"; |
| 25 const char kEcmlShipToAddress3[] = "ecom_shipto_postal_street_line3"; |
| 26 const char kEcmlShipToCity[] = "ecom_shipto_postal_city"; |
| 27 const char kEcmlShipToStateProv[] = "ecom_shipto_postal_stateprov"; |
| 28 const char kEcmlShipToPostalCode[] = "ecom_shipto_postal_postalcode"; |
| 29 const char kEcmlShipToCountry[] = "ecom_shipto_postal_countrycode"; |
| 30 const char kEcmlShipToPhone[] = "ecom_shipto_telecom_phone_number"; |
| 31 const char kEcmlShipToEmail[] = "ecom_shipto_online_email"; |
| 32 |
| 33 // Billing fields. |
| 34 const char kEcmlBillToTitle[] = "ecom_billto_postal_name_prefix"; |
| 35 const char kEcmlBillToFirstName[] = "ecom_billto_postal_name_first"; |
| 36 const char kEcmlBillToMiddleName[] = "ecom_billto_postal_name_middle"; |
| 37 const char kEcmlBillToLastName[] = "ecom_billto_postal_name_last"; |
| 38 const char kEcmlBillToNameSuffix[] = "ecom_billto_postal_name_suffix"; |
| 39 const char kEcmlBillToCompanyName[] = "ecom_billto_postal_company"; |
| 40 const char kEcmlBillToAddress1[] = "ecom_billto_postal_street_line1"; |
| 41 const char kEcmlBillToAddress2[] = "ecom_billto_postal_street_line2"; |
| 42 const char kEcmlBillToAddress3[] = "ecom_billto_postal_street_line3"; |
| 43 const char kEcmlBillToCity[] = "ecom_billto_postal_city"; |
| 44 const char kEcmlBillToStateProv[] = "ecom_billto_postal_stateprov"; |
| 45 const char kEcmlBillToPostalCode[] = "ecom_billto_postal_postalcode"; |
| 46 const char kEcmlBillToCountry[] = "ecom_billto_postal_countrycode"; |
| 47 const char kEcmlBillToPhone[] = "ecom_billto_telecom_phone_number"; |
| 48 const char kEcmlBillToEmail[] = "ecom_billto_online_email"; |
| 49 |
| 50 // Credit card fields. |
| 51 const char kEcmlCardHolder[] = "ecom_payment_card_name"; |
| 52 const char kEcmlCardType[] = "ecom_payment_card_type"; |
| 53 const char kEcmlCardNumber[] = "ecom_payment_card_number"; |
| 54 const char kEcmlCardVerification[] = "ecom_payment_card_verification"; |
| 55 const char kEcmlCardExpireDay[] = "ecom_payment_card_expdate_day"; |
| 56 const char kEcmlCardExpireMonth[] = "ecom_payment_card_expdate_month"; |
| 57 const char kEcmlCardExpireYear[] = "ecom_payment_card_expdate_year"; |
| 58 |
| 59 namespace autofill { |
| 60 |
| 61 // Checks if any of the |form|'s labels are named according to the ECML |
| 62 // standard. Returns true if at least one ECML named element is found. |
| 63 bool HasECMLField(const std::vector<AutofillField*>& fields) { |
| 64 struct EcmlField { |
| 65 const char* name_; |
| 66 const int length_; |
| 67 } ecml_fields[] = { |
| 68 #define ECML_STRING_ENTRY(x) { x, arraysize(x) - 1 }, |
| 69 ECML_STRING_ENTRY(kEcmlShipToTitle) |
| 70 ECML_STRING_ENTRY(kEcmlShipToFirstName) |
| 71 ECML_STRING_ENTRY(kEcmlShipToMiddleName) |
| 72 ECML_STRING_ENTRY(kEcmlShipToLastName) |
| 73 ECML_STRING_ENTRY(kEcmlShipToNameSuffix) |
| 74 ECML_STRING_ENTRY(kEcmlShipToCompanyName) |
| 75 ECML_STRING_ENTRY(kEcmlShipToAddress1) |
| 76 ECML_STRING_ENTRY(kEcmlShipToAddress2) |
| 77 ECML_STRING_ENTRY(kEcmlShipToAddress3) |
| 78 ECML_STRING_ENTRY(kEcmlShipToCity) |
| 79 ECML_STRING_ENTRY(kEcmlShipToStateProv) |
| 80 ECML_STRING_ENTRY(kEcmlShipToPostalCode) |
| 81 ECML_STRING_ENTRY(kEcmlShipToCountry) |
| 82 ECML_STRING_ENTRY(kEcmlShipToPhone) |
| 83 ECML_STRING_ENTRY(kEcmlShipToEmail) |
| 84 ECML_STRING_ENTRY(kEcmlBillToTitle) |
| 85 ECML_STRING_ENTRY(kEcmlBillToFirstName) |
| 86 ECML_STRING_ENTRY(kEcmlBillToMiddleName) |
| 87 ECML_STRING_ENTRY(kEcmlBillToLastName) |
| 88 ECML_STRING_ENTRY(kEcmlBillToNameSuffix) |
| 89 ECML_STRING_ENTRY(kEcmlBillToCompanyName) |
| 90 ECML_STRING_ENTRY(kEcmlBillToAddress1) |
| 91 ECML_STRING_ENTRY(kEcmlBillToAddress2) |
| 92 ECML_STRING_ENTRY(kEcmlBillToAddress3) |
| 93 ECML_STRING_ENTRY(kEcmlBillToCity) |
| 94 ECML_STRING_ENTRY(kEcmlBillToStateProv) |
| 95 ECML_STRING_ENTRY(kEcmlBillToPostalCode) |
| 96 ECML_STRING_ENTRY(kEcmlBillToCountry) |
| 97 ECML_STRING_ENTRY(kEcmlBillToPhone) |
| 98 ECML_STRING_ENTRY(kEcmlBillToPhone) |
| 99 ECML_STRING_ENTRY(kEcmlBillToEmail) |
| 100 ECML_STRING_ENTRY(kEcmlCardHolder) |
| 101 ECML_STRING_ENTRY(kEcmlCardType) |
| 102 ECML_STRING_ENTRY(kEcmlCardNumber) |
| 103 ECML_STRING_ENTRY(kEcmlCardVerification) |
| 104 ECML_STRING_ENTRY(kEcmlCardExpireMonth) |
| 105 ECML_STRING_ENTRY(kEcmlCardExpireYear) |
| 106 #undef ECML_STRING_ENTRY |
| 107 }; |
| 108 |
| 109 const string16 ecom(ASCIIToUTF16("ecom")); |
| 110 for (std::vector<AutofillField*>::const_iterator field = fields.begin(); |
| 111 field != fields.end(); |
| 112 ++field) { |
| 113 const string16& utf16_name = (*field)->name; |
| 114 if (StartsWith(utf16_name, ecom, true)) { |
| 115 std::string name(UTF16ToUTF8(utf16_name)); |
| 116 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(ecml_fields); ++i) { |
| 117 if (base::strncasecmp(name.c_str(), ecml_fields[i].name_, |
| 118 ecml_fields[i].length_) == 0) { |
| 119 return true; |
| 120 } |
| 121 } |
| 122 } |
| 123 } |
| 124 |
| 125 return false; |
| 126 } |
| 127 |
| 128 string16 GetEcmlPattern(const char* ecml_name) { |
| 129 return ASCIIToUTF16(std::string("^") + ecml_name); |
| 130 } |
| 131 |
| 132 string16 GetEcmlPattern(const char* ecml_name1, |
| 133 const char* ecml_name2, |
| 134 char pattern_operator) { |
| 135 return ASCIIToUTF16(StringPrintf("^%s%c^%s", |
| 136 ecml_name1, pattern_operator, ecml_name2)); |
| 137 } |
| 138 |
| 139 } // namespace autofill |
| OLD | NEW |