1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/payments/content/secure_payment_confirmation_no_creds.h"
#include <memory>
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "components/payments/content/secure_payment_confirmation_no_creds_view.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_contents.h"
#include "ui/base/l10n/l10n_util.h"
namespace payments {
// static
std::unique_ptr<SecurePaymentConfirmationNoCreds>
SecurePaymentConfirmationNoCreds::Create() {
return std::make_unique<SecurePaymentConfirmationNoCreds>();
}
SecurePaymentConfirmationNoCreds::SecurePaymentConfirmationNoCreds() = default;
SecurePaymentConfirmationNoCreds::~SecurePaymentConfirmationNoCreds() {
CloseDialog();
}
void SecurePaymentConfirmationNoCreds::ShowDialog(
content::WebContents* web_contents,
const std::u16string& merchant_name,
const std::string& rp_id,
ResponseCallback response_callback,
OptOutCallback opt_out_callback) {
#if BUILDFLAG(IS_ANDROID)
NOTREACHED();
#else
DCHECK(!view_);
model_.set_no_creds_text(l10n_util::GetStringFUTF16(
IDS_NO_MATCHING_CREDENTIAL_DESCRIPTION, merchant_name));
model_.set_opt_out_visible(!opt_out_callback.is_null());
model_.set_opt_out_label(
l10n_util::GetStringUTF16(IDS_SECURE_PAYMENT_CONFIRMATION_OPT_OUT_LABEL));
model_.set_opt_out_link_label(l10n_util::GetStringUTF16(
IDS_SECURE_PAYMENT_CONFIRMATION_OPT_OUT_LINK_LABEL));
model_.set_relying_party_id(base::UTF8ToUTF16(rp_id));
view_ = SecurePaymentConfirmationNoCredsView::Create();
view_->ShowDialog(web_contents, model_.GetWeakPtr(),
std::move(response_callback), std::move(opt_out_callback));
#endif // BUILDFLAG(IS_ANDROID)
}
void SecurePaymentConfirmationNoCreds::CloseDialog() {
if (!view_)
return;
view_->HideDialog();
}
bool SecurePaymentConfirmationNoCreds::ClickOptOutForTesting() {
if (!view_)
return false;
return view_->ClickOptOutForTesting();
}
} // namespace payments
|