Wolfgang Beyer | 760462e | 2020-07-13 15:01:35 | [diff] [blame] | 1 | // 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 Scheffler | 52b1f35 | 2020-07-31 09:23:50 | [diff] [blame] | 5 | // @ts-nocheck |
| 6 | // TODO(crbug.com/1011811): Enable TypeScript compiler checks |
| 7 | |
Sigurd Schneider | 1e5ad28 | 2020-07-17 11:52:08 | [diff] [blame] | 8 | import * as Common from '../common/common.js'; |
Wolfgang Beyer | 760462e | 2020-07-13 15:01:35 | [diff] [blame] | 9 | import * as SDK from '../sdk/sdk.js'; // eslint-disable-line no-unused-vars |
| 10 | import * as UI from '../ui/ui.js'; |
Sigurd Schneider | 1e5ad28 | 2020-07-17 11:52:08 | [diff] [blame] | 11 | import * as Workspace from '../workspace/workspace.js'; |
Wolfgang Beyer | 760462e | 2020-07-13 15:01:35 | [diff] [blame] | 12 | |
Sigurd Schneider | 1e5ad28 | 2020-07-17 11:52:08 | [diff] [blame] | 13 | export class FrameDetailsView extends UI.ThrottledWidget.ThrottledWidget { |
Wolfgang Beyer | 760462e | 2020-07-13 15:01:35 | [diff] [blame] | 14 | /** |
| 15 | * @param {!SDK.ResourceTreeModel.ResourceTreeFrame} frame |
| 16 | */ |
| 17 | constructor(frame) { |
| 18 | super(); |
Sigurd Schneider | 1e5ad28 | 2020-07-17 11:52:08 | [diff] [blame] | 19 | this._frame = frame; |
Wolfgang Beyer | 760462e | 2020-07-13 15:01:35 | [diff] [blame] | 20 | this._reportView = new UI.ReportView.ReportView(frame.displayName()); |
Sigurd Schneider | 1e5ad28 | 2020-07-17 11:52:08 | [diff] [blame] | 21 | this._reportView.registerRequiredCSS('resources/frameDetailsReportView.css'); |
Wolfgang Beyer | 760462e | 2020-07-13 15:01:35 | [diff] [blame] | 22 | this._reportView.show(this.contentElement); |
| 23 | |
Sigurd Schneider | 1e5ad28 | 2020-07-17 11:52:08 | [diff] [blame] | 24 | 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 Schneider | f1aba72 | 2020-07-20 09:03:19 | [diff] [blame] | 38 | this._adStatus = this._generalSection.appendField(ls`Ad Status`); |
Sigurd Schneider | 1e5ad28 | 2020-07-17 11:52:08 | [diff] [blame] | 39 | 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 Schneider | f1aba72 | 2020-07-20 09:03:19 | [diff] [blame] | 64 | this._updateAdStatus(); |
Sigurd Schneider | 1e5ad28 | 2020-07-17 11:52:08 | [diff] [blame] | 65 | if (this._ownerDomNode) { |
| 66 | this._ownerElementFieldValue.textContent = `<${this._ownerDomNode.nodeName().toLocaleLowerCase()}>`; |
| 67 | } |
Wolfgang Beyer | 760462e | 2020-07-13 15:01:35 | [diff] [blame] | 68 | } |
Sigurd Schneider | f1aba72 | 2020-07-20 09:03:19 | [diff] [blame] | 69 | |
| 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 Beyer | 760462e | 2020-07-13 15:01:35 | [diff] [blame] | 87 | } |
Wolfgang Beyer | 3b4747f | 2020-08-12 07:30:46 | [diff] [blame^] | 88 | |
| 89 | export 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 | } |