Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Unified Diff: content/browser/payments/payment_app_database.cc

Issue 2925063003: [Payments] Implement payment instrument icons (Closed)
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..87bcf7a3759232dc4842c0cc1e3a3921a2171abc 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,16 @@ 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);
+ gfx::Image icon_image = gfx::Image::CreateFrom1xPNGBytes(
please use gerrit instead 2017/06/08 21:34:10 Add a note that you've converted the image to PNG
gogerald1 2017/06/09 14:23:24 Done.
+ 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 +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,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);

Powered by Google App Engine
This is Rietveld 408576698