| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/name_field.h" | 5 #include "components/autofill/core/browser/name_field.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // A form field that can parse a full name field. | 21 // A form field that can parse a full name field. |
| 22 class FullNameField : public NameField { | 22 class FullNameField : public NameField { |
| 23 public: | 23 public: |
| 24 static FullNameField* Parse(AutofillScanner* scanner); | 24 static FullNameField* Parse(AutofillScanner* scanner); |
| 25 | 25 |
| 26 protected: | 26 protected: |
| 27 // FormField: | 27 // FormField: |
| 28 virtual bool ClassifyField(ServerFieldTypeMap* map) const OVERRIDE; | 28 virtual bool ClassifyField(ServerFieldTypeMap* map) const OVERRIDE; |
| 29 | 29 |
| 30 private: | 30 private: |
| 31 explicit FullNameField(const AutofillField* field); | 31 explicit FullNameField(AutofillField* field); |
| 32 | 32 |
| 33 const AutofillField* field_; | 33 AutofillField* field_; |
| 34 | 34 |
| 35 DISALLOW_COPY_AND_ASSIGN(FullNameField); | 35 DISALLOW_COPY_AND_ASSIGN(FullNameField); |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 // A form field that can parse a first and last name field. | 38 // A form field that can parse a first and last name field. |
| 39 class FirstLastNameField : public NameField { | 39 class FirstLastNameField : public NameField { |
| 40 public: | 40 public: |
| 41 static FirstLastNameField* ParseSpecificName(AutofillScanner* scanner); | 41 static FirstLastNameField* ParseSpecificName(AutofillScanner* scanner); |
| 42 static FirstLastNameField* ParseComponentNames(AutofillScanner* scanner); | 42 static FirstLastNameField* ParseComponentNames(AutofillScanner* scanner); |
| 43 static FirstLastNameField* Parse(AutofillScanner* scanner); | 43 static FirstLastNameField* Parse(AutofillScanner* scanner); |
| 44 | 44 |
| 45 protected: | 45 protected: |
| 46 // FormField: | 46 // FormField: |
| 47 virtual bool ClassifyField(ServerFieldTypeMap* map) const OVERRIDE; | 47 virtual bool ClassifyField(ServerFieldTypeMap* map) const OVERRIDE; |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 FirstLastNameField(); | 50 FirstLastNameField(); |
| 51 | 51 |
| 52 const AutofillField* first_name_; | 52 AutofillField* first_name_; |
| 53 const AutofillField* middle_name_; // Optional. | 53 AutofillField* middle_name_; // Optional. |
| 54 const AutofillField* last_name_; | 54 AutofillField* last_name_; |
| 55 bool middle_initial_; // True if middle_name_ is a middle initial. | 55 bool middle_initial_; // True if middle_name_ is a middle initial. |
| 56 | 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(FirstLastNameField); | 57 DISALLOW_COPY_AND_ASSIGN(FirstLastNameField); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 } // namespace | 60 } // namespace |
| 61 | 61 |
| 62 FormField* NameField::Parse(AutofillScanner* scanner) { | 62 FormField* NameField::Parse(AutofillScanner* scanner) { |
| 63 if (scanner->IsEnd()) | 63 if (scanner->IsEnd()) |
| 64 return NULL; | 64 return NULL; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 80 scanner->SaveCursor(); | 80 scanner->SaveCursor(); |
| 81 bool should_ignore = ParseField(scanner, | 81 bool should_ignore = ParseField(scanner, |
| 82 UTF8ToUTF16(autofill::kNameIgnoredRe), NULL); | 82 UTF8ToUTF16(autofill::kNameIgnoredRe), NULL); |
| 83 scanner->Rewind(); | 83 scanner->Rewind(); |
| 84 if (should_ignore) | 84 if (should_ignore) |
| 85 return NULL; | 85 return NULL; |
| 86 | 86 |
| 87 // Searching for any label containing the word "name" is too general; | 87 // Searching for any label containing the word "name" is too general; |
| 88 // for example, Travelocity_Edit travel profile.html contains a field | 88 // for example, Travelocity_Edit travel profile.html contains a field |
| 89 // "Travel Profile Name". | 89 // "Travel Profile Name". |
| 90 const AutofillField* field = NULL; | 90 AutofillField* field = NULL; |
| 91 if (ParseField(scanner, UTF8ToUTF16(autofill::kNameRe), &field)) | 91 if (ParseField(scanner, UTF8ToUTF16(autofill::kNameRe), &field)) |
| 92 return new FullNameField(field); | 92 return new FullNameField(field); |
| 93 | 93 |
| 94 return NULL; | 94 return NULL; |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool FullNameField::ClassifyField(ServerFieldTypeMap* map) const { | 97 bool FullNameField::ClassifyField(ServerFieldTypeMap* map) const { |
| 98 return AddClassification(field_, NAME_FULL, map); | 98 return AddClassification(field_, NAME_FULL, map); |
| 99 } | 99 } |
| 100 | 100 |
| 101 FullNameField::FullNameField(const AutofillField* field) | 101 FullNameField::FullNameField(AutofillField* field) : field_(field) { |
| 102 : field_(field) { | |
| 103 } | 102 } |
| 104 | 103 |
| 105 FirstLastNameField* FirstLastNameField::ParseSpecificName( | 104 FirstLastNameField* FirstLastNameField::ParseSpecificName( |
| 106 AutofillScanner* scanner) { | 105 AutofillScanner* scanner) { |
| 107 // Some pages (e.g. Overstock_comBilling.html, SmithsonianCheckout.html) | 106 // Some pages (e.g. Overstock_comBilling.html, SmithsonianCheckout.html) |
| 108 // have the label "Name" followed by two or three text fields. | 107 // have the label "Name" followed by two or three text fields. |
| 109 scoped_ptr<FirstLastNameField> v(new FirstLastNameField); | 108 scoped_ptr<FirstLastNameField> v(new FirstLastNameField); |
| 110 scanner->SaveCursor(); | 109 scanner->SaveCursor(); |
| 111 | 110 |
| 112 const AutofillField* next = NULL; | 111 AutofillField* next = NULL; |
| 113 if (ParseField(scanner, | 112 if (ParseField(scanner, |
| 114 UTF8ToUTF16(autofill::kNameSpecificRe), &v->first_name_) && | 113 UTF8ToUTF16(autofill::kNameSpecificRe), &v->first_name_) && |
| 115 ParseEmptyLabel(scanner, &next)) { | 114 ParseEmptyLabel(scanner, &next)) { |
| 116 if (ParseEmptyLabel(scanner, &v->last_name_)) { | 115 if (ParseEmptyLabel(scanner, &v->last_name_)) { |
| 117 // There are three name fields; assume that the middle one is a | 116 // There are three name fields; assume that the middle one is a |
| 118 // middle initial (it is, at least, on SmithsonianCheckout.html). | 117 // middle initial (it is, at least, on SmithsonianCheckout.html). |
| 119 v->middle_name_ = next; | 118 v->middle_name_ = next; |
| 120 v->middle_initial_ = true; | 119 v->middle_initial_ = true; |
| 121 } else { // only two name fields | 120 } else { // only two name fields |
| 122 v->last_name_ = next; | 121 v->last_name_ = next; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 209 |
| 211 bool FirstLastNameField::ClassifyField(ServerFieldTypeMap* map) const { | 210 bool FirstLastNameField::ClassifyField(ServerFieldTypeMap* map) const { |
| 212 bool ok = AddClassification(first_name_, NAME_FIRST, map); | 211 bool ok = AddClassification(first_name_, NAME_FIRST, map); |
| 213 ok = ok && AddClassification(last_name_, NAME_LAST, map); | 212 ok = ok && AddClassification(last_name_, NAME_LAST, map); |
| 214 ServerFieldType type = middle_initial_ ? NAME_MIDDLE_INITIAL : NAME_MIDDLE; | 213 ServerFieldType type = middle_initial_ ? NAME_MIDDLE_INITIAL : NAME_MIDDLE; |
| 215 ok = ok && AddClassification(middle_name_, type, map); | 214 ok = ok && AddClassification(middle_name_, type, map); |
| 216 return ok; | 215 return ok; |
| 217 } | 216 } |
| 218 | 217 |
| 219 } // namespace autofill | 218 } // namespace autofill |
| OLD | NEW |