Chromium Code Reviews| 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..c5408854ce5448ef62a43c57ba02ed157f7f3826 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,12 @@ 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(); |
| + 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 +87,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()); |
|
zino
2017/06/09 20:29:48
Although there is no desktop implementation yet, w
gogerald1
2017/06/09 22:25:02
yep, I added TODO on the start interface,
|
| + } |
| for (const auto& method : instrument_proto.enabled_methods()) |
| instrument->enabled_methods.push_back(method); |
| @@ -380,7 +401,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 +434,11 @@ 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); |
| + } |
| instrument_proto.set_stringified_capabilities( |
| instrument->stringified_capabilities); |