Index: Source/modules/serviceworkers/ServiceWorkerWindowClient.cpp |
diff --git a/Source/modules/serviceworkers/ServiceWorkerWindowClient.cpp b/Source/modules/serviceworkers/ServiceWorkerWindowClient.cpp |
index 6d463687cb700551454d8d8df8ebebc0cf40e520..c206772d2fa0596d194d11b3f4081d0d74b7364a 100644 |
--- a/Source/modules/serviceworkers/ServiceWorkerWindowClient.cpp |
+++ b/Source/modules/serviceworkers/ServiceWorkerWindowClient.cpp |
@@ -10,6 +10,8 @@ |
#include "core/dom/DOMException.h" |
#include "core/dom/ExceptionCode.h" |
#include "core/page/PageVisibilityState.h" |
+#include "core/workers/WorkerGlobalScope.h" |
+#include "core/workers/WorkerLocation.h" |
#include "modules/serviceworkers/ServiceWorkerError.h" |
#include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
#include "public/platform/WebString.h" |
@@ -58,6 +60,26 @@ ScriptPromise ServiceWorkerWindowClient::focus(ScriptState* scriptState) |
return promise; |
} |
+ScriptPromise ServiceWorkerWindowClient::navigate(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() || parsedUrl.protocolIsAbout()) { |
+ resolver->reject(V8ThrowException::createTypeError(scriptState->isolate(), "'" + url + "' is not a valid URL.")); |
+ return promise; |
+ } |
+ if (!context->securityOrigin()->canDisplay(parsedUrl)) { |
+ resolver->reject(DOMException::create(SecurityError, "'" + parsedUrl.elidedString() + "' cannot navigate.")); |
+ return promise; |
+ } |
+ |
+ ServiceWorkerGlobalScopeClient::from(context)->navigate(uuid(), parsedUrl, new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver)); |
+ return promise; |
+} |
+ |
DEFINE_TRACE(ServiceWorkerWindowClient) |
{ |
ServiceWorkerClient::trace(visitor); |