Diff
Modified: branches/safari-612-branch/Source/WebCore/ChangeLog (281897 => 281898)
--- branches/safari-612-branch/Source/WebCore/ChangeLog 2021-09-02 01:05:03 UTC (rev 281897)
+++ branches/safari-612-branch/Source/WebCore/ChangeLog 2021-09-02 01:05:06 UTC (rev 281898)
@@ -1,5 +1,66 @@
2021-09-01 Russell Epstein <[email protected]>
+ Cherry-pick r281787. rdar://problem/82651372
+
+ Web Inspector: Refactor `WorkerInspectorAgent` to use weak pointers for `WorkerInspectorProxy`s
+ https://bugs.webkit.org/show_bug.cgi?id=229632
+
+ Reviewed by Chris Dumez.
+
+ Covered by existing tests in LayoutTests/inspector/worker/*
+
+ Make `WorkerInspectorProxy` reference counted, and use `WeakPtr`s to them in `InspectorWorkerAgent`.
+
+ * inspector/agents/InspectorWorkerAgent.cpp:
+ (WebCore::InspectorWorkerAgent::initialized):
+ (WebCore::InspectorWorkerAgent::sendMessageToWorker):
+ (WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage):
+ (WebCore::InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies):
+ (WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy):
+ * inspector/agents/InspectorWorkerAgent.h:
+ * workers/WorkerInspectorProxy.cpp:
+ (WebCore::WorkerInspectorProxy::allWorkerInspectorProxies):
+ (WebCore::WorkerInspectorProxy::workerStarted):
+ (WebCore::WorkerInspectorProxy::workerTerminated):
+ * workers/WorkerInspectorProxy.h:
+ (WebCore::WorkerInspectorProxy::create):
+ * workers/WorkerMessagingProxy.cpp:
+ (WebCore::WorkerMessagingProxy::WorkerMessagingProxy):
+ * workers/WorkerMessagingProxy.h:
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281787 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2021-08-30 Patrick Angle <[email protected]>
+
+ Web Inspector: Refactor `WorkerInspectorAgent` to use weak pointers for `WorkerInspectorProxy`s
+ https://bugs.webkit.org/show_bug.cgi?id=229632
+
+ Reviewed by Chris Dumez.
+
+ Covered by existing tests in LayoutTests/inspector/worker/*
+
+ Make `WorkerInspectorProxy` reference counted, and use `WeakPtr`s to them in `InspectorWorkerAgent`.
+
+ * inspector/agents/InspectorWorkerAgent.cpp:
+ (WebCore::InspectorWorkerAgent::initialized):
+ (WebCore::InspectorWorkerAgent::sendMessageToWorker):
+ (WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage):
+ (WebCore::InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies):
+ (WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy):
+ * inspector/agents/InspectorWorkerAgent.h:
+ * workers/WorkerInspectorProxy.cpp:
+ (WebCore::WorkerInspectorProxy::allWorkerInspectorProxies):
+ (WebCore::WorkerInspectorProxy::workerStarted):
+ (WebCore::WorkerInspectorProxy::workerTerminated):
+ * workers/WorkerInspectorProxy.h:
+ (WebCore::WorkerInspectorProxy::create):
+ * workers/WorkerMessagingProxy.cpp:
+ (WebCore::WorkerMessagingProxy::WorkerMessagingProxy):
+ * workers/WorkerMessagingProxy.h:
+
+2021-09-01 Russell Epstein <[email protected]>
+
Cherry-pick r281700. rdar://problem/82650954
REGRESSION (r276882): Shadow trees may use stale style information after inline stylesheet is mutated via CSSOM
Modified: branches/safari-612-branch/Source/WebCore/inspector/agents/InspectorWorkerAgent.cpp (281897 => 281898)
--- branches/safari-612-branch/Source/WebCore/inspector/agents/InspectorWorkerAgent.cpp 2021-09-02 01:05:03 UTC (rev 281897)
+++ branches/safari-612-branch/Source/WebCore/inspector/agents/InspectorWorkerAgent.cpp 2021-09-02 01:05:06 UTC (rev 281898)
@@ -28,6 +28,8 @@
#include "Document.h"
#include "InstrumentingAgents.h"
+#include <wtf/Ref.h>
+#include <wtf/RefPtr.h>
namespace WebCore {
@@ -82,7 +84,7 @@
Protocol::ErrorStringOr<void> InspectorWorkerAgent::initialized(const String& workerId)
{
- WorkerInspectorProxy* proxy = m_connectedProxies.get(workerId);
+ RefPtr proxy = m_connectedProxies.get(workerId).get();
if (!proxy)
return makeUnexpected("Missing worker for given workerId"_s);
@@ -96,7 +98,7 @@
if (!m_enabled)
return makeUnexpected("Worker domain must be enabled"_s);
- WorkerInspectorProxy* proxy = m_connectedProxies.get(workerId);
+ RefPtr proxy = m_connectedProxies.get(workerId).get();
if (!proxy)
return makeUnexpected("Missing worker for given workerId"_s);
@@ -135,22 +137,27 @@
{
ASSERT(m_connectedProxies.isEmpty());
- for (auto* proxy : WorkerInspectorProxy::allWorkerInspectorProxies()) {
+ for (Ref proxy : WorkerInspectorProxy::allWorkerInspectorProxies()) {
if (!is<Document>(proxy->scriptExecutionContext()))
continue;
- Document& document = downcast<Document>(*proxy->scriptExecutionContext());
+ auto& document = downcast<Document>(*proxy->scriptExecutionContext());
if (document.page() != &m_page)
continue;
- connectToWorkerInspectorProxy(*proxy);
+ connectToWorkerInspectorProxy(proxy);
}
}
void InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies()
{
- for (auto* proxy : copyToVector(m_connectedProxies.values()))
+ for (auto& proxyWeakPtr : copyToVector(m_connectedProxies.values())) {
+ RefPtr proxy = proxyWeakPtr.get();
+ if (!proxy)
+ continue;
+
proxy->disconnectFromWorkerInspectorController();
+ }
m_connectedProxies.clear();
}
@@ -159,7 +166,7 @@
{
proxy.connectToWorkerInspectorController(*this);
- m_connectedProxies.set(proxy.identifier(), &proxy);
+ m_connectedProxies.set(proxy.identifier(), makeWeakPtr(proxy));
m_frontendDispatcher->workerCreated(proxy.identifier(), proxy.url().string(), proxy.name());
}
Modified: branches/safari-612-branch/Source/WebCore/inspector/agents/InspectorWorkerAgent.h (281897 => 281898)
--- branches/safari-612-branch/Source/WebCore/inspector/agents/InspectorWorkerAgent.h 2021-09-02 01:05:03 UTC (rev 281897)
+++ branches/safari-612-branch/Source/WebCore/inspector/agents/InspectorWorkerAgent.h 2021-09-02 01:05:06 UTC (rev 281898)
@@ -30,6 +30,7 @@
#include <_javascript_Core/InspectorBackendDispatchers.h>
#include <_javascript_Core/InspectorFrontendDispatchers.h>
#include <wtf/HashMap.h>
+#include <wtf/WeakPtr.h>
namespace WebCore {
@@ -70,7 +71,7 @@
RefPtr<Inspector::WorkerBackendDispatcher> m_backendDispatcher;
Page& m_page;
- HashMap<String, WorkerInspectorProxy*> m_connectedProxies;
+ HashMap<String, WeakPtr<WorkerInspectorProxy>> m_connectedProxies;
bool m_enabled { false };
};
Modified: branches/safari-612-branch/Source/WebCore/workers/WorkerInspectorProxy.cpp (281897 => 281898)
--- branches/safari-612-branch/Source/WebCore/workers/WorkerInspectorProxy.cpp 2021-09-02 01:05:03 UTC (rev 281897)
+++ branches/safari-612-branch/Source/WebCore/workers/WorkerInspectorProxy.cpp 2021-09-02 01:05:06 UTC (rev 281898)
@@ -39,9 +39,9 @@
namespace WebCore {
using namespace Inspector;
-HashSet<WorkerInspectorProxy*>& WorkerInspectorProxy::allWorkerInspectorProxies()
+WeakHashSet<WorkerInspectorProxy>& WorkerInspectorProxy::allWorkerInspectorProxies()
{
- static NeverDestroyed<HashSet<WorkerInspectorProxy*>> proxies;
+ static NeverDestroyed<WeakHashSet<WorkerInspectorProxy>> proxies;
return proxies;
}
@@ -71,7 +71,7 @@
m_url = url;
m_name = name;
- allWorkerInspectorProxies().add(this);
+ allWorkerInspectorProxies().add(*this);
InspectorInstrumentation::workerStarted(*this);
}
@@ -83,7 +83,7 @@
InspectorInstrumentation::workerTerminated(*this);
- allWorkerInspectorProxies().remove(this);
+ allWorkerInspectorProxies().remove(*this);
m_scriptExecutionContext = nullptr;
m_workerThread = nullptr;
Modified: branches/safari-612-branch/Source/WebCore/workers/WorkerInspectorProxy.h (281897 => 281898)
--- branches/safari-612-branch/Source/WebCore/workers/WorkerInspectorProxy.h 2021-09-02 01:05:03 UTC (rev 281897)
+++ branches/safari-612-branch/Source/WebCore/workers/WorkerInspectorProxy.h 2021-09-02 01:05:06 UTC (rev 281898)
@@ -25,9 +25,10 @@
#pragma once
-#include <wtf/HashSet.h>
+#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/URL.h>
+#include <wtf/WeakHashSet.h>
#include <wtf/text/WTFString.h>
// All of these methods should be called on the Main Thread.
@@ -40,11 +41,15 @@
enum class WorkerThreadStartMode;
-class WorkerInspectorProxy {
+class WorkerInspectorProxy : public RefCounted<WorkerInspectorProxy>, public CanMakeWeakPtr<WorkerInspectorProxy> {
WTF_MAKE_NONCOPYABLE(WorkerInspectorProxy);
WTF_MAKE_FAST_ALLOCATED;
public:
- WorkerInspectorProxy(const String& identifier);
+ static Ref<WorkerInspectorProxy> create(const String& identifier)
+ {
+ return adoptRef(*new WorkerInspectorProxy(identifier));
+ }
+
~WorkerInspectorProxy();
// A Worker's inspector messages come in and go out through the Page's WorkerAgent.
@@ -54,7 +59,7 @@
virtual void sendMessageFromWorkerToFrontend(WorkerInspectorProxy&, const String&) = 0;
};
- static HashSet<WorkerInspectorProxy*>& allWorkerInspectorProxies();
+ static WeakHashSet<WorkerInspectorProxy>& allWorkerInspectorProxies();
const URL& url() const { return m_url; }
const String& name() const { return m_name; }
@@ -72,6 +77,8 @@
void sendMessageFromWorkerToFrontend(const String&);
private:
+ explicit WorkerInspectorProxy(const String& identifier);
+
RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
RefPtr<WorkerThread> m_workerThread;
String m_identifier;
Modified: branches/safari-612-branch/Source/WebCore/workers/WorkerMessagingProxy.cpp (281897 => 281898)
--- branches/safari-612-branch/Source/WebCore/workers/WorkerMessagingProxy.cpp 2021-09-02 01:05:03 UTC (rev 281897)
+++ branches/safari-612-branch/Source/WebCore/workers/WorkerMessagingProxy.cpp 2021-09-02 01:05:06 UTC (rev 281898)
@@ -58,7 +58,7 @@
WorkerMessagingProxy::WorkerMessagingProxy(Worker& workerObject)
: m_scriptExecutionContext(workerObject.scriptExecutionContext())
- , m_inspectorProxy(makeUnique<WorkerInspectorProxy>(workerObject.identifier()))
+ , m_inspectorProxy(WorkerInspectorProxy::create(workerObject.identifier()))
, m_workerObject(&workerObject)
{
ASSERT((is<Document>(*m_scriptExecutionContext) && isMainThread())
Modified: branches/safari-612-branch/Source/WebCore/workers/WorkerMessagingProxy.h (281897 => 281898)
--- branches/safari-612-branch/Source/WebCore/workers/WorkerMessagingProxy.h 2021-09-02 01:05:03 UTC (rev 281897)
+++ branches/safari-612-branch/Source/WebCore/workers/WorkerMessagingProxy.h 2021-09-02 01:05:06 UTC (rev 281898)
@@ -93,7 +93,7 @@
Worker* workerObject() const { return m_workerObject; }
RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
- std::unique_ptr<WorkerInspectorProxy> m_inspectorProxy;
+ RefPtr<WorkerInspectorProxy> m_inspectorProxy;
Worker* m_workerObject;
bool m_mayBeDestroyed { false };
RefPtr<DedicatedWorkerThread> m_workerThread;