Web Inspector: Worker: should use the name of the worker if it exists
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 May 2020 19:51:30 +0000 (19:51 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 May 2020 19:51:30 +0000 (19:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=211244

Reviewed by Brian Burg.

Source/JavaScriptCore:

* inspector/protocol/Worker.json:
Include the `name` in `Worker.workerCreated`.

Source/WebCore:

Test: inspector/worker/runtime-basic.html

Pass the `name` from the `WorkerOptions` given to the `Worker` when it's constructed to Web
Inspector so it can be used in the frontend UI.

Drive-by: replace lots of pointers with references.
* workers/WorkerMessagingProxy.cpp:
(WebCore::WorkerMessagingProxy::startWorkerGlobalScope):

* workers/WorkerInspectorProxy.h:
(WebCore::WorkerInspectorProxy::name const): Added.
* workers/WorkerInspectorProxy.cpp:
(WebCore::WorkerInspectorProxy::workerStarted):
(WebCore::WorkerInspectorProxy::workerTerminated):
(WebCore::WorkerInspectorProxy::connectToWorkerInspectorController):
(WebCore::WorkerInspectorProxy::sendMessageFromWorkerToFrontend):

* inspector/InspectorInstrumentation.h:
(WebCore::InspectorInstrumentation::workerStarted):
(WebCore::InspectorInstrumentation::workerTerminated):
* inspector/InspectorInstrumentation.cpp:
(WebCore::InspectorInstrumentation::workerStartedImpl):
(WebCore::InspectorInstrumentation::workerTerminatedImpl):

* inspector/agents/InspectorWorkerAgent.h:
* inspector/agents/InspectorWorkerAgent.cpp:
(WebCore::InspectorWorkerAgent::sendMessageFromWorkerToFrontend):
(WebCore::InspectorWorkerAgent::workerStarted):
(WebCore::InspectorWorkerAgent::workerTerminated):
(WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage):
(WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy):
(WebCore::InspectorWorkerAgent::disconnectFromWorkerInspectorProxy):

Source/WebInspectorUI:

* UserInterface/Protocol/WorkerObserver.js:
(WI.WorkerObserver.prototype.workerCreated):
* UserInterface/Controllers/WorkerManager.js:
(WI.WorkerManager.prototype.workerCreated):
* UserInterface/Protocol/WorkerTarget.js:
(WI.WorkerTarget):
(WI.WorkerTarget.prototype.get customName): Added.
(WI.WorkerTarget.prototype.get displayName):
(WI.WorkerTarget.prototype.get displayURL): Added.
Use the `name` from the `WorkerOptions` given to the `Worker` when it's constructed as the
`displayName` of the `WI.WorkerTarget` if able. Also exposed via `get customName`.

* UserInterface/Views/ScriptTreeElement.js:
(WI.ScriptTreeElement):
* UserInterface/Views/WorkerTreeElement.js:
(WI.WorkerTreeElement):
Accept an `options` optional object that can be used to override the `mainTitle`.

LayoutTests:

* inspector/worker/runtime-basic.html:
* inspector/worker/runtime-basic-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261104 268f45cc-cd09-0410-ab3c-d52691b4dbfc

19 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/worker/runtime-basic-expected.txt
LayoutTests/inspector/worker/runtime-basic.html
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/protocol/Worker.json
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorInstrumentation.cpp
Source/WebCore/inspector/InspectorInstrumentation.h
Source/WebCore/inspector/agents/InspectorWorkerAgent.cpp
Source/WebCore/inspector/agents/InspectorWorkerAgent.h
Source/WebCore/workers/WorkerInspectorProxy.cpp
Source/WebCore/workers/WorkerInspectorProxy.h
Source/WebCore/workers/WorkerMessagingProxy.cpp
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Controllers/WorkerManager.js
Source/WebInspectorUI/UserInterface/Protocol/WorkerObserver.js
Source/WebInspectorUI/UserInterface/Protocol/WorkerTarget.js
Source/WebInspectorUI/UserInterface/Views/ScriptTreeElement.js
Source/WebInspectorUI/UserInterface/Views/WorkerTreeElement.js

index 04e4d6a..16ff082 100644 (file)
@@ -1,5 +1,15 @@
 2020-05-04  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Worker: should use the name of the worker if it exists
+        https://bugs.webkit.org/show_bug.cgi?id=211244
+
+        Reviewed by Brian Burg.
+
+        * inspector/worker/runtime-basic.html:
+        * inspector/worker/runtime-basic-expected.txt:
+
+2020-05-04  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: provide a way for inspector to turn on/off ITP debug mode and AdClickAttribution debug mode
         https://bugs.webkit.org/show_bug.cgi?id=209763
 
index 1f14458..d42793b 100644 (file)
@@ -6,11 +6,11 @@ Test for RuntimeAgent in a Worker.
 Target - Page - passphrase - page-passphrase
 
 -- Running test case: Worker.Runtime.evaluate
-Target - worker-1.js - passphrase - worker-passphrase
+Target - TestWorker - passphrase - worker-passphrase
 
 -- Running test case: Main.Runtime.RemoteObjectAndPropertyDescriptor.
 Target - Page - location and href - Location: inspector/worker/runtime-basic.html
 
 -- Running test case: Worker.Runtime.RemoteObjectAndPropertyDescriptor.
-Target - worker-1.js - location and href - WorkerLocation: inspector/worker/resources/worker-1.js
+Target - TestWorker - location and href - WorkerLocation: inspector/worker/resources/worker-1.js
 
index 3ffaf3e..a9c61ba 100644 (file)
@@ -4,7 +4,7 @@
 <script src="../../http/tests/inspector/resources/inspector-test.js"></script>
 <script>
 passphrase = "page-passphrase";
-let worker = new Worker("resources/worker-1.js");
+let worker = new Worker("resources/worker-1.js", {name: "TestWorker"});
 
 function test()
 {
index 6fbdae7..ebfb56a 100644 (file)
@@ -1,5 +1,15 @@
 2020-05-04  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Worker: should use the name of the worker if it exists
+        https://bugs.webkit.org/show_bug.cgi?id=211244
+
+        Reviewed by Brian Burg.
+
+        * inspector/protocol/Worker.json:
+        Include the `name` in `Worker.workerCreated`.
+
+2020-05-04  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: provide a way for inspector to turn on/off ITP debug mode and AdClickAttribution debug mode
         https://bugs.webkit.org/show_bug.cgi?id=209763
 
index 9e2bee9..6386124 100644 (file)
@@ -32,7 +32,8 @@
             "name": "workerCreated",
             "parameters": [
                 { "name": "workerId", "type": "string" },
-                { "name": "url", "type": "string" }
+                { "name": "url", "type": "string" },
+                { "name": "name", "type": "string" }
             ]
         },
         {
index 4060398..cb17ac5 100644 (file)
@@ -1,5 +1,46 @@
 2020-05-04  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Worker: should use the name of the worker if it exists
+        https://bugs.webkit.org/show_bug.cgi?id=211244
+
+        Reviewed by Brian Burg.
+
+        Test: inspector/worker/runtime-basic.html
+
+        Pass the `name` from the `WorkerOptions` given to the `Worker` when it's constructed to Web
+        Inspector so it can be used in the frontend UI.
+
+        Drive-by: replace lots of pointers with references.
+
+        * workers/WorkerMessagingProxy.cpp:
+        (WebCore::WorkerMessagingProxy::startWorkerGlobalScope):
+
+        * workers/WorkerInspectorProxy.h:
+        (WebCore::WorkerInspectorProxy::name const): Added.
+        * workers/WorkerInspectorProxy.cpp:
+        (WebCore::WorkerInspectorProxy::workerStarted):
+        (WebCore::WorkerInspectorProxy::workerTerminated):
+        (WebCore::WorkerInspectorProxy::connectToWorkerInspectorController):
+        (WebCore::WorkerInspectorProxy::sendMessageFromWorkerToFrontend):
+
+        * inspector/InspectorInstrumentation.h:
+        (WebCore::InspectorInstrumentation::workerStarted):
+        (WebCore::InspectorInstrumentation::workerTerminated):
+        * inspector/InspectorInstrumentation.cpp:
+        (WebCore::InspectorInstrumentation::workerStartedImpl):
+        (WebCore::InspectorInstrumentation::workerTerminatedImpl):
+
+        * inspector/agents/InspectorWorkerAgent.h:
+        * inspector/agents/InspectorWorkerAgent.cpp:
+        (WebCore::InspectorWorkerAgent::sendMessageFromWorkerToFrontend):
+        (WebCore::InspectorWorkerAgent::workerStarted):
+        (WebCore::InspectorWorkerAgent::workerTerminated):
+        (WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage):
+        (WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy):
+        (WebCore::InspectorWorkerAgent::disconnectFromWorkerInspectorProxy):
+
+2020-05-04  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: provide a way for inspector to turn on/off ITP debug mode and AdClickAttribution debug mode
         https://bugs.webkit.org/show_bug.cgi?id=209763
 
index 7a386a7..0c442ee 100644 (file)
@@ -979,13 +979,13 @@ bool InspectorInstrumentation::shouldWaitForDebuggerOnStartImpl(InstrumentingAge
     return false;
 }
 
-void InspectorInstrumentation::workerStartedImpl(InstrumentingAgents& instrumentingAgents, WorkerInspectorProxy* proxy, const URL& url)
+void InspectorInstrumentation::workerStartedImpl(InstrumentingAgents& instrumentingAgents, WorkerInspectorProxy& proxy)
 {
     if (InspectorWorkerAgent* workerAgent = instrumentingAgents.inspectorWorkerAgent())
-        workerAgent->workerStarted(proxy, url);
+        workerAgent->workerStarted(proxy);
 }
 
-void InspectorInstrumentation::workerTerminatedImpl(InstrumentingAgents& instrumentingAgents, WorkerInspectorProxy* proxy)
+void InspectorInstrumentation::workerTerminatedImpl(InstrumentingAgents& instrumentingAgents, WorkerInspectorProxy& proxy)
 {
     if (InspectorWorkerAgent* workerAgent = instrumentingAgents.inspectorWorkerAgent())
         workerAgent->workerTerminated(proxy);
index 21f88d1..03bdd55 100644 (file)
@@ -47,6 +47,7 @@
 #include "Page.h"
 #include "StorageArea.h"
 #include "WebAnimation.h"
+#include "WorkerInspectorProxy.h"
 #include <JavaScriptCore/ConsoleMessage.h>
 #include <initializer_list>
 #include <wtf/CompletionHandler.h>
@@ -97,7 +98,6 @@ class SharedBuffer;
 class TimerBase;
 class WebKitNamedFlow;
 class WorkerGlobalScope;
-class WorkerInspectorProxy;
 
 #if ENABLE(WEBGL)
 class WebGLProgram;
@@ -270,8 +270,8 @@ public:
     static void didDispatchDOMStorageEvent(Page&, const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*);
 
     static bool shouldWaitForDebuggerOnStart(ScriptExecutionContext&);
-    static void workerStarted(ScriptExecutionContext&, WorkerInspectorProxy*, const URL&);
-    static void workerTerminated(ScriptExecutionContext&, WorkerInspectorProxy*);
+    static void workerStarted(WorkerInspectorProxy&);
+    static void workerTerminated(WorkerInspectorProxy&);
 
     static void didCreateWebSocket(Document*, unsigned long identifier, const URL& requestURL);
     static void willSendWebSocketHandshakeRequest(Document*, unsigned long identifier, const ResourceRequest&);
@@ -470,8 +470,8 @@ private:
     static void didDispatchDOMStorageEventImpl(InstrumentingAgents&, const String& key, const String& oldValue, const String& newValue, StorageType, SecurityOrigin*);
 
     static bool shouldWaitForDebuggerOnStartImpl(InstrumentingAgents&);
-    static void workerStartedImpl(InstrumentingAgents&, WorkerInspectorProxy*, const URL&);
-    static void workerTerminatedImpl(InstrumentingAgents&, WorkerInspectorProxy*);
+    static void workerStartedImpl(InstrumentingAgents&, WorkerInspectorProxy&);
+    static void workerTerminatedImpl(InstrumentingAgents&, WorkerInspectorProxy&);
 
     static void didCreateWebSocketImpl(InstrumentingAgents&, unsigned long identifier, const URL& requestURL);
     static void willSendWebSocketHandshakeRequestImpl(InstrumentingAgents&, unsigned long identifier, const ResourceRequest&);
@@ -1293,17 +1293,17 @@ inline bool InspectorInstrumentation::shouldWaitForDebuggerOnStart(ScriptExecuti
     return false;
 }
 
-inline void InspectorInstrumentation::workerStarted(ScriptExecutionContext& context, WorkerInspectorProxy* proxy, const URL& url)
+inline void InspectorInstrumentation::workerStarted(WorkerInspectorProxy& proxy)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
-        workerStartedImpl(*instrumentingAgents, proxy, url);
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(proxy.scriptExecutionContext()))
+        workerStartedImpl(*instrumentingAgents, proxy);
 }
 
-inline void InspectorInstrumentation::workerTerminated(ScriptExecutionContext& context, WorkerInspectorProxy* proxy)
+inline void InspectorInstrumentation::workerTerminated(WorkerInspectorProxy& proxy)
 {
     FAST_RETURN_IF_NO_FRONTENDS(void());
-    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(context))
+    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForContext(proxy.scriptExecutionContext()))
         workerTerminatedImpl(*instrumentingAgents, proxy);
 }
 
index 29d8a2b..a7a20f7 100644 (file)
@@ -104,9 +104,9 @@ void InspectorWorkerAgent::sendMessageToWorker(ErrorString& errorString, const S
     proxy->sendMessageToWorkerInspectorController(message);
 }
 
-void InspectorWorkerAgent::sendMessageFromWorkerToFrontend(WorkerInspectorProxy* proxy, const String& message)
+void InspectorWorkerAgent::sendMessageFromWorkerToFrontend(WorkerInspectorProxy& proxy, const String& message)
 {
-    m_frontendDispatcher->dispatchMessageFromWorker(proxy->identifier(), message);
+    m_frontendDispatcher->dispatchMessageFromWorker(proxy.identifier(), message);
 }
 
 bool InspectorWorkerAgent::shouldWaitForDebuggerOnStart() const
@@ -114,7 +114,7 @@ bool InspectorWorkerAgent::shouldWaitForDebuggerOnStart() const
     return m_enabled;
 }
 
-void InspectorWorkerAgent::workerStarted(WorkerInspectorProxy* proxy, const URL&)
+void InspectorWorkerAgent::workerStarted(WorkerInspectorProxy& proxy)
 {
     if (!m_enabled)
         return;
@@ -122,7 +122,7 @@ void InspectorWorkerAgent::workerStarted(WorkerInspectorProxy* proxy, const URL&
     connectToWorkerInspectorProxy(proxy);
 }
 
-void InspectorWorkerAgent::workerTerminated(WorkerInspectorProxy* proxy)
+void InspectorWorkerAgent::workerTerminated(WorkerInspectorProxy& proxy)
 {
     if (!m_enabled)
         return;
@@ -142,7 +142,7 @@ void InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage()
         if (document.page() != &m_page)
             continue;
 
-        connectToWorkerInspectorProxy(proxy);
+        connectToWorkerInspectorProxy(*proxy);
     }
 }
 
@@ -154,22 +154,22 @@ void InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies()
     m_connectedProxies.clear();
 }
 
-void InspectorWorkerAgent::connectToWorkerInspectorProxy(WorkerInspectorProxy* proxy)
+void InspectorWorkerAgent::connectToWorkerInspectorProxy(WorkerInspectorProxy& proxy)
 {
-    proxy->connectToWorkerInspectorController(this);
+    proxy.connectToWorkerInspectorController(*this);
 
-    m_connectedProxies.set(proxy->identifier(), proxy);
+    m_connectedProxies.set(proxy.identifier(), &proxy);
 
-    m_frontendDispatcher->workerCreated(proxy->identifier(), proxy->url().string());
+    m_frontendDispatcher->workerCreated(proxy.identifier(), proxy.url().string(), proxy.name());
 }
 
-void InspectorWorkerAgent::disconnectFromWorkerInspectorProxy(WorkerInspectorProxy* proxy)
+void InspectorWorkerAgent::disconnectFromWorkerInspectorProxy(WorkerInspectorProxy& proxy)
 {
-    m_frontendDispatcher->workerTerminated(proxy->identifier());
+    m_frontendDispatcher->workerTerminated(proxy.identifier());
 
-    m_connectedProxies.remove(proxy->identifier());
+    m_connectedProxies.remove(proxy.identifier());
 
-    proxy->disconnectFromWorkerInspectorController();
+    proxy.disconnectFromWorkerInspectorController();
 }
 
 } // namespace Inspector
index 9447493..17d1bea 100644 (file)
@@ -55,18 +55,18 @@ public:
     void sendMessageToWorker(ErrorString&, const String& workerId, const String& message) override;
 
     // WorkerInspectorProxy::PageChannel
-    void sendMessageFromWorkerToFrontend(WorkerInspectorProxy*, const String& message) override;
+    void sendMessageFromWorkerToFrontend(WorkerInspectorProxy&, const String& message) override;
 
     // InspectorInstrumentation
     bool shouldWaitForDebuggerOnStart() const;
-    void workerStarted(WorkerInspectorProxy*, const URL&);
-    void workerTerminated(WorkerInspectorProxy*);
+    void workerStarted(WorkerInspectorProxy&);
+    void workerTerminated(WorkerInspectorProxy&);
 
 private:
     void connectToAllWorkerInspectorProxiesForPage();
     void disconnectFromAllWorkerInspectorProxies();
-    void connectToWorkerInspectorProxy(WorkerInspectorProxy*);
-    void disconnectFromWorkerInspectorProxy(WorkerInspectorProxy*);
+    void connectToWorkerInspectorProxy(WorkerInspectorProxy&);
+    void disconnectFromWorkerInspectorProxy(WorkerInspectorProxy&);
 
     std::unique_ptr<Inspector::WorkerFrontendDispatcher> m_frontendDispatcher;
     RefPtr<Inspector::WorkerBackendDispatcher> m_backendDispatcher;
index 5f7d173..632b82e 100644 (file)
@@ -31,6 +31,7 @@
 #include "WorkerGlobalScope.h"
 #include "WorkerInspectorController.h"
 #include "WorkerRunLoop.h"
+#include "WorkerThread.h"
 #include <JavaScriptCore/InspectorAgentBase.h>
 #include <wtf/NeverDestroyed.h>
 
@@ -61,17 +62,18 @@ WorkerThreadStartMode WorkerInspectorProxy::workerStartMode(ScriptExecutionConte
     return pauseOnStart ? WorkerThreadStartMode::WaitForInspector : WorkerThreadStartMode::Normal;
 }
 
-void WorkerInspectorProxy::workerStarted(ScriptExecutionContext* scriptExecutionContext, WorkerThread* thread, const URL& url)
+void WorkerInspectorProxy::workerStarted(ScriptExecutionContext* scriptExecutionContext, WorkerThread* thread, const URL& url, const String& name)
 {
     ASSERT(!m_workerThread);
 
     m_scriptExecutionContext = scriptExecutionContext;
     m_workerThread = thread;
     m_url = url;
+    m_name = name;
 
     allWorkerInspectorProxies().add(this);
 
-    InspectorInstrumentation::workerStarted(*m_scriptExecutionContext.get(), this, m_url);
+    InspectorInstrumentation::workerStarted(*this);
 }
 
 void WorkerInspectorProxy::workerTerminated()
@@ -79,7 +81,7 @@ void WorkerInspectorProxy::workerTerminated()
     if (!m_workerThread)
         return;
 
-    InspectorInstrumentation::workerTerminated(*m_scriptExecutionContext.get(), this);
+    InspectorInstrumentation::workerTerminated(*this);
 
     allWorkerInspectorProxies().remove(this);
 
@@ -95,13 +97,13 @@ void WorkerInspectorProxy::resumeWorkerIfPaused()
     });
 }
 
-void WorkerInspectorProxy::connectToWorkerInspectorController(PageChannel* channel)
+void WorkerInspectorProxy::connectToWorkerInspectorController(PageChannel& channel)
 {
     ASSERT(m_workerThread);
     if (!m_workerThread)
         return;
 
-    m_pageChannel = channel;
+    m_pageChannel = &channel;
 
     m_workerThread->runLoop().postDebuggerTask([] (ScriptExecutionContext& context) {
         downcast<WorkerGlobalScope>(context).inspectorController().connectFrontend();
@@ -141,7 +143,7 @@ void WorkerInspectorProxy::sendMessageFromWorkerToFrontend(const String& message
     if (!m_pageChannel)
         return;
 
-    m_pageChannel->sendMessageFromWorkerToFrontend(this, message);
+    m_pageChannel->sendMessageFromWorkerToFrontend(*this, message);
 }
 
 } // namespace WebCore
index a1d3ea7..5e8a1dc 100644 (file)
@@ -25,9 +25,9 @@
 
 #pragma once
 
-#include <wtf/URL.h>
-#include "WorkerThread.h"
 #include <wtf/HashSet.h>
+#include <wtf/RefPtr.h>
+#include <wtf/URL.h>
 #include <wtf/text/WTFString.h>
 
 // All of these methods should be called on the Main Thread.
@@ -38,6 +38,8 @@ namespace WebCore {
 class ScriptExecutionContext;
 class WorkerThread;
 
+enum class WorkerThreadStartMode;
+
 class WorkerInspectorProxy {
     WTF_MAKE_NONCOPYABLE(WorkerInspectorProxy);
     WTF_MAKE_FAST_ALLOCATED;
@@ -49,21 +51,22 @@ public:
     class PageChannel {
     public:
         virtual ~PageChannel() = default;
-        virtual void sendMessageFromWorkerToFrontend(WorkerInspectorProxy*, const String&) = 0;
+        virtual void sendMessageFromWorkerToFrontend(WorkerInspectorProxy&, const String&) = 0;
     };
 
     static HashSet<WorkerInspectorProxy*>& allWorkerInspectorProxies();
 
     const URL& url() const { return m_url; }
+    const String& name() const { return m_name; }
     const String& identifier() const { return m_identifier; }
     ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext.get(); }
 
     WorkerThreadStartMode workerStartMode(ScriptExecutionContext&);
-    void workerStarted(ScriptExecutionContext*, WorkerThread*, const URL&);
+    void workerStarted(ScriptExecutionContext*, WorkerThread*, const URL&, const String& name);
     void workerTerminated();
 
     void resumeWorkerIfPaused();
-    void connectToWorkerInspectorController(PageChannel*);
+    void connectToWorkerInspectorController(PageChannel&);
     void disconnectFromWorkerInspectorController();
     void sendMessageToWorkerInspectorController(const String&);
     void sendMessageFromWorkerToFrontend(const String&);
@@ -73,6 +76,7 @@ private:
     RefPtr<WorkerThread> m_workerThread;
     String m_identifier;
     URL m_url;
+    String m_name;
     PageChannel* m_pageChannel { nullptr };
 };
 
index 8860cb7..b9d1970 100644 (file)
@@ -95,7 +95,7 @@ void WorkerMessagingProxy::startWorkerGlobalScope(const URL& scriptURL, const St
     workerThreadCreated(thread.get());
     thread->start();
 
-    m_inspectorProxy->workerStarted(m_scriptExecutionContext.get(), thread.ptr(), scriptURL);
+    m_inspectorProxy->workerStarted(m_scriptExecutionContext.get(), thread.ptr(), scriptURL, name);
 }
 
 void WorkerMessagingProxy::postMessageToWorkerObject(MessageWithMessagePorts&& message)
index ad689d6..fa5b821 100644 (file)
@@ -1,5 +1,30 @@
 2020-05-04  Devin Rousso  <drousso@apple.com>
 
+        Web Inspector: Worker: should use the name of the worker if it exists
+        https://bugs.webkit.org/show_bug.cgi?id=211244
+
+        Reviewed by Brian Burg.
+
+        * UserInterface/Protocol/WorkerObserver.js:
+        (WI.WorkerObserver.prototype.workerCreated):
+        * UserInterface/Controllers/WorkerManager.js:
+        (WI.WorkerManager.prototype.workerCreated):
+        * UserInterface/Protocol/WorkerTarget.js:
+        (WI.WorkerTarget):
+        (WI.WorkerTarget.prototype.get customName): Added.
+        (WI.WorkerTarget.prototype.get displayName):
+        (WI.WorkerTarget.prototype.get displayURL): Added.
+        Use the `name` from the `WorkerOptions` given to the `Worker` when it's constructed as the
+        `displayName` of the `WI.WorkerTarget` if able. Also exposed via `get customName`.
+
+        * UserInterface/Views/ScriptTreeElement.js:
+        (WI.ScriptTreeElement):
+        * UserInterface/Views/WorkerTreeElement.js:
+        (WI.WorkerTreeElement):
+        Accept an `options` optional object that can be used to override the `mainTitle`.
+
+2020-05-04  Devin Rousso  <drousso@apple.com>
+
         Web Inspector: provide a way for inspector to turn on/off ITP debug mode and AdClickAttribution debug mode
         https://bugs.webkit.org/show_bug.cgi?id=209763
 
index 4fff175..9d4294a 100644 (file)
@@ -42,11 +42,11 @@ WI.WorkerManager = class WorkerManager extends WI.Object
 
     // WorkerObserver
 
-    workerCreated(target, workerId, url)
+    workerCreated(target, workerId, url, name)
     {
         console.assert(target.hasCommand("Worker.sendMessageToWorker"));
         let connection = new InspectorBackend.WorkerConnection;
-        let workerTarget = new WI.WorkerTarget(target, workerId, url, connection);
+        let workerTarget = new WI.WorkerTarget(target, workerId, url, name, connection);
         workerTarget.initialize();
 
         WI.targetManager.addTarget(workerTarget);
index d869d53..d7066b8 100644 (file)
@@ -27,9 +27,9 @@ WI.WorkerObserver = class WorkerObserver extends InspectorBackend.Dispatcher
 {
     // Events defined by the "Worker" domain.
 
-    workerCreated(workerId, url)
+    workerCreated(workerId, url, name)
     {
-        WI.workerManager.workerCreated(this._target, workerId, url);
+        WI.workerManager.workerCreated(this._target, workerId, url, name);
     }
 
     workerTerminated(workerId)
index d5af371..aba322d 100644 (file)
 
 WI.WorkerTarget = class WorkerTarget extends WI.Target
 {
-    constructor(parentTarget, workerId, name, connection, options = {})
+    constructor(parentTarget, workerId, url, displayName, connection, options = {})
     {
-        super(parentTarget, workerId, name, WI.TargetType.Worker, connection, options);
+        super(parentTarget, workerId, url, WI.TargetType.Worker, connection, options);
+
+        this._displayName = displayName;
 
         this._executionContext = new WI.ExecutionContext(this, WI.RuntimeManager.TopLevelContextExecutionIdentifier, WI.ExecutionContext.Type.Normal, this.displayName);
     }
 
     // Protected (Target)
 
+    get customName()
+    {
+        return this._displayName;
+    }
+
     get displayName()
     {
+        return this._displayName || this.displayURL;
+    }
+
+    get displayURL()
+    {
         return WI.displayNameForURL(this._name);
     }
 };
index 33fc9ff..9f82625 100644 (file)
 
 WI.ScriptTreeElement = class ScriptTreeElement extends WI.SourceCodeTreeElement
 {
-    constructor(script)
+    constructor(script, options = {})
     {
         console.assert(script instanceof WI.Script);
 
-        const title = null;
-        const subtitle = null;
-        super(script, "script", title, subtitle);
+        let scriptDisplayName = script.displayName;
 
-        this.mainTitle = script.displayName;
+        let title = options.mainTitle || scriptDisplayName;
+        let subtitle = null;
+        let tooltip = null;
+        let classNames = ["script"];
 
         if (script.url && !script.dynamicallyAddedScriptElement) {
-            if (script.urlComponents.scheme === "web-inspector")
-                this.tooltip = this.mainTitle;
-            else {
+            if (script.urlComponents.scheme !== "web-inspector") {
                 // Show the host as the subtitle if it is different from the main title.
                 let host = WI.displayNameForHost(script.urlComponents.host);
-                this.subtitle = this.mainTitle !== host ? host : null;
+                if (host && title !== host)
+                    subtitle = host;
+                else if (scriptDisplayName && title !== scriptDisplayName)
+                    subtitle = scriptDisplayName;
 
-                this.tooltip = script.url;
+                tooltip = script.url;
             }
 
-            this.addClassName(WI.ResourceTreeElement.ResourceIconStyleClassName);
-            this.addClassName(WI.Resource.Type.Script);
+            classNames.push(WI.ResourceTreeElement.ResourceIconStyleClassName);
+            classNames.push(WI.Resource.Type.Script);
         } else
-            this.addClassName(WI.ScriptTreeElement.AnonymousScriptIconStyleClassName);
+            classNames.push(WI.ScriptTreeElement.AnonymousScriptIconStyleClassName);
 
         if (script.isMainResource()) {
             console.assert(script.target.type === WI.TargetType.Worker || script.target.type === WI.TargetType.ServiceWorker, script.target.type);
-            this.addClassName("worker-icon");
+            classNames.push("worker-icon");
         }
 
+        super(script, classNames, title, subtitle);
+
         this._script = script;
+
+        if (tooltip)
+            this.tooltip = tooltip;
     }
 
     // Public
index 4f93258..be46f51 100644 (file)
@@ -30,12 +30,16 @@ WI.WorkerTreeElement = class WorkerTreeElement extends WI.ScriptTreeElement
 {
     constructor(target)
     {
-        super(target.mainResource);
-
         console.assert(target instanceof WI.Target);
         console.assert(target.type === WI.TargetType.Worker || target.type === WI.TargetType.ServiceWorker);
         console.assert(target.mainResource instanceof WI.Script);
 
+        let options = {};
+        if (target instanceof WI.WorkerTarget)
+            options.mainTitle = target.customName;
+
+        super(target.mainResource, options);
+
         this._target = target;
         this._target.addEventListener(WI.Target.Event.ResourceAdded, this._resourceAdded, this);
         this._target.addEventListener(WI.Target.Event.ScriptAdded, this._scriptAdded, this);