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

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentRequest.cpp

Issue 2045833002: Add 'selected' boolean to 'ShippingOption' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/PaymentRequest.h" 5 #include "modules/payments/PaymentRequest.h"
6 6
7 #include "bindings/core/v8/ExceptionState.h" 7 #include "bindings/core/v8/ExceptionState.h"
8 #include "bindings/core/v8/JSONValuesForV8.h" 8 #include "bindings/core/v8/JSONValuesForV8.h"
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/ScriptState.h" 10 #include "bindings/core/v8/ScriptState.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 }; 63 };
64 64
65 template <> 65 template <>
66 struct TypeConverter<ShippingOptionPtr, blink::ShippingOption> { 66 struct TypeConverter<ShippingOptionPtr, blink::ShippingOption> {
67 static ShippingOptionPtr Convert(const blink::ShippingOption& input) 67 static ShippingOptionPtr Convert(const blink::ShippingOption& input)
68 { 68 {
69 ShippingOptionPtr output = ShippingOption::New(); 69 ShippingOptionPtr output = ShippingOption::New();
70 output->id = input.id(); 70 output->id = input.id();
71 output->label = input.label(); 71 output->label = input.label();
72 output->amount = CurrencyAmount::From(input.amount()); 72 output->amount = CurrencyAmount::From(input.amount());
73 output->selected = input.hasSelected() && input.selected();
73 return output; 74 return output;
74 } 75 }
75 }; 76 };
76 77
77 template <> 78 template <>
78 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> { 79 struct TypeConverter<PaymentDetailsPtr, blink::PaymentDetails> {
79 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input) 80 static PaymentDetailsPtr Convert(const blink::PaymentDetails& input)
80 { 81 {
81 PaymentDetailsPtr output = PaymentDetails::New(); 82 PaymentDetailsPtr output = PaymentDetails::New();
82 output->total = PaymentItem::From(input.total()); 83 output->total = PaymentItem::From(input.total());
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 validateDisplayItems(details.displayItems(), exceptionState); 191 validateDisplayItems(details.displayItems(), exceptionState);
191 if (exceptionState.hadException()) 192 if (exceptionState.hadException())
192 return; 193 return;
193 } 194 }
194 195
195 if (details.hasShippingOptions()) { 196 if (details.hasShippingOptions()) {
196 validateShippingOptions(details.shippingOptions(), exceptionState); 197 validateShippingOptions(details.shippingOptions(), exceptionState);
197 } 198 }
198 } 199 }
199 200
201 String getSelectedShippingOption(const PaymentDetails& details)
202 {
203 String result;
204 if (!details.hasShippingOptions())
205 return result;
206
207 for (size_t i = 0; i < details.shippingOptions().size(); ++i) {
208 if (details.shippingOptions()[i].hasSelected() && details.shippingOption s()[i].selected()) {
209 result = details.shippingOptions()[i].id();
210 }
211 }
212
213 return result;
214 }
215
200 } // namespace 216 } // namespace
201 217
202 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<St ring>& supportedMethods, const PaymentDetails& details, ExceptionState& exceptio nState) 218 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<St ring>& supportedMethods, const PaymentDetails& details, ExceptionState& exceptio nState)
203 { 219 {
204 return new PaymentRequest(scriptState, supportedMethods, details, PaymentOpt ions(), ScriptValue(), exceptionState); 220 return new PaymentRequest(scriptState, supportedMethods, details, PaymentOpt ions(), ScriptValue(), exceptionState);
205 } 221 }
206 222
207 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<St ring>& supportedMethods, const PaymentDetails& details, const PaymentOptions& op tions, ExceptionState& exceptionState) 223 PaymentRequest* PaymentRequest::create(ScriptState* scriptState, const Vector<St ring>& supportedMethods, const PaymentDetails& details, const PaymentOptions& op tions, ExceptionState& exceptionState)
208 { 224 {
209 return new PaymentRequest(scriptState, supportedMethods, details, options, S criptValue(), exceptionState); 225 return new PaymentRequest(scriptState, supportedMethods, details, options, S criptValue(), exceptionState);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 return; 298 return;
283 } 299 }
284 300
285 validatePaymentDetails(details, exceptionState); 301 validatePaymentDetails(details, exceptionState);
286 if (exceptionState.hadException()) { 302 if (exceptionState.hadException()) {
287 m_showResolver->reject(DOMException::create(SyntaxError, exceptionState. message())); 303 m_showResolver->reject(DOMException::create(SyntaxError, exceptionState. message()));
288 clearResolversAndCloseMojoConnection(); 304 clearResolversAndCloseMojoConnection();
289 return; 305 return;
290 } 306 }
291 307
292 // Set the currently selected option if only one option was passed. 308 if (m_options.requestShipping())
Marijn Kruisselbrink 2016/06/07 00:31:37 According to the spec having exactly one option sh
please use gerrit instead 2016/06/07 00:52:22 I am told the spec is going to change in this dire
293 if (details.hasShippingOptions() && details.shippingOptions().size() == 1) 309 m_shippingOption = getSelectedShippingOption(details);
294 m_shippingOption = details.shippingOptions().begin()->id();
295 else
296 m_shippingOption = String();
297 310
298 m_paymentProvider->UpdateWith(mojom::blink::PaymentDetails::From(details)); 311 m_paymentProvider->UpdateWith(mojom::blink::PaymentDetails::From(details));
299 } 312 }
300 313
301 void PaymentRequest::onUpdatePaymentDetailsFailure(const ScriptValue& error) 314 void PaymentRequest::onUpdatePaymentDetailsFailure(const ScriptValue& error)
302 { 315 {
303 if (m_showResolver) 316 if (m_showResolver)
304 m_showResolver->reject(error); 317 m_showResolver->reject(error);
305 if (m_completeResolver) 318 if (m_completeResolver)
306 m_completeResolver->reject(error); 319 m_completeResolver->reject(error);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 if (paymentMethodSpecificKeyValue.value->getType() != JSONValue: :TypeObject) { 379 if (paymentMethodSpecificKeyValue.value->getType() != JSONValue: :TypeObject) {
367 exceptionState.throwTypeError("Data for '" + paymentMethodSp ecificKeyValue.key + "' should be a JSON-serializable object"); 380 exceptionState.throwTypeError("Data for '" + paymentMethodSp ecificKeyValue.key + "' should be a JSON-serializable object");
368 return; 381 return;
369 } 382 }
370 } 383 }
371 384
372 m_stringifiedData = jsonData->toJSONString(); 385 m_stringifiedData = jsonData->toJSONString();
373 } 386 }
374 } 387 }
375 388
376 // Set the currently selected option if only one option is passed and shippi ng is requested. 389 if (m_options.requestShipping())
377 if (options.requestShipping() && details.hasShippingOptions() && details.shi ppingOptions().size() == 1) 390 m_shippingOption = getSelectedShippingOption(details);
378 m_shippingOption = details.shippingOptions().begin()->id();
379 } 391 }
380 392
381 void PaymentRequest::contextDestroyed() 393 void PaymentRequest::contextDestroyed()
382 { 394 {
383 clearResolversAndCloseMojoConnection(); 395 clearResolversAndCloseMojoConnection();
384 } 396 }
385 397
386 bool PaymentRequest::hasPendingActivity() const 398 bool PaymentRequest::hasPendingActivity() const
387 { 399 {
388 return m_showResolver || m_completeResolver; 400 return m_showResolver || m_completeResolver;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 void PaymentRequest::clearResolversAndCloseMojoConnection() 478 void PaymentRequest::clearResolversAndCloseMojoConnection()
467 { 479 {
468 m_completeResolver.clear(); 480 m_completeResolver.clear();
469 m_showResolver.clear(); 481 m_showResolver.clear();
470 if (m_clientBinding.is_bound()) 482 if (m_clientBinding.is_bound())
471 m_clientBinding.Close(); 483 m_clientBinding.Close();
472 m_paymentProvider.reset(); 484 m_paymentProvider.reset();
473 } 485 }
474 486
475 } // namespace blink 487 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698