| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 * @constructor | 32 * @constructor |
| 33 * @extends {WebInspector.SDKModel} | 33 * @extends {WebInspector.SDKModel} |
| 34 * @param {!WebInspector.Target} target | 34 * @param {!WebInspector.Target} target |
| 35 */ | 35 */ |
| 36 WebInspector.ConsoleModel = function(target) | 36 WebInspector.ConsoleModel = function(target) |
| 37 { | 37 { |
| 38 WebInspector.SDKModel.call(this, WebInspector.ConsoleModel, target); | 38 WebInspector.SDKModel.call(this, WebInspector.ConsoleModel, target); |
| 39 | 39 |
| 40 /** @type {!Array.<!WebInspector.ConsoleMessage>} */ | 40 /** @type {!Array.<!WebInspector.ConsoleMessage>} */ |
| 41 this._messages = []; | 41 this._messages = []; |
| 42 /** @type {!Map<number, !WebInspector.ConsoleMessage>} */ | 42 this.warnings = 0; |
| 43 this._messageById = new Map(); | 43 this.errors = 0; |
| 44 this._warnings = 0; | |
| 45 this._errors = 0; | |
| 46 this._revokedErrors = 0; | |
| 47 this._consoleAgent = target.consoleAgent(); | 44 this._consoleAgent = target.consoleAgent(); |
| 48 target.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this)); | 45 target.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this)); |
| 49 this._enableAgent(); | 46 this._enableAgent(); |
| 50 } | 47 } |
| 51 | 48 |
| 52 WebInspector.ConsoleModel.Events = { | 49 WebInspector.ConsoleModel.Events = { |
| 53 ConsoleCleared: "ConsoleCleared", | 50 ConsoleCleared: "ConsoleCleared", |
| 54 MessageAdded: "MessageAdded", | 51 MessageAdded: "MessageAdded", |
| 55 MessageUpdated: "MessageUpdated", | |
| 56 CommandEvaluated: "CommandEvaluated", | 52 CommandEvaluated: "CommandEvaluated", |
| 57 } | 53 } |
| 58 | 54 |
| 59 WebInspector.ConsoleModel.prototype = { | 55 WebInspector.ConsoleModel.prototype = { |
| 60 _enableAgent: function() | 56 _enableAgent: function() |
| 61 { | 57 { |
| 62 this._enablingConsole = true; | 58 this._enablingConsole = true; |
| 63 | 59 |
| 64 /** | 60 /** |
| 65 * @this {WebInspector.ConsoleModel} | 61 * @this {WebInspector.ConsoleModel} |
| 66 */ | 62 */ |
| 67 function callback() | 63 function callback() |
| 68 { | 64 { |
| 69 delete this._enablingConsole; | 65 delete this._enablingConsole; |
| 70 } | 66 } |
| 71 this._consoleAgent.enable(callback.bind(this)); | 67 this._consoleAgent.enable(callback.bind(this)); |
| 72 }, | 68 }, |
| 73 | 69 |
| 74 /** | 70 /** |
| 75 * @param {!WebInspector.ConsoleMessage} msg | 71 * @param {!WebInspector.ConsoleMessage} msg |
| 76 */ | 72 */ |
| 77 addMessage: function(msg) | 73 addMessage: function(msg) |
| 78 { | 74 { |
| 79 if (msg.level === WebInspector.ConsoleMessage.MessageLevel.RevokedError
&& msg._relatedMessageId) { | 75 msg.index = this._messages.length; |
| 80 var relatedMessage = this._messageById.get(msg._relatedMessageId); | 76 this._messages.push(msg); |
| 81 if (!relatedMessage) | 77 this._incrementErrorWarningCount(msg); |
| 82 return; | |
| 83 this._errors--; | |
| 84 this._revokedErrors++; | |
| 85 relatedMessage.level = WebInspector.ConsoleMessage.MessageLevel.Revo
kedError; | |
| 86 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.Messa
geUpdated, relatedMessage); | |
| 87 return; | |
| 88 } | |
| 89 | 78 |
| 90 this._messages.push(msg); | |
| 91 if (msg._messageId) | |
| 92 this._messageById.set(msg._messageId, msg); | |
| 93 this._incrementErrorWarningCount(msg); | |
| 94 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd
ded, msg); | 79 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd
ded, msg); |
| 95 }, | 80 }, |
| 96 | 81 |
| 97 /** | 82 /** |
| 98 * @param {!WebInspector.ConsoleMessage} msg | 83 * @param {!WebInspector.ConsoleMessage} msg |
| 99 */ | 84 */ |
| 100 _incrementErrorWarningCount: function(msg) | 85 _incrementErrorWarningCount: function(msg) |
| 101 { | 86 { |
| 102 switch (msg.level) { | 87 switch (msg.level) { |
| 103 case WebInspector.ConsoleMessage.MessageLevel.Warning: | 88 case WebInspector.ConsoleMessage.MessageLevel.Warning: |
| 104 this._warnings++; | 89 this.warnings++; |
| 105 break; | 90 break; |
| 106 case WebInspector.ConsoleMessage.MessageLevel.Error: | 91 case WebInspector.ConsoleMessage.MessageLevel.Error: |
| 107 this._errors++; | 92 this.errors++; |
| 108 break; | |
| 109 case WebInspector.ConsoleMessage.MessageLevel.RevokedError: | |
| 110 this._revokedErrors++; | |
| 111 break; | 93 break; |
| 112 } | 94 } |
| 113 }, | 95 }, |
| 114 | 96 |
| 115 /** | 97 /** |
| 116 * @return {!Array.<!WebInspector.ConsoleMessage>} | 98 * @return {!Array.<!WebInspector.ConsoleMessage>} |
| 117 */ | 99 */ |
| 118 messages: function() | 100 messages: function() |
| 119 { | 101 { |
| 120 return this._messages; | 102 return this._messages; |
| 121 }, | 103 }, |
| 122 | 104 |
| 123 requestClearMessages: function() | 105 requestClearMessages: function() |
| 124 { | 106 { |
| 125 this._consoleAgent.clearMessages(); | 107 this._consoleAgent.clearMessages(); |
| 126 this._messagesCleared(); | 108 this._messagesCleared(); |
| 127 }, | 109 }, |
| 128 | 110 |
| 129 _messagesCleared: function() | 111 _messagesCleared: function() |
| 130 { | 112 { |
| 131 this._messages = []; | 113 this._messages = []; |
| 132 this._messageById.clear(); | 114 this.errors = 0; |
| 133 this._errors = 0; | 115 this.warnings = 0; |
| 134 this._revokedErrors = 0; | |
| 135 this._warnings = 0; | |
| 136 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl
eared); | 116 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl
eared); |
| 137 }, | 117 }, |
| 138 | 118 |
| 139 /** | |
| 140 * @return {number} | |
| 141 */ | |
| 142 errors: function() | |
| 143 { | |
| 144 return this._errors; | |
| 145 }, | |
| 146 | |
| 147 /** | |
| 148 * @return {number} | |
| 149 */ | |
| 150 revokedErrors: function() | |
| 151 { | |
| 152 return this._revokedErrors; | |
| 153 }, | |
| 154 | |
| 155 /** | |
| 156 * @return {number} | |
| 157 */ | |
| 158 warnings: function() | |
| 159 { | |
| 160 return this._warnings; | |
| 161 }, | |
| 162 | |
| 163 __proto__: WebInspector.SDKModel.prototype | 119 __proto__: WebInspector.SDKModel.prototype |
| 164 } | 120 } |
| 165 | 121 |
| 166 /** | 122 /** |
| 167 * @param {!WebInspector.ExecutionContext} executionContext | 123 * @param {!WebInspector.ExecutionContext} executionContext |
| 168 * @param {string} text | 124 * @param {string} text |
| 169 * @param {boolean=} useCommandLineAPI | 125 * @param {boolean=} useCommandLineAPI |
| 170 */ | 126 */ |
| 171 WebInspector.ConsoleModel.evaluateCommandInConsole = function(executionContext,
text, useCommandLineAPI) | 127 WebInspector.ConsoleModel.evaluateCommandInConsole = function(executionContext,
text, useCommandLineAPI) |
| 172 { | 128 { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 * @param {?string=} url | 167 * @param {?string=} url |
| 212 * @param {number=} line | 168 * @param {number=} line |
| 213 * @param {number=} column | 169 * @param {number=} column |
| 214 * @param {!NetworkAgent.RequestId=} requestId | 170 * @param {!NetworkAgent.RequestId=} requestId |
| 215 * @param {!Array.<!RuntimeAgent.RemoteObject>=} parameters | 171 * @param {!Array.<!RuntimeAgent.RemoteObject>=} parameters |
| 216 * @param {!Array.<!ConsoleAgent.CallFrame>=} stackTrace | 172 * @param {!Array.<!ConsoleAgent.CallFrame>=} stackTrace |
| 217 * @param {number=} timestamp | 173 * @param {number=} timestamp |
| 218 * @param {!RuntimeAgent.ExecutionContextId=} executionContextId | 174 * @param {!RuntimeAgent.ExecutionContextId=} executionContextId |
| 219 * @param {!ConsoleAgent.AsyncStackTrace=} asyncStackTrace | 175 * @param {!ConsoleAgent.AsyncStackTrace=} asyncStackTrace |
| 220 * @param {?string=} scriptId | 176 * @param {?string=} scriptId |
| 221 * @param {number=} messageId | |
| 222 * @param {number=} relatedMessageId | |
| 223 */ | 177 */ |
| 224 WebInspector.ConsoleMessage = function(target, source, level, messageText, type,
url, line, column, requestId, parameters, stackTrace, timestamp, executionConte
xtId, asyncStackTrace, scriptId, messageId, relatedMessageId) | 178 WebInspector.ConsoleMessage = function(target, source, level, messageText, type,
url, line, column, requestId, parameters, stackTrace, timestamp, executionConte
xtId, asyncStackTrace, scriptId) |
| 225 { | 179 { |
| 226 this._target = target; | 180 this._target = target; |
| 227 this.source = source; | 181 this.source = source; |
| 228 this.level = level; | 182 this.level = level; |
| 229 this.messageText = messageText; | 183 this.messageText = messageText; |
| 230 this.type = type || WebInspector.ConsoleMessage.MessageType.Log; | 184 this.type = type || WebInspector.ConsoleMessage.MessageType.Log; |
| 231 /** @type {string|undefined} */ | 185 /** @type {string|undefined} */ |
| 232 this.url = url || undefined; | 186 this.url = url || undefined; |
| 233 /** @type {number} */ | 187 /** @type {number} */ |
| 234 this.line = line || 0; | 188 this.line = line || 0; |
| 235 /** @type {number} */ | 189 /** @type {number} */ |
| 236 this.column = column || 0; | 190 this.column = column || 0; |
| 237 this.parameters = parameters; | 191 this.parameters = parameters; |
| 238 /** @type {!Array.<!ConsoleAgent.CallFrame>|undefined} */ | 192 /** @type {!Array.<!ConsoleAgent.CallFrame>|undefined} */ |
| 239 this.stackTrace = stackTrace; | 193 this.stackTrace = stackTrace; |
| 240 this.timestamp = timestamp || Date.now(); | 194 this.timestamp = timestamp || Date.now(); |
| 241 this.executionContextId = executionContextId || 0; | 195 this.executionContextId = executionContextId || 0; |
| 242 this.asyncStackTrace = asyncStackTrace; | 196 this.asyncStackTrace = asyncStackTrace; |
| 243 this.scriptId = scriptId || null; | 197 this.scriptId = scriptId || null; |
| 244 this._messageId = messageId || 0; | |
| 245 this._relatedMessageId = relatedMessageId || 0; | |
| 246 | 198 |
| 247 this.request = requestId ? target.networkLog.requestForId(requestId) : null; | 199 this.request = requestId ? target.networkLog.requestForId(requestId) : null; |
| 248 | 200 |
| 249 if (this.request) { | 201 if (this.request) { |
| 250 var initiator = this.request.initiator(); | 202 var initiator = this.request.initiator(); |
| 251 if (initiator) { | 203 if (initiator) { |
| 252 this.stackTrace = initiator.stackTrace || undefined; | 204 this.stackTrace = initiator.stackTrace || undefined; |
| 253 this.asyncStackTrace = initiator.asyncStackTrace; | 205 this.asyncStackTrace = initiator.asyncStackTrace; |
| 254 if (initiator.url) { | 206 if (initiator.url) { |
| 255 this.url = initiator.url; | 207 this.url = initiator.url; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 266 |
| 315 /** | 267 /** |
| 316 * @return {boolean} | 268 * @return {boolean} |
| 317 */ | 269 */ |
| 318 isErrorOrWarning: function() | 270 isErrorOrWarning: function() |
| 319 { | 271 { |
| 320 return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning
|| this.level === WebInspector.ConsoleMessage.MessageLevel.Error); | 272 return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning
|| this.level === WebInspector.ConsoleMessage.MessageLevel.Error); |
| 321 }, | 273 }, |
| 322 | 274 |
| 323 /** | 275 /** |
| 276 * @return {!WebInspector.ConsoleMessage} |
| 277 */ |
| 278 clone: function() |
| 279 { |
| 280 return new WebInspector.ConsoleMessage( |
| 281 this.target(), |
| 282 this.source, |
| 283 this.level, |
| 284 this.messageText, |
| 285 this.type, |
| 286 this.url, |
| 287 this.line, |
| 288 this.column, |
| 289 this.request ? this.request.requestId : undefined, |
| 290 this.parameters, |
| 291 this.stackTrace, |
| 292 this.timestamp, |
| 293 this.executionContextId, |
| 294 this.asyncStackTrace, |
| 295 this.scriptId); |
| 296 }, |
| 297 |
| 298 /** |
| 324 * @param {?WebInspector.ConsoleMessage} msg | 299 * @param {?WebInspector.ConsoleMessage} msg |
| 325 * @return {boolean} | 300 * @return {boolean} |
| 326 */ | 301 */ |
| 327 isEqual: function(msg) | 302 isEqual: function(msg) |
| 328 { | 303 { |
| 329 if (!msg) | 304 if (!msg) |
| 330 return false; | 305 return false; |
| 331 | 306 |
| 332 if (this._messageId || msg._messageId) | |
| 333 return false; | |
| 334 if (this._relatedMessageId || msg._relatedMessageId) | |
| 335 return false; | |
| 336 | |
| 337 if (!this._isEqualStackTraces(this.stackTrace, msg.stackTrace)) | 307 if (!this._isEqualStackTraces(this.stackTrace, msg.stackTrace)) |
| 338 return false; | 308 return false; |
| 339 | 309 |
| 340 var asyncTrace1 = this.asyncStackTrace; | 310 var asyncTrace1 = this.asyncStackTrace; |
| 341 var asyncTrace2 = msg.asyncStackTrace; | 311 var asyncTrace2 = msg.asyncStackTrace; |
| 342 while (asyncTrace1 || asyncTrace2) { | 312 while (asyncTrace1 || asyncTrace2) { |
| 343 if (!asyncTrace1 || !asyncTrace2) | 313 if (!asyncTrace1 || !asyncTrace2) |
| 344 return false; | 314 return false; |
| 345 if (asyncTrace1.description !== asyncTrace2.description) | 315 if (asyncTrace1.description !== asyncTrace2.description) |
| 346 return false; | 316 return false; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 404 } |
| 435 | 405 |
| 436 /** | 406 /** |
| 437 * @enum {string} | 407 * @enum {string} |
| 438 */ | 408 */ |
| 439 WebInspector.ConsoleMessage.MessageLevel = { | 409 WebInspector.ConsoleMessage.MessageLevel = { |
| 440 Log: "log", | 410 Log: "log", |
| 441 Info: "info", | 411 Info: "info", |
| 442 Warning: "warning", | 412 Warning: "warning", |
| 443 Error: "error", | 413 Error: "error", |
| 444 Debug: "debug", | 414 Debug: "debug" |
| 445 RevokedError: "revokedError" | |
| 446 }; | 415 }; |
| 447 | 416 |
| 448 /** | 417 /** |
| 449 * @param {!WebInspector.ConsoleMessage} a | 418 * @param {!WebInspector.ConsoleMessage} a |
| 450 * @param {!WebInspector.ConsoleMessage} b | 419 * @param {!WebInspector.ConsoleMessage} b |
| 451 * @return {number} | 420 * @return {number} |
| 452 */ | 421 */ |
| 453 WebInspector.ConsoleMessage.timestampComparator = function (a, b) | 422 WebInspector.ConsoleMessage.timestampComparator = function (a, b) |
| 454 { | 423 { |
| 455 return a.timestamp - b.timestamp; | 424 return a.timestamp - b.timestamp; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 480 payload.type, | 449 payload.type, |
| 481 payload.url, | 450 payload.url, |
| 482 payload.line, | 451 payload.line, |
| 483 payload.column, | 452 payload.column, |
| 484 payload.networkRequestId, | 453 payload.networkRequestId, |
| 485 payload.parameters, | 454 payload.parameters, |
| 486 payload.stackTrace, | 455 payload.stackTrace, |
| 487 payload.timestamp * 1000, // Convert to ms. | 456 payload.timestamp * 1000, // Convert to ms. |
| 488 payload.executionContextId, | 457 payload.executionContextId, |
| 489 payload.asyncStackTrace, | 458 payload.asyncStackTrace, |
| 490 payload.scriptId, | 459 payload.scriptId); |
| 491 payload.messageId, | |
| 492 payload.relatedMessageId); | |
| 493 this._console.addMessage(consoleMessage); | 460 this._console.addMessage(consoleMessage); |
| 494 }, | 461 }, |
| 495 | 462 |
| 496 /** | 463 /** |
| 497 * @override | 464 * @override |
| 498 * @param {number} count | 465 * @param {number} count |
| 499 */ | 466 */ |
| 500 messageRepeatCountUpdated: function(count) | 467 messageRepeatCountUpdated: function(count) |
| 501 { | 468 { |
| 502 }, | 469 }, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 513 | 480 |
| 514 /** | 481 /** |
| 515 * @constructor | 482 * @constructor |
| 516 * @extends {WebInspector.Object} | 483 * @extends {WebInspector.Object} |
| 517 * @implements {WebInspector.TargetManager.Observer} | 484 * @implements {WebInspector.TargetManager.Observer} |
| 518 */ | 485 */ |
| 519 WebInspector.MultitargetConsoleModel = function() | 486 WebInspector.MultitargetConsoleModel = function() |
| 520 { | 487 { |
| 521 WebInspector.targetManager.observeTargets(this); | 488 WebInspector.targetManager.observeTargets(this); |
| 522 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn
spector.ConsoleModel.Events.MessageAdded, this._consoleMessageAdded, this); | 489 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn
spector.ConsoleModel.Events.MessageAdded, this._consoleMessageAdded, this); |
| 523 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn
spector.ConsoleModel.Events.MessageUpdated, this._consoleMessageUpdated, this); | |
| 524 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn
spector.ConsoleModel.Events.CommandEvaluated, this._commandEvaluated, this); | 490 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn
spector.ConsoleModel.Events.CommandEvaluated, this._commandEvaluated, this); |
| 525 } | 491 } |
| 526 | 492 |
| 527 WebInspector.MultitargetConsoleModel.prototype = { | 493 WebInspector.MultitargetConsoleModel.prototype = { |
| 528 /** | 494 /** |
| 529 * @override | 495 * @override |
| 530 * @param {!WebInspector.Target} target | 496 * @param {!WebInspector.Target} target |
| 531 */ | 497 */ |
| 532 targetAdded: function(target) | 498 targetAdded: function(target) |
| 533 { | 499 { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 * @param {!WebInspector.Event} event | 536 * @param {!WebInspector.Event} event |
| 571 */ | 537 */ |
| 572 _consoleMessageAdded: function(event) | 538 _consoleMessageAdded: function(event) |
| 573 { | 539 { |
| 574 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd
ded, event.data); | 540 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd
ded, event.data); |
| 575 }, | 541 }, |
| 576 | 542 |
| 577 /** | 543 /** |
| 578 * @param {!WebInspector.Event} event | 544 * @param {!WebInspector.Event} event |
| 579 */ | 545 */ |
| 580 _consoleMessageUpdated: function(event) | |
| 581 { | |
| 582 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageUp
dated, event.data); | |
| 583 }, | |
| 584 | |
| 585 /** | |
| 586 * @param {!WebInspector.Event} event | |
| 587 */ | |
| 588 _commandEvaluated: function(event) | 546 _commandEvaluated: function(event) |
| 589 { | 547 { |
| 590 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv
aluated, event.data); | 548 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv
aluated, event.data); |
| 591 }, | 549 }, |
| 592 | 550 |
| 593 __proto__: WebInspector.Object.prototype | 551 __proto__: WebInspector.Object.prototype |
| 594 } | 552 } |
| 595 | 553 |
| 596 /** | 554 /** |
| 597 * @type {!WebInspector.MultitargetConsoleModel} | 555 * @type {!WebInspector.MultitargetConsoleModel} |
| 598 */ | 556 */ |
| 599 WebInspector.multitargetConsoleModel; | 557 WebInspector.multitargetConsoleModel; |
| OLD | NEW |