OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/core/browser/autofill_data_util.h" | 5 #include "components/autofill/core/browser/autofill_data_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/i18n/char_iterator.h" | 10 #include "base/i18n/char_iterator.h" |
11 #include "base/strings/string_split.h" | 11 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "components/autofill/core/browser/field_types.h" | 14 #include "components/autofill/core/browser/field_types.h" |
15 #include "third_party/icu/source/common/unicode/uscript.h" | 15 #include "third_party/icu/source/common/unicode/uscript.h" |
16 | 16 |
17 namespace autofill { | 17 namespace autofill { |
18 namespace data_util { | 18 namespace data_util { |
19 | 19 |
20 namespace { | 20 namespace { |
| 21 // Mappings from Chrome card types to Payment Request API basic card payment |
| 22 // spec types and icons. Note that "generic" is not in the spec. |
| 23 // https://w3c.github.io/webpayments-methods-card/#method-id |
| 24 const PaymentRequestData kPaymentRequestData[]{ |
| 25 {"americanExpressCC", "amex", IDR_AUTOFILL_PR_AMEX}, |
| 26 {"dinersCC", "diners", IDR_AUTOFILL_PR_DINERS}, |
| 27 {"discoverCC", "discover", IDR_AUTOFILL_PR_DISCOVER}, |
| 28 {"jcbCC", "jcb", IDR_AUTOFILL_PR_JCB}, |
| 29 {"masterCardCC", "mastercard", IDR_AUTOFILL_PR_MASTERCARD}, |
| 30 {"unionPayCC", "unionpay", IDR_AUTOFILL_PR_UNIONPAY}, |
| 31 {"visaCC", "visa", IDR_AUTOFILL_PR_VISA}, |
| 32 }; |
| 33 const PaymentRequestData kGenericPaymentRequestData = {"genericCC", "generic", |
| 34 IDR_AUTOFILL_PR_GENERIC}; |
| 35 |
21 const char* const name_prefixes[] = { | 36 const char* const name_prefixes[] = { |
22 "1lt", "1st", "2lt", "2nd", "3rd", "admiral", "capt", | 37 "1lt", "1st", "2lt", "2nd", "3rd", "admiral", "capt", |
23 "captain", "col", "cpt", "dr", "gen", "general", "lcdr", | 38 "captain", "col", "cpt", "dr", "gen", "general", "lcdr", |
24 "lt", "ltc", "ltg", "ltjg", "maj", "major", "mg", | 39 "lt", "ltc", "ltg", "ltjg", "maj", "major", "mg", |
25 "mr", "mrs", "ms", "pastor", "prof", "rep", "reverend", | 40 "mr", "mrs", "ms", "pastor", "prof", "rep", "reverend", |
26 "rev", "sen", "st"}; | 41 "rev", "sen", "st"}; |
27 | 42 |
28 const char* const name_suffixes[] = {"b.a", "ba", "d.d.s", "dds", "i", "ii", | 43 const char* const name_suffixes[] = {"b.a", "ba", "d.d.s", "dds", "i", "ii", |
29 "iii", "iv", "ix", "jr", "m.a", "m.d", | 44 "iii", "iv", "ix", "jr", "m.a", "m.d", |
30 "ma", "md", "ms", "ph.d", "phd", "sr", | 45 "ma", "md", "ms", "ph.d", "phd", "sr", |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 // LastFirst | 391 // LastFirst |
377 candidate = profile.GetRawInfo(autofill::NAME_LAST) + | 392 candidate = profile.GetRawInfo(autofill::NAME_LAST) + |
378 profile.GetRawInfo(autofill::NAME_FIRST); | 393 profile.GetRawInfo(autofill::NAME_FIRST); |
379 if (!full_name.compare(candidate)) { | 394 if (!full_name.compare(candidate)) { |
380 return true; | 395 return true; |
381 } | 396 } |
382 | 397 |
383 return false; | 398 return false; |
384 } | 399 } |
385 | 400 |
| 401 const PaymentRequestData& GetPaymentRequestData(const std::string& type) { |
| 402 for (size_t i = 0; i < arraysize(kPaymentRequestData); ++i) { |
| 403 if (type == kPaymentRequestData[i].card_type) |
| 404 return kPaymentRequestData[i]; |
| 405 } |
| 406 return kGenericPaymentRequestData; |
| 407 } |
| 408 |
| 409 const char* GetCardTypeForBasicCardPaymentType( |
| 410 const std::string& basic_card_payment_type) { |
| 411 for (size_t i = 0; i < arraysize(kPaymentRequestData); ++i) { |
| 412 if (basic_card_payment_type == |
| 413 kPaymentRequestData[i].basic_card_payment_type) { |
| 414 return kPaymentRequestData[i].card_type; |
| 415 } |
| 416 } |
| 417 return kGenericPaymentRequestData.card_type; |
| 418 } |
| 419 |
386 } // namespace data_util | 420 } // namespace data_util |
387 } // namespace autofill | 421 } // namespace autofill |
OLD | NEW |