| Index: Source/modules/serviceworkers/ServiceWorkerClients.cpp
|
| diff --git a/Source/modules/serviceworkers/ServiceWorkerClients.cpp b/Source/modules/serviceworkers/ServiceWorkerClients.cpp
|
| index 6e5ed30b07f19a82d15b58b073abde469a56bf41..7c3fb4b860565c600238368723426b08a9eb685e 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"
|
| @@ -43,6 +45,35 @@ namespace {
|
|
|
| } // namespace
|
|
|
| +class ServiceWorkerClients::OpenWindowCallbacks : public WebServiceWorkerOpenWindowCallbacks {
|
| + WTF_MAKE_NONCOPYABLE(OpenWindowCallbacks);
|
| +public:
|
| + explicit OpenWindowCallbacks(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver)
|
| + : m_resolver(resolver) { }
|
| + virtual ~OpenWindowCallbacks() { }
|
| +
|
| + void onSuccess(int clientId, const WebURL& url) override
|
| + {
|
| + WebServiceWorkerClientInfo info;
|
| + // FIXME: Payload should include state snapshot of visibility, focused
|
| + info.clientID = clientId;
|
| + info.frameType = WebURLRequest::FrameTypeTopLevel;
|
| + info.url = url;
|
| + m_resolver->resolve(ServiceWorkerClient::create(info));
|
| + m_resolver.clear();
|
| + }
|
| +
|
| + void onError() override
|
| + {
|
| + // FIXME: Route back a useful error message of some sort.
|
| + m_resolver->reject(DOMException::create(SecurityError, "Failed to open the requested URL."));
|
| + m_resolver.clear();
|
| + }
|
| +
|
| +private:
|
| + RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver;
|
| +};
|
| +
|
| ServiceWorkerClients* ServiceWorkerClients::create()
|
| {
|
| return new ServiceWorkerClients();
|
| @@ -73,4 +104,26 @@ ScriptPromise ServiceWorkerClients::getAll(ScriptState* scriptState, const Clien
|
| return promise;
|
| }
|
|
|
| +ScriptPromise ServiceWorkerClients::openWindow(ScriptState* scriptState, const String& url)
|
| +{
|
| + RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
|
| + ExecutionContext* context = scriptState->executionContext();
|
| + ScriptPromise promise = resolver->promise();
|
| +
|
| + KURL parsedURL = KURL(toWorkerGlobalScope(context)->location()->url(), url);
|
| + if (!parsedURL.isValid()) {
|
| + resolver->reject(DOMException::create(SyntaxError, "'" + url + "' is not a valid URL."));
|
| + return promise;
|
| + }
|
| +
|
| + // FIXME: Is this (1) correct and (2) sufficient?
|
| + if (!context->securityOrigin()->canRequest(parsedURL)) {
|
| + resolver->reject(DOMException::create(SecurityError, "Can only open documents in the worker's origin."));
|
| + return promise;
|
| + }
|
| +
|
| + ServiceWorkerGlobalScopeClient::from(context)->openWindow(parsedURL, new OpenWindowCallbacks(resolver));
|
| + return promise;
|
| +}
|
| +
|
| } // namespace blink
|
|
|