Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 12225095: Interactive autofill: Adds footnote view to accept legal documents in the UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: closer? Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
42 // Returns true if |input| should be shown when |field| has been requested. 46 // Returns true if |input| should be shown when |field| has been requested.
43 bool InputTypeMatchesFieldType(const DetailInput& input, 47 bool InputTypeMatchesFieldType(const DetailInput& input,
44 const AutofillField& field) { 48 const AutofillField& field) {
45 // If any credit card expiration info is asked for, show both month and year 49 // If any credit card expiration info is asked for, show both month and year
46 // inputs. 50 // inputs.
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 string16 AutofillDialogControllerImpl::SignInText() const { 267 string16 AutofillDialogControllerImpl::SignInText() const {
264 // TODO(abodenha): real strings and l10n. 268 // TODO(abodenha): real strings and l10n.
265 return string16(ASCIIToUTF16("Sign in to use Google Wallet")); 269 return string16(ASCIIToUTF16("Sign in to use Google Wallet"));
266 } 270 }
267 271
268 string16 AutofillDialogControllerImpl::CancelSignInText() const { 272 string16 AutofillDialogControllerImpl::CancelSignInText() const {
269 // TODO(abodenha): real strings and l10n. 273 // TODO(abodenha): real strings and l10n.
270 return string16(ASCIIToUTF16("Don't sign in.")); 274 return string16(ASCIIToUTF16("Don't sign in."));
271 } 275 }
272 276
277 string16 AutofillDialogControllerImpl::SaveLocallyText() const {
278 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX);
279 }
280
281 string16 AutofillDialogControllerImpl::ProgressBarText() const {
282 return l10n_util::GetStringUTF16(
283 IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR);
284 }
285
286 std::vector<string16> AutofillDialogControllerImpl::FootnoteLinkParts() const {
287 if (!wallet_items_ || wallet_items_->legal_documents().empty() ||
288 wallet_items_->legal_documents().size() > 3U) {
289 return std::vector<string16>();
290 }
291
292 const std::vector<wallet::WalletItems::LegalDocument*>& documents =
293 wallet_items_->legal_documents();
294
295 string16 text;
296 switch (documents.size()) {
297 case 1U:
298 text = l10n_util::GetStringFUTF16(
299 IDS_AUTOFILL_DIALOG_LEGAL_DOC_LINKS_1,
300 ASCIIToUTF16(documents[0]->display_name()));
301 break;
302 case 2U:
303 text = l10n_util::GetStringFUTF16(
304 IDS_AUTOFILL_DIALOG_LEGAL_DOC_LINKS_2,
305 ASCIIToUTF16(documents[0]->display_name()),
306 ASCIIToUTF16(documents[1]->display_name()));
307 break;
308 case 3U:
ahutter 2013/02/11 16:00:53 Based in our conversations on Friday; this case is
Dan Beam 2013/02/11 19:27:50 Done.
309 text = l10n_util::GetStringFUTF16(
310 IDS_AUTOFILL_DIALOG_LEGAL_DOC_LINKS_3,
311 ASCIIToUTF16(documents[0]->display_name()),
Evan Stade 2013/02/11 01:05:23 The display name should be string16. That needs to
ahutter 2013/02/11 16:00:53 Can any chrome UI be displayed without string16?
Dan Beam 2013/02/11 19:27:50 Anything that's translated should be string16. Alm
312 ASCIIToUTF16(documents[1]->display_name()),
313 ASCIIToUTF16(documents[2]->display_name()));
314 break;
Evan Stade 2013/02/11 01:05:23 default: notreached
Dan Beam 2013/02/11 19:27:50 size_t can't be negative, was bailing if size() >
315 }
316 TrimWhitespace(text, TRIM_ALL, &text);
317
318 std::vector<string16> parts;
319 base::SplitStringDontTrim(text, '|', &parts);
320 DCHECK_EQ(1U, parts.size() % 2);
321
322 return parts;
323 }
324
325 string16 AutofillDialogControllerImpl::AcceptChangesText() const {
326 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_ACCEPT_CHANGES);
327 }
328
273 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { 329 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const {
274 if (!wallet_items_) 330 if (!wallet_items_)
275 return REQUIRES_RESPONSE; 331 return REQUIRES_RESPONSE;
276 332
277 if (HasRequiredAction(wallet::GAIA_AUTH)) 333 if (HasRequiredAction(wallet::GAIA_AUTH))
278 return REQUIRES_SIGN_IN; 334 return REQUIRES_SIGN_IN;
279 335
280 if (HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) 336 if (HasRequiredAction(wallet::PASSIVE_GAIA_AUTH))
281 return REQUIRES_PASSIVE_SIGN_IN; 337 return REQUIRES_PASSIVE_SIGN_IN;
282 338
283 return SIGNED_IN; 339 return SIGNED_IN;
284 } 340 }
285 341
286 string16 AutofillDialogControllerImpl::SaveLocallyText() const { 342 DialogNotification AutofillDialogControllerImpl::CurrentNotification() const {
287 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); 343 if (HasRequiredAction(wallet::VERIFY_CVV)) {
288 } 344 return DialogNotification(
345 DialogNotification::REQUIRED_ACTION,
346 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV));
347 }
289 348
290 string16 AutofillDialogControllerImpl::ProgressBarText() const { 349 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) {
291 return l10n_util::GetStringUTF16( 350 return DialogNotification(
292 IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR); 351 DialogNotification::SECURITY_WARNING,
352 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING));
353 }
354
355 if (!invoked_from_same_origin_) {
356 return DialogNotification(
357 DialogNotification::SECURITY_WARNING,
358 l10n_util::GetStringFUTF16(
359 IDS_AUTOFILL_DIALOG_SITE_WARNING, UTF8ToUTF16(source_url_.host())));
360 }
361
362 return DialogNotification();
293 } 363 }
294 364
295 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( 365 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection(
296 DialogSection section) const { 366 DialogSection section) const {
297 switch (section) { 367 switch (section) {
298 case SECTION_EMAIL: 368 case SECTION_EMAIL:
299 return requested_email_fields_; 369 return requested_email_fields_;
300 case SECTION_CC: 370 case SECTION_CC:
301 return requested_cc_fields_; 371 return requested_cc_fields_;
302 case SECTION_BILLING: 372 case SECTION_BILLING:
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 popup_labels, 577 popup_labels,
508 popup_icons, 578 popup_icons,
509 popup_ids); 579 popup_ids);
510 section_showing_popup_ = section; 580 section_showing_popup_ = section;
511 } 581 }
512 582
513 void AutofillDialogControllerImpl::FocusMoved() { 583 void AutofillDialogControllerImpl::FocusMoved() {
514 HidePopup(); 584 HidePopup();
515 } 585 }
516 586
587 Profile* AutofillDialogControllerImpl::profile() {
588 return profile_;
589 }
590
591 content::WebContents* AutofillDialogControllerImpl::web_contents() {
592 return contents_;
593 }
594
595 void AutofillDialogControllerImpl::StartSignInFlow() {
596 DCHECK(registrar_.IsEmpty());
597
598 content::Source<content::NavigationController> source(
599 &view_->ShowSignIn());
600 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source);
601 }
602
603 void AutofillDialogControllerImpl::EndSignInFlow() {
604 DCHECK(!registrar_.IsEmpty());
605 registrar_.RemoveAll();
606 view_->HideSignIn();
607 }
608
609 void AutofillDialogControllerImpl::LegalDocumentLinkClicked(size_t index) {
610 DCHECK(wallet_items_);
611 DCHECK_LT(index, wallet_items_->legal_documents().size());
612
613 GURL url(wallet_items_->legal_documents()[index]->GetUrl());
614 #if defined(OS_ANDROID)
Dan Beam 2013/02/09 02:57:13 So I guess Android is failing to compile because i
Evan Stade 2013/02/11 01:05:23 Looks like unit tests and test shell aren't compil
Dan Beam 2013/02/11 19:27:50 Done.
615 NOTIMPLEMENTED() << " open: " << url.spec();
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(&params);
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
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
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
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
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.h ('k') | chrome/browser/ui/autofill/autofill_dialog_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698