2 * Copyright (C) 2017 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
28 #if ENABLE(SERVICE_WORKER)
30 #include "CacheStorageConnection.h"
33 #include "SecurityOrigin.h"
34 #include "ServiceWorkerDebuggable.h"
35 #include "ServiceWorkerIdentifier.h"
36 #include "ServiceWorkerInspectorProxy.h"
37 #include "ServiceWorkerThread.h"
38 #include "WorkerDebuggerProxy.h"
39 #include "WorkerLoaderProxy.h"
40 #include <wtf/HashMap.h>
44 class CacheStorageProvider;
46 class FetchLoaderClient;
47 class PageConfiguration;
48 class ServiceWorkerInspectorProxy;
49 struct ServiceWorkerContextData;
51 class ServiceWorkerThreadProxy final : public ThreadSafeRefCounted<ServiceWorkerThreadProxy>, public WorkerLoaderProxy, public WorkerDebuggerProxy {
53 template<typename... Args> static Ref<ServiceWorkerThreadProxy> create(Args&&... args)
55 return adoptRef(*new ServiceWorkerThreadProxy(std::forward<Args>(args)...));
57 ~ServiceWorkerThreadProxy();
59 ServiceWorkerIdentifier identifier() const { return m_serviceWorkerThread->identifier(); }
60 ServiceWorkerThread& thread() { return m_serviceWorkerThread.get(); }
61 ServiceWorkerInspectorProxy& inspectorProxy() { return m_inspectorProxy; }
63 bool isTerminatingOrTerminated() const { return m_isTerminatingOrTerminated; }
64 void setAsTerminatingOrTerminated() { m_isTerminatingOrTerminated = true; }
66 WEBCORE_EXPORT std::unique_ptr<FetchLoader> createBlobLoader(FetchLoaderClient&, const URL&);
68 // Public only for testing purposes.
69 WEBCORE_TESTSUPPORT_EXPORT void notifyNetworkStateChange(bool isOnline);
72 WEBCORE_EXPORT ServiceWorkerThreadProxy(PageConfiguration&&, const ServiceWorkerContextData&, PAL::SessionID, String&& userAgent, CacheStorageProvider&, SecurityOrigin::StorageBlockingPolicy);
74 WEBCORE_EXPORT static void networkStateChanged(bool isOnLine);
77 bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String& mode) final;
78 void postTaskToLoader(ScriptExecutionContext::Task&&) final;
79 Ref<CacheStorageConnection> createCacheStorageConnection() final;
81 // WorkerDebuggerProxy
82 void postMessageToDebugger(const String&) final;
83 void setResourceCachingDisabled(bool) final;
85 UniqueRef<Page> m_page;
86 Ref<Document> m_document;
87 Ref<ServiceWorkerThread> m_serviceWorkerThread;
88 CacheStorageProvider& m_cacheStorageProvider;
89 RefPtr<CacheStorageConnection> m_cacheStorageConnection;
90 PAL::SessionID m_sessionID;
91 bool m_isTerminatingOrTerminated { false };
93 ServiceWorkerInspectorProxy m_inspectorProxy;
94 #if ENABLE(REMOTE_INSPECTOR)
95 std::unique_ptr<ServiceWorkerDebuggable> m_remoteDebuggable;
101 #endif // ENABLE(SERVICE_WORKER)