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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentInstrument.idl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/payments/PaymentInstruments.h" 5 #include "modules/payments/PaymentInstruments.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "bindings/core/v8/ExceptionState.h" 9 #include "bindings/core/v8/ExceptionState.h"
10 #include "bindings/core/v8/ScriptPromise.h" 10 #include "bindings/core/v8/ScriptPromise.h"
(...skipping 23 matching lines...) Expand all
34 "There is no stored instrument")); 34 "There is no stored instrument"));
35 return true; 35 return true;
36 case payments::mojom::blink::PaymentHandlerStatus::NO_ACTIVE_WORKER: 36 case payments::mojom::blink::PaymentHandlerStatus::NO_ACTIVE_WORKER:
37 resolver->Reject( 37 resolver->Reject(
38 DOMException::Create(kInvalidStateError, "No active service worker")); 38 DOMException::Create(kInvalidStateError, "No active service worker"));
39 return true; 39 return true;
40 case payments::mojom::blink::PaymentHandlerStatus::STORAGE_OPERATION_FAILED: 40 case payments::mojom::blink::PaymentHandlerStatus::STORAGE_OPERATION_FAILED:
41 resolver->Reject(DOMException::Create(kInvalidStateError, 41 resolver->Reject(DOMException::Create(kInvalidStateError,
42 "Storage operation is failed")); 42 "Storage operation is failed"));
43 return true; 43 return true;
44 case payments::mojom::blink::PaymentHandlerStatus::
45 FETCH_INSTRUMENT_ICON_FAILED:
46 resolver->Reject(DOMException::Create(
47 kNotFoundError, "Fetch or decode instrument icon failed"));
48 return true;
44 } 49 }
45 NOTREACHED(); 50 NOTREACHED();
46 return false; 51 return false;
47 } 52 }
48 53
49 } // namespace 54 } // namespace
50 55
51 PaymentInstruments::PaymentInstruments( 56 PaymentInstruments::PaymentInstruments(
52 const payments::mojom::blink::PaymentManagerPtr& manager) 57 const payments::mojom::blink::PaymentManagerPtr& manager)
53 : manager_(manager) {} 58 : manager_(manager) {}
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 script_state, 137 script_state,
133 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable)); 138 DOMException::Create(kInvalidStateError, kPaymentManagerUnavailable));
134 } 139 }
135 140
136 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); 141 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
137 ScriptPromise promise = resolver->Promise(); 142 ScriptPromise promise = resolver->Promise();
138 143
139 payments::mojom::blink::PaymentInstrumentPtr instrument = 144 payments::mojom::blink::PaymentInstrumentPtr instrument =
140 payments::mojom::blink::PaymentInstrument::New(); 145 payments::mojom::blink::PaymentInstrument::New();
141 instrument->name = details.hasName() ? details.name() : WTF::g_empty_string; 146 instrument->name = details.hasName() ? details.name() : WTF::g_empty_string;
147 if (details.hasIcons()) {
148 ExecutionContext* context = ExecutionContext::From(script_state);
149 for (const ImageObject image_object : details.icons()) {
150 KURL parsed_url = context->CompleteURL(image_object.src());
151 if (!parsed_url.IsValid() || !parsed_url.ProtocolIsInHTTPFamily()) {
152 resolver->Reject(V8ThrowException::CreateTypeError(
153 script_state->GetIsolate(),
154 "'" + image_object.src() + "' is not a valid URL."));
155 return promise;
156 }
157
158 instrument->icons.push_back(payments::mojom::blink::ImageObject::New());
159 instrument->icons.back()->src = parsed_url;
160 }
161 }
162
142 if (details.hasEnabledMethods()) { 163 if (details.hasEnabledMethods()) {
143 instrument->enabled_methods = details.enabledMethods(); 164 instrument->enabled_methods = details.enabledMethods();
144 } 165 }
145 166
146 if (details.hasCapabilities()) { 167 if (details.hasCapabilities()) {
147 v8::Local<v8::String> value; 168 v8::Local<v8::String> value;
148 if (!v8::JSON::Stringify(script_state->GetContext(), 169 if (!v8::JSON::Stringify(script_state->GetContext(),
149 details.capabilities().V8Value().As<v8::Object>()) 170 details.capabilities().V8Value().As<v8::Object>())
150 .ToLocal(&value)) { 171 .ToLocal(&value)) {
151 exception_state.ThrowTypeError( 172 exception_state.ThrowTypeError(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 214
194 void PaymentInstruments::onGetPaymentInstrument( 215 void PaymentInstruments::onGetPaymentInstrument(
195 ScriptPromiseResolver* resolver, 216 ScriptPromiseResolver* resolver,
196 payments::mojom::blink::PaymentInstrumentPtr stored_instrument, 217 payments::mojom::blink::PaymentInstrumentPtr stored_instrument,
197 payments::mojom::blink::PaymentHandlerStatus status) { 218 payments::mojom::blink::PaymentHandlerStatus status) {
198 DCHECK(resolver); 219 DCHECK(resolver);
199 if (rejectError(resolver, status)) 220 if (rejectError(resolver, status))
200 return; 221 return;
201 PaymentInstrument instrument; 222 PaymentInstrument instrument;
202 instrument.setName(stored_instrument->name); 223 instrument.setName(stored_instrument->name);
224
225 HeapVector<ImageObject> icons;
226 for (const auto& icon : stored_instrument->icons) {
227 ImageObject image_object;
228 image_object.setSrc(icon->src.GetString());
229 icons.emplace_back(image_object);
230 }
231 instrument.setIcons(icons);
232
203 Vector<String> enabled_methods; 233 Vector<String> enabled_methods;
204 for (const auto& method : stored_instrument->enabled_methods) { 234 for (const auto& method : stored_instrument->enabled_methods) {
205 enabled_methods.push_back(method); 235 enabled_methods.push_back(method);
206 } 236 }
207 237
208 instrument.setEnabledMethods(enabled_methods); 238 instrument.setEnabledMethods(enabled_methods);
209 if (!stored_instrument->stringified_capabilities.IsEmpty()) { 239 if (!stored_instrument->stringified_capabilities.IsEmpty()) {
210 ScriptState::Scope scope(resolver->GetScriptState()); 240 ScriptState::Scope scope(resolver->GetScriptState());
211 ExceptionState exception_state(resolver->GetScriptState()->GetIsolate(), 241 ExceptionState exception_state(resolver->GetScriptState()->GetIsolate(),
212 ExceptionState::kGetterContext, 242 ExceptionState::kGetterContext,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 void PaymentInstruments::onClearPaymentInstruments( 284 void PaymentInstruments::onClearPaymentInstruments(
255 ScriptPromiseResolver* resolver, 285 ScriptPromiseResolver* resolver,
256 payments::mojom::blink::PaymentHandlerStatus status) { 286 payments::mojom::blink::PaymentHandlerStatus status) {
257 DCHECK(resolver); 287 DCHECK(resolver);
258 if (rejectError(resolver, status)) 288 if (rejectError(resolver, status))
259 return; 289 return;
260 resolver->Resolve(); 290 resolver->Resolve();
261 } 291 }
262 292
263 } // namespace blink 293 } // namespace blink
OLDNEW
« 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