| 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/content/browser/autocheckout_manager.h" | 5 #include "components/autofill/content/browser/autocheckout_manager.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/autofill/content/browser/autocheckout_request_manager.h" | 10 #include "components/autofill/content/browser/autocheckout_request_manager.h" |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 metric_logger_->LogAutocheckoutBuyFlowMetric( | 349 metric_logger_->LogAutocheckoutBuyFlowMetric( |
| 350 AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_STARTED); | 350 AutofillMetrics::AUTOCHECKOUT_BUY_FLOW_STARTED); |
| 351 | 351 |
| 352 profile_.reset(new AutofillProfile()); | 352 profile_.reset(new AutofillProfile()); |
| 353 credit_card_.reset(new CreditCard()); | 353 credit_card_.reset(new CreditCard()); |
| 354 billing_address_.reset(new AutofillProfile()); | 354 billing_address_.reset(new AutofillProfile()); |
| 355 | 355 |
| 356 for (size_t i = 0; i < result->field_count(); ++i) { | 356 for (size_t i = 0; i < result->field_count(); ++i) { |
| 357 const AutofillType& type = result->field(i)->Type(); | 357 const AutofillType& type = result->field(i)->Type(); |
| 358 const base::string16& value = result->field(i)->value; | 358 const base::string16& value = result->field(i)->value; |
| 359 if (type.server_type() == CREDIT_CARD_VERIFICATION_CODE) { | 359 ServerFieldType server_type = type.GetStorableType(); |
| 360 if (server_type == CREDIT_CARD_VERIFICATION_CODE) { |
| 360 cvv_ = result->field(i)->value; | 361 cvv_ = result->field(i)->value; |
| 361 continue; | 362 continue; |
| 362 } | 363 } |
| 363 FieldTypeGroup group = type.group(); | 364 FieldTypeGroup group = type.group(); |
| 364 if (group == CREDIT_CARD) { | 365 if (group == CREDIT_CARD) { |
| 365 credit_card_->SetRawInfo(type.server_type(), value); | 366 credit_card_->SetRawInfo(server_type, value); |
| 366 // TODO(dgwallinga): Find a way of cleanly deprecating CREDIT_CARD_NAME. | 367 // TODO(dgwallinga): Find a way of cleanly deprecating CREDIT_CARD_NAME. |
| 367 // code.google.com/p/chromium/issues/detail?id=263498 | 368 // code.google.com/p/chromium/issues/detail?id=263498 |
| 368 if (type.server_type() == CREDIT_CARD_NAME) | 369 if (server_type == CREDIT_CARD_NAME) |
| 369 billing_address_->SetRawInfo(NAME_BILLING_FULL, value); | 370 billing_address_->SetRawInfo(NAME_BILLING_FULL, value); |
| 370 } else if (type.server_type() == ADDRESS_HOME_COUNTRY) { | 371 } else if (server_type == ADDRESS_HOME_COUNTRY) { |
| 371 profile_->SetInfo(type, value, autofill_manager_->app_locale()); | 372 if (IsBillingGroup(group)) |
| 372 } else if (type.server_type() == ADDRESS_BILLING_COUNTRY) { | 373 billing_address_->SetInfo(type, value, autofill_manager_->app_locale()); |
| 373 billing_address_->SetInfo(type, value, autofill_manager_->app_locale()); | 374 else |
| 375 profile_->SetInfo(type, value, autofill_manager_->app_locale()); |
| 374 } else if (IsBillingGroup(group)) { | 376 } else if (IsBillingGroup(group)) { |
| 375 billing_address_->SetRawInfo(type.server_type(), value); | 377 billing_address_->SetRawInfo(server_type, value); |
| 376 } else { | 378 } else { |
| 377 profile_->SetRawInfo(type.server_type(), value); | 379 profile_->SetRawInfo(server_type, value); |
| 378 } | 380 } |
| 379 } | 381 } |
| 380 | 382 |
| 381 // Page types only available in first-page meta data, so save | 383 // Page types only available in first-page meta data, so save |
| 382 // them for use later as we navigate. | 384 // them for use later as we navigate. |
| 383 page_types_ = page_meta_data_->page_types; | 385 page_types_ = page_meta_data_->page_types; |
| 384 SetStepProgressForPage(page_meta_data_->current_page_number, | 386 SetStepProgressForPage(page_meta_data_->current_page_number, |
| 385 AUTOCHECKOUT_STEP_STARTED); | 387 AUTOCHECKOUT_STEP_STARTED); |
| 386 | 388 |
| 387 FillForms(); | 389 FillForms(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 } | 449 } |
| 448 | 450 |
| 449 void AutocheckoutManager::SetValue(const AutofillField& field, | 451 void AutocheckoutManager::SetValue(const AutofillField& field, |
| 450 FormFieldData* field_to_fill) { | 452 FormFieldData* field_to_fill) { |
| 451 // No-op if Autofill server doesn't know about the field. | 453 // No-op if Autofill server doesn't know about the field. |
| 452 if (field.server_type() == NO_SERVER_DATA) | 454 if (field.server_type() == NO_SERVER_DATA) |
| 453 return; | 455 return; |
| 454 | 456 |
| 455 const AutofillType& type = field.Type(); | 457 const AutofillType& type = field.Type(); |
| 456 | 458 |
| 457 if (type.server_type() == FIELD_WITH_DEFAULT_VALUE) { | 459 ServerFieldType server_type = type.GetStorableType(); |
| 460 if (server_type == FIELD_WITH_DEFAULT_VALUE) { |
| 458 // For a form with radio buttons, like: | 461 // For a form with radio buttons, like: |
| 459 // <form> | 462 // <form> |
| 460 // <input type="radio" name="sex" value="male">Male<br> | 463 // <input type="radio" name="sex" value="male">Male<br> |
| 461 // <input type="radio" name="sex" value="female">Female | 464 // <input type="radio" name="sex" value="female">Female |
| 462 // </form> | 465 // </form> |
| 463 // If the default value specified at the server is "female", then | 466 // If the default value specified at the server is "female", then |
| 464 // Autofill server responds back with following field mappings | 467 // Autofill server responds back with following field mappings |
| 465 // (fieldtype: FIELD_WITH_DEFAULT_VALUE, value: "female") | 468 // (fieldtype: FIELD_WITH_DEFAULT_VALUE, value: "female") |
| 466 // (fieldtype: FIELD_WITH_DEFAULT_VALUE, value: "female") | 469 // (fieldtype: FIELD_WITH_DEFAULT_VALUE, value: "female") |
| 467 // Note that, the field mapping is repeated twice to respond to both the | 470 // Note that, the field mapping is repeated twice to respond to both the |
| (...skipping 13 matching lines...) Expand all Loading... |
| 481 } else if (field.form_control_type == "select-one") { | 484 } else if (field.form_control_type == "select-one") { |
| 482 field_to_fill->value = default_value; | 485 field_to_fill->value = default_value; |
| 483 } else { | 486 } else { |
| 484 // FIELD_WITH_DEFAULT_VALUE should not be used for other type of fields. | 487 // FIELD_WITH_DEFAULT_VALUE should not be used for other type of fields. |
| 485 NOTREACHED(); | 488 NOTREACHED(); |
| 486 } | 489 } |
| 487 return; | 490 return; |
| 488 } | 491 } |
| 489 | 492 |
| 490 // Handle verification code directly. | 493 // Handle verification code directly. |
| 491 if (type.server_type() == CREDIT_CARD_VERIFICATION_CODE) { | 494 if (server_type == CREDIT_CARD_VERIFICATION_CODE) { |
| 492 field_to_fill->value = cvv_; | 495 field_to_fill->value = cvv_; |
| 493 return; | 496 return; |
| 494 } | 497 } |
| 495 | 498 |
| 496 if (type.group() == CREDIT_CARD) { | 499 if (type.group() == CREDIT_CARD) { |
| 497 credit_card_->FillFormField( | 500 credit_card_->FillFormField( |
| 498 field, 0, autofill_manager_->app_locale(), field_to_fill); | 501 field, 0, autofill_manager_->app_locale(), field_to_fill); |
| 499 } else if (IsBillingGroup(type.group())) { | 502 } else if (IsBillingGroup(type.group())) { |
| 500 billing_address_->FillFormField( | 503 billing_address_->FillFormField( |
| 501 field, 0, autofill_manager_->app_locale(), field_to_fill); | 504 field, 0, autofill_manager_->app_locale(), field_to_fill); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 | 572 |
| 570 SendAutocheckoutStatus(status); | 573 SendAutocheckoutStatus(status); |
| 571 if (status == SUCCESS) | 574 if (status == SUCCESS) |
| 572 autofill_manager_->delegate()->OnAutocheckoutSuccess(); | 575 autofill_manager_->delegate()->OnAutocheckoutSuccess(); |
| 573 else | 576 else |
| 574 autofill_manager_->delegate()->OnAutocheckoutError(); | 577 autofill_manager_->delegate()->OnAutocheckoutError(); |
| 575 in_autocheckout_flow_ = false; | 578 in_autocheckout_flow_ = false; |
| 576 } | 579 } |
| 577 | 580 |
| 578 } // namespace autofill | 581 } // namespace autofill |
| OLD | NEW |