diff options
Diffstat (limited to 'Source/WebCore/inspector/WorkerInspectorController.cpp')
-rw-r--r-- | Source/WebCore/inspector/WorkerInspectorController.cpp | 207 |
1 files changed, 94 insertions, 113 deletions
diff --git a/Source/WebCore/inspector/WorkerInspectorController.cpp b/Source/WebCore/inspector/WorkerInspectorController.cpp index 749c88152..d4aa76d63 100644 --- a/Source/WebCore/inspector/WorkerInspectorController.cpp +++ b/Source/WebCore/inspector/WorkerInspectorController.cpp @@ -1,152 +1,144 @@ /* - * Copyright (C) 2011 Google Inc. All rights reserved. + * 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: + * 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. * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * 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. - * * Neither the name of Google Inc. nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT - * OWNER OR 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. + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" - -#if ENABLE(INSPECTOR) - #include "WorkerInspectorController.h" #include "CommandLineAPIHost.h" -#include "InspectorClient.h" -#include "InspectorConsoleAgent.h" -#include "InspectorForwarding.h" -#include "InspectorHeapProfilerAgent.h" -#include "InspectorInstrumentation.h" -#include "InspectorProfilerAgent.h" -#include "InspectorTimelineAgent.h" -#include "InspectorWebBackendDispatchers.h" -#include "InspectorWebFrontendDispatchers.h" #include "InstrumentingAgents.h" #include "JSMainThreadExecState.h" -#include "PageInjectedScriptHost.h" -#include "PageInjectedScriptManager.h" +#include "WebHeapAgent.h" +#include "WebInjectedScriptHost.h" +#include "WebInjectedScriptManager.h" #include "WorkerConsoleAgent.h" #include "WorkerDebuggerAgent.h" #include "WorkerGlobalScope.h" -#include "WorkerReportingProxy.h" #include "WorkerRuntimeAgent.h" #include "WorkerThread.h" +#include "WorkerToPageFrontendChannel.h" +#include <inspector/InspectorAgentBase.h> #include <inspector/InspectorBackendDispatcher.h> +#include <inspector/InspectorFrontendChannel.h> +#include <inspector/InspectorFrontendDispatchers.h> +#include <inspector/InspectorFrontendRouter.h> +using namespace JSC; using namespace Inspector; namespace WebCore { -namespace { - -class PageInspectorProxy : public InspectorFrontendChannel { - WTF_MAKE_FAST_ALLOCATED; -public: - explicit PageInspectorProxy(WorkerGlobalScope& workerGlobalScope) - : m_workerGlobalScope(workerGlobalScope) { } - virtual ~PageInspectorProxy() { } -private: - virtual bool sendMessageToFrontend(const String& message) override - { - m_workerGlobalScope.thread()->workerReportingProxy().postMessageToPageInspector(message); - return true; - } - WorkerGlobalScope& m_workerGlobalScope; -}; - -} - WorkerInspectorController::WorkerInspectorController(WorkerGlobalScope& workerGlobalScope) - : m_workerGlobalScope(workerGlobalScope) - , m_instrumentingAgents(InstrumentingAgents::create(*this)) - , m_injectedScriptManager(std::make_unique<PageInjectedScriptManager>(*this, PageInjectedScriptHost::create())) - , m_runtimeAgent(nullptr) + : m_instrumentingAgents(InstrumentingAgents::create(*this)) + , m_injectedScriptManager(std::make_unique<WebInjectedScriptManager>(*this, WebInjectedScriptHost::create())) + , m_frontendRouter(FrontendRouter::create()) + , m_backendDispatcher(BackendDispatcher::create(m_frontendRouter.copyRef())) + , m_executionStopwatch(Stopwatch::create()) + , m_scriptDebugServer(workerGlobalScope) + , m_workerGlobalScope(workerGlobalScope) { - auto runtimeAgent = std::make_unique<WorkerRuntimeAgent>(m_injectedScriptManager.get(), &workerGlobalScope); - m_runtimeAgent = runtimeAgent.get(); - m_instrumentingAgents->setWorkerRuntimeAgent(m_runtimeAgent); - m_agents.append(std::move(runtimeAgent)); + AgentContext baseContext = { + *this, + *m_injectedScriptManager, + m_frontendRouter.get(), + m_backendDispatcher.get(), + }; - auto consoleAgent = std::make_unique<WorkerConsoleAgent>(m_instrumentingAgents.get(), m_injectedScriptManager.get()); - auto debuggerAgent = std::make_unique<WorkerDebuggerAgent>(m_injectedScriptManager.get(), m_instrumentingAgents.get(), &workerGlobalScope); - m_runtimeAgent->setScriptDebugServer(&debuggerAgent->scriptDebugServer()); - m_agents.append(std::move(debuggerAgent)); + WebAgentContext webContext = { + baseContext, + m_instrumentingAgents.get(), + }; - m_agents.append(InspectorProfilerAgent::create(m_instrumentingAgents.get(), consoleAgent.get(), &workerGlobalScope, m_injectedScriptManager.get())); - m_agents.append(std::make_unique<InspectorHeapProfilerAgent>(m_instrumentingAgents.get(), m_injectedScriptManager.get())); - m_agents.append(std::make_unique<InspectorTimelineAgent>(m_instrumentingAgents.get(), nullptr, nullptr, InspectorTimelineAgent::WorkerInspector, nullptr)); - m_agents.append(std::move(consoleAgent)); + WorkerAgentContext workerContext = { + webContext, + workerGlobalScope, + }; + + auto heapAgent = std::make_unique<WebHeapAgent>(workerContext); + + m_agents.append(std::make_unique<WorkerRuntimeAgent>(workerContext)); + m_agents.append(std::make_unique<WorkerDebuggerAgent>(workerContext)); + + auto consoleAgent = std::make_unique<WorkerConsoleAgent>(workerContext, heapAgent.get()); + m_instrumentingAgents->setWebConsoleAgent(consoleAgent.get()); + m_agents.append(WTFMove(consoleAgent)); + + m_agents.append(WTFMove(heapAgent)); if (CommandLineAPIHost* commandLineAPIHost = m_injectedScriptManager->commandLineAPIHost()) { - commandLineAPIHost->init(nullptr - , nullptr - , nullptr - , nullptr -#if ENABLE(SQL_DATABASE) - , nullptr -#endif + commandLineAPIHost->init( + nullptr // InspectorAgent + , m_instrumentingAgents->webConsoleAgent() + , nullptr // InspectorDOMAgent + , nullptr // InspectorDOMStorageAgent + , nullptr // InspectorDatabaseAgent ); } } - + WorkerInspectorController::~WorkerInspectorController() { + ASSERT(!m_frontendRouter->hasFrontends()); + ASSERT(!m_forwardingChannel); + m_instrumentingAgents->reset(); - disconnectFrontend(InspectorDisconnectReason::InspectedTargetDestroyed); +} + +void WorkerInspectorController::workerTerminating() +{ + m_injectedScriptManager->disconnect(); + + disconnectFrontend(Inspector::DisconnectReason::InspectedTargetDestroyed); + + m_agents.discardValues(); } void WorkerInspectorController::connectFrontend() { - ASSERT(!m_frontendChannel); - m_frontendChannel = std::make_unique<PageInspectorProxy>(m_workerGlobalScope); - m_backendDispatcher = InspectorBackendDispatcher::create(m_frontendChannel.get()); - m_agents.didCreateFrontendAndBackend(m_frontendChannel.get(), m_backendDispatcher.get()); + ASSERT(!m_frontendRouter->hasFrontends()); + ASSERT(!m_forwardingChannel); + + m_forwardingChannel = std::make_unique<WorkerToPageFrontendChannel>(m_workerGlobalScope); + m_frontendRouter->connectFrontend(m_forwardingChannel.get()); + m_agents.didCreateFrontendAndBackend(&m_frontendRouter.get(), &m_backendDispatcher.get()); } -void WorkerInspectorController::disconnectFrontend(InspectorDisconnectReason reason) +void WorkerInspectorController::disconnectFrontend(Inspector::DisconnectReason reason) { - if (!m_frontendChannel) + if (!m_frontendRouter->hasFrontends()) return; + ASSERT(m_forwardingChannel); + m_agents.willDestroyFrontendAndBackend(reason); - m_backendDispatcher->clearFrontend(); - m_backendDispatcher.clear(); - m_frontendChannel = nullptr; + m_frontendRouter->disconnectFrontend(m_forwardingChannel.get()); + m_forwardingChannel = nullptr; } void WorkerInspectorController::dispatchMessageFromFrontend(const String& message) { - if (m_backendDispatcher) - m_backendDispatcher->dispatch(message); -} - -void WorkerInspectorController::resume() -{ - ErrorString unused; - m_runtimeAgent->run(&unused); + m_backendDispatcher->dispatch(message); } InspectorFunctionCallHandler WorkerInspectorController::functionCallHandler() const @@ -159,20 +151,9 @@ InspectorEvaluateHandler WorkerInspectorController::evaluateHandler() const return WebCore::evaluateHandlerFromAnyThread; } -void WorkerInspectorController::willCallInjectedScriptFunction(JSC::ExecState* scriptState, const String& scriptName, int scriptLine) -{ - ScriptExecutionContext* scriptExecutionContext = scriptExecutionContextFromExecState(scriptState); - InspectorInstrumentationCookie cookie = InspectorInstrumentation::willCallFunction(scriptExecutionContext, scriptName, scriptLine); - m_injectedScriptInstrumentationCookies.append(cookie); -} - -void WorkerInspectorController::didCallInjectedScriptFunction() +VM& WorkerInspectorController::vm() { - ASSERT(!m_injectedScriptInstrumentationCookies.isEmpty()); - InspectorInstrumentationCookie cookie = m_injectedScriptInstrumentationCookies.takeLast(); - InspectorInstrumentation::didCallFunction(cookie); + return m_workerGlobalScope.vm(); } } // namespace WebCore - -#endif // ENABLE(INSPECTOR) |