OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
4 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 4 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. |
5 * | 5 * |
6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
8 * are met: | 8 * are met: |
9 * | 9 * |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 10 matching lines...) Expand all Loading... |
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
| 31 |
31 #include "config.h" | 32 #include "config.h" |
32 | 33 #include "core/inspector/InspectorConsoleMessage.h" |
33 | |
34 #include "core/inspector/ConsoleMessage.h" | |
35 | 34 |
36 #include "bindings/core/v8/ScriptCallStackFactory.h" | 35 #include "bindings/core/v8/ScriptCallStackFactory.h" |
37 #include "bindings/core/v8/ScriptValue.h" | 36 #include "bindings/core/v8/ScriptValue.h" |
38 #include "core/dom/ExecutionContext.h" | 37 #include "core/dom/ExecutionContext.h" |
39 #include "core/inspector/IdentifiersFactory.h" | 38 #include "core/inspector/IdentifiersFactory.h" |
40 #include "core/inspector/InjectedScript.h" | 39 #include "core/inspector/InjectedScript.h" |
41 #include "core/inspector/InjectedScriptManager.h" | 40 #include "core/inspector/InjectedScriptManager.h" |
42 #include "core/inspector/ScriptArguments.h" | 41 #include "core/inspector/ScriptArguments.h" |
43 #include "core/inspector/ScriptAsyncCallStack.h" | 42 #include "core/inspector/ScriptAsyncCallStack.h" |
44 #include "core/inspector/ScriptCallFrame.h" | 43 #include "core/inspector/ScriptCallFrame.h" |
45 #include "core/inspector/ScriptCallStack.h" | 44 #include "core/inspector/ScriptCallStack.h" |
46 #include "wtf/CurrentTime.h" | 45 #include "wtf/CurrentTime.h" |
47 | 46 |
48 namespace WebCore { | 47 namespace WebCore { |
49 | 48 |
50 ConsoleMessage::ConsoleMessage(bool canGenerateCallStack, MessageSource source,
MessageType type, MessageLevel level, const String& message) | 49 InspectorConsoleMessage::InspectorConsoleMessage(bool canGenerateCallStack, Mess
ageSource source, MessageType type, MessageLevel level, const String& message) |
51 : m_source(source) | 50 : m_source(source) |
52 , m_type(type) | 51 , m_type(type) |
53 , m_level(level) | 52 , m_level(level) |
54 , m_message(message) | 53 , m_message(message) |
55 , m_scriptState(0) | 54 , m_scriptState(0) |
56 , m_url() | 55 , m_url() |
57 , m_line(0) | 56 , m_line(0) |
58 , m_column(0) | 57 , m_column(0) |
59 , m_requestId(IdentifiersFactory::requestId(0)) | 58 , m_requestId(IdentifiersFactory::requestId(0)) |
60 , m_timestamp(WTF::currentTime()) | 59 , m_timestamp(WTF::currentTime()) |
61 { | 60 { |
62 autogenerateMetadata(canGenerateCallStack); | 61 autogenerateMetadata(canGenerateCallStack); |
63 } | 62 } |
64 | 63 |
65 ConsoleMessage::ConsoleMessage(bool canGenerateCallStack, MessageSource source,
MessageType type, MessageLevel level, const String& message, const String& url,
unsigned line, unsigned column, ScriptState* scriptState, unsigned long requestI
dentifier) | 64 InspectorConsoleMessage::InspectorConsoleMessage(bool canGenerateCallStack, Mess
ageSource source, MessageType type, MessageLevel level, const String& message, c
onst String& url, unsigned line, unsigned column, ScriptState* scriptState, unsi
gned long requestIdentifier) |
66 : m_source(source) | 65 : m_source(source) |
67 , m_type(type) | 66 , m_type(type) |
68 , m_level(level) | 67 , m_level(level) |
69 , m_message(message) | 68 , m_message(message) |
70 , m_scriptState(scriptState) | 69 , m_scriptState(scriptState) |
71 , m_url(url) | 70 , m_url(url) |
72 , m_line(line) | 71 , m_line(line) |
73 , m_column(column) | 72 , m_column(column) |
74 , m_requestId(IdentifiersFactory::requestId(requestIdentifier)) | 73 , m_requestId(IdentifiersFactory::requestId(requestIdentifier)) |
75 , m_timestamp(WTF::currentTime()) | 74 , m_timestamp(WTF::currentTime()) |
76 { | 75 { |
77 autogenerateMetadata(canGenerateCallStack, scriptState); | 76 autogenerateMetadata(canGenerateCallStack, scriptState); |
78 } | 77 } |
79 | 78 |
80 ConsoleMessage::ConsoleMessage(bool, MessageSource source, MessageType type, Mes
sageLevel level, const String& message, PassRefPtrWillBeRawPtr<ScriptCallStack>
callStack, unsigned long requestIdentifier) | 79 InspectorConsoleMessage::InspectorConsoleMessage(bool, MessageSource source, Mes
sageType type, MessageLevel level, const String& message, PassRefPtrWillBeRawPtr
<ScriptCallStack> callStack, unsigned long requestIdentifier) |
81 : m_source(source) | 80 : m_source(source) |
82 , m_type(type) | 81 , m_type(type) |
83 , m_level(level) | 82 , m_level(level) |
84 , m_message(message) | 83 , m_message(message) |
85 , m_scriptState(0) | 84 , m_scriptState(0) |
86 , m_arguments(nullptr) | 85 , m_arguments(nullptr) |
87 , m_line(0) | 86 , m_line(0) |
88 , m_column(0) | 87 , m_column(0) |
89 , m_requestId(IdentifiersFactory::requestId(requestIdentifier)) | 88 , m_requestId(IdentifiersFactory::requestId(requestIdentifier)) |
90 , m_timestamp(WTF::currentTime()) | 89 , m_timestamp(WTF::currentTime()) |
91 { | 90 { |
92 if (callStack && callStack->size()) { | 91 if (callStack && callStack->size()) { |
93 const ScriptCallFrame& frame = callStack->at(0); | 92 const ScriptCallFrame& frame = callStack->at(0); |
94 m_url = frame.sourceURL(); | 93 m_url = frame.sourceURL(); |
95 m_line = frame.lineNumber(); | 94 m_line = frame.lineNumber(); |
96 m_column = frame.columnNumber(); | 95 m_column = frame.columnNumber(); |
97 } | 96 } |
98 m_callStack = callStack; | 97 m_callStack = callStack; |
99 } | 98 } |
100 | 99 |
101 ConsoleMessage::ConsoleMessage(bool canGenerateCallStack, MessageSource source,
MessageType type, MessageLevel level, const String& message, PassRefPtrWillBeRaw
Ptr<ScriptArguments> arguments, ScriptState* scriptState, unsigned long requestI
dentifier) | 100 InspectorConsoleMessage::InspectorConsoleMessage(bool canGenerateCallStack, Mess
ageSource source, MessageType type, MessageLevel level, const String& message, P
assRefPtrWillBeRawPtr<ScriptArguments> arguments, ScriptState* scriptState, unsi
gned long requestIdentifier) |
102 : m_source(source) | 101 : m_source(source) |
103 , m_type(type) | 102 , m_type(type) |
104 , m_level(level) | 103 , m_level(level) |
105 , m_message(message) | 104 , m_message(message) |
106 , m_scriptState(scriptState) | 105 , m_scriptState(scriptState) |
107 , m_arguments(arguments) | 106 , m_arguments(arguments) |
108 , m_url() | 107 , m_url() |
109 , m_line(0) | 108 , m_line(0) |
110 , m_column(0) | 109 , m_column(0) |
111 , m_requestId(IdentifiersFactory::requestId(requestIdentifier)) | 110 , m_requestId(IdentifiersFactory::requestId(requestIdentifier)) |
112 , m_timestamp(WTF::currentTime()) | 111 , m_timestamp(WTF::currentTime()) |
113 { | 112 { |
114 autogenerateMetadata(canGenerateCallStack, scriptState); | 113 autogenerateMetadata(canGenerateCallStack, scriptState); |
115 } | 114 } |
116 | 115 |
117 ConsoleMessage::~ConsoleMessage() | 116 InspectorConsoleMessage::~InspectorConsoleMessage() |
118 { | 117 { |
119 } | 118 } |
120 | 119 |
121 void ConsoleMessage::autogenerateMetadata(bool canGenerateCallStack, ScriptState
* scriptState) | 120 void InspectorConsoleMessage::autogenerateMetadata(bool canGenerateCallStack, Sc
riptState* scriptState) |
122 { | 121 { |
123 if (m_type == EndGroupMessageType) | 122 if (m_type == EndGroupMessageType) |
124 return; | 123 return; |
125 | 124 |
126 if (scriptState) | 125 if (scriptState) |
127 m_callStack = createScriptCallStackForConsole(scriptState); | 126 m_callStack = createScriptCallStackForConsole(scriptState); |
128 else if (canGenerateCallStack) | 127 else if (canGenerateCallStack) |
129 m_callStack = createScriptCallStack(ScriptCallStack::maxCallStackSizeToC
apture, true); | 128 m_callStack = createScriptCallStack(ScriptCallStack::maxCallStackSizeToC
apture, true); |
130 else | 129 else |
131 return; | 130 return; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 switch (level) { | 180 switch (level) { |
182 case DebugMessageLevel: return TypeBuilder::Console::ConsoleMessage::Level::
Debug; | 181 case DebugMessageLevel: return TypeBuilder::Console::ConsoleMessage::Level::
Debug; |
183 case LogMessageLevel: return TypeBuilder::Console::ConsoleMessage::Level::Lo
g; | 182 case LogMessageLevel: return TypeBuilder::Console::ConsoleMessage::Level::Lo
g; |
184 case WarningMessageLevel: return TypeBuilder::Console::ConsoleMessage::Level
::Warning; | 183 case WarningMessageLevel: return TypeBuilder::Console::ConsoleMessage::Level
::Warning; |
185 case ErrorMessageLevel: return TypeBuilder::Console::ConsoleMessage::Level::
Error; | 184 case ErrorMessageLevel: return TypeBuilder::Console::ConsoleMessage::Level::
Error; |
186 case InfoMessageLevel: return TypeBuilder::Console::ConsoleMessage::Level::I
nfo; | 185 case InfoMessageLevel: return TypeBuilder::Console::ConsoleMessage::Level::I
nfo; |
187 } | 186 } |
188 return TypeBuilder::Console::ConsoleMessage::Level::Log; | 187 return TypeBuilder::Console::ConsoleMessage::Level::Log; |
189 } | 188 } |
190 | 189 |
191 void ConsoleMessage::addToFrontend(InspectorFrontend::Console* frontend, Injecte
dScriptManager* injectedScriptManager, bool generatePreview) | 190 void InspectorConsoleMessage::addToFrontend(InspectorFrontend::Console* frontend
, InjectedScriptManager* injectedScriptManager, bool generatePreview) |
192 { | 191 { |
193 RefPtr<TypeBuilder::Console::ConsoleMessage> jsonObj = TypeBuilder::Console:
:ConsoleMessage::create() | 192 RefPtr<TypeBuilder::Console::ConsoleMessage> jsonObj = TypeBuilder::Console:
:ConsoleMessage::create() |
194 .setSource(messageSourceValue(m_source)) | 193 .setSource(messageSourceValue(m_source)) |
195 .setLevel(messageLevelValue(m_level)) | 194 .setLevel(messageLevelValue(m_level)) |
196 .setText(m_message) | 195 .setText(m_message) |
197 .setTimestamp(m_timestamp); | 196 .setTimestamp(m_timestamp); |
198 // FIXME: only send out type for ConsoleAPI source messages. | 197 // FIXME: only send out type for ConsoleAPI source messages. |
199 jsonObj->setType(messageTypeValue(m_type)); | 198 jsonObj->setType(messageTypeValue(m_type)); |
200 jsonObj->setLine(static_cast<int>(m_line)); | 199 jsonObj->setLine(static_cast<int>(m_line)); |
201 jsonObj->setColumn(static_cast<int>(m_column)); | 200 jsonObj->setColumn(static_cast<int>(m_column)); |
202 jsonObj->setUrl(m_url); | 201 jsonObj->setUrl(m_url); |
203 ScriptState* scriptState = m_scriptState.get(); | 202 ScriptState* scriptState = m_scriptState.get(); |
204 if (scriptState) | 203 if (scriptState && scriptState->executionContext()->isDocument()) |
205 jsonObj->setExecutionContextId(injectedScriptManager->injectedScriptIdFo
r(scriptState)); | 204 jsonObj->setExecutionContextId(injectedScriptManager->injectedScriptIdFo
r(scriptState)); |
206 if (m_source == NetworkMessageSource && !m_requestId.isEmpty()) | 205 if (m_source == NetworkMessageSource && !m_requestId.isEmpty()) |
207 jsonObj->setNetworkRequestId(m_requestId); | 206 jsonObj->setNetworkRequestId(m_requestId); |
208 if (m_arguments && m_arguments->argumentCount()) { | 207 if (m_arguments && m_arguments->argumentCount()) { |
209 InjectedScript injectedScript = injectedScriptManager->injectedScriptFor
(m_arguments->scriptState()); | 208 InjectedScript injectedScript = injectedScriptManager->injectedScriptFor
(m_arguments->scriptState()); |
210 if (!injectedScript.isEmpty()) { | 209 if (!injectedScript.isEmpty()) { |
211 RefPtr<TypeBuilder::Array<TypeBuilder::Runtime::RemoteObject> > json
Args = TypeBuilder::Array<TypeBuilder::Runtime::RemoteObject>::create(); | 210 RefPtr<TypeBuilder::Array<TypeBuilder::Runtime::RemoteObject> > json
Args = TypeBuilder::Array<TypeBuilder::Runtime::RemoteObject>::create(); |
212 if (m_type == TableMessageType && generatePreview && m_arguments->ar
gumentCount()) { | 211 if (m_type == TableMessageType && generatePreview && m_arguments->ar
gumentCount()) { |
213 ScriptValue table = m_arguments->argumentAt(0); | 212 ScriptValue table = m_arguments->argumentAt(0); |
214 ScriptValue columns = m_arguments->argumentCount() > 1 ? m_argum
ents->argumentAt(1) : ScriptValue(); | 213 ScriptValue columns = m_arguments->argumentCount() > 1 ? m_argum
ents->argumentAt(1) : ScriptValue(); |
(...skipping 17 matching lines...) Expand all Loading... |
232 } | 231 } |
233 } | 232 } |
234 if (m_callStack) | 233 if (m_callStack) |
235 jsonObj->setStackTrace(m_callStack->buildInspectorArray()); | 234 jsonObj->setStackTrace(m_callStack->buildInspectorArray()); |
236 if (m_asyncCallStack) | 235 if (m_asyncCallStack) |
237 jsonObj->setAsyncStackTrace(m_asyncCallStack->buildInspectorObject()); | 236 jsonObj->setAsyncStackTrace(m_asyncCallStack->buildInspectorObject()); |
238 frontend->messageAdded(jsonObj); | 237 frontend->messageAdded(jsonObj); |
239 frontend->flush(); | 238 frontend->flush(); |
240 } | 239 } |
241 | 240 |
242 void ConsoleMessage::setAsyncStackTrace(PassRefPtrWillBeRawPtr<ScriptAsyncCallSt
ack> asyncCallStack) | 241 void InspectorConsoleMessage::setAsyncStackTrace(PassRefPtrWillBeRawPtr<ScriptAs
yncCallStack> asyncCallStack) |
243 { | 242 { |
244 m_asyncCallStack = asyncCallStack; | 243 m_asyncCallStack = asyncCallStack; |
245 } | 244 } |
246 | 245 |
247 void ConsoleMessage::windowCleared(LocalDOMWindow* window) | 246 void InspectorConsoleMessage::windowCleared(LocalDOMWindow* window) |
248 { | 247 { |
249 if (m_scriptState.get() && m_scriptState.get()->domWindow() == window) | 248 if (m_scriptState.get() && m_scriptState.get()->domWindow() == window) |
250 m_scriptState.clear(); | 249 m_scriptState.clear(); |
251 | 250 |
252 if (!m_arguments) | 251 if (!m_arguments) |
253 return; | 252 return; |
254 if (m_arguments->scriptState()->domWindow() != window) | 253 if (m_arguments->scriptState()->domWindow() != window) |
255 return; | 254 return; |
256 if (!m_message) | 255 if (!m_message) |
257 m_message = "<message collected>"; | 256 m_message = "<message collected>"; |
258 m_arguments.clear(); | 257 m_arguments.clear(); |
259 } | 258 } |
260 | 259 |
261 unsigned ConsoleMessage::argumentCount() | 260 unsigned InspectorConsoleMessage::argumentCount() |
262 { | 261 { |
263 if (m_arguments) | 262 if (m_arguments) |
264 return m_arguments->argumentCount(); | 263 return m_arguments->argumentCount(); |
265 return 0; | 264 return 0; |
266 } | 265 } |
267 | 266 |
268 } // namespace WebCore | 267 } // namespace WebCore |
OLD | NEW |