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

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: . 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
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
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::pair<std::vector<string16>, string16>
291 AutofillDialogControllerImpl::FootnoteTextParts() const {
292 string16 full_translation = l10n_util::GetStringFUTF16(
293 IDS_AUTOFILL_DIALOG_ACCEPT_TERMS, ConfirmButtonText());
Evan Stade 2013/02/08 15:38:53 Just make confirmbuttontext part of the translatio
Dan Beam 2013/02/08 20:53:06 Done.
294 TrimWhitespace(full_translation, TRIM_ALL, &full_translation);
295
296 std::vector<string16> sentences;
297 base::SplitString(full_translation, '\n', &sentences);
298 DCHECK_EQ(2U, sentences.size());
299
300 std::vector<string16> parts;
301 base::SplitStringDontTrim(sentences.front(), '|', &parts);
302 DCHECK_EQ(5U, parts.size());
303
304 return std::make_pair(parts, sentences.back());
Evan Stade 2013/02/08 15:38:53 Instead of front and back, use operator[]
Dan Beam 2013/02/08 20:53:06 Done. (but why?)
305 }
306
307 bool AutofillDialogControllerImpl::IsFootnoteShowing() const {
308 return HasRequiredAction(wallet::ACCEPT_TOS);
309 }
310
273 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const { 311 DialogSignedInState AutofillDialogControllerImpl::SignedInState() const {
274 if (!wallet_items_) 312 if (!wallet_items_)
275 return REQUIRES_RESPONSE; 313 return REQUIRES_RESPONSE;
276 314
277 if (HasRequiredAction(wallet::GAIA_AUTH)) 315 if (HasRequiredAction(wallet::GAIA_AUTH))
278 return REQUIRES_SIGN_IN; 316 return REQUIRES_SIGN_IN;
279 317
280 if (HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) 318 if (HasRequiredAction(wallet::PASSIVE_GAIA_AUTH))
281 return REQUIRES_PASSIVE_SIGN_IN; 319 return REQUIRES_PASSIVE_SIGN_IN;
282 320
283 return SIGNED_IN; 321 return SIGNED_IN;
284 } 322 }
285 323
286 string16 AutofillDialogControllerImpl::SaveLocallyText() const { 324 DialogNotification AutofillDialogControllerImpl::CurrentNotification() const {
287 return l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SAVE_LOCALLY_CHECKBOX); 325 if (HasRequiredAction(wallet::VERIFY_CVV)) {
288 } 326 return DialogNotification(
327 DialogNotification::REQUIRED_ACTION,
328 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_VERIFY_CVV));
329 }
289 330
290 string16 AutofillDialogControllerImpl::ProgressBarText() const { 331 if (RequestingCreditCardInfo() && !TransmissionWillBeSecure()) {
291 return l10n_util::GetStringUTF16( 332 return DialogNotification(
292 IDS_AUTOFILL_DIALOG_AUTOCHECKOUT_PROGRESS_BAR); 333 DialogNotification::SECURITY_WARNING,
334 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_SECURITY_WARNING));
335 }
336
337 if (!invoked_from_same_origin_) {
338 return DialogNotification(
339 DialogNotification::SECURITY_WARNING,
340 l10n_util::GetStringFUTF16(
341 IDS_AUTOFILL_DIALOG_SITE_WARNING, UTF8ToUTF16(source_url_.host())));
342 }
343
344 return DialogNotification();
293 } 345 }
294 346
295 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection( 347 const DetailInputs& AutofillDialogControllerImpl::RequestedFieldsForSection(
296 DialogSection section) const { 348 DialogSection section) const {
297 switch (section) { 349 switch (section) {
298 case SECTION_EMAIL: 350 case SECTION_EMAIL:
299 return requested_email_fields_; 351 return requested_email_fields_;
300 case SECTION_CC: 352 case SECTION_CC:
301 return requested_cc_fields_; 353 return requested_cc_fields_;
302 case SECTION_BILLING: 354 case SECTION_BILLING:
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 popup_labels, 559 popup_labels,
508 popup_icons, 560 popup_icons,
509 popup_ids); 561 popup_ids);
510 section_showing_popup_ = section; 562 section_showing_popup_ = section;
511 } 563 }
512 564
513 void AutofillDialogControllerImpl::FocusMoved() { 565 void AutofillDialogControllerImpl::FocusMoved() {
514 HidePopup(); 566 HidePopup();
515 } 567 }
516 568
569 Profile* AutofillDialogControllerImpl::profile() {
570 return profile_;
571 }
572
573 content::WebContents* AutofillDialogControllerImpl::web_contents() {
574 return contents_;
575 }
576
577 void AutofillDialogControllerImpl::StartSignInFlow() {
578 DCHECK(registrar_.IsEmpty());
579
580 content::Source<content::NavigationController> source(
581 &view_->ShowSignIn());
582 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, source);
583 }
584
585 void AutofillDialogControllerImpl::EndSignInFlow() {
586 DCHECK(!registrar_.IsEmpty());
587 registrar_.RemoveAll();
588 view_->HideSignIn();
589 }
590
591 void AutofillDialogControllerImpl::ShowTermsOfService() {
592 OpenInNewTab(GURL(kTermsOfServiceUrl));
593 }
594
595 void AutofillDialogControllerImpl::ShowPrivacyPolicy() {
596 OpenInNewTab(GURL(kPrivacyPolicyUrl));
597 }
598
517 void AutofillDialogControllerImpl::ViewClosed(DialogAction action) { 599 void AutofillDialogControllerImpl::ViewClosed(DialogAction action) {
518 if (action == ACTION_SUBMIT) { 600 if (action == ACTION_SUBMIT) {
519 FillOutputForSection(SECTION_EMAIL); 601 FillOutputForSection(SECTION_EMAIL);
520 FillOutputForSection(SECTION_CC); 602 FillOutputForSection(SECTION_CC);
521 FillOutputForSection(SECTION_BILLING); 603 FillOutputForSection(SECTION_BILLING);
522 if (view_->UseBillingForShipping()) { 604 if (view_->UseBillingForShipping()) {
523 FillOutputForSectionWithComparator( 605 FillOutputForSectionWithComparator(
524 SECTION_BILLING, 606 SECTION_BILLING,
525 base::Bind(DetailInputMatchesShippingField)); 607 base::Bind(DetailInputMatchesShippingField));
526 FillOutputForSectionWithComparator( 608 FillOutputForSectionWithComparator(
527 SECTION_CC, 609 SECTION_CC,
528 base::Bind(DetailInputMatchesShippingField)); 610 base::Bind(DetailInputMatchesShippingField));
529 } else { 611 } else {
530 FillOutputForSection(SECTION_SHIPPING); 612 FillOutputForSection(SECTION_SHIPPING);
531 } 613 }
532 callback_.Run(&form_structure_); 614 callback_.Run(&form_structure_);
533 } else { 615 } else {
534 callback_.Run(NULL); 616 callback_.Run(NULL);
535 } 617 }
536 618
537 delete this; 619 delete this;
538 } 620 }
539 621
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 //////////////////////////////////////////////////////////////////////////////// 622 ////////////////////////////////////////////////////////////////////////////////
590 // AutofillPopupDelegate 623 // AutofillPopupDelegate
591 624
592 void AutofillDialogControllerImpl::OnPopupShown( 625 void AutofillDialogControllerImpl::OnPopupShown(
593 content::KeyboardListener* listener) {} 626 content::KeyboardListener* listener) {}
594 627
595 void AutofillDialogControllerImpl::OnPopupHidden( 628 void AutofillDialogControllerImpl::OnPopupHidden(
596 content::KeyboardListener* listener) {} 629 content::KeyboardListener* listener) {}
597 630
598 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { 631 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 void AutofillDialogControllerImpl::OnDidGetFullWallet( 713 void AutofillDialogControllerImpl::OnDidGetFullWallet(
681 scoped_ptr<wallet::FullWallet> full_wallet) { 714 scoped_ptr<wallet::FullWallet> full_wallet) {
682 NOTIMPLEMENTED(); 715 NOTIMPLEMENTED();
683 } 716 }
684 717
685 void AutofillDialogControllerImpl::OnDidGetWalletItems( 718 void AutofillDialogControllerImpl::OnDidGetWalletItems(
686 scoped_ptr<wallet::WalletItems> wallet_items) { 719 scoped_ptr<wallet::WalletItems> wallet_items) {
687 wallet_items_ = wallet_items.Pass(); 720 wallet_items_ = wallet_items.Pass();
688 view_->UpdateAccountChooser(); 721 view_->UpdateAccountChooser();
689 view_->UpdateNotificationArea(); 722 view_->UpdateNotificationArea();
723 view_->UpdateFootnote();
690 } 724 }
691 725
692 void AutofillDialogControllerImpl::OnDidSaveAddress( 726 void AutofillDialogControllerImpl::OnDidSaveAddress(
693 const std::string& address_id) { 727 const std::string& address_id) {
694 NOTIMPLEMENTED() << " address_id=" << address_id; 728 NOTIMPLEMENTED() << " address_id=" << address_id;
695 } 729 }
696 730
697 void AutofillDialogControllerImpl::OnDidSaveInstrument( 731 void AutofillDialogControllerImpl::OnDidSaveInstrument(
698 const std::string& instrument_id) { 732 const std::string& instrument_id) {
699 NOTIMPLEMENTED() << " instrument_id=" << instrument_id; 733 NOTIMPLEMENTED() << " instrument_id=" << instrument_id;
(...skipping 19 matching lines...) Expand all
719 wallet_items_.reset(); 753 wallet_items_.reset();
720 } 754 }
721 755
722 void AutofillDialogControllerImpl::OnNetworkError(int response_code) { 756 void AutofillDialogControllerImpl::OnNetworkError(int response_code) {
723 NOTIMPLEMENTED() << " response_code=" << response_code; 757 NOTIMPLEMENTED() << " response_code=" << response_code;
724 wallet_items_.reset(); 758 wallet_items_.reset();
725 } 759 }
726 760
727 //////////////////////////////////////////////////////////////////////////////// 761 ////////////////////////////////////////////////////////////////////////////////
728 762
763 void AutofillDialogControllerImpl::UpdateProgressBar(double value) {
764 view_->UpdateProgressBar(value);
765 }
766
729 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput( 767 bool AutofillDialogControllerImpl::HandleKeyPressEventInInput(
730 const content::NativeWebKeyboardEvent& event) { 768 const content::NativeWebKeyboardEvent& event) {
731 if (popup_controller_) 769 if (popup_controller_)
732 return popup_controller_->HandleKeyPressEvent(event); 770 return popup_controller_->HandleKeyPressEvent(event);
733 771
734 return false; 772 return false;
735 } 773 }
736 774
737 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { 775 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const {
738 DCHECK_GT(form_structure_.field_count(), 0U); 776 DCHECK_GT(form_structure_.field_count(), 0U);
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( 985 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection(
948 DialogSection section) { 986 DialogSection section) {
949 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); 987 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section));
950 } 988 }
951 989
952 void AutofillDialogControllerImpl::HidePopup() { 990 void AutofillDialogControllerImpl::HidePopup() {
953 if (popup_controller_) 991 if (popup_controller_)
954 popup_controller_->Hide(); 992 popup_controller_->Hide();
955 } 993 }
956 994
995 void AutofillDialogControllerImpl::OpenInNewTab(const GURL& url) {
996 Browser* browser = chrome::FindOrCreateTabbedBrowser(
997 profile_, chrome::GetActiveDesktop());
Evan Stade 2013/02/08 15:38:53 You want to get the browser from the web contents
Dan Beam 2013/02/08 20:53:06 Done. Btw, can this API ever be triggered by a non
Evan Stade 2013/02/11 01:05:23 Potentially. It could be used in a popup browser w
Dan Beam 2013/02/11 16:45:18 Why wouldn't we want to find or created a *tabbed*
Evan Stade 2013/02/12 01:36:54 Well, the code you currently have might add a new
998 chrome::NavigateParams params(browser, url, content::PAGE_TRANSITION_LINK);
999 params.disposition = NEW_FOREGROUND_TAB;
1000 chrome::Navigate(&params);
1001 }
1002
957 } // namespace autofill 1003 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698