5 #include "src/inspector/v8-console-agent-impl.h" 7 #include "src/inspector/protocol/Protocol.h" 8 #include "src/inspector/v8-console-message.h" 9 #include "src/inspector/v8-inspector-impl.h" 10 #include "src/inspector/v8-inspector-session-impl.h" 11 #include "src/inspector/v8-stack-trace-impl.h" 15 namespace ConsoleAgentState {
16 static const char consoleEnabled[] =
"consoleEnabled";
19 V8ConsoleAgentImpl::V8ConsoleAgentImpl(
20 V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel,
21 protocol::DictionaryValue* state)
24 m_frontend(frontendChannel),
27 V8ConsoleAgentImpl::~V8ConsoleAgentImpl() =
default;
29 Response V8ConsoleAgentImpl::enable() {
30 if (m_enabled)
return Response::OK();
31 m_state->setBoolean(ConsoleAgentState::consoleEnabled,
true);
33 m_session->inspector()->enableStackCapturingIfNeeded();
35 return Response::OK();
38 Response V8ConsoleAgentImpl::disable() {
39 if (!m_enabled)
return Response::OK();
40 m_session->inspector()->disableStackCapturingIfNeeded();
41 m_state->setBoolean(ConsoleAgentState::consoleEnabled,
false);
43 return Response::OK();
46 Response V8ConsoleAgentImpl::clearMessages() {
return Response::OK(); }
48 void V8ConsoleAgentImpl::restore() {
49 if (!m_state->booleanProperty(ConsoleAgentState::consoleEnabled,
false))
54 void V8ConsoleAgentImpl::messageAdded(V8ConsoleMessage* message) {
55 if (m_enabled) reportMessage(message,
true);
58 bool V8ConsoleAgentImpl::enabled() {
return m_enabled; }
60 void V8ConsoleAgentImpl::reportAllMessages() {
61 V8ConsoleMessageStorage* storage =
62 m_session->inspector()->ensureConsoleMessageStorage(
63 m_session->contextGroupId());
64 for (
const auto& message : storage->messages()) {
65 if (message->origin() == V8MessageOrigin::kConsole) {
66 if (!reportMessage(message.get(),
false))
return;
71 bool V8ConsoleAgentImpl::reportMessage(V8ConsoleMessage* message,
72 bool generatePreview) {
73 DCHECK_EQ(V8MessageOrigin::kConsole, message->origin());
74 message->reportToFrontend(&m_frontend);
76 return m_session->inspector()->hasConsoleMessageStorage(
77 m_session->contextGroupId());