blob: bb4a8c260d994c26722052b795615c5d1ea3786e [file] [log] [blame]
Blink Reformat4c46d092018-04-07 15:32:371/*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
Tim van der Lippe64a94d82020-01-24 11:52:2431import * as Components from '../components/components.js';
32import * as SDK from '../sdk/sdk.js';
33import * as UI from '../ui/ui.js';
34
Paul Lewisd85dc382020-01-14 17:13:5635import {CustomPreviewComponent} from './CustomPreviewComponent.js';
36import {ObjectPropertiesSection} from './ObjectPropertiesSection.js';
37
38export class ObjectPopoverHelper {
Blink Reformat4c46d092018-04-07 15:32:3739 /**
Tim van der Lippe64a94d82020-01-24 11:52:2440 * @param {?Components.Linkifier.Linkifier} linkifier
Blink Reformat4c46d092018-04-07 15:32:3741 * @param {boolean} resultHighlightedAsDOM
42 */
43 constructor(linkifier, resultHighlightedAsDOM) {
44 this._linkifier = linkifier;
45 this._resultHighlightedAsDOM = resultHighlightedAsDOM;
46 }
47
48 dispose() {
Tim van der Lippe1d6e57a2019-09-30 11:55:3449 if (this._resultHighlightedAsDOM) {
Tim van der Lippe64a94d82020-01-24 11:52:2450 SDK.OverlayModel.OverlayModel.hideDOMNodeHighlight();
Tim van der Lippe1d6e57a2019-09-30 11:55:3451 }
52 if (this._linkifier) {
Blink Reformat4c46d092018-04-07 15:32:3753 this._linkifier.dispose();
Tim van der Lippe1d6e57a2019-09-30 11:55:3454 }
Blink Reformat4c46d092018-04-07 15:32:3755 }
56
57 /**
Tim van der Lippe64a94d82020-01-24 11:52:2458 * @param {!SDK.RemoteObject.RemoteObject} result
59 * @param {!UI.GlassPane.GlassPane} popover
Tim van der Lippe35741722019-11-21 15:36:2060 * @return {!Promise<?ObjectPopoverHelper>}
Blink Reformat4c46d092018-04-07 15:32:3761 */
Alexei Filippov02dfcd82018-06-26 19:23:0962 static async buildObjectPopover(result, popover) {
Simon Zünd9f9ea0f2020-10-20 06:31:0263 const description = (result.description || '').trimEndWithMaxLength(MaxPopoverTextLength);
Blink Reformat4c46d092018-04-07 15:32:3764 let popoverContentElement = null;
Alexei Filippov02dfcd82018-06-26 19:23:0965 if (result.type === 'object') {
Blink Reformat4c46d092018-04-07 15:32:3766 let linkifier = null;
67 let resultHighlightedAsDOM = false;
68 if (result.subtype === 'node') {
Tim van der Lippe64a94d82020-01-24 11:52:2469 SDK.OverlayModel.OverlayModel.highlightObjectAsDOMNode(result);
Blink Reformat4c46d092018-04-07 15:32:3770 resultHighlightedAsDOM = true;
71 }
72
73 if (result.customPreview()) {
Paul Lewisd85dc382020-01-14 17:13:5674 const customPreviewComponent = new CustomPreviewComponent(result);
Blink Reformat4c46d092018-04-07 15:32:3775 customPreviewComponent.expandIfPossible();
76 popoverContentElement = customPreviewComponent.element;
77 } else {
Tim van der Lippef49e2322020-05-01 15:03:0978 popoverContentElement = document.createElement('div');
79 popoverContentElement.classList.add('object-popover-content');
Jack Franklin71519f82020-11-03 12:08:5980 UI.Utils.appendStyle(popoverContentElement, 'object_ui/objectPopover.css', {enableLegacyPatching: true});
Blink Reformat4c46d092018-04-07 15:32:3781 const titleElement = popoverContentElement.createChild('div', 'monospace object-popover-title');
82 titleElement.createChild('span').textContent = description;
Tim van der Lippe64a94d82020-01-24 11:52:2483 linkifier = new Components.Linkifier.Linkifier();
Paul Lewisd85dc382020-01-14 17:13:5684 const section = new ObjectPropertiesSection(
Erik Luo3971e8a2018-08-09 07:27:0885 result, '', linkifier, undefined, undefined, undefined, true /* showOverflow */);
Blink Reformat4c46d092018-04-07 15:32:3786 section.element.classList.add('object-popover-tree');
87 section.titleLessMode();
88 popoverContentElement.appendChild(section.element);
89 }
Philip Pfaffee687f612020-09-02 08:06:5790 popoverContentElement.dataset.stableNameForTest = 'object-popover-content';
Tim van der Lippe64a94d82020-01-24 11:52:2491 popover.setMaxContentSize(new UI.Geometry.Size(300, 250));
Blink Reformat4c46d092018-04-07 15:32:3792 popover.setSizeBehavior(UI.GlassPane.SizeBehavior.SetExactSize);
93 popover.contentElement.appendChild(popoverContentElement);
Tim van der Lippe35741722019-11-21 15:36:2094 return new ObjectPopoverHelper(linkifier, resultHighlightedAsDOM);
Blink Reformat4c46d092018-04-07 15:32:3795 }
Alexei Filippov02dfcd82018-06-26 19:23:0996
Simon Zünd9f9ea0f2020-10-20 06:31:0297 popoverContentElement = document.createElement('span');
Philip Pfaffee687f612020-09-02 08:06:5798 popoverContentElement.dataset.stableNameForTest = 'object-popover-content';
Jack Franklin71519f82020-11-03 12:08:5999 UI.Utils.appendStyle(popoverContentElement, 'object_ui/objectValue.css', {enableLegacyPatching: true});
100 UI.Utils.appendStyle(popoverContentElement, 'object_ui/objectPopover.css', {enableLegacyPatching: true});
Alexei Filippov02dfcd82018-06-26 19:23:09101 const valueElement = popoverContentElement.createChild('span', 'monospace object-value-' + result.type);
102 valueElement.style.whiteSpace = 'pre';
103
Tim van der Lippe1d6e57a2019-09-30 11:55:34104 if (result.type === 'string') {
Sigurd Schneider23c52972020-10-13 09:31:14105 UI.UIUtils.createTextChildren(valueElement, `"${description}"`);
Tim van der Lippe1d6e57a2019-09-30 11:55:34106 } else if (result.type !== 'function') {
Alexei Filippov02dfcd82018-06-26 19:23:09107 valueElement.textContent = description;
Tim van der Lippe1d6e57a2019-09-30 11:55:34108 }
Alexei Filippov02dfcd82018-06-26 19:23:09109
110 if (result.type !== 'function') {
111 popover.contentElement.appendChild(popoverContentElement);
Tim van der Lippe35741722019-11-21 15:36:20112 return new ObjectPopoverHelper(null, false);
Alexei Filippov02dfcd82018-06-26 19:23:09113 }
114
Paul Lewisd85dc382020-01-14 17:13:56115 ObjectPropertiesSection.formatObjectAsFunction(result, valueElement, true);
Alexei Filippov02dfcd82018-06-26 19:23:09116 const response = await result.debuggerModel().functionDetailsPromise(result);
Tim van der Lippe1d6e57a2019-09-30 11:55:34117 if (!response) {
Alexei Filippov02dfcd82018-06-26 19:23:09118 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34119 }
Alexei Filippov02dfcd82018-06-26 19:23:09120
Tim van der Lippef49e2322020-05-01 15:03:09121 const container = document.createElement('div');
122 container.classList.add('object-popover-container');
Alexei Filippov02dfcd82018-06-26 19:23:09123 const title = container.createChild('div', 'function-popover-title source-code');
124 const functionName = title.createChild('span', 'function-name');
Tim van der Lippe64a94d82020-01-24 11:52:24125 functionName.textContent = UI.UIUtils.beautifyFunctionName(response.functionName);
Alexei Filippov02dfcd82018-06-26 19:23:09126
127 const rawLocation = response.location;
128 const linkContainer = title.createChild('div', 'function-title-link-container');
Simon Zünd9f9ea0f2020-10-20 06:31:02129 const script = rawLocation && rawLocation.script();
130 const sourceURL = script && script.sourceURL;
Alexei Filippov02dfcd82018-06-26 19:23:09131 let linkifier = null;
132 if (sourceURL) {
Alex Rudenkoca59b112020-05-27 09:29:14133 linkifier = new Components.Linkifier.Linkifier(undefined, undefined, popover.positionContent.bind(popover));
Tim van der Lippeffa78622019-09-16 12:07:12134 linkContainer.appendChild(
135 linkifier.linkifyRawLocation(/** @type {!SDK.DebuggerModel.Location} */ (rawLocation), sourceURL));
Alexei Filippov02dfcd82018-06-26 19:23:09136 }
137 container.appendChild(popoverContentElement);
138 popover.contentElement.appendChild(container);
Tim van der Lippe35741722019-11-21 15:36:20139 return new ObjectPopoverHelper(linkifier, false);
Blink Reformat4c46d092018-04-07 15:32:37140 }
Tim van der Lippe35741722019-11-21 15:36:20141}
Blink Reformat4c46d092018-04-07 15:32:37142
Tim van der Lippec96ccd92019-11-29 16:23:54143const MaxPopoverTextLength = 10000;