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

Unified Diff: third_party/WebKit/Source/modules/payments/PaymentInstruments.cpp

Issue 2925063003: [Payments] Implement payment instrument icons (Closed)
Patch Set: fix comment lines 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
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentInstrument.idl ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/payments/PaymentInstruments.cpp
diff --git a/third_party/WebKit/Source/modules/payments/PaymentInstruments.cpp b/third_party/WebKit/Source/modules/payments/PaymentInstruments.cpp
index 8905048b65d160ec5c33272e3d37bad6a8496bad..2da969b6564dcf4671b54b3554536e00ca35e578 100644
--- a/third_party/WebKit/Source/modules/payments/PaymentInstruments.cpp
+++ b/third_party/WebKit/Source/modules/payments/PaymentInstruments.cpp
@@ -41,6 +41,11 @@ bool rejectError(ScriptPromiseResolver* resolver,
resolver->Reject(DOMException::Create(kInvalidStateError,
"Storage operation is failed"));
return true;
+ case payments::mojom::blink::PaymentHandlerStatus::
+ FETCH_INSTRUMENT_ICON_FAILED:
+ resolver->Reject(DOMException::Create(
+ kNotFoundError, "Fetch or decode instrument icon failed"));
+ return true;
}
NOTREACHED();
return false;
@@ -139,6 +144,22 @@ ScriptPromise PaymentInstruments::set(ScriptState* script_state,
payments::mojom::blink::PaymentInstrumentPtr instrument =
payments::mojom::blink::PaymentInstrument::New();
instrument->name = details.hasName() ? details.name() : WTF::g_empty_string;
+ if (details.hasIcons()) {
+ ExecutionContext* context = ExecutionContext::From(script_state);
+ for (const ImageObject image_object : details.icons()) {
+ KURL parsed_url = context->CompleteURL(image_object.src());
+ if (!parsed_url.IsValid() || !parsed_url.ProtocolIsInHTTPFamily()) {
+ resolver->Reject(V8ThrowException::CreateTypeError(
+ script_state->GetIsolate(),
+ "'" + image_object.src() + "' is not a valid URL."));
+ return promise;
+ }
+
+ instrument->icons.push_back(payments::mojom::blink::ImageObject::New());
+ instrument->icons.back()->src = parsed_url;
+ }
+ }
+
if (details.hasEnabledMethods()) {
instrument->enabled_methods = details.enabledMethods();
}
@@ -200,6 +221,15 @@ void PaymentInstruments::onGetPaymentInstrument(
return;
PaymentInstrument instrument;
instrument.setName(stored_instrument->name);
+
+ HeapVector<ImageObject> icons;
+ for (const auto& icon : stored_instrument->icons) {
+ ImageObject image_object;
+ image_object.setSrc(icon->src.GetString());
+ icons.emplace_back(image_object);
+ }
+ instrument.setIcons(icons);
+
Vector<String> enabled_methods;
for (const auto& method : stored_instrument->enabled_methods) {
enabled_methods.push_back(method);
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentInstrument.idl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698