haikuwebkit/Source/WebCore/workers/WorkerInspectorProxy.h

84 lines
3.1 KiB
C
Raw Permalink Normal View History

Web Inspector: Introduce Page WorkerAgent and Worker InspectorController https://bugs.webkit.org/show_bug.cgi?id=163817 <rdar://problem/28899063> Reviewed by Brian Burg. Source/JavaScriptCore: * CMakeLists.txt: * DerivedSources.make: * inspector/protocol/Worker.json: Added. New Worker domain. Source/WebCore: Test: inspector/worker/worker-create-and-terminate.html From the perspective of an Inspector frontend, Workers are like a special JavaScript context, separate from the page, that may have its own set of Agents. This patch adds the necessary backend infrastructure to provide WorkerGlobalObject with an InspectorController and the means to communicate with a frontend through a Page's WorkerAgent. Pages now get a WorkerAgent. This informs the frontend about created and terminated Workers. It also provides a communication channel to dispatch and return inspector protocol messages to each of the Workers. The Page side always interacts with the WorkerInspectorProxy on the main thread. The Page's Worker Agent can sends and receives messages to WorkerInspectorControllers. WorkerGlobalScopes now get a WorkerInspectorController which will eventually contain its own set of agents. There are no agents yet, but they will be added individually in follow-up patches. The Worker side always interacts with the WorkerGlobalScope on the worker thread. WorkerInspectorController dispatches messages on its agents. All communication with Worker agents goes through Worker.sendMessageToWorker, which tunnels the command request to the Worker's InspectorController and agents. At the protocol level, worker agent command responses and worker agent events are sent as events through Worker.dispatchMessageFromWorker. On the frontend, the message dispatcher code will pair up replies with their commands, and no-reply messages as events, like normal. So calling worker agent methods in the frontend will be no different from the existing callback/promise-based ways. * CMakeLists.txt: * WebCore.xcodeproj/project.pbxproj: * inspector/InspectorAllInOne.cpp: Add new files. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): (WebCore::WorkerScriptController::initScript): * bindings/js/WorkerScriptController.h: Some cleanup. * inspector/InspectorController.cpp: (WebCore::InspectorController::InspectorController): * inspector/InspectorController.h: * inspector/InstrumentingAgents.cpp: (WebCore::InstrumentingAgents::reset): * inspector/InstrumentingAgents.h: (WebCore::InstrumentingAgents::inspectorWorkerAgent): (WebCore::InstrumentingAgents::setInspectorWorkerAgent): * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::workerStartedImpl): (WebCore::InspectorInstrumentation::workerTerminatedImpl): (WebCore::InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope): * inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::workerStarted): (WebCore::InspectorInstrumentation::workerTerminated): (WebCore::InspectorInstrumentation::instrumentingAgentsForContext): Give the Page a WorkerAgent and Instrumentation methods for Worker creation and termination. * inspector/InspectorWorkerAgent.h: Added. * inspector/InspectorWorkerAgent.cpp: Added. (WebCore::InspectorWorkerAgent::InspectorWorkerAgent): (WebCore::InspectorWorkerAgent::didCreateFrontendAndBackend): (WebCore::InspectorWorkerAgent::willDestroyFrontendAndBackend): (WebCore::InspectorWorkerAgent::enable): (WebCore::InspectorWorkerAgent::disable): (WebCore::InspectorWorkerAgent::workerStarted): (WebCore::InspectorWorkerAgent::workerTerminated): (WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage): (WebCore::InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies): (WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy): (WebCore::InspectorWorkerAgent::disconnectFromWorkerInspectorProxy): Handle connecting to Workers. This performs the "connectFrontend" and "disconnectFrontend" dance with each Worker's InspectorController. We only connect to workers when the Worker domain is enabled. (WebCore::InspectorWorkerAgent::sendMessageToWorker): (WebCore::InspectorWorkerAgent::sendMessageFromWorkerToFrontend): Proxying messages to individual messages happens through the WorkerInspectorProxy. That takes care of passing messages across threads for us. * workers/WorkerInspectorProxy.cpp: Added. (WebCore::WorkerInspectorProxy::allWorkerInspectorProxies): (WebCore::WorkerInspectorProxy::WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::~WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::workerStarted): (WebCore::WorkerInspectorProxy::workerTerminated): (WebCore::WorkerInspectorProxy::connectToWorkerInspector): (WebCore::WorkerInspectorProxy::disconnectFromWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageToWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageFromWorkerToFrontend): * workers/WorkerInspectorProxy.h: Added. (WebCore::WorkerInspectorProxy::PageChannel::~PageChannel): (WebCore::WorkerInspectorProxy::url): (WebCore::WorkerInspectorProxy::identifier): (WebCore::WorkerInspectorProxy::scriptExecutionContext): The WorkerInspectorProxy simplifies the cross thread communication between the Page Inspector and Worker Inspector. It also provides a clean interface between the two sides. * inspector/WorkerToPageFrontendChannel.h: Added. * inspector/WorkerInspectorController.h: Added. * inspector/WorkerInspectorController.cpp: Added. (WebCore::WorkerInspectorController::WorkerInspectorController): (WebCore::WorkerInspectorController::~WorkerInspectorController): (WebCore::WorkerInspectorController::workerTerminating): (WebCore::WorkerInspectorController::connectFrontend): (WebCore::WorkerInspectorController::disconnectFrontend): (WebCore::WorkerInspectorController::dispatchMessageFromFrontend): (WebCore::WorkerInspectorController::functionCallHandler): (WebCore::WorkerInspectorController::evaluateHandler): (WebCore::WorkerInspectorController::vm): A basic InspectorController for a WorkerGlobalScope. No agents yet, they will come soon. * inspector/WorkerScriptDebugServer.h: * inspector/WorkerScriptDebugServer.cpp: (WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer): (WebCore::WorkerScriptDebugServer::attachDebugger): (WebCore::WorkerScriptDebugServer::detachDebugger): (WebCore::WorkerScriptDebugServer::recompileAllJSFunctions): (WebCore::WorkerScriptDebugServer::runEventLoopWhilePaused): (WebCore::WorkerScriptDebugServer::reportException): (WebCore::WorkerScriptDebugServer::interruptAndRunTask): A basic WorkerScriptDebug server for a WorkerGlobalScope. Not really used until we implement DebuggerAgent, but needed for InspectorEnvironment. * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: (WebCore::WorkerGlobalScope::inspectorController): Give the WorkerGlobalScope an InspectorController. * workers/WorkerThread.cpp: (WebCore::WorkerThread::stop): Ensure the Worker InspectorController is immediately on the WorkerThread when it is about to be closed. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::WorkerMessagingProxy): (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): (WebCore::WorkerMessagingProxy::postMessageToPageInspector): (WebCore::WorkerMessagingProxy::workerGlobalScopeDestroyedInternal): (WebCore::WorkerMessagingProxy::terminateWorkerGlobalScope): * workers/WorkerMessagingProxy.h: * workers/WorkerReportingProxy.h: Call into the WorkerInspectorProxy for any inspector related logic, such as creation, termination, and messages received from the Worker. Source/WebInspectorUI: * UserInterface/Main.html: * UserInterface/Test.html: New files. * UserInterface/Base/Main.js: (WebInspector.loaded): * UserInterface/Test/Test.js: (WebInspector.loaded): New Observers and Managers. * UserInterface/Protocol/WorkerObserver.js: Added. (WebInspector.WorkerObserver.prototype.workerCreated): (WebInspector.WorkerObserver.prototype.workerTerminated): (WebInspector.WorkerObserver.prototype.dispatchMessageFromWorker): (WebInspector.WorkerObserver): * UserInterface/Controllers/WorkerManager.js: Added. (WebInspector.WorkerManager): (WebInspector.WorkerManager.prototype.workerCreated): (WebInspector.WorkerManager.prototype.workerTerminated): (WebInspector.WorkerManager.prototype.dispatchMessageFromWorker): To be implemented with the first Worker agent implementation when there is actually something we can do with the Worker. LayoutTests: * inspector/worker/resources/worker-1.js: Added. * inspector/worker/resources/worker-2.js: Added. * inspector/worker/resources/worker-3.js: Added. * inspector/worker/worker-create-and-terminate-expected.txt: Added. * inspector/worker/worker-create-and-terminate.html: Added. Tests for the new Worker domain events. The rest of the Worker domain will be tested as soon as we add the first Agent in Workers. Canonical link: https://commits.webkit.org/181796@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208008 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-27 22:18:55 +00:00
/*
* Copyright (C) 2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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 <wtf/HashSet.h>
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. 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: Canonical link: https://commits.webkit.org/224279@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261104 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-04 19:51:30 +00:00
#include <wtf/RefPtr.h>
#include <wtf/URL.h>
Web Inspector: Introduce Page WorkerAgent and Worker InspectorController https://bugs.webkit.org/show_bug.cgi?id=163817 <rdar://problem/28899063> Reviewed by Brian Burg. Source/JavaScriptCore: * CMakeLists.txt: * DerivedSources.make: * inspector/protocol/Worker.json: Added. New Worker domain. Source/WebCore: Test: inspector/worker/worker-create-and-terminate.html From the perspective of an Inspector frontend, Workers are like a special JavaScript context, separate from the page, that may have its own set of Agents. This patch adds the necessary backend infrastructure to provide WorkerGlobalObject with an InspectorController and the means to communicate with a frontend through a Page's WorkerAgent. Pages now get a WorkerAgent. This informs the frontend about created and terminated Workers. It also provides a communication channel to dispatch and return inspector protocol messages to each of the Workers. The Page side always interacts with the WorkerInspectorProxy on the main thread. The Page's Worker Agent can sends and receives messages to WorkerInspectorControllers. WorkerGlobalScopes now get a WorkerInspectorController which will eventually contain its own set of agents. There are no agents yet, but they will be added individually in follow-up patches. The Worker side always interacts with the WorkerGlobalScope on the worker thread. WorkerInspectorController dispatches messages on its agents. All communication with Worker agents goes through Worker.sendMessageToWorker, which tunnels the command request to the Worker's InspectorController and agents. At the protocol level, worker agent command responses and worker agent events are sent as events through Worker.dispatchMessageFromWorker. On the frontend, the message dispatcher code will pair up replies with their commands, and no-reply messages as events, like normal. So calling worker agent methods in the frontend will be no different from the existing callback/promise-based ways. * CMakeLists.txt: * WebCore.xcodeproj/project.pbxproj: * inspector/InspectorAllInOne.cpp: Add new files. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): (WebCore::WorkerScriptController::initScript): * bindings/js/WorkerScriptController.h: Some cleanup. * inspector/InspectorController.cpp: (WebCore::InspectorController::InspectorController): * inspector/InspectorController.h: * inspector/InstrumentingAgents.cpp: (WebCore::InstrumentingAgents::reset): * inspector/InstrumentingAgents.h: (WebCore::InstrumentingAgents::inspectorWorkerAgent): (WebCore::InstrumentingAgents::setInspectorWorkerAgent): * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::workerStartedImpl): (WebCore::InspectorInstrumentation::workerTerminatedImpl): (WebCore::InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope): * inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::workerStarted): (WebCore::InspectorInstrumentation::workerTerminated): (WebCore::InspectorInstrumentation::instrumentingAgentsForContext): Give the Page a WorkerAgent and Instrumentation methods for Worker creation and termination. * inspector/InspectorWorkerAgent.h: Added. * inspector/InspectorWorkerAgent.cpp: Added. (WebCore::InspectorWorkerAgent::InspectorWorkerAgent): (WebCore::InspectorWorkerAgent::didCreateFrontendAndBackend): (WebCore::InspectorWorkerAgent::willDestroyFrontendAndBackend): (WebCore::InspectorWorkerAgent::enable): (WebCore::InspectorWorkerAgent::disable): (WebCore::InspectorWorkerAgent::workerStarted): (WebCore::InspectorWorkerAgent::workerTerminated): (WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage): (WebCore::InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies): (WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy): (WebCore::InspectorWorkerAgent::disconnectFromWorkerInspectorProxy): Handle connecting to Workers. This performs the "connectFrontend" and "disconnectFrontend" dance with each Worker's InspectorController. We only connect to workers when the Worker domain is enabled. (WebCore::InspectorWorkerAgent::sendMessageToWorker): (WebCore::InspectorWorkerAgent::sendMessageFromWorkerToFrontend): Proxying messages to individual messages happens through the WorkerInspectorProxy. That takes care of passing messages across threads for us. * workers/WorkerInspectorProxy.cpp: Added. (WebCore::WorkerInspectorProxy::allWorkerInspectorProxies): (WebCore::WorkerInspectorProxy::WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::~WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::workerStarted): (WebCore::WorkerInspectorProxy::workerTerminated): (WebCore::WorkerInspectorProxy::connectToWorkerInspector): (WebCore::WorkerInspectorProxy::disconnectFromWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageToWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageFromWorkerToFrontend): * workers/WorkerInspectorProxy.h: Added. (WebCore::WorkerInspectorProxy::PageChannel::~PageChannel): (WebCore::WorkerInspectorProxy::url): (WebCore::WorkerInspectorProxy::identifier): (WebCore::WorkerInspectorProxy::scriptExecutionContext): The WorkerInspectorProxy simplifies the cross thread communication between the Page Inspector and Worker Inspector. It also provides a clean interface between the two sides. * inspector/WorkerToPageFrontendChannel.h: Added. * inspector/WorkerInspectorController.h: Added. * inspector/WorkerInspectorController.cpp: Added. (WebCore::WorkerInspectorController::WorkerInspectorController): (WebCore::WorkerInspectorController::~WorkerInspectorController): (WebCore::WorkerInspectorController::workerTerminating): (WebCore::WorkerInspectorController::connectFrontend): (WebCore::WorkerInspectorController::disconnectFrontend): (WebCore::WorkerInspectorController::dispatchMessageFromFrontend): (WebCore::WorkerInspectorController::functionCallHandler): (WebCore::WorkerInspectorController::evaluateHandler): (WebCore::WorkerInspectorController::vm): A basic InspectorController for a WorkerGlobalScope. No agents yet, they will come soon. * inspector/WorkerScriptDebugServer.h: * inspector/WorkerScriptDebugServer.cpp: (WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer): (WebCore::WorkerScriptDebugServer::attachDebugger): (WebCore::WorkerScriptDebugServer::detachDebugger): (WebCore::WorkerScriptDebugServer::recompileAllJSFunctions): (WebCore::WorkerScriptDebugServer::runEventLoopWhilePaused): (WebCore::WorkerScriptDebugServer::reportException): (WebCore::WorkerScriptDebugServer::interruptAndRunTask): A basic WorkerScriptDebug server for a WorkerGlobalScope. Not really used until we implement DebuggerAgent, but needed for InspectorEnvironment. * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: (WebCore::WorkerGlobalScope::inspectorController): Give the WorkerGlobalScope an InspectorController. * workers/WorkerThread.cpp: (WebCore::WorkerThread::stop): Ensure the Worker InspectorController is immediately on the WorkerThread when it is about to be closed. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::WorkerMessagingProxy): (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): (WebCore::WorkerMessagingProxy::postMessageToPageInspector): (WebCore::WorkerMessagingProxy::workerGlobalScopeDestroyedInternal): (WebCore::WorkerMessagingProxy::terminateWorkerGlobalScope): * workers/WorkerMessagingProxy.h: * workers/WorkerReportingProxy.h: Call into the WorkerInspectorProxy for any inspector related logic, such as creation, termination, and messages received from the Worker. Source/WebInspectorUI: * UserInterface/Main.html: * UserInterface/Test.html: New files. * UserInterface/Base/Main.js: (WebInspector.loaded): * UserInterface/Test/Test.js: (WebInspector.loaded): New Observers and Managers. * UserInterface/Protocol/WorkerObserver.js: Added. (WebInspector.WorkerObserver.prototype.workerCreated): (WebInspector.WorkerObserver.prototype.workerTerminated): (WebInspector.WorkerObserver.prototype.dispatchMessageFromWorker): (WebInspector.WorkerObserver): * UserInterface/Controllers/WorkerManager.js: Added. (WebInspector.WorkerManager): (WebInspector.WorkerManager.prototype.workerCreated): (WebInspector.WorkerManager.prototype.workerTerminated): (WebInspector.WorkerManager.prototype.dispatchMessageFromWorker): To be implemented with the first Worker agent implementation when there is actually something we can do with the Worker. LayoutTests: * inspector/worker/resources/worker-1.js: Added. * inspector/worker/resources/worker-2.js: Added. * inspector/worker/resources/worker-3.js: Added. * inspector/worker/worker-create-and-terminate-expected.txt: Added. * inspector/worker/worker-create-and-terminate.html: Added. Tests for the new Worker domain events. The rest of the Worker domain will be tested as soon as we add the first Agent in Workers. Canonical link: https://commits.webkit.org/181796@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208008 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-27 22:18:55 +00:00
#include <wtf/text/WTFString.h>
// All of these methods should be called on the Main Thread.
// Used to send messages to the WorkerInspector on the WorkerThread.
namespace WebCore {
class ScriptExecutionContext;
class WorkerThread;
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. 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: Canonical link: https://commits.webkit.org/224279@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261104 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-04 19:51:30 +00:00
enum class WorkerThreadStartMode;
Web Inspector: Introduce Page WorkerAgent and Worker InspectorController https://bugs.webkit.org/show_bug.cgi?id=163817 <rdar://problem/28899063> Reviewed by Brian Burg. Source/JavaScriptCore: * CMakeLists.txt: * DerivedSources.make: * inspector/protocol/Worker.json: Added. New Worker domain. Source/WebCore: Test: inspector/worker/worker-create-and-terminate.html From the perspective of an Inspector frontend, Workers are like a special JavaScript context, separate from the page, that may have its own set of Agents. This patch adds the necessary backend infrastructure to provide WorkerGlobalObject with an InspectorController and the means to communicate with a frontend through a Page's WorkerAgent. Pages now get a WorkerAgent. This informs the frontend about created and terminated Workers. It also provides a communication channel to dispatch and return inspector protocol messages to each of the Workers. The Page side always interacts with the WorkerInspectorProxy on the main thread. The Page's Worker Agent can sends and receives messages to WorkerInspectorControllers. WorkerGlobalScopes now get a WorkerInspectorController which will eventually contain its own set of agents. There are no agents yet, but they will be added individually in follow-up patches. The Worker side always interacts with the WorkerGlobalScope on the worker thread. WorkerInspectorController dispatches messages on its agents. All communication with Worker agents goes through Worker.sendMessageToWorker, which tunnels the command request to the Worker's InspectorController and agents. At the protocol level, worker agent command responses and worker agent events are sent as events through Worker.dispatchMessageFromWorker. On the frontend, the message dispatcher code will pair up replies with their commands, and no-reply messages as events, like normal. So calling worker agent methods in the frontend will be no different from the existing callback/promise-based ways. * CMakeLists.txt: * WebCore.xcodeproj/project.pbxproj: * inspector/InspectorAllInOne.cpp: Add new files. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): (WebCore::WorkerScriptController::initScript): * bindings/js/WorkerScriptController.h: Some cleanup. * inspector/InspectorController.cpp: (WebCore::InspectorController::InspectorController): * inspector/InspectorController.h: * inspector/InstrumentingAgents.cpp: (WebCore::InstrumentingAgents::reset): * inspector/InstrumentingAgents.h: (WebCore::InstrumentingAgents::inspectorWorkerAgent): (WebCore::InstrumentingAgents::setInspectorWorkerAgent): * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::workerStartedImpl): (WebCore::InspectorInstrumentation::workerTerminatedImpl): (WebCore::InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope): * inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::workerStarted): (WebCore::InspectorInstrumentation::workerTerminated): (WebCore::InspectorInstrumentation::instrumentingAgentsForContext): Give the Page a WorkerAgent and Instrumentation methods for Worker creation and termination. * inspector/InspectorWorkerAgent.h: Added. * inspector/InspectorWorkerAgent.cpp: Added. (WebCore::InspectorWorkerAgent::InspectorWorkerAgent): (WebCore::InspectorWorkerAgent::didCreateFrontendAndBackend): (WebCore::InspectorWorkerAgent::willDestroyFrontendAndBackend): (WebCore::InspectorWorkerAgent::enable): (WebCore::InspectorWorkerAgent::disable): (WebCore::InspectorWorkerAgent::workerStarted): (WebCore::InspectorWorkerAgent::workerTerminated): (WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage): (WebCore::InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies): (WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy): (WebCore::InspectorWorkerAgent::disconnectFromWorkerInspectorProxy): Handle connecting to Workers. This performs the "connectFrontend" and "disconnectFrontend" dance with each Worker's InspectorController. We only connect to workers when the Worker domain is enabled. (WebCore::InspectorWorkerAgent::sendMessageToWorker): (WebCore::InspectorWorkerAgent::sendMessageFromWorkerToFrontend): Proxying messages to individual messages happens through the WorkerInspectorProxy. That takes care of passing messages across threads for us. * workers/WorkerInspectorProxy.cpp: Added. (WebCore::WorkerInspectorProxy::allWorkerInspectorProxies): (WebCore::WorkerInspectorProxy::WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::~WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::workerStarted): (WebCore::WorkerInspectorProxy::workerTerminated): (WebCore::WorkerInspectorProxy::connectToWorkerInspector): (WebCore::WorkerInspectorProxy::disconnectFromWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageToWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageFromWorkerToFrontend): * workers/WorkerInspectorProxy.h: Added. (WebCore::WorkerInspectorProxy::PageChannel::~PageChannel): (WebCore::WorkerInspectorProxy::url): (WebCore::WorkerInspectorProxy::identifier): (WebCore::WorkerInspectorProxy::scriptExecutionContext): The WorkerInspectorProxy simplifies the cross thread communication between the Page Inspector and Worker Inspector. It also provides a clean interface between the two sides. * inspector/WorkerToPageFrontendChannel.h: Added. * inspector/WorkerInspectorController.h: Added. * inspector/WorkerInspectorController.cpp: Added. (WebCore::WorkerInspectorController::WorkerInspectorController): (WebCore::WorkerInspectorController::~WorkerInspectorController): (WebCore::WorkerInspectorController::workerTerminating): (WebCore::WorkerInspectorController::connectFrontend): (WebCore::WorkerInspectorController::disconnectFrontend): (WebCore::WorkerInspectorController::dispatchMessageFromFrontend): (WebCore::WorkerInspectorController::functionCallHandler): (WebCore::WorkerInspectorController::evaluateHandler): (WebCore::WorkerInspectorController::vm): A basic InspectorController for a WorkerGlobalScope. No agents yet, they will come soon. * inspector/WorkerScriptDebugServer.h: * inspector/WorkerScriptDebugServer.cpp: (WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer): (WebCore::WorkerScriptDebugServer::attachDebugger): (WebCore::WorkerScriptDebugServer::detachDebugger): (WebCore::WorkerScriptDebugServer::recompileAllJSFunctions): (WebCore::WorkerScriptDebugServer::runEventLoopWhilePaused): (WebCore::WorkerScriptDebugServer::reportException): (WebCore::WorkerScriptDebugServer::interruptAndRunTask): A basic WorkerScriptDebug server for a WorkerGlobalScope. Not really used until we implement DebuggerAgent, but needed for InspectorEnvironment. * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: (WebCore::WorkerGlobalScope::inspectorController): Give the WorkerGlobalScope an InspectorController. * workers/WorkerThread.cpp: (WebCore::WorkerThread::stop): Ensure the Worker InspectorController is immediately on the WorkerThread when it is about to be closed. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::WorkerMessagingProxy): (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): (WebCore::WorkerMessagingProxy::postMessageToPageInspector): (WebCore::WorkerMessagingProxy::workerGlobalScopeDestroyedInternal): (WebCore::WorkerMessagingProxy::terminateWorkerGlobalScope): * workers/WorkerMessagingProxy.h: * workers/WorkerReportingProxy.h: Call into the WorkerInspectorProxy for any inspector related logic, such as creation, termination, and messages received from the Worker. Source/WebInspectorUI: * UserInterface/Main.html: * UserInterface/Test.html: New files. * UserInterface/Base/Main.js: (WebInspector.loaded): * UserInterface/Test/Test.js: (WebInspector.loaded): New Observers and Managers. * UserInterface/Protocol/WorkerObserver.js: Added. (WebInspector.WorkerObserver.prototype.workerCreated): (WebInspector.WorkerObserver.prototype.workerTerminated): (WebInspector.WorkerObserver.prototype.dispatchMessageFromWorker): (WebInspector.WorkerObserver): * UserInterface/Controllers/WorkerManager.js: Added. (WebInspector.WorkerManager): (WebInspector.WorkerManager.prototype.workerCreated): (WebInspector.WorkerManager.prototype.workerTerminated): (WebInspector.WorkerManager.prototype.dispatchMessageFromWorker): To be implemented with the first Worker agent implementation when there is actually something we can do with the Worker. LayoutTests: * inspector/worker/resources/worker-1.js: Added. * inspector/worker/resources/worker-2.js: Added. * inspector/worker/resources/worker-3.js: Added. * inspector/worker/worker-create-and-terminate-expected.txt: Added. * inspector/worker/worker-create-and-terminate.html: Added. Tests for the new Worker domain events. The rest of the Worker domain will be tested as soon as we add the first Agent in Workers. Canonical link: https://commits.webkit.org/181796@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208008 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-27 22:18:55 +00:00
class WorkerInspectorProxy {
WTF_MAKE_NONCOPYABLE(WorkerInspectorProxy);
WTF_MAKE_FAST_ALLOCATED;
public:
Web Inspector: Associate Worker Resources with the Worker and not the Page https://bugs.webkit.org/show_bug.cgi?id=164342 <rdar://problem/29075775> Reviewed by Timothy Hatcher. Source/JavaScriptCore: * inspector/protocol/Network.json: * inspector/protocol/Page.json: Associate Resource data with a target. Source/WebCore: Test: inspector/worker/resources-in-worker.html Provide a way to associate an initiator identifier with a ResourceRequest. This will allow Web Inspector to identify who started particular resource loads. This is important to associate Worker(...), importScript(...), and XMLHttpRequest / Fetch loads with that specific Worker. * platform/network/ResourceRequestBase.cpp: (WebCore::ResourceRequestBase::setAsIsolatedCopy): * platform/network/ResourceRequestBase.h: (WebCore::ResourceRequestBase::initiatorIdentifier): (WebCore::ResourceRequestBase::setInitiatorIdentifier): Optional initiator identifier. Currently used only be Web Inspector. * dom/ScriptExecutionContext.h: (WebCore::ScriptExecutionContext::resourceRequestIdentifier): Non-page execution contexts, like WorkerGlobalScope, should provide a unique identifier that may be used to distinguish loads initiated from within that context. * xml/XMLHttpRequest.cpp: (WebCore::XMLHttpRequest::createRequest): * Modules/fetch/FetchLoader.cpp: (WebCore::FetchLoader::start): * Modules/fetch/FetchRequest.cpp: (WebCore::FetchRequest::initializeWith): XHR / Fetch loads should include the ScriptExecutionContext's initiator identifier. * workers/WorkerScriptLoader.cpp: (WebCore::WorkerScriptLoader::WorkerScriptLoader): (WebCore::WorkerScriptLoader::loadSynchronously): (WebCore::WorkerScriptLoader::loadAsynchronously): (WebCore::WorkerScriptLoader::createResourceRequest): * workers/WorkerScriptLoader.h: Provide a way to provide initiator identifier information for Worker script loads. Currently this is `new Worker(...)` and `importScripts(...)` resource loads. * workers/Worker.cpp: (WebCore::Worker::Worker): (WebCore::Worker::create): * workers/Worker.h: * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): (WebCore::WorkerGlobalScope::importScripts): * workers/WorkerGlobalScope.h: Give Worker itself the unique identifier, because `new Worker(...)` loads happen before the WorkerGlobalScript (ScriptExecutionContext) is actually created, but we want to associate it with this Worker. * workers/DedicatedWorkerGlobalScope.cpp: (WebCore::DedicatedWorkerGlobalScope::create): (WebCore::DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope): * workers/DedicatedWorkerGlobalScope.h: * workers/DedicatedWorkerThread.cpp: (WebCore::DedicatedWorkerThread::DedicatedWorkerThread): (WebCore::DedicatedWorkerThread::createWorkerGlobalScope): * workers/DedicatedWorkerThread.h: * workers/WorkerInspectorProxy.cpp: (WebCore::WorkerInspectorProxy::WorkerInspectorProxy): * workers/WorkerInspectorProxy.h: * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::WorkerMessagingProxy): (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): * workers/WorkerThread.cpp: (WebCore::WorkerThreadStartupData::WorkerThreadStartupData): (WebCore::WorkerThread::WorkerThread): (WebCore::WorkerThread::workerThread): * workers/WorkerThread.h: Pass the MainThread's Worker identifier through to the WorkerGlobalScope created on the WorkerThread. They should be the same identifier. * inspector/InspectorNetworkAgent.cpp: (WebCore::InspectorNetworkAgent::willSendRequest): * inspector/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::buildObjectForFrameTree): Pass the initiator identifier data to the frontend. This identifier is equivalent to a "target identifier" in the frontend. Currently the only non-Page targets are Workers. * loader/cache/CachedResourceLoader.cpp: (WebCore::CachedResourceLoader::shouldContinueAfterNotifyingLoadedFromMemoryCache): When using the memory cache we create a new resource request. Be sure to copy over useful inspector data, like the initiator identifier, from the original request. * platform/network/cf/ResourceRequestCFNet.cpp: (WebCore::ResourceRequest::updateFromDelegatePreservingOldProperties): When rebuilding a ResourceRequest from NSURLRequest, copy over the initiator identifier property that wouldn't otherwise have survived the transition. Source/WebInspectorUI: A Target may have its own list of Resource. For example, Workers may request any resources via XHR/Fetch. So we associate a ResourceCollection with a Target, and ensure we show them in Web Inspector as you would expect. At this point, Target starts acting like Frame. Target has a resourceCollection and extraScriptsCollection just like Frame. Target has events for ResourceAdded just like Frame. Even though Resource loads are happening in Workers, the Network data still comes from the Page's Network agent. The added "targetId" data with the Resource will let us associate a Resoure with a Target. When opening inspector after a page has loaded, the frontend loads Resources via the Page.getResourceTree path. In this case, the frontend may be informed of Resources for a Target that it does not know about yet. In these cases, it sets them aside as Orphaned resources for a target. Later, when that Target is created, it will adopt its Orphaned resources. Places that used to listen to just Frame.Event.ResourceWasAdded should now also listen for Target.Event.ResourceAdded to ensure it sees the resources associated with non-page targets. * UserInterface/Protocol/Target.js: (WebInspector.Target): (WebInspector.Target.prototype.get identifier): (WebInspector.Target.prototype.get resourceCollection): (WebInspector.Target.prototype.get extraScriptCollection): (WebInspector.Target.prototype.addResource): (WebInspector.Target.prototype.adoptResource): (WebInspector.Target.prototype.addScript): Give Target resource collections. (WebInspector.MainTarget): (WebInspector.MainTarget.prototype.get mainResource): Pass through to the FrameResourceManager for the MainTarget. (WebInspector.WorkerTarget): (WebInspector.WorkerTarget.prototype.initialize): Adopt orphaned resources on creation. * UserInterface/Models/Resource.js: (WebInspector.Resource): (WebInspector.Resource.prototype.get target): (WebInspector.Resource.prototype.get type): Resource now has a Target. During creation, if there is a targetId then we must produce a Target or null (orphaned). (WebInspector.Resource.prototype.associateWithScript): When associating a Resource with a Script, we can use this opportunity to convert from an XML / Other type to Script. * UserInterface/Models/Script.js: (WebInspector.Script.prototype._resolveResource): When associating Scripts with a resource we must associate resources from within the proper Target. If it is the Main target we still use the FrameResourceManager which keep searches across all Frames. * UserInterface/Protocol/NetworkObserver.js: (WebInspector.NetworkObserver.prototype.requestWillBeSent): * UserInterface/Controllers/FrameResourceManager.js: (WebInspector.FrameResourceManager.prototype.initialize): (WebInspector.FrameResourceManager.prototype.frameDidNavigate): (WebInspector.FrameResourceManager.prototype.resourceRequestWillBeSent): (WebInspector.FrameResourceManager.prototype.resourceRequestWasServedFromMemoryCache): (WebInspector.FrameResourceManager.prototype.resourceRequestDidReceiveResponse): (WebInspector.FrameResourceManager.prototype.adoptOrphanedResourcesForTarget): (WebInspector.FrameResourceManager.prototype._addNewResourceToFrameOrTarget): (WebInspector.FrameResourceManager.prototype._addResourceToTarget): (WebInspector.FrameResourceManager.prototype._createResource): (WebInspector.FrameResourceManager.prototype._addFrameTreeFromFrameResourceTreePayload): (WebInspector.FrameResourceManager.prototype._addOrphanedResource): (WebInspector.FrameResourceManager.prototype._mainFrameDidChange): (WebInspector.FrameResourceManager.prototype._addNewResourceToFrame): Deleted. When creating Resources from Network events we may now have a targetId. Once created a Resource must be associated with a Frame, Target, or orphaned. * UserInterface/Main.html: * UserInterface/Views/TargetTreeElement.js: Removed. * UserInterface/Views/WorkerTreeElement.js: Added. (WebInspector.WorkerTreeElement): (WebInspector.WorkerTreeElement.prototype.get target): (WebInspector.WorkerTreeElement.prototype.onexpand): (WebInspector.WorkerTreeElement.prototype.oncollapse): (WebInspector.WorkerTreeElement.prototype.onpopulate): (WebInspector.WorkerTreeElement.prototype.updateSourceMapResources): (WebInspector.WorkerTreeElement.prototype.onattach): (WebInspector.WorkerTreeElement.prototype.compareChildTreeElements): (WebInspector.WorkerTreeElement.prototype._handleContextMenuEvent): (WebInspector.WorkerTreeElement.prototype._scriptAdded): (WebInspector.WorkerTreeElement.prototype._resourceAdded): Convert TargetTreeElement to WorkerTreeElement as that is clearer. Behave like FrameTreeElement and populate resources on creation, handle SourceMapResource, etc. * UserInterface/Views/FolderizedTreeElement.js: (WebInspector.FolderizedTreeElement.prototype.registerFolderizeSettings): (WebInspector.FolderizedTreeElement.prototype._compareTreeElementsByMainTitle): (WebInspector.FolderizedTreeElement.prototype._parentTreeElementForRepresentedObject): If the display name for a folder is `null` then there is no folder, and place such child tree elements at the top level. This will be the case for a Worker's Script's, which we choose not to folderize. * UserInterface/Controllers/DebuggerManager.js: (WebInspector.DebuggerManager.prototype.scriptDidParse): * UserInterface/Controllers/TargetManager.js: (WebInspector.TargetManager.prototype.targetForIdentifier): * UserInterface/Models/DefaultDashboard.js: (WebInspector.DefaultDashboard): * UserInterface/Controllers/TimelineManager.js: (WebInspector.TimelineManager): * UserInterface/Controllers/WorkerManager.js: (WebInspector.WorkerManager.prototype.workerCreated): * UserInterface/Views/OpenResourceDialog.js: (WebInspector.OpenResourceDialog.prototype.didDismissDialog): (WebInspector.OpenResourceDialog.prototype.didPresentDialog): (WebInspector.OpenResourceDialog.prototype._addScriptsForTarget): Deleted. (WebInspector.OpenResourceDialog.prototype._addResourcesForTarget): Added. Ensure those that listen for Frame.Event.ResourceWasAdded now also listen for Target.Event.ResourceAdded. * UserInterface/Views/ContextMenuUtilities.js: (WebInspector.appendContextMenuItemsForSourceCode): (WebInspector.appendContextMenuItemsForResource): Deleted. * UserInterface/Views/ResourceTimelineDataGridNode.js: (WebInspector.ResourceTimelineDataGridNode.prototype.appendContextMenuItems): * UserInterface/Views/ResourceTreeElement.js: (WebInspector.ResourceTreeElement.prototype._updateTitles): (WebInspector.ResourceTreeElement.prototype._handleContextMenuEvent): Generalize ContextMenu helper to SourceCode so it can be used on a Script or Resource. * UserInterface/Views/ResourceDetailsSidebarPanel.js: (WebInspector.ResourceDetailsSidebarPanel.prototype.inspect): When looking at a WorkerTarget's mainResource (Script) show the Resource Details sidebar for its Resource. * UserInterface/Views/ResourceSidebarPanel.js: (WebInspector.ResourceSidebarPanel): (WebInspector.ResourceSidebarPanel.prototype._scriptWasAdded): (WebInspector.ResourceSidebarPanel.prototype._scriptsCleared): (WebInspector.ResourceSidebarPanel.prototype._addTargetWithMainResource): (WebInspector.ResourceSidebarPanel.prototype._targetRemoved): (WebInspector.ResourceSidebarPanel.prototype._addScriptForNonMainTarget): Deleted. Simplify ResourceSidebarPanel to only handle adding WorkerTreeElements, which will do the rest of the work for their Resources/Scripts. * UserInterface/Views/SourceCodeTreeElement.js: (WebInspector.SourceCodeTreeElement.prototype.descendantResourceTreeElementTypeDidChange): When we were changing the type of a resource, it would remove and re-insert. This would collapse the parent if it was the only child in removal, and not expand the parent when re-inserting. This ensures we re-expand. LayoutTests: * inspector/worker/resources-in-worker-expected.txt: Added. * inspector/worker/resources-in-worker.html: Added. * inspector/worker/resources/dataFetch.json: Added. * inspector/worker/resources/dataXHR.json: Added. * inspector/worker/resources/resource-utilities.js: Added. (loadResourceXHR): (loadResourceFetch): * inspector/worker/resources/worker-resources.js: Added. (importScript): (onmessage): Canonical link: https://commits.webkit.org/182245@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208520 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-10 03:54:06 +00:00
WorkerInspectorProxy(const String& identifier);
Web Inspector: Introduce Page WorkerAgent and Worker InspectorController https://bugs.webkit.org/show_bug.cgi?id=163817 <rdar://problem/28899063> Reviewed by Brian Burg. Source/JavaScriptCore: * CMakeLists.txt: * DerivedSources.make: * inspector/protocol/Worker.json: Added. New Worker domain. Source/WebCore: Test: inspector/worker/worker-create-and-terminate.html From the perspective of an Inspector frontend, Workers are like a special JavaScript context, separate from the page, that may have its own set of Agents. This patch adds the necessary backend infrastructure to provide WorkerGlobalObject with an InspectorController and the means to communicate with a frontend through a Page's WorkerAgent. Pages now get a WorkerAgent. This informs the frontend about created and terminated Workers. It also provides a communication channel to dispatch and return inspector protocol messages to each of the Workers. The Page side always interacts with the WorkerInspectorProxy on the main thread. The Page's Worker Agent can sends and receives messages to WorkerInspectorControllers. WorkerGlobalScopes now get a WorkerInspectorController which will eventually contain its own set of agents. There are no agents yet, but they will be added individually in follow-up patches. The Worker side always interacts with the WorkerGlobalScope on the worker thread. WorkerInspectorController dispatches messages on its agents. All communication with Worker agents goes through Worker.sendMessageToWorker, which tunnels the command request to the Worker's InspectorController and agents. At the protocol level, worker agent command responses and worker agent events are sent as events through Worker.dispatchMessageFromWorker. On the frontend, the message dispatcher code will pair up replies with their commands, and no-reply messages as events, like normal. So calling worker agent methods in the frontend will be no different from the existing callback/promise-based ways. * CMakeLists.txt: * WebCore.xcodeproj/project.pbxproj: * inspector/InspectorAllInOne.cpp: Add new files. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): (WebCore::WorkerScriptController::initScript): * bindings/js/WorkerScriptController.h: Some cleanup. * inspector/InspectorController.cpp: (WebCore::InspectorController::InspectorController): * inspector/InspectorController.h: * inspector/InstrumentingAgents.cpp: (WebCore::InstrumentingAgents::reset): * inspector/InstrumentingAgents.h: (WebCore::InstrumentingAgents::inspectorWorkerAgent): (WebCore::InstrumentingAgents::setInspectorWorkerAgent): * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::workerStartedImpl): (WebCore::InspectorInstrumentation::workerTerminatedImpl): (WebCore::InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope): * inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::workerStarted): (WebCore::InspectorInstrumentation::workerTerminated): (WebCore::InspectorInstrumentation::instrumentingAgentsForContext): Give the Page a WorkerAgent and Instrumentation methods for Worker creation and termination. * inspector/InspectorWorkerAgent.h: Added. * inspector/InspectorWorkerAgent.cpp: Added. (WebCore::InspectorWorkerAgent::InspectorWorkerAgent): (WebCore::InspectorWorkerAgent::didCreateFrontendAndBackend): (WebCore::InspectorWorkerAgent::willDestroyFrontendAndBackend): (WebCore::InspectorWorkerAgent::enable): (WebCore::InspectorWorkerAgent::disable): (WebCore::InspectorWorkerAgent::workerStarted): (WebCore::InspectorWorkerAgent::workerTerminated): (WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage): (WebCore::InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies): (WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy): (WebCore::InspectorWorkerAgent::disconnectFromWorkerInspectorProxy): Handle connecting to Workers. This performs the "connectFrontend" and "disconnectFrontend" dance with each Worker's InspectorController. We only connect to workers when the Worker domain is enabled. (WebCore::InspectorWorkerAgent::sendMessageToWorker): (WebCore::InspectorWorkerAgent::sendMessageFromWorkerToFrontend): Proxying messages to individual messages happens through the WorkerInspectorProxy. That takes care of passing messages across threads for us. * workers/WorkerInspectorProxy.cpp: Added. (WebCore::WorkerInspectorProxy::allWorkerInspectorProxies): (WebCore::WorkerInspectorProxy::WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::~WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::workerStarted): (WebCore::WorkerInspectorProxy::workerTerminated): (WebCore::WorkerInspectorProxy::connectToWorkerInspector): (WebCore::WorkerInspectorProxy::disconnectFromWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageToWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageFromWorkerToFrontend): * workers/WorkerInspectorProxy.h: Added. (WebCore::WorkerInspectorProxy::PageChannel::~PageChannel): (WebCore::WorkerInspectorProxy::url): (WebCore::WorkerInspectorProxy::identifier): (WebCore::WorkerInspectorProxy::scriptExecutionContext): The WorkerInspectorProxy simplifies the cross thread communication between the Page Inspector and Worker Inspector. It also provides a clean interface between the two sides. * inspector/WorkerToPageFrontendChannel.h: Added. * inspector/WorkerInspectorController.h: Added. * inspector/WorkerInspectorController.cpp: Added. (WebCore::WorkerInspectorController::WorkerInspectorController): (WebCore::WorkerInspectorController::~WorkerInspectorController): (WebCore::WorkerInspectorController::workerTerminating): (WebCore::WorkerInspectorController::connectFrontend): (WebCore::WorkerInspectorController::disconnectFrontend): (WebCore::WorkerInspectorController::dispatchMessageFromFrontend): (WebCore::WorkerInspectorController::functionCallHandler): (WebCore::WorkerInspectorController::evaluateHandler): (WebCore::WorkerInspectorController::vm): A basic InspectorController for a WorkerGlobalScope. No agents yet, they will come soon. * inspector/WorkerScriptDebugServer.h: * inspector/WorkerScriptDebugServer.cpp: (WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer): (WebCore::WorkerScriptDebugServer::attachDebugger): (WebCore::WorkerScriptDebugServer::detachDebugger): (WebCore::WorkerScriptDebugServer::recompileAllJSFunctions): (WebCore::WorkerScriptDebugServer::runEventLoopWhilePaused): (WebCore::WorkerScriptDebugServer::reportException): (WebCore::WorkerScriptDebugServer::interruptAndRunTask): A basic WorkerScriptDebug server for a WorkerGlobalScope. Not really used until we implement DebuggerAgent, but needed for InspectorEnvironment. * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: (WebCore::WorkerGlobalScope::inspectorController): Give the WorkerGlobalScope an InspectorController. * workers/WorkerThread.cpp: (WebCore::WorkerThread::stop): Ensure the Worker InspectorController is immediately on the WorkerThread when it is about to be closed. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::WorkerMessagingProxy): (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): (WebCore::WorkerMessagingProxy::postMessageToPageInspector): (WebCore::WorkerMessagingProxy::workerGlobalScopeDestroyedInternal): (WebCore::WorkerMessagingProxy::terminateWorkerGlobalScope): * workers/WorkerMessagingProxy.h: * workers/WorkerReportingProxy.h: Call into the WorkerInspectorProxy for any inspector related logic, such as creation, termination, and messages received from the Worker. Source/WebInspectorUI: * UserInterface/Main.html: * UserInterface/Test.html: New files. * UserInterface/Base/Main.js: (WebInspector.loaded): * UserInterface/Test/Test.js: (WebInspector.loaded): New Observers and Managers. * UserInterface/Protocol/WorkerObserver.js: Added. (WebInspector.WorkerObserver.prototype.workerCreated): (WebInspector.WorkerObserver.prototype.workerTerminated): (WebInspector.WorkerObserver.prototype.dispatchMessageFromWorker): (WebInspector.WorkerObserver): * UserInterface/Controllers/WorkerManager.js: Added. (WebInspector.WorkerManager): (WebInspector.WorkerManager.prototype.workerCreated): (WebInspector.WorkerManager.prototype.workerTerminated): (WebInspector.WorkerManager.prototype.dispatchMessageFromWorker): To be implemented with the first Worker agent implementation when there is actually something we can do with the Worker. LayoutTests: * inspector/worker/resources/worker-1.js: Added. * inspector/worker/resources/worker-2.js: Added. * inspector/worker/resources/worker-3.js: Added. * inspector/worker/worker-create-and-terminate-expected.txt: Added. * inspector/worker/worker-create-and-terminate.html: Added. Tests for the new Worker domain events. The rest of the Worker domain will be tested as soon as we add the first Agent in Workers. Canonical link: https://commits.webkit.org/181796@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208008 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-27 22:18:55 +00:00
~WorkerInspectorProxy();
// A Worker's inspector messages come in and go out through the Page's WorkerAgent.
class PageChannel {
public:
Use "= default" to denote default constructor or destructor https://bugs.webkit.org/show_bug.cgi?id=178528 Rubber-stamped by Andy Estes. Source/WebCore: * Modules/airplay/WebKitPlaybackTargetAvailabilityEvent.h: * Modules/applepay/ApplePayError.cpp: * Modules/applepay/ApplePayPaymentAuthorizedEvent.cpp: * Modules/applepay/ApplePayPaymentMethodSelectedEvent.cpp: * Modules/applepay/ApplePaySession.cpp: * Modules/applepay/ApplePaySessionPaymentRequest.cpp: * Modules/applepay/ApplePayShippingContactSelectedEvent.cpp: * Modules/applepay/ApplePayShippingMethodSelectedEvent.cpp: * Modules/applepay/ApplePayValidateMerchantEvent.cpp: * Modules/applepay/Payment.h: * Modules/applepay/PaymentCoordinatorClient.h: * Modules/credentials/BasicCredential.cpp: * Modules/credentials/FederatedCredential.cpp: * Modules/credentials/NavigatorCredentials.cpp: * Modules/credentials/PasswordCredential.cpp: * Modules/encryptedmedia/CDMClient.h: * Modules/encryptedmedia/legacy/LegacyCDM.cpp: * Modules/encryptedmedia/legacy/LegacyCDM.h: * Modules/encryptedmedia/legacy/LegacyCDMPrivate.h: * Modules/encryptedmedia/legacy/LegacyCDMPrivateClearKey.h: * Modules/encryptedmedia/legacy/LegacyCDMPrivateMediaPlayer.h: * Modules/encryptedmedia/legacy/LegacyCDMSessionClearKey.cpp: * Modules/encryptedmedia/legacy/WebKitMediaKeyMessageEvent.cpp: * Modules/encryptedmedia/legacy/WebKitMediaKeyNeededEvent.cpp: * Modules/entriesapi/DOMFileSystem.cpp: * Modules/entriesapi/FileSystemDirectoryReader.cpp: * Modules/entriesapi/FileSystemEntry.cpp: * Modules/fetch/FetchLoaderClient.h: * Modules/gamepad/Gamepad.cpp: * Modules/gamepad/GamepadEvent.h: * Modules/gamepad/deprecated/Gamepad.cpp: [ truncated ] Source/WebCore/PAL: * pal/Logger.h: (PAL::Logger::Observer::~Observer): Deleted. * pal/crypto/gcrypt/CryptoDigestGCrypt.cpp: * pal/system/SleepDisabler.cpp: * pal/system/SystemSleepListener.h: Canonical link: https://commits.webkit.org/194740@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@223728 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2017-10-19 23:48:45 +00:00
virtual ~PageChannel() = default;
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. 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: Canonical link: https://commits.webkit.org/224279@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261104 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-04 19:51:30 +00:00
virtual void sendMessageFromWorkerToFrontend(WorkerInspectorProxy&, const String&) = 0;
Web Inspector: Introduce Page WorkerAgent and Worker InspectorController https://bugs.webkit.org/show_bug.cgi?id=163817 <rdar://problem/28899063> Reviewed by Brian Burg. Source/JavaScriptCore: * CMakeLists.txt: * DerivedSources.make: * inspector/protocol/Worker.json: Added. New Worker domain. Source/WebCore: Test: inspector/worker/worker-create-and-terminate.html From the perspective of an Inspector frontend, Workers are like a special JavaScript context, separate from the page, that may have its own set of Agents. This patch adds the necessary backend infrastructure to provide WorkerGlobalObject with an InspectorController and the means to communicate with a frontend through a Page's WorkerAgent. Pages now get a WorkerAgent. This informs the frontend about created and terminated Workers. It also provides a communication channel to dispatch and return inspector protocol messages to each of the Workers. The Page side always interacts with the WorkerInspectorProxy on the main thread. The Page's Worker Agent can sends and receives messages to WorkerInspectorControllers. WorkerGlobalScopes now get a WorkerInspectorController which will eventually contain its own set of agents. There are no agents yet, but they will be added individually in follow-up patches. The Worker side always interacts with the WorkerGlobalScope on the worker thread. WorkerInspectorController dispatches messages on its agents. All communication with Worker agents goes through Worker.sendMessageToWorker, which tunnels the command request to the Worker's InspectorController and agents. At the protocol level, worker agent command responses and worker agent events are sent as events through Worker.dispatchMessageFromWorker. On the frontend, the message dispatcher code will pair up replies with their commands, and no-reply messages as events, like normal. So calling worker agent methods in the frontend will be no different from the existing callback/promise-based ways. * CMakeLists.txt: * WebCore.xcodeproj/project.pbxproj: * inspector/InspectorAllInOne.cpp: Add new files. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): (WebCore::WorkerScriptController::initScript): * bindings/js/WorkerScriptController.h: Some cleanup. * inspector/InspectorController.cpp: (WebCore::InspectorController::InspectorController): * inspector/InspectorController.h: * inspector/InstrumentingAgents.cpp: (WebCore::InstrumentingAgents::reset): * inspector/InstrumentingAgents.h: (WebCore::InstrumentingAgents::inspectorWorkerAgent): (WebCore::InstrumentingAgents::setInspectorWorkerAgent): * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::workerStartedImpl): (WebCore::InspectorInstrumentation::workerTerminatedImpl): (WebCore::InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope): * inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::workerStarted): (WebCore::InspectorInstrumentation::workerTerminated): (WebCore::InspectorInstrumentation::instrumentingAgentsForContext): Give the Page a WorkerAgent and Instrumentation methods for Worker creation and termination. * inspector/InspectorWorkerAgent.h: Added. * inspector/InspectorWorkerAgent.cpp: Added. (WebCore::InspectorWorkerAgent::InspectorWorkerAgent): (WebCore::InspectorWorkerAgent::didCreateFrontendAndBackend): (WebCore::InspectorWorkerAgent::willDestroyFrontendAndBackend): (WebCore::InspectorWorkerAgent::enable): (WebCore::InspectorWorkerAgent::disable): (WebCore::InspectorWorkerAgent::workerStarted): (WebCore::InspectorWorkerAgent::workerTerminated): (WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage): (WebCore::InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies): (WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy): (WebCore::InspectorWorkerAgent::disconnectFromWorkerInspectorProxy): Handle connecting to Workers. This performs the "connectFrontend" and "disconnectFrontend" dance with each Worker's InspectorController. We only connect to workers when the Worker domain is enabled. (WebCore::InspectorWorkerAgent::sendMessageToWorker): (WebCore::InspectorWorkerAgent::sendMessageFromWorkerToFrontend): Proxying messages to individual messages happens through the WorkerInspectorProxy. That takes care of passing messages across threads for us. * workers/WorkerInspectorProxy.cpp: Added. (WebCore::WorkerInspectorProxy::allWorkerInspectorProxies): (WebCore::WorkerInspectorProxy::WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::~WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::workerStarted): (WebCore::WorkerInspectorProxy::workerTerminated): (WebCore::WorkerInspectorProxy::connectToWorkerInspector): (WebCore::WorkerInspectorProxy::disconnectFromWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageToWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageFromWorkerToFrontend): * workers/WorkerInspectorProxy.h: Added. (WebCore::WorkerInspectorProxy::PageChannel::~PageChannel): (WebCore::WorkerInspectorProxy::url): (WebCore::WorkerInspectorProxy::identifier): (WebCore::WorkerInspectorProxy::scriptExecutionContext): The WorkerInspectorProxy simplifies the cross thread communication between the Page Inspector and Worker Inspector. It also provides a clean interface between the two sides. * inspector/WorkerToPageFrontendChannel.h: Added. * inspector/WorkerInspectorController.h: Added. * inspector/WorkerInspectorController.cpp: Added. (WebCore::WorkerInspectorController::WorkerInspectorController): (WebCore::WorkerInspectorController::~WorkerInspectorController): (WebCore::WorkerInspectorController::workerTerminating): (WebCore::WorkerInspectorController::connectFrontend): (WebCore::WorkerInspectorController::disconnectFrontend): (WebCore::WorkerInspectorController::dispatchMessageFromFrontend): (WebCore::WorkerInspectorController::functionCallHandler): (WebCore::WorkerInspectorController::evaluateHandler): (WebCore::WorkerInspectorController::vm): A basic InspectorController for a WorkerGlobalScope. No agents yet, they will come soon. * inspector/WorkerScriptDebugServer.h: * inspector/WorkerScriptDebugServer.cpp: (WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer): (WebCore::WorkerScriptDebugServer::attachDebugger): (WebCore::WorkerScriptDebugServer::detachDebugger): (WebCore::WorkerScriptDebugServer::recompileAllJSFunctions): (WebCore::WorkerScriptDebugServer::runEventLoopWhilePaused): (WebCore::WorkerScriptDebugServer::reportException): (WebCore::WorkerScriptDebugServer::interruptAndRunTask): A basic WorkerScriptDebug server for a WorkerGlobalScope. Not really used until we implement DebuggerAgent, but needed for InspectorEnvironment. * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: (WebCore::WorkerGlobalScope::inspectorController): Give the WorkerGlobalScope an InspectorController. * workers/WorkerThread.cpp: (WebCore::WorkerThread::stop): Ensure the Worker InspectorController is immediately on the WorkerThread when it is about to be closed. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::WorkerMessagingProxy): (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): (WebCore::WorkerMessagingProxy::postMessageToPageInspector): (WebCore::WorkerMessagingProxy::workerGlobalScopeDestroyedInternal): (WebCore::WorkerMessagingProxy::terminateWorkerGlobalScope): * workers/WorkerMessagingProxy.h: * workers/WorkerReportingProxy.h: Call into the WorkerInspectorProxy for any inspector related logic, such as creation, termination, and messages received from the Worker. Source/WebInspectorUI: * UserInterface/Main.html: * UserInterface/Test.html: New files. * UserInterface/Base/Main.js: (WebInspector.loaded): * UserInterface/Test/Test.js: (WebInspector.loaded): New Observers and Managers. * UserInterface/Protocol/WorkerObserver.js: Added. (WebInspector.WorkerObserver.prototype.workerCreated): (WebInspector.WorkerObserver.prototype.workerTerminated): (WebInspector.WorkerObserver.prototype.dispatchMessageFromWorker): (WebInspector.WorkerObserver): * UserInterface/Controllers/WorkerManager.js: Added. (WebInspector.WorkerManager): (WebInspector.WorkerManager.prototype.workerCreated): (WebInspector.WorkerManager.prototype.workerTerminated): (WebInspector.WorkerManager.prototype.dispatchMessageFromWorker): To be implemented with the first Worker agent implementation when there is actually something we can do with the Worker. LayoutTests: * inspector/worker/resources/worker-1.js: Added. * inspector/worker/resources/worker-2.js: Added. * inspector/worker/resources/worker-3.js: Added. * inspector/worker/worker-create-and-terminate-expected.txt: Added. * inspector/worker/worker-create-and-terminate.html: Added. Tests for the new Worker domain events. The rest of the Worker domain will be tested as soon as we add the first Agent in Workers. Canonical link: https://commits.webkit.org/181796@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208008 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-27 22:18:55 +00:00
};
static HashSet<WorkerInspectorProxy*>& allWorkerInspectorProxies();
const URL& url() const { return m_url; }
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. 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: Canonical link: https://commits.webkit.org/224279@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261104 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-04 19:51:30 +00:00
const String& name() const { return m_name; }
Web Inspector: Introduce Page WorkerAgent and Worker InspectorController https://bugs.webkit.org/show_bug.cgi?id=163817 <rdar://problem/28899063> Reviewed by Brian Burg. Source/JavaScriptCore: * CMakeLists.txt: * DerivedSources.make: * inspector/protocol/Worker.json: Added. New Worker domain. Source/WebCore: Test: inspector/worker/worker-create-and-terminate.html From the perspective of an Inspector frontend, Workers are like a special JavaScript context, separate from the page, that may have its own set of Agents. This patch adds the necessary backend infrastructure to provide WorkerGlobalObject with an InspectorController and the means to communicate with a frontend through a Page's WorkerAgent. Pages now get a WorkerAgent. This informs the frontend about created and terminated Workers. It also provides a communication channel to dispatch and return inspector protocol messages to each of the Workers. The Page side always interacts with the WorkerInspectorProxy on the main thread. The Page's Worker Agent can sends and receives messages to WorkerInspectorControllers. WorkerGlobalScopes now get a WorkerInspectorController which will eventually contain its own set of agents. There are no agents yet, but they will be added individually in follow-up patches. The Worker side always interacts with the WorkerGlobalScope on the worker thread. WorkerInspectorController dispatches messages on its agents. All communication with Worker agents goes through Worker.sendMessageToWorker, which tunnels the command request to the Worker's InspectorController and agents. At the protocol level, worker agent command responses and worker agent events are sent as events through Worker.dispatchMessageFromWorker. On the frontend, the message dispatcher code will pair up replies with their commands, and no-reply messages as events, like normal. So calling worker agent methods in the frontend will be no different from the existing callback/promise-based ways. * CMakeLists.txt: * WebCore.xcodeproj/project.pbxproj: * inspector/InspectorAllInOne.cpp: Add new files. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): (WebCore::WorkerScriptController::initScript): * bindings/js/WorkerScriptController.h: Some cleanup. * inspector/InspectorController.cpp: (WebCore::InspectorController::InspectorController): * inspector/InspectorController.h: * inspector/InstrumentingAgents.cpp: (WebCore::InstrumentingAgents::reset): * inspector/InstrumentingAgents.h: (WebCore::InstrumentingAgents::inspectorWorkerAgent): (WebCore::InstrumentingAgents::setInspectorWorkerAgent): * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::workerStartedImpl): (WebCore::InspectorInstrumentation::workerTerminatedImpl): (WebCore::InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope): * inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::workerStarted): (WebCore::InspectorInstrumentation::workerTerminated): (WebCore::InspectorInstrumentation::instrumentingAgentsForContext): Give the Page a WorkerAgent and Instrumentation methods for Worker creation and termination. * inspector/InspectorWorkerAgent.h: Added. * inspector/InspectorWorkerAgent.cpp: Added. (WebCore::InspectorWorkerAgent::InspectorWorkerAgent): (WebCore::InspectorWorkerAgent::didCreateFrontendAndBackend): (WebCore::InspectorWorkerAgent::willDestroyFrontendAndBackend): (WebCore::InspectorWorkerAgent::enable): (WebCore::InspectorWorkerAgent::disable): (WebCore::InspectorWorkerAgent::workerStarted): (WebCore::InspectorWorkerAgent::workerTerminated): (WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage): (WebCore::InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies): (WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy): (WebCore::InspectorWorkerAgent::disconnectFromWorkerInspectorProxy): Handle connecting to Workers. This performs the "connectFrontend" and "disconnectFrontend" dance with each Worker's InspectorController. We only connect to workers when the Worker domain is enabled. (WebCore::InspectorWorkerAgent::sendMessageToWorker): (WebCore::InspectorWorkerAgent::sendMessageFromWorkerToFrontend): Proxying messages to individual messages happens through the WorkerInspectorProxy. That takes care of passing messages across threads for us. * workers/WorkerInspectorProxy.cpp: Added. (WebCore::WorkerInspectorProxy::allWorkerInspectorProxies): (WebCore::WorkerInspectorProxy::WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::~WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::workerStarted): (WebCore::WorkerInspectorProxy::workerTerminated): (WebCore::WorkerInspectorProxy::connectToWorkerInspector): (WebCore::WorkerInspectorProxy::disconnectFromWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageToWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageFromWorkerToFrontend): * workers/WorkerInspectorProxy.h: Added. (WebCore::WorkerInspectorProxy::PageChannel::~PageChannel): (WebCore::WorkerInspectorProxy::url): (WebCore::WorkerInspectorProxy::identifier): (WebCore::WorkerInspectorProxy::scriptExecutionContext): The WorkerInspectorProxy simplifies the cross thread communication between the Page Inspector and Worker Inspector. It also provides a clean interface between the two sides. * inspector/WorkerToPageFrontendChannel.h: Added. * inspector/WorkerInspectorController.h: Added. * inspector/WorkerInspectorController.cpp: Added. (WebCore::WorkerInspectorController::WorkerInspectorController): (WebCore::WorkerInspectorController::~WorkerInspectorController): (WebCore::WorkerInspectorController::workerTerminating): (WebCore::WorkerInspectorController::connectFrontend): (WebCore::WorkerInspectorController::disconnectFrontend): (WebCore::WorkerInspectorController::dispatchMessageFromFrontend): (WebCore::WorkerInspectorController::functionCallHandler): (WebCore::WorkerInspectorController::evaluateHandler): (WebCore::WorkerInspectorController::vm): A basic InspectorController for a WorkerGlobalScope. No agents yet, they will come soon. * inspector/WorkerScriptDebugServer.h: * inspector/WorkerScriptDebugServer.cpp: (WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer): (WebCore::WorkerScriptDebugServer::attachDebugger): (WebCore::WorkerScriptDebugServer::detachDebugger): (WebCore::WorkerScriptDebugServer::recompileAllJSFunctions): (WebCore::WorkerScriptDebugServer::runEventLoopWhilePaused): (WebCore::WorkerScriptDebugServer::reportException): (WebCore::WorkerScriptDebugServer::interruptAndRunTask): A basic WorkerScriptDebug server for a WorkerGlobalScope. Not really used until we implement DebuggerAgent, but needed for InspectorEnvironment. * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: (WebCore::WorkerGlobalScope::inspectorController): Give the WorkerGlobalScope an InspectorController. * workers/WorkerThread.cpp: (WebCore::WorkerThread::stop): Ensure the Worker InspectorController is immediately on the WorkerThread when it is about to be closed. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::WorkerMessagingProxy): (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): (WebCore::WorkerMessagingProxy::postMessageToPageInspector): (WebCore::WorkerMessagingProxy::workerGlobalScopeDestroyedInternal): (WebCore::WorkerMessagingProxy::terminateWorkerGlobalScope): * workers/WorkerMessagingProxy.h: * workers/WorkerReportingProxy.h: Call into the WorkerInspectorProxy for any inspector related logic, such as creation, termination, and messages received from the Worker. Source/WebInspectorUI: * UserInterface/Main.html: * UserInterface/Test.html: New files. * UserInterface/Base/Main.js: (WebInspector.loaded): * UserInterface/Test/Test.js: (WebInspector.loaded): New Observers and Managers. * UserInterface/Protocol/WorkerObserver.js: Added. (WebInspector.WorkerObserver.prototype.workerCreated): (WebInspector.WorkerObserver.prototype.workerTerminated): (WebInspector.WorkerObserver.prototype.dispatchMessageFromWorker): (WebInspector.WorkerObserver): * UserInterface/Controllers/WorkerManager.js: Added. (WebInspector.WorkerManager): (WebInspector.WorkerManager.prototype.workerCreated): (WebInspector.WorkerManager.prototype.workerTerminated): (WebInspector.WorkerManager.prototype.dispatchMessageFromWorker): To be implemented with the first Worker agent implementation when there is actually something we can do with the Worker. LayoutTests: * inspector/worker/resources/worker-1.js: Added. * inspector/worker/resources/worker-2.js: Added. * inspector/worker/resources/worker-3.js: Added. * inspector/worker/worker-create-and-terminate-expected.txt: Added. * inspector/worker/worker-create-and-terminate.html: Added. Tests for the new Worker domain events. The rest of the Worker domain will be tested as soon as we add the first Agent in Workers. Canonical link: https://commits.webkit.org/181796@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208008 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-27 22:18:55 +00:00
const String& identifier() const { return m_identifier; }
ScriptExecutionContext* scriptExecutionContext() const { return m_scriptExecutionContext.get(); }
Web Inspector: Use more references in inspector code https://bugs.webkit.org/show_bug.cgi?id=164283 Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-11-01 Reviewed by Timothy Hatcher. (WebCore::frameForScriptExecutionContext): (WebCore::InspectorInstrumentation::didInstallTimerImpl): (WebCore::InspectorInstrumentation::didRemoveTimerImpl): (WebCore::InspectorInstrumentation::willFireTimerImpl): (WebCore::InspectorInstrumentation::didLayoutImpl): (WebCore::InspectorInstrumentation::willPaintImpl): (WebCore::InspectorInstrumentation::didPaintImpl): (WebCore::InspectorInstrumentation::didCommitLoadImpl): (WebCore::InspectorInstrumentation::frameDocumentUpdatedImpl): (WebCore::InspectorInstrumentation::didDispatchDOMStorageEventImpl): (WebCore::InspectorInstrumentation::instrumentingAgentsForRenderer): (WebCore::InspectorInstrumentation::instrumentingAgentsForPage): Deleted. (WebCore::InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope): Deleted. * inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::frameWindowDiscarded): (WebCore::InspectorInstrumentation::didInstallTimer): (WebCore::InspectorInstrumentation::didRemoveTimer): (WebCore::InspectorInstrumentation::willFireTimer): (WebCore::InspectorInstrumentation::didLayout): (WebCore::InspectorInstrumentation::willComposite): (WebCore::InspectorInstrumentation::didComposite): (WebCore::InspectorInstrumentation::willPaint): (WebCore::InspectorInstrumentation::didPaint): (WebCore::InspectorInstrumentation::continueAfterPingLoader): (WebCore::InspectorInstrumentation::scriptImported): (WebCore::InspectorInstrumentation::didCommitLoad): (WebCore::InspectorInstrumentation::frameDocumentUpdated): (WebCore::InspectorInstrumentation::frameStartedLoading): (WebCore::InspectorInstrumentation::frameStoppedLoading): (WebCore::InspectorInstrumentation::frameScheduledNavigation): (WebCore::InspectorInstrumentation::frameClearedScheduledNavigation): (WebCore::InspectorInstrumentation::didDispatchDOMStorageEvent): (WebCore::InspectorInstrumentation::shouldWaitForDebuggerOnStart): (WebCore::InspectorInstrumentation::workerStarted): (WebCore::InspectorInstrumentation::workerTerminated): (WebCore::InspectorInstrumentation::didHandleMemoryPressure): (WebCore::InspectorInstrumentation::networkStateChanged): (WebCore::InspectorInstrumentation::addMessageToConsole): (WebCore::InspectorInstrumentation::consoleCount): (WebCore::InspectorInstrumentation::startConsoleTiming): (WebCore::InspectorInstrumentation::stopConsoleTiming): (WebCore::InspectorInstrumentation::instrumentingAgentsForContext): (WebCore::InspectorInstrumentation::instrumentingAgentsForPage): (WebCore::InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope): Convert to references where possible. * inspector/InspectorCSSAgent.cpp: (WebCore::InspectorCSSAgent::getMatchedStylesForNode): (WebCore::InspectorCSSAgent::buildObjectForRule): (WebCore::InspectorCSSAgent::buildArrayForMatchedRuleList): * inspector/InspectorCSSAgent.h: * inspector/InspectorDOMAgent.cpp: (WebCore::InspectorDOMAgent::frameDocumentUpdated): * inspector/InspectorDOMAgent.h: * inspector/InspectorDOMStorageAgent.cpp: (WebCore::InspectorDOMStorageAgent::didDispatchDOMStorageEvent): * inspector/InspectorDOMStorageAgent.h: * inspector/InspectorInstrumentation.cpp: * inspector/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::frameNavigated): (WebCore::InspectorPageAgent::didPaint): * inspector/InspectorPageAgent.h: * inspector/InspectorReplayAgent.cpp: (WebCore::InspectorReplayAgent::frameNavigated): * inspector/InspectorReplayAgent.h: * inspector/InspectorTimelineAgent.cpp: (WebCore::InspectorTimelineAgent::didLayout): (WebCore::InspectorTimelineAgent::didPaint): * inspector/InspectorTimelineAgent.h: Pass references through InspectorInstrumentation to the Agents. * loader/FrameLoader.cpp: (WebCore::FrameLoader::clear): * page/DOMTimer.cpp: (WebCore::DOMTimer::install): (WebCore::DOMTimer::removeById): (WebCore::DOMTimer::fired): * page/DOMWindow.cpp: (WebCore::DOMWindow::willDetachPage): * page/Frame.cpp: (WebCore::Frame::setDocument): * page/FrameView.cpp: (WebCore::FrameView::layout): (WebCore::FrameView::willPaintContents): (WebCore::FrameView::didPaintContents): * page/Page.cpp: (WebCore::networkStateChanged): * rendering/RenderLayerBacking.cpp: (WebCore::RenderLayerBacking::paintContents): * replay/ReplayController.cpp: (WebCore::ReplayController::frameNavigated): * replay/ReplayController.h: * storage/StorageEventDispatcher.cpp: (WebCore::StorageEventDispatcher::dispatchSessionStorageEventsToFrames): (WebCore::StorageEventDispatcher::dispatchLocalStorageEventsToFrames): * workers/Worker.cpp: (WebCore::Worker::notifyFinished): * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::importScripts): (WebCore::WorkerGlobalScope::addConsoleMessage): (WebCore::WorkerGlobalScope::addMessage): * workers/WorkerInspectorProxy.cpp: (WebCore::WorkerInspectorProxy::workerStartMode): (WebCore::WorkerInspectorProxy::workerStarted): (WebCore::WorkerInspectorProxy::workerTerminated): * workers/WorkerInspectorProxy.h: * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): Pass references to InspectorInstrumentation. Canonical link: https://commits.webkit.org/182009@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208240 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-11-01 21:42:51 +00:00
WorkerThreadStartMode workerStartMode(ScriptExecutionContext&);
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. 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: Canonical link: https://commits.webkit.org/224279@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261104 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-04 19:51:30 +00:00
void workerStarted(ScriptExecutionContext*, WorkerThread*, const URL&, const String& name);
Web Inspector: Introduce Page WorkerAgent and Worker InspectorController https://bugs.webkit.org/show_bug.cgi?id=163817 <rdar://problem/28899063> Reviewed by Brian Burg. Source/JavaScriptCore: * CMakeLists.txt: * DerivedSources.make: * inspector/protocol/Worker.json: Added. New Worker domain. Source/WebCore: Test: inspector/worker/worker-create-and-terminate.html From the perspective of an Inspector frontend, Workers are like a special JavaScript context, separate from the page, that may have its own set of Agents. This patch adds the necessary backend infrastructure to provide WorkerGlobalObject with an InspectorController and the means to communicate with a frontend through a Page's WorkerAgent. Pages now get a WorkerAgent. This informs the frontend about created and terminated Workers. It also provides a communication channel to dispatch and return inspector protocol messages to each of the Workers. The Page side always interacts with the WorkerInspectorProxy on the main thread. The Page's Worker Agent can sends and receives messages to WorkerInspectorControllers. WorkerGlobalScopes now get a WorkerInspectorController which will eventually contain its own set of agents. There are no agents yet, but they will be added individually in follow-up patches. The Worker side always interacts with the WorkerGlobalScope on the worker thread. WorkerInspectorController dispatches messages on its agents. All communication with Worker agents goes through Worker.sendMessageToWorker, which tunnels the command request to the Worker's InspectorController and agents. At the protocol level, worker agent command responses and worker agent events are sent as events through Worker.dispatchMessageFromWorker. On the frontend, the message dispatcher code will pair up replies with their commands, and no-reply messages as events, like normal. So calling worker agent methods in the frontend will be no different from the existing callback/promise-based ways. * CMakeLists.txt: * WebCore.xcodeproj/project.pbxproj: * inspector/InspectorAllInOne.cpp: Add new files. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): (WebCore::WorkerScriptController::initScript): * bindings/js/WorkerScriptController.h: Some cleanup. * inspector/InspectorController.cpp: (WebCore::InspectorController::InspectorController): * inspector/InspectorController.h: * inspector/InstrumentingAgents.cpp: (WebCore::InstrumentingAgents::reset): * inspector/InstrumentingAgents.h: (WebCore::InstrumentingAgents::inspectorWorkerAgent): (WebCore::InstrumentingAgents::setInspectorWorkerAgent): * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::workerStartedImpl): (WebCore::InspectorInstrumentation::workerTerminatedImpl): (WebCore::InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope): * inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::workerStarted): (WebCore::InspectorInstrumentation::workerTerminated): (WebCore::InspectorInstrumentation::instrumentingAgentsForContext): Give the Page a WorkerAgent and Instrumentation methods for Worker creation and termination. * inspector/InspectorWorkerAgent.h: Added. * inspector/InspectorWorkerAgent.cpp: Added. (WebCore::InspectorWorkerAgent::InspectorWorkerAgent): (WebCore::InspectorWorkerAgent::didCreateFrontendAndBackend): (WebCore::InspectorWorkerAgent::willDestroyFrontendAndBackend): (WebCore::InspectorWorkerAgent::enable): (WebCore::InspectorWorkerAgent::disable): (WebCore::InspectorWorkerAgent::workerStarted): (WebCore::InspectorWorkerAgent::workerTerminated): (WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage): (WebCore::InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies): (WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy): (WebCore::InspectorWorkerAgent::disconnectFromWorkerInspectorProxy): Handle connecting to Workers. This performs the "connectFrontend" and "disconnectFrontend" dance with each Worker's InspectorController. We only connect to workers when the Worker domain is enabled. (WebCore::InspectorWorkerAgent::sendMessageToWorker): (WebCore::InspectorWorkerAgent::sendMessageFromWorkerToFrontend): Proxying messages to individual messages happens through the WorkerInspectorProxy. That takes care of passing messages across threads for us. * workers/WorkerInspectorProxy.cpp: Added. (WebCore::WorkerInspectorProxy::allWorkerInspectorProxies): (WebCore::WorkerInspectorProxy::WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::~WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::workerStarted): (WebCore::WorkerInspectorProxy::workerTerminated): (WebCore::WorkerInspectorProxy::connectToWorkerInspector): (WebCore::WorkerInspectorProxy::disconnectFromWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageToWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageFromWorkerToFrontend): * workers/WorkerInspectorProxy.h: Added. (WebCore::WorkerInspectorProxy::PageChannel::~PageChannel): (WebCore::WorkerInspectorProxy::url): (WebCore::WorkerInspectorProxy::identifier): (WebCore::WorkerInspectorProxy::scriptExecutionContext): The WorkerInspectorProxy simplifies the cross thread communication between the Page Inspector and Worker Inspector. It also provides a clean interface between the two sides. * inspector/WorkerToPageFrontendChannel.h: Added. * inspector/WorkerInspectorController.h: Added. * inspector/WorkerInspectorController.cpp: Added. (WebCore::WorkerInspectorController::WorkerInspectorController): (WebCore::WorkerInspectorController::~WorkerInspectorController): (WebCore::WorkerInspectorController::workerTerminating): (WebCore::WorkerInspectorController::connectFrontend): (WebCore::WorkerInspectorController::disconnectFrontend): (WebCore::WorkerInspectorController::dispatchMessageFromFrontend): (WebCore::WorkerInspectorController::functionCallHandler): (WebCore::WorkerInspectorController::evaluateHandler): (WebCore::WorkerInspectorController::vm): A basic InspectorController for a WorkerGlobalScope. No agents yet, they will come soon. * inspector/WorkerScriptDebugServer.h: * inspector/WorkerScriptDebugServer.cpp: (WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer): (WebCore::WorkerScriptDebugServer::attachDebugger): (WebCore::WorkerScriptDebugServer::detachDebugger): (WebCore::WorkerScriptDebugServer::recompileAllJSFunctions): (WebCore::WorkerScriptDebugServer::runEventLoopWhilePaused): (WebCore::WorkerScriptDebugServer::reportException): (WebCore::WorkerScriptDebugServer::interruptAndRunTask): A basic WorkerScriptDebug server for a WorkerGlobalScope. Not really used until we implement DebuggerAgent, but needed for InspectorEnvironment. * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: (WebCore::WorkerGlobalScope::inspectorController): Give the WorkerGlobalScope an InspectorController. * workers/WorkerThread.cpp: (WebCore::WorkerThread::stop): Ensure the Worker InspectorController is immediately on the WorkerThread when it is about to be closed. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::WorkerMessagingProxy): (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): (WebCore::WorkerMessagingProxy::postMessageToPageInspector): (WebCore::WorkerMessagingProxy::workerGlobalScopeDestroyedInternal): (WebCore::WorkerMessagingProxy::terminateWorkerGlobalScope): * workers/WorkerMessagingProxy.h: * workers/WorkerReportingProxy.h: Call into the WorkerInspectorProxy for any inspector related logic, such as creation, termination, and messages received from the Worker. Source/WebInspectorUI: * UserInterface/Main.html: * UserInterface/Test.html: New files. * UserInterface/Base/Main.js: (WebInspector.loaded): * UserInterface/Test/Test.js: (WebInspector.loaded): New Observers and Managers. * UserInterface/Protocol/WorkerObserver.js: Added. (WebInspector.WorkerObserver.prototype.workerCreated): (WebInspector.WorkerObserver.prototype.workerTerminated): (WebInspector.WorkerObserver.prototype.dispatchMessageFromWorker): (WebInspector.WorkerObserver): * UserInterface/Controllers/WorkerManager.js: Added. (WebInspector.WorkerManager): (WebInspector.WorkerManager.prototype.workerCreated): (WebInspector.WorkerManager.prototype.workerTerminated): (WebInspector.WorkerManager.prototype.dispatchMessageFromWorker): To be implemented with the first Worker agent implementation when there is actually something we can do with the Worker. LayoutTests: * inspector/worker/resources/worker-1.js: Added. * inspector/worker/resources/worker-2.js: Added. * inspector/worker/resources/worker-3.js: Added. * inspector/worker/worker-create-and-terminate-expected.txt: Added. * inspector/worker/worker-create-and-terminate.html: Added. Tests for the new Worker domain events. The rest of the Worker domain will be tested as soon as we add the first Agent in Workers. Canonical link: https://commits.webkit.org/181796@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208008 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-27 22:18:55 +00:00
void workerTerminated();
Web Inspector: Include ConsoleAgent in Workers - real console.log support https://bugs.webkit.org/show_bug.cgi?id=163844 <rdar://problem/28903328> Reviewed by Brian Burg. LayoutTests/imported/w3c: * web-platform-tests/fetch/api/policies/csp-blocked-worker-expected.txt: * web-platform-tests/streams/readable-streams/garbage-collection.https-expected.txt: Source/JavaScriptCore: * inspector/protocol/Worker.json: Source/WebCore: Test: inspector/worker/console-basic.html This introduces a real ConsoleAgent in the Worker InspectorController. We no longer need to pass partial ConsoleMessage objects to be logged through the Page, we can just send the full ConsoleMessages to a frontend once it connects to the Worker. In order to guarantee that the Worker InspectorController is properly all Workers will start paused if there is an Inspector attached to the Page. The frontend _must_ call the new Worker.initialized method after sending its setup commands to the Worker. This ensures we get handle all initialization commands (like Agent.enable(), and setting state like breakpoints) before any script executes in the Worker. This mirrors the Inspector.initialized method that does the same thing for JSContext auto-attach of the Main target. In the backend, the wait until initialized state is just running the WorkerThread's RunLoop in a special debugger mode to only process debugger commands until we are ready. This will effectively be the same as pausing so it is generalized into WorkerThread. * CMakeLists.txt: * WebCore.xcodeproj/project.pbxproj: * inspector/InspectorAllInOne.cpp: New files. * inspector/InspectorWorkerAgent.cpp: (WebCore::InspectorWorkerAgent::initialized): (WebCore::InspectorWorkerAgent::shouldWaitForDebuggerOnStart): * inspector/InspectorWorkerAgent.h: Add the new initialized method. This just uses the proxy to send a message to be handled on the Worker Thread and unpause. * inspector/WorkerConsoleAgent.cpp: (WebCore::WorkerConsoleAgent::WorkerConsoleAgent): (WebCore::WorkerConsoleAgent::addInspectedNode): * inspector/WorkerConsoleAgent.h: * inspector/WorkerInspectorController.cpp: (WebCore::WorkerInspectorController::WorkerInspectorController): Add a ConsoleAgent to WorkerInspectorController. * workers/WorkerInspectorProxy.h: * workers/WorkerInspectorProxy.cpp: (WebCore::WorkerInspectorProxy::workerStartMode): (WebCore::WorkerInspectorProxy::resumeWorkerIfPaused): (WebCore::WorkerInspectorProxy::connectToWorkerInspector): (WebCore::WorkerInspectorProxy::disconnectFromWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageToWorkerInspector): Use the debugger mode when sending messages to the WorkerThread. * workers/Worker.cpp: (WebCore::Worker::notifyFinished): * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): (WebCore::WorkerMessagingProxy::postConsoleMessageToWorkerObject): Deleted. * workers/WorkerMessagingProxy.h: * workers/WorkerReportingProxy.h: * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::addConsoleMessage): (WebCore::WorkerGlobalScope::addMessage): * workers/WorkerGlobalScope.h: * workers/WorkerGlobalScopeProxy.h: Remove legacy partial console support. * workers/WorkerRunLoop.h: * workers/WorkerRunLoop.cpp: (WebCore::WorkerRunLoop::debuggerMode): * workers/WorkerThread.h: * workers/WorkerThread.cpp: (WebCore::WorkerThread::workerThread): (WebCore::WorkerThread::startRunningDebuggerTasks): (WebCore::WorkerThread::stopRunningDebuggerTasks): General code for spinning the WorkerThread and only processing debugger (Inspector) commands. Use this when starting the thread to ensure the frontend initializes the Worker's Agents before any JavaScript executes. * page/PageConsoleClient.cpp: * workers/WorkerConsoleClient.cpp: (WebCore::WorkerConsoleClient::count): (WebCore::WorkerConsoleClient::time): (WebCore::WorkerConsoleClient::timeEnd): * inspector/InspectorConsoleInstrumentation.h: Removed. * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::startConsoleTimingImpl): (WebCore::InspectorInstrumentation::stopConsoleTimingImpl): (WebCore::InspectorInstrumentation::shouldWaitForDebuggerOnStartImpl): * inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::shouldWaitForDebuggerOnStart): (WebCore::InspectorInstrumentation::addMessageToConsole): (WebCore::InspectorInstrumentation::consoleCount): (WebCore::InspectorInstrumentation::takeHeapSnapshot): (WebCore::InspectorInstrumentation::startConsoleTiming): (WebCore::InspectorInstrumentation::stopConsoleTiming): (WebCore::InspectorInstrumentation::consoleTimeStamp): (WebCore::InspectorInstrumentation::startProfiling): (WebCore::InspectorInstrumentation::stopProfiling): Implement a few more basic console APIs that required ConsoleAgent. Source/WebInspectorUI: * UserInterface/Protocol/Target.js: (WebInspector.Target.prototype.get ConsoleAgent): (WebInspector.Target.prototype._initializeNonMainTarget): * UserInterface/Protocol/Connection.js: (InspectorBackend.WorkerConnection): Add ConsoleAgent. * UserInterface/Controllers/LogManager.js: (WebInspector.LogManager.prototype.messageWasAdded): (WebInspector.LogManager.prototype.requestClearMessages): Handle ConsoleAgent calls with multiple targets. * UserInterface/Protocol/ConsoleObserver.js: (WebInspector.ConsoleObserver.prototype.messageAdded): Dispatch with the target in case we create Model objects. * UserInterface/Controllers/WorkerManager.js: (WebInspector.WorkerManager.prototype.workerCreated): The frontend must now call "initialized" on Workers after sending our setup messages (enable, set breakpoints, etc). * UserInterface/Protocol/RemoteObject.js: (WebInspector.RemoteObject.prototype.get target): Expose an accessor for tests. * UserInterface/Protocol/LoggingProtocolTracer.js: (WebInspector.LoggingProtocolTracer.prototype._processEntry): Actually output the Exception, useful when debugging failures in tests. LayoutTests: * inspector/console/messageAdded-from-worker-expected.txt: Removed. * inspector/console/messageAdded-from-worker.html: Removed. * inspector/console/resources/worker-console-log.js: Removed. Remove the old partial console in Worker test. * inspector/worker/console-basic-expected.txt: Added. * inspector/worker/console-basic.html: Added. * inspector/worker/resources/worker-console.js: Added. New console in Worker test. * inspector/worker/worker-create-and-terminate.html: The frontend must call initialize on Workers, otherwise they are paused forever. * http/tests/security/contentSecurityPolicy/worker-blob-inherits-csp-expected.txt: * http/tests/security/contentSecurityPolicy/worker-blob-inherits-csp-importScripts-block-aborts-all-subsequent-imports-expected.txt: * http/tests/security/contentSecurityPolicy/worker-connect-src-blocked-expected.txt: * http/tests/security/contentSecurityPolicy/worker-csp-blocks-xhr-redirect-cross-origin-expected.txt: * http/tests/security/contentSecurityPolicy/worker-importscripts-blocked-expected.txt: * http/tests/security/contentSecurityPolicy/worker-multiple-csp-headers-expected.txt: * http/tests/security/contentSecurityPolicy/worker-set-timeout-blocked-expected.txt: * http/tests/websocket/tests/hybi/workers/close-expected.txt: * http/tests/xmlhttprequest/workers/access-control-basic-get-fail-non-simple-expected.txt: * security/contentSecurityPolicy/worker-inherits-blocks-xhr-expected.txt: Rebaseline. We no longer send Worker console messages through the Page, and likewise we don't send them to the WebKit client, so they will no longer appear in test output. Canonical link: https://commits.webkit.org/181798@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208010 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-27 22:19:33 +00:00
void resumeWorkerIfPaused();
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. 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: Canonical link: https://commits.webkit.org/224279@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261104 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-04 19:51:30 +00:00
void connectToWorkerInspectorController(PageChannel&);
Web Inspector: Introduce Page WorkerAgent and Worker InspectorController https://bugs.webkit.org/show_bug.cgi?id=163817 <rdar://problem/28899063> Reviewed by Brian Burg. Source/JavaScriptCore: * CMakeLists.txt: * DerivedSources.make: * inspector/protocol/Worker.json: Added. New Worker domain. Source/WebCore: Test: inspector/worker/worker-create-and-terminate.html From the perspective of an Inspector frontend, Workers are like a special JavaScript context, separate from the page, that may have its own set of Agents. This patch adds the necessary backend infrastructure to provide WorkerGlobalObject with an InspectorController and the means to communicate with a frontend through a Page's WorkerAgent. Pages now get a WorkerAgent. This informs the frontend about created and terminated Workers. It also provides a communication channel to dispatch and return inspector protocol messages to each of the Workers. The Page side always interacts with the WorkerInspectorProxy on the main thread. The Page's Worker Agent can sends and receives messages to WorkerInspectorControllers. WorkerGlobalScopes now get a WorkerInspectorController which will eventually contain its own set of agents. There are no agents yet, but they will be added individually in follow-up patches. The Worker side always interacts with the WorkerGlobalScope on the worker thread. WorkerInspectorController dispatches messages on its agents. All communication with Worker agents goes through Worker.sendMessageToWorker, which tunnels the command request to the Worker's InspectorController and agents. At the protocol level, worker agent command responses and worker agent events are sent as events through Worker.dispatchMessageFromWorker. On the frontend, the message dispatcher code will pair up replies with their commands, and no-reply messages as events, like normal. So calling worker agent methods in the frontend will be no different from the existing callback/promise-based ways. * CMakeLists.txt: * WebCore.xcodeproj/project.pbxproj: * inspector/InspectorAllInOne.cpp: Add new files. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): (WebCore::WorkerScriptController::initScript): * bindings/js/WorkerScriptController.h: Some cleanup. * inspector/InspectorController.cpp: (WebCore::InspectorController::InspectorController): * inspector/InspectorController.h: * inspector/InstrumentingAgents.cpp: (WebCore::InstrumentingAgents::reset): * inspector/InstrumentingAgents.h: (WebCore::InstrumentingAgents::inspectorWorkerAgent): (WebCore::InstrumentingAgents::setInspectorWorkerAgent): * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::workerStartedImpl): (WebCore::InspectorInstrumentation::workerTerminatedImpl): (WebCore::InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope): * inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::workerStarted): (WebCore::InspectorInstrumentation::workerTerminated): (WebCore::InspectorInstrumentation::instrumentingAgentsForContext): Give the Page a WorkerAgent and Instrumentation methods for Worker creation and termination. * inspector/InspectorWorkerAgent.h: Added. * inspector/InspectorWorkerAgent.cpp: Added. (WebCore::InspectorWorkerAgent::InspectorWorkerAgent): (WebCore::InspectorWorkerAgent::didCreateFrontendAndBackend): (WebCore::InspectorWorkerAgent::willDestroyFrontendAndBackend): (WebCore::InspectorWorkerAgent::enable): (WebCore::InspectorWorkerAgent::disable): (WebCore::InspectorWorkerAgent::workerStarted): (WebCore::InspectorWorkerAgent::workerTerminated): (WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage): (WebCore::InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies): (WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy): (WebCore::InspectorWorkerAgent::disconnectFromWorkerInspectorProxy): Handle connecting to Workers. This performs the "connectFrontend" and "disconnectFrontend" dance with each Worker's InspectorController. We only connect to workers when the Worker domain is enabled. (WebCore::InspectorWorkerAgent::sendMessageToWorker): (WebCore::InspectorWorkerAgent::sendMessageFromWorkerToFrontend): Proxying messages to individual messages happens through the WorkerInspectorProxy. That takes care of passing messages across threads for us. * workers/WorkerInspectorProxy.cpp: Added. (WebCore::WorkerInspectorProxy::allWorkerInspectorProxies): (WebCore::WorkerInspectorProxy::WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::~WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::workerStarted): (WebCore::WorkerInspectorProxy::workerTerminated): (WebCore::WorkerInspectorProxy::connectToWorkerInspector): (WebCore::WorkerInspectorProxy::disconnectFromWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageToWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageFromWorkerToFrontend): * workers/WorkerInspectorProxy.h: Added. (WebCore::WorkerInspectorProxy::PageChannel::~PageChannel): (WebCore::WorkerInspectorProxy::url): (WebCore::WorkerInspectorProxy::identifier): (WebCore::WorkerInspectorProxy::scriptExecutionContext): The WorkerInspectorProxy simplifies the cross thread communication between the Page Inspector and Worker Inspector. It also provides a clean interface between the two sides. * inspector/WorkerToPageFrontendChannel.h: Added. * inspector/WorkerInspectorController.h: Added. * inspector/WorkerInspectorController.cpp: Added. (WebCore::WorkerInspectorController::WorkerInspectorController): (WebCore::WorkerInspectorController::~WorkerInspectorController): (WebCore::WorkerInspectorController::workerTerminating): (WebCore::WorkerInspectorController::connectFrontend): (WebCore::WorkerInspectorController::disconnectFrontend): (WebCore::WorkerInspectorController::dispatchMessageFromFrontend): (WebCore::WorkerInspectorController::functionCallHandler): (WebCore::WorkerInspectorController::evaluateHandler): (WebCore::WorkerInspectorController::vm): A basic InspectorController for a WorkerGlobalScope. No agents yet, they will come soon. * inspector/WorkerScriptDebugServer.h: * inspector/WorkerScriptDebugServer.cpp: (WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer): (WebCore::WorkerScriptDebugServer::attachDebugger): (WebCore::WorkerScriptDebugServer::detachDebugger): (WebCore::WorkerScriptDebugServer::recompileAllJSFunctions): (WebCore::WorkerScriptDebugServer::runEventLoopWhilePaused): (WebCore::WorkerScriptDebugServer::reportException): (WebCore::WorkerScriptDebugServer::interruptAndRunTask): A basic WorkerScriptDebug server for a WorkerGlobalScope. Not really used until we implement DebuggerAgent, but needed for InspectorEnvironment. * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: (WebCore::WorkerGlobalScope::inspectorController): Give the WorkerGlobalScope an InspectorController. * workers/WorkerThread.cpp: (WebCore::WorkerThread::stop): Ensure the Worker InspectorController is immediately on the WorkerThread when it is about to be closed. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::WorkerMessagingProxy): (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): (WebCore::WorkerMessagingProxy::postMessageToPageInspector): (WebCore::WorkerMessagingProxy::workerGlobalScopeDestroyedInternal): (WebCore::WorkerMessagingProxy::terminateWorkerGlobalScope): * workers/WorkerMessagingProxy.h: * workers/WorkerReportingProxy.h: Call into the WorkerInspectorProxy for any inspector related logic, such as creation, termination, and messages received from the Worker. Source/WebInspectorUI: * UserInterface/Main.html: * UserInterface/Test.html: New files. * UserInterface/Base/Main.js: (WebInspector.loaded): * UserInterface/Test/Test.js: (WebInspector.loaded): New Observers and Managers. * UserInterface/Protocol/WorkerObserver.js: Added. (WebInspector.WorkerObserver.prototype.workerCreated): (WebInspector.WorkerObserver.prototype.workerTerminated): (WebInspector.WorkerObserver.prototype.dispatchMessageFromWorker): (WebInspector.WorkerObserver): * UserInterface/Controllers/WorkerManager.js: Added. (WebInspector.WorkerManager): (WebInspector.WorkerManager.prototype.workerCreated): (WebInspector.WorkerManager.prototype.workerTerminated): (WebInspector.WorkerManager.prototype.dispatchMessageFromWorker): To be implemented with the first Worker agent implementation when there is actually something we can do with the Worker. LayoutTests: * inspector/worker/resources/worker-1.js: Added. * inspector/worker/resources/worker-2.js: Added. * inspector/worker/resources/worker-3.js: Added. * inspector/worker/worker-create-and-terminate-expected.txt: Added. * inspector/worker/worker-create-and-terminate.html: Added. Tests for the new Worker domain events. The rest of the Worker domain will be tested as soon as we add the first Agent in Workers. Canonical link: https://commits.webkit.org/181796@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208008 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-27 22:18:55 +00:00
void disconnectFromWorkerInspectorController();
void sendMessageToWorkerInspectorController(const String&);
void sendMessageFromWorkerToFrontend(const String&);
private:
RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
RefPtr<WorkerThread> m_workerThread;
String m_identifier;
URL m_url;
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. 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: Canonical link: https://commits.webkit.org/224279@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261104 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-05-04 19:51:30 +00:00
String m_name;
Web Inspector: Introduce Page WorkerAgent and Worker InspectorController https://bugs.webkit.org/show_bug.cgi?id=163817 <rdar://problem/28899063> Reviewed by Brian Burg. Source/JavaScriptCore: * CMakeLists.txt: * DerivedSources.make: * inspector/protocol/Worker.json: Added. New Worker domain. Source/WebCore: Test: inspector/worker/worker-create-and-terminate.html From the perspective of an Inspector frontend, Workers are like a special JavaScript context, separate from the page, that may have its own set of Agents. This patch adds the necessary backend infrastructure to provide WorkerGlobalObject with an InspectorController and the means to communicate with a frontend through a Page's WorkerAgent. Pages now get a WorkerAgent. This informs the frontend about created and terminated Workers. It also provides a communication channel to dispatch and return inspector protocol messages to each of the Workers. The Page side always interacts with the WorkerInspectorProxy on the main thread. The Page's Worker Agent can sends and receives messages to WorkerInspectorControllers. WorkerGlobalScopes now get a WorkerInspectorController which will eventually contain its own set of agents. There are no agents yet, but they will be added individually in follow-up patches. The Worker side always interacts with the WorkerGlobalScope on the worker thread. WorkerInspectorController dispatches messages on its agents. All communication with Worker agents goes through Worker.sendMessageToWorker, which tunnels the command request to the Worker's InspectorController and agents. At the protocol level, worker agent command responses and worker agent events are sent as events through Worker.dispatchMessageFromWorker. On the frontend, the message dispatcher code will pair up replies with their commands, and no-reply messages as events, like normal. So calling worker agent methods in the frontend will be no different from the existing callback/promise-based ways. * CMakeLists.txt: * WebCore.xcodeproj/project.pbxproj: * inspector/InspectorAllInOne.cpp: Add new files. * bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::WorkerScriptController): (WebCore::WorkerScriptController::initScript): * bindings/js/WorkerScriptController.h: Some cleanup. * inspector/InspectorController.cpp: (WebCore::InspectorController::InspectorController): * inspector/InspectorController.h: * inspector/InstrumentingAgents.cpp: (WebCore::InstrumentingAgents::reset): * inspector/InstrumentingAgents.h: (WebCore::InstrumentingAgents::inspectorWorkerAgent): (WebCore::InstrumentingAgents::setInspectorWorkerAgent): * inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::workerStartedImpl): (WebCore::InspectorInstrumentation::workerTerminatedImpl): (WebCore::InspectorInstrumentation::instrumentingAgentsForWorkerGlobalScope): * inspector/InspectorInstrumentation.h: (WebCore::InspectorInstrumentation::workerStarted): (WebCore::InspectorInstrumentation::workerTerminated): (WebCore::InspectorInstrumentation::instrumentingAgentsForContext): Give the Page a WorkerAgent and Instrumentation methods for Worker creation and termination. * inspector/InspectorWorkerAgent.h: Added. * inspector/InspectorWorkerAgent.cpp: Added. (WebCore::InspectorWorkerAgent::InspectorWorkerAgent): (WebCore::InspectorWorkerAgent::didCreateFrontendAndBackend): (WebCore::InspectorWorkerAgent::willDestroyFrontendAndBackend): (WebCore::InspectorWorkerAgent::enable): (WebCore::InspectorWorkerAgent::disable): (WebCore::InspectorWorkerAgent::workerStarted): (WebCore::InspectorWorkerAgent::workerTerminated): (WebCore::InspectorWorkerAgent::connectToAllWorkerInspectorProxiesForPage): (WebCore::InspectorWorkerAgent::disconnectFromAllWorkerInspectorProxies): (WebCore::InspectorWorkerAgent::connectToWorkerInspectorProxy): (WebCore::InspectorWorkerAgent::disconnectFromWorkerInspectorProxy): Handle connecting to Workers. This performs the "connectFrontend" and "disconnectFrontend" dance with each Worker's InspectorController. We only connect to workers when the Worker domain is enabled. (WebCore::InspectorWorkerAgent::sendMessageToWorker): (WebCore::InspectorWorkerAgent::sendMessageFromWorkerToFrontend): Proxying messages to individual messages happens through the WorkerInspectorProxy. That takes care of passing messages across threads for us. * workers/WorkerInspectorProxy.cpp: Added. (WebCore::WorkerInspectorProxy::allWorkerInspectorProxies): (WebCore::WorkerInspectorProxy::WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::~WorkerInspectorProxy): (WebCore::WorkerInspectorProxy::workerStarted): (WebCore::WorkerInspectorProxy::workerTerminated): (WebCore::WorkerInspectorProxy::connectToWorkerInspector): (WebCore::WorkerInspectorProxy::disconnectFromWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageToWorkerInspector): (WebCore::WorkerInspectorProxy::sendMessageFromWorkerToFrontend): * workers/WorkerInspectorProxy.h: Added. (WebCore::WorkerInspectorProxy::PageChannel::~PageChannel): (WebCore::WorkerInspectorProxy::url): (WebCore::WorkerInspectorProxy::identifier): (WebCore::WorkerInspectorProxy::scriptExecutionContext): The WorkerInspectorProxy simplifies the cross thread communication between the Page Inspector and Worker Inspector. It also provides a clean interface between the two sides. * inspector/WorkerToPageFrontendChannel.h: Added. * inspector/WorkerInspectorController.h: Added. * inspector/WorkerInspectorController.cpp: Added. (WebCore::WorkerInspectorController::WorkerInspectorController): (WebCore::WorkerInspectorController::~WorkerInspectorController): (WebCore::WorkerInspectorController::workerTerminating): (WebCore::WorkerInspectorController::connectFrontend): (WebCore::WorkerInspectorController::disconnectFrontend): (WebCore::WorkerInspectorController::dispatchMessageFromFrontend): (WebCore::WorkerInspectorController::functionCallHandler): (WebCore::WorkerInspectorController::evaluateHandler): (WebCore::WorkerInspectorController::vm): A basic InspectorController for a WorkerGlobalScope. No agents yet, they will come soon. * inspector/WorkerScriptDebugServer.h: * inspector/WorkerScriptDebugServer.cpp: (WebCore::WorkerScriptDebugServer::WorkerScriptDebugServer): (WebCore::WorkerScriptDebugServer::attachDebugger): (WebCore::WorkerScriptDebugServer::detachDebugger): (WebCore::WorkerScriptDebugServer::recompileAllJSFunctions): (WebCore::WorkerScriptDebugServer::runEventLoopWhilePaused): (WebCore::WorkerScriptDebugServer::reportException): (WebCore::WorkerScriptDebugServer::interruptAndRunTask): A basic WorkerScriptDebug server for a WorkerGlobalScope. Not really used until we implement DebuggerAgent, but needed for InspectorEnvironment. * workers/WorkerGlobalScope.cpp: (WebCore::WorkerGlobalScope::WorkerGlobalScope): * workers/WorkerGlobalScope.h: (WebCore::WorkerGlobalScope::inspectorController): Give the WorkerGlobalScope an InspectorController. * workers/WorkerThread.cpp: (WebCore::WorkerThread::stop): Ensure the Worker InspectorController is immediately on the WorkerThread when it is about to be closed. * workers/WorkerMessagingProxy.cpp: (WebCore::WorkerMessagingProxy::WorkerMessagingProxy): (WebCore::WorkerMessagingProxy::startWorkerGlobalScope): (WebCore::WorkerMessagingProxy::postMessageToPageInspector): (WebCore::WorkerMessagingProxy::workerGlobalScopeDestroyedInternal): (WebCore::WorkerMessagingProxy::terminateWorkerGlobalScope): * workers/WorkerMessagingProxy.h: * workers/WorkerReportingProxy.h: Call into the WorkerInspectorProxy for any inspector related logic, such as creation, termination, and messages received from the Worker. Source/WebInspectorUI: * UserInterface/Main.html: * UserInterface/Test.html: New files. * UserInterface/Base/Main.js: (WebInspector.loaded): * UserInterface/Test/Test.js: (WebInspector.loaded): New Observers and Managers. * UserInterface/Protocol/WorkerObserver.js: Added. (WebInspector.WorkerObserver.prototype.workerCreated): (WebInspector.WorkerObserver.prototype.workerTerminated): (WebInspector.WorkerObserver.prototype.dispatchMessageFromWorker): (WebInspector.WorkerObserver): * UserInterface/Controllers/WorkerManager.js: Added. (WebInspector.WorkerManager): (WebInspector.WorkerManager.prototype.workerCreated): (WebInspector.WorkerManager.prototype.workerTerminated): (WebInspector.WorkerManager.prototype.dispatchMessageFromWorker): To be implemented with the first Worker agent implementation when there is actually something we can do with the Worker. LayoutTests: * inspector/worker/resources/worker-1.js: Added. * inspector/worker/resources/worker-2.js: Added. * inspector/worker/resources/worker-3.js: Added. * inspector/worker/worker-create-and-terminate-expected.txt: Added. * inspector/worker/worker-create-and-terminate.html: Added. Tests for the new Worker domain events. The rest of the Worker domain will be tested as soon as we add the first Agent in Workers. Canonical link: https://commits.webkit.org/181796@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@208008 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2016-10-27 22:18:55 +00:00
PageChannel* m_pageChannel { nullptr };
};
} // namespace WebCore