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/form_structure.h" | 5 #include "components/autofill/core/browser/form_structure.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 for (ServerFieldTypeSet::iterator field_type = types.begin(); | 139 for (ServerFieldTypeSet::iterator field_type = types.begin(); |
140 field_type != types.end(); ++field_type) { | 140 field_type != types.end(); ++field_type) { |
141 buzz::XmlElement *field_element = new buzz::XmlElement( | 141 buzz::XmlElement *field_element = new buzz::XmlElement( |
142 buzz::QName(kXMLElementFields)); | 142 buzz::QName(kXMLElementFields)); |
143 | 143 |
144 field_element->SetAttr(buzz::QName(kAttributeFieldID), | 144 field_element->SetAttr(buzz::QName(kAttributeFieldID), |
145 field.FieldSignature()); | 145 field.FieldSignature()); |
146 field_element->SetAttr(buzz::QName(kAttributeFieldType), | 146 field_element->SetAttr(buzz::QName(kAttributeFieldType), |
147 base::IntToString(*field_type)); | 147 base::IntToString(*field_type)); |
148 field_element->SetAttr(buzz::QName(kAttributeName), | 148 field_element->SetAttr(buzz::QName(kAttributeName), |
149 UTF16ToUTF8(field.name)); | 149 base::UTF16ToUTF8(field.name)); |
150 parent->AddElement(field_element); | 150 parent->AddElement(field_element); |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 // Returns |true| iff the |token| is a type hint for a contact field, as | 154 // Returns |true| iff the |token| is a type hint for a contact field, as |
155 // specified in the implementation section of http://is.gd/whatwg_autocomplete | 155 // specified in the implementation section of http://is.gd/whatwg_autocomplete |
156 // Note that "fax" and "pager" are intentionally ignored, as Chrome does not | 156 // Note that "fax" and "pager" are intentionally ignored, as Chrome does not |
157 // support filling either type of information. | 157 // support filling either type of information. |
158 bool IsContactTypeHint(const std::string& token) { | 158 bool IsContactTypeHint(const std::string& token) { |
159 return token == "home" || token == "work" || token == "mobile"; | 159 return token == "home" || token == "work" || token == "mobile"; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 (icu_pattern, UREGEX_CASE_INSENSITIVE, status)); | 301 (icu_pattern, UREGEX_CASE_INSENSITIVE, status)); |
302 DCHECK_EQ(status, U_ZERO_ERROR); | 302 DCHECK_EQ(status, U_ZERO_ERROR); |
303 | 303 |
304 icu::UnicodeString icu_input(input.data(), input.length()); | 304 icu::UnicodeString icu_input(input.data(), input.length()); |
305 matcher.reset(icu_input); | 305 matcher.reset(icu_input); |
306 | 306 |
307 icu::UnicodeString replaced_string = matcher.replaceAll("", status); | 307 icu::UnicodeString replaced_string = matcher.replaceAll("", status); |
308 | 308 |
309 std::string return_string; | 309 std::string return_string; |
310 status = U_ZERO_ERROR; | 310 status = U_ZERO_ERROR; |
311 UTF16ToUTF8(replaced_string.getBuffer(), | 311 base::UTF16ToUTF8(replaced_string.getBuffer(), |
312 static_cast<size_t>(replaced_string.length()), | 312 static_cast<size_t>(replaced_string.length()), |
313 &return_string); | 313 &return_string); |
314 if (status != U_ZERO_ERROR) { | 314 if (status != U_ZERO_ERROR) { |
315 DVLOG(1) << "Couldn't strip digits in " << UTF16ToUTF8(input); | 315 DVLOG(1) << "Couldn't strip digits in " << base::UTF16ToUTF8(input); |
316 return UTF16ToUTF8(input); | 316 return base::UTF16ToUTF8(input); |
317 } | 317 } |
318 | 318 |
319 return return_string; | 319 return return_string; |
320 } | 320 } |
321 | 321 |
322 } // namespace | 322 } // namespace |
323 | 323 |
324 FormStructure::FormStructure(const FormData& form) | 324 FormStructure::FormStructure(const FormData& form) |
325 : form_name_(form.name), | 325 : form_name_(form.name), |
326 source_url_(form.origin), | 326 source_url_(form.origin), |
(...skipping 17 matching lines...) Expand all Loading... |
344 ++active_field_count_; | 344 ++active_field_count_; |
345 } | 345 } |
346 | 346 |
347 // Generate a unique name for this field by appending a counter to the name. | 347 // Generate a unique name for this field by appending a counter to the name. |
348 // Make sure to prepend the counter with a non-numeric digit so that we are | 348 // Make sure to prepend the counter with a non-numeric digit so that we are |
349 // guaranteed to avoid collisions. | 349 // guaranteed to avoid collisions. |
350 if (!unique_names.count(field->name)) | 350 if (!unique_names.count(field->name)) |
351 unique_names[field->name] = 1; | 351 unique_names[field->name] = 1; |
352 else | 352 else |
353 ++unique_names[field->name]; | 353 ++unique_names[field->name]; |
354 base::string16 unique_name = field->name + ASCIIToUTF16("_") + | 354 base::string16 unique_name = field->name + base::ASCIIToUTF16("_") + |
355 base::IntToString16(unique_names[field->name]); | 355 base::IntToString16(unique_names[field->name]); |
356 fields_.push_back(new AutofillField(*field, unique_name)); | 356 fields_.push_back(new AutofillField(*field, unique_name)); |
357 } | 357 } |
358 | 358 |
359 std::string method = UTF16ToUTF8(form.method); | 359 std::string method = base::UTF16ToUTF8(form.method); |
360 if (StringToLowerASCII(method) == kFormMethodPost) { | 360 if (StringToLowerASCII(method) == kFormMethodPost) { |
361 method_ = POST; | 361 method_ = POST; |
362 } else { | 362 } else { |
363 // Either the method is 'get', or we don't know. In this case we default | 363 // Either the method is 'get', or we don't know. In this case we default |
364 // to GET. | 364 // to GET. |
365 method_ = GET; | 365 method_ = GET; |
366 } | 366 } |
367 } | 367 } |
368 | 368 |
369 FormStructure::~FormStructure() {} | 369 FormStructure::~FormStructure() {} |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 void FormStructure::GetFieldTypePredictions( | 607 void FormStructure::GetFieldTypePredictions( |
608 const std::vector<FormStructure*>& form_structures, | 608 const std::vector<FormStructure*>& form_structures, |
609 std::vector<FormDataPredictions>* forms) { | 609 std::vector<FormDataPredictions>* forms) { |
610 forms->clear(); | 610 forms->clear(); |
611 forms->reserve(form_structures.size()); | 611 forms->reserve(form_structures.size()); |
612 for (size_t i = 0; i < form_structures.size(); ++i) { | 612 for (size_t i = 0; i < form_structures.size(); ++i) { |
613 FormStructure* form_structure = form_structures[i]; | 613 FormStructure* form_structure = form_structures[i]; |
614 FormDataPredictions form; | 614 FormDataPredictions form; |
615 form.data.name = form_structure->form_name_; | 615 form.data.name = form_structure->form_name_; |
616 form.data.method = | 616 form.data.method = |
617 ASCIIToUTF16((form_structure->method_ == POST) ? "POST" : "GET"); | 617 base::ASCIIToUTF16((form_structure->method_ == POST) ? "POST" : "GET"); |
618 form.data.origin = form_structure->source_url_; | 618 form.data.origin = form_structure->source_url_; |
619 form.data.action = form_structure->target_url_; | 619 form.data.action = form_structure->target_url_; |
620 form.signature = form_structure->FormSignature(); | 620 form.signature = form_structure->FormSignature(); |
621 form.experiment_id = form_structure->server_experiment_id_; | 621 form.experiment_id = form_structure->server_experiment_id_; |
622 | 622 |
623 for (std::vector<AutofillField*>::const_iterator field = | 623 for (std::vector<AutofillField*>::const_iterator field = |
624 form_structure->fields_.begin(); | 624 form_structure->fields_.begin(); |
625 field != form_structure->fields_.end(); ++field) { | 625 field != form_structure->fields_.end(); ++field) { |
626 form.data.fields.push_back(FormFieldData(**field)); | 626 form.data.fields.push_back(FormFieldData(**field)); |
627 | 627 |
(...skipping 16 matching lines...) Expand all Loading... |
644 std::string host(target_url_.host()); | 644 std::string host(target_url_.host()); |
645 | 645 |
646 // If target host or scheme is empty, set scheme and host of source url. | 646 // If target host or scheme is empty, set scheme and host of source url. |
647 // This is done to match the Toolbar's behavior. | 647 // This is done to match the Toolbar's behavior. |
648 if (scheme.empty() || host.empty()) { | 648 if (scheme.empty() || host.empty()) { |
649 scheme = source_url_.scheme(); | 649 scheme = source_url_.scheme(); |
650 host = source_url_.host(); | 650 host = source_url_.host(); |
651 } | 651 } |
652 | 652 |
653 std::string form_string = scheme + "://" + host + "&" + | 653 std::string form_string = scheme + "://" + host + "&" + |
654 UTF16ToUTF8(form_name_) + | 654 base::UTF16ToUTF8(form_name_) + |
655 form_signature_field_names_; | 655 form_signature_field_names_; |
656 | 656 |
657 return Hash64Bit(form_string); | 657 return Hash64Bit(form_string); |
658 } | 658 } |
659 | 659 |
660 bool FormStructure::ShouldSkipField(const FormFieldData& field) const { | 660 bool FormStructure::ShouldSkipField(const FormFieldData& field) const { |
661 return field.is_checkable; | 661 return field.is_checkable; |
662 } | 662 } |
663 | 663 |
664 bool FormStructure::IsAutofillable(bool require_method_post) const { | 664 bool FormStructure::IsAutofillable(bool require_method_post) const { |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 std::string FormStructure::server_experiment_id() const { | 955 std::string FormStructure::server_experiment_id() const { |
956 return server_experiment_id_; | 956 return server_experiment_id_; |
957 } | 957 } |
958 | 958 |
959 FormData FormStructure::ToFormData() const { | 959 FormData FormStructure::ToFormData() const { |
960 // |data.user_submitted| will always be false. | 960 // |data.user_submitted| will always be false. |
961 FormData data; | 961 FormData data; |
962 data.name = form_name_; | 962 data.name = form_name_; |
963 data.origin = source_url_; | 963 data.origin = source_url_; |
964 data.action = target_url_; | 964 data.action = target_url_; |
965 data.method = ASCIIToUTF16(method_ == POST ? "POST" : "GET"); | 965 data.method = base::ASCIIToUTF16(method_ == POST ? "POST" : "GET"); |
966 | 966 |
967 for (size_t i = 0; i < fields_.size(); ++i) { | 967 for (size_t i = 0; i < fields_.size(); ++i) { |
968 data.fields.push_back(FormFieldData(*fields_[i])); | 968 data.fields.push_back(FormFieldData(*fields_[i])); |
969 } | 969 } |
970 | 970 |
971 return data; | 971 return data; |
972 } | 972 } |
973 | 973 |
974 bool FormStructure::operator==(const FormData& form) const { | 974 bool FormStructure::operator==(const FormData& form) const { |
975 // TODO(jhawkins): Is this enough to differentiate a form? | 975 // TODO(jhawkins): Is this enough to differentiate a form? |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1188 | 1188 |
1189 previous_type = current_type; | 1189 previous_type = current_type; |
1190 | 1190 |
1191 if (current_type != UNKNOWN_TYPE && already_saw_current_type) { | 1191 if (current_type != UNKNOWN_TYPE && already_saw_current_type) { |
1192 // We reached the end of a section, so start a new section. | 1192 // We reached the end of a section, so start a new section. |
1193 seen_types.clear(); | 1193 seen_types.clear(); |
1194 current_section = (*field)->unique_name(); | 1194 current_section = (*field)->unique_name(); |
1195 } | 1195 } |
1196 | 1196 |
1197 seen_types.insert(current_type); | 1197 seen_types.insert(current_type); |
1198 (*field)->set_section(UTF16ToUTF8(current_section)); | 1198 (*field)->set_section(base::UTF16ToUTF8(current_section)); |
1199 } | 1199 } |
1200 } | 1200 } |
1201 | 1201 |
1202 // Ensure that credit card and address fields are in separate sections. | 1202 // Ensure that credit card and address fields are in separate sections. |
1203 // This simplifies the section-aware logic in autofill_manager.cc. | 1203 // This simplifies the section-aware logic in autofill_manager.cc. |
1204 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1204 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
1205 field != fields_.end(); ++field) { | 1205 field != fields_.end(); ++field) { |
1206 FieldTypeGroup field_type_group = (*field)->Type().group(); | 1206 FieldTypeGroup field_type_group = (*field)->Type().group(); |
1207 if (field_type_group == CREDIT_CARD) | 1207 if (field_type_group == CREDIT_CARD) |
1208 (*field)->set_section((*field)->section() + "-cc"); | 1208 (*field)->set_section((*field)->section() + "-cc"); |
1209 else | 1209 else |
1210 (*field)->set_section((*field)->section() + "-default"); | 1210 (*field)->set_section((*field)->section() + "-default"); |
1211 } | 1211 } |
1212 } | 1212 } |
1213 | 1213 |
1214 } // namespace autofill | 1214 } // namespace autofill |
OLD | NEW |