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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // a minimum prefix length. These values are chosen to avoid cases such as two | 53 // a minimum prefix length. These values are chosen to avoid cases such as two |
54 // fields with "address1" and "address2" and be effective against web frameworks | 54 // fields with "address1" and "address2" and be effective against web frameworks |
55 // which prepend prefixes such as "ctl01$ctl00$MainContentRegion$" on all | 55 // which prepend prefixes such as "ctl01$ctl00$MainContentRegion$" on all |
56 // fields. | 56 // fields. |
57 const int kCommonNamePrefixRemovalFieldThreshold = 3; | 57 const int kCommonNamePrefixRemovalFieldThreshold = 3; |
58 const int kMinCommonNamePrefixLength = 16; | 58 const int kMinCommonNamePrefixLength = 16; |
59 | 59 |
60 // Maximum number of characters in the field label to be encoded in a proto. | 60 // Maximum number of characters in the field label to be encoded in a proto. |
61 const int kMaxFieldLabelNumChars = 200; | 61 const int kMaxFieldLabelNumChars = 200; |
62 | 62 |
63 // Returns whether sending autofill field metadata to the server is enabled. | |
64 bool IsAutofillFieldMetadataEnabled() { | |
65 const std::string group_name = | |
66 base::FieldTrialList::FindFullName("AutofillFieldMetadata"); | |
67 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); | |
68 } | |
69 | |
70 // Helper for |EncodeUploadRequest()| that creates a bit field corresponding to | 63 // Helper for |EncodeUploadRequest()| that creates a bit field corresponding to |
71 // |available_field_types| and returns the hex representation as a string. | 64 // |available_field_types| and returns the hex representation as a string. |
72 std::string EncodeFieldTypes(const ServerFieldTypeSet& available_field_types) { | 65 std::string EncodeFieldTypes(const ServerFieldTypeSet& available_field_types) { |
73 // There are |MAX_VALID_FIELD_TYPE| different field types and 8 bits per byte, | 66 // There are |MAX_VALID_FIELD_TYPE| different field types and 8 bits per byte, |
74 // so we need ceil(MAX_VALID_FIELD_TYPE / 8) bytes to encode the bit field. | 67 // so we need ceil(MAX_VALID_FIELD_TYPE / 8) bytes to encode the bit field. |
75 const size_t kNumBytes = (MAX_VALID_FIELD_TYPE + 0x7) / 8; | 68 const size_t kNumBytes = (MAX_VALID_FIELD_TYPE + 0x7) / 8; |
76 | 69 |
77 // Pack the types in |available_field_types| into |bit_field|. | 70 // Pack the types in |available_field_types| into |bit_field|. |
78 std::vector<uint8_t> bit_field(kNumBytes, 0); | 71 std::vector<uint8_t> bit_field(kNumBytes, 0); |
79 for (const auto& field_type : available_field_types) { | 72 for (const auto& field_type : available_field_types) { |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 annotated_field.parseable_name = | 558 annotated_field.parseable_name = |
566 base::UTF16ToUTF8(field->parseable_name()); | 559 base::UTF16ToUTF8(field->parseable_name()); |
567 form.fields.push_back(annotated_field); | 560 form.fields.push_back(annotated_field); |
568 } | 561 } |
569 | 562 |
570 forms.push_back(form); | 563 forms.push_back(form); |
571 } | 564 } |
572 return forms; | 565 return forms; |
573 } | 566 } |
574 | 567 |
| 568 // static |
| 569 bool FormStructure::IsAutofillFieldMetadataEnabled() { |
| 570 const std::string group_name = |
| 571 base::FieldTrialList::FindFullName("AutofillFieldMetadata"); |
| 572 return base::StartsWith(group_name, "Enabled", base::CompareCase::SENSITIVE); |
| 573 } |
| 574 |
575 std::string FormStructure::FormSignature() const { | 575 std::string FormStructure::FormSignature() const { |
576 return base::Uint64ToString(FormSignature64Bit()); | 576 return base::Uint64ToString(FormSignature64Bit()); |
577 } | 577 } |
578 | 578 |
579 bool FormStructure::IsAutofillable() const { | 579 bool FormStructure::IsAutofillable() const { |
580 if (autofill_count() < kRequiredFieldsForPredictionRoutines) | 580 if (autofill_count() < kRequiredFieldsForPredictionRoutines) |
581 return false; | 581 return false; |
582 | 582 |
583 return ShouldBeParsed(); | 583 return ShouldBeParsed(); |
584 } | 584 } |
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 filtered_strings[0].at(prefix_len)) { | 1365 filtered_strings[0].at(prefix_len)) { |
1366 // Mismatch found. | 1366 // Mismatch found. |
1367 return filtered_strings[i].substr(0, prefix_len); | 1367 return filtered_strings[i].substr(0, prefix_len); |
1368 } | 1368 } |
1369 } | 1369 } |
1370 } | 1370 } |
1371 return filtered_strings[0]; | 1371 return filtered_strings[0]; |
1372 } | 1372 } |
1373 | 1373 |
1374 } // namespace autofill | 1374 } // namespace autofill |
OLD | NEW |