-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SPC No matching credential UI, Desktop Implementation
Desktop version of SPC no matching credential UI needed for user privacy. Uses the shopping cart header image instead of the fingerprint icon. Bug: 1233636 Change-Id: I8b4d728fc6d84d8772c7a4f813edb4115c874f48 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3069244 Commit-Queue: Jenny Lei <jennylei@google.com> Reviewed-by: Liquan (Max) Gu <maxlg@chromium.org> Reviewed-by: Rouslan Solomakhin <rouslan@chromium.org> Cr-Commit-Position: refs/heads/master@{#908960}
- Loading branch information
1 parent
6fe5634
commit 23ac3ba
Showing
12 changed files
with
430 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
chrome/browser/ui/views/payments/secure_payment_confirmation_no_creds_dialog_view.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Copyright 2021 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/payments/secure_payment_confirmation_no_creds_dialog_view.h" | ||
|
||
#include "chrome/browser/ui/views/payments/secure_payment_confirmation_views_util.h" | ||
#include "components/constrained_window/constrained_window_views.h" | ||
#include "components/payments/content/payment_ui_observer.h" | ||
#include "ui/base/metadata/metadata_impl_macros.h" | ||
#include "ui/views/border.h" | ||
#include "ui/views/controls/label.h" | ||
#include "ui/views/layout/box_layout.h" | ||
#include "ui/views/layout/grid_layout.h" | ||
#include "ui/views/layout/layout_provider.h" | ||
|
||
namespace payments { | ||
|
||
// static | ||
base::WeakPtr<SecurePaymentConfirmationNoCredsView> | ||
SecurePaymentConfirmationNoCredsView::Create() { | ||
// On desktop, the SecurePaymentConfirmationNoCredsView object is memory | ||
// managed by the views:: machinery. It is deleted when the window is closed | ||
// and views::DialogDelegateView::DeleteDelegate() is called by its | ||
// corresponding views::Widget. | ||
return (new SecurePaymentConfirmationNoCredsDialogView( | ||
/*observer_for_test=*/nullptr)) | ||
->GetWeakPtr(); | ||
} | ||
|
||
SecurePaymentConfirmationNoCredsDialogView:: | ||
SecurePaymentConfirmationNoCredsDialogView( | ||
ObserverForTest* observer_for_test) | ||
: observer_for_test_(observer_for_test) {} | ||
SecurePaymentConfirmationNoCredsDialogView:: | ||
~SecurePaymentConfirmationNoCredsDialogView() = default; | ||
|
||
void SecurePaymentConfirmationNoCredsDialogView::ShowDialog( | ||
content::WebContents* web_contents, | ||
const std::u16string& no_creds_text, | ||
ResponseCallback response_callback) { | ||
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric( | ||
views::DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH)); | ||
|
||
SetButtons(ui::DIALOG_BUTTON_OK); | ||
SetDefaultButton(ui::DIALOG_BUTTON_OK); | ||
|
||
InitChildViews(no_creds_text); | ||
|
||
SetAccessibleTitle(no_creds_text); | ||
|
||
response_callback_ = std::move(response_callback); | ||
|
||
SetAcceptCallback(base::BindOnce( | ||
&SecurePaymentConfirmationNoCredsDialogView::OnDialogClosed, | ||
weak_ptr_factory_.GetWeakPtr())); | ||
|
||
SetModalType(ui::MODAL_TYPE_CHILD); | ||
|
||
constrained_window::ShowWebModalDialogViews(this, web_contents); | ||
|
||
// observer_for_test_ is used in views browsertests. | ||
if (observer_for_test_) | ||
observer_for_test_->OnDialogOpened(); | ||
} | ||
|
||
void SecurePaymentConfirmationNoCredsDialogView::HideDialog() { | ||
if (GetWidget()) | ||
GetWidget()->Close(); | ||
} | ||
|
||
bool SecurePaymentConfirmationNoCredsDialogView::ShouldShowCloseButton() const { | ||
return false; | ||
} | ||
|
||
base::WeakPtr<SecurePaymentConfirmationNoCredsDialogView> | ||
SecurePaymentConfirmationNoCredsDialogView::GetWeakPtr() { | ||
return weak_ptr_factory_.GetWeakPtr(); | ||
} | ||
|
||
void SecurePaymentConfirmationNoCredsDialogView::OnDialogClosed() { | ||
std::move(response_callback_).Run(); | ||
HideDialog(); | ||
|
||
if (observer_for_test_) | ||
observer_for_test_->OnDialogClosed(); | ||
} | ||
|
||
void SecurePaymentConfirmationNoCredsDialogView::InitChildViews( | ||
const std::u16string& no_creds_text) { | ||
RemoveAllChildViews(true); | ||
|
||
SetLayoutManager(std::make_unique<views::BoxLayout>( | ||
views::BoxLayout::Orientation::kVertical, gfx::Insets(), 0)); | ||
|
||
AddChildView(CreateSecurePaymentConfirmationHeaderView( | ||
static_cast<int>(DialogViewID::PROGRESS_BAR), | ||
static_cast<int>(DialogViewID::HEADER_IMAGE), /*use_cart_image=*/true)); | ||
|
||
AddChildView(CreateBodyView(no_creds_text)); | ||
|
||
InvalidateLayout(); | ||
} | ||
|
||
// Creates the body. | ||
// +------------------------------------------+ | ||
// | [header image] | | ||
// | | | ||
// | No matching credentials text | | ||
// | [OK] | | ||
// +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ | ||
std::unique_ptr<views::View> | ||
SecurePaymentConfirmationNoCredsDialogView::CreateBodyView( | ||
const std::u16string& no_creds_text) { | ||
std::unique_ptr<views::Label> no_matching_creds_view = | ||
std::make_unique<views::Label>(no_creds_text, | ||
views::style::CONTEXT_DIALOG_BODY_TEXT, | ||
views::style::STYLE_PRIMARY); | ||
no_matching_creds_view->SetMultiLine(true); | ||
no_matching_creds_view->SetLineHeight(kDescriptionLineHeight); | ||
no_matching_creds_view->SetHorizontalAlignment(gfx::ALIGN_TO_HEAD); | ||
no_matching_creds_view->SetAllowCharacterBreak(true); | ||
no_matching_creds_view->SetID( | ||
static_cast<int>(DialogViewID::NO_MATCHING_CREDS_TEXT)); | ||
no_matching_creds_view->SetBorder( | ||
views::CreateEmptyBorder(gfx::Insets(kBodyExtraInset))); | ||
|
||
return no_matching_creds_view; | ||
} | ||
|
||
BEGIN_METADATA(SecurePaymentConfirmationNoCredsDialogView, | ||
views::DialogDelegateView) | ||
END_METADATA | ||
|
||
} // namespace payments |
75 changes: 75 additions & 0 deletions
75
chrome/browser/ui/views/payments/secure_payment_confirmation_no_creds_dialog_view.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2021 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_PAYMENTS_SECURE_PAYMENT_CONFIRMATION_NO_CREDS_DIALOG_VIEW_H_ | ||
#define CHROME_BROWSER_UI_VIEWS_PAYMENTS_SECURE_PAYMENT_CONFIRMATION_NO_CREDS_DIALOG_VIEW_H_ | ||
|
||
#include "base/memory/weak_ptr.h" | ||
#include "components/payments/content/secure_payment_confirmation_no_creds_view.h" | ||
#include "ui/views/window/dialog_delegate.h" | ||
|
||
namespace payments { | ||
|
||
// Draws the user interface in the secure payment confirmation no matching | ||
// credentials flow. | ||
class SecurePaymentConfirmationNoCredsDialogView | ||
: public SecurePaymentConfirmationNoCredsView, | ||
public views::DialogDelegateView { | ||
public: | ||
METADATA_HEADER(SecurePaymentConfirmationNoCredsDialogView); | ||
|
||
class ObserverForTest { | ||
public: | ||
virtual void OnDialogOpened() = 0; | ||
virtual void OnDialogClosed() = 0; | ||
}; | ||
|
||
// IDs that identify a view within the secure payment confirmation no creds | ||
// dialog. Used to validate views in browsertests. | ||
enum class DialogViewID : int { | ||
VIEW_ID_NONE = 0, | ||
HEADER_IMAGE, | ||
PROGRESS_BAR, | ||
NO_MATCHING_CREDS_TEXT | ||
}; | ||
|
||
explicit SecurePaymentConfirmationNoCredsDialogView( | ||
ObserverForTest* observer_for_test); | ||
~SecurePaymentConfirmationNoCredsDialogView() override; | ||
|
||
SecurePaymentConfirmationNoCredsDialogView( | ||
const SecurePaymentConfirmationNoCredsDialogView& other) = delete; | ||
SecurePaymentConfirmationNoCredsDialogView& operator=( | ||
const SecurePaymentConfirmationNoCredsDialogView& other) = delete; | ||
|
||
// SecurePaymentConfirmationNoCredsView: | ||
void ShowDialog(content::WebContents* web_contents, | ||
const std::u16string& no_creds_text, | ||
ResponseCallback response_callback) override; | ||
void HideDialog() override; | ||
|
||
// views::DialogDelegate: | ||
bool ShouldShowCloseButton() const override; | ||
|
||
base::WeakPtr<SecurePaymentConfirmationNoCredsDialogView> GetWeakPtr(); | ||
|
||
private: | ||
void OnDialogClosed(); | ||
|
||
void InitChildViews(const std::u16string& no_creds_text); | ||
std::unique_ptr<views::View> CreateBodyView( | ||
const std::u16string& no_creds_text); | ||
|
||
// May be null. | ||
ObserverForTest* observer_for_test_ = nullptr; | ||
|
||
ResponseCallback response_callback_; | ||
|
||
base::WeakPtrFactory<SecurePaymentConfirmationNoCredsDialogView> | ||
weak_ptr_factory_{this}; | ||
}; | ||
|
||
} // namespace payments | ||
|
||
#endif // CHROME_BROWSER_UI_VIEWS_PAYMENTS_SECURE_PAYMENT_CONFIRMATION_NO_CREDS_DIALOG_VIEW_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.