Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/PaymentRequestEvent.h" | 5 #include "modules/payments/PaymentRequestEvent.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
| 8 #include "core/dom/DOMException.h" | |
| 9 #include "core/workers/WorkerGlobalScope.h" | |
| 10 #include "core/workers/WorkerLocation.h" | |
| 7 #include "modules/serviceworkers/RespondWithObserver.h" | 11 #include "modules/serviceworkers/RespondWithObserver.h" |
| 12 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | |
| 13 #include "modules/serviceworkers/ServiceWorkerWindowClientCallback.h" | |
| 14 #include "platform/wtf/PtrUtil.h" | |
| 8 #include "platform/wtf/text/AtomicString.h" | 15 #include "platform/wtf/text/AtomicString.h" |
| 9 | 16 |
| 10 namespace blink { | 17 namespace blink { |
| 11 | 18 |
| 12 PaymentRequestEvent* PaymentRequestEvent::Create( | 19 PaymentRequestEvent* PaymentRequestEvent::Create( |
| 13 const AtomicString& type, | 20 const AtomicString& type, |
| 14 const PaymentAppRequest& app_request, | 21 const PaymentAppRequest& app_request, |
| 15 RespondWithObserver* respond_with_observer, | 22 RespondWithObserver* respond_with_observer, |
| 16 WaitUntilObserver* wait_until_observer) { | 23 WaitUntilObserver* wait_until_observer) { |
| 17 return new PaymentRequestEvent(type, app_request, respond_with_observer, | 24 return new PaymentRequestEvent(type, app_request, respond_with_observer, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 46 | 53 |
| 47 const HeapVector<PaymentDetailsModifier>& PaymentRequestEvent::modifiers() | 54 const HeapVector<PaymentDetailsModifier>& PaymentRequestEvent::modifiers() |
| 48 const { | 55 const { |
| 49 return modifiers_; | 56 return modifiers_; |
| 50 } | 57 } |
| 51 | 58 |
| 52 const String& PaymentRequestEvent::instrumentKey() const { | 59 const String& PaymentRequestEvent::instrumentKey() const { |
| 53 return instrument_key_; | 60 return instrument_key_; |
| 54 } | 61 } |
| 55 | 62 |
| 63 ScriptPromise PaymentRequestEvent::openWindow(ScriptState* script_state, | |
| 64 const String& url) { | |
| 65 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | |
| 66 ScriptPromise promise = resolver->Promise(); | |
| 67 ExecutionContext* context = ExecutionContext::From(script_state); | |
| 68 | |
| 69 // TODO(gogerad): Check payment request state so as to through | |
|
Marijn Kruisselbrink
2017/06/02 20:49:39
nit: s/through/throw/ (although you're not technic
gogerald1
2017/06/02 21:46:03
Done.
| |
| 70 // "InvalidStateError" exception appropriately (refer | |
| 71 // https://w3c.github.io/payment-handler/#dfn-open-window-algorithm). | |
| 72 | |
| 73 KURL parsed_url_to_open = context->CompleteURL(url); | |
| 74 if (!parsed_url_to_open.IsValid()) { | |
| 75 resolver->Reject(V8ThrowException::CreateTypeError( | |
| 76 script_state->GetIsolate(), "'" + url + "' is not a valid URL.")); | |
| 77 return promise; | |
| 78 } | |
| 79 | |
| 80 if (!context->GetSecurityOrigin()->CanDisplay(parsed_url_to_open)) { | |
| 81 resolver->Reject(V8ThrowException::CreateTypeError( | |
| 82 script_state->GetIsolate(), | |
| 83 "'" + parsed_url_to_open.ElidedString() + "' cannot be opened.")); | |
| 84 return promise; | |
| 85 } | |
| 86 | |
| 87 if (!context->GetSecurityOrigin()->CanAccess( | |
| 88 SecurityOrigin::Create(parsed_url_to_open).Get())) { | |
| 89 resolver->Reject(DOMException::Create( | |
| 90 kSecurityError, | |
| 91 "'" + parsed_url_to_open.ElidedString() + "' is not allowed.")); | |
| 92 return promise; | |
| 93 } | |
| 94 | |
| 95 if (!context->IsWindowInteractionAllowed()) { | |
| 96 resolver->Reject(DOMException::Create(kInvalidAccessError, | |
| 97 "Not allowed to open a window.")); | |
| 98 return promise; | |
| 99 } | |
| 100 context->ConsumeWindowInteraction(); | |
| 101 | |
| 102 ServiceWorkerGlobalScopeClient::From(context)->OpenWindowForPaymentHandler( | |
| 103 parsed_url_to_open, WTF::MakeUnique<NavigateClientCallback>(resolver)); | |
| 104 return promise; | |
| 105 } | |
| 106 | |
| 56 void PaymentRequestEvent::respondWith(ScriptState* script_state, | 107 void PaymentRequestEvent::respondWith(ScriptState* script_state, |
| 57 ScriptPromise script_promise, | 108 ScriptPromise script_promise, |
| 58 ExceptionState& exception_state) { | 109 ExceptionState& exception_state) { |
| 59 stopImmediatePropagation(); | 110 stopImmediatePropagation(); |
| 60 if (observer_) { | 111 if (observer_) { |
| 61 observer_->RespondWith(script_state, script_promise, exception_state); | 112 observer_->RespondWith(script_state, script_promise, exception_state); |
| 62 } | 113 } |
| 63 } | 114 } |
| 64 | 115 |
| 65 DEFINE_TRACE(PaymentRequestEvent) { | 116 DEFINE_TRACE(PaymentRequestEvent) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 78 top_level_origin_(app_request.topLevelOrigin()), | 129 top_level_origin_(app_request.topLevelOrigin()), |
| 79 payment_request_origin_(app_request.paymentRequestOrigin()), | 130 payment_request_origin_(app_request.paymentRequestOrigin()), |
| 80 payment_request_id_(app_request.paymentRequestId()), | 131 payment_request_id_(app_request.paymentRequestId()), |
| 81 method_data_(std::move(app_request.methodData())), | 132 method_data_(std::move(app_request.methodData())), |
| 82 total_(app_request.total()), | 133 total_(app_request.total()), |
| 83 modifiers_(app_request.modifiers()), | 134 modifiers_(app_request.modifiers()), |
| 84 instrument_key_(app_request.instrumentKey()), | 135 instrument_key_(app_request.instrumentKey()), |
| 85 observer_(respond_with_observer) {} | 136 observer_(respond_with_observer) {} |
| 86 | 137 |
| 87 } // namespace blink | 138 } // namespace blink |
| OLD | NEW |