blob: 9fa58d3bd24b962f096b101d89320e0e1b24629d [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
Jan Schefflerf1f45a82020-07-29 14:00:3631// @ts-nocheck
32// TODO(crbug.com/1011811): Enable TypeScript compiler checks
33
Tim van der Lippe64a94d82020-01-24 11:52:2434import * as Components from '../components/components.js';
35import * as SDK from '../sdk/sdk.js';
36import * as UI from '../ui/ui.js';
37
Paul Lewisd85dc382020-01-14 17:13:5638import {CustomPreviewComponent} from './CustomPreviewComponent.js';
39import {ObjectPropertiesSection} from './ObjectPropertiesSection.js';
40
41export class ObjectPopoverHelper {
Blink Reformat4c46d092018-04-07 15:32:3742 /**
Tim van der Lippe64a94d82020-01-24 11:52:2443 * @param {?Components.Linkifier.Linkifier} linkifier
Blink Reformat4c46d092018-04-07 15:32:3744 * @param {boolean} resultHighlightedAsDOM
45 */
46 constructor(linkifier, resultHighlightedAsDOM) {
47 this._linkifier = linkifier;
48 this._resultHighlightedAsDOM = resultHighlightedAsDOM;
49 }
50
51 dispose() {
Tim van der Lippe1d6e57a2019-09-30 11:55:3452 if (this._resultHighlightedAsDOM) {
Tim van der Lippe64a94d82020-01-24 11:52:2453 SDK.OverlayModel.OverlayModel.hideDOMNodeHighlight();
Tim van der Lippe1d6e57a2019-09-30 11:55:3454 }
55 if (this._linkifier) {
Blink Reformat4c46d092018-04-07 15:32:3756 this._linkifier.dispose();
Tim van der Lippe1d6e57a2019-09-30 11:55:3457 }
Blink Reformat4c46d092018-04-07 15:32:3758 }
59
60 /**
Tim van der Lippe64a94d82020-01-24 11:52:2461 * @param {!SDK.RemoteObject.RemoteObject} result
62 * @param {!UI.GlassPane.GlassPane} popover
Tim van der Lippe35741722019-11-21 15:36:2063 * @return {!Promise<?ObjectPopoverHelper>}
Blink Reformat4c46d092018-04-07 15:32:3764 */
Alexei Filippov02dfcd82018-06-26 19:23:0965 static async buildObjectPopover(result, popover) {
Tim van der Lippe35741722019-11-21 15:36:2066 const description = result.description.trimEndWithMaxLength(MaxPopoverTextLength);
Blink Reformat4c46d092018-04-07 15:32:3767 let popoverContentElement = null;
Alexei Filippov02dfcd82018-06-26 19:23:0968 if (result.type === 'object') {
Blink Reformat4c46d092018-04-07 15:32:3769 let linkifier = null;
70 let resultHighlightedAsDOM = false;
71 if (result.subtype === 'node') {
Tim van der Lippe64a94d82020-01-24 11:52:2472 SDK.OverlayModel.OverlayModel.highlightObjectAsDOMNode(result);
Blink Reformat4c46d092018-04-07 15:32:3773 resultHighlightedAsDOM = true;
74 }
75
76 if (result.customPreview()) {
Paul Lewisd85dc382020-01-14 17:13:5677 const customPreviewComponent = new CustomPreviewComponent(result);
Blink Reformat4c46d092018-04-07 15:32:3778 customPreviewComponent.expandIfPossible();
79 popoverContentElement = customPreviewComponent.element;
80 } else {
Tim van der Lippef49e2322020-05-01 15:03:0981 popoverContentElement = document.createElement('div');
82 popoverContentElement.classList.add('object-popover-content');
Tim van der Lippe64a94d82020-01-24 11:52:2483 UI.Utils.appendStyle(popoverContentElement, 'object_ui/objectPopover.css');
Blink Reformat4c46d092018-04-07 15:32:3784 const titleElement = popoverContentElement.createChild('div', 'monospace object-popover-title');
85 titleElement.createChild('span').textContent = description;
Tim van der Lippe64a94d82020-01-24 11:52:2486 linkifier = new Components.Linkifier.Linkifier();
Paul Lewisd85dc382020-01-14 17:13:5687 const section = new ObjectPropertiesSection(
Erik Luo3971e8a2018-08-09 07:27:0888 result, '', linkifier, undefined, undefined, undefined, true /* showOverflow */);
Blink Reformat4c46d092018-04-07 15:32:3789 section.element.classList.add('object-popover-tree');
90 section.titleLessMode();
91 popoverContentElement.appendChild(section.element);
92 }
Philip Pfaffee687f612020-09-02 08:06:5793 popoverContentElement.dataset.stableNameForTest = 'object-popover-content';
Tim van der Lippe64a94d82020-01-24 11:52:2494 popover.setMaxContentSize(new UI.Geometry.Size(300, 250));
Blink Reformat4c46d092018-04-07 15:32:3795 popover.setSizeBehavior(UI.GlassPane.SizeBehavior.SetExactSize);
96 popover.contentElement.appendChild(popoverContentElement);
Tim van der Lippe35741722019-11-21 15:36:2097 return new ObjectPopoverHelper(linkifier, resultHighlightedAsDOM);
Blink Reformat4c46d092018-04-07 15:32:3798 }
Alexei Filippov02dfcd82018-06-26 19:23:0999
100 popoverContentElement = createElement('span');
Philip Pfaffee687f612020-09-02 08:06:57101 popoverContentElement.dataset.stableNameForTest = 'object-popover-content';
Tim van der Lippe64a94d82020-01-24 11:52:24102 UI.Utils.appendStyle(popoverContentElement, 'object_ui/objectValue.css');
103 UI.Utils.appendStyle(popoverContentElement, 'object_ui/objectPopover.css');
Alexei Filippov02dfcd82018-06-26 19:23:09104 const valueElement = popoverContentElement.createChild('span', 'monospace object-value-' + result.type);
105 valueElement.style.whiteSpace = 'pre';
106
Tim van der Lippe1d6e57a2019-09-30 11:55:34107 if (result.type === 'string') {
Sigurd Schneider23c52972020-10-13 09:31:14108 UI.UIUtils.createTextChildren(valueElement, `"${description}"`);
Tim van der Lippe1d6e57a2019-09-30 11:55:34109 } else if (result.type !== 'function') {
Alexei Filippov02dfcd82018-06-26 19:23:09110 valueElement.textContent = description;
Tim van der Lippe1d6e57a2019-09-30 11:55:34111 }
Alexei Filippov02dfcd82018-06-26 19:23:09112
113 if (result.type !== 'function') {
114 popover.contentElement.appendChild(popoverContentElement);
Tim van der Lippe35741722019-11-21 15:36:20115 return new ObjectPopoverHelper(null, false);
Alexei Filippov02dfcd82018-06-26 19:23:09116 }
117
Paul Lewisd85dc382020-01-14 17:13:56118 ObjectPropertiesSection.formatObjectAsFunction(result, valueElement, true);
Alexei Filippov02dfcd82018-06-26 19:23:09119 const response = await result.debuggerModel().functionDetailsPromise(result);
Tim van der Lippe1d6e57a2019-09-30 11:55:34120 if (!response) {
Alexei Filippov02dfcd82018-06-26 19:23:09121 return null;
Tim van der Lippe1d6e57a2019-09-30 11:55:34122 }
Alexei Filippov02dfcd82018-06-26 19:23:09123
Tim van der Lippef49e2322020-05-01 15:03:09124 const container = document.createElement('div');
125 container.classList.add('object-popover-container');
Alexei Filippov02dfcd82018-06-26 19:23:09126 const title = container.createChild('div', 'function-popover-title source-code');
127 const functionName = title.createChild('span', 'function-name');
Tim van der Lippe64a94d82020-01-24 11:52:24128 functionName.textContent = UI.UIUtils.beautifyFunctionName(response.functionName);
Alexei Filippov02dfcd82018-06-26 19:23:09129
130 const rawLocation = response.location;
131 const linkContainer = title.createChild('div', 'function-title-link-container');
132 const sourceURL = rawLocation && rawLocation.script() && rawLocation.script().sourceURL;
133 let linkifier = null;
134 if (sourceURL) {
Alex Rudenkoca59b112020-05-27 09:29:14135 linkifier = new Components.Linkifier.Linkifier(undefined, undefined, popover.positionContent.bind(popover));
Tim van der Lippeffa78622019-09-16 12:07:12136 linkContainer.appendChild(
137 linkifier.linkifyRawLocation(/** @type {!SDK.DebuggerModel.Location} */ (rawLocation), sourceURL));
Alexei Filippov02dfcd82018-06-26 19:23:09138 }
139 container.appendChild(popoverContentElement);
140 popover.contentElement.appendChild(container);
Tim van der Lippe35741722019-11-21 15:36:20141 return new ObjectPopoverHelper(linkifier, false);
Blink Reformat4c46d092018-04-07 15:32:37142 }
Tim van der Lippe35741722019-11-21 15:36:20143}
Blink Reformat4c46d092018-04-07 15:32:37144
Tim van der Lippec96ccd92019-11-29 16:23:54145const MaxPopoverTextLength = 10000;