| 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 |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | |
| 31 /** | 30 /** |
| 32 * @constructor | 31 * @unrestricted |
| 33 * @extends {WebInspector.SDKModel} | |
| 34 * @param {!WebInspector.Target} target | |
| 35 * @param {?Protocol.LogAgent} logAgent | |
| 36 */ | 32 */ |
| 37 WebInspector.ConsoleModel = function(target, logAgent) | 33 WebInspector.ConsoleModel = class extends WebInspector.SDKModel { |
| 38 { | 34 /** |
| 39 WebInspector.SDKModel.call(this, WebInspector.ConsoleModel, target); | 35 * @param {!WebInspector.Target} target |
| 36 * @param {?Protocol.LogAgent} logAgent |
| 37 */ |
| 38 constructor(target, logAgent) { |
| 39 super(WebInspector.ConsoleModel, target); |
| 40 | 40 |
| 41 /** @type {!Array.<!WebInspector.ConsoleMessage>} */ | 41 /** @type {!Array.<!WebInspector.ConsoleMessage>} */ |
| 42 this._messages = []; | 42 this._messages = []; |
| 43 /** @type {!Map<number, !WebInspector.ConsoleMessage>} */ | 43 /** @type {!Map<number, !WebInspector.ConsoleMessage>} */ |
| 44 this._messageByExceptionId = new Map(); | 44 this._messageByExceptionId = new Map(); |
| 45 this._warnings = 0; | 45 this._warnings = 0; |
| 46 this._errors = 0; | 46 this._errors = 0; |
| 47 this._revokedErrors = 0; | 47 this._revokedErrors = 0; |
| 48 this._logAgent = logAgent; | 48 this._logAgent = logAgent; |
| 49 if (this._logAgent) { | 49 if (this._logAgent) { |
| 50 target.registerLogDispatcher(new WebInspector.LogDispatcher(this)); | 50 target.registerLogDispatcher(new WebInspector.LogDispatcher(this)); |
| 51 this._logAgent.enable(); | 51 this._logAgent.enable(); |
| 52 } | 52 } |
| 53 }; | 53 } |
| 54 | 54 |
| 55 /** @enum {symbol} */ | 55 /** |
| 56 WebInspector.ConsoleModel.Events = { | 56 * @param {!WebInspector.ExecutionContext} executionContext |
| 57 ConsoleCleared: Symbol("ConsoleCleared"), | 57 * @param {string} text |
| 58 MessageAdded: Symbol("MessageAdded"), | 58 * @param {boolean=} useCommandLineAPI |
| 59 MessageUpdated: Symbol("MessageUpdated"), | 59 */ |
| 60 CommandEvaluated: Symbol("CommandEvaluated") | 60 static evaluateCommandInConsole(executionContext, text, useCommandLineAPI) { |
| 61 }; | |
| 62 | |
| 63 WebInspector.ConsoleModel.prototype = { | |
| 64 /** | |
| 65 * @param {!WebInspector.ConsoleMessage} msg | |
| 66 */ | |
| 67 addMessage: function(msg) | |
| 68 { | |
| 69 if (this._isBlacklisted(msg)) | |
| 70 return; | |
| 71 | |
| 72 if (msg.source === WebInspector.ConsoleMessage.MessageSource.Worker && m
sg.target().subTargetsManager && msg.target().subTargetsManager.targetForId(msg.
workerId)) | |
| 73 return; | |
| 74 | |
| 75 if (msg.source === WebInspector.ConsoleMessage.MessageSource.ConsoleAPI
&& msg.type === WebInspector.ConsoleMessage.MessageType.Clear) | |
| 76 this.clear(); | |
| 77 | |
| 78 if (msg.level === WebInspector.ConsoleMessage.MessageLevel.RevokedError
&& msg._revokedExceptionId) { | |
| 79 var exceptionMessage = this._messageByExceptionId.get(msg._revokedEx
ceptionId); | |
| 80 if (!exceptionMessage) | |
| 81 return; | |
| 82 this._errors--; | |
| 83 this._revokedErrors++; | |
| 84 exceptionMessage.level = WebInspector.ConsoleMessage.MessageLevel.Re
vokedError; | |
| 85 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.Messa
geUpdated, exceptionMessage); | |
| 86 return; | |
| 87 } | |
| 88 | |
| 89 this._messages.push(msg); | |
| 90 if (msg._exceptionId) | |
| 91 this._messageByExceptionId.set(msg._exceptionId, msg); | |
| 92 this._incrementErrorWarningCount(msg); | |
| 93 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd
ded, msg); | |
| 94 }, | |
| 95 | |
| 96 /** | |
| 97 * @param {!WebInspector.ConsoleMessage} msg | |
| 98 */ | |
| 99 _incrementErrorWarningCount: function(msg) | |
| 100 { | |
| 101 switch (msg.level) { | |
| 102 case WebInspector.ConsoleMessage.MessageLevel.Warning: | |
| 103 this._warnings++; | |
| 104 break; | |
| 105 case WebInspector.ConsoleMessage.MessageLevel.Error: | |
| 106 this._errors++; | |
| 107 break; | |
| 108 case WebInspector.ConsoleMessage.MessageLevel.RevokedError: | |
| 109 this._revokedErrors++; | |
| 110 break; | |
| 111 } | |
| 112 }, | |
| 113 | |
| 114 /** | |
| 115 * @param {!WebInspector.ConsoleMessage} msg | |
| 116 * @return {boolean} | |
| 117 */ | |
| 118 _isBlacklisted: function(msg) | |
| 119 { | |
| 120 if (msg.source !== WebInspector.ConsoleMessage.MessageSource.Network ||
msg.level !== WebInspector.ConsoleMessage.MessageLevel.Error || !msg.url || !msg
.url.startsWith("chrome-extension")) | |
| 121 return false; | |
| 122 | |
| 123 // ignore Chromecast's cast_sender spam | |
| 124 if (msg.url.includes("://boadgeojelhgndaghljhdicfkmllpafd") || msg.url.
includes("://dliochdbjfkdbacpmhlcpmleaejidimm") || msg.url.includes("://pkedcjk
defgpdelpbcmbmeomcjbeemfm") || msg.url.includes("://fjhoaacokmgbjemoflkofnenfaie
kifl") || msg.url.includes("://fmfcbgogabcbclcofgocippekhfcmgfj") || msg.url.inc
ludes("://enhhojjnijigcajfphajepfemndkmdlo") || msg.url.includes("://ekpaaapppgp
molpcldedioblbkmijaca")) | |
| 125 return true; | |
| 126 | |
| 127 return false; | |
| 128 }, | |
| 129 | |
| 130 /** | |
| 131 * @return {!Array.<!WebInspector.ConsoleMessage>} | |
| 132 */ | |
| 133 messages: function() | |
| 134 { | |
| 135 return this._messages; | |
| 136 }, | |
| 137 | |
| 138 requestClearMessages: function() | |
| 139 { | |
| 140 this._logAgent && this._logAgent.clear(); | |
| 141 this.clear(); | |
| 142 }, | |
| 143 | |
| 144 clear: function() | |
| 145 { | |
| 146 this._messages = []; | |
| 147 this._messageByExceptionId.clear(); | |
| 148 this._errors = 0; | |
| 149 this._revokedErrors = 0; | |
| 150 this._warnings = 0; | |
| 151 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl
eared); | |
| 152 }, | |
| 153 | |
| 154 /** | |
| 155 * @return {number} | |
| 156 */ | |
| 157 errors: function() | |
| 158 { | |
| 159 return this._errors; | |
| 160 }, | |
| 161 | |
| 162 /** | |
| 163 * @return {number} | |
| 164 */ | |
| 165 revokedErrors: function() | |
| 166 { | |
| 167 return this._revokedErrors; | |
| 168 }, | |
| 169 | |
| 170 /** | |
| 171 * @return {number} | |
| 172 */ | |
| 173 warnings: function() | |
| 174 { | |
| 175 return this._warnings; | |
| 176 }, | |
| 177 | |
| 178 __proto__: WebInspector.SDKModel.prototype | |
| 179 }; | |
| 180 | |
| 181 /** | |
| 182 * @param {!WebInspector.ExecutionContext} executionContext | |
| 183 * @param {string} text | |
| 184 * @param {boolean=} useCommandLineAPI | |
| 185 */ | |
| 186 WebInspector.ConsoleModel.evaluateCommandInConsole = function(executionContext,
text, useCommandLineAPI) | |
| 187 { | |
| 188 var target = executionContext.target(); | 61 var target = executionContext.target(); |
| 189 var requestedText = text; | 62 var requestedText = text; |
| 190 | 63 |
| 191 var commandMessage = new WebInspector.ConsoleMessage(target, WebInspector.Co
nsoleMessage.MessageSource.JS, null, text, WebInspector.ConsoleMessage.MessageTy
pe.Command); | 64 var commandMessage = new WebInspector.ConsoleMessage( |
| 65 target, WebInspector.ConsoleMessage.MessageSource.JS, null, text, |
| 66 WebInspector.ConsoleMessage.MessageType.Command); |
| 192 commandMessage.setExecutionContextId(executionContext.id); | 67 commandMessage.setExecutionContextId(executionContext.id); |
| 193 target.consoleModel.addMessage(commandMessage); | 68 target.consoleModel.addMessage(commandMessage); |
| 194 | 69 |
| 195 /** | 70 /** |
| 196 * @param {?WebInspector.RemoteObject} result | 71 * @param {?WebInspector.RemoteObject} result |
| 197 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails | 72 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails |
| 198 */ | 73 */ |
| 199 function printResult(result, exceptionDetails) | 74 function printResult(result, exceptionDetails) { |
| 200 { | 75 if (!result) |
| 201 if (!result) | 76 return; |
| 202 return; | |
| 203 | 77 |
| 204 WebInspector.console.showPromise().then(reportUponEvaluation); | 78 WebInspector.console.showPromise().then(reportUponEvaluation); |
| 205 function reportUponEvaluation() | 79 function reportUponEvaluation() { |
| 206 { | 80 target.consoleModel.dispatchEventToListeners( |
| 207 target.consoleModel.dispatchEventToListeners(WebInspector.ConsoleMod
el.Events.CommandEvaluated, {result: result, text: requestedText, commandMessage
: commandMessage, exceptionDetails: exceptionDetails}); | 81 WebInspector.ConsoleModel.Events.CommandEvaluated, |
| 208 } | 82 {result: result, text: requestedText, commandMessage: commandMessage
, exceptionDetails: exceptionDetails}); |
| 83 } |
| 209 } | 84 } |
| 210 | 85 |
| 211 /** | 86 /** |
| 212 * @param {string} code | 87 * @param {string} code |
| 213 * @suppress {uselessCode} | 88 * @suppress {uselessCode} |
| 214 * @return {boolean} | 89 * @return {boolean} |
| 215 */ | 90 */ |
| 216 function looksLikeAnObjectLiteral(code) | 91 function looksLikeAnObjectLiteral(code) { |
| 217 { | 92 // Only parenthesize what appears to be an object literal. |
| 218 // Only parenthesize what appears to be an object literal. | 93 if (!(/^\s*\{/.test(code) && /\}\s*$/.test(code))) |
| 219 if (!(/^\s*\{/.test(code) && /\}\s*$/.test(code))) | 94 return false; |
| 220 return false; | |
| 221 | 95 |
| 222 try { | 96 try { |
| 223 // Check if the code can be interpreted as an expression. | 97 // Check if the code can be interpreted as an expression. |
| 224 Function("return " + code + ";"); | 98 Function('return ' + code + ';'); |
| 225 | 99 |
| 226 // No syntax error! Does it work parenthesized? | 100 // No syntax error! Does it work parenthesized? |
| 227 Function("(" + code + ")"); | 101 Function('(' + code + ')'); |
| 228 | 102 |
| 229 return true; | 103 return true; |
| 230 } catch (e) { | 104 } catch (e) { |
| 231 return false; | 105 return false; |
| 232 } | 106 } |
| 233 } | 107 } |
| 234 | 108 |
| 235 if (looksLikeAnObjectLiteral(text)) | 109 if (looksLikeAnObjectLiteral(text)) |
| 236 text = "(" + text + ")"; | 110 text = '(' + text + ')'; |
| 237 | 111 |
| 238 executionContext.evaluate(text, "console", !!useCommandLineAPI, false, false
, true, true, printResult); | 112 executionContext.evaluate(text, 'console', !!useCommandLineAPI, false, false
, true, true, printResult); |
| 239 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Console
Evaluated); | 113 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Console
Evaluated); |
| 114 } |
| 115 |
| 116 /** |
| 117 * @param {!WebInspector.ConsoleMessage} msg |
| 118 */ |
| 119 addMessage(msg) { |
| 120 if (this._isBlacklisted(msg)) |
| 121 return; |
| 122 |
| 123 if (msg.source === WebInspector.ConsoleMessage.MessageSource.Worker && msg.t
arget().subTargetsManager && |
| 124 msg.target().subTargetsManager.targetForId(msg.workerId)) |
| 125 return; |
| 126 |
| 127 if (msg.source === WebInspector.ConsoleMessage.MessageSource.ConsoleAPI && |
| 128 msg.type === WebInspector.ConsoleMessage.MessageType.Clear) |
| 129 this.clear(); |
| 130 |
| 131 if (msg.level === WebInspector.ConsoleMessage.MessageLevel.RevokedError && m
sg._revokedExceptionId) { |
| 132 var exceptionMessage = this._messageByExceptionId.get(msg._revokedExceptio
nId); |
| 133 if (!exceptionMessage) |
| 134 return; |
| 135 this._errors--; |
| 136 this._revokedErrors++; |
| 137 exceptionMessage.level = WebInspector.ConsoleMessage.MessageLevel.RevokedE
rror; |
| 138 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageUpda
ted, exceptionMessage); |
| 139 return; |
| 140 } |
| 141 |
| 142 this._messages.push(msg); |
| 143 if (msg._exceptionId) |
| 144 this._messageByExceptionId.set(msg._exceptionId, msg); |
| 145 this._incrementErrorWarningCount(msg); |
| 146 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAdded,
msg); |
| 147 } |
| 148 |
| 149 /** |
| 150 * @param {!WebInspector.ConsoleMessage} msg |
| 151 */ |
| 152 _incrementErrorWarningCount(msg) { |
| 153 switch (msg.level) { |
| 154 case WebInspector.ConsoleMessage.MessageLevel.Warning: |
| 155 this._warnings++; |
| 156 break; |
| 157 case WebInspector.ConsoleMessage.MessageLevel.Error: |
| 158 this._errors++; |
| 159 break; |
| 160 case WebInspector.ConsoleMessage.MessageLevel.RevokedError: |
| 161 this._revokedErrors++; |
| 162 break; |
| 163 } |
| 164 } |
| 165 |
| 166 /** |
| 167 * @param {!WebInspector.ConsoleMessage} msg |
| 168 * @return {boolean} |
| 169 */ |
| 170 _isBlacklisted(msg) { |
| 171 if (msg.source !== WebInspector.ConsoleMessage.MessageSource.Network || |
| 172 msg.level !== WebInspector.ConsoleMessage.MessageLevel.Error || !msg.url
|| |
| 173 !msg.url.startsWith('chrome-extension')) |
| 174 return false; |
| 175 |
| 176 // ignore Chromecast's cast_sender spam |
| 177 if (msg.url.includes('://boadgeojelhgndaghljhdicfkmllpafd') || |
| 178 msg.url.includes('://dliochdbjfkdbacpmhlcpmleaejidimm') || |
| 179 msg.url.includes('://pkedcjkdefgpdelpbcmbmeomcjbeemfm') || |
| 180 msg.url.includes('://fjhoaacokmgbjemoflkofnenfaiekifl') || |
| 181 msg.url.includes('://fmfcbgogabcbclcofgocippekhfcmgfj') || |
| 182 msg.url.includes('://enhhojjnijigcajfphajepfemndkmdlo') || |
| 183 msg.url.includes('://ekpaaapppgpmolpcldedioblbkmijaca')) |
| 184 return true; |
| 185 |
| 186 return false; |
| 187 } |
| 188 |
| 189 /** |
| 190 * @return {!Array.<!WebInspector.ConsoleMessage>} |
| 191 */ |
| 192 messages() { |
| 193 return this._messages; |
| 194 } |
| 195 |
| 196 requestClearMessages() { |
| 197 this._logAgent && this._logAgent.clear(); |
| 198 this.clear(); |
| 199 } |
| 200 |
| 201 clear() { |
| 202 this._messages = []; |
| 203 this._messageByExceptionId.clear(); |
| 204 this._errors = 0; |
| 205 this._revokedErrors = 0; |
| 206 this._warnings = 0; |
| 207 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCleare
d); |
| 208 } |
| 209 |
| 210 /** |
| 211 * @return {number} |
| 212 */ |
| 213 errors() { |
| 214 return this._errors; |
| 215 } |
| 216 |
| 217 /** |
| 218 * @return {number} |
| 219 */ |
| 220 revokedErrors() { |
| 221 return this._revokedErrors; |
| 222 } |
| 223 |
| 224 /** |
| 225 * @return {number} |
| 226 */ |
| 227 warnings() { |
| 228 return this._warnings; |
| 229 } |
| 240 }; | 230 }; |
| 241 | 231 |
| 232 /** @enum {symbol} */ |
| 233 WebInspector.ConsoleModel.Events = { |
| 234 ConsoleCleared: Symbol('ConsoleCleared'), |
| 235 MessageAdded: Symbol('MessageAdded'), |
| 236 MessageUpdated: Symbol('MessageUpdated'), |
| 237 CommandEvaluated: Symbol('CommandEvaluated') |
| 238 }; |
| 239 |
| 240 |
| 242 /** | 241 /** |
| 243 * @constructor | 242 * @unrestricted |
| 244 * @param {?WebInspector.Target} target | |
| 245 * @param {string} source | |
| 246 * @param {?string} level | |
| 247 * @param {string} messageText | |
| 248 * @param {string=} type | |
| 249 * @param {?string=} url | |
| 250 * @param {number=} line | |
| 251 * @param {number=} column | |
| 252 * @param {!NetworkAgent.RequestId=} requestId | |
| 253 * @param {!Array.<!RuntimeAgent.RemoteObject>=} parameters | |
| 254 * @param {!RuntimeAgent.StackTrace=} stackTrace | |
| 255 * @param {number=} timestamp | |
| 256 * @param {!RuntimeAgent.ExecutionContextId=} executionContextId | |
| 257 * @param {?string=} scriptId | |
| 258 * @param {?string=} workerId | |
| 259 */ | 243 */ |
| 260 WebInspector.ConsoleMessage = function(target, source, level, messageText, type,
url, line, column, requestId, parameters, stackTrace, timestamp, executionConte
xtId, scriptId, workerId) | 244 WebInspector.ConsoleMessage = class { |
| 261 { | 245 /** |
| 246 * @param {?WebInspector.Target} target |
| 247 * @param {string} source |
| 248 * @param {?string} level |
| 249 * @param {string} messageText |
| 250 * @param {string=} type |
| 251 * @param {?string=} url |
| 252 * @param {number=} line |
| 253 * @param {number=} column |
| 254 * @param {!NetworkAgent.RequestId=} requestId |
| 255 * @param {!Array.<!RuntimeAgent.RemoteObject>=} parameters |
| 256 * @param {!RuntimeAgent.StackTrace=} stackTrace |
| 257 * @param {number=} timestamp |
| 258 * @param {!RuntimeAgent.ExecutionContextId=} executionContextId |
| 259 * @param {?string=} scriptId |
| 260 * @param {?string=} workerId |
| 261 */ |
| 262 constructor( |
| 263 target, |
| 264 source, |
| 265 level, |
| 266 messageText, |
| 267 type, |
| 268 url, |
| 269 line, |
| 270 column, |
| 271 requestId, |
| 272 parameters, |
| 273 stackTrace, |
| 274 timestamp, |
| 275 executionContextId, |
| 276 scriptId, |
| 277 workerId) { |
| 262 this._target = target; | 278 this._target = target; |
| 263 this.source = source; | 279 this.source = source; |
| 264 this.level = level; | 280 this.level = level; |
| 265 this.messageText = messageText; | 281 this.messageText = messageText; |
| 266 this.type = type || WebInspector.ConsoleMessage.MessageType.Log; | 282 this.type = type || WebInspector.ConsoleMessage.MessageType.Log; |
| 267 /** @type {string|undefined} */ | 283 /** @type {string|undefined} */ |
| 268 this.url = url || undefined; | 284 this.url = url || undefined; |
| 269 /** @type {number} */ | 285 /** @type {number} */ |
| 270 this.line = line || 0; | 286 this.line = line || 0; |
| 271 /** @type {number} */ | 287 /** @type {number} */ |
| 272 this.column = column || 0; | 288 this.column = column || 0; |
| 273 this.parameters = parameters; | 289 this.parameters = parameters; |
| 274 /** @type {!RuntimeAgent.StackTrace|undefined} */ | 290 /** @type {!RuntimeAgent.StackTrace|undefined} */ |
| 275 this.stackTrace = stackTrace; | 291 this.stackTrace = stackTrace; |
| 276 this.timestamp = timestamp || Date.now(); | 292 this.timestamp = timestamp || Date.now(); |
| 277 this.executionContextId = executionContextId || 0; | 293 this.executionContextId = executionContextId || 0; |
| 278 this.scriptId = scriptId || null; | 294 this.scriptId = scriptId || null; |
| 279 this.workerId = workerId || null; | 295 this.workerId = workerId || null; |
| 280 | 296 |
| 281 var networkLog = target && WebInspector.NetworkLog.fromTarget(target); | 297 var networkLog = target && WebInspector.NetworkLog.fromTarget(target); |
| 282 this.request = (requestId && networkLog) ? networkLog.requestForId(requestId
) : null; | 298 this.request = (requestId && networkLog) ? networkLog.requestForId(requestId
) : null; |
| 283 | 299 |
| 284 if (this.request) { | 300 if (this.request) { |
| 285 var initiator = this.request.initiator(); | 301 var initiator = this.request.initiator(); |
| 286 if (initiator) { | 302 if (initiator) { |
| 287 this.stackTrace = initiator.stack || undefined; | 303 this.stackTrace = initiator.stack || undefined; |
| 288 if (initiator.url) { | 304 if (initiator.url) { |
| 289 this.url = initiator.url; | 305 this.url = initiator.url; |
| 290 this.line = initiator.lineNumber || 0; | 306 this.line = initiator.lineNumber || 0; |
| 291 } | |
| 292 } | 307 } |
| 308 } |
| 293 } | 309 } |
| 294 }; | 310 } |
| 295 | 311 |
| 296 WebInspector.ConsoleMessage.prototype = { | 312 /** |
| 297 /** | 313 * @param {!WebInspector.ConsoleMessage} a |
| 298 * @return {?WebInspector.Target} | 314 * @param {!WebInspector.ConsoleMessage} b |
| 299 */ | 315 * @return {number} |
| 300 target: function() | 316 */ |
| 301 { | 317 static timestampComparator(a, b) { |
| 302 return this._target; | 318 return a.timestamp - b.timestamp; |
| 303 }, | 319 } |
| 304 | 320 |
| 305 /** | 321 /** |
| 306 * @param {!WebInspector.ConsoleMessage} originatingMessage | 322 * @param {!RuntimeAgent.ExceptionDetails} exceptionDetails |
| 307 */ | 323 * @return {string} |
| 308 setOriginatingMessage: function(originatingMessage) | 324 */ |
| 309 { | 325 static simpleTextFromException(exceptionDetails) { |
| 310 this._originatingConsoleMessage = originatingMessage; | 326 var text = exceptionDetails.text; |
| 311 this.executionContextId = originatingMessage.executionContextId; | 327 if (exceptionDetails.exception && exceptionDetails.exception.description) { |
| 312 }, | 328 var description = exceptionDetails.exception.description; |
| 329 if (description.indexOf('\n') !== -1) |
| 330 description = description.substring(0, description.indexOf('\n')); |
| 331 text += ' ' + description; |
| 332 } |
| 333 return text; |
| 334 } |
| 313 | 335 |
| 314 /** | 336 /** |
| 315 * @param {!RuntimeAgent.ExecutionContextId} executionContextId | 337 * @param {!WebInspector.Target} target |
| 316 */ | 338 * @param {!RuntimeAgent.ExceptionDetails} exceptionDetails |
| 317 setExecutionContextId: function(executionContextId) | 339 * @param {string=} messageType |
| 318 { | 340 * @param {number=} timestamp |
| 319 this.executionContextId = executionContextId; | 341 * @param {string=} forceUrl |
| 320 }, | 342 * @return {!WebInspector.ConsoleMessage} |
| 343 */ |
| 344 static fromException(target, exceptionDetails, messageType, timestamp, forceUr
l) { |
| 345 return new WebInspector.ConsoleMessage( |
| 346 target, WebInspector.ConsoleMessage.MessageSource.JS, WebInspector.Conso
leMessage.MessageLevel.Error, |
| 347 WebInspector.ConsoleMessage.simpleTextFromException(exceptionDetails), m
essageType, |
| 348 forceUrl || exceptionDetails.url, exceptionDetails.lineNumber, exception
Details.columnNumber, undefined, |
| 349 exceptionDetails.exception ? |
| 350 [WebInspector.RemoteObject.fromLocalObject(exceptionDetails.text), e
xceptionDetails.exception] : |
| 351 undefined, |
| 352 exceptionDetails.stackTrace, timestamp, exceptionDetails.executionContex
tId, exceptionDetails.scriptId); |
| 353 } |
| 321 | 354 |
| 322 /** | 355 /** |
| 323 * @param {number} exceptionId | 356 * @return {?WebInspector.Target} |
| 324 */ | 357 */ |
| 325 setExceptionId: function(exceptionId) | 358 target() { |
| 326 { | 359 return this._target; |
| 327 this._exceptionId = exceptionId; | 360 } |
| 328 }, | |
| 329 | 361 |
| 330 /** | 362 /** |
| 331 * @param {number} revokedExceptionId | 363 * @param {!WebInspector.ConsoleMessage} originatingMessage |
| 332 */ | 364 */ |
| 333 setRevokedExceptionId: function(revokedExceptionId) | 365 setOriginatingMessage(originatingMessage) { |
| 334 { | 366 this._originatingConsoleMessage = originatingMessage; |
| 335 this._revokedExceptionId = revokedExceptionId; | 367 this.executionContextId = originatingMessage.executionContextId; |
| 336 }, | 368 } |
| 337 | 369 |
| 338 /** | 370 /** |
| 339 * @return {?WebInspector.ConsoleMessage} | 371 * @param {!RuntimeAgent.ExecutionContextId} executionContextId |
| 340 */ | 372 */ |
| 341 originatingMessage: function() | 373 setExecutionContextId(executionContextId) { |
| 342 { | 374 this.executionContextId = executionContextId; |
| 343 return this._originatingConsoleMessage; | 375 } |
| 344 }, | |
| 345 | 376 |
| 346 /** | 377 /** |
| 347 * @return {boolean} | 378 * @param {number} exceptionId |
| 348 */ | 379 */ |
| 349 isGroupMessage: function() | 380 setExceptionId(exceptionId) { |
| 350 { | 381 this._exceptionId = exceptionId; |
| 351 return this.type === WebInspector.ConsoleMessage.MessageType.StartGroup
|| | 382 } |
| 352 this.type === WebInspector.ConsoleMessage.MessageType.StartGroupColl
apsed || | |
| 353 this.type === WebInspector.ConsoleMessage.MessageType.EndGroup; | |
| 354 }, | |
| 355 | 383 |
| 356 /** | 384 /** |
| 357 * @return {boolean} | 385 * @param {number} revokedExceptionId |
| 358 */ | 386 */ |
| 359 isGroupStartMessage: function() | 387 setRevokedExceptionId(revokedExceptionId) { |
| 360 { | 388 this._revokedExceptionId = revokedExceptionId; |
| 361 return this.type === WebInspector.ConsoleMessage.MessageType.StartGroup
|| | 389 } |
| 362 this.type === WebInspector.ConsoleMessage.MessageType.StartGroupColl
apsed; | |
| 363 }, | |
| 364 | 390 |
| 365 /** | 391 /** |
| 366 * @return {boolean} | 392 * @return {?WebInspector.ConsoleMessage} |
| 367 */ | 393 */ |
| 368 isErrorOrWarning: function() | 394 originatingMessage() { |
| 369 { | 395 return this._originatingConsoleMessage; |
| 370 return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning
|| this.level === WebInspector.ConsoleMessage.MessageLevel.Error); | 396 } |
| 371 }, | |
| 372 | 397 |
| 373 /** | 398 /** |
| 374 * @param {?WebInspector.ConsoleMessage} msg | 399 * @return {boolean} |
| 375 * @return {boolean} | 400 */ |
| 376 */ | 401 isGroupMessage() { |
| 377 isEqual: function(msg) | 402 return this.type === WebInspector.ConsoleMessage.MessageType.StartGroup || |
| 378 { | 403 this.type === WebInspector.ConsoleMessage.MessageType.StartGroupCollapse
d || |
| 379 if (!msg) | 404 this.type === WebInspector.ConsoleMessage.MessageType.EndGroup; |
| 380 return false; | 405 } |
| 381 | 406 |
| 382 if (this._exceptionId || msg._exceptionId) | 407 /** |
| 383 return false; | 408 * @return {boolean} |
| 384 if (this._revokedExceptionId || msg._revokedExceptionId) | 409 */ |
| 385 return false; | 410 isGroupStartMessage() { |
| 411 return this.type === WebInspector.ConsoleMessage.MessageType.StartGroup || |
| 412 this.type === WebInspector.ConsoleMessage.MessageType.StartGroupCollapse
d; |
| 413 } |
| 386 | 414 |
| 387 if (!this._isEqualStackTraces(this.stackTrace, msg.stackTrace)) | 415 /** |
| 388 return false; | 416 * @return {boolean} |
| 417 */ |
| 418 isErrorOrWarning() { |
| 419 return ( |
| 420 this.level === WebInspector.ConsoleMessage.MessageLevel.Warning || |
| 421 this.level === WebInspector.ConsoleMessage.MessageLevel.Error); |
| 422 } |
| 389 | 423 |
| 390 if (this.parameters) { | 424 /** |
| 391 if (!msg.parameters || this.parameters.length !== msg.parameters.len
gth) | 425 * @param {?WebInspector.ConsoleMessage} msg |
| 392 return false; | 426 * @return {boolean} |
| 427 */ |
| 428 isEqual(msg) { |
| 429 if (!msg) |
| 430 return false; |
| 393 | 431 |
| 394 for (var i = 0; i < msg.parameters.length; ++i) { | 432 if (this._exceptionId || msg._exceptionId) |
| 395 // Never treat objects as equal - their properties might change
over time. | 433 return false; |
| 396 if (this.parameters[i].type !== msg.parameters[i].type || msg.pa
rameters[i].type === "object" || this.parameters[i].value !== msg.parameters[i].
value) | 434 if (this._revokedExceptionId || msg._revokedExceptionId) |
| 397 return false; | 435 return false; |
| 398 } | |
| 399 } | |
| 400 | 436 |
| 401 return (this.target() === msg.target()) | 437 if (!this._isEqualStackTraces(this.stackTrace, msg.stackTrace)) |
| 402 && (this.source === msg.source) | 438 return false; |
| 403 && (this.type === msg.type) | |
| 404 && (this.level === msg.level) | |
| 405 && (this.line === msg.line) | |
| 406 && (this.url === msg.url) | |
| 407 && (this.messageText === msg.messageText) | |
| 408 && (this.request === msg.request) | |
| 409 && (this.executionContextId === msg.executionContextId) | |
| 410 && (this.scriptId === msg.scriptId); | |
| 411 }, | |
| 412 | 439 |
| 413 /** | 440 if (this.parameters) { |
| 414 * @param {!RuntimeAgent.StackTrace|undefined} stackTrace1 | 441 if (!msg.parameters || this.parameters.length !== msg.parameters.length) |
| 415 * @param {!RuntimeAgent.StackTrace|undefined} stackTrace2 | 442 return false; |
| 416 * @return {boolean} | 443 |
| 417 */ | 444 for (var i = 0; i < msg.parameters.length; ++i) { |
| 418 _isEqualStackTraces: function(stackTrace1, stackTrace2) | 445 // Never treat objects as equal - their properties might change over tim
e. |
| 419 { | 446 if (this.parameters[i].type !== msg.parameters[i].type || msg.parameters
[i].type === 'object' || |
| 420 if (!stackTrace1 !== !stackTrace2) | 447 this.parameters[i].value !== msg.parameters[i].value) |
| 421 return false; | 448 return false; |
| 422 if (!stackTrace1) | 449 } |
| 423 return true; | |
| 424 var callFrames1 = stackTrace1.callFrames; | |
| 425 var callFrames2 = stackTrace2.callFrames; | |
| 426 if (callFrames1.length !== callFrames2.length) | |
| 427 return false; | |
| 428 for (var i = 0, n = callFrames1.length; i < n; ++i) { | |
| 429 if (callFrames1[i].url !== callFrames2[i].url || | |
| 430 callFrames1[i].functionName !== callFrames2[i].functionName || | |
| 431 callFrames1[i].lineNumber !== callFrames2[i].lineNumber || | |
| 432 callFrames1[i].columnNumber !== callFrames2[i].columnNumber) | |
| 433 return false; | |
| 434 } | |
| 435 return this._isEqualStackTraces(stackTrace1.parent, stackTrace2.parent); | |
| 436 } | 450 } |
| 451 |
| 452 return (this.target() === msg.target()) && (this.source === msg.source) && (
this.type === msg.type) && |
| 453 (this.level === msg.level) && (this.line === msg.line) && (this.url ===
msg.url) && |
| 454 (this.messageText === msg.messageText) && (this.request === msg.request)
&& |
| 455 (this.executionContextId === msg.executionContextId) && (this.scriptId =
== msg.scriptId); |
| 456 } |
| 457 |
| 458 /** |
| 459 * @param {!RuntimeAgent.StackTrace|undefined} stackTrace1 |
| 460 * @param {!RuntimeAgent.StackTrace|undefined} stackTrace2 |
| 461 * @return {boolean} |
| 462 */ |
| 463 _isEqualStackTraces(stackTrace1, stackTrace2) { |
| 464 if (!stackTrace1 !== !stackTrace2) |
| 465 return false; |
| 466 if (!stackTrace1) |
| 467 return true; |
| 468 var callFrames1 = stackTrace1.callFrames; |
| 469 var callFrames2 = stackTrace2.callFrames; |
| 470 if (callFrames1.length !== callFrames2.length) |
| 471 return false; |
| 472 for (var i = 0, n = callFrames1.length; i < n; ++i) { |
| 473 if (callFrames1[i].url !== callFrames2[i].url || callFrames1[i].functionNa
me !== callFrames2[i].functionName || |
| 474 callFrames1[i].lineNumber !== callFrames2[i].lineNumber || |
| 475 callFrames1[i].columnNumber !== callFrames2[i].columnNumber) |
| 476 return false; |
| 477 } |
| 478 return this._isEqualStackTraces(stackTrace1.parent, stackTrace2.parent); |
| 479 } |
| 437 }; | 480 }; |
| 438 | 481 |
| 439 // Note: Keep these constants in sync with the ones in Console.h | 482 // Note: Keep these constants in sync with the ones in Console.h |
| 440 /** | 483 /** |
| 441 * @enum {string} | 484 * @enum {string} |
| 442 */ | 485 */ |
| 443 WebInspector.ConsoleMessage.MessageSource = { | 486 WebInspector.ConsoleMessage.MessageSource = { |
| 444 XML: "xml", | 487 XML: 'xml', |
| 445 JS: "javascript", | 488 JS: 'javascript', |
| 446 Network: "network", | 489 Network: 'network', |
| 447 ConsoleAPI: "console-api", | 490 ConsoleAPI: 'console-api', |
| 448 Storage: "storage", | 491 Storage: 'storage', |
| 449 AppCache: "appcache", | 492 AppCache: 'appcache', |
| 450 Rendering: "rendering", | 493 Rendering: 'rendering', |
| 451 CSS: "css", | 494 CSS: 'css', |
| 452 Security: "security", | 495 Security: 'security', |
| 453 Other: "other", | 496 Other: 'other', |
| 454 Deprecation: "deprecation", | 497 Deprecation: 'deprecation', |
| 455 Worker: "worker" | 498 Worker: 'worker' |
| 456 }; | 499 }; |
| 457 | 500 |
| 458 /** | 501 /** |
| 459 * @enum {string} | 502 * @enum {string} |
| 460 */ | 503 */ |
| 461 WebInspector.ConsoleMessage.MessageType = { | 504 WebInspector.ConsoleMessage.MessageType = { |
| 462 Log: "log", | 505 Log: 'log', |
| 463 Debug: "debug", | 506 Debug: 'debug', |
| 464 Info: "info", | 507 Info: 'info', |
| 465 Error: "error", | 508 Error: 'error', |
| 466 Warning: "warning", | 509 Warning: 'warning', |
| 467 Dir: "dir", | 510 Dir: 'dir', |
| 468 DirXML: "dirxml", | 511 DirXML: 'dirxml', |
| 469 Table: "table", | 512 Table: 'table', |
| 470 Trace: "trace", | 513 Trace: 'trace', |
| 471 Clear: "clear", | 514 Clear: 'clear', |
| 472 StartGroup: "startGroup", | 515 StartGroup: 'startGroup', |
| 473 StartGroupCollapsed: "startGroupCollapsed", | 516 StartGroupCollapsed: 'startGroupCollapsed', |
| 474 EndGroup: "endGroup", | 517 EndGroup: 'endGroup', |
| 475 Assert: "assert", | 518 Assert: 'assert', |
| 476 Result: "result", | 519 Result: 'result', |
| 477 Profile: "profile", | 520 Profile: 'profile', |
| 478 ProfileEnd: "profileEnd", | 521 ProfileEnd: 'profileEnd', |
| 479 Command: "command" | 522 Command: 'command' |
| 480 }; | 523 }; |
| 481 | 524 |
| 482 /** | 525 /** |
| 483 * @enum {string} | 526 * @enum {string} |
| 484 */ | 527 */ |
| 485 WebInspector.ConsoleMessage.MessageLevel = { | 528 WebInspector.ConsoleMessage.MessageLevel = { |
| 486 Log: "log", | 529 Log: 'log', |
| 487 Info: "info", | 530 Info: 'info', |
| 488 Warning: "warning", | 531 Warning: 'warning', |
| 489 Error: "error", | 532 Error: 'error', |
| 490 Debug: "debug", | 533 Debug: 'debug', |
| 491 RevokedError: "revokedError" // This is frontend-only level, used to put ex
ceptions to console. | 534 RevokedError: 'revokedError' // This is frontend-only level, used to put exce
ptions to console. |
| 535 }; |
| 536 |
| 537 |
| 538 /** |
| 539 * @implements {LogAgent.Dispatcher} |
| 540 * @unrestricted |
| 541 */ |
| 542 WebInspector.LogDispatcher = class { |
| 543 /** |
| 544 * @param {!WebInspector.ConsoleModel} console |
| 545 */ |
| 546 constructor(console) { |
| 547 this._console = console; |
| 548 } |
| 549 |
| 550 /** |
| 551 * @override |
| 552 * @param {!LogAgent.LogEntry} payload |
| 553 */ |
| 554 entryAdded(payload) { |
| 555 var consoleMessage = new WebInspector.ConsoleMessage( |
| 556 this._console.target(), payload.source, payload.level, payload.text, und
efined, payload.url, payload.lineNumber, |
| 557 undefined, payload.networkRequestId, undefined, payload.stackTrace, payl
oad.timestamp, undefined, undefined, |
| 558 payload.workerId); |
| 559 this._console.addMessage(consoleMessage); |
| 560 } |
| 492 }; | 561 }; |
| 493 | 562 |
| 494 /** | 563 /** |
| 495 * @param {!WebInspector.ConsoleMessage} a | 564 * @implements {WebInspector.TargetManager.Observer} |
| 496 * @param {!WebInspector.ConsoleMessage} b | 565 * @unrestricted |
| 497 * @return {number} | |
| 498 */ | 566 */ |
| 499 WebInspector.ConsoleMessage.timestampComparator = function(a, b) | 567 WebInspector.MultitargetConsoleModel = class extends WebInspector.Object { |
| 500 { | 568 constructor() { |
| 501 return a.timestamp - b.timestamp; | 569 super(); |
| 570 WebInspector.targetManager.observeTargets(this); |
| 571 WebInspector.targetManager.addModelListener( |
| 572 WebInspector.ConsoleModel, WebInspector.ConsoleModel.Events.MessageAdded
, this._consoleMessageAdded, this); |
| 573 WebInspector.targetManager.addModelListener( |
| 574 WebInspector.ConsoleModel, WebInspector.ConsoleModel.Events.MessageUpdat
ed, this._consoleMessageUpdated, this); |
| 575 WebInspector.targetManager.addModelListener( |
| 576 WebInspector.ConsoleModel, WebInspector.ConsoleModel.Events.CommandEvalu
ated, this._commandEvaluated, this); |
| 577 } |
| 578 |
| 579 /** |
| 580 * @override |
| 581 * @param {!WebInspector.Target} target |
| 582 */ |
| 583 targetAdded(target) { |
| 584 if (!this._mainTarget) { |
| 585 this._mainTarget = target; |
| 586 target.consoleModel.addEventListener(WebInspector.ConsoleModel.Events.Cons
oleCleared, this._consoleCleared, this); |
| 587 } |
| 588 } |
| 589 |
| 590 /** |
| 591 * @override |
| 592 * @param {!WebInspector.Target} target |
| 593 */ |
| 594 targetRemoved(target) { |
| 595 if (this._mainTarget === target) { |
| 596 delete this._mainTarget; |
| 597 target.consoleModel.removeEventListener( |
| 598 WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared,
this); |
| 599 } |
| 600 } |
| 601 |
| 602 /** |
| 603 * @return {!Array.<!WebInspector.ConsoleMessage>} |
| 604 */ |
| 605 messages() { |
| 606 var targets = WebInspector.targetManager.targets(); |
| 607 var result = []; |
| 608 for (var i = 0; i < targets.length; ++i) |
| 609 result = result.concat(targets[i].consoleModel.messages()); |
| 610 return result; |
| 611 } |
| 612 |
| 613 _consoleCleared() { |
| 614 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCleare
d); |
| 615 } |
| 616 |
| 617 /** |
| 618 * @param {!WebInspector.Event} event |
| 619 */ |
| 620 _consoleMessageAdded(event) { |
| 621 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAdded,
event.data); |
| 622 } |
| 623 |
| 624 /** |
| 625 * @param {!WebInspector.Event} event |
| 626 */ |
| 627 _consoleMessageUpdated(event) { |
| 628 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageUpdate
d, event.data); |
| 629 } |
| 630 |
| 631 /** |
| 632 * @param {!WebInspector.Event} event |
| 633 */ |
| 634 _commandEvaluated(event) { |
| 635 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEvalua
ted, event.data); |
| 636 } |
| 502 }; | 637 }; |
| 503 | 638 |
| 504 /** | 639 /** |
| 505 * @param {!RuntimeAgent.ExceptionDetails} exceptionDetails | |
| 506 * @return {string} | |
| 507 */ | |
| 508 WebInspector.ConsoleMessage.simpleTextFromException = function(exceptionDetails) | |
| 509 { | |
| 510 var text = exceptionDetails.text; | |
| 511 if (exceptionDetails.exception && exceptionDetails.exception.description) { | |
| 512 var description = exceptionDetails.exception.description; | |
| 513 if (description.indexOf("\n") !== -1) | |
| 514 description = description.substring(0, description.indexOf("\n")); | |
| 515 text += " " + description; | |
| 516 } | |
| 517 return text; | |
| 518 }; | |
| 519 | |
| 520 /** | |
| 521 * @param {!WebInspector.Target} target | |
| 522 * @param {!RuntimeAgent.ExceptionDetails} exceptionDetails | |
| 523 * @param {string=} messageType | |
| 524 * @param {number=} timestamp | |
| 525 * @param {string=} forceUrl | |
| 526 * @return {!WebInspector.ConsoleMessage} | |
| 527 */ | |
| 528 WebInspector.ConsoleMessage.fromException = function(target, exceptionDetails, m
essageType, timestamp, forceUrl) | |
| 529 { | |
| 530 return new WebInspector.ConsoleMessage( | |
| 531 target, | |
| 532 WebInspector.ConsoleMessage.MessageSource.JS, | |
| 533 WebInspector.ConsoleMessage.MessageLevel.Error, | |
| 534 WebInspector.ConsoleMessage.simpleTextFromException(exceptionDetails), | |
| 535 messageType, | |
| 536 forceUrl || exceptionDetails.url, | |
| 537 exceptionDetails.lineNumber, | |
| 538 exceptionDetails.columnNumber, | |
| 539 undefined, | |
| 540 exceptionDetails.exception ? [WebInspector.RemoteObject.fromLocalObject(
exceptionDetails.text), exceptionDetails.exception] : undefined, | |
| 541 exceptionDetails.stackTrace, | |
| 542 timestamp, | |
| 543 exceptionDetails.executionContextId, | |
| 544 exceptionDetails.scriptId); | |
| 545 }; | |
| 546 | |
| 547 /** | |
| 548 * @constructor | |
| 549 * @implements {LogAgent.Dispatcher} | |
| 550 * @param {!WebInspector.ConsoleModel} console | |
| 551 */ | |
| 552 WebInspector.LogDispatcher = function(console) | |
| 553 { | |
| 554 this._console = console; | |
| 555 }; | |
| 556 | |
| 557 WebInspector.LogDispatcher.prototype = { | |
| 558 /** | |
| 559 * @override | |
| 560 * @param {!LogAgent.LogEntry} payload | |
| 561 */ | |
| 562 entryAdded: function(payload) | |
| 563 { | |
| 564 var consoleMessage = new WebInspector.ConsoleMessage( | |
| 565 this._console.target(), | |
| 566 payload.source, | |
| 567 payload.level, | |
| 568 payload.text, | |
| 569 undefined, | |
| 570 payload.url, | |
| 571 payload.lineNumber, | |
| 572 undefined, | |
| 573 payload.networkRequestId, | |
| 574 undefined, | |
| 575 payload.stackTrace, | |
| 576 payload.timestamp, | |
| 577 undefined, | |
| 578 undefined, | |
| 579 payload.workerId); | |
| 580 this._console.addMessage(consoleMessage); | |
| 581 } | |
| 582 }; | |
| 583 | |
| 584 /** | |
| 585 * @constructor | |
| 586 * @extends {WebInspector.Object} | |
| 587 * @implements {WebInspector.TargetManager.Observer} | |
| 588 */ | |
| 589 WebInspector.MultitargetConsoleModel = function() | |
| 590 { | |
| 591 WebInspector.targetManager.observeTargets(this); | |
| 592 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn
spector.ConsoleModel.Events.MessageAdded, this._consoleMessageAdded, this); | |
| 593 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn
spector.ConsoleModel.Events.MessageUpdated, this._consoleMessageUpdated, this); | |
| 594 WebInspector.targetManager.addModelListener(WebInspector.ConsoleModel, WebIn
spector.ConsoleModel.Events.CommandEvaluated, this._commandEvaluated, this); | |
| 595 }; | |
| 596 | |
| 597 WebInspector.MultitargetConsoleModel.prototype = { | |
| 598 /** | |
| 599 * @override | |
| 600 * @param {!WebInspector.Target} target | |
| 601 */ | |
| 602 targetAdded: function(target) | |
| 603 { | |
| 604 if (!this._mainTarget) { | |
| 605 this._mainTarget = target; | |
| 606 target.consoleModel.addEventListener(WebInspector.ConsoleModel.Event
s.ConsoleCleared, this._consoleCleared, this); | |
| 607 } | |
| 608 }, | |
| 609 | |
| 610 /** | |
| 611 * @override | |
| 612 * @param {!WebInspector.Target} target | |
| 613 */ | |
| 614 targetRemoved: function(target) | |
| 615 { | |
| 616 if (this._mainTarget === target) { | |
| 617 delete this._mainTarget; | |
| 618 target.consoleModel.removeEventListener(WebInspector.ConsoleModel.Ev
ents.ConsoleCleared, this._consoleCleared, this); | |
| 619 } | |
| 620 }, | |
| 621 | |
| 622 /** | |
| 623 * @return {!Array.<!WebInspector.ConsoleMessage>} | |
| 624 */ | |
| 625 messages: function() | |
| 626 { | |
| 627 var targets = WebInspector.targetManager.targets(); | |
| 628 var result = []; | |
| 629 for (var i = 0; i < targets.length; ++i) | |
| 630 result = result.concat(targets[i].consoleModel.messages()); | |
| 631 return result; | |
| 632 }, | |
| 633 | |
| 634 _consoleCleared: function() | |
| 635 { | |
| 636 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCl
eared); | |
| 637 }, | |
| 638 | |
| 639 /** | |
| 640 * @param {!WebInspector.Event} event | |
| 641 */ | |
| 642 _consoleMessageAdded: function(event) | |
| 643 { | |
| 644 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAd
ded, event.data); | |
| 645 }, | |
| 646 | |
| 647 /** | |
| 648 * @param {!WebInspector.Event} event | |
| 649 */ | |
| 650 _consoleMessageUpdated: function(event) | |
| 651 { | |
| 652 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageUp
dated, event.data); | |
| 653 }, | |
| 654 | |
| 655 /** | |
| 656 * @param {!WebInspector.Event} event | |
| 657 */ | |
| 658 _commandEvaluated: function(event) | |
| 659 { | |
| 660 this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.CommandEv
aluated, event.data); | |
| 661 }, | |
| 662 | |
| 663 __proto__: WebInspector.Object.prototype | |
| 664 }; | |
| 665 | |
| 666 /** | |
| 667 * @type {!WebInspector.MultitargetConsoleModel} | 640 * @type {!WebInspector.MultitargetConsoleModel} |
| 668 */ | 641 */ |
| 669 WebInspector.multitargetConsoleModel; | 642 WebInspector.multitargetConsoleModel; |
| OLD | NEW |