| 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 20 matching lines...) Expand all Loading... |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @extends {WebInspector.SDKObject} | 33 * @extends {WebInspector.SDKObject} |
| 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.SDKObject.call(this, target); | 38 WebInspector.SDKObject.call(this, target); |
| 39 | 39 |
| 40 /** @type {!Array.<!WebInspector.ConsoleMessage>} */ | 40 /** @type {!Array.<!WebInspector.ConsoleMessage>} */ |
| 41 this.messages = []; | 41 this._messages = []; |
| 42 this.warnings = 0; | 42 this.warnings = 0; |
| 43 this.errors = 0; | 43 this.errors = 0; |
| 44 this._consoleAgent = target.consoleAgent(); | 44 this._consoleAgent = target.consoleAgent(); |
| 45 target.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this)); | 45 target.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this)); |
| 46 this._enableAgent(); | 46 this._enableAgent(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 WebInspector.ConsoleModel.Events = { | 49 WebInspector.ConsoleModel.Events = { |
| 50 ConsoleCleared: "ConsoleCleared", | 50 ConsoleCleared: "ConsoleCleared", |
| 51 MessageAdded: "MessageAdded", | 51 MessageAdded: "MessageAdded", |
| (...skipping 21 matching lines...) Expand all Loading... |
| 73 /** | 73 /** |
| 74 * @return {boolean} | 74 * @return {boolean} |
| 75 */ | 75 */ |
| 76 enablingConsole: function() | 76 enablingConsole: function() |
| 77 { | 77 { |
| 78 return !!this._enablingConsole; | 78 return !!this._enablingConsole; |
| 79 }, | 79 }, |
| 80 | 80 |
| 81 /** | 81 /** |
| 82 * @param {!WebInspector.ConsoleMessage} msg | 82 * @param {!WebInspector.ConsoleMessage} msg |
| 83 * @param {boolean=} isFromBackend | |
| 84 */ | 83 */ |
| 85 addMessage: function(msg, isFromBackend) | 84 addMessage: function(msg) |
| 86 { | 85 { |
| 87 if (isFromBackend && WebInspector.NetworkManager.hasDevToolsRequestHeade
r(msg.request)) | 86 if (WebInspector.NetworkManager.hasDevToolsRequestHeader(msg.request)) |
| 88 return; | 87 return; |
| 89 | 88 |
| 90 msg.index = this.messages.length; | 89 msg.index = this._messages.length; |
| 91 this.messages.push(msg); | 90 this._messages.push(msg); |
| 92 this._incrementErrorWarningCount(msg); | 91 this._incrementErrorWarningCount(msg); |
| 93 | 92 |
| 94 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd
ded, msg); | 93 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd
ded, msg); |
| 95 }, | 94 }, |
| 96 | 95 |
| 97 show: function() | |
| 98 { | |
| 99 WebInspector.Revealer.reveal(this); | |
| 100 }, | |
| 101 | |
| 102 /** | |
| 103 * @param {string} messageText | |
| 104 * @param {!WebInspector.ConsoleMessage.MessageLevel=} messageLevel | |
| 105 * @param {boolean=} showConsole | |
| 106 */ | |
| 107 log: function(messageText, messageLevel, showConsole) | |
| 108 { | |
| 109 var message = new WebInspector.ConsoleMessage( | |
| 110 this.target(), | |
| 111 WebInspector.ConsoleMessage.MessageSource.Other, | |
| 112 messageLevel || WebInspector.ConsoleMessage.MessageLevel.Debug, | |
| 113 messageText); | |
| 114 | |
| 115 this.addMessage(message); | |
| 116 if (showConsole) | |
| 117 this.show(); | |
| 118 }, | |
| 119 | |
| 120 /** | |
| 121 * @param {string} error | |
| 122 */ | |
| 123 showErrorMessage: function(error) | |
| 124 { | |
| 125 this.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true); | |
| 126 }, | |
| 127 | |
| 128 /** | 96 /** |
| 129 * @param {!WebInspector.ConsoleMessage} msg | 97 * @param {!WebInspector.ConsoleMessage} msg |
| 130 */ | 98 */ |
| 131 _incrementErrorWarningCount: function(msg) | 99 _incrementErrorWarningCount: function(msg) |
| 132 { | 100 { |
| 133 switch (msg.level) { | 101 switch (msg.level) { |
| 134 case WebInspector.ConsoleMessage.MessageLevel.Warning: | 102 case WebInspector.ConsoleMessage.MessageLevel.Warning: |
| 135 this.warnings++; | 103 this.warnings++; |
| 136 break; | 104 break; |
| 137 case WebInspector.ConsoleMessage.MessageLevel.Error: | 105 case WebInspector.ConsoleMessage.MessageLevel.Error: |
| 138 this.errors++; | 106 this.errors++; |
| 139 break; | 107 break; |
| 140 } | 108 } |
| 141 }, | 109 }, |
| 142 | 110 |
| 111 /** |
| 112 * @return {!Array.<!WebInspector.ConsoleMessage>} |
| 113 */ |
| 114 messages: function() |
| 115 { |
| 116 return this._messages; |
| 117 }, |
| 118 |
| 143 requestClearMessages: function() | 119 requestClearMessages: function() |
| 144 { | 120 { |
| 145 this._consoleAgent.clearMessages(); | 121 this._consoleAgent.clearMessages(); |
| 146 this.clearMessages(); | 122 this._messagesCleared(); |
| 147 }, | 123 }, |
| 148 | 124 |
| 149 clearMessages: function() | 125 _messagesCleared: function() |
| 150 { | 126 { |
| 151 this.messages = []; | 127 this._messages = []; |
| 152 this.errors = 0; | 128 this.errors = 0; |
| 153 this.warnings = 0; | 129 this.warnings = 0; |
| 154 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl
eared); | 130 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl
eared); |
| 155 }, | 131 }, |
| 156 | 132 |
| 157 __proto__: WebInspector.SDKObject.prototype | 133 __proto__: WebInspector.SDKObject.prototype |
| 158 } | 134 } |
| 159 | 135 |
| 160 /** | 136 /** |
| 161 * @param {!WebInspector.ExecutionContext} executionContext | 137 * @param {!WebInspector.ExecutionContext} executionContext |
| (...skipping 12 matching lines...) Expand all Loading... |
| 174 * @param {?WebInspector.RemoteObject} result | 150 * @param {?WebInspector.RemoteObject} result |
| 175 * @param {boolean} wasThrown | 151 * @param {boolean} wasThrown |
| 176 * @param {?RuntimeAgent.RemoteObject=} valueResult | 152 * @param {?RuntimeAgent.RemoteObject=} valueResult |
| 177 * @this {WebInspector.ConsoleModel} | 153 * @this {WebInspector.ConsoleModel} |
| 178 */ | 154 */ |
| 179 function printResult(result, wasThrown, valueResult) | 155 function printResult(result, wasThrown, valueResult) |
| 180 { | 156 { |
| 181 if (!result) | 157 if (!result) |
| 182 return; | 158 return; |
| 183 | 159 |
| 184 this.show(); | 160 WebInspector.console.show(); |
| 185 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv
aluated, {result: result, wasThrown: wasThrown, text: text, commandMessage: comm
andMessage}); | 161 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv
aluated, {result: result, wasThrown: wasThrown, text: text, commandMessage: comm
andMessage}); |
| 186 } | 162 } |
| 187 | 163 |
| 188 executionContext.evaluate(text, "console", useCommandLineAPI, false, false,
true, printResult.bind(target.consoleModel)); | 164 executionContext.evaluate(text, "console", useCommandLineAPI, false, false,
true, printResult.bind(target.consoleModel)); |
| 189 | 165 |
| 190 WebInspector.userMetrics.ConsoleEvaluated.record(); | 166 WebInspector.userMetrics.ConsoleEvaluated.record(); |
| 191 } | 167 } |
| 192 | 168 |
| 193 | 169 |
| 194 /** | 170 /** |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 payload.url, | 442 payload.url, |
| 467 payload.line, | 443 payload.line, |
| 468 payload.column, | 444 payload.column, |
| 469 payload.networkRequestId, | 445 payload.networkRequestId, |
| 470 payload.parameters, | 446 payload.parameters, |
| 471 payload.stackTrace, | 447 payload.stackTrace, |
| 472 payload.timestamp * 1000, // Convert to ms. | 448 payload.timestamp * 1000, // Convert to ms. |
| 473 this._console._enablingConsole, | 449 this._console._enablingConsole, |
| 474 payload.executionContextId, | 450 payload.executionContextId, |
| 475 payload.asyncStackTrace); | 451 payload.asyncStackTrace); |
| 476 this._console.addMessage(consoleMessage, true); | 452 this._console.addMessage(consoleMessage); |
| 477 }, | 453 }, |
| 478 | 454 |
| 479 /** | 455 /** |
| 480 * @param {number} count | 456 * @param {number} count |
| 481 */ | 457 */ |
| 482 messageRepeatCountUpdated: function(count) | 458 messageRepeatCountUpdated: function(count) |
| 483 { | 459 { |
| 484 }, | 460 }, |
| 485 | 461 |
| 486 messagesCleared: function() | 462 messagesCleared: function() |
| 487 { | 463 { |
| 488 if (!WebInspector.settings.preserveConsoleLog.get()) | 464 if (!WebInspector.settings.preserveConsoleLog.get()) |
| 489 this._console.clearMessages(); | 465 this._console._messagesCleared(); |
| 490 } | 466 } |
| 491 } | 467 } |
| 492 | 468 |
| 493 /** | 469 /** |
| 494 * @type {!WebInspector.ConsoleModel} | 470 * @constructor |
| 471 * @extends {WebInspector.Object} |
| 472 * @implements {WebInspector.TargetManager.Observer} |
| 495 */ | 473 */ |
| 496 WebInspector.consoleModel; | 474 WebInspector.MultitargetConsoleModel = function() |
| 475 { |
| 476 WebInspector.targetManager.observeTargets(this); |
| 477 } |
| 478 |
| 479 WebInspector.MultitargetConsoleModel.prototype = { |
| 480 /** |
| 481 * @param {!WebInspector.Target} target |
| 482 */ |
| 483 targetAdded: function(target) |
| 484 { |
| 485 if (!this._mainTarget) { |
| 486 this._mainTarget = target; |
| 487 target.consoleModel.addEventListener(WebInspector.ConsoleModel.Event
s.ConsoleCleared, this._consoleCleared, this); |
| 488 } |
| 489 target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.Me
ssageAdded, this._consoleMessageAdded, this); |
| 490 target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.Co
mmandEvaluated, this._commandEvaluated, this); |
| 491 }, |
| 492 |
| 493 /** |
| 494 * @param {!WebInspector.Target} target |
| 495 */ |
| 496 targetRemoved: function(target) |
| 497 { |
| 498 if (this._mainTarget === target) { |
| 499 delete this._mainTarget; |
| 500 target.consoleModel.removeEventListener(WebInspector.ConsoleModel.Ev
ents.ConsoleCleared, this._consoleCleared, this); |
| 501 } |
| 502 target.consoleModel.removeEventListener(WebInspector.ConsoleModel.Events
.MessageAdded, this._consoleMessageAdded, this); |
| 503 target.consoleModel.removeEventListener(WebInspector.ConsoleModel.Events
.CommandEvaluated, this._commandEvaluated, this); |
| 504 }, |
| 505 |
| 506 /** |
| 507 * @return {!Array.<!WebInspector.ConsoleMessage>} |
| 508 */ |
| 509 messages: function() |
| 510 { |
| 511 var targets = WebInspector.targetManager.targets(); |
| 512 var result = []; |
| 513 for (var i = 0; i < targets.length; ++i) |
| 514 result = result.concat(targets[i].consoleModel.messages()); |
| 515 return result; |
| 516 }, |
| 517 |
| 518 _consoleCleared: function() |
| 519 { |
| 520 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl
eared); |
| 521 }, |
| 522 |
| 523 /** |
| 524 * @param {!WebInspector.Event} event |
| 525 */ |
| 526 _consoleMessageAdded: function(event) |
| 527 { |
| 528 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd
ded, event.data); |
| 529 }, |
| 530 |
| 531 /** |
| 532 * @param {!WebInspector.Event} event |
| 533 */ |
| 534 _commandEvaluated: function(event) |
| 535 { |
| 536 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv
aluated, event.data); |
| 537 }, |
| 538 |
| 539 __proto__: WebInspector.Object.prototype |
| 540 } |
| 541 |
| 542 /** |
| 543 * @type {!WebInspector.MultitargetConsoleModel} |
| 544 */ |
| 545 WebInspector.multitargetConsoleModel; |
| OLD | NEW |