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(), 3U); | |
ahutter
2013/02/11 16:00:53
Should be 2U
Dan Beam
2013/02/11 18:30:05
Done.
| |
292 | |
293 const bool new_user = HasRequiredAction(wallet::SETUP_WALLET); | |
294 | |
295 string16 text; | |
ahutter
2013/02/11 16:00:53
Where is the privacy policy?
Dan Beam
2013/02/11 18:30:05
Adding.
| |
296 switch (documents.size()) { | |
297 case 1U: | |
298 text = l10n_util::GetStringFUTF16( | |
299 new_user ? IDS_AUTOFILL_DIALOG_LEGAL_LINKS_NEW_1 : | |
300 IDS_AUTOFILL_DIALOG_LEGAL_LINKS_UPDATED_1, | |
301 ASCIIToUTF16(documents[0]->display_name())); | |
302 break; | |
303 case 2U: | |
304 text = l10n_util::GetStringFUTF16( | |
305 new_user ? IDS_AUTOFILL_DIALOG_LEGAL_LINKS_NEW_2 : | |
306 IDS_AUTOFILL_DIALOG_LEGAL_LINKS_UPDATED_2, | |
307 ASCIIToUTF16(documents[0]->display_name()), | |
308 ASCIIToUTF16(documents[1]->display_name())); | |
309 break; | |
310 case 3U: | |
ahutter
2013/02/11 16:00:53
Can't happen.
Dan Beam
2013/02/11 18:30:05
Yeah, figured this out.
| |
311 text = l10n_util::GetStringFUTF16( | |
312 new_user ? IDS_AUTOFILL_DIALOG_LEGAL_LINKS_NEW_3 : | |
313 IDS_AUTOFILL_DIALOG_LEGAL_LINKS_UPDATED_3, | |
314 ASCIIToUTF16(documents[0]->display_name()), | |
315 ASCIIToUTF16(documents[1]->display_name()), | |
316 ASCIIToUTF16(documents[2]->display_name())); | |
317 break; | |
318 } | |
319 TrimWhitespace(text, TRIM_ALL, &text); | |
320 | |
321 std::vector<string16> parts; | |
322 base::SplitStringDontTrim(text, '|', &parts); | |
323 DCHECK_EQ(1U, parts.size() % 2); | |
324 | |
325 return parts; | |
326 } | |
327 | |
328 string16 AutofillDialogControllerImpl::AcceptFootnoteLinksText() const { | |
329 return l10n_util::GetStringUTF16(HasRequiredAction(wallet::SETUP_WALLET) ? | |
330 IDS_AUTOFILL_DIALOG_ACCEPT_NEW : IDS_AUTOFILL_DIALOG_ACCEPT_UPDATE); | |
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 GURL url(wallet_items_->legal_documents()[index]->GetUrl()); | |
618 #if defined(OS_ANDROID) | |
619 NOTIMPLEMENTED() << " open: " << url.spec(); | |
620 #else | |
621 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | |
622 chrome::NavigateParams params(browser, url, content::PAGE_TRANSITION_LINK); | |
623 params.disposition = NEW_FOREGROUND_TAB; | |
624 chrome::Navigate(¶ms); | |
625 #endif | |
626 } | |
627 | |
517 void AutofillDialogControllerImpl::ViewClosed(DialogAction action) { | 628 void AutofillDialogControllerImpl::ViewClosed(DialogAction action) { |
518 if (action == ACTION_SUBMIT) { | 629 if (action == ACTION_SUBMIT) { |
519 FillOutputForSection(SECTION_EMAIL); | 630 FillOutputForSection(SECTION_EMAIL); |
520 FillOutputForSection(SECTION_CC); | 631 FillOutputForSection(SECTION_CC); |
521 FillOutputForSection(SECTION_BILLING); | 632 FillOutputForSection(SECTION_BILLING); |
522 if (view_->UseBillingForShipping()) { | 633 if (view_->UseBillingForShipping()) { |
523 FillOutputForSectionWithComparator( | 634 FillOutputForSectionWithComparator( |
524 SECTION_BILLING, | 635 SECTION_BILLING, |
525 base::Bind(DetailInputMatchesShippingField)); | 636 base::Bind(DetailInputMatchesShippingField)); |
526 FillOutputForSectionWithComparator( | 637 FillOutputForSectionWithComparator( |
527 SECTION_CC, | 638 SECTION_CC, |
528 base::Bind(DetailInputMatchesShippingField)); | 639 base::Bind(DetailInputMatchesShippingField)); |
529 } else { | 640 } else { |
530 FillOutputForSection(SECTION_SHIPPING); | 641 FillOutputForSection(SECTION_SHIPPING); |
531 } | 642 } |
532 callback_.Run(&form_structure_); | 643 callback_.Run(&form_structure_); |
533 } else { | 644 } else { |
534 callback_.Run(NULL); | 645 callback_.Run(NULL); |
535 } | 646 } |
536 | 647 |
537 delete this; | 648 delete this; |
538 } | 649 } |
539 | 650 |
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 //////////////////////////////////////////////////////////////////////////////// | 651 //////////////////////////////////////////////////////////////////////////////// |
590 // AutofillPopupDelegate | 652 // AutofillPopupDelegate |
591 | 653 |
592 void AutofillDialogControllerImpl::OnPopupShown( | 654 void AutofillDialogControllerImpl::OnPopupShown( |
593 content::KeyboardListener* listener) {} | 655 content::KeyboardListener* listener) {} |
594 | 656 |
595 void AutofillDialogControllerImpl::OnPopupHidden( | 657 void AutofillDialogControllerImpl::OnPopupHidden( |
596 content::KeyboardListener* listener) {} | 658 content::KeyboardListener* listener) {} |
597 | 659 |
598 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { | 660 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 void AutofillDialogControllerImpl::OnDidGetFullWallet( | 742 void AutofillDialogControllerImpl::OnDidGetFullWallet( |
681 scoped_ptr<wallet::FullWallet> full_wallet) { | 743 scoped_ptr<wallet::FullWallet> full_wallet) { |
682 NOTIMPLEMENTED(); | 744 NOTIMPLEMENTED(); |
683 } | 745 } |
684 | 746 |
685 void AutofillDialogControllerImpl::OnDidGetWalletItems( | 747 void AutofillDialogControllerImpl::OnDidGetWalletItems( |
686 scoped_ptr<wallet::WalletItems> wallet_items) { | 748 scoped_ptr<wallet::WalletItems> wallet_items) { |
687 wallet_items_ = wallet_items.Pass(); | 749 wallet_items_ = wallet_items.Pass(); |
688 view_->UpdateAccountChooser(); | 750 view_->UpdateAccountChooser(); |
689 view_->UpdateNotificationArea(); | 751 view_->UpdateNotificationArea(); |
752 view_->UpdateFootnote(); | |
690 } | 753 } |
691 | 754 |
692 void AutofillDialogControllerImpl::OnDidSaveAddress( | 755 void AutofillDialogControllerImpl::OnDidSaveAddress( |
693 const std::string& address_id) { | 756 const std::string& address_id) { |
694 NOTIMPLEMENTED() << " address_id=" << address_id; | 757 NOTIMPLEMENTED() << " address_id=" << address_id; |
695 } | 758 } |
696 | 759 |
697 void AutofillDialogControllerImpl::OnDidSaveInstrument( | 760 void AutofillDialogControllerImpl::OnDidSaveInstrument( |
698 const std::string& instrument_id) { | 761 const std::string& instrument_id) { |
699 NOTIMPLEMENTED() << " instrument_id=" << instrument_id; | 762 NOTIMPLEMENTED() << " instrument_id=" << instrument_id; |
(...skipping 19 matching lines...) Expand all Loading... | |
719 wallet_items_.reset(); | 782 wallet_items_.reset(); |
720 } | 783 } |
721 | 784 |
722 void AutofillDialogControllerImpl::OnNetworkError(int response_code) { | 785 void AutofillDialogControllerImpl::OnNetworkError(int response_code) { |
723 NOTIMPLEMENTED() << " response_code=" << response_code; | 786 NOTIMPLEMENTED() << " response_code=" << response_code; |
724 wallet_items_.reset(); | 787 wallet_items_.reset(); |
725 } | 788 } |
726 | 789 |
727 //////////////////////////////////////////////////////////////////////////////// | 790 //////////////////////////////////////////////////////////////////////////////// |
728 | 791 |
792 void AutofillDialogControllerImpl::UpdateProgressBar(double value) { | |
793 view_->UpdateProgressBar(value); | |
794 } | |
795 | |
729 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( | 796 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( |
730 const content::NativeWebKeyboardEvent& event) { | 797 const content::NativeWebKeyboardEvent& event) { |
731 if (popup_controller_) | 798 if (popup_controller_) |
732 return popup_controller_->HandleKeyPressEvent(event); | 799 return popup_controller_->HandleKeyPressEvent(event); |
733 | 800 |
734 return false; | 801 return false; |
735 } | 802 } |
736 | 803 |
737 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { | 804 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { |
738 DCHECK_GT(form_structure_.field_count(), 0U); | 805 DCHECK_GT(form_structure_.field_count(), 0U); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
948 DialogSection section) { | 1015 DialogSection section) { |
949 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 1016 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
950 } | 1017 } |
951 | 1018 |
952 void AutofillDialogControllerImpl::HidePopup() { | 1019 void AutofillDialogControllerImpl::HidePopup() { |
953 if (popup_controller_) | 1020 if (popup_controller_) |
954 popup_controller_->Hide(); | 1021 popup_controller_->Hide(); |
955 } | 1022 } |
956 | 1023 |
957 } // namespace autofill | 1024 } // namespace autofill |
OLD | NEW |