| 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..6627c49adbdc248234b31b1e7ee6fb2e5e319ab4 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,
|
| + const String& url) {
|
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
|
| + ScriptPromise promise = resolver->Promise();
|
| + ExecutionContext* context = ExecutionContext::From(script_state);
|
| +
|
| + // TODO(gogerald): Check payment request state so as to reject promise with
|
| + // "InvalidStateError" 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;
|
| + }
|
| +
|
| + // TODO(gogerald): Once the issue of the spec is resolved, we should apply the
|
| + // changes. Refer https://github.com/w3c/payment-handler/issues/168.
|
| + if (!context->GetSecurityOrigin()->IsSameSchemeHostPortAndSuborigin(
|
| + SecurityOrigin::Create(parsed_url_to_open).Get())) {
|
| + resolver->Reject(DOMException::Create(
|
| + kSecurityError,
|
| + "'" + parsed_url_to_open.ElidedString() + "' is not allowed."));
|
| + return promise;
|
| + }
|
| +
|
| + // TODO(gogerald): Once the issue of the spec is resolved, we should apply the
|
| + // changes. Refer https://github.com/w3c/payment-handler/issues/169.
|
| + 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) {
|
|
|