123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- /*
- * Copyright (C) 2011 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- /**
- * @constructor
- * @extends {WebInspector.Object}
- */
- WebInspector.ConsoleModel = function()
- {
- this.messages = [];
- this.warnings = 0;
- this.errors = 0;
- this._interruptRepeatCount = false;
- InspectorBackend.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this));
- }
- WebInspector.ConsoleModel.Events = {
- ConsoleCleared: "console-cleared",
- MessageAdded: "console-message-added",
- RepeatCountUpdated: "repeat-count-updated"
- }
- WebInspector.ConsoleModel.prototype = {
- enableAgent: function()
- {
- if (WebInspector.settings.monitoringXHREnabled.get())
- ConsoleAgent.setMonitoringXHREnabled(true);
- this._enablingConsole = true;
- function callback()
- {
- delete this._enablingConsole;
- }
- ConsoleAgent.enable(callback.bind(this));
- },
- /**
- * @return {boolean}
- */
- enablingConsole: function()
- {
- return !!this._enablingConsole;
- },
- /**
- * @param {WebInspector.ConsoleMessage} msg
- * @param {boolean=} isFromBackend
- */
- addMessage: function(msg, isFromBackend)
- {
- if (isFromBackend && WebInspector.SourceMap.hasSourceMapRequestHeader(msg.request()))
- return;
- msg.index = this.messages.length;
- this.messages.push(msg);
- this._incrementErrorWarningCount(msg);
- if (isFromBackend)
- this._previousMessage = msg;
- this._interruptRepeatCount = !isFromBackend;
- this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAdded, msg);
- },
- /**
- * @param {WebInspector.ConsoleMessage} msg
- */
- _incrementErrorWarningCount: function(msg)
- {
- switch (msg.level) {
- case WebInspector.ConsoleMessage.MessageLevel.Warning:
- this.warnings += msg.repeatDelta;
- break;
- case WebInspector.ConsoleMessage.MessageLevel.Error:
- this.errors += msg.repeatDelta;
- break;
- }
- },
- requestClearMessages: function()
- {
- ConsoleAgent.clearMessages();
- this.clearMessages();
- },
- clearMessages: function()
- {
- this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCleared);
- this.messages = [];
- delete this._previousMessage;
- this.errors = 0;
- this.warnings = 0;
- },
- /**
- * @param {number} count
- */
- _messageRepeatCountUpdated: function(count)
- {
- var msg = this._previousMessage;
- if (!msg)
- return;
- var prevRepeatCount = msg.totalRepeatCount;
- if (!this._interruptRepeatCount) {
- msg.repeatDelta = count - prevRepeatCount;
- msg.repeatCount = msg.repeatCount + msg.repeatDelta;
- msg.totalRepeatCount = count;
- msg.updateRepeatCount();
- this._incrementErrorWarningCount(msg);
- this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.RepeatCountUpdated, msg);
- } else {
- var msgCopy = msg.clone();
- msgCopy.totalRepeatCount = count;
- msgCopy.repeatCount = (count - prevRepeatCount) || 1;
- msgCopy.repeatDelta = msgCopy.repeatCount;
- this.addMessage(msgCopy, true);
- }
- },
- __proto__: WebInspector.Object.prototype
- }
- /**
- * @constructor
- * @param {string} source
- * @param {string} level
- * @param {string=} url
- * @param {number=} line
- * @param {number=} column
- * @param {number=} repeatCount
- */
- WebInspector.ConsoleMessage = function(source, level, url, line, column, repeatCount)
- {
- this.source = source;
- this.level = level;
- this.url = url || null;
- this.line = line || 0;
- this.column = column || 0;
- this.message = "";
- repeatCount = repeatCount || 1;
- this.repeatCount = repeatCount;
- this.repeatDelta = repeatCount;
- this.totalRepeatCount = repeatCount;
- }
- WebInspector.ConsoleMessage.prototype = {
- /**
- * @return {boolean}
- */
- isErrorOrWarning: function()
- {
- return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning || this.level === WebInspector.ConsoleMessage.MessageLevel.Error);
- },
- updateRepeatCount: function()
- {
- // Implemented by concrete instances
- },
- /**
- * @return {WebInspector.ConsoleMessage}
- */
- clone: function()
- {
- // Implemented by concrete instances
- },
- /**
- * @return {WebInspector.DebuggerModel.Location}
- */
- location: function()
- {
- // Implemented by concrete instances
- }
- }
- /**
- * @param {string} source
- * @param {string} level
- * @param {string} message
- * @param {string=} type
- * @param {string=} url
- * @param {number=} line
- * @param {number=} column
- * @param {number=} repeatCount
- * @param {Array.<RuntimeAgent.RemoteObject>=} parameters
- * @param {ConsoleAgent.StackTrace=} stackTrace
- * @param {NetworkAgent.RequestId=} requestId
- * @param {boolean=} isOutdated
- * @return {WebInspector.ConsoleMessage}
- */
- WebInspector.ConsoleMessage.create = function(source, level, message, type, url, line, column, repeatCount, parameters, stackTrace, requestId, isOutdated)
- {
- }
- // Note: Keep these constants in sync with the ones in Console.h
- WebInspector.ConsoleMessage.MessageSource = {
- XML: "xml",
- JS: "javascript",
- Network: "network",
- ConsoleAPI: "console-api",
- Storage: "storage",
- AppCache: "appcache",
- Rendering: "rendering",
- CSS: "css",
- Security: "security",
- Other: "other",
- Deprecation: "deprecation"
- }
- WebInspector.ConsoleMessage.MessageType = {
- Log: "log",
- Dir: "dir",
- DirXML: "dirxml",
- Table: "table",
- Trace: "trace",
- Clear: "clear",
- StartGroup: "startGroup",
- StartGroupCollapsed: "startGroupCollapsed",
- EndGroup: "endGroup",
- Assert: "assert",
- Result: "result",
- Profile: "profile",
- ProfileEnd: "profileEnd"
- }
- WebInspector.ConsoleMessage.MessageLevel = {
- Log: "log",
- Warning: "warning",
- Error: "error",
- Debug: "debug"
- }
- /**
- * @constructor
- * @implements {ConsoleAgent.Dispatcher}
- * @param {WebInspector.ConsoleModel} console
- */
- WebInspector.ConsoleDispatcher = function(console)
- {
- this._console = console;
- }
- WebInspector.ConsoleDispatcher.prototype = {
- /**
- * @param {ConsoleAgent.ConsoleMessage} payload
- */
- messageAdded: function(payload)
- {
- var consoleMessage = WebInspector.ConsoleMessage.create(
- payload.source,
- payload.level,
- payload.text,
- payload.type,
- payload.url,
- payload.line,
- payload.column,
- payload.repeatCount,
- payload.parameters,
- payload.stackTrace,
- payload.networkRequestId,
- this._console._enablingConsole);
- this._console.addMessage(consoleMessage, true);
- },
- /**
- * @param {number} count
- */
- messageRepeatCountUpdated: function(count)
- {
- this._console._messageRepeatCountUpdated(count);
- },
- messagesCleared: function()
- {
- if (!WebInspector.settings.preserveConsoleLog.get())
- this._console.clearMessages();
- }
- }
- /**
- * @type {?WebInspector.ConsoleModel}
- */
- WebInspector.console = null;
|