| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/inspector/InspectorConsoleAgent.h" | 27 #include "core/inspector/InspectorConsoleAgent.h" |
| 28 | 28 |
| 29 #include "bindings/core/v8/ScriptCallStackFactory.h" | 29 #include "bindings/core/v8/ScriptCallStackFactory.h" |
| 30 #include "bindings/core/v8/ScriptController.h" | 30 #include "bindings/core/v8/ScriptController.h" |
| 31 #include "bindings/core/v8/ScriptProfiler.h" | 31 #include "bindings/core/v8/ScriptProfiler.h" |
| 32 #include "core/frame/LocalFrame.h" | 32 #include "core/frame/LocalFrame.h" |
| 33 #include "core/inspector/ConsoleMessage.h" | 33 #include "core/inspector/ConsoleMessage.h" |
| 34 #include "core/inspector/InjectedScriptHost.h" | 34 #include "core/inspector/InjectedScriptHost.h" |
| 35 #include "core/inspector/InjectedScriptManager.h" | 35 #include "core/inspector/InjectedScriptManager.h" |
| 36 #include "core/inspector/InspectorConsoleMessage.h" |
| 36 #include "core/inspector/InspectorDebuggerAgent.h" | 37 #include "core/inspector/InspectorDebuggerAgent.h" |
| 37 #include "core/inspector/InspectorState.h" | 38 #include "core/inspector/InspectorState.h" |
| 38 #include "core/inspector/InspectorTimelineAgent.h" | 39 #include "core/inspector/InspectorTimelineAgent.h" |
| 39 #include "core/inspector/InstrumentingAgents.h" | 40 #include "core/inspector/InstrumentingAgents.h" |
| 40 #include "core/inspector/ScriptArguments.h" | 41 #include "core/inspector/ScriptArguments.h" |
| 41 #include "core/inspector/ScriptAsyncCallStack.h" | 42 #include "core/inspector/ScriptAsyncCallStack.h" |
| 42 #include "core/inspector/ScriptCallFrame.h" | 43 #include "core/inspector/ScriptCallFrame.h" |
| 43 #include "core/inspector/ScriptCallStack.h" | 44 #include "core/inspector/ScriptCallStack.h" |
| 44 #include "core/loader/DocumentLoader.h" | 45 #include "core/loader/DocumentLoader.h" |
| 45 #include "core/page/Page.h" | 46 #include "core/page/Page.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 if (m_enabled) | 92 if (m_enabled) |
| 92 return; | 93 return; |
| 93 m_enabled = true; | 94 m_enabled = true; |
| 94 if (!s_enabledAgentCount) | 95 if (!s_enabledAgentCount) |
| 95 ScriptController::setCaptureCallStackForUncaughtExceptions(true); | 96 ScriptController::setCaptureCallStackForUncaughtExceptions(true); |
| 96 ++s_enabledAgentCount; | 97 ++s_enabledAgentCount; |
| 97 | 98 |
| 98 m_state->setBoolean(ConsoleAgentState::consoleMessagesEnabled, true); | 99 m_state->setBoolean(ConsoleAgentState::consoleMessagesEnabled, true); |
| 99 | 100 |
| 100 if (m_expiredConsoleMessageCount) { | 101 if (m_expiredConsoleMessageCount) { |
| 101 ConsoleMessage expiredMessage(!isWorkerAgent(), OtherMessageSource, LogM
essageType, WarningMessageLevel, String::format("%d console messages are not sho
wn.", m_expiredConsoleMessageCount)); | 102 InspectorConsoleMessage expiredMessage(!isWorkerAgent(), OtherMessageSou
rce, LogMessageType, WarningMessageLevel, String::format("%d console messages ar
e not shown.", m_expiredConsoleMessageCount)); |
| 102 expiredMessage.setTimestamp(0); | 103 expiredMessage.setTimestamp(0); |
| 103 expiredMessage.addToFrontend(m_frontend, m_injectedScriptManager, false)
; | 104 expiredMessage.addToFrontend(m_frontend, m_injectedScriptManager, false)
; |
| 104 } | 105 } |
| 105 | 106 |
| 106 size_t messageCount = m_consoleMessages.size(); | 107 size_t messageCount = m_consoleMessages.size(); |
| 107 for (size_t i = 0; i < messageCount; ++i) | 108 for (size_t i = 0; i < messageCount; ++i) |
| 108 m_consoleMessages[i]->addToFrontend(m_frontend, m_injectedScriptManager,
false); | 109 m_consoleMessages[i]->addToFrontend(m_frontend, m_injectedScriptManager,
false); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void InspectorConsoleAgent::disable(ErrorString*) | 112 void InspectorConsoleAgent::disable(ErrorString*) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 m_frontend = frontend->console(); | 150 m_frontend = frontend->console(); |
| 150 } | 151 } |
| 151 | 152 |
| 152 void InspectorConsoleAgent::clearFrontend() | 153 void InspectorConsoleAgent::clearFrontend() |
| 153 { | 154 { |
| 154 m_frontend = 0; | 155 m_frontend = 0; |
| 155 String errorString; | 156 String errorString; |
| 156 disable(&errorString); | 157 disable(&errorString); |
| 157 } | 158 } |
| 158 | 159 |
| 159 void InspectorConsoleAgent::addMessageToConsole(MessageSource source, MessageTyp
e type, MessageLevel level, const String& message, PassRefPtrWillBeRawPtr<Script
CallStack> callStack, unsigned long requestIdentifier) | 160 void InspectorConsoleAgent::addMessageToConsole(PassRefPtr<ConsoleMessage> messa
ge) |
| 160 { | 161 { |
| 161 if (type == ClearMessageType) { | 162 if (message->callStack()) { |
| 162 ErrorString error; | 163 addConsoleMessage(adoptPtr(new InspectorConsoleMessage(!isWorkerAgent(),
message->source(), LogMessageType, message->level(), message->message(), messag
e->callStack(), message->requestIdentifier()))); |
| 163 clearMessages(&error); | 164 } else { |
| 165 bool canGenerateCallStack = !isWorkerAgent() && m_frontend; |
| 166 addConsoleMessage(adoptPtr(new InspectorConsoleMessage(canGenerateCallSt
ack, message->source(), LogMessageType, message->level(), message->message(), me
ssage->url(), message->lineNumber(), message->columnNumber(), nullptr, message->
requestIdentifier()))); |
| 164 } | 167 } |
| 165 | |
| 166 addConsoleMessage(adoptPtr(new ConsoleMessage(!isWorkerAgent(), source, type
, level, message, callStack, requestIdentifier))); | |
| 167 } | 168 } |
| 168 | 169 |
| 169 void InspectorConsoleAgent::addMessageToConsole(MessageSource source, MessageTyp
e type, MessageLevel level, const String& message, ScriptState* scriptState, Pas
sRefPtrWillBeRawPtr<ScriptArguments> arguments, unsigned long requestIdentifier) | 170 void InspectorConsoleAgent::addMessageToConsole(MessageSource source, MessageTyp
e type, MessageLevel level, const String& message, ScriptState* scriptState, Pas
sRefPtrWillBeRawPtr<ScriptArguments> arguments, unsigned long requestIdentifier) |
| 170 { | 171 { |
| 171 if (type == ClearMessageType) { | 172 if (type == ClearMessageType) { |
| 172 ErrorString error; | 173 ErrorString error; |
| 173 clearMessages(&error); | 174 clearMessages(&error); |
| 174 } | 175 } |
| 175 | 176 |
| 176 addConsoleMessage(adoptPtr(new ConsoleMessage(!isWorkerAgent(), source, type
, level, message, arguments, scriptState, requestIdentifier))); | 177 addConsoleMessage(adoptPtr(new InspectorConsoleMessage(!isWorkerAgent(), sou
rce, type, level, message, arguments, scriptState, requestIdentifier))); |
| 177 } | |
| 178 | |
| 179 void InspectorConsoleAgent::addMessageToConsole(MessageSource source, MessageTyp
e type, MessageLevel level, const String& message, const String& scriptId, unsig
ned lineNumber, unsigned columnNumber, ScriptState* scriptState, unsigned long r
equestIdentifier) | |
| 180 { | |
| 181 if (type == ClearMessageType) { | |
| 182 ErrorString error; | |
| 183 clearMessages(&error); | |
| 184 } | |
| 185 | |
| 186 bool canGenerateCallStack = !isWorkerAgent() && m_frontend; | |
| 187 addConsoleMessage(adoptPtr(new ConsoleMessage(canGenerateCallStack, source,
type, level, message, scriptId, lineNumber, columnNumber, scriptState, requestId
entifier))); | |
| 188 } | 178 } |
| 189 | 179 |
| 190 Vector<unsigned> InspectorConsoleAgent::consoleMessageArgumentCounts() | 180 Vector<unsigned> InspectorConsoleAgent::consoleMessageArgumentCounts() |
| 191 { | 181 { |
| 192 Vector<unsigned> result(m_consoleMessages.size()); | 182 Vector<unsigned> result(m_consoleMessages.size()); |
| 193 for (size_t i = 0; i < m_consoleMessages.size(); i++) | 183 for (size_t i = 0; i < m_consoleMessages.size(); i++) |
| 194 result[i] = m_consoleMessages[i]->argumentCount(); | 184 result[i] = m_consoleMessages[i]->argumentCount(); |
| 195 return result; | 185 return result; |
| 196 } | 186 } |
| 197 | 187 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 214 | 204 |
| 215 HashMap<String, double>::iterator it = m_times.find(title); | 205 HashMap<String, double>::iterator it = m_times.find(title); |
| 216 if (it == m_times.end()) | 206 if (it == m_times.end()) |
| 217 return; | 207 return; |
| 218 | 208 |
| 219 double startTime = it->value; | 209 double startTime = it->value; |
| 220 m_times.remove(it); | 210 m_times.remove(it); |
| 221 | 211 |
| 222 double elapsed = monotonicallyIncreasingTime() - startTime; | 212 double elapsed = monotonicallyIncreasingTime() - startTime; |
| 223 String message = title + String::format(": %.3fms", elapsed * 1000); | 213 String message = title + String::format(": %.3fms", elapsed * 1000); |
| 224 addMessageToConsole(ConsoleAPIMessageSource, LogMessageType, DebugMessageLev
el, message, String(), 0, 0, scriptState); | 214 addMessageToConsole(ConsoleAPIMessageSource, LogMessageType, DebugMessageLev
el, message, scriptState, nullptr); |
| 225 } | 215 } |
| 226 | 216 |
| 227 void InspectorConsoleAgent::consoleTimeline(ExecutionContext* context, const Str
ing& title, ScriptState* scriptState) | 217 void InspectorConsoleAgent::consoleTimeline(ExecutionContext* context, const Str
ing& title, ScriptState* scriptState) |
| 228 { | 218 { |
| 229 m_timelineAgent->consoleTimeline(context, title, scriptState); | 219 m_timelineAgent->consoleTimeline(context, title, scriptState); |
| 230 } | 220 } |
| 231 | 221 |
| 232 void InspectorConsoleAgent::consoleTimelineEnd(ExecutionContext* context, const
String& title, ScriptState* scriptState) | 222 void InspectorConsoleAgent::consoleTimelineEnd(ExecutionContext* context, const
String& title, ScriptState* scriptState) |
| 233 { | 223 { |
| 234 m_timelineAgent->consoleTimelineEnd(context, title, scriptState); | 224 m_timelineAgent->consoleTimelineEnd(context, title, scriptState); |
| 235 } | 225 } |
| 236 | 226 |
| 237 void InspectorConsoleAgent::consoleCount(ScriptState* scriptState, PassRefPtrWil
lBeRawPtr<ScriptArguments> arguments) | 227 void InspectorConsoleAgent::consoleCount(ScriptState* scriptState, PassRefPtrWil
lBeRawPtr<ScriptArguments> arguments) |
| 238 { | 228 { |
| 239 RefPtrWillBeRawPtr<ScriptCallStack> callStack(createScriptCallStackForConsol
e(scriptState)); | 229 RefPtrWillBeRawPtr<ScriptCallStack> callStack(createScriptCallStackForConsol
e(scriptState)); |
| 240 const ScriptCallFrame& lastCaller = callStack->at(0); | 230 const ScriptCallFrame& lastCaller = callStack->at(0); |
| 241 // Follow Firebug's behavior of counting with null and undefined title in | 231 // Follow Firebug's behavior of counting with null and undefined title in |
| 242 // the same bucket as no argument | 232 // the same bucket as no argument |
| 243 String title; | 233 String title; |
| 244 arguments->getFirstArgumentAsString(title); | 234 arguments->getFirstArgumentAsString(title); |
| 245 String identifier = title.isEmpty() ? String(lastCaller.sourceURL() + ':' +
String::number(lastCaller.lineNumber())) | 235 String identifier = title.isEmpty() ? String(lastCaller.sourceURL() + ':' +
String::number(lastCaller.lineNumber())) |
| 246 : String(title + '@'); | 236 : String(title + '@'); |
| 247 | 237 |
| 248 HashCountedSet<String>::AddResult result = m_counts.add(identifier); | 238 HashCountedSet<String>::AddResult result = m_counts.add(identifier); |
| 249 String message = title + ": " + String::number(result.storedValue->value); | 239 String message = title + ": " + String::number(result.storedValue->value); |
| 250 addMessageToConsole(ConsoleAPIMessageSource, LogMessageType, DebugMessageLev
el, message, callStack.get()); | 240 addMessageToConsole(ConsoleAPIMessageSource, LogMessageType, DebugMessageLev
el, message, nullptr, nullptr); |
| 251 } | 241 } |
| 252 | 242 |
| 253 void InspectorConsoleAgent::frameWindowDiscarded(LocalDOMWindow* window) | 243 void InspectorConsoleAgent::frameWindowDiscarded(LocalDOMWindow* window) |
| 254 { | 244 { |
| 255 size_t messageCount = m_consoleMessages.size(); | 245 size_t messageCount = m_consoleMessages.size(); |
| 256 for (size_t i = 0; i < messageCount; ++i) | 246 for (size_t i = 0; i < messageCount; ++i) |
| 257 m_consoleMessages[i]->windowCleared(window); | 247 m_consoleMessages[i]->windowCleared(window); |
| 258 m_injectedScriptManager->discardInjectedScriptsFor(window); | 248 m_injectedScriptManager->discardInjectedScriptsFor(window); |
| 259 } | 249 } |
| 260 | 250 |
| 261 void InspectorConsoleAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loa
der) | 251 void InspectorConsoleAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loa
der) |
| 262 { | 252 { |
| 263 if (loader->frame() != frame->page()->mainFrame()) | 253 if (loader->frame() != frame->page()->mainFrame()) |
| 264 return; | 254 return; |
| 265 reset(); | 255 reset(); |
| 266 } | 256 } |
| 267 | 257 |
| 268 void InspectorConsoleAgent::didFinishXHRLoading(XMLHttpRequest*, ThreadableLoade
rClient*, unsigned long requestIdentifier, ScriptString, const AtomicString& met
hod, const String& url, const String& sendURL, unsigned sendLineNumber) | 258 void InspectorConsoleAgent::didFinishXHRLoading(XMLHttpRequest*, ThreadableLoade
rClient*, unsigned long requestIdentifier, ScriptString, const AtomicString& met
hod, const String& url, const String& sendURL, unsigned sendLineNumber) |
| 269 { | 259 { |
| 270 if (m_frontend && m_state->getBoolean(ConsoleAgentState::monitoringXHR)) { | 260 if (m_frontend && m_state->getBoolean(ConsoleAgentState::monitoringXHR)) { |
| 271 String message = "XHR finished loading: " + method + " \"" + url + "\"."
; | 261 String message = "XHR finished loading: " + method + " \"" + url + "\"."
; |
| 272 addMessageToConsole(NetworkMessageSource, LogMessageType, DebugMessageLe
vel, message, sendURL, sendLineNumber, 0, 0, requestIdentifier); | 262 addMessageToConsole(ConsoleMessage::create(NetworkMessageSource, DebugMe
ssageLevel, message, sendURL, sendLineNumber, 0, nullptr, nullptr, requestIdenti
fier, NotSharableCrossOrigin)); |
| 273 } | 263 } |
| 274 } | 264 } |
| 275 | 265 |
| 276 void InspectorConsoleAgent::didReceiveResourceResponse(LocalFrame*, unsigned lon
g requestIdentifier, DocumentLoader* loader, const ResourceResponse& response, R
esourceLoader* resourceLoader) | 266 void InspectorConsoleAgent::didReceiveResourceResponse(LocalFrame*, unsigned lon
g requestIdentifier, DocumentLoader* loader, const ResourceResponse& response, R
esourceLoader* resourceLoader) |
| 277 { | 267 { |
| 278 if (!loader) | 268 if (!loader) |
| 279 return; | 269 return; |
| 280 if (response.httpStatusCode() >= 400) { | 270 if (response.httpStatusCode() >= 400) { |
| 281 String message = "Failed to load resource: the server responded with a s
tatus of " + String::number(response.httpStatusCode()) + " (" + response.httpSta
tusText() + ')'; | 271 String message = "Failed to load resource: the server responded with a s
tatus of " + String::number(response.httpStatusCode()) + " (" + response.httpSta
tusText() + ')'; |
| 282 addMessageToConsole(NetworkMessageSource, LogMessageType, ErrorMessageLe
vel, message, response.url().string(), 0, 0, 0, requestIdentifier); | 272 addMessageToConsole(ConsoleMessage::create(NetworkMessageSource, ErrorMe
ssageLevel, message, response.url().string(), 0, 0, nullptr, nullptr, requestIde
ntifier, NotSharableCrossOrigin)); |
| 283 } | 273 } |
| 284 } | 274 } |
| 285 | 275 |
| 286 void InspectorConsoleAgent::didFailLoading(unsigned long requestIdentifier, cons
t ResourceError& error) | 276 void InspectorConsoleAgent::didFailLoading(unsigned long requestIdentifier, cons
t ResourceError& error) |
| 287 { | 277 { |
| 288 if (error.isCancellation()) // Report failures only. | 278 if (error.isCancellation()) // Report failures only. |
| 289 return; | 279 return; |
| 290 StringBuilder message; | 280 StringBuilder message; |
| 291 message.appendLiteral("Failed to load resource"); | 281 message.appendLiteral("Failed to load resource"); |
| 292 if (!error.localizedDescription().isEmpty()) { | 282 if (!error.localizedDescription().isEmpty()) { |
| 293 message.appendLiteral(": "); | 283 message.appendLiteral(": "); |
| 294 message.append(error.localizedDescription()); | 284 message.append(error.localizedDescription()); |
| 295 } | 285 } |
| 296 addMessageToConsole(NetworkMessageSource, LogMessageType, ErrorMessageLevel,
message.toString(), error.failingURL(), 0, 0, 0, requestIdentifier); | 286 addMessageToConsole(ConsoleMessage::create(NetworkMessageSource, ErrorMessag
eLevel, message.toString(), error.failingURL(), 0, 0, nullptr, nullptr, requestI
dentifier, NotSharableCrossOrigin)); |
| 297 } | 287 } |
| 298 | 288 |
| 299 void InspectorConsoleAgent::setMonitoringXHREnabled(ErrorString*, bool enabled) | 289 void InspectorConsoleAgent::setMonitoringXHREnabled(ErrorString*, bool enabled) |
| 300 { | 290 { |
| 301 m_state->setBoolean(ConsoleAgentState::monitoringXHR, enabled); | 291 m_state->setBoolean(ConsoleAgentState::monitoringXHR, enabled); |
| 302 } | 292 } |
| 303 | 293 |
| 304 void InspectorConsoleAgent::addConsoleMessage(PassOwnPtr<ConsoleMessage> console
Message) | 294 void InspectorConsoleAgent::addConsoleMessage(PassOwnPtr<InspectorConsoleMessage
> consoleMessage) |
| 305 { | 295 { |
| 306 ASSERT_ARG(consoleMessage, consoleMessage); | 296 ASSERT_ARG(consoleMessage, consoleMessage); |
| 307 | 297 |
| 308 if (InspectorDebuggerAgent* debuggerAgent = m_instrumentingAgents->inspector
DebuggerAgent()) | 298 if (InspectorDebuggerAgent* debuggerAgent = m_instrumentingAgents->inspector
DebuggerAgent()) |
| 309 consoleMessage->setAsyncStackTrace(debuggerAgent->currentAsyncStackTrace
ForConsole()); | 299 consoleMessage->setAsyncStackTrace(debuggerAgent->currentAsyncStackTrace
ForConsole()); |
| 310 | 300 |
| 311 if (m_frontend && m_enabled) | 301 if (m_frontend && m_enabled) |
| 312 consoleMessage->addToFrontend(m_frontend, m_injectedScriptManager, true)
; | 302 consoleMessage->addToFrontend(m_frontend, m_injectedScriptManager, true)
; |
| 313 | 303 |
| 314 m_consoleMessages.append(consoleMessage); | 304 m_consoleMessages.append(consoleMessage); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 330 int m_heapObjectId; | 320 int m_heapObjectId; |
| 331 }; | 321 }; |
| 332 | 322 |
| 333 void InspectorConsoleAgent::addInspectedHeapObject(ErrorString*, int inspectedHe
apObjectId) | 323 void InspectorConsoleAgent::addInspectedHeapObject(ErrorString*, int inspectedHe
apObjectId) |
| 334 { | 324 { |
| 335 m_injectedScriptManager->injectedScriptHost()->addInspectedObject(adoptPtr(n
ew InspectableHeapObject(inspectedHeapObjectId))); | 325 m_injectedScriptManager->injectedScriptHost()->addInspectedObject(adoptPtr(n
ew InspectableHeapObject(inspectedHeapObjectId))); |
| 336 } | 326 } |
| 337 | 327 |
| 338 } // namespace WebCore | 328 } // namespace WebCore |
| 339 | 329 |
| OLD | NEW |