| 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 288 } |
| 289 | 289 |
| 290 bool IsCreditCardExpirationType(ServerFieldType type) { | 290 bool IsCreditCardExpirationType(ServerFieldType type) { |
| 291 return type == CREDIT_CARD_EXP_MONTH || | 291 return type == CREDIT_CARD_EXP_MONTH || |
| 292 type == CREDIT_CARD_EXP_2_DIGIT_YEAR || | 292 type == CREDIT_CARD_EXP_2_DIGIT_YEAR || |
| 293 type == CREDIT_CARD_EXP_4_DIGIT_YEAR || | 293 type == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
| 294 type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || | 294 type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || |
| 295 type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR; | 295 type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR; |
| 296 } | 296 } |
| 297 | 297 |
| 298 // Returns true iff all form fields autofill types are in |contained_types|. |
| 299 bool AllTypesCaptured(const FormStructure& form, |
| 300 const ServerFieldTypeSet& contained_types) { |
| 301 for (const auto& field : form) { |
| 302 for (const auto& type : field->possible_types()) { |
| 303 if (type != UNKNOWN_TYPE && type != EMPTY_TYPE && |
| 304 !contained_types.count(type)) |
| 305 return false; |
| 306 } |
| 307 } |
| 308 return true; |
| 309 } |
| 310 |
| 298 } // namespace | 311 } // namespace |
| 299 | 312 |
| 300 FormStructure::FormStructure(const FormData& form) | 313 FormStructure::FormStructure(const FormData& form) |
| 301 : form_name_(form.name), | 314 : form_name_(form.name), |
| 302 source_url_(form.origin), | 315 source_url_(form.origin), |
| 303 target_url_(form.action), | 316 target_url_(form.action), |
| 304 autofill_count_(0), | 317 autofill_count_(0), |
| 305 active_field_count_(0), | 318 active_field_count_(0), |
| 306 upload_required_(USE_UPLOAD_RATES), | 319 upload_required_(USE_UPLOAD_RATES), |
| 307 has_author_specified_types_(false), | 320 has_author_specified_types_(false), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 base::TimeTicks::Now() - determine_heuristic_types_start_time); | 401 base::TimeTicks::Now() - determine_heuristic_types_start_time); |
| 389 } | 402 } |
| 390 | 403 |
| 391 bool FormStructure::EncodeUploadRequest( | 404 bool FormStructure::EncodeUploadRequest( |
| 392 const ServerFieldTypeSet& available_field_types, | 405 const ServerFieldTypeSet& available_field_types, |
| 393 bool form_was_autofilled, | 406 bool form_was_autofilled, |
| 394 const std::string& login_form_signature, | 407 const std::string& login_form_signature, |
| 395 bool observed_submission, | 408 bool observed_submission, |
| 396 AutofillUploadContents* upload) const { | 409 AutofillUploadContents* upload) const { |
| 397 DCHECK(ShouldBeCrowdsourced()); | 410 DCHECK(ShouldBeCrowdsourced()); |
| 398 | 411 DCHECK(AllTypesCaptured(*this, available_field_types)); |
| 399 // Verify that |available_field_types| agrees with the possible field types we | |
| 400 // are uploading. | |
| 401 for (const auto& field : *this) { | |
| 402 for (const auto& type : field->possible_types()) { | |
| 403 DCHECK(type == UNKNOWN_TYPE || type == EMPTY_TYPE || | |
| 404 available_field_types.count(type)); | |
| 405 } | |
| 406 } | |
| 407 | 412 |
| 408 upload->set_submission(observed_submission); | 413 upload->set_submission(observed_submission); |
| 409 upload->set_client_version(kClientVersion); | 414 upload->set_client_version(kClientVersion); |
| 410 upload->set_form_signature(form_signature()); | 415 upload->set_form_signature(form_signature()); |
| 411 upload->set_autofill_used(form_was_autofilled); | 416 upload->set_autofill_used(form_was_autofilled); |
| 412 upload->set_data_present(EncodeFieldTypes(available_field_types)); | 417 upload->set_data_present(EncodeFieldTypes(available_field_types)); |
| 413 | 418 |
| 414 if (IsAutofillFieldMetadataEnabled()) { | 419 if (IsAutofillFieldMetadataEnabled()) { |
| 415 upload->set_action_signature(StrToHash64Bit(target_url_.host())); | 420 upload->set_action_signature(StrToHash64Bit(target_url_.host())); |
| 416 if (!form_name().empty()) | 421 if (!form_name().empty()) |
| (...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 filtered_strings[0].at(prefix_len)) { | 1381 filtered_strings[0].at(prefix_len)) { |
| 1377 // Mismatch found. | 1382 // Mismatch found. |
| 1378 return filtered_strings[i].substr(0, prefix_len); | 1383 return filtered_strings[i].substr(0, prefix_len); |
| 1379 } | 1384 } |
| 1380 } | 1385 } |
| 1381 } | 1386 } |
| 1382 return filtered_strings[0]; | 1387 return filtered_strings[0]; |
| 1383 } | 1388 } |
| 1384 | 1389 |
| 1385 } // namespace autofill | 1390 } // namespace autofill |
| OLD | NEW |