11// Copyright 2021 The Chromium Authors
22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
4- /* eslint-disable @devtools/no-lit-render-outside-of-view */
54
65import '../../../ui/components/expandable_list/expandable_list.js' ;
76import '../../../ui/components/report_view/report_view.js' ;
@@ -20,8 +19,6 @@ import * as NetworkForward from '../../../panels/network/forward/forward.js';
2019import * as CspEvaluator from '../../../third_party/csp_evaluator/csp_evaluator.js' ;
2120import * as Buttons from '../../../ui/components/buttons/buttons.js' ;
2221import type * as ExpandableList from '../../../ui/components/expandable_list/expandable_list.js' ;
23- import * as LegacyWrapper from '../../../ui/components/legacy_wrapper/legacy_wrapper.js' ;
24- import * as RenderCoordinator from '../../../ui/components/render_coordinator/render_coordinator.js' ;
2522import type * as ReportView from '../../../ui/components/report_view/report_view.js' ;
2623import * as Components from '../../../ui/legacy/components/utils/utils.js' ;
2724import * as UI from '../../../ui/legacy/legacy.js' ;
@@ -288,7 +285,9 @@ interface FrameDetailsViewInput {
288285 onRevealInSources : ( ) => void ;
289286}
290287
291- function renderFrameDetailsView ( input : FrameDetailsViewInput , target : ShadowRoot ) : void {
288+ type View = ( input : FrameDetailsViewInput , output : undefined , target : HTMLElement ) => void ;
289+
290+ const DEFAULT_VIEW : View = ( input , _output , target ) => {
292291 if ( ! input . frame ) {
293292 return ;
294293 }
@@ -310,7 +309,7 @@ function renderFrameDetailsView(input: FrameDetailsViewInput, target: ShadowRoot
310309 </ devtools-report >
311310 ` , target ) ;
312311 // clang-format on
313- }
312+ } ;
314313
315314function renderOriginTrial ( trials : Protocol . Page . OriginTrial [ ] | null ) : LitTemplate {
316315 if ( ! trials ) {
@@ -848,27 +847,31 @@ function renderAdditionalInfoSection(frame: SDK.ResourceTreeModel.ResourceTreeFr
848847 ` ;
849848}
850849
851- export class FrameDetailsReportView extends LegacyWrapper . LegacyWrapper . WrappableComponent {
852- readonly #shadow = this . attachShadow ( { mode : 'open' } ) ;
850+ export class FrameDetailsReportView extends UI . Widget . Widget {
853851 #frame?: SDK . ResourceTreeModel . ResourceTreeFrame ;
854852 #target: SDK . Target . Target | null = null ;
855853 #protocolMonitorExperimentEnabled = false ;
856854 #permissionsPolicies: Promise < Protocol . Page . PermissionsPolicyFeatureState [ ] | null > | null = null ;
857855 #linkifier = new Components . Linkifier . Linkifier ( ) ;
858856 #adScriptAncestry: Protocol . Page . AdScriptAncestry | null = null ;
857+ #view: View ;
859858
860- constructor ( frame : SDK . ResourceTreeModel . ResourceTreeFrame ) {
861- super ( ) ;
859+ constructor ( element ?: HTMLElement , view = DEFAULT_VIEW ) {
860+ super ( element , { useShadowDom : true } ) ;
861+ this . #protocolMonitorExperimentEnabled = Root . Runtime . experiments . isEnabled ( 'protocol-monitor' ) ;
862+ this . #view = view ;
863+ }
864+
865+ set frame ( frame : SDK . ResourceTreeModel . ResourceTreeFrame ) {
862866 this . #frame = frame ;
863- void this . render ( ) ;
867+ this . requestUpdate ( ) ;
864868 }
865869
866- connectedCallback ( ) : void {
867- this . parentElement ?. classList . add ( 'overflow-auto' ) ;
868- this . #protocolMonitorExperimentEnabled = Root . Runtime . experiments . isEnabled ( 'protocol-monitor' ) ;
870+ get frame ( ) : SDK . ResourceTreeModel . ResourceTreeFrame | undefined {
871+ return this . #frame;
869872 }
870873
871- override async render ( ) : Promise < void > {
874+ override async performUpdate ( ) : Promise < void > {
872875 const result = await this . #frame?. parentFrame ( ) ?. getAdScriptAncestry ( this . #frame?. id ) ;
873876 if ( result && result . ancestryChain . length > 0 ) {
874877 this . #adScriptAncestry = result ;
@@ -887,41 +890,39 @@ export class FrameDetailsReportView extends LegacyWrapper.LegacyWrapper.Wrappabl
887890 if ( ! this . #permissionsPolicies && this . #frame) {
888891 this . #permissionsPolicies = this . #frame. getPermissionsPolicyState ( ) ;
889892 }
890- await RenderCoordinator . write ( 'FrameDetailsView render' , async ( ) => {
891- const frame = this . #frame;
892- if ( ! frame ) {
893- return ;
894- }
895- const networkManager = frame . resourceTreeModel ( ) . target ( ) . model ( SDK . NetworkManager . NetworkManager ) ;
896- const securityIsolationInfo = networkManager ?. getSecurityIsolationStatus ( frame . id ) ;
897- const linkTargetDOMNode = frame . getOwnerDOMNodeOrDocument ( ) ;
898- const frameRequest = frame . resourceForURL ( frame . url ) ?. request ;
899- const input = {
900- frame,
901- target : this . #target,
902- protocolMonitorExperimentEnabled : this . #protocolMonitorExperimentEnabled,
903- permissionsPolicies : this . #permissionsPolicies,
904- adScriptAncestry : this . #adScriptAncestry,
905- linkifier : this . #linkifier,
906- linkTargetDOMNode,
907- trials : await frame . getOriginTrials ( ) ,
908- securityIsolationInfo,
909- onRevealInNetwork : frameRequest ?
910- ( ) => {
911- const requestLocation = NetworkForward . UIRequestLocation . UIRequestLocation . tab (
912- frameRequest , NetworkForward . UIRequestLocation . UIRequestTabs . HEADERS_COMPONENT ) ;
913- return Common . Revealer . reveal ( requestLocation ) ;
914- } :
915- undefined ,
916- onRevealInSources : async ( ) => {
917- const sourceCode = this . #uiSourceCodeForFrame( frame ) ;
918- if ( sourceCode ) {
919- await Common . Revealer . reveal ( sourceCode ) ;
920- }
921- } ,
922- } ;
923- renderFrameDetailsView ( input , this . #shadow) ;
924- } ) ;
893+ const frame = this . #frame;
894+ if ( ! frame ) {
895+ return ;
896+ }
897+ const networkManager = frame . resourceTreeModel ( ) . target ( ) . model ( SDK . NetworkManager . NetworkManager ) ;
898+ const securityIsolationInfo = networkManager ?. getSecurityIsolationStatus ( frame . id ) ;
899+ const linkTargetDOMNode = frame . getOwnerDOMNodeOrDocument ( ) ;
900+ const frameRequest = frame . resourceForURL ( frame . url ) ?. request ;
901+ const input = {
902+ frame,
903+ target : this . #target,
904+ protocolMonitorExperimentEnabled : this . #protocolMonitorExperimentEnabled,
905+ permissionsPolicies : this . #permissionsPolicies,
906+ adScriptAncestry : this . #adScriptAncestry,
907+ linkifier : this . #linkifier,
908+ linkTargetDOMNode,
909+ trials : await frame . getOriginTrials ( ) ,
910+ securityIsolationInfo,
911+ onRevealInNetwork : frameRequest ?
912+ ( ) => {
913+ const requestLocation = NetworkForward . UIRequestLocation . UIRequestLocation . tab (
914+ frameRequest , NetworkForward . UIRequestLocation . UIRequestTabs . HEADERS_COMPONENT ) ;
915+ return Common . Revealer . reveal ( requestLocation ) ;
916+ } :
917+ undefined ,
918+ onRevealInSources : async ( ) => {
919+ const sourceCode = this . #uiSourceCodeForFrame( frame ) ;
920+ if ( sourceCode ) {
921+ await Common . Revealer . reveal ( sourceCode ) ;
922+ }
923+ } ,
924+ } ;
925+ this . #view( input , undefined , this . contentElement ) ;
925926 }
926927
927928 #uiSourceCodeForFrame( frame : SDK . ResourceTreeModel . ResourceTreeFrame ) : Workspace . UISourceCode . UISourceCode | null {
@@ -937,11 +938,3 @@ export class FrameDetailsReportView extends LegacyWrapper.LegacyWrapper.Wrappabl
937938 return null ;
938939 }
939940}
940-
941- customElements . define ( 'devtools-resources-frame-details-view' , FrameDetailsReportView ) ;
942-
943- declare global {
944- interface HTMLElementTagNameMap {
945- 'devtools-resources-frame-details-view' : FrameDetailsReportView ;
946- }
947- }
0 commit comments