Index: content/browser/payments/payment_app_database.cc |
diff --git a/content/browser/payments/payment_app_database.cc b/content/browser/payments/payment_app_database.cc |
index 5c58b9b6e1f1f51970b90e4895b2c6ec4bd27bd5..7d7e6dd8b5023fb7bc17a5d322abce9039268bbf 100644 |
--- a/content/browser/payments/payment_app_database.cc |
+++ b/content/browser/payments/payment_app_database.cc |
@@ -7,6 +7,7 @@ |
#include <map> |
#include <utility> |
+#include "base/base64.h" |
#include "base/bind.h" |
#include "base/memory/ptr_util.h" |
#include "base/optional.h" |
@@ -16,6 +17,8 @@ |
#include "content/browser/service_worker/service_worker_context_wrapper.h" |
#include "content/browser/service_worker/service_worker_registration.h" |
#include "content/public/browser/browser_thread.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
+#include "ui/gfx/image/image.h" |
namespace content { |
namespace { |
@@ -58,6 +61,14 @@ PaymentInstrumentPtr ToPaymentInstrumentForMojo(const std::string& input) { |
PaymentInstrumentPtr instrument = PaymentInstrument::New(); |
instrument->name = instrument_proto.name(); |
+ for (const auto& icon : instrument_proto.icons()) { |
+ payments::mojom::ImageObjectPtr image_object = |
+ payments::mojom::ImageObject::New(); |
+ image_object->src = icon.src(); |
+ image_object->sizes = icon.sizes(); |
+ image_object->type = icon.type(); |
+ instrument->icons.emplace_back(std::move(image_object)); |
+ } |
for (const auto& method : instrument_proto.enabled_methods()) |
instrument->enabled_methods.push_back(method); |
instrument->stringified_capabilities = |
@@ -78,6 +89,18 @@ std::unique_ptr<StoredPaymentInstrument> ToStoredPaymentInstrument( |
instrument->instrument_key = instrument_proto.instrument_key(); |
instrument->origin = GURL(instrument_proto.origin()); |
instrument->name = instrument_proto.name(); |
+ |
+ if (!instrument_proto.decoded_instrument_icon().empty()) { |
+ std::string icon_raw_data; |
+ base::Base64Decode(instrument_proto.decoded_instrument_icon(), |
+ &icon_raw_data); |
+ // Note that the icon has been decoded to PNG raw data regardless of the |
+ // original icon format that was downloaded. |
+ gfx::Image icon_image = gfx::Image::CreateFrom1xPNGBytes( |
+ reinterpret_cast<const unsigned char*>(icon_raw_data.data()), |
+ icon_raw_data.size()); |
+ instrument->icon = base::MakeUnique<SkBitmap>(icon_image.AsBitmap()); |
+ } |
for (const auto& method : instrument_proto.enabled_methods()) |
instrument->enabled_methods.push_back(method); |
@@ -380,7 +403,32 @@ void PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument( |
return; |
} |
+ instrument_icon_fetcher_ = base::MakeUnique<PaymentInstrumentIconFetcher>(); |
+ instrument_icon_fetcher_->start( |
+ registration->pattern(), instrument->icons, service_worker_context_, |
+ base::Bind(&PaymentAppDatabase::DidFetchedPaymentInstrumentIcon, |
+ weak_ptr_factory_.GetWeakPtr(), instrument_key, |
+ base::Passed(std::move(instrument)), |
+ base::Passed(std::move(callback)), |
+ base::Passed(std::move(registration)))); |
+} |
+ |
+void PaymentAppDatabase::DidFetchedPaymentInstrumentIcon( |
+ const std::string& instrument_key, |
+ payments::mojom::PaymentInstrumentPtr instrument, |
+ WritePaymentInstrumentCallback callback, |
+ scoped_refptr<ServiceWorkerRegistration> registration, |
+ const std::string& icon) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
+ |
+ instrument_icon_fetcher_.reset(nullptr); |
+ if (icon.empty()) { |
+ std::move(callback).Run(PaymentHandlerStatus::FETCH_INSTRUMENT_ICON_FAILED); |
+ return; |
+ } |
+ |
StoredPaymentInstrumentProto instrument_proto; |
+ instrument_proto.set_decoded_instrument_icon(icon); |
instrument_proto.set_registration_id(registration->id()); |
instrument_proto.set_instrument_key(instrument_key); |
instrument_proto.set_origin(registration->pattern().GetOrigin().spec()); |
@@ -388,6 +436,13 @@ void PaymentAppDatabase::DidFindRegistrationToWritePaymentInstrument( |
for (const auto& method : instrument->enabled_methods) { |
instrument_proto.add_enabled_methods(method); |
} |
+ for (const auto& image_object : instrument->icons) { |
+ StoredPaymentInstrumentImageObject* image_object_proto = |
+ instrument_proto.add_icons(); |
+ image_object_proto->set_src(image_object->src); |
+ image_object_proto->set_sizes(image_object->sizes); |
+ image_object_proto->set_type(image_object->type); |
+ } |
instrument_proto.set_stringified_capabilities( |
instrument->stringified_capabilities); |