| 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 "core/frame/FrameConsole.h" | 29 #include "core/frame/FrameConsole.h" |
| 30 | 30 |
| 31 #include "bindings/core/v8/SourceLocation.h" | 31 #include "bindings/core/v8/SourceLocation.h" |
| 32 #include "core/frame/FrameHost.h" | 32 #include "core/frame/FrameHost.h" |
| 33 #include "core/inspector/ConsoleMessage.h" | 33 #include "core/inspector/ConsoleMessage.h" |
| 34 #include "core/inspector/ConsoleMessageStorage.h" | 34 #include "core/inspector/IdentifiersFactory.h" |
| 35 #include "core/inspector/InspectorConsoleInstrumentation.h" | 35 #include "core/inspector/MainThreadDebugger.h" |
| 36 #include "core/page/ChromeClient.h" | 36 #include "core/page/ChromeClient.h" |
| 37 #include "core/page/Page.h" | 37 #include "core/page/Page.h" |
| 38 #include "platform/network/ResourceError.h" | 38 #include "platform/network/ResourceError.h" |
| 39 #include "platform/network/ResourceResponse.h" | 39 #include "platform/network/ResourceResponse.h" |
| 40 #include "wtf/text/StringBuilder.h" | 40 #include "wtf/text/StringBuilder.h" |
| 41 | 41 |
| 42 namespace blink { | 42 namespace blink { |
| 43 | 43 |
| 44 namespace { | |
| 45 | |
| 46 int muteCount = 0; | |
| 47 | |
| 48 } | |
| 49 | |
| 50 FrameConsole::FrameConsole(LocalFrame& frame) | 44 FrameConsole::FrameConsole(LocalFrame& frame) |
| 51 : m_frame(&frame) | 45 : m_frame(&frame) |
| 52 { | 46 { |
| 53 } | 47 } |
| 54 | 48 |
| 55 void FrameConsole::addMessage(ConsoleMessage* consoleMessage) | 49 void FrameConsole::addMessage(ConsoleMessage* consoleMessage) |
| 56 { | 50 { |
| 57 if (addMessageToStorage(consoleMessage)) | 51 if (addMessageToStorage(consoleMessage)) |
| 58 reportMessageToClient(consoleMessage); | 52 reportMessageToClient(consoleMessage); |
| 59 } | 53 } |
| 60 | 54 |
| 61 bool FrameConsole::addMessageToStorage(ConsoleMessage* consoleMessage) | 55 bool FrameConsole::addMessageToStorage(ConsoleMessage* consoleMessage) |
| 62 { | 56 { |
| 63 if (muteCount && consoleMessage->source() != ConsoleAPIMessageSource) | 57 // TODO(dgozman): drop this check, it's left here to preserve tests output. |
| 58 if (!m_frame->document()) |
| 64 return false; | 59 return false; |
| 65 if (!m_frame->document() || !messageStorage()) | 60 MainThreadDebugger* debugger = MainThreadDebugger::instance(); |
| 66 return false; | 61 return debugger->debugger()->addConsoleMessage( |
| 67 messageStorage()->reportMessage(m_frame->document(), consoleMessage); | 62 debugger->contextGroupId(m_frame), |
| 68 return true; | 63 consoleMessage->source(), |
| 64 consoleMessage->level(), |
| 65 consoleMessage->message(), |
| 66 consoleMessage->location()->url(), |
| 67 consoleMessage->location()->lineNumber(), |
| 68 consoleMessage->location()->columnNumber(), |
| 69 consoleMessage->location()->cloneStackTrace(), |
| 70 consoleMessage->location()->scriptId(), |
| 71 IdentifiersFactory::requestId(consoleMessage->requestIdentifier())); |
| 69 } | 72 } |
| 70 | 73 |
| 71 void FrameConsole::reportMessageToClient(ConsoleMessage* consoleMessage) | 74 void FrameConsole::reportMessageToClient(ConsoleMessage* consoleMessage) |
| 72 { | 75 { |
| 73 if (muteCount && consoleMessage->source() != ConsoleAPIMessageSource) | |
| 74 return; | |
| 75 if (consoleMessage->source() == NetworkMessageSource) | 76 if (consoleMessage->source() == NetworkMessageSource) |
| 76 return; | 77 return; |
| 77 | 78 |
| 78 String url = consoleMessage->location()->url(); | 79 String url = consoleMessage->location()->url(); |
| 79 String stackTrace; | 80 String stackTrace; |
| 80 if (consoleMessage->source() == ConsoleAPIMessageSource) { | 81 if (consoleMessage->source() == ConsoleAPIMessageSource) { |
| 81 if (!frame().host()) | 82 if (!frame().host()) |
| 82 return; | 83 return; |
| 83 if (frame().chromeClient().shouldReportDetailedMessageForSource(frame(),
url)) { | 84 if (frame().chromeClient().shouldReportDetailedMessageForSource(frame(),
url)) { |
| 84 OwnPtr<SourceLocation> location = SourceLocation::captureWithFullSta
ckTrace(); | 85 OwnPtr<SourceLocation> location = SourceLocation::captureWithFullSta
ckTrace(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 109 return; | 110 return; |
| 110 if (response.httpStatusCode() < 400) | 111 if (response.httpStatusCode() < 400) |
| 111 return; | 112 return; |
| 112 if (response.wasFallbackRequiredByServiceWorker()) | 113 if (response.wasFallbackRequiredByServiceWorker()) |
| 113 return; | 114 return; |
| 114 String message = "Failed to load resource: the server responded with a statu
s of " + String::number(response.httpStatusCode()) + " (" + response.httpStatusT
ext() + ')'; | 115 String message = "Failed to load resource: the server responded with a statu
s of " + String::number(response.httpStatusCode()) + " (" + response.httpStatusT
ext() + ')'; |
| 115 ConsoleMessage* consoleMessage = ConsoleMessage::createForRequest(NetworkMes
sageSource, ErrorMessageLevel, message, response.url().getString(), requestIdent
ifier); | 116 ConsoleMessage* consoleMessage = ConsoleMessage::createForRequest(NetworkMes
sageSource, ErrorMessageLevel, message, response.url().getString(), requestIdent
ifier); |
| 116 addMessage(consoleMessage); | 117 addMessage(consoleMessage); |
| 117 } | 118 } |
| 118 | 119 |
| 119 void FrameConsole::mute() | |
| 120 { | |
| 121 muteCount++; | |
| 122 } | |
| 123 | |
| 124 void FrameConsole::unmute() | |
| 125 { | |
| 126 ASSERT(muteCount > 0); | |
| 127 muteCount--; | |
| 128 } | |
| 129 | |
| 130 ConsoleMessageStorage* FrameConsole::messageStorage() | |
| 131 { | |
| 132 if (!m_frame->host()) | |
| 133 return nullptr; | |
| 134 return &m_frame->host()->consoleMessageStorage(); | |
| 135 } | |
| 136 | |
| 137 void FrameConsole::clearMessages() | |
| 138 { | |
| 139 ConsoleMessageStorage* storage = messageStorage(); | |
| 140 if (storage) | |
| 141 storage->clear(m_frame->document()); | |
| 142 } | |
| 143 | |
| 144 void FrameConsole::didFailLoading(unsigned long requestIdentifier, const Resourc
eError& error) | 120 void FrameConsole::didFailLoading(unsigned long requestIdentifier, const Resourc
eError& error) |
| 145 { | 121 { |
| 146 if (error.isCancellation()) // Report failures only. | 122 if (error.isCancellation()) // Report failures only. |
| 147 return; | 123 return; |
| 148 ConsoleMessageStorage* storage = messageStorage(); | |
| 149 if (!storage) | |
| 150 return; | |
| 151 StringBuilder message; | 124 StringBuilder message; |
| 152 message.append("Failed to load resource"); | 125 message.append("Failed to load resource"); |
| 153 if (!error.localizedDescription().isEmpty()) { | 126 if (!error.localizedDescription().isEmpty()) { |
| 154 message.append(": "); | 127 message.append(": "); |
| 155 message.append(error.localizedDescription()); | 128 message.append(error.localizedDescription()); |
| 156 } | 129 } |
| 157 ConsoleMessage* consoleMessage = ConsoleMessage::createForRequest(NetworkMes
sageSource, ErrorMessageLevel, message.toString(), error.failingURL(), requestId
entifier); | 130 addMessageToStorage(ConsoleMessage::createForRequest(NetworkMessageSource, E
rrorMessageLevel, message.toString(), error.failingURL(), requestIdentifier)); |
| 158 storage->reportMessage(m_frame->document(), consoleMessage); | |
| 159 } | 131 } |
| 160 | 132 |
| 161 DEFINE_TRACE(FrameConsole) | 133 DEFINE_TRACE(FrameConsole) |
| 162 { | 134 { |
| 163 visitor->trace(m_frame); | 135 visitor->trace(m_frame); |
| 164 } | 136 } |
| 165 | 137 |
| 166 } // namespace blink | 138 } // namespace blink |
| OLD | NEW |