#include "config.h"
#include "JSGlobalObjectInspectorController.h"
-#if ENABLE(INSPECTOR)
-
#include "Completion.h"
+#include "ConsoleMessage.h"
#include "ErrorHandlingScope.h"
+#include "Exception.h"
#include "InjectedScriptHost.h"
#include "InjectedScriptManager.h"
#include "InspectorAgent.h"
#include "InspectorBackendDispatcher.h"
#include "InspectorFrontendChannel.h"
-#include "JSConsoleClient.h"
#include "JSGlobalObject.h"
#include "JSGlobalObjectConsoleAgent.h"
+#include "JSGlobalObjectConsoleClient.h"
#include "JSGlobalObjectDebuggerAgent.h"
-#include "JSGlobalObjectProfilerAgent.h"
#include "JSGlobalObjectRuntimeAgent.h"
#include "ScriptArguments.h"
#include "ScriptCallStack.h"
#include "ScriptCallStackFactory.h"
+#include <wtf/Stopwatch.h>
+
#include <cxxabi.h>
+#if OS(DARWIN) || (OS(LINUX) && !PLATFORM(GTK))
#include <dlfcn.h>
#include <execinfo.h>
+#endif
#if ENABLE(REMOTE_INSPECTOR)
#include "JSGlobalObjectDebuggable.h"
JSGlobalObjectInspectorController::JSGlobalObjectInspectorController(JSGlobalObject& globalObject)
: m_globalObject(globalObject)
, m_injectedScriptManager(std::make_unique<InjectedScriptManager>(*this, InjectedScriptHost::create()))
- , m_inspectorFrontendChannel(nullptr)
+ , m_frontendChannel(nullptr)
+ , m_executionStopwatch(Stopwatch::create())
, m_includeNativeCallStackWithExceptions(true)
+ , m_isAutomaticInspection(false)
+#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
+ , m_augmentingClient(nullptr)
+#endif
{
+ auto inspectorAgent = std::make_unique<InspectorAgent>(*this);
auto runtimeAgent = std::make_unique<JSGlobalObjectRuntimeAgent>(m_injectedScriptManager.get(), m_globalObject);
auto consoleAgent = std::make_unique<JSGlobalObjectConsoleAgent>(m_injectedScriptManager.get());
auto debuggerAgent = std::make_unique<JSGlobalObjectDebuggerAgent>(m_injectedScriptManager.get(), m_globalObject, consoleAgent.get());
- auto profilerAgent = std::make_unique<JSGlobalObjectProfilerAgent>(m_globalObject);
+ m_inspectorAgent = inspectorAgent.get();
+ m_debuggerAgent = debuggerAgent.get();
m_consoleAgent = consoleAgent.get();
- m_consoleClient = std::make_unique<JSConsoleClient>(m_consoleAgent, profilerAgent.get());
+ m_consoleClient = std::make_unique<JSGlobalObjectConsoleClient>(m_consoleAgent);
runtimeAgent->setScriptDebugServer(&debuggerAgent->scriptDebugServer());
- profilerAgent->setScriptDebugServer(&debuggerAgent->scriptDebugServer());
- m_agents.append(std::make_unique<InspectorAgent>());
+ m_agents.append(WTF::move(inspectorAgent));
m_agents.append(WTF::move(runtimeAgent));
m_agents.append(WTF::move(consoleAgent));
m_agents.append(WTF::move(debuggerAgent));
+
+ m_executionStopwatch->start();
}
JSGlobalObjectInspectorController::~JSGlobalObjectInspectorController()
void JSGlobalObjectInspectorController::globalObjectDestroyed()
{
- disconnectFrontend(InspectorDisconnectReason::InspectedTargetDestroyed);
+ disconnectFrontend(DisconnectReason::InspectedTargetDestroyed);
m_injectedScriptManager->disconnect();
}
-void JSGlobalObjectInspectorController::connectFrontend(InspectorFrontendChannel* frontendChannel)
+void JSGlobalObjectInspectorController::connectFrontend(FrontendChannel* frontendChannel, bool isAutomaticInspection)
{
- ASSERT(!m_inspectorFrontendChannel);
- ASSERT(!m_inspectorBackendDispatcher);
+ ASSERT(!m_frontendChannel);
+ ASSERT(!m_backendDispatcher);
- m_inspectorFrontendChannel = frontendChannel;
- m_inspectorBackendDispatcher = InspectorBackendDispatcher::create(frontendChannel);
+ m_isAutomaticInspection = isAutomaticInspection;
- m_agents.didCreateFrontendAndBackend(frontendChannel, m_inspectorBackendDispatcher.get());
+ m_frontendChannel = frontendChannel;
+ m_backendDispatcher = BackendDispatcher::create(frontendChannel);
+
+ m_agents.didCreateFrontendAndBackend(frontendChannel, m_backendDispatcher.get());
+
+#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
+ m_inspectorAgent->activateExtraDomains(m_agents.extraDomains());
+
+ if (m_augmentingClient)
+ m_augmentingClient->inspectorConnected();
+#endif
}
-void JSGlobalObjectInspectorController::disconnectFrontend(InspectorDisconnectReason reason)
+void JSGlobalObjectInspectorController::disconnectFrontend(DisconnectReason reason)
{
- if (!m_inspectorFrontendChannel)
+ if (!m_frontendChannel)
return;
m_agents.willDestroyFrontendAndBackend(reason);
- m_inspectorBackendDispatcher->clearFrontend();
- m_inspectorBackendDispatcher.clear();
- m_inspectorFrontendChannel = nullptr;
+ m_backendDispatcher->clearFrontend();
+ m_backendDispatcher = nullptr;
+ m_frontendChannel = nullptr;
+
+ m_isAutomaticInspection = false;
+
+#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
+ if (m_augmentingClient)
+ m_augmentingClient->inspectorDisconnected();
+#endif
}
void JSGlobalObjectInspectorController::dispatchMessageFromFrontend(const String& message)
{
- if (m_inspectorBackendDispatcher)
- m_inspectorBackendDispatcher->dispatch(message);
+ if (m_backendDispatcher)
+ m_backendDispatcher->dispatch(message);
+}
+
+void JSGlobalObjectInspectorController::pause()
+{
+ if (!m_frontendChannel)
+ return;
+
+ ErrorString dummyError;
+ m_debuggerAgent->enable(dummyError);
+ m_debuggerAgent->pause(dummyError);
}
void JSGlobalObjectInspectorController::appendAPIBacktrace(ScriptCallStack* callStack)
{
+#if OS(DARWIN) || (OS(LINUX) && !PLATFORM(GTK))
static const int framesToShow = 31;
static const int framesToSkip = 3; // WTFGetBacktrace, appendAPIBacktrace, reportAPIException.
callStack->append(ScriptCallFrame(ASCIILiteral("?"), ASCIILiteral("[native code]"), 0, 0));
free(cxaDemangled);
}
+#else
+ UNUSED_PARAM(callStack);
+#endif
}
-void JSGlobalObjectInspectorController::reportAPIException(ExecState* exec, JSValue exception)
+void JSGlobalObjectInspectorController::reportAPIException(ExecState* exec, Exception* exception)
{
if (isTerminatedExecutionException(exception))
return;
// FIXME: <http://webkit.org/b/115087> Web Inspector: Should not evaluate JavaScript handling exceptions
// If this is a custom exception object, call toString on it to try and get a nice string representation for the exception.
- String errorMessage = exception.toString(exec)->value(exec);
+ String errorMessage = exception->value().toString(exec)->value(exec);
exec->clearException();
- if (JSConsoleClient::logToSystemConsole()) {
+ if (JSGlobalObjectConsoleClient::logToSystemConsole()) {
if (callStack->size()) {
const ScriptCallFrame& callFrame = callStack->at(0);
ConsoleClient::printConsoleMessage(MessageSource::JS, MessageType::Log, MessageLevel::Error, errorMessage, callFrame.sourceURL(), callFrame.lineNumber(), callFrame.columnNumber());
ConsoleClient::printConsoleMessage(MessageSource::JS, MessageType::Log, MessageLevel::Error, errorMessage, String(), 0, 0);
}
- m_consoleAgent->addMessageToConsole(MessageSource::JS, MessageType::Log, MessageLevel::Error, errorMessage, callStack);
+ m_consoleAgent->addMessageToConsole(std::make_unique<ConsoleMessage>(MessageSource::JS, MessageType::Log, MessageLevel::Error, errorMessage, callStack));
}
ConsoleClient* JSGlobalObjectInspectorController::consoleClient() const
bool JSGlobalObjectInspectorController::developerExtrasEnabled() const
{
#if ENABLE(REMOTE_INSPECTOR)
- if (!RemoteInspector::shared().enabled())
+ if (!RemoteInspector::singleton().enabled())
return false;
if (!m_globalObject.inspectorDebuggable().remoteDebuggingAllowed())
return JSC::evaluate;
}
+void JSGlobalObjectInspectorController::frontendInitialized()
+{
+#if ENABLE(REMOTE_INSPECTOR)
+ if (m_isAutomaticInspection)
+ m_globalObject.inspectorDebuggable().unpauseForInitializedInspector();
+#endif
+}
+
+Ref<Stopwatch> JSGlobalObjectInspectorController::executionStopwatch()
+{
+ return m_executionStopwatch.copyRef();
+}
+
+#if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS)
+void JSGlobalObjectInspectorController::appendExtraAgent(std::unique_ptr<InspectorAgentBase> agent)
+{
+ String domainName = agent->domainName();
+
+ if (m_frontendChannel)
+ agent->didCreateFrontendAndBackend(m_frontendChannel, m_backendDispatcher.get());
+
+ m_agents.appendExtraAgent(WTF::move(agent));
+
+ if (m_frontendChannel)
+ m_inspectorAgent->activateExtraDomain(domainName);
+}
+#endif
+
} // namespace Inspector
-#endif // ENABLE(INSPECTOR)