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 ConsoleAgent.enable();
60 * @param {WebInspector.ConsoleMessage} msg
62 addMessage: function(msg)
64 this.messages.push(msg);
65 this._previousMessage = msg;
66 this._incrementErrorWarningCount(msg);
67 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAdded, msg);
68 this._interruptRepeatCount = false;
72 * @param {WebInspector.ConsoleMessage} msg
74 _incrementErrorWarningCount: function(msg)
77 case WebInspector.ConsoleMessage.MessageLevel.Warning:
78 this.warnings += msg.repeatDelta;
80 case WebInspector.ConsoleMessage.MessageLevel.Error:
81 this.errors += msg.repeatDelta;
86 requestClearMessages: function()
88 ConsoleAgent.clearMessages();
92 clearMessages: function()
99 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCleared);
102 interruptRepeatCount: function()
104 this._interruptRepeatCount = true;
107 _messageRepeatCountUpdated: function(count)
109 var msg = this._previousMessage;
113 var prevRepeatCount = msg.totalRepeatCount;
115 if (!this._interruptRepeatCount) {
116 msg.repeatDelta = count - prevRepeatCount;
117 msg.repeatCount = msg.repeatCount + msg.repeatDelta;
118 msg.totalRepeatCount = count;
119 msg.updateRepeatCount();
121 this._incrementErrorWarningCount(msg);
122 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.RepeatCountUpdated, msg);
124 var msgCopy = WebInspector.ConsoleMessage.create(msg.source, msg.level, msg._messageText, msg.type, msg.url, msg.line, count - prevRepeatCount, msg._parameters, msg._stackTrace, msg._request);
125 msgCopy.totalRepeatCount = count;
126 this.addMessage(msgCopy);
131 WebInspector.ConsoleModel.prototype.__proto__ = WebInspector.Object.prototype;
136 WebInspector.ConsoleMessage = function()
138 this.repeatDelta = 0;
139 this.repeatCount = 0;
140 this._totalRepeatCount = 0;
143 WebInspector.ConsoleMessage.prototype = {
147 get totalRepeatCount()
149 return this._totalRepeatCount;
152 set totalRepeatCount(totalRepeatCount)
154 this._totalRepeatCount = totalRepeatCount;
157 updateRepeatCount: function()
159 // Implemented by concrete instances
164 * @param {string} source
165 * @param {string} level
166 * @param {string} message
167 * @param {string=} type
168 * @param {string=} url
169 * @param {number=} line
170 * @param {number=} repeatCount
171 * @param {Array.<RuntimeAgent.RemoteObject>=} parameters
172 * @param {ConsoleAgent.StackTrace=} stackTrace
173 * @param {WebInspector.Resource=} request
175 * @return {WebInspector.ConsoleMessage}
177 WebInspector.ConsoleMessage.create = function(source, level, message, type, url, line, repeatCount, parameters, stackTrace, request)
181 // Note: Keep these constants in sync with the ones in Console.h
182 WebInspector.ConsoleMessage.MessageSource = {
187 ConsoleAPI: "console-api",
191 WebInspector.ConsoleMessage.MessageType = {
196 StartGroup: "startGroup",
197 StartGroupCollapsed: "startGroupCollapsed",
198 EndGroup: "endGroup",
203 WebInspector.ConsoleMessage.MessageLevel = {
214 * @implements {ConsoleAgent.Dispatcher}
215 * @param {WebInspector.ConsoleModel} console
217 WebInspector.ConsoleDispatcher = function(console)
219 this._console = console;
222 WebInspector.ConsoleDispatcher.prototype = {
224 * @param {ConsoleAgent.ConsoleMessage} payload
226 messageAdded: function(payload)
228 var consoleMessage = WebInspector.ConsoleMessage.create(
238 payload.networkRequestId ? WebInspector.networkResourceById(payload.networkRequestId) : undefined);
239 this._console.addMessage(consoleMessage);
243 * @param {number} count
245 messageRepeatCountUpdated: function(count)
247 this._console._messageRepeatCountUpdated(count);
250 messagesCleared: function()
252 if (!WebInspector.settings.preserveConsoleLog.get())
253 this._console.clearMessages();
258 * @type {?WebInspector.ConsoleModel}
260 WebInspector.console = null;