Title: [288975] trunk/Source/WebCore
Revision
288975
Author
[email protected]
Date
2022-02-02 11:56:51 -0800 (Wed, 02 Feb 2022)

Log Message

Move SharedWorkerThread & SharedWorkerProxy to workers/shared/context/
https://bugs.webkit.org/show_bug.cgi?id=236017

Reviewed by Youenn Fablet.

Move SharedWorkerThread & SharedWorkerProxy to workers/shared/context/, for consistency with service workers.
Also rename SharedWorkerProxy to SharedWorkerThreadProxy.

* CMakeLists.txt:
* Headers.cmake:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* workers/shared/SharedWorker.cpp:
(WebCore::SharedWorker::SharedWorker):
* workers/shared/SharedWorker.h:
* workers/shared/SharedWorkerManager.cpp:
* workers/shared/context/SharedWorkerThread.cpp: Renamed from Source/WebCore/workers/shared/SharedWorkerThread.cpp.
* workers/shared/context/SharedWorkerThread.h: Renamed from Source/WebCore/workers/shared/SharedWorkerThread.h.
* workers/shared/context/SharedWorkerThreadProxy.cpp: Renamed from Source/WebCore/workers/shared/SharedWorkerProxy.cpp.
* workers/shared/context/SharedWorkerThreadProxy.h: Renamed from Source/WebCore/workers/shared/SharedWorkerProxy.h.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/CMakeLists.txt (288974 => 288975)


--- trunk/Source/WebCore/CMakeLists.txt	2022-02-02 19:51:20 UTC (rev 288974)
+++ trunk/Source/WebCore/CMakeLists.txt	2022-02-02 19:56:51 UTC (rev 288975)
@@ -179,6 +179,7 @@
     "${WEBCORE_DIR}/workers/service/context"
     "${WEBCORE_DIR}/workers/service/server"
     "${WEBCORE_DIR}/workers/shared"
+    "${WEBCORE_DIR}/workers/shared/context"
     "${WEBCORE_DIR}/worklets"
     "${WEBCORE_DIR}/xml"
     "${WEBCORE_DIR}/xml/parser"

Modified: trunk/Source/WebCore/ChangeLog (288974 => 288975)


--- trunk/Source/WebCore/ChangeLog	2022-02-02 19:51:20 UTC (rev 288974)
+++ trunk/Source/WebCore/ChangeLog	2022-02-02 19:56:51 UTC (rev 288975)
@@ -1,5 +1,28 @@
 2022-02-02  Chris Dumez  <[email protected]>
 
+        Move SharedWorkerThread & SharedWorkerProxy to workers/shared/context/
+        https://bugs.webkit.org/show_bug.cgi?id=236017
+
+        Reviewed by Youenn Fablet.
+
+        Move SharedWorkerThread & SharedWorkerProxy to workers/shared/context/, for consistency with service workers.
+        Also rename SharedWorkerProxy to SharedWorkerThreadProxy.
+
+        * CMakeLists.txt:
+        * Headers.cmake:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * workers/shared/SharedWorker.cpp:
+        (WebCore::SharedWorker::SharedWorker):
+        * workers/shared/SharedWorker.h:
+        * workers/shared/SharedWorkerManager.cpp:
+        * workers/shared/context/SharedWorkerThread.cpp: Renamed from Source/WebCore/workers/shared/SharedWorkerThread.cpp.
+        * workers/shared/context/SharedWorkerThread.h: Renamed from Source/WebCore/workers/shared/SharedWorkerThread.h.
+        * workers/shared/context/SharedWorkerThreadProxy.cpp: Renamed from Source/WebCore/workers/shared/SharedWorkerProxy.cpp.
+        * workers/shared/context/SharedWorkerThreadProxy.h: Renamed from Source/WebCore/workers/shared/SharedWorkerProxy.h.
+
+2022-02-02  Chris Dumez  <[email protected]>
+
         Support sending WorkerOptions over IPC
         https://bugs.webkit.org/show_bug.cgi?id=236026
 

Modified: trunk/Source/WebCore/Headers.cmake (288974 => 288975)


--- trunk/Source/WebCore/Headers.cmake	2022-02-02 19:51:20 UTC (rev 288974)
+++ trunk/Source/WebCore/Headers.cmake	2022-02-02 19:56:51 UTC (rev 288975)
@@ -2000,6 +2000,9 @@
     workers/service/server/SWServerToContextConnection.h
     workers/service/server/SWServerWorker.h
 
+    workers/shared/context/SharedWorkerThread.h
+    workers/shared/context/SharedWorkerThreadProxy.h
+
     xml/CustomXPathNSResolver.h
     xml/XPathExpression.h
     xml/XPathNSResolver.h

Modified: trunk/Source/WebCore/Sources.txt (288974 => 288975)


--- trunk/Source/WebCore/Sources.txt	2022-02-02 19:51:20 UTC (rev 288974)
+++ trunk/Source/WebCore/Sources.txt	2022-02-02 19:56:51 UTC (rev 288975)
@@ -2787,9 +2787,9 @@
 workers/shared/SharedWorker.cpp
 workers/shared/SharedWorkerGlobalScope.cpp
 workers/shared/SharedWorkerManager.cpp
-workers/shared/SharedWorkerProxy.cpp
 workers/shared/SharedWorkerScriptLoader.cpp
-workers/shared/SharedWorkerThread.cpp
+workers/shared/context/SharedWorkerThread.cpp
+workers/shared/context/SharedWorkerThreadProxy.cpp
 worklets/PaintWorkletGlobalScope.cpp
 worklets/Worklet.cpp
 worklets/WorkletGlobalScope.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (288974 => 288975)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-02-02 19:51:20 UTC (rev 288974)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-02-02 19:56:51 UTC (rev 288975)
@@ -1342,9 +1342,9 @@
 		4672AA9826B0943300E6EC38 /* CrossOriginEmbedderPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4672AA9626B0942100E6EC38 /* CrossOriginEmbedderPolicy.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		4672AA9926B0943F00E6EC38 /* CrossOriginOpenerPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4672AA9726B0942100E6EC38 /* CrossOriginOpenerPolicy.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		467302021C4EFE7800BCB357 /* IgnoreOpensDuringUnloadCountIncrementer.h in Headers */ = {isa = PBXBuildFile; fileRef = 467302011C4EFE6600BCB357 /* IgnoreOpensDuringUnloadCountIncrementer.h */; };
-		467A68D7275EA991009B31C5 /* SharedWorkerThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 467A68D4275EA98B009B31C5 /* SharedWorkerThread.h */; };
+		467A68D7275EA991009B31C5 /* SharedWorkerThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 467A68D4275EA98B009B31C5 /* SharedWorkerThread.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		467A68D8275EA995009B31C5 /* SharedWorkerScriptLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 467A68D5275EA98C009B31C5 /* SharedWorkerScriptLoader.h */; };
-		467A68D9275EA998009B31C5 /* SharedWorkerProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 467A68D6275EA98C009B31C5 /* SharedWorkerProxy.h */; };
+		467A68D9275EA998009B31C5 /* SharedWorkerThreadProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 467A68D6275EA98C009B31C5 /* SharedWorkerThreadProxy.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		467A68DA275EA99C009B31C5 /* SharedWorkerManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 467A68D2275EA98A009B31C5 /* SharedWorkerManager.h */; };
 		4682D2001F79783000C863DB /* StoredCredentialsPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4682D1FF1F79782300C863DB /* StoredCredentialsPolicy.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		468344E01EDDFAAA00B7795B /* DOMRectList.h in Headers */ = {isa = PBXBuildFile; fileRef = 468344DE1EDDFA5F00B7795B /* DOMRectList.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -9234,7 +9234,7 @@
 		467302011C4EFE6600BCB357 /* IgnoreOpensDuringUnloadCountIncrementer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IgnoreOpensDuringUnloadCountIncrementer.h; sourceTree = "<group>"; };
 		467802B02747117B00DA9FB6 /* WebLockManagerSnapshot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebLockManagerSnapshot.h; sourceTree = "<group>"; };
 		467802B22747118500DA9FB6 /* WebLockIdentifier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebLockIdentifier.h; sourceTree = "<group>"; };
-		467A68CF275EA989009B31C5 /* SharedWorkerProxy.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SharedWorkerProxy.cpp; sourceTree = "<group>"; };
+		467A68CF275EA989009B31C5 /* SharedWorkerThreadProxy.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SharedWorkerThreadProxy.cpp; sourceTree = "<group>"; };
 		467A68D0275EA989009B31C5 /* SharedWorkerThread.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SharedWorkerThread.cpp; sourceTree = "<group>"; };
 		467A68D1275EA98A009B31C5 /* SharedWorkerScriptLoader.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SharedWorkerScriptLoader.cpp; sourceTree = "<group>"; };
 		467A68D2275EA98A009B31C5 /* SharedWorkerManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SharedWorkerManager.h; sourceTree = "<group>"; };
@@ -9241,7 +9241,7 @@
 		467A68D3275EA98B009B31C5 /* SharedWorkerManager.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SharedWorkerManager.cpp; sourceTree = "<group>"; };
 		467A68D4275EA98B009B31C5 /* SharedWorkerThread.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SharedWorkerThread.h; sourceTree = "<group>"; };
 		467A68D5275EA98C009B31C5 /* SharedWorkerScriptLoader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SharedWorkerScriptLoader.h; sourceTree = "<group>"; };
-		467A68D6275EA98C009B31C5 /* SharedWorkerProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SharedWorkerProxy.h; sourceTree = "<group>"; };
+		467A68D6275EA98C009B31C5 /* SharedWorkerThreadProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SharedWorkerThreadProxy.h; sourceTree = "<group>"; };
 		4682D1FF1F79782300C863DB /* StoredCredentialsPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StoredCredentialsPolicy.h; sourceTree = "<group>"; };
 		468344DC1EDDFA5F00B7795B /* DOMRectList.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = DOMRectList.idl; sourceTree = "<group>"; };
 		468344DD1EDDFA5F00B7795B /* DOMRectList.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DOMRectList.cpp; sourceTree = "<group>"; };
@@ -21552,9 +21552,21 @@
 			path = "web-locks";
 			sourceTree = "<group>";
 		};
+		4647CE6127AAE1DA009CBD48 /* context */ = {
+			isa = PBXGroup;
+			children = (
+				467A68D0275EA989009B31C5 /* SharedWorkerThread.cpp */,
+				467A68D4275EA98B009B31C5 /* SharedWorkerThread.h */,
+				467A68CF275EA989009B31C5 /* SharedWorkerThreadProxy.cpp */,
+				467A68D6275EA98C009B31C5 /* SharedWorkerThreadProxy.h */,
+			);
+			path = context;
+			sourceTree = "<group>";
+		};
 		46694CDE2759446D00E3150E /* shared */ = {
 			isa = PBXGroup;
 			children = (
+				4647CE6127AAE1DA009CBD48 /* context */,
 				46694CE32759448D00E3150E /* SharedWorker.cpp */,
 				46694CE22759448D00E3150E /* SharedWorker.h */,
 				46694CE52759448E00E3150E /* SharedWorker.idl */,
@@ -21563,12 +21575,8 @@
 				46694CE02759448C00E3150E /* SharedWorkerGlobalScope.idl */,
 				467A68D3275EA98B009B31C5 /* SharedWorkerManager.cpp */,
 				467A68D2275EA98A009B31C5 /* SharedWorkerManager.h */,
-				467A68CF275EA989009B31C5 /* SharedWorkerProxy.cpp */,
-				467A68D6275EA98C009B31C5 /* SharedWorkerProxy.h */,
 				467A68D1275EA98A009B31C5 /* SharedWorkerScriptLoader.cpp */,
 				467A68D5275EA98C009B31C5 /* SharedWorkerScriptLoader.h */,
-				467A68D0275EA989009B31C5 /* SharedWorkerThread.cpp */,
-				467A68D4275EA98B009B31C5 /* SharedWorkerThread.h */,
 			);
 			path = shared;
 			sourceTree = "<group>";
@@ -37179,9 +37187,9 @@
 				93309EA3099EB78C0056E581 /* SharedTimer.h in Headers */,
 				41DC04FE27A83C93008CF968 /* SharedVideoFrameInfo.h in Headers */,
 				467A68DA275EA99C009B31C5 /* SharedWorkerManager.h in Headers */,
-				467A68D9275EA998009B31C5 /* SharedWorkerProxy.h in Headers */,
 				467A68D8275EA995009B31C5 /* SharedWorkerScriptLoader.h in Headers */,
 				467A68D7275EA991009B31C5 /* SharedWorkerThread.h in Headers */,
+				467A68D9275EA998009B31C5 /* SharedWorkerThreadProxy.h in Headers */,
 				1C4DB02627339FE0007B0AD1 /* ShouldLocalizeAxisNames.h in Headers */,
 				DF19E2AC24772BC1007BDACB /* ShouldRelaxThirdPartyCookieBlocking.h in Headers */,
 				8362E8C120CEF9CB00245886 /* ShouldTreatAsContinuingLoad.h in Headers */,

Modified: trunk/Source/WebCore/workers/shared/SharedWorker.cpp (288974 => 288975)


--- trunk/Source/WebCore/workers/shared/SharedWorker.cpp	2022-02-02 19:51:20 UTC (rev 288974)
+++ trunk/Source/WebCore/workers/shared/SharedWorker.cpp	2022-02-02 19:56:51 UTC (rev 288975)
@@ -32,7 +32,7 @@
 #include "MessagePort.h"
 #include "SecurityOrigin.h"
 #include "SharedWorkerManager.h"
-#include "SharedWorkerProxy.h"
+#include "SharedWorkerThreadProxy.h"
 #include "WorkerOptions.h"
 #include <_javascript_Core/IdentifiersFactory.h>
 #include <wtf/IsoMallocInlines.h>
@@ -80,7 +80,7 @@
     , m_identifierForInspector("SharedWorker:" + Inspector::IdentifiersFactory::createIdentifier())
     , m_runtimeFlags(runtimeFlags)
     , m_creationTime(MonotonicTime::now())
-    , m_proxy(SharedWorkerProxy::create(*this))
+    , m_proxy(SharedWorkerThreadProxy::create(*this))
 {
 }
 

Modified: trunk/Source/WebCore/workers/shared/SharedWorker.h (288974 => 288975)


--- trunk/Source/WebCore/workers/shared/SharedWorker.h	2022-02-02 19:51:20 UTC (rev 288974)
+++ trunk/Source/WebCore/workers/shared/SharedWorker.h	2022-02-02 19:56:51 UTC (rev 288975)
@@ -33,7 +33,7 @@
 namespace WebCore {
 
 class MessagePort;
-class SharedWorkerProxy;
+class SharedWorkerThreadProxy;
 
 struct WorkerOptions;
 
@@ -49,7 +49,7 @@
     const String& identifierForInspector() const { return m_identifierForInspector; }
     MonotonicTime creationTime() const { return m_creationTime; }
 
-    SharedWorkerProxy& proxy() { return m_proxy; }
+    SharedWorkerThreadProxy& proxy() { return m_proxy; }
 
     void setIsLoading(bool isLoading) { m_isLoading = isLoading; }
 
@@ -74,7 +74,7 @@
     String m_identifierForInspector;
     JSC::RuntimeFlags m_runtimeFlags;
     MonotonicTime m_creationTime;
-    SharedWorkerProxy& m_proxy; // The proxy outlives the worker to perform thread shutdown.
+    SharedWorkerThreadProxy& m_proxy; // The proxy outlives the worker to perform thread shutdown.
     bool m_isLoading { false };
 };
 

Modified: trunk/Source/WebCore/workers/shared/SharedWorkerManager.cpp (288974 => 288975)


--- trunk/Source/WebCore/workers/shared/SharedWorkerManager.cpp	2022-02-02 19:51:20 UTC (rev 288974)
+++ trunk/Source/WebCore/workers/shared/SharedWorkerManager.cpp	2022-02-02 19:56:51 UTC (rev 288975)
@@ -33,9 +33,9 @@
 #include "PlatformStrategies.h"
 #include "SharedWorker.h"
 #include "SharedWorkerGlobalScope.h"
-#include "SharedWorkerProxy.h"
 #include "SharedWorkerScriptLoader.h"
 #include "SharedWorkerThread.h"
+#include "SharedWorkerThreadProxy.h"
 #include "WorkerRunLoop.h"
 #include "WorkerScriptLoader.h"
 #include <wtf/NeverDestroyed.h>

Deleted: trunk/Source/WebCore/workers/shared/SharedWorkerProxy.cpp (288974 => 288975)


--- trunk/Source/WebCore/workers/shared/SharedWorkerProxy.cpp	2022-02-02 19:51:20 UTC (rev 288974)
+++ trunk/Source/WebCore/workers/shared/SharedWorkerProxy.cpp	2022-02-02 19:56:51 UTC (rev 288975)
@@ -1,233 +0,0 @@
-/*
- * Copyright (C) 2021 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 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.
- */
-
-#include "config.h"
-#include "SharedWorkerProxy.h"
-
-#include "CacheStorageProvider.h"
-#include "ErrorEvent.h"
-#include "EventNames.h"
-#include "LibWebRTCProvider.h"
-#include "MessageEvent.h"
-#include "MessagePort.h"
-#include "Page.h"
-#include "RTCDataChannelRemoteHandlerConnection.h"
-#include "SharedWorker.h"
-#include "SharedWorkerGlobalScope.h"
-#include "SharedWorkerThread.h"
-
-namespace WebCore {
-
-SharedWorkerProxy::SharedWorkerProxy(SharedWorker& sharedWorker)
-    : m_sharedWorker(sharedWorker)
-    , m_scriptExecutionContext(sharedWorker.scriptExecutionContext())
-    , m_identifierForInspector(sharedWorker.identifierForInspector())
-{
-}
-
-void SharedWorkerProxy::startWorkerGlobalScope(const URL& scriptURL, const String& name, const String& userAgent, bool isOnline, const ScriptBuffer& scriptBuffer, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicyResponseHeaders, bool shouldBypassMainWorldContentSecurityPolicy, const CrossOriginEmbedderPolicy& crossOriginEmbedderPolicy, MonotonicTime timeOrigin, ReferrerPolicy referrerPolicy, WorkerType workerType, FetchRequestCredentials credentials, JSC::RuntimeFlags runtimeFlags)
-{
-    if (m_askedToTerminate)
-        return;
-
-    auto parameters = WorkerParameters {
-        scriptURL,
-        name,
-        m_identifierForInspector,
-        userAgent,
-        isOnline,
-        contentSecurityPolicyResponseHeaders,
-        shouldBypassMainWorldContentSecurityPolicy,
-        crossOriginEmbedderPolicy,
-        timeOrigin,
-        referrerPolicy,
-        workerType,
-        credentials,
-        m_scriptExecutionContext->settingsValues()
-    };
-
-    if (!m_workerThread) {
-        m_workerThread = SharedWorkerThread::create(parameters, scriptBuffer, *this, *this, *this, WorkerThreadStartMode::Normal, m_scriptExecutionContext->topOrigin(), m_scriptExecutionContext->idbConnectionProxy(), m_scriptExecutionContext->socketProvider(), runtimeFlags);
-        m_workerThread->start();
-    }
-}
-
-void SharedWorkerProxy::terminateWorkerGlobalScope()
-{
-    if (m_askedToTerminate)
-        return;
-
-    m_askedToTerminate = true;
-    if (m_workerThread)
-        m_workerThread->stop(nullptr);
-}
-
-void SharedWorkerProxy::postMessageToWorkerGlobalScope(MessageWithMessagePorts&& message)
-{
-    // FIXME: SharedWorker doesn't have postMessage, so this might not be necessary.
-    postTaskToWorkerGlobalScope([message = WTFMove(message)](auto& scriptContext) mutable {
-        auto& context = downcast<SharedWorkerGlobalScope>(scriptContext);
-        auto ports = MessagePort::entanglePorts(scriptContext, WTFMove(message.transferredPorts));
-        context.dispatchEvent(MessageEvent::create(WTFMove(ports), message.message.releaseNonNull()));
-    });
-}
-
-void SharedWorkerProxy::postTaskToWorkerGlobalScope(Function<void(ScriptExecutionContext&)>&& task)
-{
-    if (m_askedToTerminate)
-        return;
-    m_workerThread->runLoop().postTask(WTFMove(task));
-}
-
-bool SharedWorkerProxy::hasPendingActivity() const
-{
-    return m_hasPendingActivity && !m_askedToTerminate;
-}
-
-void SharedWorkerProxy::workerObjectDestroyed()
-{
-    m_sharedWorker = nullptr;
-    m_scriptExecutionContext->postTask([this] (ScriptExecutionContext&) {
-        m_mayBeDestroyed = true;
-        if (m_workerThread)
-            terminateWorkerGlobalScope();
-        else
-            workerGlobalScopeDestroyedInternal();
-    });
-}
-
-void SharedWorkerProxy::notifyNetworkStateChange(bool isOnline)
-{
-    if (m_askedToTerminate)
-        return;
-
-    if (!m_workerThread)
-        return;
-
-    m_workerThread->runLoop().postTask([isOnline] (ScriptExecutionContext& context) {
-        auto& globalScope = downcast<WorkerGlobalScope>(context);
-        globalScope.setIsOnline(isOnline);
-        globalScope.dispatchEvent(Event::create(isOnline ? eventNames().onlineEvent : eventNames().offlineEvent, Event::CanBubble::No, Event::IsCancelable::No));
-    });
-}
-
-void SharedWorkerProxy::suspendForBackForwardCache()
-{
-
-}
-
-void SharedWorkerProxy::resumeForBackForwardCache()
-{
-
-}
-
-void SharedWorkerProxy::postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL)
-{
-    m_scriptExecutionContext->postTask([this, errorMessage = errorMessage.isolatedCopy(), sourceURL = sourceURL.isolatedCopy(), lineNumber, columnNumber] (ScriptExecutionContext&) {
-        if (!m_sharedWorker)
-            return;
-
-        // We don't bother checking the askedToTerminate() flag here, because exceptions should *always* be reported even if the thread is terminated.
-        // This is intentionally different than the behavior in MessageWorkerTask, because terminated workers no longer deliver messages (section 4.6 of the WebWorker spec), but they do report exceptions.
-        ActiveDOMObject::queueTaskToDispatchEvent(*m_sharedWorker, TaskSource::DOMManipulation, ErrorEvent::create(errorMessage, sourceURL, lineNumber, columnNumber, { }));
-    });
-}
-
-void SharedWorkerProxy::workerGlobalScopeDestroyed()
-{
-    m_scriptExecutionContext->postTask([this] (ScriptExecutionContext&) {
-        workerGlobalScopeDestroyedInternal();
-    });
-}
-
-void SharedWorkerProxy::postMessageToWorkerObject(MessageWithMessagePorts&&)
-{
-
-}
-
-void SharedWorkerProxy::confirmMessageFromWorkerObject(bool)
-{
-}
-
-void SharedWorkerProxy::reportPendingActivity(bool hasPendingActivity)
-{
-    m_scriptExecutionContext->postTask([this, hasPendingActivity] (ScriptExecutionContext&) {
-        m_hasPendingActivity = hasPendingActivity;
-    });
-}
-
-RefPtr<CacheStorageConnection> SharedWorkerProxy::createCacheStorageConnection()
-{
-    ASSERT(isMainThread());
-    auto& document = downcast<Document>(*m_scriptExecutionContext);
-    return document.page()->cacheStorageProvider().createCacheStorageConnection();
-}
-
-RefPtr<RTCDataChannelRemoteHandlerConnection> SharedWorkerProxy::createRTCDataChannelRemoteHandlerConnection()
-{
-    ASSERT(isMainThread());
-    auto& document = downcast<Document>(*m_scriptExecutionContext);
-    if (!document.page())
-        return nullptr;
-    return document.page()->libWebRTCProvider().createRTCDataChannelRemoteHandlerConnection();
-}
-
-void SharedWorkerProxy::postTaskToLoader(ScriptExecutionContext::Task&& task)
-{
-    m_scriptExecutionContext->postTask(WTFMove(task));
-}
-
-bool SharedWorkerProxy::postTaskForModeToWorkerOrWorkletGlobalScope(ScriptExecutionContext::Task&& task, const String& mode)
-{
-    if (m_askedToTerminate)
-        return false;
-
-    m_workerThread->runLoop().postTaskForMode(WTFMove(task), mode);
-    return true;
-}
-
-void SharedWorkerProxy::postMessageToDebugger(const String&)
-{
-
-}
-
-void SharedWorkerProxy::setResourceCachingDisabledByWebInspector(bool)
-{
-
-}
-
-void SharedWorkerProxy::workerGlobalScopeDestroyedInternal()
-{
-    // This is always the last task to be performed, so the proxy is not needed for communication
-    // in either side any more. However, the Worker object may still exist, and it assumes that the proxy exists, too.
-    m_askedToTerminate = true;
-    m_workerThread = nullptr;
-
-    // This balances the original ref in construction.
-    if (m_mayBeDestroyed)
-        deref();
-}
-
-} // namespace WebCore

Deleted: trunk/Source/WebCore/workers/shared/SharedWorkerProxy.h (288974 => 288975)


--- trunk/Source/WebCore/workers/shared/SharedWorkerProxy.h	2022-02-02 19:51:20 UTC (rev 288974)
+++ trunk/Source/WebCore/workers/shared/SharedWorkerProxy.h	2022-02-02 19:56:51 UTC (rev 288975)
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2021 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 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.
- */
-
-#pragma once
-
-#include "WorkerDebuggerProxy.h"
-#include "WorkerGlobalScopeProxy.h"
-#include "WorkerLoaderProxy.h"
-#include "WorkerObjectProxy.h"
-#include "WorkerOptions.h"
-#include <wtf/WeakPtr.h>
-
-namespace WebCore {
-
-class SharedWorker;
-class SharedWorkerThread;
-
-class SharedWorkerProxy : public ThreadSafeRefCounted<SharedWorkerProxy>, public WorkerGlobalScopeProxy, public WorkerObjectProxy, public WorkerLoaderProxy, public WorkerDebuggerProxy {
-public:
-    template<typename... Args> static SharedWorkerProxy& create(Args&&... args) { return *new SharedWorkerProxy(std::forward<Args>(args)...); }
-
-    SharedWorkerThread* thread() { return m_workerThread.get(); }
-
-    void startWorkerGlobalScope(const URL& scriptURL, const String& name, const String& userAgent, bool isOnline, const ScriptBuffer& sourceCode, const ContentSecurityPolicyResponseHeaders&, bool shouldBypassMainWorldContentSecurityPolicy, const CrossOriginEmbedderPolicy&, MonotonicTime timeOrigin, ReferrerPolicy, WorkerType, FetchRequestCredentials, JSC::RuntimeFlags) final;
-    void terminateWorkerGlobalScope() final;
-    void postMessageToWorkerGlobalScope(MessageWithMessagePorts&&) final;
-    void postTaskToWorkerGlobalScope(Function<void(ScriptExecutionContext&)>&&) final;
-    bool hasPendingActivity() const final;
-    void workerObjectDestroyed() final;
-    void notifyNetworkStateChange(bool isOnline) final;
-    void suspendForBackForwardCache() final;
-    void resumeForBackForwardCache() final;
-    void postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) final;
-    void workerGlobalScopeDestroyed() final;
-    void postMessageToWorkerObject(MessageWithMessagePorts&&) final;
-    void confirmMessageFromWorkerObject(bool hasPendingActivity) final;
-    void reportPendingActivity(bool hasPendingActivity) final;
-    RefPtr<CacheStorageConnection> createCacheStorageConnection() final;
-    RefPtr<RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() final;
-    void postTaskToLoader(ScriptExecutionContext::Task&&) final;
-    bool postTaskForModeToWorkerOrWorkletGlobalScope(ScriptExecutionContext::Task&&, const String& mode) final;
-    void postMessageToDebugger(const String&) final;
-    void setResourceCachingDisabledByWebInspector(bool) final;
-
-private:
-    SharedWorkerProxy(SharedWorker&);
-
-    void workerGlobalScopeDestroyedInternal();
-
-    WeakPtr<SharedWorker> m_sharedWorker;
-    RefPtr<SharedWorkerThread> m_workerThread;
-    const RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
-    const String m_identifierForInspector;
-    bool m_askedToTerminate { false };
-    bool m_hasPendingActivity { false };
-    bool m_mayBeDestroyed { false };
-};
-
-} // namespace WebCore

Deleted: trunk/Source/WebCore/workers/shared/SharedWorkerThread.cpp (288974 => 288975)


--- trunk/Source/WebCore/workers/shared/SharedWorkerThread.cpp	2022-02-02 19:51:20 UTC (rev 288974)
+++ trunk/Source/WebCore/workers/shared/SharedWorkerThread.cpp	2022-02-02 19:56:51 UTC (rev 288975)
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2021 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 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.
- */
-
-#include "config.h"
-#include "SharedWorkerThread.h"
-
-#include "SharedWorkerGlobalScope.h"
-#include "WorkerObjectProxy.h"
-
-namespace WebCore {
-
-SharedWorkerThread::SharedWorkerThread(const WorkerParameters& parameters, const ScriptBuffer& sourceCode, WorkerLoaderProxy& loaderProxy, WorkerDebuggerProxy& debuggerProxy, WorkerObjectProxy& objectProxy, WorkerThreadStartMode startMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, JSC::RuntimeFlags runtimeFlags)
-    : WorkerThread(parameters, sourceCode, loaderProxy, debuggerProxy, objectProxy, startMode, topOrigin, connectionProxy, socketProvider, runtimeFlags)
-    , m_name(parameters.name.isolatedCopy())
-{
-}
-
-Ref<WorkerGlobalScope> SharedWorkerThread::createWorkerGlobalScope(const WorkerParameters& parameters, Ref<SecurityOrigin>&& origin, Ref<SecurityOrigin>&& topOrigin)
-{
-    return SharedWorkerGlobalScope::create(std::exchange(m_name, { }), parameters, WTFMove(origin), *this, WTFMove(topOrigin), idbConnectionProxy(), socketProvider());
-}
-
-} // namespace WebCore

Deleted: trunk/Source/WebCore/workers/shared/SharedWorkerThread.h (288974 => 288975)


--- trunk/Source/WebCore/workers/shared/SharedWorkerThread.h	2022-02-02 19:51:20 UTC (rev 288974)
+++ trunk/Source/WebCore/workers/shared/SharedWorkerThread.h	2022-02-02 19:56:51 UTC (rev 288975)
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2021 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 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.
- */
-
-#pragma once
-
-#include "WorkerThread.h"
-
-namespace WebCore {
-
-class WorkerObjectProxy;
-
-class SharedWorkerThread : public WorkerThread {
-public:
-    template<typename... Args> static Ref<SharedWorkerThread> create(Args&&... args) { return adoptRef(*new SharedWorkerThread(std::forward<Args>(args)...)); }
-private:
-    SharedWorkerThread(const WorkerParameters&, const ScriptBuffer& sourceCode, WorkerLoaderProxy&, WorkerDebuggerProxy&, WorkerObjectProxy&, WorkerThreadStartMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, JSC::RuntimeFlags);
-
-    Ref<WorkerGlobalScope> createWorkerGlobalScope(const WorkerParameters&, Ref<SecurityOrigin>&&, Ref<SecurityOrigin>&& topOrigin) final;
-    ASCIILiteral threadName() const final { return "WebCore: SharedWorker"_s; }
-
-    String m_name;
-};
-
-} // namespace WebCore

Copied: trunk/Source/WebCore/workers/shared/context/SharedWorkerThread.cpp (from rev 288974, trunk/Source/WebCore/workers/shared/SharedWorkerThread.cpp) (0 => 288975)


--- trunk/Source/WebCore/workers/shared/context/SharedWorkerThread.cpp	                        (rev 0)
+++ trunk/Source/WebCore/workers/shared/context/SharedWorkerThread.cpp	2022-02-02 19:56:51 UTC (rev 288975)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 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.
+ */
+
+#include "config.h"
+#include "SharedWorkerThread.h"
+
+#include "SharedWorkerGlobalScope.h"
+#include "WorkerObjectProxy.h"
+
+namespace WebCore {
+
+SharedWorkerThread::SharedWorkerThread(const WorkerParameters& parameters, const ScriptBuffer& sourceCode, WorkerLoaderProxy& loaderProxy, WorkerDebuggerProxy& debuggerProxy, WorkerObjectProxy& objectProxy, WorkerThreadStartMode startMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy* connectionProxy, SocketProvider* socketProvider, JSC::RuntimeFlags runtimeFlags)
+    : WorkerThread(parameters, sourceCode, loaderProxy, debuggerProxy, objectProxy, startMode, topOrigin, connectionProxy, socketProvider, runtimeFlags)
+    , m_name(parameters.name.isolatedCopy())
+{
+}
+
+Ref<WorkerGlobalScope> SharedWorkerThread::createWorkerGlobalScope(const WorkerParameters& parameters, Ref<SecurityOrigin>&& origin, Ref<SecurityOrigin>&& topOrigin)
+{
+    return SharedWorkerGlobalScope::create(std::exchange(m_name, { }), parameters, WTFMove(origin), *this, WTFMove(topOrigin), idbConnectionProxy(), socketProvider());
+}
+
+} // namespace WebCore

Copied: trunk/Source/WebCore/workers/shared/context/SharedWorkerThread.h (from rev 288974, trunk/Source/WebCore/workers/shared/SharedWorkerThread.h) (0 => 288975)


--- trunk/Source/WebCore/workers/shared/context/SharedWorkerThread.h	                        (rev 0)
+++ trunk/Source/WebCore/workers/shared/context/SharedWorkerThread.h	2022-02-02 19:56:51 UTC (rev 288975)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 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.
+ */
+
+#pragma once
+
+#include "WorkerThread.h"
+
+namespace WebCore {
+
+class WorkerObjectProxy;
+
+class SharedWorkerThread : public WorkerThread {
+public:
+    template<typename... Args> static Ref<SharedWorkerThread> create(Args&&... args) { return adoptRef(*new SharedWorkerThread(std::forward<Args>(args)...)); }
+private:
+    SharedWorkerThread(const WorkerParameters&, const ScriptBuffer& sourceCode, WorkerLoaderProxy&, WorkerDebuggerProxy&, WorkerObjectProxy&, WorkerThreadStartMode, const SecurityOrigin& topOrigin, IDBClient::IDBConnectionProxy*, SocketProvider*, JSC::RuntimeFlags);
+
+    Ref<WorkerGlobalScope> createWorkerGlobalScope(const WorkerParameters&, Ref<SecurityOrigin>&&, Ref<SecurityOrigin>&& topOrigin) final;
+    ASCIILiteral threadName() const final { return "WebCore: SharedWorker"_s; }
+
+    String m_name;
+};
+
+} // namespace WebCore

Copied: trunk/Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.cpp (from rev 288974, trunk/Source/WebCore/workers/shared/SharedWorkerProxy.cpp) (0 => 288975)


--- trunk/Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.cpp	                        (rev 0)
+++ trunk/Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.cpp	2022-02-02 19:56:51 UTC (rev 288975)
@@ -0,0 +1,233 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 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.
+ */
+
+#include "config.h"
+#include "SharedWorkerThreadProxy.h"
+
+#include "CacheStorageProvider.h"
+#include "ErrorEvent.h"
+#include "EventNames.h"
+#include "LibWebRTCProvider.h"
+#include "MessageEvent.h"
+#include "MessagePort.h"
+#include "Page.h"
+#include "RTCDataChannelRemoteHandlerConnection.h"
+#include "SharedWorker.h"
+#include "SharedWorkerGlobalScope.h"
+#include "SharedWorkerThread.h"
+
+namespace WebCore {
+
+SharedWorkerThreadProxy::SharedWorkerThreadProxy(SharedWorker& sharedWorker)
+    : m_sharedWorker(sharedWorker)
+    , m_scriptExecutionContext(sharedWorker.scriptExecutionContext())
+    , m_identifierForInspector(sharedWorker.identifierForInspector())
+{
+}
+
+void SharedWorkerThreadProxy::startWorkerGlobalScope(const URL& scriptURL, const String& name, const String& userAgent, bool isOnline, const ScriptBuffer& scriptBuffer, const ContentSecurityPolicyResponseHeaders& contentSecurityPolicyResponseHeaders, bool shouldBypassMainWorldContentSecurityPolicy, const CrossOriginEmbedderPolicy& crossOriginEmbedderPolicy, MonotonicTime timeOrigin, ReferrerPolicy referrerPolicy, WorkerType workerType, FetchRequestCredentials credentials, JSC::RuntimeFlags runtimeFlags)
+{
+    if (m_askedToTerminate)
+        return;
+
+    auto parameters = WorkerParameters {
+        scriptURL,
+        name,
+        m_identifierForInspector,
+        userAgent,
+        isOnline,
+        contentSecurityPolicyResponseHeaders,
+        shouldBypassMainWorldContentSecurityPolicy,
+        crossOriginEmbedderPolicy,
+        timeOrigin,
+        referrerPolicy,
+        workerType,
+        credentials,
+        m_scriptExecutionContext->settingsValues()
+    };
+
+    if (!m_workerThread) {
+        m_workerThread = SharedWorkerThread::create(parameters, scriptBuffer, *this, *this, *this, WorkerThreadStartMode::Normal, m_scriptExecutionContext->topOrigin(), m_scriptExecutionContext->idbConnectionProxy(), m_scriptExecutionContext->socketProvider(), runtimeFlags);
+        m_workerThread->start();
+    }
+}
+
+void SharedWorkerThreadProxy::terminateWorkerGlobalScope()
+{
+    if (m_askedToTerminate)
+        return;
+
+    m_askedToTerminate = true;
+    if (m_workerThread)
+        m_workerThread->stop(nullptr);
+}
+
+void SharedWorkerThreadProxy::postMessageToWorkerGlobalScope(MessageWithMessagePorts&& message)
+{
+    // FIXME: SharedWorker doesn't have postMessage, so this might not be necessary.
+    postTaskToWorkerGlobalScope([message = WTFMove(message)](auto& scriptContext) mutable {
+        auto& context = downcast<SharedWorkerGlobalScope>(scriptContext);
+        auto ports = MessagePort::entanglePorts(scriptContext, WTFMove(message.transferredPorts));
+        context.dispatchEvent(MessageEvent::create(WTFMove(ports), message.message.releaseNonNull()));
+    });
+}
+
+void SharedWorkerThreadProxy::postTaskToWorkerGlobalScope(Function<void(ScriptExecutionContext&)>&& task)
+{
+    if (m_askedToTerminate)
+        return;
+    m_workerThread->runLoop().postTask(WTFMove(task));
+}
+
+bool SharedWorkerThreadProxy::hasPendingActivity() const
+{
+    return m_hasPendingActivity && !m_askedToTerminate;
+}
+
+void SharedWorkerThreadProxy::workerObjectDestroyed()
+{
+    m_sharedWorker = nullptr;
+    m_scriptExecutionContext->postTask([this] (auto&) {
+        m_mayBeDestroyed = true;
+        if (m_workerThread)
+            terminateWorkerGlobalScope();
+        else
+            workerGlobalScopeDestroyedInternal();
+    });
+}
+
+void SharedWorkerThreadProxy::notifyNetworkStateChange(bool isOnline)
+{
+    if (m_askedToTerminate)
+        return;
+
+    if (!m_workerThread)
+        return;
+
+    m_workerThread->runLoop().postTask([isOnline] (ScriptExecutionContext& context) {
+        auto& globalScope = downcast<WorkerGlobalScope>(context);
+        globalScope.setIsOnline(isOnline);
+        globalScope.dispatchEvent(Event::create(isOnline ? eventNames().onlineEvent : eventNames().offlineEvent, Event::CanBubble::No, Event::IsCancelable::No));
+    });
+}
+
+void SharedWorkerThreadProxy::suspendForBackForwardCache()
+{
+
+}
+
+void SharedWorkerThreadProxy::resumeForBackForwardCache()
+{
+
+}
+
+void SharedWorkerThreadProxy::postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL)
+{
+    m_scriptExecutionContext->postTask([this, errorMessage = errorMessage.isolatedCopy(), sourceURL = sourceURL.isolatedCopy(), lineNumber, columnNumber] (ScriptExecutionContext&) {
+        if (!m_sharedWorker)
+            return;
+
+        // We don't bother checking the askedToTerminate() flag here, because exceptions should *always* be reported even if the thread is terminated.
+        // This is intentionally different than the behavior in MessageWorkerTask, because terminated workers no longer deliver messages (section 4.6 of the WebWorker spec), but they do report exceptions.
+        ActiveDOMObject::queueTaskToDispatchEvent(*m_sharedWorker, TaskSource::DOMManipulation, ErrorEvent::create(errorMessage, sourceURL, lineNumber, columnNumber, { }));
+    });
+}
+
+void SharedWorkerThreadProxy::workerGlobalScopeDestroyed()
+{
+    m_scriptExecutionContext->postTask([this] (ScriptExecutionContext&) {
+        workerGlobalScopeDestroyedInternal();
+    });
+}
+
+void SharedWorkerThreadProxy::postMessageToWorkerObject(MessageWithMessagePorts&&)
+{
+
+}
+
+void SharedWorkerThreadProxy::confirmMessageFromWorkerObject(bool)
+{
+}
+
+void SharedWorkerThreadProxy::reportPendingActivity(bool hasPendingActivity)
+{
+    m_scriptExecutionContext->postTask([this, hasPendingActivity] (ScriptExecutionContext&) {
+        m_hasPendingActivity = hasPendingActivity;
+    });
+}
+
+RefPtr<CacheStorageConnection> SharedWorkerThreadProxy::createCacheStorageConnection()
+{
+    ASSERT(isMainThread());
+    auto& document = downcast<Document>(*m_scriptExecutionContext);
+    return document.page()->cacheStorageProvider().createCacheStorageConnection();
+}
+
+RefPtr<RTCDataChannelRemoteHandlerConnection> SharedWorkerThreadProxy::createRTCDataChannelRemoteHandlerConnection()
+{
+    ASSERT(isMainThread());
+    auto& document = downcast<Document>(*m_scriptExecutionContext);
+    if (!document.page())
+        return nullptr;
+    return document.page()->libWebRTCProvider().createRTCDataChannelRemoteHandlerConnection();
+}
+
+void SharedWorkerThreadProxy::postTaskToLoader(ScriptExecutionContext::Task&& task)
+{
+    m_scriptExecutionContext->postTask(WTFMove(task));
+}
+
+bool SharedWorkerThreadProxy::postTaskForModeToWorkerOrWorkletGlobalScope(ScriptExecutionContext::Task&& task, const String& mode)
+{
+    if (m_askedToTerminate)
+        return false;
+
+    m_workerThread->runLoop().postTaskForMode(WTFMove(task), mode);
+    return true;
+}
+
+void SharedWorkerThreadProxy::postMessageToDebugger(const String&)
+{
+
+}
+
+void SharedWorkerThreadProxy::setResourceCachingDisabledByWebInspector(bool)
+{
+
+}
+
+void SharedWorkerThreadProxy::workerGlobalScopeDestroyedInternal()
+{
+    // This is always the last task to be performed, so the proxy is not needed for communication
+    // in either side any more. However, the Worker object may still exist, and it assumes that the proxy exists, too.
+    m_askedToTerminate = true;
+    m_workerThread = nullptr;
+
+    // This balances the original ref in construction.
+    if (m_mayBeDestroyed)
+        deref();
+}
+
+} // namespace WebCore

Copied: trunk/Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.h (from rev 288974, trunk/Source/WebCore/workers/shared/SharedWorkerProxy.h) (0 => 288975)


--- trunk/Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.h	                        (rev 0)
+++ trunk/Source/WebCore/workers/shared/context/SharedWorkerThreadProxy.h	2022-02-02 19:56:51 UTC (rev 288975)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2021 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    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 INC. AND ITS CONTRIBUTORS ``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 INC. OR ITS 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 PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 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.
+ */
+
+#pragma once
+
+#include "WorkerDebuggerProxy.h"
+#include "WorkerGlobalScopeProxy.h"
+#include "WorkerLoaderProxy.h"
+#include "WorkerObjectProxy.h"
+#include "WorkerOptions.h"
+#include <wtf/WeakPtr.h>
+
+namespace WebCore {
+
+class SharedWorker;
+class SharedWorkerThread;
+
+class SharedWorkerThreadProxy final : public ThreadSafeRefCounted<SharedWorkerThreadProxy>, public WorkerGlobalScopeProxy, public WorkerObjectProxy, public WorkerLoaderProxy, public WorkerDebuggerProxy {
+public:
+    template<typename... Args> static SharedWorkerThreadProxy& create(Args&&... args) { return *new SharedWorkerThreadProxy(std::forward<Args>(args)...); }
+
+    SharedWorkerThread* thread() { return m_workerThread.get(); }
+
+    void startWorkerGlobalScope(const URL& scriptURL, const String& name, const String& userAgent, bool isOnline, const ScriptBuffer& sourceCode, const ContentSecurityPolicyResponseHeaders&, bool shouldBypassMainWorldContentSecurityPolicy, const CrossOriginEmbedderPolicy&, MonotonicTime timeOrigin, ReferrerPolicy, WorkerType, FetchRequestCredentials, JSC::RuntimeFlags) final;
+    void workerObjectDestroyed() final;
+    bool hasPendingActivity() const final;
+    void terminateWorkerGlobalScope() final;
+
+private:
+    explicit SharedWorkerThreadProxy(SharedWorker&);
+
+    void workerGlobalScopeDestroyedInternal();
+
+    void postMessageToWorkerGlobalScope(MessageWithMessagePorts&&) final;
+    void postTaskToWorkerGlobalScope(Function<void(ScriptExecutionContext&)>&&) final;
+    void notifyNetworkStateChange(bool isOnline) final;
+    void suspendForBackForwardCache() final;
+    void resumeForBackForwardCache() final;
+    void postExceptionToWorkerObject(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL) final;
+    void workerGlobalScopeDestroyed() final;
+    void postMessageToWorkerObject(MessageWithMessagePorts&&) final;
+    void confirmMessageFromWorkerObject(bool hasPendingActivity) final;
+    void reportPendingActivity(bool hasPendingActivity) final;
+    RefPtr<CacheStorageConnection> createCacheStorageConnection() final;
+    RefPtr<RTCDataChannelRemoteHandlerConnection> createRTCDataChannelRemoteHandlerConnection() final;
+    void postTaskToLoader(ScriptExecutionContext::Task&&) final;
+    bool postTaskForModeToWorkerOrWorkletGlobalScope(ScriptExecutionContext::Task&&, const String& mode) final;
+    void postMessageToDebugger(const String&) final;
+    void setResourceCachingDisabledByWebInspector(bool) final;
+
+    WeakPtr<SharedWorker> m_sharedWorker;
+    RefPtr<SharedWorkerThread> m_workerThread;
+    const RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
+    const String m_identifierForInspector;
+    bool m_askedToTerminate { false };
+    bool m_hasPendingActivity { false };
+    bool m_mayBeDestroyed { false };
+};
+
+} // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to