Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1201)

Side by Side Diff: src/inspector/V8ConsoleAgentImpl.cpp

Issue 2292573002: [inspector] Initial import of v8_inspector. (Closed)
Patch Set: format the code, disable cpplint Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/inspector/V8ConsoleAgentImpl.h ('k') | src/inspector/V8ConsoleMessage.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "src/inspector/V8ConsoleAgentImpl.h"
6
7 #include "src/inspector/V8ConsoleMessage.h"
8 #include "src/inspector/V8InspectorImpl.h"
9 #include "src/inspector/V8InspectorSessionImpl.h"
10 #include "src/inspector/V8StackTraceImpl.h"
11 #include "src/inspector/protocol/Protocol.h"
12
13 namespace v8_inspector {
14
15 namespace ConsoleAgentState {
16 static const char consoleEnabled[] = "consoleEnabled";
17 }
18
19 V8ConsoleAgentImpl::V8ConsoleAgentImpl(
20 V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel,
21 protocol::DictionaryValue* state)
22 : m_session(session),
23 m_state(state),
24 m_frontend(frontendChannel),
25 m_enabled(false) {}
26
27 V8ConsoleAgentImpl::~V8ConsoleAgentImpl() {}
28
29 void V8ConsoleAgentImpl::enable(ErrorString* errorString) {
30 if (m_enabled) return;
31 m_state->setBoolean(ConsoleAgentState::consoleEnabled, true);
32 m_enabled = true;
33 m_session->inspector()->enableStackCapturingIfNeeded();
34 reportAllMessages();
35 }
36
37 void V8ConsoleAgentImpl::disable(ErrorString* errorString) {
38 if (!m_enabled) return;
39 m_session->inspector()->disableStackCapturingIfNeeded();
40 m_state->setBoolean(ConsoleAgentState::consoleEnabled, false);
41 m_enabled = false;
42 }
43
44 void V8ConsoleAgentImpl::clearMessages(ErrorString* errorString) {}
45
46 void V8ConsoleAgentImpl::restore() {
47 if (!m_state->booleanProperty(ConsoleAgentState::consoleEnabled, false))
48 return;
49 ErrorString ignored;
50 enable(&ignored);
51 }
52
53 void V8ConsoleAgentImpl::messageAdded(V8ConsoleMessage* message) {
54 if (m_enabled) reportMessage(message, true);
55 }
56
57 bool V8ConsoleAgentImpl::enabled() { return m_enabled; }
58
59 void V8ConsoleAgentImpl::reportAllMessages() {
60 V8ConsoleMessageStorage* storage =
61 m_session->inspector()->ensureConsoleMessageStorage(
62 m_session->contextGroupId());
63 for (const auto& message : storage->messages()) {
64 if (message->origin() == V8MessageOrigin::kConsole)
65 reportMessage(message.get(), false);
66 }
67 }
68
69 void V8ConsoleAgentImpl::reportMessage(V8ConsoleMessage* message,
70 bool generatePreview) {
71 DCHECK(message->origin() == V8MessageOrigin::kConsole);
72 message->reportToFrontend(&m_frontend);
73 m_frontend.flush();
74 }
75
76 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/V8ConsoleAgentImpl.h ('k') | src/inspector/V8ConsoleMessage.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698