| 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" | |
| 20 #include "wtf/RefPtr.h" | 19 #include "wtf/RefPtr.h" |
| 21 #include "wtf/Vector.h" | 20 #include "wtf/Vector.h" |
| 22 #include <memory> | 21 #include <memory> |
| 22 #include <utility> |
| 23 | 23 |
| 24 namespace blink { | 24 namespace blink { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class ClientArray { | 28 class ClientArray { |
| 29 public: | 29 public: |
| 30 using WebType = const WebServiceWorkerClientsInfo&; | 30 using WebType = const WebServiceWorkerClientsInfo&; |
| 31 static HeapVector<Member<ServiceWorkerClient>> take( | 31 static HeapVector<Member<ServiceWorkerClient>> take( |
| 32 ScriptPromiseResolver*, | 32 ScriptPromiseResolver*, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 class GetCallback : public WebServiceWorkerClientCallbacks { | 63 class GetCallback : public WebServiceWorkerClientCallbacks { |
| 64 public: | 64 public: |
| 65 explicit GetCallback(ScriptPromiseResolver* resolver) | 65 explicit GetCallback(ScriptPromiseResolver* resolver) |
| 66 : m_resolver(resolver) {} | 66 : m_resolver(resolver) {} |
| 67 ~GetCallback() override {} | 67 ~GetCallback() override {} |
| 68 | 68 |
| 69 void onSuccess( | 69 void onSuccess( |
| 70 std::unique_ptr<WebServiceWorkerClientInfo> webClient) override { | 70 std::unique_ptr<WebServiceWorkerClientInfo> webClient) override { |
| 71 std::unique_ptr<WebServiceWorkerClientInfo> client = | 71 std::unique_ptr<WebServiceWorkerClientInfo> client = std::move(webClient); |
| 72 wrapUnique(webClient.release()); | 72 if (!m_resolver->getExecutionContext()) |
| 73 if (!m_resolver->getExecutionContext() || | |
| 74 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | |
| 75 return; | 73 return; |
| 76 if (!client) { | 74 if (!client) { |
| 77 // Resolve the promise with undefined. | 75 // Resolve the promise with undefined. |
| 78 m_resolver->resolve(); | 76 m_resolver->resolve(); |
| 79 return; | 77 return; |
| 80 } | 78 } |
| 81 m_resolver->resolve( | 79 m_resolver->resolve( |
| 82 ServiceWorkerClient::take(m_resolver, std::move(client))); | 80 ServiceWorkerClient::take(m_resolver, std::move(client))); |
| 83 } | 81 } |
| 84 | 82 |
| 85 void onError(const WebServiceWorkerError& error) override { | 83 void onError(const WebServiceWorkerError& error) override { |
| 86 if (!m_resolver->getExecutionContext() || | 84 if (!m_resolver->getExecutionContext()) |
| 87 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | |
| 88 return; | 85 return; |
| 89 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); | 86 m_resolver->reject(ServiceWorkerError::take(m_resolver.get(), error)); |
| 90 } | 87 } |
| 91 | 88 |
| 92 private: | 89 private: |
| 93 Persistent<ScriptPromiseResolver> m_resolver; | 90 Persistent<ScriptPromiseResolver> m_resolver; |
| 94 WTF_MAKE_NONCOPYABLE(GetCallback); | 91 WTF_MAKE_NONCOPYABLE(GetCallback); |
| 95 }; | 92 }; |
| 96 | 93 |
| 97 } // namespace | 94 } // namespace |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 return promise; | 178 return promise; |
| 182 } | 179 } |
| 183 context->consumeWindowInteraction(); | 180 context->consumeWindowInteraction(); |
| 184 | 181 |
| 185 ServiceWorkerGlobalScopeClient::from(context)->openWindow( | 182 ServiceWorkerGlobalScopeClient::from(context)->openWindow( |
| 186 parsedUrl, new NavigateClientCallback(resolver)); | 183 parsedUrl, new NavigateClientCallback(resolver)); |
| 187 return promise; | 184 return promise; |
| 188 } | 185 } |
| 189 | 186 |
| 190 } // namespace blink | 187 } // namespace blink |
| OLD | NEW |