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

Side by Side Diff: sky/engine/core/frame/FrameConsole.cpp

Issue 922893002: Merge the Sky Engine changes from the SkyDart branch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « sky/engine/core/frame/FrameConsole.h ('k') | sky/engine/core/frame/ImageBitmap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 11 matching lines...) Expand all
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
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 "sky/engine/config.h" 29 #include "sky/engine/config.h"
30 #include "sky/engine/core/frame/FrameConsole.h" 30 #include "sky/engine/core/frame/FrameConsole.h"
31 31
32 #include "sky/engine/bindings/core/v8/ScriptCallStackFactory.h"
33 #include "sky/engine/core/dom/Document.h" 32 #include "sky/engine/core/dom/Document.h"
34 #include "sky/engine/core/frame/FrameHost.h" 33 #include "sky/engine/core/frame/FrameHost.h"
35 #include "sky/engine/core/inspector/ConsoleAPITypes.h" 34 #include "sky/engine/core/inspector/ConsoleAPITypes.h"
36 #include "sky/engine/core/inspector/ConsoleMessage.h" 35 #include "sky/engine/core/inspector/ConsoleMessage.h"
37 #include "sky/engine/core/inspector/ConsoleMessageStorage.h"
38 #include "sky/engine/core/inspector/ScriptArguments.h"
39 #include "sky/engine/core/inspector/ScriptCallStack.h"
40 #include "sky/engine/core/page/ChromeClient.h" 36 #include "sky/engine/core/page/ChromeClient.h"
41 #include "sky/engine/core/page/Page.h" 37 #include "sky/engine/core/page/Page.h"
42 #include "sky/engine/platform/network/ResourceResponse.h" 38 #include "sky/engine/platform/network/ResourceResponse.h"
43 #include "sky/engine/wtf/text/StringBuilder.h" 39 #include "sky/engine/wtf/text/StringBuilder.h"
44 40
45 namespace blink { 41 namespace blink {
46 42
47 static const HashSet<int>& allClientReportingMessageTypes()
48 {
49 DEFINE_STATIC_LOCAL(HashSet<int>, types, ());
50 if (types.isEmpty()) {
51 types.add(LogMessageType);
52 types.add(DirMessageType);
53 types.add(DirXMLMessageType);
54 types.add(TableMessageType);
55 types.add(TraceMessageType);
56 types.add(ClearMessageType);
57 types.add(AssertMessageType);
58 }
59 return types;
60 }
61
62 namespace {
63
64 int muteCount = 0;
65
66 }
67
68 FrameConsole::FrameConsole(LocalFrame& frame) 43 FrameConsole::FrameConsole(LocalFrame& frame)
69 : m_frame(frame) 44 : m_frame(frame)
70 { 45 {
71 } 46 }
72 47
73 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(FrameConsole); 48 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(FrameConsole);
74 49
75 void FrameConsole::addMessage(PassRefPtr<ConsoleMessage> prpConsoleMessage) 50 void FrameConsole::addMessage(PassRefPtr<ConsoleMessage> prpConsoleMessage)
76 { 51 {
77 RefPtr<ConsoleMessage> consoleMessage = prpConsoleMessage; 52 RefPtr<ConsoleMessage> consoleMessage = prpConsoleMessage;
78 if (muteCount && consoleMessage->source() != ConsoleAPIMessageSource)
79 return;
80 53
81 // FIXME: This should not need to reach for the main-frame. 54 // FIXME: This should not need to reach for the main-frame.
82 // Inspector code should just take the current frame and know how to walk it self. 55 // Inspector code should just take the current frame and know how to walk it self.
83 ExecutionContext* context = m_frame.document(); 56 ExecutionContext* context = m_frame.document();
84 if (!context) 57 if (!context)
85 return; 58 return;
86 59
87 String messageURL; 60 String messageURL = consoleMessage->url();
88 unsigned lineNumber = 0; 61 unsigned lineNumber = consoleMessage->lineNumber();
89 if (consoleMessage->callStack() && consoleMessage->callStack()->size()) { 62 m_frame.page()->addMessageToConsole(&m_frame, consoleMessage->source(), cons oleMessage->level(), consoleMessage->message(), lineNumber, messageURL, String() );
90 lineNumber = consoleMessage->callStack()->at(0).lineNumber();
91 messageURL = consoleMessage->callStack()->at(0).sourceURL();
92 } else {
93 lineNumber = consoleMessage->lineNumber();
94 messageURL = consoleMessage->url();
95 }
96
97 messageStorage()->reportMessage(consoleMessage);
98
99 RefPtr<ScriptCallStack> reportedCallStack = nullptr;
100 if (consoleMessage->source() != ConsoleAPIMessageSource) {
101 if (consoleMessage->callStack() && m_frame.page()->shouldReportDetailedM essageForSource(messageURL))
102 reportedCallStack = consoleMessage->callStack();
103 } else {
104 if (!m_frame.host() || (consoleMessage->scriptArguments() && consoleMess age->scriptArguments()->argumentCount() == 0))
105 return;
106
107 if (!allClientReportingMessageTypes().contains(consoleMessage->type()))
108 return;
109
110 if (m_frame.page()->shouldReportDetailedMessageForSource(messageURL))
111 reportedCallStack = createScriptCallStack(ScriptCallStack::maxCallSt ackSizeToCapture);
112 }
113
114 String stackTrace;
115 if (reportedCallStack)
116 stackTrace = FrameConsole::formatStackTraceString(consoleMessage->messag e(), reportedCallStack);
117 m_frame.page()->addMessageToConsole(&m_frame, consoleMessage->source(), cons oleMessage->level(), consoleMessage->message(), lineNumber, messageURL, stackTra ce);
118 } 63 }
119 64
120 void FrameConsole::reportResourceResponseReceived(Document* document, unsigned l ong requestIdentifier, const ResourceResponse& response) 65 void FrameConsole::reportResourceResponseReceived(Document* document, unsigned l ong requestIdentifier, const ResourceResponse& response)
121 { 66 {
122 if (!document) 67 if (!document)
123 return; 68 return;
124 if (response.httpStatusCode() < 400) 69 if (response.httpStatusCode() < 400)
125 return; 70 return;
126 String message = "Failed to load resource: the server responded with a statu s of " + String::number(response.httpStatusCode()) + " (" + response.httpStatusT ext() + ')'; 71 String message = "Failed to load resource: the server responded with a statu s of " + String::number(response.httpStatusCode()) + " (" + response.httpStatusT ext() + ')';
127 RefPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(NetworkMessag eSource, ErrorMessageLevel, message, response.url().string()); 72 RefPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(NetworkMessag eSource, ErrorMessageLevel, message, response.url().string());
128 consoleMessage->setRequestIdentifier(requestIdentifier); 73 consoleMessage->setRequestIdentifier(requestIdentifier);
129 addMessage(consoleMessage.release()); 74 addMessage(consoleMessage.release());
130 } 75 }
131 76
132 String FrameConsole::formatStackTraceString(const String& originalMessage, PassR efPtr<ScriptCallStack> callStack)
133 {
134 StringBuilder stackTrace;
135 for (size_t i = 0; i < callStack->size(); ++i) {
136 const ScriptCallFrame& frame = callStack->at(i);
137 stackTrace.append("\n at " + (frame.functionName().length() ? frame.f unctionName() : "(anonymous function)"));
138 stackTrace.appendLiteral(" (");
139 stackTrace.append(frame.sourceURL());
140 stackTrace.append(':');
141 stackTrace.append(String::number(frame.lineNumber()));
142 stackTrace.append(':');
143 stackTrace.append(String::number(frame.columnNumber()));
144 stackTrace.append(')');
145 }
146
147 return stackTrace.toString();
148 }
149
150 void FrameConsole::mute()
151 {
152 muteCount++;
153 }
154
155 void FrameConsole::unmute()
156 {
157 ASSERT(muteCount > 0);
158 muteCount--;
159 }
160
161 ConsoleMessageStorage* FrameConsole::messageStorage()
162 {
163 if (!m_consoleMessageStorage)
164 m_consoleMessageStorage = ConsoleMessageStorage::createForFrame(&m_frame );
165 return m_consoleMessageStorage.get();
166 }
167
168 void FrameConsole::clearMessages()
169 {
170 messageStorage()->clear();
171 }
172
173 } // namespace blink 77 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/core/frame/FrameConsole.h ('k') | sky/engine/core/frame/ImageBitmap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698