| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/autofill/phone_field.h" | 5 #include "chrome/browser/autofill/phone_field.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.h" |
| 8 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 9 #include "base/string16.h" | 10 #include "base/string16.h" |
| 10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/autofill/autofill_field.h" | 13 #include "chrome/browser/autofill/autofill_field.h" |
| 14 #include "grit/autofill_resources.h" |
| 13 | 15 |
| 14 // static | 16 // static |
| 15 PhoneField* PhoneField::Parse(std::vector<AutoFillField*>::const_iterator* iter, | 17 PhoneField* PhoneField::Parse(std::vector<AutoFillField*>::const_iterator* iter, |
| 16 bool is_ecml) { | 18 bool is_ecml) { |
| 17 DCHECK(iter); | 19 DCHECK(iter); |
| 18 if (!iter) | 20 if (!iter) |
| 19 return NULL; | 21 return NULL; |
| 20 | 22 |
| 21 if (is_ecml) | 23 if (is_ecml) |
| 22 return ParseECML(iter); | 24 return ParseECML(iter); |
| 23 | 25 |
| 24 std::vector<AutoFillField*>::const_iterator q = *iter; | 26 std::vector<AutoFillField*>::const_iterator q = *iter; |
| 25 AutoFillField* phone = NULL; | 27 AutoFillField* phone = NULL; |
| 26 AutoFillField* phone2 = NULL; | 28 AutoFillField* phone2 = NULL; |
| 27 AutoFillField* phone3 = NULL; | 29 AutoFillField* phone3 = NULL; |
| 28 bool area_code; // true if we've parsed an area code field. | 30 bool area_code; // true if we've parsed an area code field. |
| 29 | 31 |
| 30 // Some pages, such as BloomingdalesShipping.html, have a field labeled | 32 // Some pages, such as BloomingdalesShipping.html, have a field labeled |
| 31 // "Area Code and Phone"; we want to parse this as a phone number field so | 33 // "Area Code and Phone"; we want to parse this as a phone number field so |
| 32 // we look for "phone" before we look for "area code". | 34 // we look for "phone" before we look for "area code". |
| 33 if (ParseText(&q, ASCIIToUTF16("phone"), &phone)) { | 35 if (ParseText(&q, l10n_util::GetStringUTF16(IDS_AUTOFILL_PHONE_RE), &phone)) { |
| 34 area_code = false; | 36 area_code = false; |
| 35 } else { | 37 } else { |
| 36 if (!ParseText(&q, ASCIIToUTF16("area code"), &phone)) | 38 if (!ParseText(&q, |
| 39 l10n_util::GetStringUTF16(IDS_AUTOFILL_AREA_CODE_RE), |
| 40 &phone)) |
| 37 return NULL; | 41 return NULL; |
| 38 area_code = true; | 42 area_code = true; |
| 39 ParseText(&q, ASCIIToUTF16("phone"), &phone2); | 43 ParseText(&q, l10n_util::GetStringUTF16(IDS_AUTOFILL_PHONE_RE), &phone2); |
| 40 } | 44 } |
| 41 | 45 |
| 42 // Sometimes phone number fields are separated by "-" (e.g. test page | 46 // Sometimes phone number fields are separated by "-" (e.g. test page |
| 43 // Crate and Barrel Check Out.html). Also, area codes are sometimes | 47 // Crate and Barrel Check Out.html). Also, area codes are sometimes |
| 44 // surrounded by parentheses, so a ")" may appear after the area code field. | 48 // surrounded by parentheses, so a ")" may appear after the area code field. |
| 45 // | 49 // |
| 46 // We used to match "tel" here, which we've seen in field names (e.g. on | 50 // We used to match "tel" here, which we've seen in field names (e.g. on |
| 47 // Newegg2.html), but that's too general: some pages (e.g. | 51 // Newegg2.html), but that's too general: some pages (e.g. |
| 48 // uk/Furniture123-1.html) have several phone numbers in succession and we | 52 // uk/Furniture123-1.html) have several phone numbers in succession and we |
| 49 // don't want those to be parsed as components of a single phone number. | 53 // don't want those to be parsed as components of a single phone number. |
| 50 if (phone2 == NULL) | 54 if (phone2 == NULL) |
| 51 ParseText(&q, ASCIIToUTF16("^-$|\\)$|prefix"), &phone2); | 55 ParseText(&q, |
| 56 l10n_util::GetStringUTF16(IDS_AUTOFILL_PHONE_PREFIX_RE), |
| 57 &phone2); |
| 52 | 58 |
| 53 // Look for a third text box. | 59 // Look for a third text box. |
| 54 if (phone2) | 60 if (phone2) |
| 55 ParseText(&q, ASCIIToUTF16("^-$|suffix"), &phone3); | 61 ParseText(&q, |
| 62 l10n_util::GetStringUTF16(IDS_AUTOFILL_PHONE_SUFFIX_RE), |
| 63 &phone3); |
| 56 | 64 |
| 57 // Now we have one, two, or three phone number text fields. Package them | 65 // Now we have one, two, or three phone number text fields. Package them |
| 58 // up into a PhoneField object. | 66 // up into a PhoneField object. |
| 59 | 67 |
| 60 scoped_ptr<PhoneField> phone_field(new PhoneField); | 68 scoped_ptr<PhoneField> phone_field(new PhoneField); |
| 61 if (phone2 == NULL) { // only one field | 69 if (phone2 == NULL) { // only one field |
| 62 if (area_code) // it's an area code | 70 if (area_code) // it's an area code |
| 63 return NULL; // doesn't make sense | 71 return NULL; // doesn't make sense |
| 64 phone_field->phone_ = phone; | 72 phone_field->phone_ = phone; |
| 65 } else { | 73 } else { |
| 66 phone_field->area_code_ = phone; | 74 phone_field->area_code_ = phone; |
| 67 if (phone3 == NULL) { // two fields | 75 if (phone3 == NULL) { // two fields |
| 68 phone_field->phone_ = phone2; | 76 phone_field->phone_ = phone2; |
| 69 } else { // three boxes: area code, prefix and suffix | 77 } else { // three boxes: area code, prefix and suffix |
| 70 phone_field->prefix_ = phone2; | 78 phone_field->prefix_ = phone2; |
| 71 phone_field->phone_ = phone3; | 79 phone_field->phone_ = phone3; |
| 72 } | 80 } |
| 73 } | 81 } |
| 74 | 82 |
| 75 // Now look for an extension. | 83 // Now look for an extension. |
| 76 ParseText(&q, ASCIIToUTF16("ext"), &phone_field->extension_); | 84 ParseText(&q, |
| 85 l10n_util::GetStringUTF16(IDS_AUTOFILL_PHONE_EXTENSION_RE), |
| 86 &phone_field->extension_); |
| 77 | 87 |
| 78 *iter = q; | 88 *iter = q; |
| 79 return phone_field.release(); | 89 return phone_field.release(); |
| 80 } | 90 } |
| 81 | 91 |
| 82 // static | 92 // static |
| 83 PhoneField* PhoneField::ParseECML( | 93 PhoneField* PhoneField::ParseECML( |
| 84 std::vector<AutoFillField*>::const_iterator* iter) { | 94 std::vector<AutoFillField*>::const_iterator* iter) { |
| 85 string16 pattern(GetEcmlPattern(kEcmlShipToPhone, kEcmlBillToPhone, '|')); | 95 string16 pattern(GetEcmlPattern(kEcmlShipToPhone, kEcmlBillToPhone, '|')); |
| 86 | 96 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 135 |
| 126 return ok; | 136 return ok; |
| 127 } | 137 } |
| 128 | 138 |
| 129 PhoneField::PhoneField() | 139 PhoneField::PhoneField() |
| 130 : phone_(NULL), | 140 : phone_(NULL), |
| 131 area_code_(NULL), | 141 area_code_(NULL), |
| 132 prefix_(NULL), | 142 prefix_(NULL), |
| 133 extension_(NULL) { | 143 extension_(NULL) { |
| 134 } | 144 } |
| OLD | NEW |