2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @extends {WebInspector.Object}
35 WebInspector.ConsoleModel = function()
40 this._interruptRepeatCount = false;
41 InspectorBackend.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this));
44 WebInspector.ConsoleModel.Events = {
45 ConsoleCleared: "console-cleared",
46 MessageAdded: "console-message-added",
47 RepeatCountUpdated: "repeat-count-updated"
50 WebInspector.ConsoleModel.prototype = {
51 enableAgent: function()
53 if (WebInspector.settings.monitoringXHREnabled.get())
54 ConsoleAgent.setMonitoringXHREnabled(true);
56 this._enablingConsole = true;
59 delete this._enablingConsole;
61 ConsoleAgent.enable(callback.bind(this));
67 enablingConsole: function()
69 return !!this._enablingConsole;
73 * @param {WebInspector.ConsoleMessage} msg
74 * @param {boolean=} isFromBackend
76 addMessage: function(msg, isFromBackend)
78 if (isFromBackend && WebInspector.SourceMap.hasSourceMapRequestHeader(msg.request()))
81 msg.index = this.messages.length;
82 this.messages.push(msg);
83 this._incrementErrorWarningCount(msg);
86 this._previousMessage = msg;
88 this._interruptRepeatCount = !isFromBackend;
90 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAdded, msg);
94 * @param {WebInspector.ConsoleMessage} msg
96 _incrementErrorWarningCount: function(msg)
99 case WebInspector.ConsoleMessage.MessageLevel.Warning:
100 this.warnings += msg.repeatDelta;
102 case WebInspector.ConsoleMessage.MessageLevel.Error:
103 this.errors += msg.repeatDelta;
108 requestClearMessages: function()
110 ConsoleAgent.clearMessages();
111 this.clearMessages();
114 clearMessages: function()
116 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCleared);
119 delete this._previousMessage;
126 * @param {number} count
128 _messageRepeatCountUpdated: function(count)
130 var msg = this._previousMessage;
134 var prevRepeatCount = msg.totalRepeatCount;
136 if (!this._interruptRepeatCount) {
137 msg.repeatDelta = count - prevRepeatCount;
138 msg.repeatCount = msg.repeatCount + msg.repeatDelta;
139 msg.totalRepeatCount = count;
140 msg.updateRepeatCount();
142 this._incrementErrorWarningCount(msg);
143 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.RepeatCountUpdated, msg);
145 var msgCopy = msg.clone();
146 msgCopy.totalRepeatCount = count;
147 msgCopy.repeatCount = (count - prevRepeatCount) || 1;
148 msgCopy.repeatDelta = msgCopy.repeatCount;
149 this.addMessage(msgCopy, true);
153 __proto__: WebInspector.Object.prototype
158 * @param {string} source
159 * @param {string} level
160 * @param {string=} url
161 * @param {number=} line
162 * @param {number=} column
163 * @param {number=} repeatCount
165 WebInspector.ConsoleMessage = function(source, level, url, line, column, repeatCount)
167 this.source = source;
169 this.url = url || null;
170 this.line = line || 0;
171 this.column = column || 0;
174 repeatCount = repeatCount || 1;
175 this.repeatCount = repeatCount;
176 this.repeatDelta = repeatCount;
177 this.totalRepeatCount = repeatCount;
180 WebInspector.ConsoleMessage.prototype = {
184 isErrorOrWarning: function()
186 return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning || this.level === WebInspector.ConsoleMessage.MessageLevel.Error);
189 updateRepeatCount: function()
191 // Implemented by concrete instances
195 * @return {WebInspector.ConsoleMessage}
199 // Implemented by concrete instances
203 * @return {WebInspector.DebuggerModel.Location}
207 // Implemented by concrete instances
212 * @param {string} source
213 * @param {string} level
214 * @param {string} message
215 * @param {string=} type
216 * @param {string=} url
217 * @param {number=} line
218 * @param {number=} column
219 * @param {number=} repeatCount
220 * @param {Array.<RuntimeAgent.RemoteObject>=} parameters
221 * @param {ConsoleAgent.StackTrace=} stackTrace
222 * @param {NetworkAgent.RequestId=} requestId
223 * @param {boolean=} isOutdated
224 * @return {WebInspector.ConsoleMessage}
226 WebInspector.ConsoleMessage.create = function(source, level, message, type, url, line, column, repeatCount, parameters, stackTrace, requestId, isOutdated)
230 // Note: Keep these constants in sync with the ones in Console.h
231 WebInspector.ConsoleMessage.MessageSource = {
235 ConsoleAPI: "console-api",
237 AppCache: "appcache",
238 Rendering: "rendering",
240 Security: "security",
242 Deprecation: "deprecation"
245 WebInspector.ConsoleMessage.MessageType = {
252 StartGroup: "startGroup",
253 StartGroupCollapsed: "startGroupCollapsed",
254 EndGroup: "endGroup",
258 ProfileEnd: "profileEnd"
261 WebInspector.ConsoleMessage.MessageLevel = {
272 * @implements {ConsoleAgent.Dispatcher}
273 * @param {WebInspector.ConsoleModel} console
275 WebInspector.ConsoleDispatcher = function(console)
277 this._console = console;
280 WebInspector.ConsoleDispatcher.prototype = {
282 * @param {ConsoleAgent.ConsoleMessage} payload
284 messageAdded: function(payload)
286 var consoleMessage = WebInspector.ConsoleMessage.create(
297 payload.networkRequestId,
298 this._console._enablingConsole);
299 this._console.addMessage(consoleMessage, true);
303 * @param {number} count
305 messageRepeatCountUpdated: function(count)
307 this._console._messageRepeatCountUpdated(count);
310 messagesCleared: function()
312 if (!WebInspector.settings.preserveConsoleLog.get())
313 this._console.clearMessages();
318 * @type {?WebInspector.ConsoleModel}
320 WebInspector.console = null;