| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2013 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 13 matching lines...) Expand all Loading... |
| 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 "config.h" | 29 #include "config.h" |
| 30 #include "core/frame/FrameConsole.h" | 30 #include "core/frame/FrameConsole.h" |
| 31 | 31 |
| 32 #include "core/frame/FrameHost.h" | 32 #include "core/frame/FrameHost.h" |
| 33 #include "core/inspector/ConsoleAPITypes.h" | 33 #include "core/inspector/ConsoleAPITypes.h" |
| 34 #include "core/inspector/ConsoleMessage.h" |
| 34 #include "core/inspector/InspectorConsoleInstrumentation.h" | 35 #include "core/inspector/InspectorConsoleInstrumentation.h" |
| 35 #include "core/page/Chrome.h" | 36 #include "core/page/Chrome.h" |
| 36 #include "core/page/ChromeClient.h" | 37 #include "core/page/ChromeClient.h" |
| 37 #include "core/page/Page.h" | 38 #include "core/page/Page.h" |
| 38 #include "wtf/text/StringBuilder.h" | 39 #include "wtf/text/StringBuilder.h" |
| 39 | 40 |
| 40 namespace WebCore { | 41 namespace WebCore { |
| 41 | 42 |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 int muteCount = 0; | 45 int muteCount = 0; |
| 45 | 46 |
| 46 } | 47 } |
| 47 | 48 |
| 48 FrameConsole::FrameConsole(LocalFrame& frame) | 49 FrameConsole::FrameConsole(LocalFrame& frame) |
| 49 : m_frame(frame) | 50 : m_frame(frame) |
| 50 { | 51 { |
| 51 } | 52 } |
| 52 | 53 |
| 53 void FrameConsole::addMessage(MessageSource source, MessageLevel level, const St
ring& message) | 54 void FrameConsole::addMessage(PassRefPtrWillBeRawPtr<ConsoleMessage> prpConsoleE
rror) |
| 54 { | |
| 55 addMessage(source, level, message, String(), 0, 0, nullptr, 0, 0); | |
| 56 } | |
| 57 | |
| 58 void FrameConsole::addMessage(MessageSource source, MessageLevel level, const St
ring& message, PassRefPtrWillBeRawPtr<ScriptCallStack> callStack) | |
| 59 { | |
| 60 addMessage(source, level, message, String(), 0, 0, callStack, 0); | |
| 61 } | |
| 62 | |
| 63 void FrameConsole::addMessage(MessageSource source, MessageLevel level, const St
ring& message, const String& url, unsigned lineNumber, unsigned columnNumber, Pa
ssRefPtrWillBeRawPtr<ScriptCallStack> callStack, ScriptState* scriptState, unsig
ned long requestIdentifier) | |
| 64 { | 55 { |
| 65 if (muteCount) | 56 if (muteCount) |
| 66 return; | 57 return; |
| 67 | 58 |
| 68 // FIXME: This should not need to reach for the main-frame. | 59 // FIXME: This should not need to reach for the main-frame. |
| 69 // Inspector code should just take the current frame and know how to walk it
self. | 60 // Inspector code should just take the current frame and know how to walk it
self. |
| 70 ExecutionContext* context = m_frame.document(); | 61 ExecutionContext* context = m_frame.document(); |
| 71 if (!context) | 62 if (!context) |
| 72 return; | 63 return; |
| 73 | 64 |
| 65 RefPtr<ConsoleMessage> consoleError = prpConsoleError; |
| 66 |
| 74 String messageURL; | 67 String messageURL; |
| 75 if (callStack) { | 68 if (consoleError->callStack()) |
| 76 messageURL = callStack->at(0).sourceURL(); | 69 messageURL = consoleError->callStack()->at(0).sourceURL(); |
| 77 InspectorInstrumentation::addMessageToConsole(context, source, LogMessag
eType, level, message, callStack, requestIdentifier); | 70 else |
| 78 } else { | 71 messageURL = consoleError->url(); |
| 79 messageURL = url; | |
| 80 InspectorInstrumentation::addMessageToConsole(context, source, LogMessag
eType, level, message, url, lineNumber, columnNumber, scriptState, requestIdenti
fier); | |
| 81 } | |
| 82 | 72 |
| 83 if (source == CSSMessageSource) | 73 InspectorInstrumentation::addMessageToConsole(context, consoleError); |
| 74 |
| 75 if (consoleError->source() == CSSMessageSource) |
| 84 return; | 76 return; |
| 85 | 77 |
| 86 String stackTrace; | 78 String stackTrace; |
| 87 if (callStack && m_frame.chromeClient().shouldReportDetailedMessageForSource
(messageURL)) | 79 if (consoleError->callStack() && m_frame.chromeClient().shouldReportDetailed
MessageForSource(messageURL)) |
| 88 stackTrace = FrameConsole::formatStackTraceString(message, callStack); | 80 stackTrace = FrameConsole::formatStackTraceString(consoleError->message(
), consoleError->callStack()); |
| 89 | 81 |
| 90 m_frame.chromeClient().addMessageToConsole(&m_frame, source, level, message,
lineNumber, messageURL, stackTrace); | 82 m_frame.chromeClient().addMessageToConsole(&m_frame, consoleError->source(),
consoleError->level(), consoleError->message(), consoleError->lineNumber(), mes
sageURL, stackTrace); |
| 91 } | 83 } |
| 92 | 84 |
| 93 String FrameConsole::formatStackTraceString(const String& originalMessage, PassR
efPtrWillBeRawPtr<ScriptCallStack> callStack) | 85 String FrameConsole::formatStackTraceString(const String& originalMessage, PassR
efPtrWillBeRawPtr<ScriptCallStack> callStack) |
| 94 { | 86 { |
| 95 StringBuilder stackTrace; | 87 StringBuilder stackTrace; |
| 96 for (size_t i = 0; i < callStack->size(); ++i) { | 88 for (size_t i = 0; i < callStack->size(); ++i) { |
| 97 const ScriptCallFrame& frame = callStack->at(i); | 89 const ScriptCallFrame& frame = callStack->at(i); |
| 98 stackTrace.append("\n at " + (frame.functionName().length() ? frame.f
unctionName() : "(anonymous function)")); | 90 stackTrace.append("\n at " + (frame.functionName().length() ? frame.f
unctionName() : "(anonymous function)")); |
| 99 stackTrace.append(" ("); | 91 stackTrace.append(" ("); |
| 100 stackTrace.append(frame.sourceURL()); | 92 stackTrace.append(frame.sourceURL()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 113 muteCount++; | 105 muteCount++; |
| 114 } | 106 } |
| 115 | 107 |
| 116 void FrameConsole::unmute() | 108 void FrameConsole::unmute() |
| 117 { | 109 { |
| 118 ASSERT(muteCount > 0); | 110 ASSERT(muteCount > 0); |
| 119 muteCount--; | 111 muteCount--; |
| 120 } | 112 } |
| 121 | 113 |
| 122 } // namespace WebCore | 114 } // namespace WebCore |
| OLD | NEW |