summaryrefslogtreecommitdiff
path: root/Source/WebCore/workers/WorkerGlobalScope.h
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2017-06-27 06:07:23 +0000
commit1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch)
tree46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/workers/WorkerGlobalScope.h
parent32761a6cee1d0dee366b885b7b9c777e67885688 (diff)
downloadWebKitGtk-tarball-master.tar.gz
Diffstat (limited to 'Source/WebCore/workers/WorkerGlobalScope.h')
-rw-r--r--Source/WebCore/workers/WorkerGlobalScope.h230
1 files changed, 120 insertions, 110 deletions
diff --git a/Source/WebCore/workers/WorkerGlobalScope.h b/Source/WebCore/workers/WorkerGlobalScope.h
index 5819965bf..ebe812342 100644
--- a/Source/WebCore/workers/WorkerGlobalScope.h
+++ b/Source/WebCore/workers/WorkerGlobalScope.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2008-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
@@ -10,10 +10,10 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -24,159 +24,169 @@
*
*/
-#ifndef WorkerGlobalScope_h
-#define WorkerGlobalScope_h
+#pragma once
-#include "ContentSecurityPolicy.h"
-#include "EventListener.h"
-#include "EventNames.h"
+#include "Base64Utilities.h"
#include "EventTarget.h"
-#include "GroupSettings.h"
#include "ScriptExecutionContext.h"
+#include "URL.h"
#include "WorkerEventQueue.h"
#include "WorkerScriptController.h"
-#include <wtf/Assertions.h>
-#include <wtf/HashMap.h>
-#include <wtf/OwnPtr.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
-#include <wtf/text/AtomicStringHash.h>
+#include <inspector/ConsoleMessage.h>
+#include <memory>
namespace WebCore {
- class Blob;
- class ScheduledAction;
- class WorkerInspectorController;
- class WorkerLocation;
- class WorkerNavigator;
- class WorkerThread;
+class ContentSecurityPolicyResponseHeaders;
+class Crypto;
+class Performance;
+class ScheduledAction;
+class WorkerInspectorController;
+class WorkerLocation;
+class WorkerNavigator;
+class WorkerThread;
- class WorkerGlobalScope : public RefCounted<WorkerGlobalScope>, public ScriptExecutionContext, public EventTargetWithInlineData {
- public:
- virtual ~WorkerGlobalScope();
+namespace IDBClient {
+class IDBConnectionProxy;
+}
- virtual bool isWorkerGlobalScope() const override { return true; }
+class WorkerGlobalScope : public RefCounted<WorkerGlobalScope>, public Supplementable<WorkerGlobalScope>, public ScriptExecutionContext, public EventTargetWithInlineData, public Base64Utilities {
+public:
+ virtual ~WorkerGlobalScope();
- virtual ScriptExecutionContext* scriptExecutionContext() const override final { return const_cast<WorkerGlobalScope*>(this); }
+ virtual bool isDedicatedWorkerGlobalScope() const { return false; }
- virtual bool isSharedWorkerGlobalScope() const { return false; }
- virtual bool isDedicatedWorkerGlobalScope() const { return false; }
+ const URL& url() const final { return m_url; }
- virtual const URL& url() const override final { return m_url; }
- virtual URL completeURL(const String&) const override final;
+#if ENABLE(INDEXED_DATABASE)
+ IDBClient::IDBConnectionProxy* idbConnectionProxy() final;
+ void stopIndexedDatabase();
+#endif
+
+ WorkerScriptController* script() { return m_script.get(); }
+ void clearScript() { m_script = nullptr; }
+
+ WorkerInspectorController& inspectorController() const { return *m_inspectorController; }
- const GroupSettings* groupSettings() { return m_groupSettings.get(); }
- virtual String userAgent(const URL&) const override;
+ WorkerThread& thread() const { return m_thread; }
- virtual void disableEval(const String& errorMessage) override;
+ using ScriptExecutionContext::hasPendingActivity;
- WorkerScriptController* script() { return m_script.get(); }
- void clearScript() { m_script.clear(); }
+ void postTask(Task&&) final; // Executes the task on context's thread asynchronously.
- WorkerThread* thread() const { return m_thread; }
+ WorkerGlobalScope& self() { return *this; }
+ WorkerLocation& location() const;
+ void close();
- bool hasPendingActivity() const;
+ virtual ExceptionOr<void> importScripts(const Vector<String>& urls);
+ WorkerNavigator& navigator() const;
- virtual void postTask(PassOwnPtr<Task>) override; // Executes the task on context's thread asynchronously.
+ int setTimeout(std::unique_ptr<ScheduledAction>, int timeout);
+ void clearTimeout(int timeoutId);
+ int setInterval(std::unique_ptr<ScheduledAction>, int timeout);
+ void clearInterval(int timeoutId);
- // WorkerGlobalScope
- WorkerGlobalScope* self() { return this; }
- WorkerLocation* location() const;
- void close();
+ bool isContextThread() const final;
- DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
- DEFINE_ATTRIBUTE_EVENT_LISTENER(offline);
- DEFINE_ATTRIBUTE_EVENT_LISTENER(online);
+ WorkerNavigator* optionalNavigator() const { return m_navigator.get(); }
+ WorkerLocation* optionalLocation() const { return m_location.get(); }
- // WorkerUtils
- virtual void importScripts(const Vector<String>& urls, ExceptionCode&);
- WorkerNavigator* navigator() const;
+ using RefCounted::ref;
+ using RefCounted::deref;
- // Timers
- int setTimeout(PassOwnPtr<ScheduledAction>, int timeout);
- void clearTimeout(int timeoutId);
- int setInterval(PassOwnPtr<ScheduledAction>, int timeout);
- void clearInterval(int timeoutId);
+ bool isClosing() { return m_closing; }
- virtual bool isContextThread() const override;
- virtual bool isJSExecutionForbidden() const override;
+ void addConsoleMessage(std::unique_ptr<Inspector::ConsoleMessage>&&);
-#if ENABLE(INSPECTOR)
- WorkerInspectorController& workerInspectorController() { return *m_workerInspectorController; }
+ Crypto& crypto();
+
+#if ENABLE(WEB_TIMING)
+ Performance& performance() const;
#endif
- // These methods are used for GC marking. See JSWorkerGlobalScope::visitChildrenVirtual(SlotVisitor&) in
- // JSWorkerGlobalScopeCustom.cpp.
- WorkerNavigator* optionalNavigator() const { return m_navigator.get(); }
- WorkerLocation* optionalLocation() const { return m_location.get(); }
- using RefCounted<WorkerGlobalScope>::ref;
- using RefCounted<WorkerGlobalScope>::deref;
+ void removeAllEventListeners() final;
- bool isClosing() { return m_closing; }
+protected:
+ WorkerGlobalScope(const URL&, const String& identifier, const String& userAgent, WorkerThread&, bool shouldBypassMainWorldContentSecurityPolicy, Ref<SecurityOrigin>&& topOrigin, MonotonicTime timeOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*);
- // An observer interface to be notified when the worker thread is getting stopped.
- class Observer {
- WTF_MAKE_NONCOPYABLE(Observer);
- public:
- Observer(WorkerGlobalScope*);
- virtual ~Observer();
- virtual void notifyStop() = 0;
- void stopObserving();
- private:
- WorkerGlobalScope* m_context;
- };
- friend class Observer;
- void registerObserver(Observer*);
- void unregisterObserver(Observer*);
- void notifyObserversOfStop();
+ void applyContentSecurityPolicyResponseHeaders(const ContentSecurityPolicyResponseHeaders&);
- virtual SecurityOrigin* topOrigin() const override { return m_topOrigin.get(); }
+private:
+ void refScriptExecutionContext() final { ref(); }
+ void derefScriptExecutionContext() final { deref(); }
- virtual void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier = 0) override;
+ void refEventTarget() final { ref(); }
+ void derefEventTarget() final { deref(); }
- protected:
- WorkerGlobalScope(const URL&, const String& userAgent, std::unique_ptr<GroupSettings>, WorkerThread*, PassRefPtr<SecurityOrigin> topOrigin);
- void applyContentSecurityPolicyFromString(const String& contentSecurityPolicy, ContentSecurityPolicy::HeaderType);
+ void logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, RefPtr<Inspector::ScriptCallStack>&&) final;
+ void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, RefPtr<Inspector::ScriptCallStack>&&, JSC::ExecState*, unsigned long requestIdentifier) final;
+ void addConsoleMessage(MessageSource, MessageLevel, const String& message, unsigned long requestIdentifier) final;
- virtual void logExceptionToConsole(const String& errorMessage, const String& sourceURL, int lineNumber, int columnNumber, PassRefPtr<ScriptCallStack>) override;
- void addMessageToWorkerConsole(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, PassRefPtr<ScriptCallStack>, JSC::ExecState* = 0, unsigned long requestIdentifier = 0);
+ bool isWorkerGlobalScope() const final { return true; }
- private:
- virtual void refScriptExecutionContext() override { ref(); }
- virtual void derefScriptExecutionContext() override { deref(); }
+ ScriptExecutionContext* scriptExecutionContext() const final { return const_cast<WorkerGlobalScope*>(this); }
+ URL completeURL(const String&) const final;
+ String userAgent(const URL&) const final;
+ void disableEval(const String& errorMessage) final;
+ EventTarget* errorEventTarget() final;
+ WorkerEventQueue& eventQueue() const final;
+ String resourceRequestIdentifier() const final { return m_identifier; }
- virtual void refEventTarget() override final { ref(); }
- virtual void derefEventTarget() override final { deref(); }
+#if ENABLE(WEB_SOCKETS)
+ SocketProvider* socketProvider() final;
+#endif
- virtual void addMessage(MessageSource, MessageLevel, const String& message, const String& sourceURL, unsigned lineNumber, unsigned columnNumber, PassRefPtr<ScriptCallStack>, JSC::ExecState* = 0, unsigned long requestIdentifier = 0) override;
+ bool shouldBypassMainWorldContentSecurityPolicy() const final { return m_shouldBypassMainWorldContentSecurityPolicy; }
+ bool isJSExecutionForbidden() const final;
+ SecurityOrigin& topOrigin() const final { return m_topOrigin.get(); }
+
+#if ENABLE(SUBTLE_CRYPTO)
+ // The following two functions are side effects of providing extra protection to serialized
+ // CryptoKey data that went through the structured clone algorithm to local storage such as
+ // IndexedDB. They don't provide any proctection against communications between mainThread
+ // and workerThreads. In fact, they cause extra expense as workerThreads cannot talk to clients
+ // to unwrap/wrap crypto keys. Hence, workerThreads must always ask mainThread to unwrap/wrap
+ // keys, which results in a second communication and plain keys being transferred between
+ // workerThreads and the mainThread.
+ bool wrapCryptoKey(const Vector<uint8_t>& key, Vector<uint8_t>& wrappedKey) final;
+ bool unwrapCryptoKey(const Vector<uint8_t>& wrappedKey, Vector<uint8_t>& key) final;
+#endif
+
+ URL m_url;
+ String m_identifier;
+ String m_userAgent;
- virtual EventTarget* errorEventTarget() override;
+ mutable RefPtr<WorkerLocation> m_location;
+ mutable RefPtr<WorkerNavigator> m_navigator;
- virtual WorkerEventQueue& eventQueue() const override final;
+ WorkerThread& m_thread;
+ std::unique_ptr<WorkerScriptController> m_script;
+ std::unique_ptr<WorkerInspectorController> m_inspectorController;
- URL m_url;
- String m_userAgent;
- std::unique_ptr<GroupSettings> m_groupSettings;
+ bool m_closing { false };
+ bool m_shouldBypassMainWorldContentSecurityPolicy;
- mutable RefPtr<WorkerLocation> m_location;
- mutable RefPtr<WorkerNavigator> m_navigator;
+ mutable WorkerEventQueue m_eventQueue;
- OwnPtr<WorkerScriptController> m_script;
- WorkerThread* m_thread;
+ Ref<SecurityOrigin> m_topOrigin;
-#if ENABLE(INSPECTOR)
- const std::unique_ptr<WorkerInspectorController> m_workerInspectorController;
+#if ENABLE(INDEXED_DATABASE)
+ RefPtr<IDBClient::IDBConnectionProxy> m_connectionProxy;
#endif
- bool m_closing;
- HashSet<Observer*> m_workerObservers;
+#if ENABLE(WEB_SOCKETS)
+ RefPtr<SocketProvider> m_socketProvider;
+#endif
- mutable WorkerEventQueue m_eventQueue;
+#if ENABLE(WEB_TIMING)
+ RefPtr<Performance> m_performance;
+#endif
- RefPtr<SecurityOrigin> m_topOrigin;
- };
+ mutable RefPtr<Crypto> m_crypto;
+};
} // namespace WebCore
-#endif // WorkerGlobalScope_h
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::WorkerGlobalScope)
+ static bool isType(const WebCore::ScriptExecutionContext& context) { return context.isWorkerGlobalScope(); }
+SPECIALIZE_TYPE_TRAITS_END()