Title: [295189] branches/safari-613-branch/Source/WebCore
- Revision
- 295189
- Author
- alanc...@apple.com
- Date
- 2022-06-02 23:45:44 -0700 (Thu, 02 Jun 2022)
Log Message
Cherry-pick cb6ddf5edf6c. rdar://problem/92853663
Create a stopped CacheStorageConnection for workers in case of detached documents
https://bugs.webkit.org/show_bug.cgi?id=240224
<rdar://problem/92853663>
Reviewed by Chris Dumez.
A worker might not always have a main thread connection as its document may be detached.
In that case, we now create a StoppedCacheStorageConnection that will always return Error::Stopped to any callback.
Covered by existing tests.
* Modules/cache/WorkerCacheStorageConnection.cpp:
(WebCore::StoppedCacheStorageConnection::create):
(WebCore::createMainThreadConnection):
(WebCore::WorkerCacheStorageConnection::WorkerCacheStorageConnection):
(WebCore::WorkerCacheStorageConnection::~WorkerCacheStorageConnection):
(WebCore::WorkerCacheStorageConnection::create): Deleted.
* Modules/cache/WorkerCacheStorageConnection.h:
Canonical link: https://commits.webkit.org/250442@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@294006 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Modified Paths
Diff
Modified: branches/safari-613-branch/Source/WebCore/ChangeLog (295188 => 295189)
--- branches/safari-613-branch/Source/WebCore/ChangeLog 2022-06-03 06:45:41 UTC (rev 295188)
+++ branches/safari-613-branch/Source/WebCore/ChangeLog 2022-06-03 06:45:44 UTC (rev 295189)
@@ -1,3 +1,24 @@
+2022-05-10 Youenn Fablet <you...@apple.com>
+
+ Create a stopped CacheStorageConnection for workers in case of detached documents
+ https://bugs.webkit.org/show_bug.cgi?id=240224
+ <rdar://problem/92853663>
+
+ Reviewed by Chris Dumez.
+
+ A worker might not always have a main thread connection as its document may be detached.
+ In that case, we now create a StoppedCacheStorageConnection that will always return Error::Stopped to any callback.
+
+ Covered by existing tests.
+
+ * Modules/cache/WorkerCacheStorageConnection.cpp:
+ (WebCore::StoppedCacheStorageConnection::create):
+ (WebCore::createMainThreadConnection):
+ (WebCore::WorkerCacheStorageConnection::WorkerCacheStorageConnection):
+ (WebCore::WorkerCacheStorageConnection::~WorkerCacheStorageConnection):
+ (WebCore::WorkerCacheStorageConnection::create): Deleted.
+ * Modules/cache/WorkerCacheStorageConnection.h:
+
2022-05-13 Brent Fulgham <bfulg...@apple.com>
REGRESSION (r281791): [iOS] WKWebView cannot load local .log file
Modified: branches/safari-613-branch/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp (295188 => 295189)
--- branches/safari-613-branch/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp 2022-06-03 06:45:41 UTC (rev 295188)
+++ branches/safari-613-branch/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.cpp 2022-06-03 06:45:44 UTC (rev 295189)
@@ -31,6 +31,7 @@
#include "CacheStorageProvider.h"
#include "ClientOrigin.h"
#include "Document.h"
+#include "Logging.h"
#include "Page.h"
#include "WorkerGlobalScope.h"
#include "WorkerLoaderProxy.h"
@@ -113,25 +114,43 @@
return recordsFromRecordsData(WTFMove(recordsData.value()));
}
-Ref<WorkerCacheStorageConnection> WorkerCacheStorageConnection::create(WorkerGlobalScope& scope)
+class StoppedCacheStorageConnection final : public CacheStorageConnection {
+public:
+ static Ref<CacheStorageConnection> create() { return adoptRef(*new StoppedCacheStorageConnection); }
+
+private:
+ void open(const ClientOrigin&, const String&, DOMCacheEngine::CacheIdentifierCallback&& callback) final { callback(makeUnexpected(DOMCacheEngine::Error::Stopped)); }
+ void remove(uint64_t, DOMCacheEngine::CacheIdentifierCallback&& callback) final { callback(makeUnexpected(DOMCacheEngine::Error::Stopped)); }
+ void retrieveCaches(const ClientOrigin&, uint64_t, DOMCacheEngine::CacheInfosCallback&& callback) final { callback(makeUnexpected(DOMCacheEngine::Error::Stopped)); }
+ void retrieveRecords(uint64_t, RetrieveRecordsOptions&&, DOMCacheEngine::RecordsCallback&& callback) final { callback(makeUnexpected(DOMCacheEngine::Error::Stopped)); }
+ void batchDeleteOperation(uint64_t, const ResourceRequest&, CacheQueryOptions&&, DOMCacheEngine::RecordIdentifiersCallback&& callback) final { callback(makeUnexpected(DOMCacheEngine::Error::Stopped)); }
+ void batchPutOperation(uint64_t, Vector<DOMCacheEngine::Record>&&, DOMCacheEngine::RecordIdentifiersCallback&& callback) final { callback(makeUnexpected(DOMCacheEngine::Error::Stopped)); }
+ void reference(uint64_t) final { }
+ void dereference(uint64_t) final { }
+};
+
+static Ref<CacheStorageConnection> createMainThreadConnection(WorkerGlobalScope& scope)
{
- auto connection = adoptRef(*new WorkerCacheStorageConnection(scope));
- callOnMainThreadAndWait([workerThread = Ref { scope.thread() }, connection = connection.ptr()]() mutable {
- connection->m_mainThreadConnection = workerThread->workerLoaderProxy().createCacheStorageConnection();
+ RefPtr<CacheStorageConnection> mainThreadConnection;
+ callOnMainThreadAndWait([workerThread = Ref { scope.thread() }, &mainThreadConnection]() mutable {
+ mainThreadConnection = workerThread->workerLoaderProxy().createCacheStorageConnection();
+ if (!mainThreadConnection) {
+ RELEASE_LOG_INFO(ServiceWorker, "Creating stopped WorkerCacheStorageConnection");
+ mainThreadConnection = StoppedCacheStorageConnection::create();
+ }
});
- ASSERT(connection->m_mainThreadConnection);
- return connection;
+ return mainThreadConnection.releaseNonNull();
}
WorkerCacheStorageConnection::WorkerCacheStorageConnection(WorkerGlobalScope& scope)
: m_scope(scope)
+ , m_mainThreadConnection(createMainThreadConnection(scope))
{
}
WorkerCacheStorageConnection::~WorkerCacheStorageConnection()
{
- if (m_mainThreadConnection)
- callOnMainThread([mainThreadConnection = WTFMove(m_mainThreadConnection)]() mutable { });
+ callOnMainThread([mainThreadConnection = WTFMove(m_mainThreadConnection)]() mutable { });
}
void WorkerCacheStorageConnection::open(const ClientOrigin& origin, const String& cacheName, CacheIdentifierCallback&& callback)
Modified: branches/safari-613-branch/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.h (295188 => 295189)
--- branches/safari-613-branch/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.h 2022-06-03 06:45:41 UTC (rev 295188)
+++ branches/safari-613-branch/Source/WebCore/Modules/cache/WorkerCacheStorageConnection.h 2022-06-03 06:45:44 UTC (rev 295189)
@@ -37,7 +37,7 @@
class WorkerCacheStorageConnection final : public CacheStorageConnection {
public:
- static Ref<WorkerCacheStorageConnection> create(WorkerGlobalScope&);
+ static Ref<WorkerCacheStorageConnection> create(WorkerGlobalScope& scope) { return adoptRef(*new WorkerCacheStorageConnection(scope)); }
~WorkerCacheStorageConnection();
void clearPendingRequests();
@@ -72,7 +72,7 @@
WorkerGlobalScope& m_scope;
- RefPtr<CacheStorageConnection> m_mainThreadConnection;
+ Ref<CacheStorageConnection> m_mainThreadConnection;
HashMap<uint64_t, DOMCacheEngine::CacheIdentifierCallback> m_openAndRemoveCachePendingRequests;
HashMap<uint64_t, DOMCacheEngine::CacheInfosCallback> m_retrieveCachesPendingRequests;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes