UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 6.42 kB
import*as Common from"../../core/common/common.js";import*as i18n from"../../core/i18n/i18n.js";import*as SDK from"../../core/sdk/sdk.js";import*as UI from"../../ui/legacy/legacy.js";import openedWindowDetailsViewStyles from"./openedWindowDetailsView.css.js";const UIStrings={yes:"Yes",no:"No",clickToRevealInElementsPanel:"Click to reveal in Elements panel",document:"Document",url:"URL",security:"Security",openerFrame:"Opener Frame",accessToOpener:"Access to opener",showsWhetherTheOpenedWindowIs:"Shows whether the opened window is able to access its opener and vice versa",windowWithoutTitle:"Window without title",closed:"closed",worker:"worker",type:"Type",securityIsolation:"Security & Isolation",crossoriginEmbedderPolicy:"Cross-Origin Embedder Policy",webWorker:"Web Worker",unknown:"Unknown",reportingTo:"reporting to"},str_=i18n.i18n.registerUIStrings("panels/application/OpenedWindowDetailsView.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_),booleanToYesNo=e=>i18nString(e?UIStrings.yes:UIStrings.no);function linkifyIcon(e,t,i){const n=UI.Icon.Icon.create(e,"icon-link devtools-link"),r=document.createElement("span");return UI.Tooltip.Tooltip.install(r,t),r.classList.add("devtools-link"),r.tabIndex=0,r.appendChild(n),r.addEventListener("click",(e=>{e.consume(!0),i()})),r.addEventListener("keydown",(e=>{"Enter"===e.key&&(e.consume(!0),i())})),r}async function maybeCreateLinkToElementsPanel(e){let t=null;if(e instanceof SDK.ResourceTreeModel.ResourceTreeFrame?t=e:e&&(t=SDK.FrameManager.FrameManager.instance().getFrame(e)),!t)return null;const i=await t.getOwnerDOMNodeOrDocument();if(!i)return null;const n=linkifyIcon("code-circle",i18nString(UIStrings.clickToRevealInElementsPanel),(()=>Common.Revealer.reveal(i))),r=document.createElement("span");return r.textContent=`<${i.nodeName().toLocaleLowerCase()}>`,n.insertBefore(r,n.firstChild),n.addEventListener("mouseenter",(()=>{t&&t.highlight()})),n.addEventListener("mouseleave",(()=>{SDK.OverlayModel.OverlayModel.hideDOMNodeHighlight()})),n}export class OpenedWindowDetailsView extends UI.ThrottledWidget.ThrottledWidget{targetInfo;isWindowClosed;reportView;documentSection;URLFieldValue;securitySection;openerElementField;hasDOMAccessValue;constructor(e,t){super(),this.targetInfo=e,this.isWindowClosed=t,this.contentElement.classList.add("frame-details-container"),this.reportView=new UI.ReportView.ReportView(this.buildTitle()),this.reportView.show(this.contentElement),this.reportView.element.classList.add("frame-details-report-container"),this.documentSection=this.reportView.appendSection(i18nString(UIStrings.document)),this.URLFieldValue=this.documentSection.appendField(i18nString(UIStrings.url)).createChild("div","text-ellipsis"),this.securitySection=this.reportView.appendSection(i18nString(UIStrings.security)),this.openerElementField=this.securitySection.appendField(i18nString(UIStrings.openerFrame)),this.securitySection.setFieldVisible(i18nString(UIStrings.openerFrame),!1),this.hasDOMAccessValue=this.securitySection.appendField(i18nString(UIStrings.accessToOpener)),UI.Tooltip.Tooltip.install(this.hasDOMAccessValue,i18nString(UIStrings.showsWhetherTheOpenedWindowIs)),this.update()}async doUpdate(){var e;this.reportView.setTitle(this.buildTitle()),this.URLFieldValue.textContent=this.targetInfo.url,this.URLFieldValue.title=this.targetInfo.url,this.hasDOMAccessValue.textContent=(e=this.targetInfo.canAccessOpener,i18nString(e?UIStrings.yes:UIStrings.no)),this.maybeDisplayOpenerFrame()}async maybeDisplayOpenerFrame(){this.openerElementField.removeChildren();const e=await maybeCreateLinkToElementsPanel(this.targetInfo.openerFrameId);if(e)return this.openerElementField.append(e),void this.securitySection.setFieldVisible(i18nString(UIStrings.openerFrame),!0);this.securitySection.setFieldVisible(i18nString(UIStrings.openerFrame),!1)}buildTitle(){let e=this.targetInfo.title||i18nString(UIStrings.windowWithoutTitle);return this.isWindowClosed&&(e+=` (${i18nString(UIStrings.closed)})`),e}setIsWindowClosed(e){this.isWindowClosed=e}setTargetInfo(e){this.targetInfo=e}wasShown(){super.wasShown(),this.reportView.registerCSSFiles([openedWindowDetailsViewStyles]),this.registerCSSFiles([openedWindowDetailsViewStyles])}}export class WorkerDetailsView extends UI.ThrottledWidget.ThrottledWidget{targetInfo;reportView;documentSection;isolationSection;coepPolicy;constructor(e){super(),this.targetInfo=e,this.contentElement.classList.add("frame-details-container"),this.reportView=new UI.ReportView.ReportView(this.targetInfo.title||this.targetInfo.url||i18nString(UIStrings.worker)),this.reportView.show(this.contentElement),this.reportView.element.classList.add("frame-details-report-container"),this.documentSection=this.reportView.appendSection(i18nString(UIStrings.document));const t=this.documentSection.appendField(i18nString(UIStrings.url)).createChild("div","text-ellipsis");t.textContent=this.targetInfo.url,t.title=this.targetInfo.url;this.documentSection.appendField(i18nString(UIStrings.type)).textContent=this.workerTypeToString(this.targetInfo.type),this.isolationSection=this.reportView.appendSection(i18nString(UIStrings.securityIsolation)),this.coepPolicy=this.isolationSection.appendField(i18nString(UIStrings.crossoriginEmbedderPolicy)),this.update()}workerTypeToString(e){return"worker"===e?i18nString(UIStrings.webWorker):"service_worker"===e?i18n.i18n.lockedString("Service Worker"):i18nString(UIStrings.unknown)}async updateCoopCoepStatus(){const e=SDK.TargetManager.TargetManager.instance().targetById(this.targetInfo.targetId);if(!e)return;const t=e.model(SDK.NetworkManager.NetworkManager),i=t&&await t.getSecurityIsolationStatus(null);if(!i)return;this.fillCrossOriginPolicy(this.coepPolicy,(e=>"None"!==e),i.coep)}fillCrossOriginPolicy(e,t,i){if(!i)return void(e.textContent="");const n=t(i.value);if(e.textContent=n?i.value:i.reportOnlyValue,!n&&t(i.reportOnlyValue)){const t=document.createElement("span");t.classList.add("inline-comment"),t.textContent="report-only",e.appendChild(t)}const r=n?i.reportingEndpoint:i.reportOnlyReportingEndpoint;if(r){e.createChild("span","inline-name").textContent=i18nString(UIStrings.reportingTo);e.createChild("span").textContent=r}}async doUpdate(){await this.updateCoopCoepStatus()}wasShown(){super.wasShown(),this.reportView.registerCSSFiles([openedWindowDetailsViewStyles]),this.registerCSSFiles([openedWindowDetailsViewStyles])}}