| 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_NUMBER_H_ | 5 #ifndef CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ |
| 6 #define CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ | 6 #define CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "chrome/browser/autofill/autofill_type.h" | 14 #include "chrome/browser/autofill/autofill_type.h" |
| 15 #include "chrome/browser/autofill/form_group.h" | 15 #include "chrome/browser/autofill/form_group.h" |
| 16 #include "chrome/browser/autofill/phone_number_i18n.h" | 16 #include "chrome/browser/autofill/phone_number_i18n.h" |
| 17 | 17 |
| 18 class AutofillProfile; | 18 class AutofillProfile; |
| 19 | 19 |
| 20 // A form group that stores phone number information. | 20 // A form group that stores phone number information. |
| 21 class PhoneNumber : public FormGroup { | 21 class PhoneNumber : public FormGroup { |
| 22 public: | 22 public: |
| 23 explicit PhoneNumber(AutofillProfile* profile); | 23 explicit PhoneNumber(AutofillProfile* profile); |
| 24 // The |profile| can be NULL; but if so, clients should avoid calling | |
| 25 // |GetInfo()| or |SetInfo()|. This is typically only useful if you want to | |
| 26 // call into the |GetNumberType()| (etc.) functions. | |
| 27 PhoneNumber(AutofillType::FieldTypeGroup phone_group, | |
| 28 AutofillProfile* profile); | |
| 29 PhoneNumber(const PhoneNumber& number); | 24 PhoneNumber(const PhoneNumber& number); |
| 30 virtual ~PhoneNumber(); | 25 virtual ~PhoneNumber(); |
| 31 | 26 |
| 32 PhoneNumber& operator=(const PhoneNumber& number); | 27 PhoneNumber& operator=(const PhoneNumber& number); |
| 33 | 28 |
| 34 void set_profile(AutofillProfile* profile) { profile_ = profile; } | 29 void set_profile(AutofillProfile* profile) { profile_ = profile; } |
| 35 | 30 |
| 36 // FormGroup implementation: | 31 // FormGroup implementation: |
| 37 virtual void GetMatchingTypes(const string16& text, | 32 virtual void GetMatchingTypes(const string16& text, |
| 38 FieldTypeSet* matching_types) const OVERRIDE; | 33 FieldTypeSet* matching_types) const OVERRIDE; |
| 39 virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE; | 34 virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE; |
| 40 virtual void SetInfo(AutofillFieldType type, const string16& value) OVERRIDE; | 35 virtual void SetInfo(AutofillFieldType type, const string16& value) OVERRIDE; |
| 41 virtual string16 GetCanonicalizedInfo(AutofillFieldType type) const OVERRIDE; | 36 virtual string16 GetCanonicalizedInfo(AutofillFieldType type) const OVERRIDE; |
| 42 virtual bool SetCanonicalizedInfo(AutofillFieldType type, | 37 virtual bool SetCanonicalizedInfo(AutofillFieldType type, |
| 43 const string16& value) OVERRIDE; | 38 const string16& value) OVERRIDE; |
| 44 | 39 |
| 45 // Size and offset of the prefix and suffix portions of phone numbers. | 40 // Size and offset of the prefix and suffix portions of phone numbers. |
| 46 static const size_t kPrefixOffset = 0; | 41 static const size_t kPrefixOffset = 0; |
| 47 static const size_t kPrefixLength = 3; | 42 static const size_t kPrefixLength = 3; |
| 48 static const size_t kSuffixOffset = 3; | 43 static const size_t kSuffixOffset = 3; |
| 49 static const size_t kSuffixLength = 4; | 44 static const size_t kSuffixLength = 4; |
| 50 | 45 |
| 51 // The following functions should return the field type for each part of the | 46 // The class used to combine home phone parts into a whole number. |
| 52 // phone number. Currently, these are either fax or home phone number types. | |
| 53 AutofillFieldType GetNumberType() const; | |
| 54 AutofillFieldType GetCityCodeType() const; | |
| 55 AutofillFieldType GetCountryCodeType() const; | |
| 56 AutofillFieldType GetCityAndNumberType() const; | |
| 57 AutofillFieldType GetWholeNumberType() const; | |
| 58 | |
| 59 // The class used to combine home phone or fax parts into a whole number. | |
| 60 class PhoneCombineHelper { | 47 class PhoneCombineHelper { |
| 61 public: | 48 public: |
| 62 explicit PhoneCombineHelper(AutofillType::FieldTypeGroup phone_group); | 49 PhoneCombineHelper(); |
| 63 ~PhoneCombineHelper(); | 50 ~PhoneCombineHelper(); |
| 64 | 51 |
| 65 // If |type| is a phone field type, saves the |value| accordingly and | 52 // If |type| is a phone field type, saves the |value| accordingly and |
| 66 // returns true. For all other field types returs false. | 53 // returns true. For all other field types returs false. |
| 67 bool SetInfo(AutofillFieldType type, const string16& value); | 54 bool SetInfo(AutofillFieldType type, const string16& value); |
| 68 | 55 |
| 69 // Returns true if parsing was successful, false otherwise. | 56 // Returns true if parsing was successful, false otherwise. |
| 70 bool ParseNumber(const std::string& locale, string16* value); | 57 bool ParseNumber(const std::string& locale, string16* value); |
| 71 | 58 |
| 72 // Returns true if both |phone_| and |whole_number_| are empty. | 59 // Returns true if both |phone_| and |whole_number_| are empty. |
| 73 bool IsEmpty() const; | 60 bool IsEmpty() const; |
| 74 | 61 |
| 75 private: | 62 private: |
| 76 string16 country_; | 63 string16 country_; |
| 77 string16 city_; | 64 string16 city_; |
| 78 string16 phone_; | 65 string16 phone_; |
| 79 string16 whole_number_; | 66 string16 whole_number_; |
| 80 AutofillType::FieldTypeGroup phone_group_; | |
| 81 }; | 67 }; |
| 82 | 68 |
| 83 private: | 69 private: |
| 84 FRIEND_TEST_ALL_PREFIXES(PhoneNumberTest, Matcher); | 70 FRIEND_TEST_ALL_PREFIXES(PhoneNumberTest, Matcher); |
| 85 | 71 |
| 86 // FormGroup: | 72 // FormGroup: |
| 87 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE; | 73 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const OVERRIDE; |
| 88 | 74 |
| 89 // Validates |number_| and translates it into digits-only format. | 75 // Validates |number_| and translates it into digits-only format. |
| 90 bool NormalizePhone(); | 76 bool NormalizePhone(); |
| 91 | 77 |
| 92 // Returns the locale for this phone number, based on the |profile_|. | 78 // Returns the locale for this phone number, based on the |profile_|. |
| 93 std::string locale() const; | 79 std::string locale() const; |
| 94 | 80 |
| 95 // Updates the cached parsed number if the profile's locale has changed | 81 // Updates the cached parsed number if the profile's locale has changed |
| 96 // since the last time the cache was updated. | 82 // since the last time the cache was updated. |
| 97 void UpdateCacheIfNeeded() const; | 83 void UpdateCacheIfNeeded() const; |
| 98 | 84 |
| 99 // Phone group - currently it is PHONE_HOME and PHONE_FAX. | |
| 100 AutofillType::FieldTypeGroup phone_group_; | |
| 101 // The phone number. | 85 // The phone number. |
| 102 string16 number_; | 86 string16 number_; |
| 103 // Profile which stores the locale used as hint when normalizing the number. | 87 // Profile which stores the locale used as hint when normalizing the number. |
| 104 AutofillProfile* profile_; // WEAK | 88 AutofillProfile* profile_; // WEAK |
| 105 | 89 |
| 106 // Cached number. | 90 // Cached number. |
| 107 mutable autofill_i18n::PhoneObject cached_parsed_phone_; | 91 mutable autofill_i18n::PhoneObject cached_parsed_phone_; |
| 108 }; | 92 }; |
| 109 | 93 |
| 110 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ | 94 #endif // CHROME_BROWSER_AUTOFILL_PHONE_NUMBER_H_ |
| OLD | NEW |