blob: c57327b441036b95ec29dd242fc014641b6fb9cf [file] [log] [blame]
Wolfgang Beyer760462e2020-07-13 15:01:351// Copyright 2020 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
Jan Scheffler52b1f352020-07-31 09:23:505// @ts-nocheck
6// TODO(crbug.com/1011811): Enable TypeScript compiler checks
7
Sigurd Schneider1e5ad282020-07-17 11:52:088import * as Common from '../common/common.js';
Wolfgang Beyer760462e2020-07-13 15:01:359import * as SDK from '../sdk/sdk.js'; // eslint-disable-line no-unused-vars
10import * as UI from '../ui/ui.js';
Sigurd Schneider1e5ad282020-07-17 11:52:0811import * as Workspace from '../workspace/workspace.js';
Wolfgang Beyer760462e2020-07-13 15:01:3512
Sigurd Schneider1e5ad282020-07-17 11:52:0813export class FrameDetailsView extends UI.ThrottledWidget.ThrottledWidget {
Wolfgang Beyer760462e2020-07-13 15:01:3514 /**
15 * @param {!SDK.ResourceTreeModel.ResourceTreeFrame} frame
16 */
17 constructor(frame) {
18 super();
Sigurd Schneider1e5ad282020-07-17 11:52:0819 this._frame = frame;
Wolfgang Beyer760462e2020-07-13 15:01:3520 this._reportView = new UI.ReportView.ReportView(frame.displayName());
Sigurd Schneider1e5ad282020-07-17 11:52:0821 this._reportView.registerRequiredCSS('resources/frameDetailsReportView.css');
Wolfgang Beyer760462e2020-07-13 15:01:3522 this._reportView.show(this.contentElement);
23
Sigurd Schneider1e5ad282020-07-17 11:52:0824 this._generalSection = this._reportView.appendSection(ls`Document`);
25 this._urlFieldValue = this._generalSection.appendField(ls`URL`);
26 this._originFieldValue = this._generalSection.appendField(ls`Origin`);
27
28 this._ownerElementFieldValue = this._generalSection.appendField(ls`Owner Element`);
29 this._ownerElementFieldValue.classList.add('devtools-link');
30 this._ownerElementFieldValue.title = ls`Click to reveal in Elements panel`;
31 /** @type {?SDK.DOMModel.DOMNode} */
32 this._ownerDomNode = null;
33 this._ownerElementFieldValue.addEventListener('click', () => {
34 if (this._ownerDomNode) {
35 Common.Revealer.reveal(this._ownerDomNode);
36 }
37 });
Sigurd Schneiderf1aba722020-07-20 09:03:1938 this._adStatus = this._generalSection.appendField(ls`Ad Status`);
Sigurd Schneider1e5ad282020-07-17 11:52:0839 this.update();
40 }
41
42 /**
43 * @override
44 * @return {!Promise<?>}
45 */
46 async doUpdate() {
47 this._urlFieldValue.textContent = this._frame.url;
48 const revealSources = this._urlFieldValue.createChild('span', 'report-field-value-part devtools-link');
49 revealSources.textContent = ls`View Source`;
50 revealSources.addEventListener('click', () => {
51 const sourceCode = Workspace.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(this._frame.url);
52 Common.Revealer.reveal(sourceCode);
53 });
54 const documentResource = this._frame.resourceForURL(this._frame.url);
55 if (documentResource && documentResource.request) {
56 const revealRequest = this._urlFieldValue.createChild('span', 'report-field-value-part devtools-link');
57 revealRequest.textContent = ls`View Request`;
58 revealRequest.addEventListener('click', () => {
59 Common.Revealer.reveal(documentResource.request);
60 });
61 }
62 this._originFieldValue.textContent = this._frame.securityOrigin;
63 this._ownerDomNode = await this._frame.getOwnerDOMNodeOrDocument();
Sigurd Schneiderf1aba722020-07-20 09:03:1964 this._updateAdStatus();
Sigurd Schneider1e5ad282020-07-17 11:52:0865 if (this._ownerDomNode) {
66 this._ownerElementFieldValue.textContent = `<${this._ownerDomNode.nodeName().toLocaleLowerCase()}>`;
67 }
Wolfgang Beyer760462e2020-07-13 15:01:3568 }
Sigurd Schneiderf1aba722020-07-20 09:03:1969
70 _updateAdStatus() {
71 switch (this._frame.adFrameType()) {
72 case Protocol.Page.AdFrameType.Root:
73 this._generalSection.setFieldVisible(ls`Ad Status`, true);
74 this._adStatus.textContent = ls`root`;
75 this._adStatus.title = ls`This frame has been identified as the root frame of an ad`;
76 break;
77 case Protocol.Page.AdFrameType.Child:
78 this._generalSection.setFieldVisible(ls`Ad Status`, true);
79 this._adStatus.textContent = ls`child`;
80 this._adStatus.title = ls`This frame has been identified as the a child frame of an ad`;
81 break;
82 default:
83 this._generalSection.setFieldVisible(ls`Ad Status`, false);
84 break;
85 }
86 }
Wolfgang Beyer760462e2020-07-13 15:01:3587}
Wolfgang Beyer3b4747f2020-08-12 07:30:4688
89export class OpenedWindowDetailsView extends UI.ThrottledWidget.ThrottledWidget {
90 /**
91 * @param {!Protocol.Target.TargetInfo} targetInfo
92 * @param {boolean} isWindowClosed
93 */
94 constructor(targetInfo, isWindowClosed) {
95 super();
96 this._targetInfo = targetInfo;
97 this._isWindowClosed = isWindowClosed;
98 this._reportView = new UI.ReportView.ReportView(this.buildTitle());
99 this._reportView.registerRequiredCSS('resources/frameDetailsReportView.css');
100 this._reportView.show(this.contentElement);
101
102 this._documentSection = this._reportView.appendSection(ls`Document`);
103 this._URLFieldValue = this._documentSection.appendField(ls`URL`);
104
105 this._securitySection = this._reportView.appendSection(ls`Security`);
106 this._hasDOMAccessValue = this._securitySection.appendField(ls`Access to opener`);
107
108 this.update();
109 }
110
111 /**
112 * @override
113 * @return {!Promise<?>}
114 */
115 async doUpdate() {
116 this._reportView.setTitle(this.buildTitle());
117 this._URLFieldValue.textContent = this._targetInfo.url;
118 this._hasDOMAccessValue.textContent = this._targetInfo.canAccessOpener ? ls`Yes` : ls`No`;
119 }
120
121 /**
122 * @return {string}
123 */
124 buildTitle() {
125 let title = this._targetInfo.title || ls`Window without title`;
126 if (this._isWindowClosed) {
127 title += ` (${ls`closed`})`;
128 }
129 return title;
130 }
131
132 /**
133 * @param {boolean} isWindowClosed
134 */
135 setIsWindowClosed(isWindowClosed) {
136 this._isWindowClosed = isWindowClosed;
137 }
138
139 /**
140 * @param {!Protocol.Target.TargetInfo} targetInfo
141 */
142 setTargetInfo(targetInfo) {
143 this._targetInfo = targetInfo;
144 }
145}