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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/inspector/V8ConsoleAgentImpl.h ('k') | src/inspector/V8ConsoleMessage.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/inspector/V8ConsoleAgentImpl.cpp
diff --git a/src/inspector/V8ConsoleAgentImpl.cpp b/src/inspector/V8ConsoleAgentImpl.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..02e0b6c6e1ca29f55e2e13618a5fe23db0763823
--- /dev/null
+++ b/src/inspector/V8ConsoleAgentImpl.cpp
@@ -0,0 +1,76 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/inspector/V8ConsoleAgentImpl.h"
+
+#include "src/inspector/V8ConsoleMessage.h"
+#include "src/inspector/V8InspectorImpl.h"
+#include "src/inspector/V8InspectorSessionImpl.h"
+#include "src/inspector/V8StackTraceImpl.h"
+#include "src/inspector/protocol/Protocol.h"
+
+namespace v8_inspector {
+
+namespace ConsoleAgentState {
+static const char consoleEnabled[] = "consoleEnabled";
+}
+
+V8ConsoleAgentImpl::V8ConsoleAgentImpl(
+ V8InspectorSessionImpl* session, protocol::FrontendChannel* frontendChannel,
+ protocol::DictionaryValue* state)
+ : m_session(session),
+ m_state(state),
+ m_frontend(frontendChannel),
+ m_enabled(false) {}
+
+V8ConsoleAgentImpl::~V8ConsoleAgentImpl() {}
+
+void V8ConsoleAgentImpl::enable(ErrorString* errorString) {
+ if (m_enabled) return;
+ m_state->setBoolean(ConsoleAgentState::consoleEnabled, true);
+ m_enabled = true;
+ m_session->inspector()->enableStackCapturingIfNeeded();
+ reportAllMessages();
+}
+
+void V8ConsoleAgentImpl::disable(ErrorString* errorString) {
+ if (!m_enabled) return;
+ m_session->inspector()->disableStackCapturingIfNeeded();
+ m_state->setBoolean(ConsoleAgentState::consoleEnabled, false);
+ m_enabled = false;
+}
+
+void V8ConsoleAgentImpl::clearMessages(ErrorString* errorString) {}
+
+void V8ConsoleAgentImpl::restore() {
+ if (!m_state->booleanProperty(ConsoleAgentState::consoleEnabled, false))
+ return;
+ ErrorString ignored;
+ enable(&ignored);
+}
+
+void V8ConsoleAgentImpl::messageAdded(V8ConsoleMessage* message) {
+ if (m_enabled) reportMessage(message, true);
+}
+
+bool V8ConsoleAgentImpl::enabled() { return m_enabled; }
+
+void V8ConsoleAgentImpl::reportAllMessages() {
+ V8ConsoleMessageStorage* storage =
+ m_session->inspector()->ensureConsoleMessageStorage(
+ m_session->contextGroupId());
+ for (const auto& message : storage->messages()) {
+ if (message->origin() == V8MessageOrigin::kConsole)
+ reportMessage(message.get(), false);
+ }
+}
+
+void V8ConsoleAgentImpl::reportMessage(V8ConsoleMessage* message,
+ bool generatePreview) {
+ DCHECK(message->origin() == V8MessageOrigin::kConsole);
+ message->reportToFrontend(&m_frontend);
+ m_frontend.flush();
+}
+
+} // namespace v8_inspector
« 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