| 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/ServiceWorkerClients.h" | 5 #include "modules/serviceworkers/ServiceWorkerClients.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" |
| 11 #include "core/workers/WorkerGlobalScope.h" | 11 #include "core/workers/WorkerGlobalScope.h" |
| 12 #include "core/workers/WorkerLocation.h" | 12 #include "core/workers/WorkerLocation.h" |
| 13 #include "modules/serviceworkers/ServiceWorkerError.h" | 13 #include "modules/serviceworkers/ServiceWorkerError.h" |
| 14 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" | 14 #include "modules/serviceworkers/ServiceWorkerGlobalScopeClient.h" |
| 15 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" | 15 #include "modules/serviceworkers/ServiceWorkerWindowClient.h" |
| 16 #include "modules/serviceworkers/ServiceWorkerWindowClientCallback.h" | 16 #include "modules/serviceworkers/ServiceWorkerWindowClientCallback.h" |
| 17 #include "public/platform/modules/serviceworker/WebServiceWorkerClientQueryOptio
ns.h" | 17 #include "public/platform/modules/serviceworker/WebServiceWorkerClientQueryOptio
ns.h" |
| 18 #include "public/platform/modules/serviceworker/WebServiceWorkerClientsInfo.h" | 18 #include "public/platform/modules/serviceworker/WebServiceWorkerClientsInfo.h" |
| 19 #include "wtf/PtrUtil.h" | 19 #include "wtf/PtrUtil.h" |
| 20 #include "wtf/RefPtr.h" | 20 #include "wtf/RefPtr.h" |
| 21 #include "wtf/Vector.h" | 21 #include "wtf/Vector.h" |
| 22 #include <memory> | 22 #include <memory> |
| 23 #include <utility> |
| 23 | 24 |
| 24 namespace blink { | 25 namespace blink { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 class ClientArray { | 29 class ClientArray { |
| 29 public: | 30 public: |
| 30 using WebType = const WebServiceWorkerClientsInfo&; | 31 using WebType = const WebServiceWorkerClientsInfo&; |
| 31 static HeapVector<Member<ServiceWorkerClient>> take( | 32 static HeapVector<Member<ServiceWorkerClient>> take( |
| 32 ScriptPromiseResolver*, | 33 ScriptPromiseResolver*, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 108 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 108 // TODO(jungkees): May be null due to worker termination: | 109 // TODO(jungkees): May be null due to worker termination: |
| 109 // http://crbug.com/413518. | 110 // http://crbug.com/413518. |
| 110 if (!executionContext) | 111 if (!executionContext) |
| 111 return ScriptPromise(); | 112 return ScriptPromise(); |
| 112 | 113 |
| 113 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 114 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 114 ScriptPromise promise = resolver->promise(); | 115 ScriptPromise promise = resolver->promise(); |
| 115 | 116 |
| 116 ServiceWorkerGlobalScopeClient::from(executionContext) | 117 ServiceWorkerGlobalScopeClient::from(executionContext) |
| 117 ->getClient(id, new GetCallback(resolver)); | 118 ->getClient(id, WTF::makeUnique<GetCallback>(resolver)); |
| 118 return promise; | 119 return promise; |
| 119 } | 120 } |
| 120 | 121 |
| 121 ScriptPromise ServiceWorkerClients::matchAll( | 122 ScriptPromise ServiceWorkerClients::matchAll( |
| 122 ScriptState* scriptState, | 123 ScriptState* scriptState, |
| 123 const ClientQueryOptions& options) { | 124 const ClientQueryOptions& options) { |
| 124 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 125 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 125 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 126 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
| 126 if (!executionContext) | 127 if (!executionContext) |
| 127 return ScriptPromise(); | 128 return ScriptPromise(); |
| 128 | 129 |
| 129 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 130 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 130 ScriptPromise promise = resolver->promise(); | 131 ScriptPromise promise = resolver->promise(); |
| 131 | 132 |
| 132 WebServiceWorkerClientQueryOptions webOptions; | 133 WebServiceWorkerClientQueryOptions webOptions; |
| 133 webOptions.clientType = getClientType(options.type()); | 134 webOptions.clientType = getClientType(options.type()); |
| 134 webOptions.includeUncontrolled = options.includeUncontrolled(); | 135 webOptions.includeUncontrolled = options.includeUncontrolled(); |
| 135 ServiceWorkerGlobalScopeClient::from(executionContext) | 136 ServiceWorkerGlobalScopeClient::from(executionContext) |
| 136 ->getClients(webOptions, | 137 ->getClients(webOptions, |
| 137 new CallbackPromiseAdapter<ClientArray, ServiceWorkerError>( | 138 WTF::makeUnique< |
| 139 CallbackPromiseAdapter<ClientArray, ServiceWorkerError>>( |
| 138 resolver)); | 140 resolver)); |
| 139 return promise; | 141 return promise; |
| 140 } | 142 } |
| 141 | 143 |
| 142 ScriptPromise ServiceWorkerClients::claim(ScriptState* scriptState) { | 144 ScriptPromise ServiceWorkerClients::claim(ScriptState* scriptState) { |
| 143 ExecutionContext* executionContext = scriptState->getExecutionContext(); | 145 ExecutionContext* executionContext = scriptState->getExecutionContext(); |
| 144 | 146 |
| 145 // FIXME: May be null due to worker termination: http://crbug.com/413518. | 147 // FIXME: May be null due to worker termination: http://crbug.com/413518. |
| 146 if (!executionContext) | 148 if (!executionContext) |
| 147 return ScriptPromise(); | 149 return ScriptPromise(); |
| 148 | 150 |
| 149 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 151 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 150 ScriptPromise promise = resolver->promise(); | 152 ScriptPromise promise = resolver->promise(); |
| 151 | 153 |
| 152 WebServiceWorkerClientsClaimCallbacks* callbacks = | 154 auto callbacks = |
| 153 new CallbackPromiseAdapter<void, ServiceWorkerError>(resolver); | 155 WTF::makeUnique<CallbackPromiseAdapter<void, ServiceWorkerError>>( |
| 154 ServiceWorkerGlobalScopeClient::from(executionContext)->claim(callbacks); | 156 resolver); |
| 157 ServiceWorkerGlobalScopeClient::from(executionContext) |
| 158 ->claim(std::move(callbacks)); |
| 155 return promise; | 159 return promise; |
| 156 } | 160 } |
| 157 | 161 |
| 158 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* scriptState, | 162 ScriptPromise ServiceWorkerClients::openWindow(ScriptState* scriptState, |
| 159 const String& url) { | 163 const String& url) { |
| 160 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 164 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 161 ScriptPromise promise = resolver->promise(); | 165 ScriptPromise promise = resolver->promise(); |
| 162 ExecutionContext* context = scriptState->getExecutionContext(); | 166 ExecutionContext* context = scriptState->getExecutionContext(); |
| 163 | 167 |
| 164 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); | 168 KURL parsedUrl = KURL(toWorkerGlobalScope(context)->location()->url(), url); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 176 } | 180 } |
| 177 | 181 |
| 178 if (!context->isWindowInteractionAllowed()) { | 182 if (!context->isWindowInteractionAllowed()) { |
| 179 resolver->reject(DOMException::create(InvalidAccessError, | 183 resolver->reject(DOMException::create(InvalidAccessError, |
| 180 "Not allowed to open a window.")); | 184 "Not allowed to open a window.")); |
| 181 return promise; | 185 return promise; |
| 182 } | 186 } |
| 183 context->consumeWindowInteraction(); | 187 context->consumeWindowInteraction(); |
| 184 | 188 |
| 185 ServiceWorkerGlobalScopeClient::from(context)->openWindow( | 189 ServiceWorkerGlobalScopeClient::from(context)->openWindow( |
| 186 parsedUrl, new NavigateClientCallback(resolver)); | 190 parsedUrl, WTF::makeUnique<NavigateClientCallback>(resolver)); |
| 187 return promise; | 191 return promise; |
| 188 } | 192 } |
| 189 | 193 |
| 190 } // namespace blink | 194 } // namespace blink |
| OLD | NEW |