Commit f29cfde5 authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

[Payments] Decode icon for secure-payment-confirmation instrument

Bug: 1121021
Change-Id: If656f90953fcc45f53741974dc44fda5314e465c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2376455
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#802439}
parent 1df4d968
......@@ -9,10 +9,13 @@
#include <vector>
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/memory/ref_counted.h"
#include "base/path_service.h"
#include "base/strings/strcat.h"
#include "base/strings/string16.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_data_service_factory.h"
......@@ -46,6 +49,22 @@ std::string getInvokePaymentRequestSnippet() {
return base::StringPrintf("getStatusForMethodData(%s)", kTestMethodData);
}
std::vector<uint8_t> GetEncodedIcon(const std::string& icon_file_name) {
base::FilePath base_path;
CHECK(base::PathService::Get(base::DIR_SOURCE_ROOT, &base_path));
std::string icon_as_string;
base::FilePath icon_file_path =
base_path.AppendASCII("components/test/data/payments")
.AppendASCII(icon_file_name);
{
base::ScopedAllowBlockingForTesting allow_blocking;
CHECK(base::PathExists(icon_file_path));
CHECK(base::ReadFileToString(icon_file_path, &icon_as_string));
}
return std::vector<uint8_t>(icon_as_string.begin(), icon_as_string.end());
}
#if !defined(OS_ANDROID)
std::string getPaymentCreationOptions(const std::string& icon_url) {
return base::StrCat(
......@@ -138,7 +157,7 @@ IN_PROC_BROWSER_TEST_F(SecurePaymentConfirmationTest,
test_controller()->SetHasAuthenticator(true);
NavigateTo("a.com", "/payment_handler_status.html");
std::vector<uint8_t> credential_id = {'c', 'r', 'e', 'd'};
std::vector<uint8_t> icon = {0, 1, 2, 3};
std::vector<uint8_t> icon = GetEncodedIcon("icon.png");
WebDataServiceFactory::GetPaymentManifestWebDataForProfile(
Profile::FromBrowserContext(GetActiveWebContents()->GetBrowserContext()),
ServiceAccessType::EXPLICIT_ACCESS)
......
......@@ -64,6 +64,7 @@ static_library("content") {
"//components/webdata/common",
"//content/public/browser",
"//device/fido",
"//services/data_decoder/public/cpp",
"//third_party/blink/public:blink_headers",
"//url",
]
......
......@@ -23,6 +23,7 @@
#include "components/payments/core/secure_payment_confirmation_instrument.h"
#include "components/webdata/common/web_data_results.h"
#include "components/webdata/common/web_data_service_base.h"
#include "services/data_decoder/public/cpp/decode_image.h"
#include "third_party/blink/public/mojom/payments/payment_request.mojom.h"
#include "url/origin.h"
......@@ -187,10 +188,23 @@ void SecurePaymentConfirmationAppFactory::OnWebDataServiceRequestDone(
std::unique_ptr<SecurePaymentConfirmationInstrument> instrument =
std::move(instruments.front());
// TODO(https://crbug.com/1110324): Decode `instrument->icon` from
// std::unique_ptr<std::vector<uint8_t>> into std::unique_ptr<SkBitmap> and
// check the icon validity.
auto icon = std::make_unique<SkBitmap>();
auto* instrument_ptr = instrument.get();
// Decode the icon in a sandboxed process off the main thread.
data_decoder::DecodeImageIsolated(
instrument_ptr->icon, data_decoder::mojom::ImageCodec::DEFAULT,
/*shrink_to_fit=*/false, data_decoder::kDefaultMaxSizeInBytes,
/*desired_image_frame_size=*/gfx::Size(),
base::BindOnce(&SecurePaymentConfirmationAppFactory::OnAppIconDecoded,
weak_ptr_factory_.GetWeakPtr(), std::move(instrument),
std::move(request)));
}
void SecurePaymentConfirmationAppFactory::OnAppIconDecoded(
std::unique_ptr<SecurePaymentConfirmationInstrument> instrument,
std::unique_ptr<Request> request,
const SkBitmap& decoded_icon) {
DCHECK(!decoded_icon.drawsNothing());
auto icon = std::make_unique<SkBitmap>(decoded_icon);
request->delegate->OnPaymentAppCreated(
std::make_unique<SecurePaymentConfirmationApp>(
......
......@@ -14,6 +14,8 @@
namespace payments {
struct SecurePaymentConfirmationInstrument;
class SecurePaymentConfirmationAppFactory : public PaymentAppFactory,
public WebDataServiceConsumer {
public:
......@@ -42,6 +44,11 @@ class SecurePaymentConfirmationAppFactory : public PaymentAppFactory,
std::unique_ptr<autofill::InternalAuthenticator> authenticator,
bool is_available);
void OnAppIconDecoded(
std::unique_ptr<SecurePaymentConfirmationInstrument> instrument,
std::unique_ptr<Request> request,
const SkBitmap& decoded_image);
std::map<WebDataServiceBase::Handle, std::unique_ptr<Request>> requests_;
base::WeakPtrFactory<SecurePaymentConfirmationAppFactory> weak_ptr_factory_{
this};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment