#pragma once
#include "ContentSecurityPolicyResponseHeaders.h"
#include "WorkerOrWorkletThread.h"
#include <JavaScriptCore/RuntimeFlags.h>
#include <memory>
#include <wtf/URL.h>
namespace WebCore {
class NotificationClient;
class SecurityOrigin;
class SocketProvider;
class WorkerGlobalScope;
class WorkerLoaderProxy;
class WorkerDebuggerProxy;
class WorkerReportingProxy;
enum class WorkerThreadStartMode {
Normal,
WaitForInspector,
};
namespace IDBClient {
class IDBConnectionProxy;
}
struct WorkerThreadStartupData;
struct WorkerParameters {
public:
URL scriptURL;
String name;
String identifier;
String userAgent;
bool isOnline;
ContentSecurityPolicyResponseHeaders contentSecurityPolicyResponseHeaders;
bool shouldBypassMainWorldContentSecurityPolicy;
MonotonicTime timeOrigin;
ReferrerPolicy referrerPolicy;
Settings::Values settingsValues;
WorkerParameters isolatedCopy() const;
};
class WorkerThread : public WorkerOrWorkletThread {
public:
virtual ~WorkerThread();
WorkerLoaderProxy& workerLoaderProxy() final { return m_workerLoaderProxy; }
WorkerDebuggerProxy* workerDebuggerProxy() const final { return &m_workerDebuggerProxy; }
WorkerReportingProxy& workerReportingProxy() const { return m_workerReportingProxy; }
WEBCORE_EXPORT static unsigned workerThreadCount();
#if ENABLE(NOTIFICATIONS)
NotificationClient* getNotificationClient() { return m_notificationClient; }
void setNotificationClient(NotificationClient* client) { m_notificationClient = client; }
#endif
JSC::RuntimeFlags runtimeFlags() const { return m_runtimeFlags; }
protected:
WorkerThread(const WorkerParameters&, const String& sourceCode, WorkerLoaderProxy&, WorkerDebuggerProxy&, WorkerReportingProxy&, WorkerThreadStartMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, JSC::RuntimeFlags);
virtual Ref<WorkerGlobalScope> createWorkerGlobalScope(const WorkerParameters&, Ref<SecurityOrigin>&&, Ref<SecurityOrigin>&& topOrigin) = 0;
WorkerGlobalScope* globalScope();
IDBClient::IDBConnectionProxy* idbConnectionProxy();
SocketProvider* socketProvider();
private:
virtual bool isServiceWorkerThread() const { return false; }
virtual void finishedEvaluatingScript() { }
Ref<WTF::Thread> createThread() final;
Ref<WorkerOrWorkletGlobalScope> createGlobalScope() final;
void evaluateScriptIfNecessary(String& exceptionMessage) final;
bool shouldWaitForWebInspectorOnStartup() const final;
WorkerLoaderProxy& m_workerLoaderProxy;
WorkerDebuggerProxy& m_workerDebuggerProxy;
WorkerReportingProxy& m_workerReportingProxy;
JSC::RuntimeFlags m_runtimeFlags;
std::unique_ptr<WorkerThreadStartupData> m_startupData;
#if ENABLE(NOTIFICATIONS)
NotificationClient* m_notificationClient { nullptr };
#endif
#if ENABLE(INDEXED_DATABASE)
RefPtr<IDBClient::IDBConnectionProxy> m_idbConnectionProxy;
#endif
RefPtr<SocketProvider> m_socketProvider;
};
}