| 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,
|
| + const String& url) {
|
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state);
|
| + ScriptPromise promise = resolver->Promise();
|
| + ExecutionContext* context = ExecutionContext::From(script_state);
|
| +
|
| + KURL parsed_url_to_open =
|
| + 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) {
|
|
|