OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/inspector/v8-console-agent-impl.h" | 5 #include "src/inspector/v8-console-agent-impl.h" |
6 | 6 |
7 #include "src/inspector/protocol/Protocol.h" | 7 #include "src/inspector/protocol/Protocol.h" |
8 #include "src/inspector/v8-console-message.h" | 8 #include "src/inspector/v8-console-message.h" |
9 #include "src/inspector/v8-inspector-impl.h" | 9 #include "src/inspector/v8-inspector-impl.h" |
10 #include "src/inspector/v8-inspector-session-impl.h" | 10 #include "src/inspector/v8-inspector-session-impl.h" |
11 #include "src/inspector/v8-stack-trace-impl.h" | 11 #include "src/inspector/v8-stack-trace-impl.h" |
12 | 12 |
13 namespace v8_inspector { | 13 namespace v8_inspector { |
14 | 14 |
15 namespace ConsoleAgentState { | 15 namespace ConsoleAgentState { |
16 static const char consoleEnabled[] = "consoleEnabled"; | 16 static const char consoleEnabled[] = "consoleEnabled"; |
17 } | 17 } |
18 | 18 |
19 V8ConsoleAgentImpl::V8ConsoleAgentImpl( | 19 V8ConsoleAgentImpl::V8ConsoleAgentImpl( |
20 V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel, | 20 V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel, |
21 protocol::DictionaryValue* state) | 21 protocol::DictionaryValue* state) |
22 : m_session(session), | 22 : m_session(session), |
23 m_state(state), | 23 m_state(state), |
24 m_frontend(frontendChannel), | 24 m_frontend(frontendChannel), |
25 m_enabled(false) {} | 25 m_enabled(false) {} |
26 | 26 |
27 V8ConsoleAgentImpl::~V8ConsoleAgentImpl() {} | 27 V8ConsoleAgentImpl::~V8ConsoleAgentImpl() {} |
28 | 28 |
29 void V8ConsoleAgentImpl::enable(ErrorString* errorString) { | 29 Response V8ConsoleAgentImpl::enable() { |
30 if (m_enabled) return; | 30 if (m_enabled) return Response::OK(); |
31 m_state->setBoolean(ConsoleAgentState::consoleEnabled, true); | 31 m_state->setBoolean(ConsoleAgentState::consoleEnabled, true); |
32 m_enabled = true; | 32 m_enabled = true; |
33 m_session->inspector()->enableStackCapturingIfNeeded(); | 33 m_session->inspector()->enableStackCapturingIfNeeded(); |
34 reportAllMessages(); | 34 reportAllMessages(); |
| 35 return Response::OK(); |
35 } | 36 } |
36 | 37 |
37 void V8ConsoleAgentImpl::disable(ErrorString* errorString) { | 38 Response V8ConsoleAgentImpl::disable() { |
38 if (!m_enabled) return; | 39 if (!m_enabled) return Response::OK(); |
39 m_session->inspector()->disableStackCapturingIfNeeded(); | 40 m_session->inspector()->disableStackCapturingIfNeeded(); |
40 m_state->setBoolean(ConsoleAgentState::consoleEnabled, false); | 41 m_state->setBoolean(ConsoleAgentState::consoleEnabled, false); |
41 m_enabled = false; | 42 m_enabled = false; |
| 43 return Response::OK(); |
42 } | 44 } |
43 | 45 |
44 void V8ConsoleAgentImpl::clearMessages(ErrorString* errorString) {} | 46 Response V8ConsoleAgentImpl::clearMessages() { return Response::OK(); } |
45 | 47 |
46 void V8ConsoleAgentImpl::restore() { | 48 void V8ConsoleAgentImpl::restore() { |
47 if (!m_state->booleanProperty(ConsoleAgentState::consoleEnabled, false)) | 49 if (!m_state->booleanProperty(ConsoleAgentState::consoleEnabled, false)) |
48 return; | 50 return; |
49 ErrorString ignored; | 51 enable(); |
50 enable(&ignored); | |
51 } | 52 } |
52 | 53 |
53 void V8ConsoleAgentImpl::messageAdded(V8ConsoleMessage* message) { | 54 void V8ConsoleAgentImpl::messageAdded(V8ConsoleMessage* message) { |
54 if (m_enabled) reportMessage(message, true); | 55 if (m_enabled) reportMessage(message, true); |
55 } | 56 } |
56 | 57 |
57 bool V8ConsoleAgentImpl::enabled() { return m_enabled; } | 58 bool V8ConsoleAgentImpl::enabled() { return m_enabled; } |
58 | 59 |
59 void V8ConsoleAgentImpl::reportAllMessages() { | 60 void V8ConsoleAgentImpl::reportAllMessages() { |
60 V8ConsoleMessageStorage* storage = | 61 V8ConsoleMessageStorage* storage = |
61 m_session->inspector()->ensureConsoleMessageStorage( | 62 m_session->inspector()->ensureConsoleMessageStorage( |
62 m_session->contextGroupId()); | 63 m_session->contextGroupId()); |
63 for (const auto& message : storage->messages()) { | 64 for (const auto& message : storage->messages()) { |
64 if (message->origin() == V8MessageOrigin::kConsole) { | 65 if (message->origin() == V8MessageOrigin::kConsole) { |
65 if (!reportMessage(message.get(), false)) return; | 66 if (!reportMessage(message.get(), false)) return; |
66 } | 67 } |
67 } | 68 } |
68 } | 69 } |
69 | 70 |
70 bool V8ConsoleAgentImpl::reportMessage(V8ConsoleMessage* message, | 71 bool V8ConsoleAgentImpl::reportMessage(V8ConsoleMessage* message, |
71 bool generatePreview) { | 72 bool generatePreview) { |
72 DCHECK(message->origin() == V8MessageOrigin::kConsole); | 73 DCHECK(message->origin() == V8MessageOrigin::kConsole); |
73 message->reportToFrontend(&m_frontend); | 74 message->reportToFrontend(&m_frontend); |
74 m_frontend.flush(); | 75 m_frontend.flush(); |
75 return m_session->inspector()->hasConsoleMessageStorage( | 76 return m_session->inspector()->hasConsoleMessageStorage( |
76 m_session->contextGroupId()); | 77 m_session->contextGroupId()); |
77 } | 78 } |
78 | 79 |
79 } // namespace v8_inspector | 80 } // namespace v8_inspector |
OLD | NEW |