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

Side by Side Diff: third_party/WebKit/Source/core/frame/ConsoleBase.cpp

Issue 1859293002: [DevTools] Move Console to v8_inspector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 12 matching lines...) Expand all
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "core/frame/Console.h" 29 #include "core/frame/Console.h"
30 30
31 #include "bindings/core/v8/ScriptCallStack.h" 31 #include "bindings/core/v8/ScriptCallStack.h"
32 #include "core/inspector/ConsoleMessage.h" 32 #include "core/inspector/ConsoleMessage.h"
33 #include "core/inspector/InspectorConsoleInstrumentation.h"
34 #include "core/inspector/InspectorTraceEvents.h"
35 #include "core/inspector/ScriptArguments.h" 33 #include "core/inspector/ScriptArguments.h"
36 #include "platform/TraceEvent.h" 34 #include "platform/TraceEvent.h"
35 #include "wtf/CurrentTime.h"
37 #include "wtf/text/CString.h" 36 #include "wtf/text/CString.h"
38 #include "wtf/text/WTFString.h" 37 #include "wtf/text/WTFString.h"
39 38
40 namespace blink { 39 namespace blink {
41 40
42 ConsoleBase::~ConsoleBase() 41 ConsoleBase::~ConsoleBase()
43 { 42 {
44 } 43 }
45 44
46 void ConsoleBase::debug(ScriptState* scriptState, ScriptArguments* arguments)
47 {
48 internalAddMessage(LogMessageType, DebugMessageLevel, scriptState, arguments );
49 }
50
51 void ConsoleBase::error(ScriptState* scriptState, ScriptArguments* arguments)
52 {
53 internalAddMessage(LogMessageType, ErrorMessageLevel, scriptState, arguments , false);
54 }
55
56 void ConsoleBase::info(ScriptState* scriptState, ScriptArguments* arguments)
57 {
58 internalAddMessage(LogMessageType, InfoMessageLevel, scriptState, arguments) ;
59 }
60
61 void ConsoleBase::log(ScriptState* scriptState, ScriptArguments* arguments)
62 {
63 internalAddMessage(LogMessageType, LogMessageLevel, scriptState, arguments);
64 }
65
66 void ConsoleBase::warn(ScriptState* scriptState, ScriptArguments* arguments)
67 {
68 internalAddMessage(LogMessageType, WarningMessageLevel, scriptState, argumen ts);
69 }
70
71 void ConsoleBase::dir(ScriptState* scriptState, ScriptArguments* arguments)
72 {
73 internalAddMessage(DirMessageType, LogMessageLevel, scriptState, arguments);
74 }
75
76 void ConsoleBase::dirxml(ScriptState* scriptState, ScriptArguments* arguments)
77 {
78 internalAddMessage(DirXMLMessageType, LogMessageLevel, scriptState, argument s);
79 }
80
81 void ConsoleBase::table(ScriptState* scriptState, ScriptArguments* arguments)
82 {
83 internalAddMessage(TableMessageType, LogMessageLevel, scriptState, arguments );
84 }
85
86 void ConsoleBase::clear(ScriptState* scriptState, ScriptArguments* arguments)
87 {
88 internalAddMessage(ClearMessageType, LogMessageLevel, scriptState, arguments , true);
89 }
90
91 void ConsoleBase::trace(ScriptState* scriptState, ScriptArguments* arguments)
92 {
93 internalAddMessage(TraceMessageType, LogMessageLevel, scriptState, arguments , true);
94 }
95
96 void ConsoleBase::assertCondition(ScriptState* scriptState, ScriptArguments* arg uments, bool condition)
97 {
98 if (condition)
99 return;
100
101 internalAddMessage(AssertMessageType, ErrorMessageLevel, scriptState, argume nts, true);
102 }
103
104 void ConsoleBase::count(ScriptState* scriptState, ScriptArguments* arguments) 45 void ConsoleBase::count(ScriptState* scriptState, ScriptArguments* arguments)
105 { 46 {
106 RefPtr<ScriptCallStack> callStack(ScriptCallStack::capture(1)); 47 RefPtr<ScriptCallStack> callStack(ScriptCallStack::capture(1));
107 // Follow Firebug's behavior of counting with null and undefined title in 48 // Follow Firebug's behavior of counting with null and undefined title in
108 // the same bucket as no argument 49 // the same bucket as no argument
109 String title; 50 String title;
110 arguments->getFirstArgumentAsString(title); 51 arguments->getFirstArgumentAsString(title);
111 String identifier = title.isEmpty() ? String(callStack->topSourceURL() + ':' + String::number(callStack->topLineNumber())) 52 String identifier = title.isEmpty() ? String(callStack->topSourceURL() + ':' + String::number(callStack->topLineNumber()))
112 : String(title + '@'); 53 : String(title + '@');
113 54
114 HashCountedSet<String>::AddResult result = m_counts.add(identifier); 55 HashCountedSet<String>::AddResult result = m_counts.add(identifier);
115 String message = title + ": " + String::number(result.storedValue->value); 56 String message = title + ": " + String::number(result.storedValue->value);
116 57
117 ConsoleMessage* consoleMessage = ConsoleMessage::create(ConsoleAPIMessageSou rce, DebugMessageLevel, message); 58 ConsoleMessage* consoleMessage = ConsoleMessage::create(ConsoleAPIMessageSou rce, DebugMessageLevel, message);
118 consoleMessage->setType(CountMessageType); 59 consoleMessage->setType(CountMessageType);
119 consoleMessage->setScriptState(scriptState); 60 consoleMessage->setScriptState(scriptState);
120 consoleMessage->setCallStack(callStack.release()); 61 consoleMessage->setCallStack(callStack.release());
121 reportMessageToConsole(consoleMessage); 62 reportMessageToConsole(consoleMessage);
122 } 63 }
123 64
124 void ConsoleBase::markTimeline(const String& title)
125 {
126 timeStamp(title);
127 }
128
129 void ConsoleBase::profile(const String& title)
130 {
131 InspectorInstrumentation::consoleProfile(context(), title);
132 }
133
134 void ConsoleBase::profileEnd(const String& title)
135 {
136 InspectorInstrumentation::consoleProfileEnd(context(), title);
137 }
138
139 void ConsoleBase::time(const String& title) 65 void ConsoleBase::time(const String& title)
140 { 66 {
141 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", title.utf8().data(), this); 67 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", title.utf8().data(), this);
142 68
143 if (title.isNull()) 69 if (title.isNull())
144 return; 70 return;
145 71
146 m_times.add(title, monotonicallyIncreasingTime()); 72 m_times.add(title, monotonicallyIncreasingTime());
147 } 73 }
148 74
(...skipping 16 matching lines...) Expand all
165 double elapsed = monotonicallyIncreasingTime() - startTime; 91 double elapsed = monotonicallyIncreasingTime() - startTime;
166 String message = title + String::format(": %.3fms", elapsed * 1000); 92 String message = title + String::format(": %.3fms", elapsed * 1000);
167 93
168 ConsoleMessage* consoleMessage = ConsoleMessage::create(ConsoleAPIMessageSou rce, DebugMessageLevel, message); 94 ConsoleMessage* consoleMessage = ConsoleMessage::create(ConsoleAPIMessageSou rce, DebugMessageLevel, message);
169 consoleMessage->setType(TimeEndMessageType); 95 consoleMessage->setType(TimeEndMessageType);
170 consoleMessage->setScriptState(scriptState); 96 consoleMessage->setScriptState(scriptState);
171 consoleMessage->setCallStack(ScriptCallStack::capture(1)); 97 consoleMessage->setCallStack(ScriptCallStack::capture(1));
172 reportMessageToConsole(consoleMessage); 98 reportMessageToConsole(consoleMessage);
173 } 99 }
174 100
175 void ConsoleBase::timeStamp(const String& title)
176 {
177 TRACE_EVENT_INSTANT1("devtools.timeline", "TimeStamp", TRACE_EVENT_SCOPE_THR EAD, "data", InspectorTimeStampEvent::data(context(), title));
178 }
179
180 static String formatTimelineTitle(const String& title)
181 {
182 return String::format("Timeline '%s'", title.utf8().data());
183 }
184
185 void ConsoleBase::timeline(ScriptState* scriptState, const String& title)
186 {
187 TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", formatTimelineTitle(title).ut f8().data(), this);
188 }
189
190 void ConsoleBase::timelineEnd(ScriptState* scriptState, const String& title)
191 {
192 TRACE_EVENT_COPY_ASYNC_END0("blink.console", formatTimelineTitle(title).utf8 ().data(), this);
193 }
194
195 void ConsoleBase::group(ScriptState* scriptState, ScriptArguments* arguments)
196 {
197 internalAddMessage(StartGroupMessageType, LogMessageLevel, scriptState, argu ments, true);
198 }
199
200 void ConsoleBase::groupCollapsed(ScriptState* scriptState, ScriptArguments* argu ments)
201 {
202 internalAddMessage(StartGroupCollapsedMessageType, LogMessageLevel, scriptSt ate, arguments, true);
203 }
204
205 void ConsoleBase::groupEnd()
206 {
207 internalAddMessage(EndGroupMessageType, LogMessageLevel, nullptr, nullptr, t rue);
208 }
209
210 void ConsoleBase::internalAddMessage(MessageType type, MessageLevel level, Scrip tState* scriptState, ScriptArguments* scriptArguments, bool acceptNoArguments)
211 {
212 ScriptArguments* arguments = scriptArguments;
213 if (!acceptNoArguments && (!arguments || !arguments->argumentCount()))
214 return;
215
216 if (scriptState && !scriptState->contextIsValid())
217 arguments = nullptr;
218 String message;
219 if (arguments)
220 arguments->getFirstArgumentAsString(message);
221
222 ConsoleMessage* consoleMessage = ConsoleMessage::create(ConsoleAPIMessageSou rce, level, message);
223 consoleMessage->setType(type);
224 consoleMessage->setScriptState(scriptState);
225 consoleMessage->setScriptArguments(arguments);
226 consoleMessage->setCallStack(ScriptCallStack::captureForConsole());
227 reportMessageToConsole(consoleMessage);
228 }
229
230 } // namespace blink 101 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698