Index: Source/core/page/Console.cpp |
diff --git a/Source/core/page/Console.cpp b/Source/core/page/Console.cpp |
index bd34162ac01de4fa12be8ecbfa4529726f6c7d9f..0bbadf6fa3ae500dbb96f9cb9a500e3ecb4d75b3 100644 |
--- a/Source/core/page/Console.cpp |
+++ b/Source/core/page/Console.cpp |
@@ -69,16 +69,28 @@ static void internalAddMessage(Page* page, MessageType type, MessageLevel level, |
if (!acceptNoArguments && !arguments->argumentCount()) |
return; |
- size_t stackSize = printTrace ? ScriptCallStack::maxCallStackSizeToCapture : 1; |
- RefPtr<ScriptCallStack> callStack(createScriptCallStack(state, stackSize)); |
+ bool reportDetailedMessage = page->chrome().client()->shouldReportDetailedMessage(state->scriptExecutionContext()->url().string()); |
+ |
+ size_t stackSize = printTrace || reportDetailedMessage ? ScriptCallStack::maxCallStackSizeToCapture : 1; |
+ RefPtr<ScriptCallStack> callStack(createScriptCallStack(stackSize)); |
const ScriptCallFrame& lastCaller = callStack->at(0); |
String message; |
bool gotMessage = arguments->getFirstArgumentAsString(message); |
InspectorInstrumentation::addMessageToConsole(page, ConsoleAPIMessageSource, type, level, message, state, arguments); |
- if (gotMessage) |
- page->chrome().client()->addMessageToConsole(ConsoleAPIMessageSource, type, level, message, lastCaller.lineNumber(), lastCaller.sourceURL()); |
+ if (gotMessage) { |
+ RefPtr<ScriptCallStack> stackToUse = callStack; |
+ // Unfortunately, the check above for whether or not we care is only heuristically correct, since the url isn't always the same as the context in which the script was executed. In this case, we may decide we want detailed information only after we generate the original stack trace. |
+ if (!reportDetailedMessage && (reportDetailedMessage = page->chrome().client()->shouldReportDetailedMessage(lastCaller.sourceURL()))) |
+ stackToUse = createScriptCallStack(ScriptCallStack::maxCallStackSizeToCapture); |
+ |
+ String stackTrace; |
+ if (reportDetailedMessage) |
+ stackTrace = stackToUse->buildInspectorArray()->toJSONString(); |
+ |
+ page->chrome().client()->addMessageToConsole(ConsoleAPIMessageSource, level, message, lastCaller.lineNumber(), lastCaller.sourceURL(), stackTrace); |
+ } |
} |
void Console::debug(ScriptState* state, PassRefPtr<ScriptArguments> arguments) |