Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 | * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 4 | * Copyright (C) 2009 Joseph Pecoraro |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
| 16 | * its contributors may be used to endorse or promote products derived |
| 17 | * from this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | /** |
| 31 | * @implements {Console.ConsoleViewportElement} |
| 32 | * @unrestricted |
| 33 | */ |
| 34 | Console.ConsoleViewMessage = class { |
| 35 | /** |
| 36 | * @param {!SDK.ConsoleMessage} consoleMessage |
| 37 | * @param {!Components.Linkifier} linkifier |
| 38 | * @param {!ProductRegistry.BadgePool} badgePool |
| 39 | * @param {number} nestingLevel |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame^] | 40 | * @param {function(!Common.Event)} onResize |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 41 | */ |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame^] | 42 | constructor(consoleMessage, linkifier, badgePool, nestingLevel, onResize) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 43 | this._message = consoleMessage; |
| 44 | this._linkifier = linkifier; |
| 45 | this._badgePool = badgePool; |
| 46 | this._repeatCount = 1; |
| 47 | this._closeGroupDecorationCount = 0; |
| 48 | this._nestingLevel = nestingLevel; |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 49 | /** @type {!Array<{element: !Element, selectFirst: function()}>} */ |
| 50 | this._selectableChildren = []; |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame^] | 51 | this._messageResized = onResize; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 52 | |
| 53 | /** @type {?DataGrid.DataGrid} */ |
| 54 | this._dataGrid = null; |
| 55 | this._previewFormatter = new ObjectUI.RemoteObjectPreviewFormatter(); |
| 56 | this._searchRegex = null; |
| 57 | /** @type {?UI.Icon} */ |
| 58 | this._messageLevelIcon = null; |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 59 | this._traceExpanded = false; |
| 60 | /** @type {?function(boolean)} */ |
| 61 | this._expandTrace = null; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @override |
| 66 | * @return {!Element} |
| 67 | */ |
| 68 | element() { |
| 69 | return this.toMessageElement(); |
| 70 | } |
| 71 | |
| 72 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 73 | * @override |
| 74 | */ |
| 75 | wasShown() { |
| 76 | if (this._dataGrid) |
| 77 | this._dataGrid.updateWidths(); |
| 78 | this._isVisible = true; |
| 79 | } |
| 80 | |
| 81 | onResize() { |
| 82 | if (!this._isVisible) |
| 83 | return; |
| 84 | if (this._dataGrid) |
| 85 | this._dataGrid.onResize(); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * @override |
| 90 | */ |
| 91 | willHide() { |
| 92 | this._isVisible = false; |
Erik Luo | 4b00232 | 2018-07-30 21:23:31 | [diff] [blame] | 93 | this._cachedHeight = this.element().offsetHeight; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @return {number} |
| 98 | */ |
| 99 | fastHeight() { |
| 100 | if (this._cachedHeight) |
| 101 | return this._cachedHeight; |
| 102 | // This value reflects the 18px min-height of .console-message, plus the |
| 103 | // 1px border of .console-message-wrapper. Keep in sync with consoleView.css. |
| 104 | const defaultConsoleRowHeight = 19; |
| 105 | if (this._message.type === SDK.ConsoleMessage.MessageType.Table) { |
| 106 | const table = this._message.parameters[0]; |
| 107 | if (table && table.preview) |
| 108 | return defaultConsoleRowHeight * table.preview.properties.length; |
| 109 | } |
| 110 | return defaultConsoleRowHeight; |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * @return {!SDK.ConsoleMessage} |
| 115 | */ |
| 116 | consoleMessage() { |
| 117 | return this._message; |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @return {!Element} |
| 122 | */ |
| 123 | _buildTableMessage() { |
| 124 | const formattedMessage = createElementWithClass('span', 'source-code'); |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 125 | this._anchorElement = this._buildMessageAnchor(); |
| 126 | if (this._anchorElement) |
| 127 | formattedMessage.appendChild(this._anchorElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 128 | const badgeElement = this._buildMessageBadge(); |
| 129 | if (badgeElement) |
| 130 | formattedMessage.appendChild(badgeElement); |
| 131 | |
| 132 | let table = this._message.parameters && this._message.parameters.length ? this._message.parameters[0] : null; |
| 133 | if (table) |
| 134 | table = this._parameterToRemoteObject(table); |
| 135 | if (!table || !table.preview) |
Erik Luo | 16e3e38 | 2018-11-09 02:56:01 | [diff] [blame] | 136 | return this._buildMessage(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 137 | |
| 138 | const rawValueColumnSymbol = Symbol('rawValueColumn'); |
| 139 | const columnNames = []; |
| 140 | const preview = table.preview; |
| 141 | const rows = []; |
| 142 | for (let i = 0; i < preview.properties.length; ++i) { |
| 143 | const rowProperty = preview.properties[i]; |
| 144 | let rowSubProperties; |
| 145 | if (rowProperty.valuePreview) |
| 146 | rowSubProperties = rowProperty.valuePreview.properties; |
| 147 | else if (rowProperty.value) |
| 148 | rowSubProperties = [{name: rawValueColumnSymbol, type: rowProperty.type, value: rowProperty.value}]; |
| 149 | else |
| 150 | continue; |
| 151 | |
| 152 | const rowValue = {}; |
| 153 | const maxColumnsToRender = 20; |
| 154 | for (let j = 0; j < rowSubProperties.length; ++j) { |
| 155 | const cellProperty = rowSubProperties[j]; |
| 156 | let columnRendered = columnNames.indexOf(cellProperty.name) !== -1; |
| 157 | if (!columnRendered) { |
| 158 | if (columnNames.length === maxColumnsToRender) |
| 159 | continue; |
| 160 | columnRendered = true; |
| 161 | columnNames.push(cellProperty.name); |
| 162 | } |
| 163 | |
| 164 | if (columnRendered) { |
| 165 | const cellElement = this._renderPropertyPreviewOrAccessor(table, [rowProperty, cellProperty]); |
| 166 | cellElement.classList.add('console-message-nowrap-below'); |
| 167 | rowValue[cellProperty.name] = cellElement; |
| 168 | } |
| 169 | } |
| 170 | rows.push([rowProperty.name, rowValue]); |
| 171 | } |
| 172 | |
| 173 | const flatValues = []; |
| 174 | for (let i = 0; i < rows.length; ++i) { |
| 175 | const rowName = rows[i][0]; |
| 176 | const rowValue = rows[i][1]; |
| 177 | flatValues.push(rowName); |
| 178 | for (let j = 0; j < columnNames.length; ++j) |
| 179 | flatValues.push(rowValue[columnNames[j]]); |
| 180 | } |
| 181 | columnNames.unshift(Common.UIString('(index)')); |
| 182 | const columnDisplayNames = columnNames.map(name => name === rawValueColumnSymbol ? Common.UIString('Value') : name); |
| 183 | |
| 184 | if (flatValues.length) { |
| 185 | this._dataGrid = DataGrid.SortableDataGrid.create(columnDisplayNames, flatValues); |
| 186 | this._dataGrid.setStriped(true); |
| 187 | |
| 188 | const formattedResult = createElementWithClass('span', 'console-message-text'); |
| 189 | const tableElement = formattedResult.createChild('div', 'console-message-formatted-table'); |
| 190 | const dataGridContainer = tableElement.createChild('span'); |
| 191 | tableElement.appendChild(this._formatParameter(table, true, false)); |
| 192 | dataGridContainer.appendChild(this._dataGrid.element); |
| 193 | formattedMessage.appendChild(formattedResult); |
| 194 | this._dataGrid.renderInline(); |
| 195 | } |
| 196 | return formattedMessage; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * @return {!Element} |
| 201 | */ |
| 202 | _buildMessage() { |
| 203 | let messageElement; |
| 204 | let messageText = this._message.messageText; |
| 205 | if (this._message.source === SDK.ConsoleMessage.MessageSource.ConsoleAPI) { |
| 206 | switch (this._message.type) { |
| 207 | case SDK.ConsoleMessage.MessageType.Trace: |
| 208 | messageElement = this._format(this._message.parameters || ['console.trace']); |
| 209 | break; |
| 210 | case SDK.ConsoleMessage.MessageType.Clear: |
| 211 | messageElement = createElementWithClass('span', 'console-info'); |
| 212 | if (Common.moduleSetting('preserveConsoleLog').get()) |
| 213 | messageElement.textContent = Common.UIString('console.clear() was prevented due to \'Preserve log\''); |
| 214 | else |
| 215 | messageElement.textContent = Common.UIString('Console was cleared'); |
| 216 | messageElement.title = |
| 217 | Common.UIString('Clear all messages with ' + UI.shortcutRegistry.shortcutTitleForAction('console.clear')); |
| 218 | break; |
| 219 | case SDK.ConsoleMessage.MessageType.Assert: { |
| 220 | let args = [Common.UIString('Assertion failed:')]; |
| 221 | if (this._message.parameters) |
| 222 | args = args.concat(this._message.parameters); |
| 223 | messageElement = this._format(args); |
| 224 | break; |
| 225 | } |
| 226 | case SDK.ConsoleMessage.MessageType.Dir: { |
| 227 | const obj = this._message.parameters ? this._message.parameters[0] : undefined; |
| 228 | const args = ['%O', obj]; |
| 229 | messageElement = this._format(args); |
| 230 | break; |
| 231 | } |
| 232 | case SDK.ConsoleMessage.MessageType.Profile: |
| 233 | case SDK.ConsoleMessage.MessageType.ProfileEnd: |
| 234 | messageElement = this._format([messageText]); |
| 235 | break; |
| 236 | default: { |
| 237 | if (this._message.parameters && this._message.parameters.length === 1 && |
| 238 | this._message.parameters[0].type === 'string') |
| 239 | messageElement = this._tryFormatAsError(/** @type {string} */ (this._message.parameters[0].value)); |
| 240 | const args = this._message.parameters || [messageText]; |
| 241 | messageElement = messageElement || this._format(args); |
| 242 | } |
| 243 | } |
| 244 | } else { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 245 | if (this._message.source === SDK.ConsoleMessage.MessageSource.Network) { |
| 246 | messageElement = this._formatAsNetworkRequest() || this._format([messageText]); |
| 247 | } else { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 248 | const messageInParameters = |
| 249 | this._message.parameters && messageText === /** @type {string} */ (this._message.parameters[0]); |
| 250 | if (this._message.source === SDK.ConsoleMessage.MessageSource.Violation) |
| 251 | messageText = Common.UIString('[Violation] %s', messageText); |
| 252 | else if (this._message.source === SDK.ConsoleMessage.MessageSource.Intervention) |
| 253 | messageText = Common.UIString('[Intervention] %s', messageText); |
| 254 | else if (this._message.source === SDK.ConsoleMessage.MessageSource.Deprecation) |
| 255 | messageText = Common.UIString('[Deprecation] %s', messageText); |
| 256 | const args = this._message.parameters || [messageText]; |
| 257 | if (messageInParameters) |
| 258 | args[0] = messageText; |
| 259 | messageElement = this._format(args); |
| 260 | } |
| 261 | } |
| 262 | messageElement.classList.add('console-message-text'); |
| 263 | |
| 264 | const formattedMessage = createElementWithClass('span', 'source-code'); |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 265 | this._anchorElement = this._buildMessageAnchor(); |
| 266 | if (this._anchorElement) |
| 267 | formattedMessage.appendChild(this._anchorElement); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 268 | const badgeElement = this._buildMessageBadge(); |
| 269 | if (badgeElement) |
| 270 | formattedMessage.appendChild(badgeElement); |
| 271 | formattedMessage.appendChild(messageElement); |
| 272 | return formattedMessage; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * @return {?Element} |
| 277 | */ |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 278 | _formatAsNetworkRequest() { |
| 279 | const request = SDK.NetworkLog.requestForConsoleMessage(this._message); |
| 280 | if (!request) |
| 281 | return null; |
| 282 | const messageElement = createElement('span'); |
| 283 | if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error) { |
| 284 | messageElement.createTextChild(request.requestMethod + ' '); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 285 | const linkElement = Components.Linkifier.linkifyRevealable(request, request.url(), request.url()); |
| 286 | // Focus is handled by the viewport. |
| 287 | linkElement.tabIndex = -1; |
| 288 | this._selectableChildren.push({element: linkElement, selectFirst: () => linkElement.focus()}); |
| 289 | messageElement.appendChild(linkElement); |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 290 | if (request.failed) |
| 291 | messageElement.createTextChildren(' ', request.localizedFailDescription); |
| 292 | if (request.statusCode !== 0) |
| 293 | messageElement.createTextChildren(' ', String(request.statusCode)); |
| 294 | if (request.statusText) |
| 295 | messageElement.createTextChildren(' (', request.statusText, ')'); |
| 296 | } else { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 297 | const fragment = this._linkifyWithCustomLinkifier(this._message.messageText, title => { |
| 298 | const linkElement = Components.Linkifier.linkifyRevealable( |
| 299 | /** @type {!SDK.NetworkRequest} */ (request), title, request.url()); |
| 300 | linkElement.tabIndex = -1; |
| 301 | this._selectableChildren.push({element: linkElement, selectFirst: () => linkElement.focus()}); |
| 302 | return linkElement; |
| 303 | }); |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 304 | messageElement.appendChild(fragment); |
| 305 | } |
| 306 | return messageElement; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * @return {?Element} |
| 311 | */ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 312 | _buildMessageAnchor() { |
| 313 | let anchorElement = null; |
| 314 | if (this._message.scriptId) { |
| 315 | anchorElement = this._linkifyScriptId( |
| 316 | this._message.scriptId, this._message.url || '', this._message.line, this._message.column); |
| 317 | } else if (this._message.stackTrace && this._message.stackTrace.callFrames.length) { |
| 318 | anchorElement = this._linkifyStackTraceTopFrame(this._message.stackTrace); |
| 319 | } else if (this._message.url && this._message.url !== 'undefined') { |
| 320 | anchorElement = this._linkifyLocation(this._message.url, this._message.line, this._message.column); |
| 321 | } |
| 322 | |
| 323 | // Append a space to prevent the anchor text from being glued to the console message when the user selects and copies the console messages. |
| 324 | if (anchorElement) { |
| 325 | const anchorWrapperElement = createElementWithClass('span', 'console-message-anchor'); |
| 326 | anchorWrapperElement.appendChild(anchorElement); |
| 327 | anchorWrapperElement.createTextChild(' '); |
| 328 | return anchorWrapperElement; |
| 329 | } |
| 330 | return null; |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * @return {?Element} |
| 335 | */ |
| 336 | _buildMessageBadge() { |
| 337 | const badgeElement = this._badgeElement(); |
| 338 | if (!badgeElement) |
| 339 | return null; |
| 340 | badgeElement.classList.add('console-message-badge'); |
| 341 | return badgeElement; |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * @return {?Element} |
| 346 | */ |
| 347 | _badgeElement() { |
| 348 | if (this._message._url) |
| 349 | return this._badgePool.badgeForURL(new Common.ParsedURL(this._message._url)); |
| 350 | if (this._message.stackTrace) { |
| 351 | let stackTrace = this._message.stackTrace; |
| 352 | while (stackTrace) { |
| 353 | for (const callFrame of this._message.stackTrace.callFrames) { |
| 354 | if (callFrame.url) |
| 355 | return this._badgePool.badgeForURL(new Common.ParsedURL(callFrame.url)); |
| 356 | } |
| 357 | stackTrace = stackTrace.parent; |
| 358 | } |
| 359 | } |
| 360 | if (!this._message.executionContextId) |
| 361 | return null; |
| 362 | const runtimeModel = this._message.runtimeModel(); |
| 363 | if (!runtimeModel) |
| 364 | return null; |
| 365 | const executionContext = runtimeModel.executionContext(this._message.executionContextId); |
| 366 | if (!executionContext || !executionContext.frameId) |
| 367 | return null; |
| 368 | const resourceTreeModel = executionContext.target().model(SDK.ResourceTreeModel); |
| 369 | if (!resourceTreeModel) |
| 370 | return null; |
| 371 | const frame = resourceTreeModel.frameForId(executionContext.frameId); |
| 372 | if (!frame || !frame.parentFrame) |
| 373 | return null; |
| 374 | return this._badgePool.badgeForFrame(frame); |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * @return {!Element} |
| 379 | */ |
| 380 | _buildMessageWithStackTrace() { |
| 381 | const toggleElement = createElementWithClass('div', 'console-message-stack-trace-toggle'); |
| 382 | const contentElement = toggleElement.createChild('div', 'console-message-stack-trace-wrapper'); |
| 383 | |
| 384 | const messageElement = this._buildMessage(); |
| 385 | const icon = UI.Icon.create('smallicon-triangle-right', 'console-message-expand-icon'); |
| 386 | const clickableElement = contentElement.createChild('div'); |
| 387 | clickableElement.appendChild(icon); |
Erik Luo | b5bfff4 | 2018-09-20 02:52:39 | [diff] [blame] | 388 | // Intercept focus to avoid highlight on click. |
| 389 | clickableElement.tabIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 390 | |
| 391 | clickableElement.appendChild(messageElement); |
| 392 | const stackTraceElement = contentElement.createChild('div'); |
| 393 | const stackTracePreview = Components.JSPresentationUtils.buildStackTracePreviewContents( |
| 394 | this._message.runtimeModel().target(), this._linkifier, this._message.stackTrace); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 395 | stackTraceElement.appendChild(stackTracePreview.element); |
| 396 | for (const linkElement of stackTracePreview.links) { |
| 397 | linkElement.tabIndex = -1; |
| 398 | this._selectableChildren.push({element: linkElement, selectFirst: () => linkElement.focus()}); |
| 399 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 400 | stackTraceElement.classList.add('hidden'); |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 401 | this._expandTrace = expand => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 402 | icon.setIconType(expand ? 'smallicon-triangle-down' : 'smallicon-triangle-right'); |
| 403 | stackTraceElement.classList.toggle('hidden', !expand); |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 404 | this._traceExpanded = expand; |
| 405 | }; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 406 | |
| 407 | /** |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 408 | * @this {!Console.ConsoleViewMessage} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 409 | * @param {?Event} event |
| 410 | */ |
| 411 | function toggleStackTrace(event) { |
Erik Luo | b5bfff4 | 2018-09-20 02:52:39 | [diff] [blame] | 412 | if (UI.isEditing() || contentElement.hasSelection()) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 413 | return; |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 414 | this._expandTrace(stackTraceElement.classList.contains('hidden')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 415 | event.consume(); |
| 416 | } |
| 417 | |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 418 | clickableElement.addEventListener('click', toggleStackTrace.bind(this), false); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 419 | if (this._message.type === SDK.ConsoleMessage.MessageType.Trace) |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 420 | this._expandTrace(true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 421 | |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 422 | toggleElement._expandStackTraceForTest = this._expandTrace.bind(this, true); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 423 | return toggleElement; |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * @param {string} url |
| 428 | * @param {number} lineNumber |
| 429 | * @param {number} columnNumber |
| 430 | * @return {?Element} |
| 431 | */ |
| 432 | _linkifyLocation(url, lineNumber, columnNumber) { |
| 433 | if (!this._message.runtimeModel()) |
| 434 | return null; |
| 435 | return this._linkifier.linkifyScriptLocation( |
| 436 | this._message.runtimeModel().target(), null, url, lineNumber, columnNumber); |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * @param {!Protocol.Runtime.StackTrace} stackTrace |
| 441 | * @return {?Element} |
| 442 | */ |
| 443 | _linkifyStackTraceTopFrame(stackTrace) { |
| 444 | if (!this._message.runtimeModel()) |
| 445 | return null; |
| 446 | return this._linkifier.linkifyStackTraceTopFrame(this._message.runtimeModel().target(), stackTrace); |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * @param {string} scriptId |
| 451 | * @param {string} url |
| 452 | * @param {number} lineNumber |
| 453 | * @param {number} columnNumber |
| 454 | * @return {?Element} |
| 455 | */ |
| 456 | _linkifyScriptId(scriptId, url, lineNumber, columnNumber) { |
| 457 | if (!this._message.runtimeModel()) |
| 458 | return null; |
| 459 | return this._linkifier.linkifyScriptLocation( |
| 460 | this._message.runtimeModel().target(), scriptId, url, lineNumber, columnNumber); |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * @param {!SDK.RemoteObject|!Protocol.Runtime.RemoteObject|string} parameter |
| 465 | * @return {!SDK.RemoteObject} |
| 466 | */ |
| 467 | _parameterToRemoteObject(parameter) { |
| 468 | if (parameter instanceof SDK.RemoteObject) |
| 469 | return parameter; |
| 470 | const runtimeModel = this._message.runtimeModel(); |
| 471 | if (!runtimeModel) |
| 472 | return SDK.RemoteObject.fromLocalObject(parameter); |
| 473 | if (typeof parameter === 'object') |
| 474 | return runtimeModel.createRemoteObject(parameter); |
| 475 | return runtimeModel.createRemoteObjectFromPrimitiveValue(parameter); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * @param {!Array.<!SDK.RemoteObject|string>} rawParameters |
| 480 | * @return {!Element} |
| 481 | */ |
| 482 | _format(rawParameters) { |
| 483 | // This node is used like a Builder. Values are continually appended onto it. |
| 484 | const formattedResult = createElement('span'); |
| 485 | if (!rawParameters.length) |
| 486 | return formattedResult; |
| 487 | |
| 488 | // Formatting code below assumes that parameters are all wrappers whereas frontend console |
| 489 | // API allows passing arbitrary values as messages (strings, numbers, etc.). Wrap them here. |
| 490 | // FIXME: Only pass runtime wrappers here. |
| 491 | let parameters = []; |
| 492 | for (let i = 0; i < rawParameters.length; ++i) |
| 493 | parameters[i] = this._parameterToRemoteObject(rawParameters[i]); |
| 494 | |
| 495 | // There can be string log and string eval result. We distinguish between them based on message type. |
| 496 | const shouldFormatMessage = |
| 497 | SDK.RemoteObject.type((/** @type {!Array.<!SDK.RemoteObject>} **/ (parameters))[0]) === 'string' && |
| 498 | (this._message.type !== SDK.ConsoleMessage.MessageType.Result || |
| 499 | this._message.level === SDK.ConsoleMessage.MessageLevel.Error); |
| 500 | |
| 501 | // Multiple parameters with the first being a format string. Save unused substitutions. |
| 502 | if (shouldFormatMessage) { |
| 503 | const result = this._formatWithSubstitutionString( |
| 504 | /** @type {string} **/ (parameters[0].description), parameters.slice(1), formattedResult); |
| 505 | parameters = result.unusedSubstitutions; |
| 506 | if (parameters.length) |
| 507 | formattedResult.createTextChild(' '); |
| 508 | } |
| 509 | |
| 510 | // Single parameter, or unused substitutions from above. |
| 511 | for (let i = 0; i < parameters.length; ++i) { |
| 512 | // Inline strings when formatting. |
| 513 | if (shouldFormatMessage && parameters[i].type === 'string') |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 514 | formattedResult.appendChild(this._linkifyStringAsFragment(parameters[i].description)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 515 | else |
| 516 | formattedResult.appendChild(this._formatParameter(parameters[i], false, true)); |
| 517 | if (i < parameters.length - 1) |
| 518 | formattedResult.createTextChild(' '); |
| 519 | } |
| 520 | return formattedResult; |
| 521 | } |
| 522 | |
| 523 | /** |
| 524 | * @param {!SDK.RemoteObject} output |
| 525 | * @param {boolean=} forceObjectFormat |
| 526 | * @param {boolean=} includePreview |
| 527 | * @return {!Element} |
| 528 | */ |
| 529 | _formatParameter(output, forceObjectFormat, includePreview) { |
| 530 | if (output.customPreview()) |
| 531 | return (new ObjectUI.CustomPreviewComponent(output)).element; |
| 532 | |
| 533 | const type = forceObjectFormat ? 'object' : (output.subtype || output.type); |
| 534 | let element; |
| 535 | switch (type) { |
| 536 | case 'error': |
| 537 | element = this._formatParameterAsError(output); |
| 538 | break; |
| 539 | case 'function': |
| 540 | element = this._formatParameterAsFunction(output, includePreview); |
| 541 | break; |
| 542 | case 'array': |
| 543 | case 'arraybuffer': |
| 544 | case 'blob': |
| 545 | case 'dataview': |
| 546 | case 'generator': |
| 547 | case 'iterator': |
| 548 | case 'map': |
| 549 | case 'object': |
| 550 | case 'promise': |
| 551 | case 'proxy': |
| 552 | case 'set': |
| 553 | case 'typedarray': |
| 554 | case 'weakmap': |
| 555 | case 'weakset': |
| 556 | element = this._formatParameterAsObject(output, includePreview); |
| 557 | break; |
| 558 | case 'node': |
| 559 | element = output.isNode() ? this._formatParameterAsNode(output) : this._formatParameterAsObject(output, false); |
| 560 | break; |
| 561 | case 'string': |
| 562 | element = this._formatParameterAsString(output); |
| 563 | break; |
| 564 | case 'boolean': |
| 565 | case 'date': |
| 566 | case 'null': |
| 567 | case 'number': |
| 568 | case 'regexp': |
| 569 | case 'symbol': |
| 570 | case 'undefined': |
| 571 | case 'bigint': |
| 572 | element = this._formatParameterAsValue(output); |
| 573 | break; |
| 574 | default: |
| 575 | element = this._formatParameterAsValue(output); |
| 576 | console.error('Tried to format remote object of unknown type.'); |
| 577 | } |
| 578 | element.classList.add('object-value-' + type); |
| 579 | element.classList.add('source-code'); |
| 580 | return element; |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * @param {!SDK.RemoteObject} obj |
| 585 | * @return {!Element} |
| 586 | */ |
| 587 | _formatParameterAsValue(obj) { |
| 588 | const result = createElement('span'); |
| 589 | const description = obj.description || ''; |
| 590 | if (description.length > Console.ConsoleViewMessage._MaxTokenizableStringLength) |
Erik Luo | 5fb33bd | 2018-06-04 23:23:52 | [diff] [blame] | 591 | result.appendChild(UI.createExpandableText(description, Console.ConsoleViewMessage._LongStringVisibleLength)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 592 | else |
| 593 | result.createTextChild(description); |
| 594 | if (obj.objectId) |
| 595 | result.addEventListener('contextmenu', this._contextMenuEventFired.bind(this, obj), false); |
| 596 | return result; |
| 597 | } |
| 598 | |
| 599 | /** |
| 600 | * @param {!SDK.RemoteObject} obj |
| 601 | * @param {boolean=} includePreview |
| 602 | * @return {!Element} |
| 603 | */ |
| 604 | _formatParameterAsObject(obj, includePreview) { |
| 605 | const titleElement = createElementWithClass('span', 'console-object'); |
| 606 | if (includePreview && obj.preview) { |
| 607 | titleElement.classList.add('console-object-preview'); |
| 608 | this._previewFormatter.appendObjectPreview(titleElement, obj.preview, false /* isEntry */); |
| 609 | } else if (obj.type === 'function') { |
| 610 | const functionElement = titleElement.createChild('span'); |
| 611 | ObjectUI.ObjectPropertiesSection.formatObjectAsFunction(obj, functionElement, false); |
| 612 | titleElement.classList.add('object-value-function'); |
| 613 | } else { |
| 614 | titleElement.createTextChild(obj.description || ''); |
| 615 | } |
| 616 | |
| 617 | if (!obj.hasChildren || obj.customPreview()) |
| 618 | return titleElement; |
| 619 | |
| 620 | const note = titleElement.createChild('span', 'object-state-note info-note'); |
| 621 | if (this._message.type === SDK.ConsoleMessage.MessageType.QueryObjectResult) |
| 622 | note.title = ls`This value will not be collected until console is cleared.`; |
| 623 | else |
| 624 | note.title = ls`Value below was evaluated just now.`; |
| 625 | |
| 626 | const section = new ObjectUI.ObjectPropertiesSection(obj, titleElement, this._linkifier); |
| 627 | section.element.classList.add('console-view-object-properties-section'); |
| 628 | section.enableContextMenu(); |
Erik Luo | cc14b81 | 2018-11-03 01:33:09 | [diff] [blame] | 629 | section.setShowSelectionOnKeyboardFocus(true, true); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 630 | this._selectableChildren.push(section); |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame^] | 631 | section.addEventListener(UI.TreeOutline.Events.ElementAttached, this._messageResized); |
| 632 | section.addEventListener(UI.TreeOutline.Events.ElementExpanded, this._messageResized); |
| 633 | section.addEventListener(UI.TreeOutline.Events.ElementCollapsed, this._messageResized); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 634 | return section.element; |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * @param {!SDK.RemoteObject} func |
| 639 | * @param {boolean=} includePreview |
| 640 | * @return {!Element} |
| 641 | */ |
| 642 | _formatParameterAsFunction(func, includePreview) { |
| 643 | const result = createElement('span'); |
| 644 | SDK.RemoteFunction.objectAsFunction(func).targetFunction().then(formatTargetFunction.bind(this)); |
| 645 | return result; |
| 646 | |
| 647 | /** |
| 648 | * @param {!SDK.RemoteObject} targetFunction |
| 649 | * @this {Console.ConsoleViewMessage} |
| 650 | */ |
| 651 | function formatTargetFunction(targetFunction) { |
| 652 | const functionElement = createElement('span'); |
| 653 | ObjectUI.ObjectPropertiesSection.formatObjectAsFunction(targetFunction, functionElement, true, includePreview); |
| 654 | result.appendChild(functionElement); |
| 655 | if (targetFunction !== func) { |
| 656 | const note = result.createChild('span', 'object-info-state-note'); |
| 657 | note.title = Common.UIString('Function was resolved from bound function.'); |
| 658 | } |
| 659 | result.addEventListener('contextmenu', this._contextMenuEventFired.bind(this, targetFunction), false); |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | /** |
| 664 | * @param {!SDK.RemoteObject} obj |
| 665 | * @param {!Event} event |
| 666 | */ |
| 667 | _contextMenuEventFired(obj, event) { |
| 668 | const contextMenu = new UI.ContextMenu(event); |
| 669 | contextMenu.appendApplicableItems(obj); |
| 670 | contextMenu.show(); |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * @param {?SDK.RemoteObject} object |
| 675 | * @param {!Array.<!Protocol.Runtime.PropertyPreview>} propertyPath |
| 676 | * @return {!Element} |
| 677 | */ |
| 678 | _renderPropertyPreviewOrAccessor(object, propertyPath) { |
| 679 | const property = propertyPath.peekLast(); |
| 680 | if (property.type === 'accessor') |
| 681 | return this._formatAsAccessorProperty(object, propertyPath.map(property => property.name), false); |
| 682 | return this._previewFormatter.renderPropertyPreview( |
| 683 | property.type, /** @type {string} */ (property.subtype), property.value); |
| 684 | } |
| 685 | |
| 686 | /** |
| 687 | * @param {!SDK.RemoteObject} remoteObject |
| 688 | * @return {!Element} |
| 689 | */ |
| 690 | _formatParameterAsNode(remoteObject) { |
| 691 | const result = createElement('span'); |
| 692 | |
| 693 | const domModel = remoteObject.runtimeModel().target().model(SDK.DOMModel); |
| 694 | if (!domModel) |
| 695 | return result; |
Erik Luo | 54fdd91 | 2018-11-01 17:57:01 | [diff] [blame] | 696 | domModel.pushObjectAsNodeToFrontend(remoteObject).then(async node => { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 697 | if (!node) { |
| 698 | result.appendChild(this._formatParameterAsObject(remoteObject, false)); |
| 699 | return; |
| 700 | } |
Erik Luo | 54fdd91 | 2018-11-01 17:57:01 | [diff] [blame] | 701 | const renderResult = await UI.Renderer.render(/** @type {!Object} */ (node)); |
Erik Luo | fc6a630 | 2018-11-02 06:48:52 | [diff] [blame] | 702 | if (renderResult) { |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame^] | 703 | if (renderResult.tree) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 704 | this._selectableChildren.push(renderResult.tree); |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame^] | 705 | renderResult.tree.addEventListener(UI.TreeOutline.Events.ElementAttached, this._messageResized); |
| 706 | renderResult.tree.addEventListener(UI.TreeOutline.Events.ElementExpanded, this._messageResized); |
| 707 | renderResult.tree.addEventListener(UI.TreeOutline.Events.ElementCollapsed, this._messageResized); |
| 708 | } |
Erik Luo | fc6a630 | 2018-11-02 06:48:52 | [diff] [blame] | 709 | result.appendChild(renderResult.node); |
| 710 | } else { |
| 711 | result.appendChild(this._formatParameterAsObject(remoteObject, false)); |
| 712 | } |
Erik Luo | 54fdd91 | 2018-11-01 17:57:01 | [diff] [blame] | 713 | this._formattedParameterAsNodeForTest(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 714 | }); |
| 715 | |
| 716 | return result; |
| 717 | } |
| 718 | |
| 719 | _formattedParameterAsNodeForTest() { |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * @param {!SDK.RemoteObject} output |
| 724 | * @return {!Element} |
| 725 | */ |
| 726 | _formatParameterAsString(output) { |
| 727 | const span = createElement('span'); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 728 | span.appendChild(this._linkifyStringAsFragment(output.description || '')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 729 | |
| 730 | const result = createElement('span'); |
| 731 | result.createChild('span', 'object-value-string-quote').textContent = '"'; |
| 732 | result.appendChild(span); |
| 733 | result.createChild('span', 'object-value-string-quote').textContent = '"'; |
| 734 | return result; |
| 735 | } |
| 736 | |
| 737 | /** |
| 738 | * @param {!SDK.RemoteObject} output |
| 739 | * @return {!Element} |
| 740 | */ |
| 741 | _formatParameterAsError(output) { |
| 742 | const result = createElement('span'); |
| 743 | const errorSpan = this._tryFormatAsError(output.description || ''); |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 744 | result.appendChild(errorSpan ? errorSpan : this._linkifyStringAsFragment(output.description || '')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 745 | return result; |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * @param {!SDK.RemoteObject} output |
| 750 | * @return {!Element} |
| 751 | */ |
| 752 | _formatAsArrayEntry(output) { |
| 753 | return this._previewFormatter.renderPropertyPreview(output.type, output.subtype, output.description); |
| 754 | } |
| 755 | |
| 756 | /** |
| 757 | * @param {?SDK.RemoteObject} object |
| 758 | * @param {!Array.<string>} propertyPath |
| 759 | * @param {boolean} isArrayEntry |
| 760 | * @return {!Element} |
| 761 | */ |
| 762 | _formatAsAccessorProperty(object, propertyPath, isArrayEntry) { |
| 763 | const rootElement = ObjectUI.ObjectPropertyTreeElement.createRemoteObjectAccessorPropertySpan( |
| 764 | object, propertyPath, onInvokeGetterClick.bind(this)); |
| 765 | |
| 766 | /** |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 767 | * @param {!SDK.CallFunctionResult} result |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 768 | * @this {Console.ConsoleViewMessage} |
| 769 | */ |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 770 | function onInvokeGetterClick(result) { |
| 771 | const wasThrown = result.wasThrown; |
| 772 | const object = result.object; |
| 773 | if (!object) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 774 | return; |
| 775 | rootElement.removeChildren(); |
| 776 | if (wasThrown) { |
| 777 | const element = rootElement.createChild('span'); |
| 778 | element.textContent = Common.UIString('<exception>'); |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 779 | element.title = /** @type {string} */ (object.description); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 780 | } else if (isArrayEntry) { |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 781 | rootElement.appendChild(this._formatAsArrayEntry(object)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 782 | } else { |
| 783 | // Make a PropertyPreview from the RemoteObject similar to the backend logic. |
| 784 | const maxLength = 100; |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 785 | const type = object.type; |
| 786 | const subtype = object.subtype; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 787 | let description = ''; |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 788 | if (type !== 'function' && object.description) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 789 | if (type === 'string' || subtype === 'regexp') |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 790 | description = object.description.trimMiddle(maxLength); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 791 | else |
Alexey Kozyatinskiy | 330bffb | 2018-09-21 19:20:18 | [diff] [blame] | 792 | description = object.description.trimEnd(maxLength); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 793 | } |
| 794 | rootElement.appendChild(this._previewFormatter.renderPropertyPreview(type, subtype, description)); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | return rootElement; |
| 799 | } |
| 800 | |
| 801 | /** |
| 802 | * @param {string} format |
| 803 | * @param {!Array.<!SDK.RemoteObject>} parameters |
| 804 | * @param {!Element} formattedResult |
| 805 | */ |
| 806 | _formatWithSubstitutionString(format, parameters, formattedResult) { |
| 807 | const formatters = {}; |
| 808 | |
| 809 | /** |
| 810 | * @param {boolean} force |
| 811 | * @param {boolean} includePreview |
| 812 | * @param {!SDK.RemoteObject} obj |
| 813 | * @return {!Element} |
| 814 | * @this {Console.ConsoleViewMessage} |
| 815 | */ |
| 816 | function parameterFormatter(force, includePreview, obj) { |
| 817 | return this._formatParameter(obj, force, includePreview); |
| 818 | } |
| 819 | |
| 820 | function stringFormatter(obj) { |
| 821 | return obj.description; |
| 822 | } |
| 823 | |
| 824 | function floatFormatter(obj) { |
| 825 | if (typeof obj.value !== 'number') |
| 826 | return 'NaN'; |
| 827 | return obj.value; |
| 828 | } |
| 829 | |
| 830 | function integerFormatter(obj) { |
Alexey Kozyatinskiy | beb38de | 2018-08-10 18:54:19 | [diff] [blame] | 831 | if (obj.type === 'bigint') |
| 832 | return obj.description; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 833 | if (typeof obj.value !== 'number') |
| 834 | return 'NaN'; |
| 835 | return Math.floor(obj.value); |
| 836 | } |
| 837 | |
| 838 | function bypassFormatter(obj) { |
| 839 | return (obj instanceof Node) ? obj : ''; |
| 840 | } |
| 841 | |
| 842 | let currentStyle = null; |
| 843 | function styleFormatter(obj) { |
| 844 | currentStyle = {}; |
| 845 | const buffer = createElement('span'); |
| 846 | buffer.setAttribute('style', obj.description); |
| 847 | for (let i = 0; i < buffer.style.length; i++) { |
| 848 | const property = buffer.style[i]; |
| 849 | if (isWhitelistedProperty(property)) |
| 850 | currentStyle[property] = buffer.style[property]; |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | function isWhitelistedProperty(property) { |
| 855 | // Make sure that allowed properties do not interfere with link visibility. |
| 856 | const prefixes = [ |
| 857 | 'background', 'border', 'color', 'font', 'line', 'margin', 'padding', 'text', '-webkit-background', |
| 858 | '-webkit-border', '-webkit-font', '-webkit-margin', '-webkit-padding', '-webkit-text' |
| 859 | ]; |
| 860 | for (let i = 0; i < prefixes.length; i++) { |
| 861 | if (property.startsWith(prefixes[i])) |
| 862 | return true; |
| 863 | } |
| 864 | return false; |
| 865 | } |
| 866 | |
| 867 | // Firebug uses %o for formatting objects. |
| 868 | formatters.o = parameterFormatter.bind(this, false /* force */, true /* includePreview */); |
| 869 | formatters.s = stringFormatter; |
| 870 | formatters.f = floatFormatter; |
| 871 | // Firebug allows both %i and %d for formatting integers. |
| 872 | formatters.i = integerFormatter; |
| 873 | formatters.d = integerFormatter; |
| 874 | |
| 875 | // Firebug uses %c for styling the message. |
| 876 | formatters.c = styleFormatter; |
| 877 | |
| 878 | // Support %O to force object formatting, instead of the type-based %o formatting. |
| 879 | formatters.O = parameterFormatter.bind(this, true /* force */, false /* includePreview */); |
| 880 | |
| 881 | formatters._ = bypassFormatter; |
| 882 | |
| 883 | /** |
| 884 | * @param {!Element} a |
| 885 | * @param {*} b |
| 886 | * @this {!Console.ConsoleViewMessage} |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 887 | * @return {!Element} |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 888 | */ |
| 889 | function append(a, b) { |
| 890 | if (b instanceof Node) { |
| 891 | a.appendChild(b); |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 892 | return a; |
| 893 | } |
| 894 | if (typeof b === 'undefined') |
| 895 | return a; |
| 896 | if (!currentStyle) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 897 | a.appendChild(this._linkifyStringAsFragment(String(b))); |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 898 | return a; |
| 899 | } |
| 900 | const lines = String(b).split('\n'); |
| 901 | for (let i = 0; i < lines.length; i++) { |
| 902 | const line = lines[i]; |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 903 | const lineFragment = this._linkifyStringAsFragment(line); |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 904 | const wrapper = createElement('span'); |
| 905 | wrapper.style.setProperty('contain', 'paint'); |
| 906 | wrapper.style.setProperty('display', 'inline-block'); |
| 907 | wrapper.style.setProperty('max-width', '100%'); |
| 908 | wrapper.appendChild(lineFragment); |
| 909 | applyCurrentStyle(wrapper); |
| 910 | for (const child of wrapper.children) { |
| 911 | if (child.classList.contains('devtools-link')) |
| 912 | this._applyForcedVisibleStyle(child); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 913 | } |
Erik Luo | 1792639 | 2018-05-17 22:06:12 | [diff] [blame] | 914 | a.appendChild(wrapper); |
| 915 | if (i < lines.length - 1) |
| 916 | a.appendChild(createElement('br')); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 917 | } |
| 918 | return a; |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * @param {!Element} element |
| 923 | */ |
| 924 | function applyCurrentStyle(element) { |
| 925 | for (const key in currentStyle) |
| 926 | element.style[key] = currentStyle[key]; |
| 927 | } |
| 928 | |
| 929 | // String.format does treat formattedResult like a Builder, result is an object. |
| 930 | return String.format(format, parameters, formatters, formattedResult, append.bind(this)); |
| 931 | } |
| 932 | |
| 933 | /** |
| 934 | * @param {!Element} element |
| 935 | */ |
| 936 | _applyForcedVisibleStyle(element) { |
| 937 | element.style.setProperty('-webkit-text-stroke', '0', 'important'); |
| 938 | element.style.setProperty('text-decoration', 'underline', 'important'); |
| 939 | |
| 940 | const themedColor = UI.themeSupport.patchColorText('rgb(33%, 33%, 33%)', UI.ThemeSupport.ColorUsage.Foreground); |
| 941 | element.style.setProperty('color', themedColor, 'important'); |
| 942 | |
| 943 | let backgroundColor = 'hsl(0, 0%, 100%)'; |
| 944 | if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error) |
| 945 | backgroundColor = 'hsl(0, 100%, 97%)'; |
| 946 | else if (this._message.level === SDK.ConsoleMessage.MessageLevel.Warning || this._shouldRenderAsWarning()) |
| 947 | backgroundColor = 'hsl(50, 100%, 95%)'; |
| 948 | const themedBackgroundColor = |
| 949 | UI.themeSupport.patchColorText(backgroundColor, UI.ThemeSupport.ColorUsage.Background); |
| 950 | element.style.setProperty('background-color', themedBackgroundColor, 'important'); |
| 951 | } |
| 952 | |
| 953 | /** |
| 954 | * @return {boolean} |
| 955 | */ |
| 956 | matchesFilterRegex(regexObject) { |
| 957 | regexObject.lastIndex = 0; |
Erik Luo | 5976c8c | 2018-07-24 02:03:09 | [diff] [blame] | 958 | const contentElement = this.contentElement(); |
| 959 | const anchorText = this._anchorElement ? this._anchorElement.deepTextContent() : ''; |
| 960 | return (anchorText && regexObject.test(anchorText.trim())) || |
| 961 | regexObject.test(contentElement.deepTextContent().slice(anchorText.length)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | /** |
| 965 | * @param {string} filter |
| 966 | * @return {boolean} |
| 967 | */ |
| 968 | matchesFilterText(filter) { |
| 969 | const text = this.contentElement().deepTextContent(); |
| 970 | return text.toLowerCase().includes(filter.toLowerCase()); |
| 971 | } |
| 972 | |
| 973 | updateTimestamp() { |
| 974 | if (!this._contentElement) |
| 975 | return; |
| 976 | |
| 977 | if (Common.moduleSetting('consoleTimestampsEnabled').get()) { |
| 978 | if (!this._timestampElement) |
| 979 | this._timestampElement = createElementWithClass('span', 'console-timestamp'); |
| 980 | this._timestampElement.textContent = formatTimestamp(this._message.timestamp, false) + ' '; |
| 981 | this._timestampElement.title = formatTimestamp(this._message.timestamp, true); |
| 982 | this._contentElement.insertBefore(this._timestampElement, this._contentElement.firstChild); |
| 983 | } else if (this._timestampElement) { |
| 984 | this._timestampElement.remove(); |
| 985 | delete this._timestampElement; |
| 986 | } |
| 987 | |
| 988 | /** |
| 989 | * @param {number} timestamp |
| 990 | * @param {boolean} full |
| 991 | * @return {string} |
| 992 | */ |
| 993 | function formatTimestamp(timestamp, full) { |
| 994 | const date = new Date(timestamp); |
| 995 | const yymmdd = date.getFullYear() + '-' + leadZero(date.getMonth() + 1, 2) + '-' + leadZero(date.getDate(), 2); |
| 996 | const hhmmssfff = leadZero(date.getHours(), 2) + ':' + leadZero(date.getMinutes(), 2) + ':' + |
| 997 | leadZero(date.getSeconds(), 2) + '.' + leadZero(date.getMilliseconds(), 3); |
| 998 | return full ? (yymmdd + ' ' + hhmmssfff) : hhmmssfff; |
| 999 | |
| 1000 | /** |
| 1001 | * @param {number} value |
| 1002 | * @param {number} length |
| 1003 | * @return {string} |
| 1004 | */ |
| 1005 | function leadZero(value, length) { |
| 1006 | const valueString = value.toString(); |
| 1007 | const padding = length - valueString.length; |
| 1008 | return padding <= 0 ? valueString : '0'.repeat(padding) + valueString; |
| 1009 | } |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | /** |
| 1014 | * @return {number} |
| 1015 | */ |
| 1016 | nestingLevel() { |
| 1017 | return this._nestingLevel; |
| 1018 | } |
| 1019 | |
| 1020 | /** |
| 1021 | * @param {boolean} inSimilarGroup |
| 1022 | * @param {boolean=} isLast |
| 1023 | */ |
| 1024 | setInSimilarGroup(inSimilarGroup, isLast) { |
| 1025 | this._inSimilarGroup = inSimilarGroup; |
| 1026 | this._lastInSimilarGroup = inSimilarGroup && !!isLast; |
| 1027 | if (this._similarGroupMarker && !inSimilarGroup) { |
| 1028 | this._similarGroupMarker.remove(); |
| 1029 | this._similarGroupMarker = null; |
| 1030 | } else if (this._element && !this._similarGroupMarker && inSimilarGroup) { |
| 1031 | this._similarGroupMarker = createElementWithClass('div', 'nesting-level-marker'); |
| 1032 | this._element.insertBefore(this._similarGroupMarker, this._element.firstChild); |
| 1033 | this._similarGroupMarker.classList.toggle('group-closed', this._lastInSimilarGroup); |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | /** |
| 1038 | * @return {boolean} |
| 1039 | */ |
| 1040 | isLastInSimilarGroup() { |
| 1041 | return this._inSimilarGroup && this._lastInSimilarGroup; |
| 1042 | } |
| 1043 | |
| 1044 | resetCloseGroupDecorationCount() { |
| 1045 | if (!this._closeGroupDecorationCount) |
| 1046 | return; |
| 1047 | this._closeGroupDecorationCount = 0; |
| 1048 | this._updateCloseGroupDecorations(); |
| 1049 | } |
| 1050 | |
| 1051 | incrementCloseGroupDecorationCount() { |
| 1052 | ++this._closeGroupDecorationCount; |
| 1053 | this._updateCloseGroupDecorations(); |
| 1054 | } |
| 1055 | |
| 1056 | _updateCloseGroupDecorations() { |
| 1057 | if (!this._nestingLevelMarkers) |
| 1058 | return; |
| 1059 | for (let i = 0, n = this._nestingLevelMarkers.length; i < n; ++i) { |
| 1060 | const marker = this._nestingLevelMarkers[i]; |
| 1061 | marker.classList.toggle('group-closed', n - i <= this._closeGroupDecorationCount); |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | /** |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1066 | * @return {number} |
| 1067 | */ |
| 1068 | _focusedChildIndex() { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1069 | if (!this._selectableChildren.length) |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1070 | return -1; |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1071 | return this._selectableChildren.findIndex(child => child.element.hasFocus()); |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | /** |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1075 | * @param {!Event} event |
| 1076 | */ |
| 1077 | _onKeyDown(event) { |
| 1078 | if (UI.isEditing() || !this._element.hasFocus() || this._element.hasSelection()) |
| 1079 | return; |
| 1080 | if (this.maybeHandleOnKeyDown(event)) |
| 1081 | event.consume(true); |
| 1082 | } |
| 1083 | |
| 1084 | /** |
| 1085 | * @protected |
| 1086 | * @param {!Event} event |
| 1087 | */ |
| 1088 | maybeHandleOnKeyDown(event) { |
| 1089 | // Handle trace expansion. |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1090 | const focusedChildIndex = this._focusedChildIndex(); |
| 1091 | const isWrapperFocused = focusedChildIndex === -1; |
| 1092 | if (this._expandTrace && isWrapperFocused) { |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1093 | if ((event.key === 'ArrowLeft' && this._traceExpanded) || (event.key === 'ArrowRight' && !this._traceExpanded)) { |
| 1094 | this._expandTrace(!this._traceExpanded); |
| 1095 | return true; |
| 1096 | } |
| 1097 | } |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1098 | if (!this._selectableChildren.length) |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1099 | return false; |
| 1100 | |
| 1101 | if (event.key === 'ArrowLeft') { |
| 1102 | this._element.focus(); |
| 1103 | return true; |
| 1104 | } |
| 1105 | if (event.key === 'ArrowRight') { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1106 | if (isWrapperFocused && this._selectNearestVisibleChild(0)) |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1107 | return true; |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1108 | } |
| 1109 | if (event.key === 'ArrowUp') { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1110 | const firstVisibleChild = this._nearestVisibleChild(0); |
| 1111 | if (this._selectableChildren[focusedChildIndex] === firstVisibleChild && firstVisibleChild) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1112 | this._element.focus(); |
| 1113 | return true; |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1114 | } else if (this._selectNearestVisibleChild(focusedChildIndex - 1, true /* backwards */)) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1115 | return true; |
| 1116 | } |
| 1117 | } |
| 1118 | if (event.key === 'ArrowDown') { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1119 | if (isWrapperFocused && this._selectNearestVisibleChild(0)) |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1120 | return true; |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1121 | if (!isWrapperFocused && this._selectNearestVisibleChild(focusedChildIndex + 1)) |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1122 | return true; |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1123 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1124 | return false; |
| 1125 | } |
| 1126 | |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1127 | /** |
| 1128 | * @param {number} fromIndex |
| 1129 | * @param {boolean=} backwards |
| 1130 | * @return {boolean} |
| 1131 | */ |
| 1132 | _selectNearestVisibleChild(fromIndex, backwards) { |
| 1133 | const nearestChild = this._nearestVisibleChild(fromIndex, backwards); |
| 1134 | if (nearestChild) { |
| 1135 | nearestChild.selectFirst(); |
| 1136 | return true; |
| 1137 | } |
| 1138 | return false; |
| 1139 | } |
| 1140 | |
| 1141 | /** |
| 1142 | * @param {number} fromIndex |
| 1143 | * @param {boolean=} backwards |
| 1144 | * @return {?{element: !Element, selectFirst: function()}} |
| 1145 | */ |
| 1146 | _nearestVisibleChild(fromIndex, backwards) { |
| 1147 | const childCount = this._selectableChildren.length; |
| 1148 | if (fromIndex < 0 || fromIndex >= childCount) |
| 1149 | return null; |
| 1150 | const direction = backwards ? -1 : 1; |
| 1151 | let index = fromIndex; |
| 1152 | |
| 1153 | while (!this._selectableChildren[index].element.offsetParent) { |
| 1154 | index += direction; |
| 1155 | if (index < 0 || index >= childCount) |
| 1156 | return null; |
| 1157 | } |
| 1158 | return this._selectableChildren[index]; |
| 1159 | } |
| 1160 | |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1161 | focusLastChildOrSelf() { |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1162 | if (this._element && !this._selectNearestVisibleChild(this._selectableChildren.length - 1, true /* backwards */)) |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1163 | this._element.focus(); |
| 1164 | } |
| 1165 | |
| 1166 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1167 | * @return {!Element} |
| 1168 | */ |
| 1169 | contentElement() { |
| 1170 | if (this._contentElement) |
| 1171 | return this._contentElement; |
| 1172 | |
| 1173 | const contentElement = createElementWithClass('div', 'console-message'); |
| 1174 | if (this._messageLevelIcon) |
| 1175 | contentElement.appendChild(this._messageLevelIcon); |
| 1176 | this._contentElement = contentElement; |
| 1177 | |
| 1178 | let formattedMessage; |
| 1179 | const shouldIncludeTrace = !!this._message.stackTrace && |
| 1180 | (this._message.source === SDK.ConsoleMessage.MessageSource.Network || |
| 1181 | this._message.source === SDK.ConsoleMessage.MessageSource.Violation || |
| 1182 | this._message.level === SDK.ConsoleMessage.MessageLevel.Error || |
| 1183 | this._message.level === SDK.ConsoleMessage.MessageLevel.Warning || |
| 1184 | this._message.type === SDK.ConsoleMessage.MessageType.Trace); |
| 1185 | if (this._message.runtimeModel() && shouldIncludeTrace) |
| 1186 | formattedMessage = this._buildMessageWithStackTrace(); |
| 1187 | else if (this._message.type === SDK.ConsoleMessage.MessageType.Table) |
| 1188 | formattedMessage = this._buildTableMessage(); |
| 1189 | else |
| 1190 | formattedMessage = this._buildMessage(); |
| 1191 | contentElement.appendChild(formattedMessage); |
| 1192 | |
| 1193 | this.updateTimestamp(); |
| 1194 | return this._contentElement; |
| 1195 | } |
| 1196 | |
| 1197 | /** |
| 1198 | * @return {!Element} |
| 1199 | */ |
| 1200 | toMessageElement() { |
| 1201 | if (this._element) |
| 1202 | return this._element; |
| 1203 | |
| 1204 | this._element = createElement('div'); |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1205 | if (Runtime.experiments.isEnabled('consoleKeyboardNavigation')) { |
Erik Luo | b5bfff4 | 2018-09-20 02:52:39 | [diff] [blame] | 1206 | this._element.tabIndex = -1; |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1207 | this._element.addEventListener('keydown', this._onKeyDown.bind(this)); |
| 1208 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1209 | this.updateMessageElement(); |
| 1210 | return this._element; |
| 1211 | } |
| 1212 | |
| 1213 | updateMessageElement() { |
| 1214 | if (!this._element) |
| 1215 | return; |
| 1216 | |
| 1217 | this._element.className = 'console-message-wrapper'; |
| 1218 | this._element.removeChildren(); |
| 1219 | if (this._message.isGroupStartMessage()) |
| 1220 | this._element.classList.add('console-group-title'); |
| 1221 | if (this._message.source === SDK.ConsoleMessage.MessageSource.ConsoleAPI) |
| 1222 | this._element.classList.add('console-from-api'); |
| 1223 | if (this._inSimilarGroup) { |
| 1224 | this._similarGroupMarker = this._element.createChild('div', 'nesting-level-marker'); |
| 1225 | this._similarGroupMarker.classList.toggle('group-closed', this._lastInSimilarGroup); |
| 1226 | } |
| 1227 | |
| 1228 | this._nestingLevelMarkers = []; |
| 1229 | for (let i = 0; i < this._nestingLevel; ++i) |
| 1230 | this._nestingLevelMarkers.push(this._element.createChild('div', 'nesting-level-marker')); |
| 1231 | this._updateCloseGroupDecorations(); |
| 1232 | this._element.message = this; |
| 1233 | |
| 1234 | switch (this._message.level) { |
| 1235 | case SDK.ConsoleMessage.MessageLevel.Verbose: |
| 1236 | this._element.classList.add('console-verbose-level'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1237 | break; |
| 1238 | case SDK.ConsoleMessage.MessageLevel.Info: |
| 1239 | this._element.classList.add('console-info-level'); |
| 1240 | if (this._message.type === SDK.ConsoleMessage.MessageType.System) |
| 1241 | this._element.classList.add('console-system-type'); |
| 1242 | break; |
| 1243 | case SDK.ConsoleMessage.MessageLevel.Warning: |
| 1244 | this._element.classList.add('console-warning-level'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1245 | break; |
| 1246 | case SDK.ConsoleMessage.MessageLevel.Error: |
| 1247 | this._element.classList.add('console-error-level'); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1248 | break; |
| 1249 | } |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1250 | this._updateMessageLevelIcon(); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1251 | if (this._shouldRenderAsWarning()) |
| 1252 | this._element.classList.add('console-warning-level'); |
| 1253 | |
| 1254 | this._element.appendChild(this.contentElement()); |
| 1255 | if (this._repeatCount > 1) |
| 1256 | this._showRepeatCountElement(); |
| 1257 | } |
| 1258 | |
| 1259 | /** |
| 1260 | * @return {boolean} |
| 1261 | */ |
| 1262 | _shouldRenderAsWarning() { |
| 1263 | return (this._message.level === SDK.ConsoleMessage.MessageLevel.Verbose || |
| 1264 | this._message.level === SDK.ConsoleMessage.MessageLevel.Info) && |
| 1265 | (this._message.source === SDK.ConsoleMessage.MessageSource.Violation || |
| 1266 | this._message.source === SDK.ConsoleMessage.MessageSource.Deprecation || |
| 1267 | this._message.source === SDK.ConsoleMessage.MessageSource.Intervention || |
| 1268 | this._message.source === SDK.ConsoleMessage.MessageSource.Recommendation); |
| 1269 | } |
| 1270 | |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1271 | _updateMessageLevelIcon() { |
| 1272 | let iconType = ''; |
| 1273 | let accessibleName = ''; |
| 1274 | if (this._message.level === SDK.ConsoleMessage.MessageLevel.Warning) { |
| 1275 | iconType = 'smallicon-warning'; |
| 1276 | accessibleName = ls`Warning`; |
| 1277 | } else if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error) { |
| 1278 | iconType = 'smallicon-error'; |
| 1279 | accessibleName = ls`Error`; |
| 1280 | } |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1281 | if (!iconType && !this._messageLevelIcon) |
| 1282 | return; |
| 1283 | if (iconType && !this._messageLevelIcon) { |
| 1284 | this._messageLevelIcon = UI.Icon.create('', 'message-level-icon'); |
| 1285 | if (this._contentElement) |
| 1286 | this._contentElement.insertBefore(this._messageLevelIcon, this._contentElement.firstChild); |
| 1287 | } |
| 1288 | this._messageLevelIcon.setIconType(iconType); |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1289 | UI.ARIAUtils.setAccessibleName(this._messageLevelIcon, accessibleName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * @return {number} |
| 1294 | */ |
| 1295 | repeatCount() { |
| 1296 | return this._repeatCount || 1; |
| 1297 | } |
| 1298 | |
| 1299 | resetIncrementRepeatCount() { |
| 1300 | this._repeatCount = 1; |
| 1301 | if (!this._repeatCountElement) |
| 1302 | return; |
| 1303 | |
| 1304 | this._repeatCountElement.remove(); |
| 1305 | if (this._contentElement) |
| 1306 | this._contentElement.classList.remove('repeated-message'); |
| 1307 | delete this._repeatCountElement; |
| 1308 | } |
| 1309 | |
| 1310 | incrementRepeatCount() { |
| 1311 | this._repeatCount++; |
| 1312 | this._showRepeatCountElement(); |
| 1313 | } |
| 1314 | |
| 1315 | /** |
| 1316 | * @param {number} repeatCount |
| 1317 | */ |
| 1318 | setRepeatCount(repeatCount) { |
| 1319 | this._repeatCount = repeatCount; |
| 1320 | this._showRepeatCountElement(); |
| 1321 | } |
| 1322 | |
| 1323 | _showRepeatCountElement() { |
| 1324 | if (!this._element) |
| 1325 | return; |
| 1326 | |
| 1327 | if (!this._repeatCountElement) { |
| 1328 | this._repeatCountElement = createElementWithClass('label', 'console-message-repeat-count', 'dt-small-bubble'); |
| 1329 | switch (this._message.level) { |
| 1330 | case SDK.ConsoleMessage.MessageLevel.Warning: |
| 1331 | this._repeatCountElement.type = 'warning'; |
| 1332 | break; |
| 1333 | case SDK.ConsoleMessage.MessageLevel.Error: |
| 1334 | this._repeatCountElement.type = 'error'; |
| 1335 | break; |
| 1336 | case SDK.ConsoleMessage.MessageLevel.Verbose: |
| 1337 | this._repeatCountElement.type = 'verbose'; |
| 1338 | break; |
| 1339 | default: |
| 1340 | this._repeatCountElement.type = 'info'; |
| 1341 | } |
| 1342 | if (this._shouldRenderAsWarning()) |
| 1343 | this._repeatCountElement.type = 'warning'; |
| 1344 | |
| 1345 | this._element.insertBefore(this._repeatCountElement, this._contentElement); |
| 1346 | this._contentElement.classList.add('repeated-message'); |
| 1347 | } |
| 1348 | this._repeatCountElement.textContent = this._repeatCount; |
Erik Luo | fd3e7d4 | 2018-09-25 02:12:35 | [diff] [blame] | 1349 | let accessibleName = ls`Repeat ${this._repeatCount}`; |
| 1350 | if (this._message.level === SDK.ConsoleMessage.MessageLevel.Warning) |
| 1351 | accessibleName = ls`Warning ${accessibleName}`; |
| 1352 | else if (this._message.level === SDK.ConsoleMessage.MessageLevel.Error) |
| 1353 | accessibleName = ls`Error ${accessibleName}`; |
| 1354 | UI.ARIAUtils.setAccessibleName(this._repeatCountElement, accessibleName); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | get text() { |
| 1358 | return this._message.messageText; |
| 1359 | } |
| 1360 | |
| 1361 | /** |
| 1362 | * @return {string} |
| 1363 | */ |
| 1364 | toExportString() { |
| 1365 | const lines = []; |
| 1366 | const nodes = this.contentElement().childTextNodes(); |
| 1367 | const messageContent = nodes.map(Components.Linkifier.untruncatedNodeText).join(''); |
| 1368 | for (let i = 0; i < this.repeatCount(); ++i) |
| 1369 | lines.push(messageContent); |
| 1370 | return lines.join('\n'); |
| 1371 | } |
| 1372 | |
| 1373 | /** |
| 1374 | * @param {?RegExp} regex |
| 1375 | */ |
| 1376 | setSearchRegex(regex) { |
| 1377 | if (this._searchHiglightNodeChanges && this._searchHiglightNodeChanges.length) |
| 1378 | UI.revertDomChanges(this._searchHiglightNodeChanges); |
| 1379 | this._searchRegex = regex; |
| 1380 | this._searchHighlightNodes = []; |
| 1381 | this._searchHiglightNodeChanges = []; |
| 1382 | if (!this._searchRegex) |
| 1383 | return; |
| 1384 | |
| 1385 | const text = this.contentElement().deepTextContent(); |
| 1386 | let match; |
| 1387 | this._searchRegex.lastIndex = 0; |
| 1388 | const sourceRanges = []; |
| 1389 | while ((match = this._searchRegex.exec(text)) && match[0]) |
| 1390 | sourceRanges.push(new TextUtils.SourceRange(match.index, match[0].length)); |
| 1391 | |
| 1392 | if (sourceRanges.length) { |
| 1393 | this._searchHighlightNodes = |
| 1394 | UI.highlightSearchResults(this.contentElement(), sourceRanges, this._searchHiglightNodeChanges); |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | /** |
| 1399 | * @return {?RegExp} |
| 1400 | */ |
| 1401 | searchRegex() { |
| 1402 | return this._searchRegex; |
| 1403 | } |
| 1404 | |
| 1405 | /** |
| 1406 | * @return {number} |
| 1407 | */ |
| 1408 | searchCount() { |
| 1409 | return this._searchHighlightNodes.length; |
| 1410 | } |
| 1411 | |
| 1412 | /** |
| 1413 | * @return {!Element} |
| 1414 | */ |
| 1415 | searchHighlightNode(index) { |
| 1416 | return this._searchHighlightNodes[index]; |
| 1417 | } |
| 1418 | |
| 1419 | /** |
| 1420 | * @param {string} string |
| 1421 | * @return {?Element} |
| 1422 | */ |
| 1423 | _tryFormatAsError(string) { |
| 1424 | /** |
| 1425 | * @param {string} prefix |
| 1426 | */ |
| 1427 | function startsWith(prefix) { |
| 1428 | return string.startsWith(prefix); |
| 1429 | } |
| 1430 | |
| 1431 | const errorPrefixes = |
| 1432 | ['EvalError', 'ReferenceError', 'SyntaxError', 'TypeError', 'RangeError', 'Error', 'URIError']; |
| 1433 | if (!this._message.runtimeModel() || !errorPrefixes.some(startsWith)) |
| 1434 | return null; |
| 1435 | const debuggerModel = this._message.runtimeModel().debuggerModel(); |
| 1436 | const baseURL = this._message.runtimeModel().target().inspectedURL(); |
| 1437 | |
| 1438 | const lines = string.split('\n'); |
| 1439 | const links = []; |
| 1440 | let position = 0; |
| 1441 | for (let i = 0; i < lines.length; ++i) { |
| 1442 | position += i > 0 ? lines[i - 1].length + 1 : 0; |
| 1443 | const isCallFrameLine = /^\s*at\s/.test(lines[i]); |
| 1444 | if (!isCallFrameLine && links.length) |
| 1445 | return null; |
| 1446 | |
| 1447 | if (!isCallFrameLine) |
| 1448 | continue; |
| 1449 | |
| 1450 | let openBracketIndex = -1; |
| 1451 | let closeBracketIndex = -1; |
| 1452 | const match = /\([^\)\(]+\)/.exec(lines[i]); |
| 1453 | if (match) { |
| 1454 | openBracketIndex = match.index; |
| 1455 | closeBracketIndex = match.index + match[0].length - 1; |
| 1456 | } |
| 1457 | const hasOpenBracket = openBracketIndex !== -1; |
| 1458 | const left = hasOpenBracket ? openBracketIndex + 1 : lines[i].indexOf('at') + 3; |
| 1459 | const right = hasOpenBracket ? closeBracketIndex : lines[i].length; |
| 1460 | const linkCandidate = lines[i].substring(left, right); |
| 1461 | const splitResult = Common.ParsedURL.splitLineAndColumn(linkCandidate); |
| 1462 | if (!splitResult) |
| 1463 | return null; |
| 1464 | |
| 1465 | if (splitResult.url === '<anonymous>') |
| 1466 | continue; |
| 1467 | let url = parseOrScriptMatch(splitResult.url); |
| 1468 | if (!url && Common.ParsedURL.isRelativeURL(splitResult.url)) |
| 1469 | url = parseOrScriptMatch(Common.ParsedURL.completeURL(baseURL, splitResult.url)); |
| 1470 | if (!url) |
| 1471 | return null; |
| 1472 | |
| 1473 | links.push({ |
| 1474 | url: url, |
| 1475 | positionLeft: position + left, |
| 1476 | positionRight: position + right, |
| 1477 | lineNumber: splitResult.lineNumber, |
| 1478 | columnNumber: splitResult.columnNumber |
| 1479 | }); |
| 1480 | } |
| 1481 | |
| 1482 | if (!links.length) |
| 1483 | return null; |
| 1484 | |
| 1485 | const formattedResult = createElement('span'); |
| 1486 | let start = 0; |
| 1487 | for (let i = 0; i < links.length; ++i) { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1488 | formattedResult.appendChild(this._linkifyStringAsFragment(string.substring(start, links[i].positionLeft))); |
Erik Luo | 182bece | 2018-11-29 03:15:22 | [diff] [blame] | 1489 | const scriptLocationLink = this._linkifier.linkifyScriptLocation( |
| 1490 | debuggerModel.target(), null, links[i].url, links[i].lineNumber, links[i].columnNumber); |
| 1491 | scriptLocationLink.tabIndex = -1; |
| 1492 | this._selectableChildren.push({element: scriptLocationLink, selectFirst: () => scriptLocationLink.focus()}); |
| 1493 | formattedResult.appendChild(scriptLocationLink); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1494 | start = links[i].positionRight; |
| 1495 | } |
| 1496 | |
| 1497 | if (start !== string.length) |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1498 | formattedResult.appendChild(this._linkifyStringAsFragment(string.substring(start))); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1499 | |
| 1500 | return formattedResult; |
| 1501 | |
| 1502 | /** |
| 1503 | * @param {?string} url |
| 1504 | * @return {?string} |
| 1505 | */ |
| 1506 | function parseOrScriptMatch(url) { |
| 1507 | if (!url) |
| 1508 | return null; |
| 1509 | const parsedURL = url.asParsedURL(); |
| 1510 | if (parsedURL) |
| 1511 | return parsedURL.url; |
| 1512 | if (debuggerModel.scriptsForSourceURL(url).length) |
| 1513 | return url; |
| 1514 | return null; |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | /** |
| 1519 | * @param {string} string |
| 1520 | * @param {function(string,string,number=,number=):!Node} linkifier |
| 1521 | * @return {!DocumentFragment} |
| 1522 | */ |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 1523 | _linkifyWithCustomLinkifier(string, linkifier) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1524 | if (string.length > Console.ConsoleViewMessage._MaxTokenizableStringLength) |
Erik Luo | 5fb33bd | 2018-06-04 23:23:52 | [diff] [blame] | 1525 | return UI.createExpandableText(string, Console.ConsoleViewMessage._LongStringVisibleLength); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1526 | const container = createDocumentFragment(); |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 1527 | const tokens = Console.ConsoleViewMessage._tokenizeMessageText(string); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1528 | for (const token of tokens) { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 1529 | if (!token.text) |
| 1530 | continue; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1531 | switch (token.type) { |
| 1532 | case 'url': { |
| 1533 | const realURL = (token.text.startsWith('www.') ? 'http://' + token.text : token.text); |
| 1534 | const splitResult = Common.ParsedURL.splitLineAndColumn(realURL); |
| 1535 | let linkNode; |
| 1536 | if (splitResult) |
| 1537 | linkNode = linkifier(token.text, splitResult.url, splitResult.lineNumber, splitResult.columnNumber); |
| 1538 | else |
| 1539 | linkNode = linkifier(token.text, token.value); |
| 1540 | container.appendChild(linkNode); |
| 1541 | break; |
| 1542 | } |
| 1543 | default: |
| 1544 | container.appendChild(createTextNode(token.text)); |
| 1545 | break; |
| 1546 | } |
| 1547 | } |
| 1548 | return container; |
| 1549 | } |
| 1550 | |
| 1551 | /** |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1552 | * @param {string} string |
| 1553 | * @return {!DocumentFragment} |
| 1554 | */ |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1555 | _linkifyStringAsFragment(string) { |
Erik Luo | fc2214f | 2018-11-21 19:54:58 | [diff] [blame] | 1556 | return this._linkifyWithCustomLinkifier(string, (text, url, lineNumber, columnNumber) => { |
Erik Luo | 383f21d | 2018-11-07 23:16:37 | [diff] [blame] | 1557 | const linkElement = Components.Linkifier.linkifyURL(url, {text, lineNumber, columnNumber}); |
| 1558 | linkElement.tabIndex = -1; |
| 1559 | this._selectableChildren.push({element: linkElement, selectFirst: () => linkElement.focus()}); |
| 1560 | return linkElement; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1561 | }); |
| 1562 | } |
| 1563 | |
| 1564 | /** |
| 1565 | * @param {string} string |
| 1566 | * @return {!Array<{type: string, text: (string|undefined)}>} |
| 1567 | */ |
| 1568 | static _tokenizeMessageText(string) { |
| 1569 | if (!Console.ConsoleViewMessage._tokenizerRegexes) { |
| 1570 | const controlCodes = '\\u0000-\\u0020\\u007f-\\u009f'; |
| 1571 | const linkStringRegex = new RegExp( |
| 1572 | '(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\\/\\/|data:|www\\.)[^\\s' + controlCodes + '"]{2,}[^\\s' + controlCodes + |
| 1573 | '"\')}\\],:;.!?]', |
| 1574 | 'u'); |
| 1575 | const pathLineRegex = /(?:\/[\w\.-]*)+\:[\d]+/; |
| 1576 | const timeRegex = /took [\d]+ms/; |
| 1577 | const eventRegex = /'\w+' event/; |
| 1578 | const milestoneRegex = /\sM[6-7]\d/; |
| 1579 | const autofillRegex = /\(suggested: \"[\w-]+\"\)/; |
| 1580 | const handlers = new Map(); |
| 1581 | handlers.set(linkStringRegex, 'url'); |
| 1582 | handlers.set(pathLineRegex, 'url'); |
| 1583 | handlers.set(timeRegex, 'time'); |
| 1584 | handlers.set(eventRegex, 'event'); |
| 1585 | handlers.set(milestoneRegex, 'milestone'); |
| 1586 | handlers.set(autofillRegex, 'autofill'); |
| 1587 | Console.ConsoleViewMessage._tokenizerRegexes = Array.from(handlers.keys()); |
| 1588 | Console.ConsoleViewMessage._tokenizerTypes = Array.from(handlers.values()); |
| 1589 | } |
| 1590 | if (string.length > Console.ConsoleViewMessage._MaxTokenizableStringLength) |
| 1591 | return [{text: string, type: undefined}]; |
| 1592 | const results = TextUtils.TextUtils.splitStringByRegexes(string, Console.ConsoleViewMessage._tokenizerRegexes); |
| 1593 | return results.map( |
| 1594 | result => ({text: result.value, type: Console.ConsoleViewMessage._tokenizerTypes[result.regexIndex]})); |
| 1595 | } |
| 1596 | |
| 1597 | /** |
| 1598 | * @return {string} |
| 1599 | */ |
| 1600 | groupKey() { |
| 1601 | if (!this._groupKey) |
| 1602 | this._groupKey = this._message.groupCategoryKey() + ':' + this.groupTitle(); |
| 1603 | return this._groupKey; |
| 1604 | } |
| 1605 | |
| 1606 | /** |
| 1607 | * @return {string} |
| 1608 | */ |
| 1609 | groupTitle() { |
| 1610 | const tokens = Console.ConsoleViewMessage._tokenizeMessageText(this._message.messageText); |
| 1611 | const result = tokens.reduce((acc, token) => { |
| 1612 | let text = token.text; |
| 1613 | if (token.type === 'url') |
| 1614 | text = Common.UIString('<URL>'); |
| 1615 | else if (token.type === 'time') |
| 1616 | text = Common.UIString('took <N>ms'); |
| 1617 | else if (token.type === 'event') |
| 1618 | text = Common.UIString('<some> event'); |
| 1619 | else if (token.type === 'milestone') |
| 1620 | text = Common.UIString(' M<XX>'); |
| 1621 | else if (token.type === 'autofill') |
| 1622 | text = Common.UIString('<attribute>'); |
| 1623 | return acc + text; |
| 1624 | }, ''); |
| 1625 | return result.replace(/[%]o/g, ''); |
| 1626 | } |
| 1627 | }; |
| 1628 | |
| 1629 | /** |
| 1630 | * @unrestricted |
| 1631 | */ |
| 1632 | Console.ConsoleGroupViewMessage = class extends Console.ConsoleViewMessage { |
| 1633 | /** |
| 1634 | * @param {!SDK.ConsoleMessage} consoleMessage |
| 1635 | * @param {!Components.Linkifier} linkifier |
| 1636 | * @param {!ProductRegistry.BadgePool} badgePool |
| 1637 | * @param {number} nestingLevel |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1638 | * @param {function()} onToggle |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame^] | 1639 | * @param {function(!Common.Event)} onResize |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1640 | */ |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame^] | 1641 | constructor(consoleMessage, linkifier, badgePool, nestingLevel, onToggle, onResize) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1642 | console.assert(consoleMessage.isGroupStartMessage()); |
Erik Luo | 840be6b | 2018-12-03 20:54:27 | [diff] [blame^] | 1643 | super(consoleMessage, linkifier, badgePool, nestingLevel, onResize); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1644 | this._collapsed = consoleMessage.type === SDK.ConsoleMessage.MessageType.StartGroupCollapsed; |
| 1645 | /** @type {?UI.Icon} */ |
| 1646 | this._expandGroupIcon = null; |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1647 | this._onToggle = onToggle; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | /** |
| 1651 | * @param {boolean} collapsed |
| 1652 | */ |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1653 | _setCollapsed(collapsed) { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1654 | this._collapsed = collapsed; |
| 1655 | if (this._expandGroupIcon) |
| 1656 | this._expandGroupIcon.setIconType(this._collapsed ? 'smallicon-triangle-right' : 'smallicon-triangle-down'); |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1657 | this._onToggle.call(null); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | /** |
| 1661 | * @return {boolean} |
| 1662 | */ |
| 1663 | collapsed() { |
| 1664 | return this._collapsed; |
| 1665 | } |
| 1666 | |
| 1667 | /** |
| 1668 | * @override |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1669 | * @param {!Event} event |
| 1670 | */ |
| 1671 | maybeHandleOnKeyDown(event) { |
Erik Luo | 0b8282e | 2018-10-08 20:37:46 | [diff] [blame] | 1672 | const focusedChildIndex = this._focusedChildIndex(); |
| 1673 | if (focusedChildIndex === -1) { |
| 1674 | if ((event.key === 'ArrowLeft' && !this._collapsed) || (event.key === 'ArrowRight' && this._collapsed)) { |
| 1675 | this._setCollapsed(!this._collapsed); |
| 1676 | return true; |
| 1677 | } |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1678 | } |
| 1679 | return super.maybeHandleOnKeyDown(event); |
| 1680 | } |
| 1681 | |
| 1682 | /** |
| 1683 | * @override |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1684 | * @return {!Element} |
| 1685 | */ |
| 1686 | toMessageElement() { |
| 1687 | if (!this._element) { |
| 1688 | super.toMessageElement(); |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1689 | const iconType = this._collapsed ? 'smallicon-triangle-right' : 'smallicon-triangle-down'; |
| 1690 | this._expandGroupIcon = UI.Icon.create(iconType, 'expand-group-icon'); |
Erik Luo | b5bfff4 | 2018-09-20 02:52:39 | [diff] [blame] | 1691 | // Intercept focus to avoid highlight on click. |
| 1692 | this._contentElement.tabIndex = -1; |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1693 | if (this._repeatCountElement) |
| 1694 | this._repeatCountElement.insertBefore(this._expandGroupIcon, this._repeatCountElement.firstChild); |
| 1695 | else |
| 1696 | this._element.insertBefore(this._expandGroupIcon, this._contentElement); |
Erik Luo | 8ef5d0c | 2018-09-25 21:16:00 | [diff] [blame] | 1697 | this._element.addEventListener('click', () => this._setCollapsed(!this._collapsed)); |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 | [diff] [blame] | 1698 | } |
| 1699 | return this._element; |
| 1700 | } |
| 1701 | |
| 1702 | /** |
| 1703 | * @override |
| 1704 | */ |
| 1705 | _showRepeatCountElement() { |
| 1706 | super._showRepeatCountElement(); |
| 1707 | if (this._repeatCountElement && this._expandGroupIcon) |
| 1708 | this._repeatCountElement.insertBefore(this._expandGroupIcon, this._repeatCountElement.firstChild); |
| 1709 | } |
| 1710 | }; |
| 1711 | |
| 1712 | /** |
| 1713 | * @const |
| 1714 | * @type {number} |
| 1715 | */ |
| 1716 | Console.ConsoleViewMessage.MaxLengthForLinks = 40; |
| 1717 | |
| 1718 | Console.ConsoleViewMessage._MaxTokenizableStringLength = 10000; |
| 1719 | |
| 1720 | Console.ConsoleViewMessage._LongStringVisibleLength = 5000; |