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