Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_ |
| 6 #define CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_ | 6 #define CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 protected: | 30 protected: |
| 31 // FormField: | 31 // FormField: |
| 32 virtual bool ClassifyField(FieldTypeMap* map) const OVERRIDE; | 32 virtual bool ClassifyField(FieldTypeMap* map) const OVERRIDE; |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ParseOneLinePhone); | 35 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ParseOneLinePhone); |
| 36 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ParseTwoLinePhone); | 36 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ParseTwoLinePhone); |
| 37 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumber); | 37 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumber); |
| 38 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix); | 38 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix); |
| 39 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix2); | 39 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartPhoneNumberPrefixSuffix2); |
| 40 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ParseOneLineFax); | |
| 41 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ParseTwoLineFax); | |
| 42 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, ThreePartFaxNumberPrefixSuffix); | |
| 43 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, CountryAndCityAndPhoneNumber); | 40 FRIEND_TEST_ALL_PREFIXES(PhoneFieldTest, CountryAndCityAndPhoneNumber); |
| 44 | 41 |
| 45 PhoneField(); | 42 PhoneField(); |
| 46 | 43 |
| 47 enum PhoneType { | 44 // Some field names are different for phone. |
|
Ilya Sherman
2011/09/15 03:47:08
nit: This comment no longer makes sense. I think
James Hawkins
2011/09/16 03:23:28
Done.
| |
| 48 PHONE_TYPE_FIRST = 0, | |
| 49 HOME_PHONE = PHONE_TYPE_FIRST, | |
| 50 FAX_PHONE, | |
| 51 | |
| 52 // Must be last. | |
| 53 PHONE_TYPE_MAX, | |
| 54 }; | |
| 55 | |
| 56 // Some field names are different for phone and fax. | |
| 57 string16 GetCountryRegex() const; | 45 string16 GetCountryRegex() const; |
| 58 // This string includes all area code separators, including NoText. | 46 // This string includes all area code separators, including NoText. |
| 59 string16 GetAreaRegex() const; | 47 string16 GetAreaRegex() const; |
| 60 // Separator of the area code in the case fields are formatted without | 48 // Separator of the area code in the case fields are formatted without |
| 61 // any text indicating what fields are (e.g. field1 "(" field2 ")" field3 "-" | 49 // any text indicating what fields are (e.g. field1 "(" field2 ")" field3 "-" |
| 62 // field4 means Country Code, Area Code, Prefix, Suffix) | 50 // field4 means Country Code, Area Code, Prefix, Suffix) |
| 63 string16 GetAreaNoTextRegex() const; | 51 string16 GetAreaNoTextRegex() const; |
| 64 string16 GetPhoneRegex() const; | 52 string16 GetPhoneRegex() const; |
| 65 string16 GetPrefixSeparatorRegex() const; | 53 string16 GetPrefixSeparatorRegex() const; |
| 66 string16 GetPrefixRegex() const; | 54 string16 GetPrefixRegex() const; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 84 // Separates regexps in grammar. | 72 // Separates regexps in grammar. |
| 85 REGEX_SEPARATOR, | 73 REGEX_SEPARATOR, |
| 86 }; | 74 }; |
| 87 | 75 |
| 88 string16 GetRegExp(RegexType regex_id) const; | 76 string16 GetRegExp(RegexType regex_id) const; |
| 89 | 77 |
| 90 // |field| - field to fill up on successful parsing. | 78 // |field| - field to fill up on successful parsing. |
| 91 // |iter| - in/out. Form field iterator, points to the first field that is | 79 // |iter| - in/out. Form field iterator, points to the first field that is |
| 92 // attempted to be parsed. If parsing successful, points to the first field | 80 // attempted to be parsed. If parsing successful, points to the first field |
| 93 // after parsed fields. | 81 // after parsed fields. |
| 94 // |regular_phone| - true if the parsed phone is a HOME phone, false | 82 // TODO(isherman): This method doc is out of date. |
| 95 // otherwise. | 83 static bool ParseInternal(PhoneField* field, AutofillScanner* scanner); |
| 96 static bool ParseInternal(PhoneField* field, | |
| 97 AutofillScanner* scanner, | |
| 98 bool regular_phone); | |
| 99 | 84 |
| 100 void SetPhoneType(PhoneType phone_type); | 85 // TODO(jhawkins): This is probably not necessary anymore. |
|
Ilya Sherman
2011/09/15 03:47:08
Indeed, I think you can nix it.
James Hawkins
2011/09/16 03:23:28
Done.
| |
| 101 | |
| 102 // Field types are different as well, so we create a temporary phone number, | |
| 103 // to get relevant field types. | |
| 104 scoped_ptr<PhoneNumber> number_; | 86 scoped_ptr<PhoneNumber> number_; |
| 105 PhoneType phone_type_; | |
| 106 | |
| 107 | 87 |
| 108 // Parsed fields. | 88 // Parsed fields. |
| 109 enum PhonePart { | 89 enum PhonePart { |
| 110 FIELD_NONE = -1, | 90 FIELD_NONE = -1, |
| 111 FIELD_COUNTRY_CODE, | 91 FIELD_COUNTRY_CODE, |
| 112 FIELD_AREA_CODE, | 92 FIELD_AREA_CODE, |
| 113 FIELD_PHONE, | 93 FIELD_PHONE, |
| 114 FIELD_SUFFIX, | 94 FIELD_SUFFIX, |
| 115 FIELD_EXTENSION, | 95 FIELD_EXTENSION, |
| 116 | 96 |
| 117 FIELD_MAX, | 97 FIELD_MAX, |
| 118 }; | 98 }; |
| 119 | 99 |
| 120 // FIELD_PHONE is always present; holds suffix if prefix is present. | 100 // FIELD_PHONE is always present; holds suffix if prefix is present. |
| 121 // The rest could be NULL. | 101 // The rest could be NULL. |
| 122 const AutofillField* parsed_phone_fields_[FIELD_MAX]; | 102 const AutofillField* parsed_phone_fields_[FIELD_MAX]; |
| 123 | 103 |
| 124 static struct Parser { | 104 static struct Parser { |
| 125 RegexType regex; // Field matching reg-ex. | 105 RegexType regex; // Field matching reg-ex. |
| 126 PhonePart phone_part; // Index of the field. | 106 PhonePart phone_part; // Index of the field. |
| 127 size_t max_size; // Max size of the field to match. 0 means any. | 107 size_t max_size; // Max size of the field to match. 0 means any. |
| 128 } phone_field_grammars_[]; | 108 } phone_field_grammars_[]; |
| 129 | 109 |
| 130 DISALLOW_COPY_AND_ASSIGN(PhoneField); | 110 DISALLOW_COPY_AND_ASSIGN(PhoneField); |
| 131 }; | 111 }; |
| 132 | 112 |
| 133 #endif // CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_ | 113 #endif // CHROME_BROWSER_AUTOFILL_PHONE_FIELD_H_ |
| OLD | NEW |