/*
- * Copyright (C) 2008, 2010 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2008, 2010, 2016 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
*/
-#ifndef Worker_h
-#define Worker_h
+#pragma once
#include "AbstractWorker.h"
#include "ActiveDOMObject.h"
-#include "EventListener.h"
+#include "ContentSecurityPolicyResponseHeaders.h"
#include "EventTarget.h"
#include "MessagePort.h"
#include "WorkerScriptLoaderClient.h"
-#include <wtf/Forward.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefPtr.h>
-#include <wtf/text/AtomicStringHash.h>
+#include <JavaScriptCore/RuntimeFlags.h>
+#include <wtf/MonotonicTime.h>
+#include <wtf/Optional.h>
+#include <wtf/text/AtomStringHash.h>
+
+namespace JSC {
+class ExecState;
+class JSObject;
+class JSValue;
+}
namespace WebCore {
- class ScriptExecutionContext;
- class WorkerGlobalScopeProxy;
- class WorkerScriptLoader;
+class ScriptExecutionContext;
+class WorkerGlobalScopeProxy;
+class WorkerScriptLoader;
- typedef int ExceptionCode;
+class Worker final : public AbstractWorker, public ActiveDOMObject, private WorkerScriptLoaderClient {
+ WTF_MAKE_ISO_ALLOCATED(Worker);
+public:
+ struct Options {
+ String name;
+ };
+ static ExceptionOr<Ref<Worker>> create(ScriptExecutionContext&, JSC::RuntimeFlags, const String& url, const Options&);
+ virtual ~Worker();
- class Worker final : public AbstractWorker, public ActiveDOMObject, private WorkerScriptLoaderClient {
- public:
- static PassRefPtr<Worker> create(ScriptExecutionContext&, const String& url, ExceptionCode&);
- virtual ~Worker();
+ ExceptionOr<void> postMessage(JSC::ExecState&, JSC::JSValue message, Vector<JSC::Strong<JSC::JSObject>>&&);
- virtual EventTargetInterface eventTargetInterface() const override { return WorkerEventTargetInterfaceType; }
+ void terminate();
- void postMessage(PassRefPtr<SerializedScriptValue> message, const MessagePortArray*, ExceptionCode&);
- // Needed for Objective-C bindings (see bug 28774).
- void postMessage(PassRefPtr<SerializedScriptValue> message, MessagePort*, ExceptionCode&);
+ bool hasPendingActivity() const final;
- void terminate();
+ String identifier() const { return m_identifier; }
- // EventTarget API.
- virtual ScriptExecutionContext* scriptExecutionContext() const override final { return ActiveDOMObject::scriptExecutionContext(); }
+ ScriptExecutionContext* scriptExecutionContext() const final { return ActiveDOMObject::scriptExecutionContext(); }
- // ActiveDOMObject API.
- bool hasPendingActivity() const override;
+private:
+ explicit Worker(ScriptExecutionContext&, JSC::RuntimeFlags, const Options&);
- private:
- explicit Worker(ScriptExecutionContext&);
+ EventTargetInterface eventTargetInterface() const final { return WorkerEventTargetInterfaceType; }
- void notifyNetworkStateChange(bool isOnline);
+ void notifyNetworkStateChange(bool isOnline);
- // WorkerScriptLoaderClient callbacks
- virtual void didReceiveResponse(unsigned long identifier, const ResourceResponse&) override;
- virtual void notifyFinished() override;
+ void didReceiveResponse(unsigned long identifier, const ResourceResponse&) final;
+ void notifyFinished() final;
- // ActiveDOMObject API.
- bool canSuspendForPageCache() const override;
- void stop() override;
- const char* activeDOMObjectName() const override;
+ bool canSuspendForDocumentSuspension() const final;
+ void stop() final;
+ const char* activeDOMObjectName() const final;
- friend void networkStateChanged(bool isOnLine);
+ static void networkStateChanged(bool isOnLine);
- RefPtr<WorkerScriptLoader> m_scriptLoader;
- WorkerGlobalScopeProxy* m_contextProxy; // The proxy outlives the worker to perform thread shutdown.
- };
+ RefPtr<WorkerScriptLoader> m_scriptLoader;
+ String m_name;
+ String m_identifier;
+ WorkerGlobalScopeProxy& m_contextProxy; // The proxy outlives the worker to perform thread shutdown.
+ Optional<ContentSecurityPolicyResponseHeaders> m_contentSecurityPolicyResponseHeaders;
+ MonotonicTime m_workerCreationTime;
+ bool m_shouldBypassMainWorldContentSecurityPolicy { false };
+ JSC::RuntimeFlags m_runtimeFlags;
+};
} // namespace WebCore
-
-#endif // Worker_h