Index: Source/modules/serviceworkers/ServiceWorkerClients.cpp |
diff --git a/Source/modules/serviceworkers/ServiceWorkerClients.cpp b/Source/modules/serviceworkers/ServiceWorkerClients.cpp |
index 7d9e8d4da331d370b77ffeea089b38fc25e1f6fe..d1f08f73e96d5e0f9bc4d333fc765caa0085dc97 100644 |
--- a/Source/modules/serviceworkers/ServiceWorkerClients.cpp |
+++ b/Source/modules/serviceworkers/ServiceWorkerClients.cpp |
@@ -8,6 +8,8 @@ |
#include "bindings/core/v8/CallbackPromiseAdapter.h" |
#include "bindings/core/v8/ScriptPromiseResolver.h" |
#include "core/dom/ExceptionCode.h" |
+#include "core/workers/WorkerGlobalScope.h" |
+#include "core/workers/WorkerLocation.h" |
#include "modules/serviceworkers/ServiceWorkerError.h" |
#include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
#include "modules/serviceworkers/ServiceWorkerWindowClient.h" |
@@ -89,4 +91,31 @@ ScriptPromise ServiceWorkerClients::claim(ScriptState* scriptState) |
return promise; |
} |
+ScriptPromise ServiceWorkerClients::openWindow(ScriptState* scriptState, const String& url) |
+{ |
+ RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState); |
+ ScriptPromise promise = resolver->promise(); |
+ ExecutionContext* context = scriptState->executionContext(); |
+ |
+ KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); |
+ if (!parsedUrl.isValid()) { |
+ resolver->reject(DOMException::create(SyntaxError, "'" + url + "' is not a valid URL.")); |
+ return promise; |
+ } |
+ |
+ if (!context->securityOrigin()->canRequest(parsedUrl)) { |
+ resolver->reject(DOMException::create(SecurityError, "'" + parsedUrl.elidedString() + "' is not same-origin with the Worker.")); |
+ return promise; |
+ } |
+ |
+ if (!context->isWindowInteractionAllowed()) { |
+ resolver->reject(DOMException::create(InvalidAccessError, "Not allowed to open a window.")); |
+ return promise; |
+ } |
+ context->consumeWindowInteraction(); |
+ |
+ ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedUrl, new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver)); |
+ return promise; |
+} |
+ |
} // namespace blink |