Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: third_party/WebKit/Source/core/frame/FrameConsole.cpp

Issue 2035653006: [DevTools] Move Console to v8 inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: improved api a bit Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 #include <memory> 41 #include <memory>
42 42
43 namespace blink { 43 namespace blink {
44 44
45 namespace {
46
47 int muteCount = 0;
48
49 }
50
51 FrameConsole::FrameConsole(LocalFrame& frame) 45 FrameConsole::FrameConsole(LocalFrame& frame)
52 : m_frame(&frame) 46 : m_frame(&frame)
53 { 47 {
54 } 48 }
55 49
56 void FrameConsole::addMessage(ConsoleMessage* consoleMessage) 50 void FrameConsole::addMessage(ConsoleMessage* consoleMessage)
57 { 51 {
58 if (addMessageToStorage(consoleMessage)) 52 if (addMessageToStorage(consoleMessage))
59 reportMessageToClient(consoleMessage); 53 reportMessageToClient(consoleMessage);
60 } 54 }
61 55
62 bool FrameConsole::addMessageToStorage(ConsoleMessage* consoleMessage) 56 bool FrameConsole::addMessageToStorage(ConsoleMessage* consoleMessage)
63 { 57 {
64 if (muteCount && consoleMessage->source() != ConsoleAPIMessageSource) 58 // TODO(dgozman): drop this check, it's left here to preserve tests output.
59 if (!m_frame->document())
65 return false; 60 return false;
66 if (!m_frame->document() || !messageStorage()) 61 MainThreadDebugger* debugger = MainThreadDebugger::instance();
67 return false; 62 return debugger->debugger()->addConsoleMessage(
68 messageStorage()->reportMessage(m_frame->document(), consoleMessage); 63 debugger->contextGroupId(m_frame),
69 return true; 64 consoleMessage->source(),
65 consoleMessage->level(),
66 consoleMessage->message(),
67 consoleMessage->location()->url(),
68 consoleMessage->location()->lineNumber(),
69 consoleMessage->location()->columnNumber(),
70 consoleMessage->location()->cloneStackTrace(),
71 consoleMessage->location()->scriptId(),
72 IdentifiersFactory::requestId(consoleMessage->requestIdentifier()));
70 } 73 }
71 74
72 void FrameConsole::reportMessageToClient(ConsoleMessage* consoleMessage) 75 void FrameConsole::reportMessageToClient(ConsoleMessage* consoleMessage)
73 { 76 {
74 if (muteCount && consoleMessage->source() != ConsoleAPIMessageSource)
75 return;
76 if (consoleMessage->source() == NetworkMessageSource) 77 if (consoleMessage->source() == NetworkMessageSource)
77 return; 78 return;
78 79
79 String url = consoleMessage->location()->url(); 80 String url = consoleMessage->location()->url();
80 String stackTrace; 81 String stackTrace;
81 if (consoleMessage->source() == ConsoleAPIMessageSource) { 82 if (consoleMessage->source() == ConsoleAPIMessageSource) {
82 if (!frame().host()) 83 if (!frame().host())
83 return; 84 return;
84 if (frame().chromeClient().shouldReportDetailedMessageForSource(frame(), url)) { 85 if (frame().chromeClient().shouldReportDetailedMessageForSource(frame(), url)) {
85 std::unique_ptr<SourceLocation> location = SourceLocation::captureWi thFullStackTrace(); 86 std::unique_ptr<SourceLocation> location = SourceLocation::captureWi thFullStackTrace();
(...skipping 24 matching lines...) Expand all
110 return; 111 return;
111 if (response.httpStatusCode() < 400) 112 if (response.httpStatusCode() < 400)
112 return; 113 return;
113 if (response.wasFallbackRequiredByServiceWorker()) 114 if (response.wasFallbackRequiredByServiceWorker())
114 return; 115 return;
115 String message = "Failed to load resource: the server responded with a statu s of " + String::number(response.httpStatusCode()) + " (" + response.httpStatusT ext() + ')'; 116 String message = "Failed to load resource: the server responded with a statu s of " + String::number(response.httpStatusCode()) + " (" + response.httpStatusT ext() + ')';
116 ConsoleMessage* consoleMessage = ConsoleMessage::createForRequest(NetworkMes sageSource, ErrorMessageLevel, message, response.url().getString(), requestIdent ifier); 117 ConsoleMessage* consoleMessage = ConsoleMessage::createForRequest(NetworkMes sageSource, ErrorMessageLevel, message, response.url().getString(), requestIdent ifier);
117 addMessage(consoleMessage); 118 addMessage(consoleMessage);
118 } 119 }
119 120
120 void FrameConsole::mute()
121 {
122 muteCount++;
123 }
124
125 void FrameConsole::unmute()
126 {
127 ASSERT(muteCount > 0);
128 muteCount--;
129 }
130
131 ConsoleMessageStorage* FrameConsole::messageStorage()
132 {
133 if (!m_frame->host())
134 return nullptr;
135 return &m_frame->host()->consoleMessageStorage();
136 }
137
138 void FrameConsole::clearMessages()
139 {
140 ConsoleMessageStorage* storage = messageStorage();
141 if (storage)
142 storage->clear(m_frame->document());
143 }
144
145 void FrameConsole::didFailLoading(unsigned long requestIdentifier, const Resourc eError& error) 121 void FrameConsole::didFailLoading(unsigned long requestIdentifier, const Resourc eError& error)
146 { 122 {
147 if (error.isCancellation()) // Report failures only. 123 if (error.isCancellation()) // Report failures only.
148 return; 124 return;
149 ConsoleMessageStorage* storage = messageStorage();
150 if (!storage)
151 return;
152 StringBuilder message; 125 StringBuilder message;
153 message.append("Failed to load resource"); 126 message.append("Failed to load resource");
154 if (!error.localizedDescription().isEmpty()) { 127 if (!error.localizedDescription().isEmpty()) {
155 message.append(": "); 128 message.append(": ");
156 message.append(error.localizedDescription()); 129 message.append(error.localizedDescription());
157 } 130 }
158 ConsoleMessage* consoleMessage = ConsoleMessage::createForRequest(NetworkMes sageSource, ErrorMessageLevel, message.toString(), error.failingURL(), requestId entifier); 131 addMessageToStorage(ConsoleMessage::createForRequest(NetworkMessageSource, E rrorMessageLevel, message.toString(), error.failingURL(), requestIdentifier));
159 storage->reportMessage(m_frame->document(), consoleMessage);
160 } 132 }
161 133
162 DEFINE_TRACE(FrameConsole) 134 DEFINE_TRACE(FrameConsole)
163 { 135 {
164 visitor->trace(m_frame); 136 visitor->trace(m_frame);
165 } 137 }
166 138
167 } // namespace blink 139 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameConsole.h ('k') | third_party/WebKit/Source/core/frame/FrameHost.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698