[email protected] | 7b37fbb | 2011-03-07 16:16:03 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 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 CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_ |
| 6 | #define CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 8 | |
| 9 | #include <vector> |
| 10 | |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 11 | #include "base/gtest_prod_util.h" |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 12 | #include "base/string16.h" |
| 13 | #include "chrome/browser/autofill/form_group.h" |
| 14 | |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 15 | // A form group that stores name information. |
| 16 | class NameInfo : public FormGroup { |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 17 | public: |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 18 | NameInfo(); |
[email protected] | 791c8c7 | 2011-03-28 22:54:03 | [diff] [blame^] | 19 | NameInfo(const NameInfo& info); |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 20 | virtual ~NameInfo(); |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 21 | |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 22 | NameInfo& operator=(const NameInfo& info); |
| 23 | |
| 24 | // FormGroup: |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 25 | virtual void GetPossibleFieldTypes(const string16& text, |
| 26 | FieldTypeSet* possible_types) const; |
[email protected] | cea1d11 | 2010-07-01 00:57:33 | [diff] [blame] | 27 | virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; |
[email protected] | 1ffe8e99 | 2011-03-17 06:26:29 | [diff] [blame] | 28 | virtual void FindInfoMatches(AutofillFieldType type, |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 29 | const string16& info, |
| 30 | std::vector<string16>* matched_text) const; |
[email protected] | 3b3a0ca7 | 2011-03-17 23:04:55 | [diff] [blame] | 31 | virtual string16 GetInfo(AutofillFieldType type) const; |
[email protected] | 1ffe8e99 | 2011-03-17 06:26:29 | [diff] [blame] | 32 | virtual void SetInfo(AutofillFieldType type, const string16& value); |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 33 | |
[email protected] | 87753517 | 2010-03-03 01:57:07 | [diff] [blame] | 34 | private: |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 35 | FRIEND_TEST_ALL_PREFIXES(NameInfoTest, TestSetFullName); |
[email protected] | 87753517 | 2010-03-03 01:57:07 | [diff] [blame] | 36 | |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 37 | // Returns the full name, which can include up to the first, middle, and last |
| 38 | // name. |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 39 | string16 FullName() const; |
| 40 | |
[email protected] | 87753517 | 2010-03-03 01:57:07 | [diff] [blame] | 41 | // Returns the middle initial if |middle_| is non-empty. Returns an empty |
| 42 | // string otherwise. |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 43 | string16 MiddleInitial() const; |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 44 | |
[email protected] | 87753517 | 2010-03-03 01:57:07 | [diff] [blame] | 45 | const string16& first() const { return first_; } |
| 46 | const string16& middle() const { return middle_; } |
| 47 | const string16& last() const { return last_; } |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 48 | |
| 49 | // A helper function for FindInfoMatches that only handles matching the info |
| 50 | // with the requested field type. |
[email protected] | 1ffe8e99 | 2011-03-17 06:26:29 | [diff] [blame] | 51 | bool FindInfoMatchesHelper(AutofillFieldType field_type, |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 52 | const string16& info, |
| 53 | string16* matched_text) const; |
| 54 | |
| 55 | // Returns true if |text| is the first name. |
| 56 | bool IsFirstName(const string16& text) const; |
| 57 | |
| 58 | // Returns true if |text| is the middle name. |
| 59 | bool IsMiddleName(const string16& text) const; |
| 60 | |
| 61 | // Returns true if |text| is the last name. |
| 62 | bool IsLastName(const string16& text) const; |
| 63 | |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 64 | // Returns true if |text| is the middle initial. |
| 65 | bool IsMiddleInitial(const string16& text) const; |
| 66 | |
| 67 | // Returns true if |text| is the last name. |
| 68 | bool IsFullName(const string16& text) const; |
| 69 | |
| 70 | // Returns true if all of the tokens in |text| match the tokens in |
| 71 | // |name_tokens|. |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 72 | bool IsNameMatch(const string16& text, |
| 73 | const std::vector<string16>& name_tokens) const; |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 74 | |
| 75 | // Returns true if |word| is one of the tokens in |name_tokens|. |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 76 | bool IsWordInName(const string16& word, |
| 77 | const std::vector<string16>& name_tokens) const; |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 78 | |
| 79 | // Sets |first_| to |first| and |first_tokens_| to the set of tokens in |
| 80 | // |first|, made lowercase. |
| 81 | void SetFirst(const string16& first); |
| 82 | |
| 83 | // Sets |middle_| to |middle| and |middle_tokens_| to the set of tokens in |
| 84 | // |middle|, made lowercase. |
| 85 | void SetMiddle(const string16& middle); |
| 86 | |
| 87 | // Sets |last_| to |last| and |last_tokens_| to the set of tokens in |last|, |
| 88 | // made lowercase. |
| 89 | void SetLast(const string16& last); |
| 90 | |
[email protected] | 95f4165 | 2010-06-07 22:29:24 | [diff] [blame] | 91 | // Sets |first_|, |middle_|, |last_| and |*_tokens_| to the tokenized |
| 92 | // |full|. It is tokenized on a space only. |
| 93 | void SetFullName(const string16& full); |
| 94 | |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 95 | // List of tokens in each part of the name. |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 96 | std::vector<string16> first_tokens_; |
| 97 | std::vector<string16> middle_tokens_; |
| 98 | std::vector<string16> last_tokens_; |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 99 | |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 100 | string16 first_; |
| 101 | string16 middle_; |
| 102 | string16 last_; |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | class EmailInfo : public FormGroup { |
| 106 | public: |
| 107 | EmailInfo(); |
[email protected] | 791c8c7 | 2011-03-28 22:54:03 | [diff] [blame^] | 108 | EmailInfo(const EmailInfo& info); |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 109 | virtual ~EmailInfo(); |
| 110 | |
| 111 | EmailInfo& operator=(const EmailInfo& info); |
| 112 | |
| 113 | // FormGroup: |
| 114 | virtual void GetPossibleFieldTypes(const string16& text, |
| 115 | FieldTypeSet* possible_types) const; |
| 116 | virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; |
[email protected] | 1ffe8e99 | 2011-03-17 06:26:29 | [diff] [blame] | 117 | virtual void FindInfoMatches(AutofillFieldType type, |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 118 | const string16& info, |
| 119 | std::vector<string16>* matched_text) const; |
[email protected] | 3b3a0ca7 | 2011-03-17 23:04:55 | [diff] [blame] | 120 | virtual string16 GetInfo(AutofillFieldType type) const; |
[email protected] | 1ffe8e99 | 2011-03-17 06:26:29 | [diff] [blame] | 121 | virtual void SetInfo(AutofillFieldType type, const string16& value); |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 122 | |
| 123 | private: |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 124 | string16 email_; |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | class CompanyInfo : public FormGroup { |
| 128 | public: |
| 129 | CompanyInfo(); |
[email protected] | 791c8c7 | 2011-03-28 22:54:03 | [diff] [blame^] | 130 | CompanyInfo(const CompanyInfo& info); |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 131 | virtual ~CompanyInfo(); |
| 132 | |
| 133 | CompanyInfo& operator=(const CompanyInfo& info); |
| 134 | |
| 135 | // FormGroup: |
| 136 | virtual void GetPossibleFieldTypes(const string16& text, |
| 137 | FieldTypeSet* possible_types) const; |
| 138 | virtual void GetAvailableFieldTypes(FieldTypeSet* available_types) const; |
[email protected] | 1ffe8e99 | 2011-03-17 06:26:29 | [diff] [blame] | 139 | virtual void FindInfoMatches(AutofillFieldType type, |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 140 | const string16& info, |
| 141 | std::vector<string16>* matched_text) const; |
[email protected] | 3b3a0ca7 | 2011-03-17 23:04:55 | [diff] [blame] | 142 | virtual string16 GetInfo(AutofillFieldType type) const; |
[email protected] | 1ffe8e99 | 2011-03-17 06:26:29 | [diff] [blame] | 143 | virtual void SetInfo(AutofillFieldType type, const string16& value); |
[email protected] | 4389724 | 2011-03-09 03:52:11 | [diff] [blame] | 144 | |
| 145 | private: |
[email protected] | 6c17851 | 2010-01-04 20:27:25 | [diff] [blame] | 146 | string16 company_name_; |
| 147 | }; |
| 148 | |
| 149 | #endif // CHROME_BROWSER_AUTOFILL_CONTACT_INFO_H_ |