Commit 4405a06d authored by sergeyv@chromium.org's avatar sergeyv@chromium.org

DevTools: Make ConsoleMessage TargetAware

BUG=
R=pfeldman@chromium.org

Review URL: https://codereview.chromium.org/222143003

git-svn-id: svn://svn.chromium.org/blink/trunk@170667 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent b25d76e3
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<script> <script>
function test() function test()
{ {
WebInspector.console.addMessage(new WebInspector.ConsoleMessage(WebInspector.ConsoleMessage.MessageSource.Other, WebInspector.ConsoleMessage.MessageLevel.Log, "PASS")); WebInspector.console.addMessage(new WebInspector.ConsoleMessage(WebInspector.console.target(), WebInspector.ConsoleMessage.MessageSource.Other, WebInspector.ConsoleMessage.MessageLevel.Log, "PASS"));
WebInspector.settings.preserveConsoleLog.set(true); WebInspector.settings.preserveConsoleLog.set(true);
InspectorTest.reloadPage(function() { InspectorTest.reloadPage(function() {
InspectorTest.dumpConsoleMessages(); InspectorTest.dumpConsoleMessages();
......
...@@ -11,6 +11,7 @@ function test() ...@@ -11,6 +11,7 @@ function test()
function addMessageWithFixedTimestamp(messageText, timestamp) function addMessageWithFixedTimestamp(messageText, timestamp)
{ {
var message = new WebInspector.ConsoleMessage( var message = new WebInspector.ConsoleMessage(
WebInspector.console.target(),
WebInspector.ConsoleMessage.MessageSource.Other, // source WebInspector.ConsoleMessage.MessageSource.Other, // source
WebInspector.ConsoleMessage.MessageLevel.Log, // level WebInspector.ConsoleMessage.MessageLevel.Log, // level
messageText, messageText,
......
...@@ -722,6 +722,7 @@ WebInspector.CPUProfileType.prototype = { ...@@ -722,6 +722,7 @@ WebInspector.CPUProfileType.prototype = {
{ {
var script = scriptLocation.script(); var script = scriptLocation.script();
var message = new WebInspector.ConsoleMessage( var message = new WebInspector.ConsoleMessage(
WebInspector.console.target(),
WebInspector.ConsoleMessage.MessageSource.ConsoleAPI, WebInspector.ConsoleMessage.MessageSource.ConsoleAPI,
WebInspector.ConsoleMessage.MessageLevel.Debug, WebInspector.ConsoleMessage.MessageLevel.Debug,
messageText, messageText,
......
...@@ -102,7 +102,7 @@ WebInspector.ConsoleModel.prototype = { ...@@ -102,7 +102,7 @@ WebInspector.ConsoleModel.prototype = {
{ {
this.show(); this.show();
var commandMessage = new WebInspector.ConsoleMessage(WebInspector.ConsoleMessage.MessageSource.JS, null, text, WebInspector.ConsoleMessage.MessageType.Command); var commandMessage = new WebInspector.ConsoleMessage(this.target(), WebInspector.ConsoleMessage.MessageSource.JS, null, text, WebInspector.ConsoleMessage.MessageType.Command);
this.addMessage(commandMessage); this.addMessage(commandMessage);
/** /**
...@@ -144,6 +144,7 @@ WebInspector.ConsoleModel.prototype = { ...@@ -144,6 +144,7 @@ WebInspector.ConsoleModel.prototype = {
log: function(messageText, messageLevel, showConsole) log: function(messageText, messageLevel, showConsole)
{ {
var message = new WebInspector.ConsoleMessage( var message = new WebInspector.ConsoleMessage(
this.target(),
WebInspector.ConsoleMessage.MessageSource.Other, WebInspector.ConsoleMessage.MessageSource.Other,
messageLevel || WebInspector.ConsoleMessage.MessageLevel.Debug, messageLevel || WebInspector.ConsoleMessage.MessageLevel.Debug,
messageText); messageText);
...@@ -196,6 +197,8 @@ WebInspector.ConsoleModel.prototype = { ...@@ -196,6 +197,8 @@ WebInspector.ConsoleModel.prototype = {
/** /**
* @constructor * @constructor
* @extends {WebInspector.TargetAware}
* @param {!WebInspector.Target} target
* @param {string} source * @param {string} source
* @param {?string} level * @param {?string} level
* @param {string} messageText * @param {string} messageText
...@@ -210,9 +213,9 @@ WebInspector.ConsoleModel.prototype = { ...@@ -210,9 +213,9 @@ WebInspector.ConsoleModel.prototype = {
* @param {boolean=} isOutdated * @param {boolean=} isOutdated
* @param {!RuntimeAgent.ExecutionContextId=} executionContextId * @param {!RuntimeAgent.ExecutionContextId=} executionContextId
*/ */
WebInspector.ConsoleMessage = function(target, source, level, messageText, type, url, line, column, requestId, parameters, stackTrace, timestamp, isOutdated, executionContextId)
WebInspector.ConsoleMessage = function(source, level, messageText, type, url, line, column, requestId, parameters, stackTrace, timestamp, isOutdated, executionContextId)
{ {
WebInspector.TargetAware.call(this, target);
this.source = source; this.source = source;
this.level = level; this.level = level;
this.messageText = messageText; this.messageText = messageText;
...@@ -255,6 +258,7 @@ WebInspector.ConsoleMessage.prototype = { ...@@ -255,6 +258,7 @@ WebInspector.ConsoleMessage.prototype = {
clone: function() clone: function()
{ {
return new WebInspector.ConsoleMessage( return new WebInspector.ConsoleMessage(
this.target(),
this.source, this.source,
this.level, this.level,
this.messageText, this.messageText,
...@@ -310,7 +314,9 @@ WebInspector.ConsoleMessage.prototype = { ...@@ -310,7 +314,9 @@ WebInspector.ConsoleMessage.prototype = {
&& (this.url === msg.url) && (this.url === msg.url)
&& (this.messageText === msg.messageText) && (this.messageText === msg.messageText)
&& (this.request === msg.request); && (this.request === msg.request);
} },
__proto__: WebInspector.TargetAware.prototype
} }
// Note: Keep these constants in sync with the ones in Console.h // Note: Keep these constants in sync with the ones in Console.h
...@@ -379,6 +385,7 @@ WebInspector.ConsoleDispatcher.prototype = { ...@@ -379,6 +385,7 @@ WebInspector.ConsoleDispatcher.prototype = {
messageAdded: function(payload) messageAdded: function(payload)
{ {
var consoleMessage = new WebInspector.ConsoleMessage( var consoleMessage = new WebInspector.ConsoleMessage(
this._console.target(),
payload.source, payload.source,
payload.level, payload.level,
payload.text, payload.text,
......
...@@ -135,10 +135,10 @@ WebInspector.ConsoleView.prototype = { ...@@ -135,10 +135,10 @@ WebInspector.ConsoleView.prototype = {
*/ */
targetAdded: function(target) targetAdded: function(target)
{ {
target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._onConsoleMessageAdded.bind(this, target), this); target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._onConsoleMessageAdded, this);
target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, this); target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, this);
target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.CommandEvaluated, this._commandEvaluated, this); target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.CommandEvaluated, this._commandEvaluated, this);
target.consoleModel.messages.forEach(this._consoleMessageAdded.bind(this, target)); target.consoleModel.messages.forEach(this._consoleMessageAdded, this);
/** /**
* @param {!WebInspector.ExecutionContextList} contextList * @param {!WebInspector.ExecutionContextList} contextList
...@@ -429,7 +429,7 @@ WebInspector.ConsoleView.prototype = { ...@@ -429,7 +429,7 @@ WebInspector.ConsoleView.prototype = {
/** /**
* @param {!WebInspector.ConsoleMessage} message * @param {!WebInspector.ConsoleMessage} message
*/ */
_consoleMessageAdded: function(target, message) _consoleMessageAdded: function(message)
{ {
if (this._urlToMessageCount[message.url]) if (this._urlToMessageCount[message.url])
this._urlToMessageCount[message.url]++; this._urlToMessageCount[message.url]++;
...@@ -444,7 +444,7 @@ WebInspector.ConsoleView.prototype = { ...@@ -444,7 +444,7 @@ WebInspector.ConsoleView.prototype = {
} }
this._consoleMessages.push(message); this._consoleMessages.push(message);
var viewMessage = this._createViewMessage(target, message); var viewMessage = this._createViewMessage(message);
if (this._filter.shouldBeVisible(viewMessage)) if (this._filter.shouldBeVisible(viewMessage))
this._showConsoleMessage(viewMessage); this._showConsoleMessage(viewMessage);
...@@ -455,10 +455,10 @@ WebInspector.ConsoleView.prototype = { ...@@ -455,10 +455,10 @@ WebInspector.ConsoleView.prototype = {
/** /**
* @param {!WebInspector.Event} event * @param {!WebInspector.Event} event
*/ */
_onConsoleMessageAdded: function(target, event) _onConsoleMessageAdded: function(event)
{ {
var message = /** @type {!WebInspector.ConsoleMessage} */ (event.data); var message = /** @type {!WebInspector.ConsoleMessage} */ (event.data);
this._consoleMessageAdded(target, message); this._consoleMessageAdded(message);
}, },
/** /**
...@@ -499,15 +499,15 @@ WebInspector.ConsoleView.prototype = { ...@@ -499,15 +499,15 @@ WebInspector.ConsoleView.prototype = {
* @param {!WebInspector.ConsoleMessage} message * @param {!WebInspector.ConsoleMessage} message
* @return {!WebInspector.ConsoleViewMessage} * @return {!WebInspector.ConsoleViewMessage}
*/ */
_createViewMessage: function(target, message) _createViewMessage: function(message)
{ {
var viewMessage = this._messageToViewMessage.get(message); var viewMessage = this._messageToViewMessage.get(message);
if (viewMessage) if (viewMessage)
return viewMessage; return viewMessage;
if (message.type === WebInspector.ConsoleMessage.MessageType.Command) if (message.type === WebInspector.ConsoleMessage.MessageType.Command)
viewMessage = new WebInspector.ConsoleCommand(target, message); viewMessage = new WebInspector.ConsoleCommand(message);
else else
viewMessage = new WebInspector.ConsoleViewMessage(target, message, this._linkifier); viewMessage = new WebInspector.ConsoleViewMessage(message, this._linkifier);
this._messageToViewMessage.put(message, viewMessage); this._messageToViewMessage.put(message, viewMessage);
return viewMessage; return viewMessage;
}, },
...@@ -1000,9 +1000,9 @@ WebInspector.ConsoleViewFilter.prototype = { ...@@ -1000,9 +1000,9 @@ WebInspector.ConsoleViewFilter.prototype = {
* @extends {WebInspector.ConsoleViewMessage} * @extends {WebInspector.ConsoleViewMessage}
* @param {!WebInspector.ConsoleMessage} message * @param {!WebInspector.ConsoleMessage} message
*/ */
WebInspector.ConsoleCommand = function(target, message) WebInspector.ConsoleCommand = function(message)
{ {
WebInspector.ConsoleViewMessage.call(this, target, message, null); WebInspector.ConsoleViewMessage.call(this, message, null);
} }
WebInspector.ConsoleCommand.prototype = { WebInspector.ConsoleCommand.prototype = {
...@@ -1075,8 +1075,8 @@ WebInspector.ConsoleCommand.prototype = { ...@@ -1075,8 +1075,8 @@ WebInspector.ConsoleCommand.prototype = {
} }
/** /**
* @extends {WebInspector.ConsoleViewMessage}
* @constructor * @constructor
* @extends {WebInspector.ConsoleViewMessage}
* @param {!WebInspector.RemoteObject} result * @param {!WebInspector.RemoteObject} result
* @param {boolean} wasThrown * @param {boolean} wasThrown
* @param {?WebInspector.ConsoleCommand} originatingCommand * @param {?WebInspector.ConsoleCommand} originatingCommand
...@@ -1089,9 +1089,8 @@ WebInspector.ConsoleCommandResult = function(result, wasThrown, originatingComma ...@@ -1089,9 +1089,8 @@ WebInspector.ConsoleCommandResult = function(result, wasThrown, originatingComma
{ {
this.originatingCommand = originatingCommand; this.originatingCommand = originatingCommand;
var level = wasThrown ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log; var level = wasThrown ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log;
var message = new WebInspector.ConsoleMessage(/** @type {!WebInspector.Target} */ (result.target()), WebInspector.ConsoleMessage.MessageSource.JS, level, "", WebInspector.ConsoleMessage.MessageType.Result, url, lineNumber, columnNumber, undefined, [result]);
var message = new WebInspector.ConsoleMessage(WebInspector.ConsoleMessage.MessageSource.JS, level, "", WebInspector.ConsoleMessage.MessageType.Result, url, lineNumber, columnNumber, undefined, [result]); WebInspector.ConsoleViewMessage.call(this, message, linkifier);
WebInspector.ConsoleViewMessage.call(this, /** @type {!WebInspector.Target} */ (result.target()), message, linkifier);
} }
WebInspector.ConsoleCommandResult.prototype = { WebInspector.ConsoleCommandResult.prototype = {
......
...@@ -31,13 +31,12 @@ ...@@ -31,13 +31,12 @@
/** /**
* @constructor * @constructor
* @extends {WebInspector.TargetAware} * @extends {WebInspector.TargetAware}
* @param {!WebInspector.Target} target
* @param {!WebInspector.ConsoleMessage} consoleMessage * @param {!WebInspector.ConsoleMessage} consoleMessage
* @param {?WebInspector.Linkifier} linkifier * @param {?WebInspector.Linkifier} linkifier
*/ */
WebInspector.ConsoleViewMessage = function(target, consoleMessage, linkifier) WebInspector.ConsoleViewMessage = function(consoleMessage, linkifier)
{ {
WebInspector.TargetAware.call(this, target); WebInspector.TargetAware.call(this, consoleMessage.target());
this._message = consoleMessage; this._message = consoleMessage;
this._linkifier = linkifier; this._linkifier = linkifier;
this._repeatCount = 1; this._repeatCount = 1;
......
...@@ -417,6 +417,7 @@ WebInspector.ExtensionServer.prototype = { ...@@ -417,6 +417,7 @@ WebInspector.ExtensionServer.prototype = {
return this._status.E_BADARG("message.severity", message.severity); return this._status.E_BADARG("message.severity", message.severity);
var consoleMessage = new WebInspector.ConsoleMessage( var consoleMessage = new WebInspector.ConsoleMessage(
WebInspector.console.target(),
WebInspector.ConsoleMessage.MessageSource.JS, WebInspector.ConsoleMessage.MessageSource.JS,
level, level,
message.text, message.text,
......
...@@ -193,7 +193,8 @@ WebInspector.NetworkDispatcher.prototype = { ...@@ -193,7 +193,8 @@ WebInspector.NetworkDispatcher.prototype = {
networkRequest.timing = response.timing; networkRequest.timing = response.timing;
if (!this._mimeTypeIsConsistentWithType(networkRequest)) { if (!this._mimeTypeIsConsistentWithType(networkRequest)) {
this._manager._target.consoleModel.addMessage(new WebInspector.ConsoleMessage(WebInspector.ConsoleMessage.MessageSource.Network, var consoleModel = this._manager._target.consoleModel;
consoleModel.addMessage(new WebInspector.ConsoleMessage(consoleModel.target(), WebInspector.ConsoleMessage.MessageSource.Network,
WebInspector.ConsoleMessage.MessageLevel.Log, WebInspector.ConsoleMessage.MessageLevel.Log,
WebInspector.UIString("Resource interpreted as %s but transferred with MIME type %s: \"%s\".", networkRequest.type.title(), networkRequest.mimeType, networkRequest.url), WebInspector.UIString("Resource interpreted as %s but transferred with MIME type %s: \"%s\".", networkRequest.type.title(), networkRequest.mimeType, networkRequest.url),
WebInspector.ConsoleMessage.MessageType.Log, WebInspector.ConsoleMessage.MessageType.Log,
......
...@@ -223,6 +223,7 @@ WebInspector.ScriptSnippetModel.prototype = { ...@@ -223,6 +223,7 @@ WebInspector.ScriptSnippetModel.prototype = {
if (!scriptId) { if (!scriptId) {
var consoleMessage = new WebInspector.ConsoleMessage( var consoleMessage = new WebInspector.ConsoleMessage(
WebInspector.console.target(),
WebInspector.ConsoleMessage.MessageSource.JS, WebInspector.ConsoleMessage.MessageSource.JS,
WebInspector.ConsoleMessage.MessageLevel.Error, WebInspector.ConsoleMessage.MessageLevel.Error,
syntaxErrorMessage || ""); syntaxErrorMessage || "");
...@@ -269,7 +270,7 @@ WebInspector.ScriptSnippetModel.prototype = { ...@@ -269,7 +270,7 @@ WebInspector.ScriptSnippetModel.prototype = {
_printRunScriptResult: function(result, wasThrown) _printRunScriptResult: function(result, wasThrown)
{ {
var level = (wasThrown ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log); var level = (wasThrown ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log);
var message = new WebInspector.ConsoleMessage( var message = new WebInspector.ConsoleMessage(WebInspector.console.target(),
WebInspector.ConsoleMessage.MessageSource.JS, WebInspector.ConsoleMessage.MessageSource.JS,
level, level,
"", "",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment