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

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

Issue 2020913002: PaymentRequest: Rename ShippingAddress to PaymentAddress. (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"
11 #include "bindings/modules/v8/V8PaymentDetails.h" 11 #include "bindings/modules/v8/V8PaymentDetails.h"
12 #include "core/EventTypeNames.h" 12 #include "core/EventTypeNames.h"
13 #include "core/dom/DOMException.h" 13 #include "core/dom/DOMException.h"
14 #include "core/dom/ExceptionCode.h" 14 #include "core/dom/ExceptionCode.h"
15 #include "core/events/Event.h" 15 #include "core/events/Event.h"
16 #include "core/events/EventQueue.h" 16 #include "core/events/EventQueue.h"
17 #include "modules/EventTargetModulesNames.h" 17 #include "modules/EventTargetModulesNames.h"
18 #include "modules/payments/PaymentAddress.h"
18 #include "modules/payments/PaymentItem.h" 19 #include "modules/payments/PaymentItem.h"
19 #include "modules/payments/PaymentRequestUpdateEvent.h" 20 #include "modules/payments/PaymentRequestUpdateEvent.h"
20 #include "modules/payments/PaymentResponse.h" 21 #include "modules/payments/PaymentResponse.h"
21 #include "modules/payments/PaymentsValidators.h" 22 #include "modules/payments/PaymentsValidators.h"
22 #include "modules/payments/ShippingAddress.h"
23 #include "modules/payments/ShippingOption.h" 23 #include "modules/payments/ShippingOption.h"
24 #include "mojo/public/cpp/bindings/interface_request.h" 24 #include "mojo/public/cpp/bindings/interface_request.h"
25 #include "mojo/public/cpp/bindings/wtf_array.h" 25 #include "mojo/public/cpp/bindings/wtf_array.h"
26 #include "platform/mojo/MojoHelper.h" 26 #include "platform/mojo/MojoHelper.h"
27 #include "public/platform/ServiceRegistry.h" 27 #include "public/platform/ServiceRegistry.h"
28 #include <utility> 28 #include <utility>
29 29
30 namespace mojo { 30 namespace mojo {
31 31
32 using blink::mojom::blink::CurrencyAmount; 32 using blink::mojom::blink::CurrencyAmount;
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 void PaymentRequest::contextDestroyed() 355 void PaymentRequest::contextDestroyed()
356 { 356 {
357 clearResolversAndCloseMojoConnection(); 357 clearResolversAndCloseMojoConnection();
358 } 358 }
359 359
360 bool PaymentRequest::hasPendingActivity() const 360 bool PaymentRequest::hasPendingActivity() const
361 { 361 {
362 return m_showResolver || m_completeResolver; 362 return m_showResolver || m_completeResolver;
363 } 363 }
364 364
365 void PaymentRequest::OnShippingAddressChange(mojom::blink::ShippingAddressPtr ad dress) 365 void PaymentRequest::OnShippingAddressChange(mojom::blink::PaymentAddressPtr add ress)
366 { 366 {
367 DCHECK(m_showResolver); 367 DCHECK(m_showResolver);
368 DCHECK(!m_completeResolver); 368 DCHECK(!m_completeResolver);
369 369
370 String errorMessage; 370 String errorMessage;
371 if (!PaymentsValidators::isValidShippingAddress(address, &errorMessage)) { 371 if (!PaymentsValidators::isValidShippingAddress(address, &errorMessage)) {
372 m_showResolver->reject(DOMException::create(SyntaxError, errorMessage)); 372 m_showResolver->reject(DOMException::create(SyntaxError, errorMessage));
373 clearResolversAndCloseMojoConnection(); 373 clearResolversAndCloseMojoConnection();
374 return; 374 return;
375 } 375 }
376 376
377 m_shippingAddress = new ShippingAddress(std::move(address)); 377 m_shippingAddress = new PaymentAddress(std::move(address));
378 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange); 378 PaymentRequestUpdateEvent* event = PaymentRequestUpdateEvent::create(EventTy peNames::shippingaddresschange);
379 event->setTarget(this); 379 event->setTarget(this);
380 event->setPaymentDetailsUpdater(this); 380 event->setPaymentDetailsUpdater(this);
381 bool success = getExecutionContext()->getEventQueue()->enqueueEvent(event); 381 bool success = getExecutionContext()->getEventQueue()->enqueueEvent(event);
382 DCHECK(success); 382 DCHECK(success);
383 ALLOW_UNUSED_LOCAL(success); 383 ALLOW_UNUSED_LOCAL(success);
384 } 384 }
385 385
386 void PaymentRequest::OnShippingOptionChange(const String& shippingOptionId) 386 void PaymentRequest::OnShippingOptionChange(const String& shippingOptionId)
387 { 387 {
(...skipping 14 matching lines...) Expand all
402 DCHECK(!m_completeResolver); 402 DCHECK(!m_completeResolver);
403 403
404 if (response->shipping_address) { 404 if (response->shipping_address) {
405 String errorMessage; 405 String errorMessage;
406 if (!PaymentsValidators::isValidShippingAddress(response->shipping_addre ss, &errorMessage)) { 406 if (!PaymentsValidators::isValidShippingAddress(response->shipping_addre ss, &errorMessage)) {
407 m_showResolver->reject(DOMException::create(SyntaxError, errorMessag e)); 407 m_showResolver->reject(DOMException::create(SyntaxError, errorMessag e));
408 clearResolversAndCloseMojoConnection(); 408 clearResolversAndCloseMojoConnection();
409 return; 409 return;
410 } 410 }
411 411
412 m_shippingAddress = new ShippingAddress(std::move(response->shipping_add ress)); 412 m_shippingAddress = new PaymentAddress(std::move(response->shipping_addr ess));
413 m_shippingOption = response->shipping_option_id; 413 m_shippingOption = response->shipping_option_id;
414 } 414 }
415 415
416 m_showResolver->resolve(new PaymentResponse(std::move(response), this)); 416 m_showResolver->resolve(new PaymentResponse(std::move(response), this));
417 417
418 // Do not close the mojo connection here. The merchant website should call 418 // Do not close the mojo connection here. The merchant website should call
419 // PaymentResponse::complete(boolean), which will be forwarded over the mojo 419 // PaymentResponse::complete(boolean), which will be forwarded over the mojo
420 // connection to display a success or failure message to the user. 420 // connection to display a success or failure message to the user.
421 m_showResolver.clear(); 421 m_showResolver.clear();
422 } 422 }
(...skipping 17 matching lines...) Expand all
440 void PaymentRequest::clearResolversAndCloseMojoConnection() 440 void PaymentRequest::clearResolversAndCloseMojoConnection()
441 { 441 {
442 m_completeResolver.clear(); 442 m_completeResolver.clear();
443 m_showResolver.clear(); 443 m_showResolver.clear();
444 if (m_clientBinding.is_bound()) 444 if (m_clientBinding.is_bound())
445 m_clientBinding.Close(); 445 m_clientBinding.Close();
446 m_paymentProvider.reset(); 446 m_paymentProvider.reset();
447 } 447 }
448 448
449 } // namespace blink 449 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698