Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / frame / ConsoleBase.cpp
1 /*
2  * Copyright (C) 2007 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14  *     its contributors may be used to endorse or promote products derived
15  *     from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
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
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.
27  */
28
29 #include "config.h"
30 #include "core/frame/Console.h"
31
32 #include "bindings/core/v8/ScriptCallStackFactory.h"
33 #include "core/inspector/InspectorConsoleInstrumentation.h"
34 #include "core/inspector/InspectorTraceEvents.h"
35 #include "core/inspector/ScriptArguments.h"
36 #include "platform/TraceEvent.h"
37 #include "wtf/text/CString.h"
38 #include "wtf/text/WTFString.h"
39
40 namespace blink {
41
42 ConsoleBase::~ConsoleBase()
43 {
44 }
45
46 void ConsoleBase::debug(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
47 {
48     internalAddMessage(LogMessageType, DebugMessageLevel, scriptState, arguments);
49 }
50
51 void ConsoleBase::error(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
52 {
53     internalAddMessage(LogMessageType, ErrorMessageLevel, scriptState, arguments);
54 }
55
56 void ConsoleBase::info(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
57 {
58     internalAddMessage(LogMessageType, InfoMessageLevel, scriptState, arguments);
59 }
60
61 void ConsoleBase::log(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
62 {
63     internalAddMessage(LogMessageType, LogMessageLevel, scriptState, arguments);
64 }
65
66 void ConsoleBase::warn(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
67 {
68     internalAddMessage(LogMessageType, WarningMessageLevel, scriptState, arguments);
69 }
70
71 void ConsoleBase::dir(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
72 {
73     internalAddMessage(DirMessageType, LogMessageLevel, scriptState, arguments);
74 }
75
76 void ConsoleBase::dirxml(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
77 {
78     internalAddMessage(DirXMLMessageType, LogMessageLevel, scriptState, arguments);
79 }
80
81 void ConsoleBase::table(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
82 {
83     internalAddMessage(TableMessageType, LogMessageLevel, scriptState, arguments);
84 }
85
86 void ConsoleBase::clear(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
87 {
88     InspectorInstrumentation::addConsoleAPIMessageToConsole(context(), ClearMessageType, LogMessageLevel, String(), scriptState, arguments);
89 }
90
91 void ConsoleBase::trace(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
92 {
93     internalAddMessage(TraceMessageType, LogMessageLevel, scriptState, arguments, true, true);
94 }
95
96 void ConsoleBase::assertCondition(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments, bool condition)
97 {
98     if (condition)
99         return;
100
101     internalAddMessage(AssertMessageType, ErrorMessageLevel, scriptState, arguments, true);
102 }
103
104 void ConsoleBase::count(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
105 {
106     InspectorInstrumentation::consoleCount(context(), scriptState, arguments);
107 }
108
109 void ConsoleBase::markTimeline(const String& title)
110 {
111     timeStamp(title);
112 }
113
114 void ConsoleBase::profile(const String& title)
115 {
116     InspectorInstrumentation::consoleProfile(context(), title);
117 }
118
119 void ConsoleBase::profileEnd(const String& title)
120 {
121     InspectorInstrumentation::consoleProfileEnd(context(), title);
122 }
123
124 void ConsoleBase::time(const String& title)
125 {
126     InspectorInstrumentation::consoleTime(context(), title);
127     TRACE_EVENT_COPY_ASYNC_BEGIN0("blink.console", title.utf8().data(), this);
128 }
129
130 void ConsoleBase::timeEnd(ScriptState* scriptState, const String& title)
131 {
132     TRACE_EVENT_COPY_ASYNC_END0("blink.console", title.utf8().data(), this);
133     InspectorInstrumentation::consoleTimeEnd(context(), title, scriptState);
134 }
135
136 void ConsoleBase::timeStamp(const String& title)
137 {
138     TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "TimeStamp", "data", InspectorTimeStampEvent::data(context(), title));
139     // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeline migrates to tracing.
140     InspectorInstrumentation::consoleTimeStamp(context(), title);
141 }
142
143 void ConsoleBase::timeline(ScriptState* scriptState, const String& title)
144 {
145     InspectorInstrumentation::consoleTimeline(context(), title, scriptState);
146 }
147
148 void ConsoleBase::timelineEnd(ScriptState* scriptState, const String& title)
149 {
150     InspectorInstrumentation::consoleTimelineEnd(context(), title, scriptState);
151 }
152
153 void ConsoleBase::group(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
154 {
155     InspectorInstrumentation::addConsoleAPIMessageToConsole(context(), StartGroupMessageType, LogMessageLevel, String(), scriptState, arguments);
156 }
157
158 void ConsoleBase::groupCollapsed(ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> arguments)
159 {
160     InspectorInstrumentation::addConsoleAPIMessageToConsole(context(), StartGroupCollapsedMessageType, LogMessageLevel, String(), scriptState, arguments);
161 }
162
163 void ConsoleBase::groupEnd()
164 {
165     InspectorInstrumentation::addConsoleAPIMessageToConsole(context(), EndGroupMessageType, LogMessageLevel, String(), nullptr, nullptr);
166 }
167
168 void ConsoleBase::internalAddMessage(MessageType type, MessageLevel level, ScriptState* scriptState, PassRefPtrWillBeRawPtr<ScriptArguments> scriptArguments, bool acceptNoArguments, bool printTrace)
169 {
170     if (!context())
171         return;
172
173     RefPtrWillBeRawPtr<ScriptArguments> arguments = scriptArguments;
174     if (!acceptNoArguments && !arguments->argumentCount())
175         return;
176
177     size_t stackSize = printTrace ? ScriptCallStack::maxCallStackSizeToCapture : 1;
178     RefPtrWillBeRawPtr<ScriptCallStack> callStack(createScriptCallStackForConsole(stackSize));
179
180     String message;
181     bool gotStringMessage = arguments->getFirstArgumentAsString(message);
182     InspectorInstrumentation::addConsoleAPIMessageToConsole(context(), type, level, message, scriptState, arguments);
183     if (gotStringMessage)
184         reportMessageToClient(level, message, callStack);
185 }
186
187 } // namespace blink