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

Unified Diff: chrome/browser/ui/views/payments/payment_sheet_view_controller.cc

Issue 2876663002: [Web Payments] Add data attribution string to dialog (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
diff --git a/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc b/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
index 71fca35bd7c84ff9e99b1a906520b11b138fbbb9..a40b30e7729cbf0241f7c759c24fa35768c45228 100644
--- a/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
+++ b/chrome/browser/ui/views/payments/payment_sheet_view_controller.cc
@@ -15,8 +15,11 @@
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
#include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
#include "chrome/browser/ui/views/payments/payment_request_row_view.h"
@@ -24,11 +27,13 @@
#include "chrome/grit/generated_resources.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/personal_data_manager.h"
+#include "components/payments/content/payment_prefs.h"
#include "components/payments/content/payment_request_spec.h"
#include "components/payments/content/payment_request_state.h"
#include "components/payments/core/currency_formatter.h"
#include "components/payments/core/payment_instrument.h"
#include "components/payments/core/strings_util.h"
+#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
@@ -39,6 +44,7 @@
#include "ui/gfx/range/range.h"
#include "ui/gfx/text_elider.h"
#include "ui/gfx/text_utils.h"
+#include "ui/views/border.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
@@ -460,6 +466,8 @@ void PaymentSheetViewController::FillContentView(views::View* content_view) {
layout->StartRow(0, 0);
layout->AddView(CreateContactInfoRow().release());
}
+ layout->StartRow(0, 0);
+ layout->AddView(CreateDataSourceRow().release());
}
// Adds the product logo to the footer.
@@ -532,6 +540,16 @@ void PaymentSheetViewController::ButtonPressed(
}
}
+void PaymentSheetViewController::StyledLabelLinkClicked(
+ views::StyledLabel* label,
+ const gfx::Range& range,
+ int event_flags) {
+ // The only thing that can trigger this is the user clicking on the "settings"
+ // link in the data attribution text.
+ chrome::ShowSettingsSubPageForProfile(
+ Profile::FromBrowserContext(state()->GetBrowserContext()), "");
Mathieu 2017/05/11 00:28:04 could we expose BrowserContext from the PaymentReq
anthonyvd 2017/05/11 00:56:46 Good point, somehow I missed the fact that the dia
+}
+
void PaymentSheetViewController::UpdatePayButtonState(bool enabled) {
pay_button_->SetEnabled(enabled);
}
@@ -897,4 +915,65 @@ PaymentSheetViewController::CreateShippingOptionRow() {
}
}
+std::unique_ptr<views::View> PaymentSheetViewController::CreateDataSourceRow() {
+ std::unique_ptr<views::View> content_view = base::MakeUnique<views::View>();
+ views::BoxLayout* layout = new views::BoxLayout(
+ views::BoxLayout::kVertical, kPaymentRequestRowHorizontalInsets, 0, 0);
+ layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
+ layout->set_cross_axis_alignment(
+ views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
+ content_view->SetLayoutManager(layout);
+
+ base::string16 data_source;
+ bool first_transaction_completed =
+ Profile::FromBrowserContext(state()->GetBrowserContext())
+ ->GetPrefs()
+ ->GetBoolean(payments::kPaymentsFirstTransactionCompleted);
+ if (first_transaction_completed) {
Mathieu 2017/05/11 00:28:04 would benefit from a top-level comment to explain
anthonyvd 2017/05/11 00:56:46 Done.
+ data_source =
+ l10n_util::GetStringUTF16(IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS);
+ } else {
+ std::string user_email = state()->GetAuthenticatedEmail();
+ if (!user_email.empty()) {
+ // Insert the user's email into the format string.
+ data_source = base::UTF8ToUTF16(base::StringPrintf(
+ l10n_util::GetStringUTF8(
+ IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_IN)
+ .c_str(),
+ user_email.c_str()));
+ // Settings link.
Mathieu 2017/05/11 00:28:04 remove
anthonyvd 2017/05/11 00:56:46 Done.
+ } else {
+ data_source = l10n_util::GetStringUTF16(
+ IDS_PAYMENTS_CARD_AND_ADDRESS_SETTINGS_SIGNED_OUT);
+ }
+ }
+
+ base::string16 begin_tag = base::UTF8ToUTF16("BEGIN_LINK");
Mathieu 2017/05/11 00:28:04 // Activate the "Settings" link in the data source
anthonyvd 2017/05/11 00:56:46 Done.
+ base::string16 end_tag = base::UTF8ToUTF16("END_LINK");
+ size_t link_begin = data_source.find(begin_tag);
+ DCHECK(link_begin != base::string16::npos);
+
+ size_t link_end = data_source.find(end_tag);
+ DCHECK(link_end != base::string16::npos);
+
+ size_t link_length = link_end - link_begin - begin_tag.size();
+ data_source.erase(link_end, end_tag.size());
+ data_source.erase(link_begin, begin_tag.size());
+
+ std::unique_ptr<views::StyledLabel> data_source_label =
+ base::MakeUnique<views::StyledLabel>(data_source, this);
+ data_source_label->SetBorder(views::CreateEmptyBorder(22, 0, 0, 0));
+
+ views::StyledLabel::RangeStyleInfo default_style;
+ default_style.color = data_source_label->GetNativeTheme()->GetSystemColor(
+ ui::NativeTheme::kColorId_LabelDisabledColor);
+ data_source_label->SetDefaultStyle(default_style);
+ data_source_label->AddStyleRange(
+ gfx::Range(link_begin, link_begin + link_length),
+ views::StyledLabel::RangeStyleInfo::CreateForLink());
+ data_source_label->SizeToFit(0);
+ content_view->AddChildView(data_source_label.release());
+ return content_view;
+}
+
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698