Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" | 6 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/page/PageVisibilityState.h" | 12 #include "core/page/PageVisibilityState.h" |
| 13 #include "core/workers/WorkerGlobalScope.h" | |
| 14 #include "core/workers/WorkerLocation.h" | |
| 13 #include "modules/serviceworkers/ServiceWorkerError.h" | 15 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 14 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 16 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| 15 #include "public/platform/WebString.h" | 17 #include "public/platform/WebString.h" |
| 16 #include "wtf/RefPtr.h" | 18 #include "wtf/RefPtr.h" |
| 17 | 19 |
| 18 namespace blink { | 20 namespace blink { |
| 19 | 21 |
| 20 ServiceWorkerWindowClient* ServiceWorkerWindowClient::take(ScriptPromiseResolver *, PassOwnPtr<ServiceWorkerWindowClient::WebType> webClient) | 22 ServiceWorkerWindowClient* ServiceWorkerWindowClient::take(ScriptPromiseResolver *, PassOwnPtr<ServiceWorkerWindowClient::WebType> webClient) |
| 21 { | 23 { |
| 22 return ServiceWorkerWindowClient::create(*webClient); | 24 return ServiceWorkerWindowClient::create(*webClient); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 51 if (!scriptState->executionContext()->isWindowInteractionAllowed()) { | 53 if (!scriptState->executionContext()->isWindowInteractionAllowed()) { |
| 52 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o focus a window.")); | 54 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o focus a window.")); |
| 53 return promise; | 55 return promise; |
| 54 } | 56 } |
| 55 scriptState->executionContext()->consumeWindowInteraction(); | 57 scriptState->executionContext()->consumeWindowInteraction(); |
| 56 | 58 |
| 57 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus (uuid(), new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerErro r>(resolver)); | 59 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus (uuid(), new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerErro r>(resolver)); |
| 58 return promise; | 60 return promise; |
| 59 } | 61 } |
| 60 | 62 |
| 63 ScriptPromise ServiceWorkerWindowClient::navigate(ScriptState* scriptState, cons t String& url) | |
| 64 { | |
| 65 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | |
| 66 ScriptPromise promise = resolver->promise(); | |
| 67 ExecutionContext* context = scriptState->executionContext(); | |
| 68 | |
| 69 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); | |
| 70 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.
| |
| 71 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.
| |
| 72 return promise; | |
| 73 } | |
| 74 if (!context->securityOrigin()->canDisplay(parsedUrl)) { | |
| 75 resolver->reject(DOMException::create(SecurityError, "'" + parsedUrl.eli dedString() + "' cannot navigate.")); | |
| 76 return promise; | |
| 77 } | |
| 78 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.
| |
| 79 resolver->reject(DOMException::create(InvalidAccessError, "Not allowed t o navigate.")); | |
| 80 return promise; | |
| 81 } | |
| 82 context->consumeWindowInteraction(); | |
| 83 | |
| 84 ServiceWorkerGlobalScopeClient::from(context)->navigate(uuid(), parsedUrl, n ew CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerError>(resolve r)); | |
| 85 return promise; | |
| 86 } | |
| 87 | |
| 61 DEFINE_TRACE(ServiceWorkerWindowClient) | 88 DEFINE_TRACE(ServiceWorkerWindowClient) |
| 62 { | 89 { |
| 63 ServiceWorkerClient::trace(visitor); | 90 ServiceWorkerClient::trace(visitor); |
| 64 } | 91 } |
| 65 | 92 |
| 66 } // namespace blink | 93 } // namespace blink |
| OLD | NEW |