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

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

Issue 1196193003: ServiceWorker: Implement navigate() method in WindowClient (blink side). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 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/ServiceWorkerWindowClient.cpp
diff --git a/Source/modules/serviceworkers/ServiceWorkerWindowClient.cpp b/Source/modules/serviceworkers/ServiceWorkerWindowClient.cpp
index 6d463687cb700551454d8d8df8ebebc0cf40e520..132e904be6a012199e49681f1c2f6c16566f180a 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,31 @@ 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()) {
nhiroki 2015/07/10 04:50:59 FYI: As you might know, the way to handle "about:"
zino 2015/07/13 07:13:21 Thank you for the information.
+ resolver->reject(DOMException::create(SyntaxError, "'" + url + "' is not a valid URL."));
nhiroki 2015/07/10 04:50:59 Could you reject this by TypeError? From the spec
zino 2015/07/13 07:13:21 Done.
+ return promise;
+ }
+ if (!context->securityOrigin()->canDisplay(parsedUrl)) {
+ resolver->reject(DOMException::create(SecurityError, "'" + parsedUrl.elidedString() + "' cannot navigate."));
+ return promise;
+ }
+ if (!context->isWindowInteractionAllowed()) {
nhiroki 2015/07/10 04:50:59 Maybe we don't have to check this because this API
zino 2015/07/13 07:13:21 Done.
+ resolver->reject(DOMException::create(InvalidAccessError, "Not allowed to navigate."));
+ return promise;
+ }
+ context->consumeWindowInteraction();
+
+ ServiceWorkerGlobalScopeClient::from(context)->navigate(uuid(), parsedUrl, new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolver));
+ return promise;
+}
+
DEFINE_TRACE(ServiceWorkerWindowClient)
{
ServiceWorkerClient::trace(visitor);

Powered by Google App Engine
This is Rietveld 408576698