Skip to content

Commit

Permalink
[ConsentV2] Add the consent dialog view
Browse files Browse the repository at this point in the history
This CL implements the complete consent dialog view.

Mock: https://screenshot.googleplex.com/BWL9oYXggrXJfci
Screenshot: https://screenshot.googleplex.com/7GAshxrJbNA8dfN

(cherry picked from commit ed06c8f)

Bug: 1318685
Change-Id: Iaa0c9368a1f5010b524e87b4690025d75456c2c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3603024
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Mei Liang <meiliang@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1005546}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3680288
Reviewed-by: Prudhvikumar Bommana <pbommana@google.com>
Owners-Override: Prudhvikumar Bommana <pbommana@google.com>
Commit-Queue: Prudhvikumar Bommana <pbommana@google.com>
Cr-Commit-Position: refs/branch-heads/5060@{#430}
Cr-Branched-From: b83393d-refs/heads/main@{#1002911}
  • Loading branch information
Mei Liang authored and Chromium LUCI CQ committed May 31, 2022
1 parent b5ebee0 commit fd8a954
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 2 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4205,6 +4205,8 @@ static_library("ui") {
"views/collected_cookies_views.h",
"views/commander_frontend_views.cc",
"views/commander_frontend_views.h",
"views/commerce/ntp_discount_consent_dialog_view.cc",
"views/commerce/ntp_discount_consent_dialog_view.h",
"views/confirm_bubble_views.cc",
"views/confirm_bubble_views.h",
"views/constrained_web_dialog_delegate_views.cc",
Expand Down
104 changes: 104 additions & 0 deletions chrome/browser/ui/views/commerce/ntp_discount_consent_dialog_view.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/commerce/ntp_discount_consent_dialog_view.h"

#include "base/callback_helpers.h"
#include "chrome/browser/cart/chrome_cart.mojom.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "components/constrained_window/constrained_window_views.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"

#include "chrome/browser/ui/views/accessibility/theme_tracking_non_accessible_image_view.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/grit/theme_resources.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"

namespace {
// Spacing between child of the Discount Consent Dialog View
constexpr int kChildSpacing = 24;
} // namespace

// static
void NtpDiscountConsentDialogView::Show(Browser* browser,
ActionCallback callback) {
constrained_window::CreateBrowserModalDialogViews(
std::make_unique<NtpDiscountConsentDialogView>(std::move(callback)),
browser->window()->GetNativeWindow())
->Show();
}

NtpDiscountConsentDialogView::NtpDiscountConsentDialogView(
ActionCallback callback)
: callback_(std::move(callback)) {
// Set up dialog properties.
SetModalType(ui::MODAL_TYPE_WINDOW);
SetShowCloseButton(false);
SetOwnedByWidget(true);
// TODO(meiliang@): Set text for the button.
SetButtons(ui::DIALOG_BUTTON_CANCEL | ui::DIALOG_BUTTON_OK);
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric(
DISTANCE_LARGE_MODAL_DIALOG_PREFERRED_WIDTH));

SetAcceptCallback(base::BindOnce(&NtpDiscountConsentDialogView::OnAccept,
base::Unretained(this)));
SetCancelCallback(base::BindOnce(&NtpDiscountConsentDialogView::OnReject,
base::Unretained(this)));
SetCloseCallback(base::BindOnce(&NtpDiscountConsentDialogView::OnDismiss,
base::Unretained(this)));

// Set up dialog content view.
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
ChromeLayoutProvider::Get()->GetInsetsMetric(views::INSETS_DIALOG),
kChildSpacing));

ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();

AddChildView(std::make_unique<ThemeTrackingNonAccessibleImageView>(
*bundle.GetImageSkiaNamed(IDR_NTP_CART_DISCOUNT_CONSENT_LIGHT),
*bundle.GetImageSkiaNamed(IDR_NTP_CART_DISCOUNT_CONSENT_DARK),
base::BindRepeating(&NtpDiscountConsentDialogView::GetBackgroundColor,
base::Unretained(this))));

auto title_label = std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_NATIVE_NTP_CART_DISCOUNT_CONSENT_TITLE),
CONTEXT_HEADLINE, views::style::STYLE_PRIMARY);
auto* title = AddChildView(std::move(title_label));
title->SetMultiLine(true);

auto consent_label = std::make_unique<views::Label>(
l10n_util::GetStringUTF16(IDS_NATIVE_NTP_CART_DISCOUNT_CONSENT_BODY),
views::style::CONTEXT_DIALOG_BODY_TEXT, views::style::STYLE_SECONDARY);
auto* consent = AddChildView(std::move(consent_label));
consent->SetMultiLine(true);
}

NtpDiscountConsentDialogView::~NtpDiscountConsentDialogView() = default;

SkColor NtpDiscountConsentDialogView::GetBackgroundColor() {
return GetWidget()->GetColorProvider()->GetColor(ui::kColorDialogBackground);
}

void NtpDiscountConsentDialogView::OnAccept() {
assert(callback_);
std::move(callback_).Run(chrome_cart::mojom::ConsentStatus::ACCEPTED);
}

void NtpDiscountConsentDialogView::OnReject() {
assert(callback_);
std::move(callback_).Run(chrome_cart::mojom::ConsentStatus::REJECTED);
}

void NtpDiscountConsentDialogView::OnDismiss() {
assert(callback_);
std::move(callback_).Run(chrome_cart::mojom::ConsentStatus::DISMISSED);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_VIEWS_COMMERCE_NTP_DISCOUNT_CONSENT_DIALOG_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_COMMERCE_NTP_DISCOUNT_CONSENT_DIALOG_VIEW_H_

#include "base/callback_helpers.h"
#include "chrome/browser/cart/chrome_cart.mojom.h"
#include "ui/views/window/dialog_delegate.h"

class Browser;

class NtpDiscountConsentDialogView : public views::DialogDelegateView {
public:
using ActionCallback =
base::OnceCallback<void(chrome_cart::mojom::ConsentStatus)>;
static void Show(Browser* browser, ActionCallback callback);
explicit NtpDiscountConsentDialogView(ActionCallback callback);
~NtpDiscountConsentDialogView() override;

private:
ActionCallback callback_;

SkColor GetBackgroundColor();
// Called when the accept button is clicked.
void OnAccept();
// Called when the reject button is clicked.
void OnReject();
// Called when the Esc key is used.
void OnDismiss();
};

#endif // CHROME_BROWSER_UI_VIEWS_COMMERCE_NTP_DISCOUNT_CONSENT_DIALOG_VIEW_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/commerce/ntp_discount_consent_dialog_view.h"

#include "chrome/browser/ui/test/test_browser_dialog.h"
#include "content/public/test/browser_test.h"

// Test harness for integration tests using NtpDiscountConsentView.
class NtpDiscountConsentDialogViewBrowserTest : public DialogBrowserTest {
public:
NtpDiscountConsentDialogViewBrowserTest() = default;

NtpDiscountConsentDialogViewBrowserTest(
const NtpDiscountConsentDialogViewBrowserTest&) = delete;
NtpDiscountConsentDialogViewBrowserTest& operator=(
const NtpDiscountConsentDialogViewBrowserTest&) = delete;

// DialogBrowserTest:
void ShowUi(const std::string& name) override {
NtpDiscountConsentDialogView::Show(
browser(),
base::BindOnce([](chrome_cart::mojom::ConsentStatus status) {}));
}
};

// Shows the dialog for bookmarking all tabs. This shows a BookmarkEditorView
// dialog, with a tree view, where a user can rename and select a parent folder.
IN_PROC_BROWSER_TEST_F(NtpDiscountConsentDialogViewBrowserTest,
InvokeUi_default) {
ShowAndVerifyUi();
}
1 change: 1 addition & 0 deletions chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3183,6 +3183,7 @@ if (!is_android) {
"../browser/ui/views/bubble/webui_bubble_manager_browsertest.cc",
"../browser/ui/views/certificate_selector_dialog_browsertest.cc",
"../browser/ui/views/collected_cookies_views_browsertest.cc",
"../browser/ui/views/commerce/ntp_discount_consent_dialog_view_browsertest.cc",
"../browser/ui/views/desktop_capture/desktop_media_picker_views_browsertest.cc",
"../browser/ui/views/extensions/extension_install_blocked_dialog_view_browsertest.cc",
"../browser/ui/views/extensions/extension_install_dialog_view_browsertest.cc",
Expand Down
8 changes: 6 additions & 2 deletions components/commerce_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
<message name="IDS_DISCOUNT_CONTEXTUAL_CONSENT_ACCEPTED_CONFIRMATION_DONE" desc="The text shown on the consent confirmation bubble bubble. User can click this button to close the bubble.">
Done
</message>
<message name="IDS_NATIVE_NTP_CART_DISCOUNT_CONSENT_TITLE" translateable="false" desc="The title shown on the native consent dialog for getting discount. Note: This is intentionally left blank. No translation is required."></message>
<message name="IDS_NATIVE_NTP_CART_DISCOUNT_CONSENT_BODY" translateable="false" desc="The actual consent descrition that shows in the native consent dialog. Note: This is intentionally left blank. No translation is required."></message>
<message name="IDS_NATIVE_NTP_CART_DISCOUNT_CONSENT_TITLE" translateable="false" desc="The title shown on the native consent dialog for getting discount. Note: This is intentionally left blank. No translation is required.">
Get discounts on your carts&#13; &amp; when you shop online
</message>
<message name="IDS_NATIVE_NTP_CART_DISCOUNT_CONSENT_BODY" translateable="false" desc="The actual consent descrition that shows in the native consent dialog. Note: This is intentionally left blank. No translation is required.">
Let Google find personalized discounts on your carts and on online stores you visit. When available, discounts will automatically show up on your carts and on sites.
</message>
</if>
</grit-part>

0 comments on commit fd8a954

Please sign in to comment.