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..e3c71a33b30db4ed13afaf07b064f7a36e47dae6 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,47 @@ const String& PaymentRequestEvent::instrumentKey() const { |
| return instrument_key_; |
| } |
| +ScriptPromise PaymentRequestEvent::openWindow(ScriptState* script_state, |
|
Marijn Kruisselbrink
2017/06/02 18:19:02
The logic in this method doesn't seem to match wha
gogerald1
2017/06/02 19:33:59
Add a TODO for checking payment request state.
Ca
Marijn Kruisselbrink
2017/06/02 20:49:38
CanAccess is not exactly the same as checking for
gogerald1
2017/06/02 21:46:03
CanDisplay
From the comments "For example, web sit
Marijn Kruisselbrink
2017/06/02 22:18:05
Well, it depends... Clients.openWindow doesn't hav
gogerald1
2017/06/05 13:49:46
Done.
gogerald1
2017/06/05 13:49:46
Filed two bugs against the spec and added two todo
Marijn Kruisselbrink
2017/06/05 21:23:03
Yes, if the desired behavior is that during a paym
|
| + const String& url) { |
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| + ScriptPromise promise = resolver->Promise(); |
| + ExecutionContext* context = ExecutionContext::From(script_state); |
| + |
| + KURL parsed_url_to_open = |
|
Marijn Kruisselbrink
2017/06/02 18:19:02
Isn't this just context->CompleteURL(url) ?
gogerald1
2017/06/02 19:34:00
The url could be relative url
gogerald1
2017/06/02 20:09:05
Done.
|
| + KURL(ToWorkerGlobalScope(context)->location()->Url(), 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) { |