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 "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "apps/shell_window.h" | 11 #include "apps/shell_window.h" |
12 #include "base/base64.h" | 12 #include "base/base64.h" |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 22 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
23 #include "chrome/browser/browser_process.h" | 23 #include "chrome/browser/browser_process.h" |
24 #include "chrome/browser/extensions/shell_window_registry.h" | 24 #include "chrome/browser/extensions/shell_window_registry.h" |
25 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 25 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/ui/autofill/autofill_credit_card_bubble_controller.h" | 27 #include "chrome/browser/ui/autofill/autofill_credit_card_bubble_controller.h" |
28 #include "chrome/browser/ui/autofill/autofill_dialog_utils.h" | |
28 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 29 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
29 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 30 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
30 #include "chrome/browser/ui/browser.h" | 31 #include "chrome/browser/ui/browser.h" |
31 #include "chrome/browser/ui/browser_finder.h" | 32 #include "chrome/browser/ui/browser_finder.h" |
32 #include "chrome/browser/ui/browser_navigator.h" | 33 #include "chrome/browser/ui/browser_navigator.h" |
33 #include "chrome/browser/ui/browser_window.h" | 34 #include "chrome/browser/ui/browser_window.h" |
34 #include "chrome/browser/ui/extensions/native_app_window.h" | 35 #include "chrome/browser/ui/extensions/native_app_window.h" |
35 #include "chrome/common/chrome_version_info.h" | 36 #include "chrome/common/chrome_version_info.h" |
36 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
37 #include "chrome/common/render_messages.h" | 38 #include "chrome/common/render_messages.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 // Limit Wallet items refresh rate to at most once per minute. | 105 // Limit Wallet items refresh rate to at most once per minute. |
105 const int kWalletItemsRefreshRateSeconds = 60; | 106 const int kWalletItemsRefreshRateSeconds = 60; |
106 | 107 |
107 // Returns true if |card_type| is supported by Wallet. | 108 // Returns true if |card_type| is supported by Wallet. |
108 bool IsWalletSupportedCard(const std::string& card_type) { | 109 bool IsWalletSupportedCard(const std::string& card_type) { |
109 return card_type == autofill::kVisaCard || | 110 return card_type == autofill::kVisaCard || |
110 card_type == autofill::kMasterCard || | 111 card_type == autofill::kMasterCard || |
111 card_type == autofill::kDiscoverCard; | 112 card_type == autofill::kDiscoverCard; |
112 } | 113 } |
113 | 114 |
114 // Returns true if |input| should be shown when |field_type| has been requested. | |
115 bool InputTypeMatchesFieldType(const DetailInput& input, | |
116 AutofillFieldType field_type) { | |
117 // If any credit card expiration info is asked for, show both month and year | |
118 // inputs. | |
119 if (field_type == CREDIT_CARD_EXP_4_DIGIT_YEAR || | |
120 field_type == CREDIT_CARD_EXP_2_DIGIT_YEAR || | |
121 field_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || | |
122 field_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || | |
123 field_type == CREDIT_CARD_EXP_MONTH) { | |
124 return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR || | |
125 input.type == CREDIT_CARD_EXP_MONTH; | |
126 } | |
127 | |
128 if (field_type == CREDIT_CARD_TYPE) | |
129 return input.type == CREDIT_CARD_NUMBER; | |
130 | |
131 return input.type == field_type; | |
132 } | |
133 | |
134 // Returns true if |input| in the given |section| should be used for a | |
135 // site-requested |field|. | |
136 bool DetailInputMatchesField(DialogSection section, | |
137 const DetailInput& input, | |
138 const AutofillField& field) { | |
139 // The credit card name is filled from the billing section's data. | |
140 if (field.type() == CREDIT_CARD_NAME && | |
141 (section == SECTION_BILLING || section == SECTION_CC_BILLING)) { | |
142 return input.type == NAME_FULL; | |
143 } | |
144 | |
145 return InputTypeMatchesFieldType(input, field.type()); | |
146 } | |
147 | |
148 bool IsCreditCardType(AutofillFieldType type) { | |
149 return AutofillType(type).group() == AutofillType::CREDIT_CARD; | |
150 } | |
151 | |
152 // Returns true if |input| should be used to fill a site-requested |field| which | 115 // Returns true if |input| should be used to fill a site-requested |field| which |
153 // is notated with a "shipping" tag, for use when the user has decided to use | 116 // is notated with a "shipping" tag, for use when the user has decided to use |
154 // the billing address as the shipping address. | 117 // the billing address as the shipping address. |
155 bool DetailInputMatchesShippingField(const DetailInput& input, | 118 bool DetailInputMatchesShippingField(const DetailInput& input, |
156 const AutofillField& field) { | 119 const AutofillField& field) { |
157 // Equivalent billing field type is used to support UseBillingAsShipping | 120 // Equivalent billing field type is used to support UseBillingAsShipping |
158 // usecase. | 121 // usecase. |
159 AutofillFieldType field_type = | 122 AutofillFieldType field_type = |
160 AutofillType::GetEquivalentBillingFieldType(field.type()); | 123 AutofillType::GetEquivalentBillingFieldType(field.type()); |
161 | 124 |
162 return InputTypeMatchesFieldType(input, field_type); | 125 return utils::InputTypeMatchesFieldType(input, field_type); |
163 } | |
164 | |
165 // Constructs |inputs| from template data. | |
166 void BuildInputs(const DetailInput* input_template, | |
167 size_t template_size, | |
168 DetailInputs* inputs) { | |
169 for (size_t i = 0; i < template_size; ++i) { | |
170 const DetailInput* input = &input_template[i]; | |
171 inputs->push_back(*input); | |
172 } | |
173 } | 126 } |
174 | 127 |
175 // Initializes |form_group| from user-entered data. | 128 // Initializes |form_group| from user-entered data. |
176 void FillFormGroupFromOutputs(const DetailOutputMap& detail_outputs, | 129 void FillFormGroupFromOutputs(const DetailOutputMap& detail_outputs, |
177 FormGroup* form_group) { | 130 FormGroup* form_group) { |
178 for (DetailOutputMap::const_iterator iter = detail_outputs.begin(); | 131 for (DetailOutputMap::const_iterator iter = detail_outputs.begin(); |
179 iter != detail_outputs.end(); ++iter) { | 132 iter != detail_outputs.end(); ++iter) { |
180 if (!iter->second.empty()) { | 133 if (!iter->second.empty()) { |
181 AutofillFieldType type = iter->first->type; | 134 AutofillFieldType type = iter->first->type; |
182 if (type == ADDRESS_HOME_COUNTRY || type == ADDRESS_BILLING_COUNTRY) { | 135 if (type == ADDRESS_HOME_COUNTRY || type == ADDRESS_BILLING_COUNTRY) { |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
420 return base::string16(); | 373 return base::string16(); |
421 } | 374 } |
422 | 375 |
423 gfx::Image GetGeneratedCardImage(const string16& card_number) { | 376 gfx::Image GetGeneratedCardImage(const string16& card_number) { |
424 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 377 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
425 const gfx::ImageSkia* card = | 378 const gfx::ImageSkia* card = |
426 rb.GetImageSkiaNamed(IDR_AUTOFILL_GENERATED_CARD); | 379 rb.GetImageSkiaNamed(IDR_AUTOFILL_GENERATED_CARD); |
427 gfx::Canvas canvas(card->size(), ui::SCALE_FACTOR_100P, false); | 380 gfx::Canvas canvas(card->size(), ui::SCALE_FACTOR_100P, false); |
428 canvas.DrawImageInt(*card, 0, 0); | 381 canvas.DrawImageInt(*card, 0, 0); |
429 | 382 |
430 #if !defined(OS_ANDROID) | |
431 gfx::Rect display_rect(gfx::Point(), card->size()); | 383 gfx::Rect display_rect(gfx::Point(), card->size()); |
432 display_rect.Inset(14, 0, 14, 0); | 384 display_rect.Inset(14, 0, 14, 0); |
433 // TODO(estade): fallback font for systems that don't have Helvetica? | 385 // TODO(estade): fallback font for systems that don't have Helvetica? |
434 gfx::Font helvetica("Helvetica", 14); | 386 gfx::Font helvetica("Helvetica", 14); |
435 gfx::ShadowValues shadows; | 387 gfx::ShadowValues shadows; |
436 shadows.push_back(gfx::ShadowValue(gfx::Point(0, 1), | 388 shadows.push_back(gfx::ShadowValue(gfx::Point(0, 1), |
437 0.0, | 389 0.0, |
438 SkColorSetARGB(85, 0, 0, 0))); | 390 SkColorSetARGB(85, 0, 0, 0))); |
439 canvas.DrawStringWithShadows( | 391 canvas.DrawStringWithShadows( |
440 card_number, | 392 card_number, |
441 helvetica, | 393 helvetica, |
442 SK_ColorWHITE, | 394 SK_ColorWHITE, |
443 display_rect, 0, 0, shadows); | 395 display_rect, 0, 0, shadows); |
444 #endif | |
445 | 396 |
446 gfx::ImageSkia skia(canvas.ExtractImageRep()); | 397 gfx::ImageSkia skia(canvas.ExtractImageRep()); |
447 return gfx::Image(skia); | 398 return gfx::Image(skia); |
448 } | 399 } |
449 | 400 |
450 } // namespace | 401 } // namespace |
451 | 402 |
452 AutofillDialogController::~AutofillDialogController() {} | 403 AutofillDialogController::~AutofillDialogController() {} |
453 | 404 |
454 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { | 405 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { |
455 if (popup_controller_) | 406 if (popup_controller_) |
456 popup_controller_->Hide(); | 407 popup_controller_->Hide(); |
457 | 408 |
458 GetMetricLogger().LogDialogInitialUserState( | 409 GetMetricLogger().LogDialogInitialUserState( |
459 GetDialogType(), initial_user_state_); | 410 GetDialogType(), initial_user_state_); |
460 | 411 |
461 if (deemphasized_render_view_) { | 412 if (deemphasized_render_view_) { |
462 web_contents()->GetRenderViewHost()->Send( | 413 web_contents()->GetRenderViewHost()->Send( |
463 new ChromeViewMsg_SetVisuallyDeemphasized( | 414 new ChromeViewMsg_SetVisuallyDeemphasized( |
464 web_contents()->GetRenderViewHost()->GetRoutingID(), false)); | 415 web_contents()->GetRenderViewHost()->GetRoutingID(), false)); |
465 } | 416 } |
466 } | 417 } |
467 | 418 |
468 // static | 419 // static |
469 base::WeakPtr<AutofillDialogControllerImpl> | 420 base::WeakPtr<AutofillDialogTabManagerDelegate> |
470 AutofillDialogControllerImpl::Create( | 421 AutofillDialogTabManagerDelegate::Create( |
471 content::WebContents* contents, | 422 content::WebContents* contents, |
472 const FormData& form_structure, | 423 const FormData& form_structure, |
473 const GURL& source_url, | 424 const GURL& source_url, |
425 const DialogType dialog_type, | |
426 const base::Callback<void(const FormStructure*, | |
427 const std::string&)>& callback) { | |
428 return AutofillDialogControllerImpl::Create(contents, | |
429 form_structure, | |
430 source_url, | |
431 dialog_type, | |
432 callback); | |
433 } | |
434 | |
435 // static | |
436 void AutofillDialogTabManagerDelegate::RegisterProfilePrefs( | |
437 user_prefs::PrefRegistrySyncable* registry) { | |
438 AutofillDialogControllerImpl::RegisterProfilePrefs(registry); | |
439 } | |
440 | |
441 // static | |
442 base::WeakPtr<AutofillDialogTabManagerDelegate> | |
443 AutofillDialogControllerImpl::Create( | |
444 content::WebContents* contents, | |
445 const FormData& form_structure, | |
446 const GURL& source_url, | |
474 const DialogType dialog_type, | 447 const DialogType dialog_type, |
475 const base::Callback<void(const FormStructure*, | 448 const base::Callback<void(const FormStructure*, |
476 const std::string&)>& callback) { | 449 const std::string&)>& callback) { |
477 // AutofillDialogControllerImpl owns itself. | 450 // AutofillDialogControllerImpl owns itself. |
478 AutofillDialogControllerImpl* autofill_dialog_controller = | 451 AutofillDialogControllerImpl* autofill_dialog_controller = |
479 new AutofillDialogControllerImpl(contents, | 452 new AutofillDialogControllerImpl(contents, |
480 form_structure, | 453 form_structure, |
481 source_url, | 454 source_url, |
482 dialog_type, | 455 dialog_type, |
483 callback); | 456 callback); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 form_structure_.ParseFieldTypesFromAutocompleteAttributes( | 509 form_structure_.ParseFieldTypesFromAutocompleteAttributes( |
537 FormStructure::PARSE_FOR_AUTOFILL_DIALOG, &has_types, &has_sections); | 510 FormStructure::PARSE_FOR_AUTOFILL_DIALOG, &has_types, &has_sections); |
538 | 511 |
539 // Fail if the author didn't specify autocomplete types. | 512 // Fail if the author didn't specify autocomplete types. |
540 if (!has_types) { | 513 if (!has_types) { |
541 callback_.Run(NULL, std::string()); | 514 callback_.Run(NULL, std::string()); |
542 delete this; | 515 delete this; |
543 return; | 516 return; |
544 } | 517 } |
545 | 518 |
546 const DetailInput kEmailInputs[] = { | 519 utils::BuildInputsForSection(SECTION_EMAIL, &requested_email_fields_); |
547 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 520 utils::BuildInputsForSection(SECTION_CC, &requested_cc_fields_); |
548 }; | 521 utils::BuildInputsForSection(SECTION_BILLING, &requested_billing_fields_); |
549 | 522 utils::BuildInputsForSection(SECTION_CC_BILLING, |
550 const DetailInput kCCInputs[] = { | 523 &requested_cc_billing_fields_); |
551 { 2, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, | 524 utils::BuildInputsForSection(SECTION_SHIPPING, &requested_shipping_fields_); |
552 { 3, CREDIT_CARD_EXP_MONTH }, | |
553 { 3, CREDIT_CARD_EXP_4_DIGIT_YEAR }, | |
554 { 3, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, | |
555 1.5 }, | |
556 }; | |
557 | |
558 const DetailInput kBillingInputs[] = { | |
559 { 4, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, | |
560 { 5, ADDRESS_BILLING_LINE1, | |
561 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | |
562 { 6, ADDRESS_BILLING_LINE2, | |
563 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | |
564 { 7, ADDRESS_BILLING_CITY, | |
565 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | |
566 // TODO(estade): state placeholder should depend on locale. | |
567 { 8, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, | |
568 { 8, ADDRESS_BILLING_ZIP, | |
569 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | |
570 // We don't allow the user to change the country: http://crbug.com/247518 | |
571 { -1, ADDRESS_BILLING_COUNTRY, 0 }, | |
572 { 10, PHONE_BILLING_WHOLE_NUMBER, | |
573 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | |
574 }; | |
575 | |
576 const DetailInput kShippingInputs[] = { | |
577 { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, | |
578 { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | |
579 { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | |
580 { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | |
581 { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, | |
582 { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | |
583 { -1, ADDRESS_HOME_COUNTRY, 0 }, | |
584 { 17, PHONE_HOME_WHOLE_NUMBER, | |
585 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | |
586 }; | |
587 | |
588 BuildInputs(kEmailInputs, | |
589 arraysize(kEmailInputs), | |
590 &requested_email_fields_); | |
591 | |
592 BuildInputs(kCCInputs, | |
593 arraysize(kCCInputs), | |
594 &requested_cc_fields_); | |
595 | |
596 BuildInputs(kBillingInputs, | |
597 arraysize(kBillingInputs), | |
598 &requested_billing_fields_); | |
599 | |
600 BuildInputs(kCCInputs, | |
601 arraysize(kCCInputs), | |
602 &requested_cc_billing_fields_); | |
603 BuildInputs(kBillingInputs, | |
604 arraysize(kBillingInputs), | |
605 &requested_cc_billing_fields_); | |
606 | |
607 BuildInputs(kShippingInputs, | |
608 arraysize(kShippingInputs), | |
609 &requested_shipping_fields_); | |
610 | 525 |
611 // Test whether we need to show the shipping section. If filling that section | 526 // Test whether we need to show the shipping section. If filling that section |
612 // would be a no-op, don't show it. | 527 // would be a no-op, don't show it. |
613 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); | 528 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); |
614 EmptyDataModelWrapper empty_wrapper; | 529 EmptyDataModelWrapper empty_wrapper; |
615 cares_about_shipping_ = empty_wrapper.FillFormStructure( | 530 cares_about_shipping_ = empty_wrapper.FillFormStructure( |
616 inputs, | 531 inputs, |
617 base::Bind(DetailInputMatchesField, SECTION_SHIPPING), | 532 base::Bind(utils::DetailInputMatchesField, SECTION_SHIPPING), |
618 &form_structure_); | 533 &form_structure_); |
619 | 534 |
620 SuggestionsUpdated(); | 535 SuggestionsUpdated(); |
621 | 536 |
622 int show_count = | 537 int show_count = |
623 profile_->GetPrefs()->GetInteger(::prefs::kAutofillDialogShowCount); | 538 profile_->GetPrefs()->GetInteger(::prefs::kAutofillDialogShowCount); |
624 profile_->GetPrefs()->SetInteger(::prefs::kAutofillDialogShowCount, | 539 profile_->GetPrefs()->SetInteger(::prefs::kAutofillDialogShowCount, |
625 show_count + 1); | 540 show_count + 1); |
626 | 541 |
627 // TODO(estade): don't show the dialog if the site didn't specify the right | 542 // TODO(estade): don't show the dialog if the site didn't specify the right |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
834 !IsSubmitPausedOn(wallet::VERIFY_CVV) && | 749 !IsSubmitPausedOn(wallet::VERIFY_CVV) && |
835 GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE; | 750 GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE; |
836 if (!show_wallet_interstitial) | 751 if (!show_wallet_interstitial) |
837 return DialogOverlayState(); | 752 return DialogOverlayState(); |
838 | 753 |
839 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 754 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
840 DialogOverlayState state; | 755 DialogOverlayState state; |
841 | 756 |
842 state.strings.push_back(DialogOverlayString()); | 757 state.strings.push_back(DialogOverlayString()); |
843 DialogOverlayString& string = state.strings.back(); | 758 DialogOverlayString& string = state.strings.back(); |
844 #if !defined(OS_ANDROID) | |
845 // gfx::Font isn't implemented on Android; DeriveFont() causes a null deref. | |
846 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4); | 759 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4); |
847 #endif | |
848 | 760 |
849 // First-run, post-submit, Wallet expository page. | 761 // First-run, post-submit, Wallet expository page. |
850 if (full_wallet_ && full_wallet_->required_actions().empty()) { | 762 if (full_wallet_ && full_wallet_->required_actions().empty()) { |
851 string16 cc_number = full_wallet_->GetInfo(CREDIT_CARD_NUMBER); | 763 string16 cc_number = full_wallet_->GetInfo(CREDIT_CARD_NUMBER); |
852 DCHECK_EQ(16U, cc_number.size()); | 764 DCHECK_EQ(16U, cc_number.size()); |
853 state.image = GetGeneratedCardImage( | 765 state.image = GetGeneratedCardImage( |
854 ASCIIToUTF16("xxxx xxxx xxxx ") + | 766 ASCIIToUTF16("xxxx xxxx xxxx ") + |
855 cc_number.substr(cc_number.size() - 4)); | 767 cc_number.substr(cc_number.size() - 4)); |
856 string.text = l10n_util::GetStringUTF16( | 768 string.text = l10n_util::GetStringUTF16( |
857 IDS_AUTOFILL_DIALOG_CARD_GENERATION_DONE); | 769 IDS_AUTOFILL_DIALOG_CARD_GENERATION_DONE); |
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1738 } | 1650 } |
1739 | 1651 |
1740 // If the user clicks while the popup is already showing, be sure to hide | 1652 // If the user clicks while the popup is already showing, be sure to hide |
1741 // it. | 1653 // it. |
1742 if (!was_edit && popup_controller_.get()) { | 1654 if (!was_edit && popup_controller_.get()) { |
1743 HidePopup(); | 1655 HidePopup(); |
1744 return; | 1656 return; |
1745 } | 1657 } |
1746 | 1658 |
1747 std::vector<string16> popup_values, popup_labels, popup_icons; | 1659 std::vector<string16> popup_values, popup_labels, popup_icons; |
1748 if (IsCreditCardType(input->type)) { | 1660 if (utils::IsCreditCardType(input->type)) { |
1749 GetManager()->GetCreditCardSuggestions(input->type, | 1661 GetManager()->GetCreditCardSuggestions(input->type, |
1750 field_contents, | 1662 field_contents, |
1751 &popup_values, | 1663 &popup_values, |
1752 &popup_labels, | 1664 &popup_labels, |
1753 &popup_icons, | 1665 &popup_icons, |
1754 &popup_guids_); | 1666 &popup_guids_); |
1755 } else { | 1667 } else { |
1756 std::vector<AutofillFieldType> field_types; | 1668 std::vector<AutofillFieldType> field_types; |
1757 field_types.push_back(EMAIL_ADDRESS); | 1669 field_types.push_back(EMAIL_ADDRESS); |
1758 for (DetailInputs::const_iterator iter = requested_shipping_fields_.begin(); | 1670 for (DetailInputs::const_iterator iter = requested_shipping_fields_.begin(); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2040 | 1952 |
2041 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { | 1953 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { |
2042 // TODO(estade): implement. | 1954 // TODO(estade): implement. |
2043 } | 1955 } |
2044 | 1956 |
2045 void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value, | 1957 void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value, |
2046 int identifier) { | 1958 int identifier) { |
2047 const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier]; | 1959 const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier]; |
2048 | 1960 |
2049 scoped_ptr<DataModelWrapper> wrapper; | 1961 scoped_ptr<DataModelWrapper> wrapper; |
2050 if (IsCreditCardType(input_showing_popup_->type)) { | 1962 if (utils::IsCreditCardType(input_showing_popup_->type)) { |
2051 wrapper.reset(new AutofillCreditCardWrapper( | 1963 wrapper.reset(new AutofillCreditCardWrapper( |
2052 GetManager()->GetCreditCardByGUID(pair.first))); | 1964 GetManager()->GetCreditCardByGUID(pair.first))); |
2053 } else { | 1965 } else { |
2054 wrapper.reset(new AutofillProfileWrapper( | 1966 wrapper.reset(new AutofillProfileWrapper( |
2055 GetManager()->GetProfileByGUID(pair.first), pair.second)); | 1967 GetManager()->GetProfileByGUID(pair.first), pair.second)); |
2056 } | 1968 } |
2057 | 1969 |
2058 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 1970 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
2059 DialogSection section = static_cast<DialogSection>(i); | 1971 DialogSection section = static_cast<DialogSection>(i); |
2060 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); | 1972 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2324 if (popup_controller_.get()) | 2236 if (popup_controller_.get()) |
2325 return popup_controller_->HandleKeyPressEvent(event); | 2237 return popup_controller_->HandleKeyPressEvent(event); |
2326 | 2238 |
2327 return false; | 2239 return false; |
2328 } | 2240 } |
2329 | 2241 |
2330 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { | 2242 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { |
2331 DCHECK_GT(form_structure_.field_count(), 0U); | 2243 DCHECK_GT(form_structure_.field_count(), 0U); |
2332 | 2244 |
2333 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 2245 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
2334 if (IsCreditCardType(form_structure_.field(i)->type())) | 2246 if (utils::IsCreditCardType(form_structure_.field(i)->type())) |
2335 return true; | 2247 return true; |
2336 } | 2248 } |
2337 | 2249 |
2338 return false; | 2250 return false; |
2339 } | 2251 } |
2340 | 2252 |
2341 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const { | 2253 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const { |
2342 return source_url_.SchemeIs(chrome::kHttpsScheme); | 2254 return source_url_.SchemeIs(chrome::kHttpsScheme); |
2343 } | 2255 } |
2344 | 2256 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2378 wallet_server_validation_recoverable_(true), | 2290 wallet_server_validation_recoverable_(true), |
2379 data_was_passed_back_(false), | 2291 data_was_passed_back_(false), |
2380 autocheckout_state_(AUTOCHECKOUT_NOT_STARTED), | 2292 autocheckout_state_(AUTOCHECKOUT_NOT_STARTED), |
2381 was_ui_latency_logged_(false), | 2293 was_ui_latency_logged_(false), |
2382 deemphasized_render_view_(false) { | 2294 deemphasized_render_view_(false) { |
2383 // TODO(estade): remove duplicates from |form_structure|? | 2295 // TODO(estade): remove duplicates from |form_structure|? |
2384 DCHECK(!callback_.is_null()); | 2296 DCHECK(!callback_.is_null()); |
2385 } | 2297 } |
2386 | 2298 |
2387 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { | 2299 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { |
2300 #if defined(TOOLKIT_VIEWS) | |
aruslan
2013/07/31 02:43:19
This should be #if defined(ENABLE_AUTOFILL_DIALOG)
aruslan
2013/08/01 19:30:29
Actually, #if should be removed entirely.
aruslan
2013/08/07 23:17:03
Done.
aruslan
2013/08/07 23:17:03
Done: removed entirely.
| |
2388 return AutofillDialogView::Create(this); | 2301 return AutofillDialogView::Create(this); |
2302 #else | |
2303 NOTIMPLEMENTED(); | |
2304 return NULL; | |
2305 #endif // defined(TOOLKIT_VIEWS) | |
2389 } | 2306 } |
2390 | 2307 |
2391 PersonalDataManager* AutofillDialogControllerImpl::GetManager() { | 2308 PersonalDataManager* AutofillDialogControllerImpl::GetManager() { |
2392 return PersonalDataManagerFactory::GetForProfile(profile_); | 2309 return PersonalDataManagerFactory::GetForProfile(profile_); |
2393 } | 2310 } |
2394 | 2311 |
2395 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() { | 2312 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() { |
2396 return &wallet_client_; | 2313 return &wallet_client_; |
2397 } | 2314 } |
2398 | 2315 |
2399 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { | 2316 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { |
2400 return account_chooser_model_.WalletIsSelected() && | 2317 return account_chooser_model_.WalletIsSelected() && |
2401 SignedInState() == SIGNED_IN; | 2318 SignedInState() == SIGNED_IN; |
2402 } | 2319 } |
2403 | 2320 |
2404 void AutofillDialogControllerImpl::LoadRiskFingerprintData() { | 2321 void AutofillDialogControllerImpl::LoadRiskFingerprintData() { |
2405 risk_data_.clear(); | 2322 risk_data_.clear(); |
2406 | 2323 |
2407 uint64 obfuscated_gaia_id = 0; | 2324 uint64 obfuscated_gaia_id = 0; |
2408 bool success = base::StringToUint64(wallet_items_->obfuscated_gaia_id(), | 2325 bool success = base::StringToUint64(wallet_items_->obfuscated_gaia_id(), |
2409 &obfuscated_gaia_id); | 2326 &obfuscated_gaia_id); |
2410 DCHECK(success); | 2327 DCHECK(success); |
2411 | 2328 |
2412 gfx::Rect window_bounds; | 2329 gfx::Rect window_bounds = |
2413 #if !defined(OS_ANDROID) | 2330 GetBaseWindowForWebContents(web_contents())->GetBounds(); |
2414 window_bounds = GetBaseWindowForWebContents(web_contents())->GetBounds(); | |
2415 #else | |
2416 // TODO(dbeam): figure out the correct browser window size to pass along for | |
2417 // android. | |
2418 #endif | |
2419 | 2331 |
2420 PrefService* user_prefs = profile_->GetPrefs(); | 2332 PrefService* user_prefs = profile_->GetPrefs(); |
2421 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset); | 2333 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset); |
2422 std::string accept_languages = | 2334 std::string accept_languages = |
2423 user_prefs->GetString(::prefs::kAcceptLanguages); | 2335 user_prefs->GetString(::prefs::kAcceptLanguages); |
2424 base::Time install_time = base::Time::FromTimeT( | 2336 base::Time install_time = base::Time::FromTimeT( |
2425 g_browser_process->local_state()->GetInt64(::prefs::kInstallDate)); | 2337 g_browser_process->local_state()->GetInt64(::prefs::kInstallDate)); |
2426 | 2338 |
2427 risk::GetFingerprint( | 2339 risk::GetFingerprint( |
2428 obfuscated_gaia_id, window_bounds, *web_contents(), | 2340 obfuscated_gaia_id, window_bounds, *web_contents(), |
2429 chrome::VersionInfo().Version(), charset, accept_languages, install_time, | 2341 chrome::VersionInfo().Version(), charset, accept_languages, install_time, |
2430 dialog_type_, g_browser_process->GetApplicationLocale(), | 2342 dialog_type_, g_browser_process->GetApplicationLocale(), |
2431 base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData, | 2343 base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData, |
2432 weak_ptr_factory_.GetWeakPtr())); | 2344 weak_ptr_factory_.GetWeakPtr())); |
2433 } | 2345 } |
2434 | 2346 |
2435 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( | 2347 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( |
2436 scoped_ptr<risk::Fingerprint> fingerprint) { | 2348 scoped_ptr<risk::Fingerprint> fingerprint) { |
2437 DCHECK(AreLegalDocumentsCurrent()); | 2349 DCHECK(AreLegalDocumentsCurrent()); |
2438 | 2350 |
2439 std::string proto_data; | 2351 std::string proto_data; |
2440 fingerprint->SerializeToString(&proto_data); | 2352 fingerprint->SerializeToString(&proto_data); |
2441 bool success = base::Base64Encode(proto_data, &risk_data_); | 2353 bool success = base::Base64Encode(proto_data, &risk_data_); |
2442 DCHECK(success); | 2354 DCHECK(success); |
2443 | 2355 |
2444 SubmitWithWallet(); | 2356 SubmitWithWallet(); |
2445 } | 2357 } |
2446 | 2358 |
2447 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) { | 2359 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) { |
2448 #if !defined(OS_ANDROID) | |
2449 chrome::NavigateParams params( | 2360 chrome::NavigateParams params( |
2450 chrome::FindBrowserWithWebContents(web_contents()), | 2361 chrome::FindBrowserWithWebContents(web_contents()), |
2451 url, | 2362 url, |
2452 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 2363 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
2453 params.disposition = NEW_FOREGROUND_TAB; | 2364 params.disposition = NEW_FOREGROUND_TAB; |
2454 chrome::Navigate(¶ms); | 2365 chrome::Navigate(¶ms); |
2455 #else | |
2456 // TODO(estade): use TabModelList? | |
2457 #endif | |
2458 } | 2366 } |
2459 | 2367 |
2460 bool AutofillDialogControllerImpl::IsEditingExistingData( | 2368 bool AutofillDialogControllerImpl::IsEditingExistingData( |
2461 DialogSection section) const { | 2369 DialogSection section) const { |
2462 return section_editing_state_.count(section) > 0; | 2370 return section_editing_state_.count(section) > 0; |
2463 } | 2371 } |
2464 | 2372 |
2465 bool AutofillDialogControllerImpl::IsManuallyEditingSection( | 2373 bool AutofillDialogControllerImpl::IsManuallyEditingSection( |
2466 DialogSection section) const { | 2374 DialogSection section) const { |
2467 return IsEditingExistingData(section) || | 2375 return IsEditingExistingData(section) || |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2601 suggested_cc_.AddKeyedItemWithIcon( | 2509 suggested_cc_.AddKeyedItemWithIcon( |
2602 cards[i]->guid(), | 2510 cards[i]->guid(), |
2603 cards[i]->Label(), | 2511 cards[i]->Label(), |
2604 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); | 2512 rb.GetImageNamed(CreditCard::IconResourceId(cards[i]->type()))); |
2605 } | 2513 } |
2606 | 2514 |
2607 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); | 2515 const std::vector<AutofillProfile*>& profiles = manager->GetProfiles(); |
2608 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 2516 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
2609 for (size_t i = 0; i < profiles.size(); ++i) { | 2517 for (size_t i = 0; i < profiles.size(); ++i) { |
2610 if (!HasCompleteAndVerifiedData(*profiles[i], | 2518 if (!HasCompleteAndVerifiedData(*profiles[i], |
2611 requested_shipping_fields_) || | 2519 requested_shipping_fields_) || |
aruslan
2013/07/31 02:43:19
indent.
aruslan
2013/08/07 23:17:03
Done.
| |
2612 HasInvalidAddress(*profiles[i])) { | 2520 HasInvalidAddress(*profiles[i])) { |
2613 continue; | 2521 continue; |
2614 } | 2522 } |
2615 | 2523 |
2616 // Add all email addresses. | 2524 // Add all email addresses. |
2617 std::vector<string16> values; | 2525 std::vector<string16> values; |
2618 profiles[i]->GetMultiInfo(EMAIL_ADDRESS, app_locale, &values); | 2526 profiles[i]->GetMultiInfo(EMAIL_ADDRESS, app_locale, &values); |
2619 for (size_t j = 0; j < values.size(); ++j) { | 2527 for (size_t j = 0; j < values.size(); ++j) { |
2620 if (IsValidEmailAddress(values[j])) | 2528 if (IsValidEmailAddress(values[j])) |
2621 suggested_email_.AddKeyedItem(profiles[i]->guid(), values[j]); | 2529 suggested_email_.AddKeyedItem(profiles[i]->guid(), values[j]); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2773 SaveProfileGleanedFromSection(profile, section); | 2681 SaveProfileGleanedFromSection(profile, section); |
2774 | 2682 |
2775 AutofillProfileWrapper profile_wrapper(&profile, 0); | 2683 AutofillProfileWrapper profile_wrapper(&profile, 0); |
2776 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); | 2684 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); |
2777 } | 2685 } |
2778 } | 2686 } |
2779 } | 2687 } |
2780 | 2688 |
2781 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { | 2689 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { |
2782 FillOutputForSectionWithComparator( | 2690 FillOutputForSectionWithComparator( |
2783 section, base::Bind(DetailInputMatchesField, section)); | 2691 section, base::Bind(utils::DetailInputMatchesField, section)); |
2784 } | 2692 } |
2785 | 2693 |
2786 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( | 2694 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( |
2787 DialogSection section) const { | 2695 DialogSection section) const { |
2788 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for | 2696 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for |
2789 // any of the fields. | 2697 // any of the fields. |
2790 // TODO(estade): remove !IsPayingWithWallet() check once WalletClient support | 2698 // TODO(estade): remove !IsPayingWithWallet() check once WalletClient support |
2791 // is added. http://crbug.com/243514 | 2699 // is added. http://crbug.com/243514 |
2792 if (section == SECTION_SHIPPING && !IsPayingWithWallet()) | 2700 if (section == SECTION_SHIPPING && !IsPayingWithWallet()) |
2793 return cares_about_shipping_; | 2701 return cares_about_shipping_; |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3480 view_->GetUserInput(SECTION_CC_BILLING, &output); | 3388 view_->GetUserInput(SECTION_CC_BILLING, &output); |
3481 CreditCard card; | 3389 CreditCard card; |
3482 GetBillingInfoFromOutputs(output, &card, NULL, NULL); | 3390 GetBillingInfoFromOutputs(output, &card, NULL, NULL); |
3483 backing_last_four = card.TypeAndLastFourDigits(); | 3391 backing_last_four = card.TypeAndLastFourDigits(); |
3484 } | 3392 } |
3485 AutofillCreditCardBubbleController::ShowGeneratedCardBubble( | 3393 AutofillCreditCardBubbleController::ShowGeneratedCardBubble( |
3486 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); | 3394 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); |
3487 } | 3395 } |
3488 | 3396 |
3489 } // namespace autofill | 3397 } // namespace autofill |
OLD | NEW |