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 "modules/serviceworkers/ServiceWorkerWindowClient.h" | 5 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" |
6 | 6 |
7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 String ServiceWorkerWindowClient::visibilityState() const | 43 String ServiceWorkerWindowClient::visibilityState() const |
44 { | 44 { |
45 return pageVisibilityStateString(static_cast<PageVisibilityState>(m_pageVisi
bilityState)); | 45 return pageVisibilityStateString(static_cast<PageVisibilityState>(m_pageVisi
bilityState)); |
46 } | 46 } |
47 | 47 |
48 ScriptPromise ServiceWorkerWindowClient::focus(ScriptState* scriptState) | 48 ScriptPromise ServiceWorkerWindowClient::focus(ScriptState* scriptState) |
49 { | 49 { |
50 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 50 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
51 ScriptPromise promise = resolver->promise(); | 51 ScriptPromise promise = resolver->promise(); |
52 | 52 |
53 if (!scriptState->executionContext()->isWindowInteractionAllowed()) { | 53 if (!scriptState->getExecutionContext()->isWindowInteractionAllowed()) { |
54 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.")); |
55 return promise; | 55 return promise; |
56 } | 56 } |
57 scriptState->executionContext()->consumeWindowInteraction(); | 57 scriptState->getExecutionContext()->consumeWindowInteraction(); |
58 | 58 |
59 ServiceWorkerGlobalScopeClient::from(scriptState->executionContext())->focus
(uuid(), new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerErro
r>(resolver)); | 59 ServiceWorkerGlobalScopeClient::from(scriptState->getExecutionContext())->fo
cus(uuid(), new CallbackPromiseAdapter<ServiceWorkerWindowClient, ServiceWorkerE
rror>(resolver)); |
60 return promise; | 60 return promise; |
61 } | 61 } |
62 | 62 |
63 ScriptPromise ServiceWorkerWindowClient::navigate(ScriptState* scriptState, cons
t String& url) | 63 ScriptPromise ServiceWorkerWindowClient::navigate(ScriptState* scriptState, cons
t String& url) |
64 { | 64 { |
65 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 65 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
66 ScriptPromise promise = resolver->promise(); | 66 ScriptPromise promise = resolver->promise(); |
67 ExecutionContext* context = scriptState->executionContext(); | 67 ExecutionContext* context = scriptState->getExecutionContext(); |
68 | 68 |
69 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); | 69 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); |
70 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { | 70 if (!parsedUrl.isValid() || parsedUrl.protocolIsAbout()) { |
71 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate(
), "'" + url + "' is not a valid URL.")); | 71 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate(
), "'" + url + "' is not a valid URL.")); |
72 return promise; | 72 return promise; |
73 } | 73 } |
74 if (!context->securityOrigin()->canDisplay(parsedUrl)) { | 74 if (!context->getSecurityOrigin()->canDisplay(parsedUrl)) { |
75 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate(
), "'" + parsedUrl.elidedString() + "' cannot navigate.")); | 75 resolver->reject(V8ThrowException::createTypeError(scriptState->isolate(
), "'" + parsedUrl.elidedString() + "' cannot navigate.")); |
76 return promise; | 76 return promise; |
77 } | 77 } |
78 | 78 |
79 ServiceWorkerGlobalScopeClient::from(context)->navigate(uuid(), parsedUrl, n
ew NavigateClientCallback(resolver)); | 79 ServiceWorkerGlobalScopeClient::from(context)->navigate(uuid(), parsedUrl, n
ew NavigateClientCallback(resolver)); |
80 return promise; | 80 return promise; |
81 } | 81 } |
82 | 82 |
83 DEFINE_TRACE(ServiceWorkerWindowClient) | 83 DEFINE_TRACE(ServiceWorkerWindowClient) |
84 { | 84 { |
85 ServiceWorkerClient::trace(visitor); | 85 ServiceWorkerClient::trace(visitor); |
86 } | 86 } |
87 | 87 |
88 } // namespace blink | 88 } // namespace blink |
OLD | NEW |