Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Unified Diff: Source/modules/serviceworkers/ServiceWorkerClients.cpp

Issue 850413002: [ServiceWorker] Implement ServiceWorkerClients.openWindow(). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@sw_client_info_cb
Patch Set: rebase Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
« no previous file with comments | « Source/modules/serviceworkers/ServiceWorkerClients.h ('k') | Source/modules/serviceworkers/ServiceWorkerGlobalScopeClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698