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

Side by Side Diff: chrome/browser/ui/views/payments/payment_sheet_view_controller.cc

Issue 2876663002: [Web Payments] Add data attribution string to dialog (Closed)
Patch Set: Address comments, fix tests compile Created 3 years, 7 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/views/payments/payment_sheet_view_controller.h" 5 #include "chrome/browser/ui/views/payments/payment_sheet_view_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/i18n/message_formatter.h" 13 #include "base/i18n/message_formatter.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/chrome_pages.h"
20 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" 23 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
21 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" 24 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
22 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" 25 #include "chrome/browser/ui/views/payments/payment_request_row_view.h"
23 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" 26 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
24 #include "chrome/grit/generated_resources.h" 27 #include "chrome/grit/generated_resources.h"
25 #include "components/autofill/core/browser/field_types.h" 28 #include "components/autofill/core/browser/field_types.h"
26 #include "components/autofill/core/browser/personal_data_manager.h" 29 #include "components/autofill/core/browser/personal_data_manager.h"
27 #include "components/payments/content/payment_request_spec.h" 30 #include "components/payments/content/payment_request_spec.h"
28 #include "components/payments/content/payment_request_state.h" 31 #include "components/payments/content/payment_request_state.h"
29 #include "components/payments/core/currency_formatter.h" 32 #include "components/payments/core/currency_formatter.h"
30 #include "components/payments/core/payment_instrument.h" 33 #include "components/payments/core/payment_instrument.h"
34 #include "components/payments/core/payment_prefs.h"
31 #include "components/payments/core/strings_util.h" 35 #include "components/payments/core/strings_util.h"
36 #include "components/prefs/pref_service.h"
32 #include "components/strings/grit/components_strings.h" 37 #include "components/strings/grit/components_strings.h"
33 #include "content/public/browser/web_contents.h" 38 #include "content/public/browser/web_contents.h"
34 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/resource/resource_bundle.h" 40 #include "ui/base/resource/resource_bundle.h"
36 #include "ui/gfx/color_utils.h" 41 #include "ui/gfx/color_utils.h"
37 #include "ui/gfx/font.h" 42 #include "ui/gfx/font.h"
38 #include "ui/gfx/paint_vector_icon.h" 43 #include "ui/gfx/paint_vector_icon.h"
39 #include "ui/gfx/range/range.h" 44 #include "ui/gfx/range/range.h"
40 #include "ui/gfx/text_elider.h" 45 #include "ui/gfx/text_elider.h"
41 #include "ui/gfx/text_utils.h" 46 #include "ui/gfx/text_utils.h"
47 #include "ui/views/border.h"
42 #include "ui/views/controls/button/md_text_button.h" 48 #include "ui/views/controls/button/md_text_button.h"
43 #include "ui/views/controls/image_view.h" 49 #include "ui/views/controls/image_view.h"
44 #include "ui/views/controls/label.h" 50 #include "ui/views/controls/label.h"
45 #include "ui/views/controls/styled_label.h" 51 #include "ui/views/controls/styled_label.h"
46 #include "ui/views/layout/box_layout.h" 52 #include "ui/views/layout/box_layout.h"
47 #include "ui/views/layout/fill_layout.h" 53 #include "ui/views/layout/fill_layout.h"
48 #include "ui/views/layout/grid_layout.h" 54 #include "ui/views/layout/grid_layout.h"
49 #include "ui/views/vector_icons.h" 55 #include "ui/views/vector_icons.h"
50 #include "ui/views/view.h" 56 #include "ui/views/view.h"
51 57
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 layout->AddView(shipping_row.release()); 459 layout->AddView(shipping_row.release());
454 } 460 }
455 } 461 }
456 layout->StartRow(0, 0); 462 layout->StartRow(0, 0);
457 layout->AddView(CreatePaymentMethodRow().release()); 463 layout->AddView(CreatePaymentMethodRow().release());
458 if (spec()->request_payer_name() || spec()->request_payer_email() || 464 if (spec()->request_payer_name() || spec()->request_payer_email() ||
459 spec()->request_payer_phone()) { 465 spec()->request_payer_phone()) {
460 layout->StartRow(0, 0); 466 layout->StartRow(0, 0);
461 layout->AddView(CreateContactInfoRow().release()); 467 layout->AddView(CreateContactInfoRow().release());
462 } 468 }
469 layout->StartRow(0, 0);
470 layout->AddView(CreateDataSourceRow().release());
463 } 471 }
464 472
465 // Adds the product logo to the footer. 473 // Adds the product logo to the footer.
466 // +---------------------------------------------------------+ 474 // +---------------------------------------------------------+
467 // | (•) chrome | PAY | CANCEL | 475 // | (•) chrome | PAY | CANCEL |
468 // +---------------------------------------------------------+ 476 // +---------------------------------------------------------+
469 std::unique_ptr<views::View> 477 std::unique_ptr<views::View>
470 PaymentSheetViewController::CreateExtraFooterView() { 478 PaymentSheetViewController::CreateExtraFooterView() {
471 return CreateProductLogoFooterView(); 479 return CreateProductLogoFooterView();
472 } 480 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON): 533 PaymentSheetViewControllerTags::SHOW_SHIPPING_OPTION_BUTTON):
526 dialog()->ShowShippingOptionSheet(); 534 dialog()->ShowShippingOptionSheet();
527 break; 535 break;
528 536
529 default: 537 default:
530 PaymentRequestSheetController::ButtonPressed(sender, event); 538 PaymentRequestSheetController::ButtonPressed(sender, event);
531 break; 539 break;
532 } 540 }
533 } 541 }
534 542
543 void PaymentSheetViewController::StyledLabelLinkClicked(
544 views::StyledLabel* label,
545 const gfx::Range& range,
546 int event_flags) {
547 // The only thing that can trigger this is the user clicking on the "settings"
548 // link in the data attribution text.
549 chrome::ShowSettingsSubPageForProfile(dialog()->GetProfile(), "");
550 }
551
535 void PaymentSheetViewController::UpdatePayButtonState(bool enabled) { 552 void PaymentSheetViewController::UpdatePayButtonState(bool enabled) {
536 pay_button_->SetEnabled(enabled); 553 pay_button_->SetEnabled(enabled);
537 } 554 }
538 555
539 // Creates the Order Summary row, which contains an "Order Summary" label, 556 // Creates the Order Summary row, which contains an "Order Summary" label,
540 // an inline list of display items, a Total Amount label, and a Chevron. 557 // an inline list of display items, a Total Amount label, and a Chevron.
541 // +----------------------------------------------+ 558 // +----------------------------------------------+
542 // | Order Summary Item 1 $ 1.34 | 559 // | Order Summary Item 1 $ 1.34 |
543 // | Item 2 $ 2.00 > | 560 // | Item 2 $ 2.00 > |
544 // | 2 more items... | 561 // | 2 more items... |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 } 907 }
891 } else { 908 } else {
892 return builder 909 return builder
893 .Id(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION_BUTTON) 910 .Id(DialogViewID::PAYMENT_SHEET_SHIPPING_OPTION_SECTION_BUTTON)
894 .CreateWithButton( 911 .CreateWithButton(
895 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CHOOSE_AN_ADDRESS), 912 l10n_util::GetStringUTF16(IDS_PAYMENT_REQUEST_CHOOSE_AN_ADDRESS),
896 l10n_util::GetStringUTF16(IDS_CHOOSE), /*button_enabled=*/false); 913 l10n_util::GetStringUTF16(IDS_CHOOSE), /*button_enabled=*/false);
897 } 914 }
898 } 915 }
899 916
917 std::unique_ptr<views::View> PaymentSheetViewController::CreateDataSourceRow() {
918 std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>();
919 views::BoxLayout* layout = new views::BoxLayout(
920 views::BoxLayout::kVertical, kPaymentRequestRowHorizontalInsets, 0, 0);
921 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
922 layout->set_cross_axis_alignment(
923 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
924 content_view->SetLayoutManager(layout);
925
926 base::string16 data_source;
927 // If no transaction has been completed so far, choose which string to display
928 // as a function of the profile's signed in state. Otherwise, always show the
929 // same string.
930 bool first_transaction_completed =
931 dialog()->GetProfile()->GetPrefs()->GetBoolean(
932 payments::kPaymentsFirstTransactionCompleted);
933 if (first_transaction_completed) {
934 data_source =
935 l10n_util::GetStringUTF16(IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS);
936 } else {
937 std::string user_email = state()->GetAuthenticatedEmail();
938 if (!user_email.empty()) {
939 // Insert the user's email into the format string.
940 data_source = base::UTF8ToUTF16(base::StringPrintf(
941 l10n_util::GetStringUTF8(
942 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_IN)
943 .c_str(),
944 user_email.c_str()));
945 } else {
946 data_source = l10n_util::GetStringUTF16(
947 IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_OUT);
948 }
949 }
950
951 // The translated string will surround the actual "Settings" substring with
952 // BEGIN_LINK and END_LINK. Find the beginning of the link range and the
953 // length of the "settings" part, then remove the BEGIN_LINK and END_LINK
954 // parts and linkify "settings".
955 base::string16 begin_tag = base::UTF8ToUTF16("BEGIN_LINK");
956 base::string16 end_tag = base::UTF8ToUTF16("END_LINK");
957 size_t link_begin = data_source.find(begin_tag);
958 DCHECK(link_begin != base::string16::npos);
959
960 size_t link_end = data_source.find(end_tag);
961 DCHECK(link_end != base::string16::npos);
962
963 size_t link_length = link_end - link_begin - begin_tag.size();
964 data_source.erase(link_end, end_tag.size());
965 data_source.erase(link_begin, begin_tag.size());
966
967 std::unique_ptr<views::StyledLabel> data_source_label =
968 base::MakeUnique<views::StyledLabel>(data_source, this);
969 data_source_label->SetBorder(views::CreateEmptyBorder(22, 0, 0, 0));
970
971 views::StyledLabel::RangeStyleInfo default_style;
972 default_style.color = data_source_label->GetNativeTheme()->GetSystemColor(
973 ui::NativeTheme::kColorId_LabelDisabledColor);
974 data_source_label->SetDefaultStyle(default_style);
975 data_source_label->AddStyleRange(
976 gfx::Range(link_begin, link_begin + link_length),
977 views::StyledLabel::RangeStyleInfo::CreateForLink());
978 data_source_label->SizeToFit(0);
979 content_view->AddChildView(data_source_label.release());
980 return content_view;
981 }
982
900 } // namespace payments 983 } // namespace payments
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/payments/payment_sheet_view_controller.h ('k') | components/payments/content/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698