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" |
32 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
33 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
34 #include "net/base/cert_status_flags.h" | 36 #include "net/base/cert_status_flags.h" |
35 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
36 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
39 #include "ui/base/window_open_disposition.h" | |
37 | 40 |
38 namespace autofill { | 41 namespace autofill { |
39 | 42 |
40 namespace { | 43 namespace { |
41 | 44 |
42 // Returns true if |input| should be shown when |field| has been requested. | 45 // Returns true if |input| should be shown when |field| has been requested. |
43 bool InputTypeMatchesFieldType(const DetailInput& input, | 46 bool InputTypeMatchesFieldType(const DetailInput& input, |
44 const AutofillField& field) { | 47 const AutofillField& field) { |
45 // If any credit card expiration info is asked for, show both month and year | 48 // If any credit card expiration info is asked for, show both month and year |
46 // inputs. | 49 // inputs. |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 string16 AutofillDialogControllerImpl::SignInText() const { | 266 string16 AutofillDialogControllerImpl::SignInText() const { |
264 // TODO(abodenha): real strings and l10n. | 267 // TODO(abodenha): real strings and l10n. |
265 return string16(ASCIIToUTF16("Sign in to use Google Wallet")); | 268 return string16(ASCIIToUTF16("Sign in to use Google Wallet")); |
266 } | 269 } |
267 | 270 |
268 string16 AutofillDialogControllerImpl::CancelSignInText() const { | 271 string16 AutofillDialogControllerImpl::CancelSignInText() const { |
269 // TODO(abodenha): real strings and l10n. | 272 // TODO(abodenha): real strings and l10n. |
270 return string16(ASCIIToUTF16("Don't sign in.")); | 273 return string16(ASCIIToUTF16("Don't sign in.")); |
271 } | 274 } |
272 | 275 |
276 string16 AutofillDialogControllerImpl::SaveLocallyText() const { | |
277 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); | |
278 } | |
279 | |
280 string16 AutofillDialogControllerImpl::ProgressBarText() const { | |
281 return l10n_util::GetStringUTF16( | |
282 IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR); | |
283 } | |
284 | |
285 std::vector<string16> AutofillDialogControllerImpl::FootnoteLinkParts() const { | |
286 if (!wallet_items_ || wallet_items_->legal_documents().empty()) | |
287 return std::vector<string16>(); | |
288 | |
289 const std::vector<wallet::WalletItems::LegalDocument*>& documents = | |
290 wallet_items_->legal_documents(); | |
291 DCHECK_LE(documents.size(), 2U); | |
292 | |
293 const bool new_user = HasRequiredAction(wallet::SETUP_WALLET); | |
294 | |
295 string16 text; | |
296 switch (documents.size()) { | |
297 case 1U: | |
298 text = l10n_util::GetStringFUTF16( | |
299 new_user ? IDS_AUTOFILL_DIALOG_LEGAL_LINKS_NEW_2 : | |
300 IDS_AUTOFILL_DIALOG_LEGAL_LINKS_UPDATED_2, | |
301 documents[0]->display_name(), | |
302 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PRIVACY_NOTICE)); | |
303 break; | |
304 case 2U: | |
305 text = l10n_util::GetStringFUTF16( | |
306 new_user ? IDS_AUTOFILL_DIALOG_LEGAL_LINKS_NEW_3 : | |
307 IDS_AUTOFILL_DIALOG_LEGAL_LINKS_UPDATED_3, | |
308 documents[0]->display_name(), | |
309 documents[1]->display_name(), | |
310 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PRIVACY_NOTICE)); | |
311 break; | |
312 } | |
313 TrimWhitespace(text, TRIM_ALL, &text); | |
314 | |
315 std::vector<string16> parts; | |
316 base::SplitStringDontTrim(text, '|', &parts); | |
317 DCHECK_EQ(1U, parts.size() % 2); | |
318 | |
319 return parts; | |
320 } | |
321 | |
322 string16 AutofillDialogControllerImpl::AcceptFootnoteLinksText() const { | |
323 return l10n_util::GetStringUTF16(HasRequiredAction(wallet::SETUP_WALLET) ? | |
324 IDS_AUTOFILL_DIALOG_ACCEPT_NEW : IDS_AUTOFILL_DIALOG_ACCEPT_UPDATE); | |
325 } | |
326 | |
273 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { | 327 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { |
274 if (!wallet_items_) | 328 if (!wallet_items_) |
275 return REQUIRES_RESPONSE; | 329 return REQUIRES_RESPONSE; |
276 | 330 |
277 if (HasRequiredAction(wallet::GAIA_AUTH)) | 331 if (HasRequiredAction(wallet::GAIA_AUTH)) |
278 return REQUIRES_SIGN_IN; | 332 return REQUIRES_SIGN_IN; |
279 | 333 |
280 if (HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) | 334 if (HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) |
281 return REQUIRES_PASSIVE_SIGN_IN; | 335 return REQUIRES_PASSIVE_SIGN_IN; |
282 | 336 |
283 return SIGNED_IN; | 337 return SIGNED_IN; |
284 } | 338 } |
285 | 339 |
286 string16 AutofillDialogControllerImpl::SaveLocallyText() const { | 340 DialogNotification AutofillDialogControllerImpl::CurrentNotification() const { |
287 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); | 341 if (HasRequiredAction(wallet::VERIFY_CVV)) { |
288 } | 342 return DialogNotification( |
343 DialogNotification::REQUIRED_ACTION, | |
344 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV)); | |
345 } | |
289 | 346 |
290 string16 AutofillDialogControllerImpl::ProgressBarText() const { | 347 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) { |
291 return l10n_util::GetStringUTF16( | 348 return DialogNotification( |
292 IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR); | 349 DialogNotification::SECURITY_WARNING, |
350 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING)); | |
351 } | |
352 | |
353 if (!invoked_from_same_origin_) { | |
354 return DialogNotification( | |
355 DialogNotification::SECURITY_WARNING, | |
356 l10n_util::GetStringFUTF16( | |
357 IDS_AUTOFILL_DIALOG_SITE_WARNING, UTF8ToUTF16(source_url_.host()))); | |
358 } | |
359 | |
360 return DialogNotification(); | |
293 } | 361 } |
294 | 362 |
295 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( | 363 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( |
296 DialogSection section) const { | 364 DialogSection section) const { |
297 switch (section) { | 365 switch (section) { |
298 case SECTION_EMAIL: | 366 case SECTION_EMAIL: |
299 return requested_email_fields_; | 367 return requested_email_fields_; |
300 case SECTION_CC: | 368 case SECTION_CC: |
301 return requested_cc_fields_; | 369 return requested_cc_fields_; |
302 case SECTION_BILLING: | 370 case SECTION_BILLING: |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
507 popup_labels, | 575 popup_labels, |
508 popup_icons, | 576 popup_icons, |
509 popup_ids); | 577 popup_ids); |
510 section_showing_popup_ = section; | 578 section_showing_popup_ = section; |
511 } | 579 } |
512 | 580 |
513 void AutofillDialogControllerImpl::FocusMoved() { | 581 void AutofillDialogControllerImpl::FocusMoved() { |
514 HidePopup(); | 582 HidePopup(); |
515 } | 583 } |
516 | 584 |
585 Profile* AutofillDialogControllerImpl::profile() { | |
586 return profile_; | |
587 } | |
588 | |
589 content::WebContents* AutofillDialogControllerImpl::web_contents() { | |
590 return contents_; | |
591 } | |
592 | |
593 void AutofillDialogControllerImpl::StartSignInFlow() { | |
594 DCHECK(registrar_.IsEmpty()); | |
595 | |
596 content::Source<content::NavigationController> source( | |
597 &view_->ShowSignIn()); | |
598 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source); | |
599 } | |
600 | |
601 void AutofillDialogControllerImpl::EndSignInFlow() { | |
602 DCHECK(!registrar_.IsEmpty()); | |
603 registrar_.RemoveAll(); | |
604 view_->HideSignIn(); | |
605 } | |
606 | |
607 void AutofillDialogControllerImpl::LegalDocumentLinkClicked(size_t index) { | |
608 DCHECK(wallet_items_); | |
609 DCHECK_LE(index, wallet_items_->legal_documents().size()); | |
610 | |
611 GURL url(index == wallet_items_->legal_documents().size() ? | |
612 GURL(wallet::kPrivacyNoticeUrl) : | |
613 wallet_items_->legal_documents()[index]->GetUrl()); | |
614 #if defined(OS_ANDROID) | |
615 NOTIMPLEMENTED() << " open: " << url.spec(); | |
Evan Stade
2013/02/12 01:36:54
NOTIMPLEMENTED is annoying, you should not use it.
| |
616 #else | |
617 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | |
618 chrome::NavigateParams params(browser, url, content::PAGE_TRANSITION_LINK); | |
619 params.disposition = NEW_FOREGROUND_TAB; | |
620 chrome::Navigate(¶ms); | |
621 #endif | |
622 } | |
623 | |
517 void AutofillDialogControllerImpl::ViewClosed(DialogAction action) { | 624 void AutofillDialogControllerImpl::ViewClosed(DialogAction action) { |
518 if (action == ACTION_SUBMIT) { | 625 if (action == ACTION_SUBMIT) { |
519 FillOutputForSection(SECTION_EMAIL); | 626 FillOutputForSection(SECTION_EMAIL); |
520 FillOutputForSection(SECTION_CC); | 627 FillOutputForSection(SECTION_CC); |
521 FillOutputForSection(SECTION_BILLING); | 628 FillOutputForSection(SECTION_BILLING); |
522 if (view_->UseBillingForShipping()) { | 629 if (view_->UseBillingForShipping()) { |
523 FillOutputForSectionWithComparator( | 630 FillOutputForSectionWithComparator( |
524 SECTION_BILLING, | 631 SECTION_BILLING, |
525 base::Bind(DetailInputMatchesShippingField)); | 632 base::Bind(DetailInputMatchesShippingField)); |
526 FillOutputForSectionWithComparator( | 633 FillOutputForSectionWithComparator( |
527 SECTION_CC, | 634 SECTION_CC, |
528 base::Bind(DetailInputMatchesShippingField)); | 635 base::Bind(DetailInputMatchesShippingField)); |
529 } else { | 636 } else { |
530 FillOutputForSection(SECTION_SHIPPING); | 637 FillOutputForSection(SECTION_SHIPPING); |
531 } | 638 } |
532 callback_.Run(&form_structure_); | 639 callback_.Run(&form_structure_); |
533 } else { | 640 } else { |
534 callback_.Run(NULL); | 641 callback_.Run(NULL); |
535 } | 642 } |
536 | 643 |
537 delete this; | 644 delete this; |
538 } | 645 } |
539 | 646 |
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 //////////////////////////////////////////////////////////////////////////////// | 647 //////////////////////////////////////////////////////////////////////////////// |
590 // AutofillPopupDelegate | 648 // AutofillPopupDelegate |
591 | 649 |
592 void AutofillDialogControllerImpl::OnPopupShown( | 650 void AutofillDialogControllerImpl::OnPopupShown( |
593 content::KeyboardListener* listener) {} | 651 content::KeyboardListener* listener) {} |
594 | 652 |
595 void AutofillDialogControllerImpl::OnPopupHidden( | 653 void AutofillDialogControllerImpl::OnPopupHidden( |
596 content::KeyboardListener* listener) {} | 654 content::KeyboardListener* listener) {} |
597 | 655 |
598 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { | 656 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 void AutofillDialogControllerImpl::OnDidGetFullWallet( | 738 void AutofillDialogControllerImpl::OnDidGetFullWallet( |
681 scoped_ptr<wallet::FullWallet> full_wallet) { | 739 scoped_ptr<wallet::FullWallet> full_wallet) { |
682 NOTIMPLEMENTED(); | 740 NOTIMPLEMENTED(); |
683 } | 741 } |
684 | 742 |
685 void AutofillDialogControllerImpl::OnDidGetWalletItems( | 743 void AutofillDialogControllerImpl::OnDidGetWalletItems( |
686 scoped_ptr<wallet::WalletItems> wallet_items) { | 744 scoped_ptr<wallet::WalletItems> wallet_items) { |
687 wallet_items_ = wallet_items.Pass(); | 745 wallet_items_ = wallet_items.Pass(); |
688 view_->UpdateAccountChooser(); | 746 view_->UpdateAccountChooser(); |
689 view_->UpdateNotificationArea(); | 747 view_->UpdateNotificationArea(); |
748 view_->UpdateFootnote(); | |
690 } | 749 } |
691 | 750 |
692 void AutofillDialogControllerImpl::OnDidSaveAddress( | 751 void AutofillDialogControllerImpl::OnDidSaveAddress( |
693 const std::string& address_id) { | 752 const std::string& address_id) { |
694 NOTIMPLEMENTED() << " address_id=" << address_id; | 753 NOTIMPLEMENTED() << " address_id=" << address_id; |
695 } | 754 } |
696 | 755 |
697 void AutofillDialogControllerImpl::OnDidSaveInstrument( | 756 void AutofillDialogControllerImpl::OnDidSaveInstrument( |
698 const std::string& instrument_id) { | 757 const std::string& instrument_id) { |
699 NOTIMPLEMENTED() << " instrument_id=" << instrument_id; | 758 NOTIMPLEMENTED() << " instrument_id=" << instrument_id; |
(...skipping 19 matching lines...) Expand all Loading... | |
719 wallet_items_.reset(); | 778 wallet_items_.reset(); |
720 } | 779 } |
721 | 780 |
722 void AutofillDialogControllerImpl::OnNetworkError(int response_code) { | 781 void AutofillDialogControllerImpl::OnNetworkError(int response_code) { |
723 NOTIMPLEMENTED() << " response_code=" << response_code; | 782 NOTIMPLEMENTED() << " response_code=" << response_code; |
724 wallet_items_.reset(); | 783 wallet_items_.reset(); |
725 } | 784 } |
726 | 785 |
727 //////////////////////////////////////////////////////////////////////////////// | 786 //////////////////////////////////////////////////////////////////////////////// |
728 | 787 |
788 void AutofillDialogControllerImpl::UpdateProgressBar(double value) { | |
789 view_->UpdateProgressBar(value); | |
790 } | |
791 | |
729 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( | 792 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( |
730 const content::NativeWebKeyboardEvent& event) { | 793 const content::NativeWebKeyboardEvent& event) { |
731 if (popup_controller_) | 794 if (popup_controller_) |
732 return popup_controller_->HandleKeyPressEvent(event); | 795 return popup_controller_->HandleKeyPressEvent(event); |
733 | 796 |
734 return false; | 797 return false; |
735 } | 798 } |
736 | 799 |
737 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { | 800 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { |
738 DCHECK_GT(form_structure_.field_count(), 0U); | 801 DCHECK_GT(form_structure_.field_count(), 0U); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
948 DialogSection section) { | 1011 DialogSection section) { |
949 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 1012 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
950 } | 1013 } |
951 | 1014 |
952 void AutofillDialogControllerImpl::HidePopup() { | 1015 void AutofillDialogControllerImpl::HidePopup() { |
953 if (popup_controller_) | 1016 if (popup_controller_) |
954 popup_controller_->Hide(); | 1017 popup_controller_->Hide(); |
955 } | 1018 } |
956 | 1019 |
957 } // namespace autofill | 1020 } // namespace autofill |
OLD | NEW |