blob: b8752401657e719aa09f71104f283f06e1c4c080 [file] [log] [blame]
Patrick Hulcea087f622018-05-18 00:37:53 +00001// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5/**
6 * @override
7 */
8Audits2.ReportRenderer = class extends ReportRenderer {
9 /**
Paul Irish8f1e33d2018-05-31 02:29:50 +000010 * @param {!Element} el Parent element to render the report into.
11 * @param {!ReportRenderer.RunnerResultArtifacts=} artifacts
Patrick Hulcea087f622018-05-18 00:37:53 +000012 */
Paul Irish8f1e33d2018-05-31 02:29:50 +000013 static addViewTraceButton(el, artifacts) {
14 if (!artifacts || !artifacts.traces || !artifacts.traces.defaultPass)
15 return;
Patrick Hulcea087f622018-05-18 00:37:53 +000016
Paul Irish8f1e33d2018-05-31 02:29:50 +000017 const defaultPassTrace = artifacts.traces.defaultPass;
18 const timelineButton = UI.createTextButton(Common.UIString('View Trace'), onViewTraceClick, 'view-trace');
Paul Irishb5fc8bc2018-10-11 01:07:32 +000019 el.querySelector('.lh-column').appendChild(timelineButton);
Paul Irish8f1e33d2018-05-31 02:29:50 +000020 return el;
21
22 async function onViewTraceClick() {
Paul Irishca4e6bc2018-09-05 03:10:03 +000023 Host.userMetrics.actionTaken(Host.UserMetrics.Action.Audits2ViewTrace);
Paul Irish8f1e33d2018-05-31 02:29:50 +000024 await UI.inspectorView.showPanel('timeline');
25 Timeline.TimelinePanel.instance().loadFromEvents(defaultPassTrace.traceEvents);
26 }
Patrick Hulcea087f622018-05-18 00:37:53 +000027 }
28};
29
30class ReportUIFeatures {
31 /**
32 * @param {!ReportRenderer.ReportJSON} report
33 */
34 initFeatures(report) {
35 }
36}
37
Patrick Hulcea087f622018-05-18 00:37:53 +000038
39Audits2.DetailsRenderer = class extends DetailsRenderer {
40 /**
41 * @param {!DOM} dom
42 */
43 constructor(dom) {
44 super(dom);
45 this._onLoadPromise = null;
46 }
47
48 /**
49 * @override
50 * @param {!DetailsRenderer.NodeDetailsJSON} item
51 * @return {!Element}
52 */
53 renderNode(item) {
54 const element = super.renderNode(item);
55 this._replaceWithDeferredNodeBlock(element, item);
56 return element;
57 }
58
59 /**
60 * @param {!Element} origElement
61 * @param {!DetailsRenderer.NodeDetailsJSON} detailsItem
62 */
63 async _replaceWithDeferredNodeBlock(origElement, detailsItem) {
64 const mainTarget = SDK.targetManager.mainTarget();
65 if (!this._onLoadPromise) {
66 const resourceTreeModel = mainTarget.model(SDK.ResourceTreeModel);
67 this._onLoadPromise = resourceTreeModel.once(SDK.ResourceTreeModel.Events.Load);
68 }
69
70 await this._onLoadPromise;
71
72 const domModel = mainTarget.model(SDK.DOMModel);
73 if (!detailsItem.path)
74 return;
75
76 const nodeId = await domModel.pushNodeByPathToFrontend(detailsItem.path);
77
78 if (!nodeId)
79 return;
80 const node = domModel.nodeForId(nodeId);
81 if (!node)
82 return;
83
84 const element =
85 await Common.Linkifier.linkify(node, /** @type {!Common.Linkifier.Options} */ ({title: detailsItem.snippet}));
86 origElement.title = '';
87 origElement.textContent = '';
88 origElement.appendChild(element);
89 }
90};