OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/autofill/autofill_country.h" | 13 #include "chrome/browser/autofill/autofill_country.h" |
14 #include "chrome/browser/autofill/autofill_manager.h" | 14 #include "chrome/browser/autofill/autofill_manager.h" |
15 #include "chrome/browser/autofill/autofill_type.h" | 15 #include "chrome/browser/autofill/autofill_type.h" |
16 #include "chrome/browser/autofill/personal_data_manager.h" | 16 #include "chrome/browser/autofill/personal_data_manager.h" |
17 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 17 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
18 #include "chrome/browser/autofill/validation.h" | 18 #include "chrome/browser/autofill/validation.h" |
19 #include "chrome/browser/autofill/wallet/full_wallet.h" | 19 #include "chrome/browser/autofill/wallet/full_wallet.h" |
20 #include "chrome/browser/autofill/wallet/wallet_items.h" | 20 #include "chrome/browser/autofill/wallet/wallet_items.h" |
21 #include "chrome/browser/autofill/wallet/wallet_service_url.h" | 21 #include "chrome/browser/autofill/wallet/wallet_service_url.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 23 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 24 #include "chrome/browser/ui/browser_finder.h" |
| 25 #include "chrome/browser/ui/browser_navigator.h" |
24 #include "chrome/common/form_data.h" | 26 #include "chrome/common/form_data.h" |
25 #include "content/public/browser/navigation_controller.h" | 27 #include "content/public/browser/navigation_controller.h" |
26 #include "content/public/browser/navigation_details.h" | 28 #include "content/public/browser/navigation_details.h" |
27 #include "content/public/browser/navigation_entry.h" | 29 #include "content/public/browser/navigation_entry.h" |
28 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
29 #include "content/public/browser/notification_types.h" | 31 #include "content/public/browser/notification_types.h" |
30 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
31 #include "content/public/common/url_constants.h" | 33 #include "content/public/common/url_constants.h" |
| 34 #include "googleurl/src/gurl.h" |
32 #include "grit/chromium_strings.h" | 35 #include "grit/chromium_strings.h" |
33 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
34 #include "net/base/cert_status_flags.h" | 37 #include "net/base/cert_status_flags.h" |
35 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
36 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
| 40 #include "ui/base/window_open_disposition.h" |
37 | 41 |
38 namespace autofill { | 42 namespace autofill { |
39 | 43 |
40 namespace { | 44 namespace { |
41 | 45 |
| 46 // TODO(dbeam): real URLs. |
| 47 const char kPrivacyPolicyUrl[] = "chrome://policy"; |
| 48 const char kTermsOfServiceUrl[] = "chrome://terms"; |
| 49 |
42 // Returns true if |input| should be shown when |field| has been requested. | 50 // Returns true if |input| should be shown when |field| has been requested. |
43 bool InputTypeMatchesFieldType(const DetailInput& input, | 51 bool InputTypeMatchesFieldType(const DetailInput& input, |
44 const AutofillField& field) { | 52 const AutofillField& field) { |
45 // If any credit card expiration info is asked for, show both month and year | 53 // If any credit card expiration info is asked for, show both month and year |
46 // inputs. | 54 // inputs. |
47 if (field.type() == CREDIT_CARD_EXP_4_DIGIT_YEAR || | 55 if (field.type() == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
48 field.type() == CREDIT_CARD_EXP_2_DIGIT_YEAR || | 56 field.type() == CREDIT_CARD_EXP_2_DIGIT_YEAR || |
49 field.type() == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || | 57 field.type() == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || |
50 field.type() == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || | 58 field.type() == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || |
51 field.type() == CREDIT_CARD_EXP_MONTH) { | 59 field.type() == CREDIT_CARD_EXP_MONTH) { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 string16 AutofillDialogControllerImpl::SignInText() const { | 271 string16 AutofillDialogControllerImpl::SignInText() const { |
264 // TODO(abodenha): real strings and l10n. | 272 // TODO(abodenha): real strings and l10n. |
265 return string16(ASCIIToUTF16("Sign in to use Google Wallet")); | 273 return string16(ASCIIToUTF16("Sign in to use Google Wallet")); |
266 } | 274 } |
267 | 275 |
268 string16 AutofillDialogControllerImpl::CancelSignInText() const { | 276 string16 AutofillDialogControllerImpl::CancelSignInText() const { |
269 // TODO(abodenha): real strings and l10n. | 277 // TODO(abodenha): real strings and l10n. |
270 return string16(ASCIIToUTF16("Don't sign in.")); | 278 return string16(ASCIIToUTF16("Don't sign in.")); |
271 } | 279 } |
272 | 280 |
| 281 string16 AutofillDialogControllerImpl::SaveLocallyText() const { |
| 282 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); |
| 283 } |
| 284 |
| 285 string16 AutofillDialogControllerImpl::ProgressBarText() const { |
| 286 return l10n_util::GetStringUTF16( |
| 287 IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR); |
| 288 } |
| 289 |
| 290 std::vector<string16> AutofillDialogControllerImpl::FootnoteLinkParts() const { |
| 291 if (!wallet_items_ || wallet_items_->legal_documents().empty() || |
| 292 wallet_items_->legal_documents().size() > 3U) { |
| 293 return std::vector<string16>(); |
| 294 } |
| 295 |
| 296 const std::vector<wallet::WalletItems::LegalDocument*>& documents = |
| 297 wallet_items_->legal_documents(); |
| 298 |
| 299 string16 text; |
| 300 switch (documents.size()) { |
| 301 case 1U: |
| 302 text = l10n_util::GetStringFUTF16( |
| 303 IDS_AUTOFILL_DIALOG_LEGAL_DOC_LINKS_1, |
| 304 ASCIIToUTF16(documents[0]->display_name())); |
| 305 break; |
| 306 case 2U: |
| 307 text = l10n_util::GetStringFUTF16( |
| 308 IDS_AUTOFILL_DIALOG_LEGAL_DOC_LINKS_2, |
| 309 ASCIIToUTF16(documents[0]->display_name()), |
| 310 ASCIIToUTF16(documents[1]->display_name())); |
| 311 break; |
| 312 case 3U: |
| 313 text = l10n_util::GetStringFUTF16( |
| 314 IDS_AUTOFILL_DIALOG_LEGAL_DOC_LINKS_3, |
| 315 ASCIIToUTF16(documents[0]->display_name()), |
| 316 ASCIIToUTF16(documents[1]->display_name()), |
| 317 ASCIIToUTF16(documents[2]->display_name())); |
| 318 break; |
| 319 } |
| 320 TrimWhitespace(text, TRIM_ALL, &text); |
| 321 |
| 322 std::vector<string16> parts; |
| 323 base::SplitStringDontTrim(text, '|', &parts); |
| 324 DCHECK_EQ(1U, parts.size() % 2); |
| 325 |
| 326 return parts; |
| 327 } |
| 328 |
| 329 string16 AutofillDialogControllerImpl::AcceptChangesText() const { |
| 330 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ACCEPT_CHANGES); |
| 331 } |
| 332 |
273 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { | 333 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { |
274 if (!wallet_items_) | 334 if (!wallet_items_) |
275 return REQUIRES_RESPONSE; | 335 return REQUIRES_RESPONSE; |
276 | 336 |
277 if (HasRequiredAction(wallet::GAIA_AUTH)) | 337 if (HasRequiredAction(wallet::GAIA_AUTH)) |
278 return REQUIRES_SIGN_IN; | 338 return REQUIRES_SIGN_IN; |
279 | 339 |
280 if (HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) | 340 if (HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) |
281 return REQUIRES_PASSIVE_SIGN_IN; | 341 return REQUIRES_PASSIVE_SIGN_IN; |
282 | 342 |
283 return SIGNED_IN; | 343 return SIGNED_IN; |
284 } | 344 } |
285 | 345 |
286 string16 AutofillDialogControllerImpl::SaveLocallyText() const { | 346 DialogNotification AutofillDialogControllerImpl::CurrentNotification() const { |
287 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); | 347 if (HasRequiredAction(wallet::VERIFY_CVV)) { |
288 } | 348 return DialogNotification( |
| 349 DialogNotification::REQUIRED_ACTION, |
| 350 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV)); |
| 351 } |
289 | 352 |
290 string16 AutofillDialogControllerImpl::ProgressBarText() const { | 353 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) { |
291 return l10n_util::GetStringUTF16( | 354 return DialogNotification( |
292 IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR); | 355 DialogNotification::SECURITY_WARNING, |
| 356 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING)); |
| 357 } |
| 358 |
| 359 if (!invoked_from_same_origin_) { |
| 360 return DialogNotification( |
| 361 DialogNotification::SECURITY_WARNING, |
| 362 l10n_util::GetStringFUTF16( |
| 363 IDS_AUTOFILL_DIALOG_SITE_WARNING, UTF8ToUTF16(source_url_.host()))); |
| 364 } |
| 365 |
| 366 return DialogNotification(); |
293 } | 367 } |
294 | 368 |
295 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( | 369 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( |
296 DialogSection section) const { | 370 DialogSection section) const { |
297 switch (section) { | 371 switch (section) { |
298 case SECTION_EMAIL: | 372 case SECTION_EMAIL: |
299 return requested_email_fields_; | 373 return requested_email_fields_; |
300 case SECTION_CC: | 374 case SECTION_CC: |
301 return requested_cc_fields_; | 375 return requested_cc_fields_; |
302 case SECTION_BILLING: | 376 case SECTION_BILLING: |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 popup_labels, | 581 popup_labels, |
508 popup_icons, | 582 popup_icons, |
509 popup_ids); | 583 popup_ids); |
510 section_showing_popup_ = section; | 584 section_showing_popup_ = section; |
511 } | 585 } |
512 | 586 |
513 void AutofillDialogControllerImpl::FocusMoved() { | 587 void AutofillDialogControllerImpl::FocusMoved() { |
514 HidePopup(); | 588 HidePopup(); |
515 } | 589 } |
516 | 590 |
| 591 Profile* AutofillDialogControllerImpl::profile() { |
| 592 return profile_; |
| 593 } |
| 594 |
| 595 content::WebContents* AutofillDialogControllerImpl::web_contents() { |
| 596 return contents_; |
| 597 } |
| 598 |
| 599 void AutofillDialogControllerImpl::StartSignInFlow() { |
| 600 DCHECK(registrar_.IsEmpty()); |
| 601 |
| 602 content::Source<content::NavigationController> source( |
| 603 &view_->ShowSignIn()); |
| 604 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); |
| 605 } |
| 606 |
| 607 void AutofillDialogControllerImpl::EndSignInFlow() { |
| 608 DCHECK(!registrar_.IsEmpty()); |
| 609 registrar_.RemoveAll(); |
| 610 view_->HideSignIn(); |
| 611 } |
| 612 |
| 613 void AutofillDialogControllerImpl::LegalDocumentLinkClicked(size_t index) { |
| 614 DCHECK(wallet_items_); |
| 615 DCHECK_LT(index, wallet_items_->legal_documents().size()); |
| 616 |
| 617 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
| 618 GURL url(wallet_items_->legal_documents()[index]->GetUrl()); |
| 619 chrome::NavigateParams params(browser, url, content::PAGE_TRANSITION_LINK); |
| 620 params.disposition = NEW_FOREGROUND_TAB; |
| 621 |
| 622 chrome::Navigate(¶ms); |
| 623 } |
| 624 |
517 void AutofillDialogControllerImpl::ViewClosed(DialogAction action) { | 625 void AutofillDialogControllerImpl::ViewClosed(DialogAction action) { |
518 if (action == ACTION_SUBMIT) { | 626 if (action == ACTION_SUBMIT) { |
519 FillOutputForSection(SECTION_EMAIL); | 627 FillOutputForSection(SECTION_EMAIL); |
520 FillOutputForSection(SECTION_CC); | 628 FillOutputForSection(SECTION_CC); |
521 FillOutputForSection(SECTION_BILLING); | 629 FillOutputForSection(SECTION_BILLING); |
522 if (view_->UseBillingForShipping()) { | 630 if (view_->UseBillingForShipping()) { |
523 FillOutputForSectionWithComparator( | 631 FillOutputForSectionWithComparator( |
524 SECTION_BILLING, | 632 SECTION_BILLING, |
525 base::Bind(DetailInputMatchesShippingField)); | 633 base::Bind(DetailInputMatchesShippingField)); |
526 FillOutputForSectionWithComparator( | 634 FillOutputForSectionWithComparator( |
527 SECTION_CC, | 635 SECTION_CC, |
528 base::Bind(DetailInputMatchesShippingField)); | 636 base::Bind(DetailInputMatchesShippingField)); |
529 } else { | 637 } else { |
530 FillOutputForSection(SECTION_SHIPPING); | 638 FillOutputForSection(SECTION_SHIPPING); |
531 } | 639 } |
532 callback_.Run(&form_structure_); | 640 callback_.Run(&form_structure_); |
533 } else { | 641 } else { |
534 callback_.Run(NULL); | 642 callback_.Run(NULL); |
535 } | 643 } |
536 | 644 |
537 delete this; | 645 delete this; |
538 } | 646 } |
539 | 647 |
540 void AutofillDialogControllerImpl::UpdateProgressBar(double value) { | |
541 view_->UpdateProgressBar(value); | |
542 } | |
543 | |
544 DialogNotification AutofillDialogControllerImpl::CurrentNotification() const { | |
545 if (HasRequiredAction(wallet::VERIFY_CVV)) { | |
546 return DialogNotification( | |
547 DialogNotification::REQUIRED_ACTION, | |
548 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV)); | |
549 } | |
550 | |
551 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) { | |
552 return DialogNotification( | |
553 DialogNotification::SECURITY_WARNING, | |
554 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING)); | |
555 } | |
556 | |
557 if (!invoked_from_same_origin_) { | |
558 return DialogNotification( | |
559 DialogNotification::SECURITY_WARNING, | |
560 l10n_util::GetStringFUTF16( | |
561 IDS_AUTOFILL_DIALOG_SITE_WARNING, UTF8ToUTF16(source_url_.host()))); | |
562 } | |
563 | |
564 return DialogNotification(); | |
565 } | |
566 | |
567 void AutofillDialogControllerImpl::StartSignInFlow() { | |
568 DCHECK(registrar_.IsEmpty()); | |
569 | |
570 content::Source<content::NavigationController> source( | |
571 &view_->ShowSignIn()); | |
572 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); | |
573 } | |
574 | |
575 void AutofillDialogControllerImpl::EndSignInFlow() { | |
576 DCHECK(!registrar_.IsEmpty()); | |
577 registrar_.RemoveAll(); | |
578 view_->HideSignIn(); | |
579 } | |
580 | |
581 Profile* AutofillDialogControllerImpl::profile() { | |
582 return profile_; | |
583 } | |
584 | |
585 content::WebContents* AutofillDialogControllerImpl::web_contents() { | |
586 return contents_; | |
587 } | |
588 | |
589 //////////////////////////////////////////////////////////////////////////////// | 648 //////////////////////////////////////////////////////////////////////////////// |
590 // AutofillPopupDelegate | 649 // AutofillPopupDelegate |
591 | 650 |
592 void AutofillDialogControllerImpl::OnPopupShown( | 651 void AutofillDialogControllerImpl::OnPopupShown( |
593 content::KeyboardListener* listener) {} | 652 content::KeyboardListener* listener) {} |
594 | 653 |
595 void AutofillDialogControllerImpl::OnPopupHidden( | 654 void AutofillDialogControllerImpl::OnPopupHidden( |
596 content::KeyboardListener* listener) {} | 655 content::KeyboardListener* listener) {} |
597 | 656 |
598 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { | 657 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 void AutofillDialogControllerImpl::OnDidGetFullWallet( | 739 void AutofillDialogControllerImpl::OnDidGetFullWallet( |
681 scoped_ptr<wallet::FullWallet> full_wallet) { | 740 scoped_ptr<wallet::FullWallet> full_wallet) { |
682 NOTIMPLEMENTED(); | 741 NOTIMPLEMENTED(); |
683 } | 742 } |
684 | 743 |
685 void AutofillDialogControllerImpl::OnDidGetWalletItems( | 744 void AutofillDialogControllerImpl::OnDidGetWalletItems( |
686 scoped_ptr<wallet::WalletItems> wallet_items) { | 745 scoped_ptr<wallet::WalletItems> wallet_items) { |
687 wallet_items_ = wallet_items.Pass(); | 746 wallet_items_ = wallet_items.Pass(); |
688 view_->UpdateAccountChooser(); | 747 view_->UpdateAccountChooser(); |
689 view_->UpdateNotificationArea(); | 748 view_->UpdateNotificationArea(); |
| 749 view_->UpdateFootnote(); |
690 } | 750 } |
691 | 751 |
692 void AutofillDialogControllerImpl::OnDidSaveAddress( | 752 void AutofillDialogControllerImpl::OnDidSaveAddress( |
693 const std::string& address_id) { | 753 const std::string& address_id) { |
694 NOTIMPLEMENTED() << " address_id=" << address_id; | 754 NOTIMPLEMENTED() << " address_id=" << address_id; |
695 } | 755 } |
696 | 756 |
697 void AutofillDialogControllerImpl::OnDidSaveInstrument( | 757 void AutofillDialogControllerImpl::OnDidSaveInstrument( |
698 const std::string& instrument_id) { | 758 const std::string& instrument_id) { |
699 NOTIMPLEMENTED() << " instrument_id=" << instrument_id; | 759 NOTIMPLEMENTED() << " instrument_id=" << instrument_id; |
(...skipping 19 matching lines...) Expand all Loading... |
719 wallet_items_.reset(); | 779 wallet_items_.reset(); |
720 } | 780 } |
721 | 781 |
722 void AutofillDialogControllerImpl::OnNetworkError(int response_code) { | 782 void AutofillDialogControllerImpl::OnNetworkError(int response_code) { |
723 NOTIMPLEMENTED() << " response_code=" << response_code; | 783 NOTIMPLEMENTED() << " response_code=" << response_code; |
724 wallet_items_.reset(); | 784 wallet_items_.reset(); |
725 } | 785 } |
726 | 786 |
727 //////////////////////////////////////////////////////////////////////////////// | 787 //////////////////////////////////////////////////////////////////////////////// |
728 | 788 |
| 789 void AutofillDialogControllerImpl::UpdateProgressBar(double value) { |
| 790 view_->UpdateProgressBar(value); |
| 791 } |
| 792 |
729 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( | 793 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( |
730 const content::NativeWebKeyboardEvent& event) { | 794 const content::NativeWebKeyboardEvent& event) { |
731 if (popup_controller_) | 795 if (popup_controller_) |
732 return popup_controller_->HandleKeyPressEvent(event); | 796 return popup_controller_->HandleKeyPressEvent(event); |
733 | 797 |
734 return false; | 798 return false; |
735 } | 799 } |
736 | 800 |
737 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { | 801 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { |
738 DCHECK_GT(form_structure_.field_count(), 0U); | 802 DCHECK_GT(form_structure_.field_count(), 0U); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 DialogSection section) { | 1012 DialogSection section) { |
949 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 1013 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
950 } | 1014 } |
951 | 1015 |
952 void AutofillDialogControllerImpl::HidePopup() { | 1016 void AutofillDialogControllerImpl::HidePopup() { |
953 if (popup_controller_) | 1017 if (popup_controller_) |
954 popup_controller_->Hide(); | 1018 popup_controller_->Hide(); |
955 } | 1019 } |
956 | 1020 |
957 } // namespace autofill | 1021 } // namespace autofill |
OLD | NEW |