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" |
11 #include "components/autofill/content/browser/autocheckout_statistic.h" | 11 #include "components/autofill/content/browser/autocheckout_statistic.h" |
12 #include "components/autofill/content/browser/autocheckout_steps.h" | 12 #include "components/autofill/content/browser/autocheckout_steps.h" |
13 #include "components/autofill/core/browser/autofill_country.h" | 13 #include "components/autofill/core/browser/autofill_country.h" |
14 #include "components/autofill/core/browser/autofill_field.h" | 14 #include "components/autofill/core/browser/autofill_field.h" |
15 #include "components/autofill/core/browser/autofill_manager.h" | 15 #include "components/autofill/core/browser/autofill_manager.h" |
16 #include "components/autofill/core/browser/autofill_metrics.h" | 16 #include "components/autofill/core/browser/autofill_metrics.h" |
17 #include "components/autofill/core/browser/autofill_profile.h" | 17 #include "components/autofill/core/browser/autofill_profile.h" |
| 18 #include "components/autofill/core/browser/autofill_type.h" |
18 #include "components/autofill/core/browser/credit_card.h" | 19 #include "components/autofill/core/browser/credit_card.h" |
19 #include "components/autofill/core/browser/field_types.h" | |
20 #include "components/autofill/core/browser/form_structure.h" | 20 #include "components/autofill/core/browser/form_structure.h" |
21 #include "components/autofill/core/common/autofill_messages.h" | 21 #include "components/autofill/core/common/autofill_messages.h" |
22 #include "components/autofill/core/common/form_data.h" | 22 #include "components/autofill/core/common/form_data.h" |
23 #include "components/autofill/core/common/form_field_data.h" | 23 #include "components/autofill/core/common/form_field_data.h" |
24 #include "components/autofill/core/common/web_element_descriptor.h" | 24 #include "components/autofill/core/common/web_element_descriptor.h" |
25 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/render_view_host.h" | 27 #include "content/public/browser/render_view_host.h" |
28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
29 #include "net/cookies/cookie_options.h" | 29 #include "net/cookies/cookie_options.h" |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 in_autocheckout_flow_ = true; | 347 in_autocheckout_flow_ = true; |
348 should_preserve_dialog_ = true; | 348 should_preserve_dialog_ = true; |
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 AutofillFieldType 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 == CREDIT_CARD_VERIFICATION_CODE) { | 359 if (type.server_type() == CREDIT_CARD_VERIFICATION_CODE) { |
360 cvv_ = result->field(i)->value; | 360 cvv_ = result->field(i)->value; |
361 continue; | 361 continue; |
362 } | 362 } |
363 FieldTypeGroup group = AutofillType(type).group(); | 363 FieldTypeGroup group = type.group(); |
364 if (group == CREDIT_CARD) { | 364 if (group == CREDIT_CARD) { |
365 credit_card_->SetRawInfo(type, value); | 365 credit_card_->SetRawInfo(type.server_type(), value); |
366 // TODO(dgwallinga): Find a way of cleanly deprecating CREDIT_CARD_NAME. | 366 // TODO(dgwallinga): Find a way of cleanly deprecating CREDIT_CARD_NAME. |
367 // code.google.com/p/chromium/issues/detail?id=263498 | 367 // code.google.com/p/chromium/issues/detail?id=263498 |
368 if (type == CREDIT_CARD_NAME) | 368 if (type.server_type() == CREDIT_CARD_NAME) |
369 billing_address_->SetRawInfo(NAME_BILLING_FULL, value); | 369 billing_address_->SetRawInfo(NAME_BILLING_FULL, value); |
370 } else if (type == ADDRESS_HOME_COUNTRY) { | 370 } else if (type.server_type() == ADDRESS_HOME_COUNTRY) { |
371 profile_->SetInfo(type, value, autofill_manager_->app_locale()); | 371 profile_->SetInfo(type, value, autofill_manager_->app_locale()); |
372 } else if (type == ADDRESS_BILLING_COUNTRY) { | 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 if (IsBillingGroup(group)) { | 374 } else if (IsBillingGroup(group)) { |
375 billing_address_->SetRawInfo(type, value); | 375 billing_address_->SetRawInfo(type.server_type(), value); |
376 } else { | 376 } else { |
377 profile_->SetRawInfo(type, value); | 377 profile_->SetRawInfo(type.server_type(), value); |
378 } | 378 } |
379 } | 379 } |
380 | 380 |
381 // Page types only available in first-page meta data, so save | 381 // Page types only available in first-page meta data, so save |
382 // them for use later as we navigate. | 382 // them for use later as we navigate. |
383 page_types_ = page_meta_data_->page_types; | 383 page_types_ = page_meta_data_->page_types; |
384 SetStepProgressForPage(page_meta_data_->current_page_number, | 384 SetStepProgressForPage(page_meta_data_->current_page_number, |
385 AUTOCHECKOUT_STEP_STARTED); | 385 AUTOCHECKOUT_STEP_STARTED); |
386 | 386 |
387 FillForms(); | 387 FillForms(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 bool AutocheckoutManager::IsInAutofillableFlow() const { | 445 bool AutocheckoutManager::IsInAutofillableFlow() const { |
446 return page_meta_data_ && page_meta_data_->IsInAutofillableFlow(); | 446 return page_meta_data_ && page_meta_data_->IsInAutofillableFlow(); |
447 } | 447 } |
448 | 448 |
449 void AutocheckoutManager::SetValue(const AutofillField& field, | 449 void AutocheckoutManager::SetValue(const AutofillField& field, |
450 FormFieldData* field_to_fill) { | 450 FormFieldData* field_to_fill) { |
451 // No-op if Autofill server doesn't know about the field. | 451 // No-op if Autofill server doesn't know about the field. |
452 if (field.server_type() == NO_SERVER_DATA) | 452 if (field.server_type() == NO_SERVER_DATA) |
453 return; | 453 return; |
454 | 454 |
455 AutofillFieldType type = field.type(); | 455 const AutofillType& type = field.Type(); |
456 | 456 |
457 if (type == FIELD_WITH_DEFAULT_VALUE) { | 457 if (type.server_type() == FIELD_WITH_DEFAULT_VALUE) { |
458 // For a form with radio buttons, like: | 458 // For a form with radio buttons, like: |
459 // <form> | 459 // <form> |
460 // <input type="radio" name="sex" value="male">Male<br> | 460 // <input type="radio" name="sex" value="male">Male<br> |
461 // <input type="radio" name="sex" value="female">Female | 461 // <input type="radio" name="sex" value="female">Female |
462 // </form> | 462 // </form> |
463 // If the default value specified at the server is "female", then | 463 // If the default value specified at the server is "female", then |
464 // Autofill server responds back with following field mappings | 464 // Autofill server responds back with following field mappings |
465 // (fieldtype: FIELD_WITH_DEFAULT_VALUE, value: "female") | 465 // (fieldtype: FIELD_WITH_DEFAULT_VALUE, value: "female") |
466 // (fieldtype: FIELD_WITH_DEFAULT_VALUE, value: "female") | 466 // (fieldtype: FIELD_WITH_DEFAULT_VALUE, value: "female") |
467 // Note that, the field mapping is repeated twice to respond to both the | 467 // 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") { | 481 } else if (field.form_control_type == "select-one") { |
482 field_to_fill->value = default_value; | 482 field_to_fill->value = default_value; |
483 } else { | 483 } else { |
484 // FIELD_WITH_DEFAULT_VALUE should not be used for other type of fields. | 484 // FIELD_WITH_DEFAULT_VALUE should not be used for other type of fields. |
485 NOTREACHED(); | 485 NOTREACHED(); |
486 } | 486 } |
487 return; | 487 return; |
488 } | 488 } |
489 | 489 |
490 // Handle verification code directly. | 490 // Handle verification code directly. |
491 if (type == CREDIT_CARD_VERIFICATION_CODE) { | 491 if (type.server_type() == CREDIT_CARD_VERIFICATION_CODE) { |
492 field_to_fill->value = cvv_; | 492 field_to_fill->value = cvv_; |
493 return; | 493 return; |
494 } | 494 } |
495 | 495 |
496 if (AutofillType(type).group() == CREDIT_CARD) { | 496 if (type.group() == CREDIT_CARD) { |
497 credit_card_->FillFormField( | 497 credit_card_->FillFormField( |
498 field, 0, autofill_manager_->app_locale(), field_to_fill); | 498 field, 0, autofill_manager_->app_locale(), field_to_fill); |
499 } else if (IsBillingGroup(AutofillType(type).group())) { | 499 } else if (IsBillingGroup(type.group())) { |
500 billing_address_->FillFormField( | 500 billing_address_->FillFormField( |
501 field, 0, autofill_manager_->app_locale(), field_to_fill); | 501 field, 0, autofill_manager_->app_locale(), field_to_fill); |
502 } else { | 502 } else { |
503 profile_->FillFormField( | 503 profile_->FillFormField( |
504 field, 0, autofill_manager_->app_locale(), field_to_fill); | 504 field, 0, autofill_manager_->app_locale(), field_to_fill); |
505 } | 505 } |
506 } | 506 } |
507 | 507 |
508 void AutocheckoutManager::SendAutocheckoutStatus(AutocheckoutStatus status) { | 508 void AutocheckoutManager::SendAutocheckoutStatus(AutocheckoutStatus status) { |
509 // To ensure stale data isn't being sent. | 509 // To ensure stale data isn't being sent. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 | 569 |
570 SendAutocheckoutStatus(status); | 570 SendAutocheckoutStatus(status); |
571 if (status == SUCCESS) | 571 if (status == SUCCESS) |
572 autofill_manager_->delegate()->OnAutocheckoutSuccess(); | 572 autofill_manager_->delegate()->OnAutocheckoutSuccess(); |
573 else | 573 else |
574 autofill_manager_->delegate()->OnAutocheckoutError(); | 574 autofill_manager_->delegate()->OnAutocheckoutError(); |
575 in_autocheckout_flow_ = false; | 575 in_autocheckout_flow_ = false; |
576 } | 576 } |
577 | 577 |
578 } // namespace autofill | 578 } // namespace autofill |
OLD | NEW |