Chromium Code Reviews| Index: third_party/WebKit/Source/modules/payments/PaymentRequestEvent.cpp |
| diff --git a/third_party/WebKit/Source/modules/payments/PaymentRequestEvent.cpp b/third_party/WebKit/Source/modules/payments/PaymentRequestEvent.cpp |
| index 748de28bfa536339d42abb6323929f6bd6341052..22750823f79c7ff9ed9366514ddbeac0ae85dcb3 100644 |
| --- a/third_party/WebKit/Source/modules/payments/PaymentRequestEvent.cpp |
| +++ b/third_party/WebKit/Source/modules/payments/PaymentRequestEvent.cpp |
| @@ -4,7 +4,14 @@ |
| #include "modules/payments/PaymentRequestEvent.h" |
| +#include "bindings/core/v8/ScriptPromiseResolver.h" |
| +#include "core/dom/DOMException.h" |
| +#include "core/workers/WorkerGlobalScope.h" |
| +#include "core/workers/WorkerLocation.h" |
| #include "modules/serviceworkers/RespondWithObserver.h" |
| +#include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| +#include "modules/serviceworkers/ServiceWorkerWindowClientCallback.h" |
| +#include "platform/wtf/PtrUtil.h" |
| #include "platform/wtf/text/AtomicString.h" |
| namespace blink { |
| @@ -53,6 +60,50 @@ const String& PaymentRequestEvent::instrumentKey() const { |
| return instrument_key_; |
| } |
| +ScriptPromise PaymentRequestEvent::openWindow(ScriptState* script_state, |
| + const String& url) { |
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| + ScriptPromise promise = resolver->Promise(); |
| + ExecutionContext* context = ExecutionContext::From(script_state); |
| + |
| + // 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.
|
| + // "InvalidStateError" exception appropriately (refer |
| + // https://w3c.github.io/payment-handler/#dfn-open-window-algorithm). |
| + |
| + KURL parsed_url_to_open = context->CompleteURL(url); |
| + if (!parsed_url_to_open.IsValid()) { |
| + resolver->Reject(V8ThrowException::CreateTypeError( |
| + script_state->GetIsolate(), "'" + url + "' is not a valid URL.")); |
| + return promise; |
| + } |
| + |
| + if (!context->GetSecurityOrigin()->CanDisplay(parsed_url_to_open)) { |
| + resolver->Reject(V8ThrowException::CreateTypeError( |
| + script_state->GetIsolate(), |
| + "'" + parsed_url_to_open.ElidedString() + "' cannot be opened.")); |
| + return promise; |
| + } |
| + |
| + if (!context->GetSecurityOrigin()->CanAccess( |
| + SecurityOrigin::Create(parsed_url_to_open).Get())) { |
| + resolver->Reject(DOMException::Create( |
| + kSecurityError, |
| + "'" + parsed_url_to_open.ElidedString() + "' is not allowed.")); |
| + return promise; |
| + } |
| + |
| + if (!context->IsWindowInteractionAllowed()) { |
| + resolver->Reject(DOMException::Create(kInvalidAccessError, |
| + "Not allowed to open a window.")); |
| + return promise; |
| + } |
| + context->ConsumeWindowInteraction(); |
| + |
| + ServiceWorkerGlobalScopeClient::From(context)->OpenWindowForPaymentHandler( |
| + parsed_url_to_open, WTF::MakeUnique<NavigateClientCallback>(resolver)); |
| + return promise; |
| +} |
| + |
| void PaymentRequestEvent::respondWith(ScriptState* script_state, |
| ScriptPromise script_promise, |
| ExceptionState& exception_state) { |