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)...));
58 ServiceWorkerIdentifier identifier() const { return m_serviceWorkerThread->identifier(); }
59 ServiceWorkerThread& thread() { return m_serviceWorkerThread.get(); }
60 ServiceWorkerInspectorProxy& inspectorProxy() { return m_inspectorProxy; }
62 bool isTerminatingOrTerminated() const { return m_isTerminatingOrTerminated; }
63 void setAsTerminatingOrTerminated() { m_isTerminatingOrTerminated = true; }
65 WEBCORE_EXPORT std::unique_ptr<FetchLoader> createBlobLoader(FetchLoaderClient&, const URL&);
68 WEBCORE_EXPORT ServiceWorkerThreadProxy(PageConfiguration&&, const ServiceWorkerContextData&, PAL::SessionID, String&& userAgent, CacheStorageProvider&, SecurityOrigin::StorageBlockingPolicy);
71 bool postTaskForModeToWorkerGlobalScope(ScriptExecutionContext::Task&&, const String& mode) final;
72 void postTaskToLoader(ScriptExecutionContext::Task&&) final;
73 Ref<CacheStorageConnection> createCacheStorageConnection() final;
75 // WorkerDebuggerProxy
76 void postMessageToDebugger(const String&) final;
77 void setResourceCachingDisabled(bool) final;
79 UniqueRef<Page> m_page;
80 Ref<Document> m_document;
81 Ref<ServiceWorkerThread> m_serviceWorkerThread;
82 CacheStorageProvider& m_cacheStorageProvider;
83 RefPtr<CacheStorageConnection> m_cacheStorageConnection;
84 PAL::SessionID m_sessionID;
85 bool m_isTerminatingOrTerminated { false };
87 ServiceWorkerInspectorProxy m_inspectorProxy;
88 #if ENABLE(REMOTE_INSPECTOR)
89 std::unique_ptr<ServiceWorkerDebuggable> m_remoteDebuggable;
95 #endif // ENABLE(SERVICE_WORKER)