-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.js
More file actions
50 lines (50 loc) · 48.9 KB
/
common.js
File metadata and controls
50 lines (50 loc) · 48.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import*as e from"../../core/host/host.js";import*as t from"../../core/i18n/i18n.js";import*as s from"../../models/geometry/geometry.js";import"../../ui/components/buttons/buttons.js";import*as n from"../../ui/legacy/legacy.js";import*as i from"../../ui/lit/lit.js";import*as r from"../../core/platform/platform.js";import*as o from"../../core/sdk/sdk.js";import*as a from"../../models/extensions/extensions.js";import*as c from"../../core/common/common.js";import*as d from"../../models/edge_focus_mode/forward/forward.js";import*as l from"../../models/bindings/bindings.js";import*as u from"../../models/har/har.js";import*as h from"../../models/logs/logs.js";import*as p from"../../models/text_utils/text_utils.js";import*as g from"../../models/workspace/workspace.js";import*as m from"../../ui/legacy/components/utils/utils.js";import*as b from"../../ui/legacy/theme_support/theme_support.js";import*as f from"../../models/persistence/persistence.js";import*as E from"../../ui/components/icon_button/icon_button.js";var x=`.fre-disclaimer{width:var(--sys-size-33);padding:var(--sys-size-9);header{display:flex;gap:var(--sys-size-8);margin-bottom:var(--sys-size-6);align-items:center;h2{margin:0;color:var(--sys-color-on-surface);font:var(--sys-typescale-headline5)}.header-icon-container{background:linear-gradient(135deg,var(--sys-color-gradient-primary),var(--sys-color-gradient-tertiary));border-radius:var(--sys-size-4);min-height:var(--sys-size-14);min-width:var(--sys-size-14);display:flex;align-items:center;justify-content:center;devtools-icon{width:var(--sys-size-9);height:var(--sys-size-9)}}}.reminder-container{border-radius:var(--sys-size-6);background-color:var(--sys-color-surface4);padding:var(--sys-size-9);h3{color:var(--sys-color-on-surface);font:var(--sys-typescale-body4-medium);margin:0}.reminder-item{display:flex;flex-direction:row;align-items:center;gap:var(--sys-size-5);margin-top:var(--sys-size-6);font:var(--sys-typescale-body5-regular);devtools-icon.reminder-icon{width:var(--sys-size-8);height:var(--sys-size-8)}.link{color:var(--sys-color-primary);text-decoration-line:underline}}}footer{display:flex;flex-direction:row;align-items:center;justify-content:space-between;margin-top:var(--sys-size-8);min-width:var(--sys-size-28);.right-buttons{display:flex;gap:var(--sys-size-5)}}}.type-to-allow-dialog{width:100%;.header{display:flex;justify-content:space-between;font:var(--sys-typescale-body2-medium);margin:var(--sys-size-5) var(--sys-size-5) var(--sys-size-5) var(--sys-size-8)}.title{padding-top:var(--sys-size-3)}.dialog-close-button{margin:var(--sys-size-3);z-index:1}.message,\n .text-input{margin:0 var(--sys-size-8)}.text-input{margin-top:var(--sys-size-5)}.button{text-align:right;margin:var(--sys-size-6) var(--sys-size-8) var(--sys-size-8) var(--sys-size-8);gap:var(--sys-size-5);display:flex;flex-direction:row-reverse;justify-content:flex-start}.button button{min-width:var(--sys-size-19)}}\n/*# sourceURL=${import.meta.resolve("./common.css")} */`;const{render:R,html:w,Directives:{ref:v}}=i,S=(e,t,s)=>{R(w`<iframe
${v(e=>{t.iframe=e})}
src=${e.src}
class=${e.className}
@load=${e.onLoad}></iframe>`,s)};let y=class extends n.Widget.Widget{#e;#t;#s;#n;#i;#r;#o;constructor(e,t,s,n,i=S){super(),this.#o=i,this.#e=e,this.#s=s,this.#n=n,this.#t=t,this.setHideOnDetach(),this.performUpdate()}performUpdate(){const e={};this.#o({src:this.#s,className:this.#n,onLoad:this.onLoad.bind(this)},e,this.element),e.iframe&&(this.#i=e.iframe)}wasShown(){super.wasShown(),"number"==typeof this.#r&&this.#e.notifyViewShown(this.#t,this.#r)}willHide(){super.willHide(),"number"==typeof this.#r&&this.#e.notifyViewHidden(this.#t)}onLoad(){if(!this.#i)return;const e=window.frames;this.#r=Array.prototype.indexOf.call(e,this.#i.contentWindow),this.isShowing()&&this.#e.notifyViewShown(this.#t,this.#r)}};class A extends n.Widget.VBox{server;id;constructor(e,t){super(),this.server=e,this.id=t}wasShown(){super.wasShown(),this.server.notifyViewShown(this.id)}willHide(){super.willHide(),this.server.notifyViewHidden(this.id)}}var I=Object.freeze({__proto__:null,ExtensionNotifierView:A,ExtensionView:y});let C=class extends n.Panel.Panel{server;id;panelToolbar;searchableViewInternal;constructor(e,t,s,i){super(t),this.server=e,this.id=s,this.setHideOnDetach(),this.panelToolbar=this.element.createChild("devtools-toolbar","hidden"),this.searchableViewInternal=new n.SearchableView.SearchableView(this,null),this.searchableViewInternal.show(this.element);new y(e,this.id,i,"extension").show(this.searchableViewInternal.element)}addToolbarItem(e){this.panelToolbar.classList.remove("hidden"),this.panelToolbar.appendToolbarItem(e)}onSearchCanceled(){this.server.notifySearchAction(this.id,"cancelSearch"),this.searchableViewInternal.updateSearchMatchesCount(0)}searchableView(){return this.searchableViewInternal}performSearch(e,t,s){const n=e.query;this.server.notifySearchAction(this.id,"performSearch",n)}jumpToNextSearchResult(){this.server.notifySearchAction(this.id,"nextSearchResult")}jumpToPreviousSearchResult(){this.server.notifySearchAction(this.id,"previousSearchResult")}supportsCaseSensitiveSearch(){return!1}supportsWholeWordSearch(){return!1}supportsRegexSearch(){return!1}};class O{id;toolbarButtonInternal;constructor(e,t,s,i,r){this.id=t,this.toolbarButtonInternal=new n.Toolbar.ToolbarButton("",""),this.toolbarButtonInternal.addEventListener("Click",e.notifyButtonClicked.bind(e,this.id)),this.update(s,i,r)}update(e,t,s){"string"==typeof e&&this.toolbarButtonInternal.setBackgroundImage(e),"string"==typeof t&&this.toolbarButtonInternal.setTitle(t),"boolean"==typeof s&&this.toolbarButtonInternal.setEnabled(!s)}toolbarButton(){return this.toolbarButtonInternal}}class P extends n.View.SimpleView{panelNameInternal;server;idInternal;extensionView;objectPropertiesView;constructor(e,t,s,n){super({title:s,viewId:r.StringUtilities.toKebabCase(s)}),this.element.classList.add("fill"),this.panelNameInternal=t,this.server=e,this.idInternal=n}id(){return this.idInternal}panelName(){return this.panelNameInternal}setObject(e,t,s){this.createObjectPropertiesView(),this.setObjectInternal(o.RemoteObject.RemoteObject.fromLocalObject(e),t,s)}setExpression(e,t,s,n,i){this.createObjectPropertiesView(),this.server.evaluate(e,!0,!1,s,n,this.onEvaluate.bind(this,t,i))}setPage(e){this.objectPropertiesView&&(this.objectPropertiesView.detach(),delete this.objectPropertiesView),this.extensionView&&this.extensionView.detach(!0),this.extensionView=new y(this.server,this.idInternal,e,"extension fill"),this.extensionView.show(this.element),this.element.style.height||this.setHeight("150px")}setHeight(e){this.element.style.height=e}onEvaluate(e,t,s,n,i){s?t(s.toString()):n?this.setObjectInternal(n,e,t):t()}createObjectPropertiesView(){this.objectPropertiesView||(this.extensionView&&(this.extensionView.detach(!0),delete this.extensionView),this.objectPropertiesView=new A(this.server,this.idInternal),this.objectPropertiesView.show(this.element))}setObjectInternal(e,t,s){const i=this.objectPropertiesView;i?(i.element.removeChildren(),n.UIUtils.Renderer.render(e,{title:t,editable:!1,expand:!0}).then(e=>{e?(i.element.appendChild(e.element),s()):s()})):s("operation cancelled")}}var T=Object.freeze({__proto__:null,ExtensionButton:O,ExtensionPanel:C,ExtensionSidebarPane:P});const L={},U=new WeakMap,H=["http:","https:","file:","data:","chrome-extension:","about:"];let k;class M{runtimeAllowedHosts;runtimeBlockedHosts;static create(e){const t=[],s=[];if(e){for(const s of e.runtimeAllowedHosts){const e=a.HostUrlPattern.HostUrlPattern.parse(s);if(!e)return null;t.push(e)}for(const t of e.runtimeBlockedHosts){const e=a.HostUrlPattern.HostUrlPattern.parse(t);if(!e)return null;s.push(e)}}return new M(t,s)}constructor(e,t){this.runtimeAllowedHosts=e,this.runtimeBlockedHosts=t}isAllowedOnURL(e){return e?!(this.runtimeBlockedHosts.some(t=>t.matchesUrl(e))&&!this.runtimeAllowedHosts.some(t=>t.matchesUrl(e))):0===this.runtimeBlockedHosts.length}}class _{name;hostsPolicy;allowFileAccess;openResourceScheme=null;constructor(e,t,s){this.name=e,this.hostsPolicy=t,this.allowFileAccess=s}isAllowedOnTarget(e){if(e||(e=o.TargetManager.TargetManager.instance().primaryPageTarget()?.inspectedURL()),!e)return!1;if(this.openResourceScheme&&e.startsWith(this.openResourceScheme))return!0;if(!L.ExtensionServer.canInspectURL(e))return!1;if(!this.hostsPolicy.isAllowedOnURL(e))return!1;if(!this.allowFileAccess){let t;try{t=new URL(e)}catch{return!1}return"file:"!==t.protocol}return!0}}class B{filter;constructor(e){this.filter=e}}let D=class extends c.ObjectWrapper.ObjectWrapper{clientObjects;handlers;subscribers;subscriptionStartHandlers;subscriptionStopHandlers;extraHeaders;requests;requestIds;lastRequestId;registeredExtensions;status;sidebarPanesInternal;extensionsEnabled;inspectedTabId;extensionAPITestHook;themeChangeHandlers=new Map;#a=[];constructor(){super(),this.clientObjects=new Map,this.handlers=new Map,this.subscribers=new Map,this.subscriptionStartHandlers=new Map,this.subscriptionStopHandlers=new Map,this.extraHeaders=new Map,this.requests=new Map,this.requestIds=new Map,this.lastRequestId=0,this.registeredExtensions=new Map,this.status=new N,this.sidebarPanesInternal=[],this.extensionsEnabled=!0,this.registerHandler("addRequestHeaders",this.onAddRequestHeaders.bind(this)),this.registerHandler("createPanel",this.onCreatePanel.bind(this)),this.registerHandler("createSidebarPane",this.onCreateSidebarPane.bind(this)),this.registerHandler("createToolbarButton",this.onCreateToolbarButton.bind(this)),this.registerHandler("evaluateOnInspectedPage",this.onEvaluateOnInspectedPage.bind(this)),this.registerHandler("_forwardKeyboardEvent",this.onForwardKeyboardEvent.bind(this)),this.registerHandler("getHAR",this.onGetHAR.bind(this)),this.registerHandler("getPageResources",this.onGetPageResources.bind(this)),this.registerHandler("getRequestContent",this.onGetRequestContent.bind(this)),this.registerHandler("getResourceContent",this.onGetResourceContent.bind(this)),this.registerHandler("Reload",this.onReload.bind(this)),this.registerHandler("setOpenResourceHandler",this.onSetOpenResourceHandler.bind(this)),this.registerHandler("setThemeChangeHandler",this.onSetThemeChangeHandler.bind(this)),this.registerHandler("setResourceContent",this.onSetResourceContent.bind(this)),this.registerHandler("attachSourceMapToResource",this.onAttachSourceMapToResource.bind(this)),this.registerHandler("setSidebarHeight",this.onSetSidebarHeight.bind(this)),this.registerHandler("setSidebarContent",this.onSetSidebarContent.bind(this)),this.registerHandler("setSidebarPage",this.onSetSidebarPage.bind(this)),this.registerHandler("showPanel",this.onShowPanel.bind(this)),this.registerHandler("subscribe",this.onSubscribe.bind(this)),this.registerHandler("openResource",this.onOpenResource.bind(this)),this.registerHandler("unsubscribe",this.onUnsubscribe.bind(this)),this.registerHandler("updateButton",this.onUpdateButton.bind(this)),this.registerHandler("registerLanguageExtensionPlugin",this.registerLanguageExtensionEndpoint.bind(this)),this.registerHandler("getWasmLinearMemory",this.onGetWasmLinearMemory.bind(this)),this.registerHandler("getWasmGlobal",this.onGetWasmGlobal.bind(this)),this.registerHandler("getWasmLocal",this.onGetWasmLocal.bind(this)),this.registerHandler("getWasmOp",this.onGetWasmOp.bind(this)),this.registerHandler("registerRecorderExtensionPlugin",this.registerRecorderExtensionEndpoint.bind(this)),this.registerHandler("reportResourceLoad",this.onReportResourceLoad.bind(this)),this.registerHandler("setFunctionRangesForScript",this.onSetFunctionRangesForScript.bind(this)),this.registerHandler("createRecorderView",this.onCreateRecorderView.bind(this)),this.registerHandler("showRecorderView",this.onShowRecorderView.bind(this)),this.registerHandler("showNetworkPanel",this.onShowNetworkPanel.bind(this)),window.addEventListener("message",this.onWindowMessage,!1);const t=window.DevToolsAPI?.getInspectedTabId?.();t&&this.setInspectedTabId({data:t}),e.InspectorFrontendHost.InspectorFrontendHostInstance.events.addEventListener(e.InspectorFrontendHostAPI.Events.SetInspectedTabId,this.setInspectedTabId,this),this.initExtensions(),b.ThemeSupport.instance().addEventListener(b.ThemeChangeEvent.eventName,this.#c)}get isEnabledForTest(){return this.extensionsEnabled}dispose(){b.ThemeSupport.instance().removeEventListener(b.ThemeChangeEvent.eventName,this.#c),o.TargetManager.TargetManager.instance().removeEventListener("InspectedURLChanged",this.inspectedURLChanged,this),e.InspectorFrontendHost.InspectorFrontendHostInstance.events.removeEventListener(e.InspectorFrontendHostAPI.Events.SetInspectedTabId,this.setInspectedTabId,this),window.removeEventListener("message",this.onWindowMessage,!1)}#c=()=>{const e=b.ThemeSupport.instance().themeName();for(const t of this.themeChangeHandlers.values())t.postMessage({command:"host-theme-change",themeName:e})};static instance(e={forceNew:null}){const{forceNew:t}=e;return k&&!t||(k?.dispose(),k=new L.ExtensionServer),k}initializeExtensions(){null!==this.inspectedTabId&&e.InspectorFrontendHost.InspectorFrontendHostInstance.setAddExtensionCallback(this.addExtension.bind(this))}hasExtensions(){return Boolean(this.registeredExtensions.size)}notifySearchAction(e,t,s){this.postNotification("panel-search-"+e,[t,s])}notifyViewShown(e,t){this.postNotification("view-shown-"+e,[t])}notifyViewHidden(e){this.postNotification("view-hidden,"+e,[])}notifyButtonClicked(e){this.postNotification("button-clicked-"+e,[])}profilingStarted(){this.postNotification("profiling-started-",[])}profilingStopped(){this.postNotification("profiling-stopped-",[])}registerLanguageExtensionEndpoint(e,t){if("registerLanguageExtensionPlugin"!==e.command)return this.status.E_BADARG("command","expected registerLanguageExtensionPlugin");const{pluginManager:s}=l.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance(),{pluginName:n,port:i,supportedScriptTypes:{language:r,symbol_types:o}}=e,c=Array.isArray(o)&&o.every(e=>"string"==typeof e)?o:[],d=this.getExtensionOrigin(t),u=this.registeredExtensions.get(d);if(!u)throw new Error("Received a message from an unregistered extension");const h=new a.LanguageExtensionEndpoint.LanguageExtensionEndpoint(u.allowFileAccess,d,n,{language:r,symbol_types:c},i);return s.addPlugin(h),this.status.OK()}async loadWasmValue(e,t,s,n){const{pluginManager:i}=l.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance(),r=i.callFrameForStopId(n);if(!r)return this.status.E_BADARG("stopId","Unknown stop id");const o=await r.debuggerModel.agent.invoke_evaluateOnCallFrame({callFrameId:r.id,expression:s,silent:!0,returnByValue:!e,generatePreview:e,throwOnSideEffect:!0});return o.exceptionDetails||o.getError()?this.status.E_FAILED("Failed"):t(o.result)}async onGetWasmLinearMemory(e){return"getWasmLinearMemory"!==e.command?this.status.E_BADARG("command","expected getWasmLinearMemory"):await this.loadWasmValue(!1,e=>e.value,`[].slice.call(new Uint8Array(memories[0].buffer, ${Number(e.offset)}, ${Number(e.length)}))`,e.stopId)}convertWasmValue(e,t){return s=>{if("undefined"===s.type)return;if("object"!==s.type||"wasmvalue"!==s.subtype)return this.status.E_FAILED("Bad object type");const n=s?.description,i=s.preview?.properties?.find(e=>"value"===e.name)?.value??"";switch(n){case"i32":case"f32":case"f64":return{type:n,value:Number(i)};case"i64":return{type:n,value:BigInt(i.replace(/n$/,""))};case"v128":return{type:n,value:i};default:return{type:"reftype",valueClass:e,index:t}}}}async onGetWasmGlobal(e){if("getWasmGlobal"!==e.command)return this.status.E_BADARG("command","expected getWasmGlobal");const t=Number(e.global);return await this.loadWasmValue(!0,this.convertWasmValue("global",t),`globals[${t}]`,e.stopId)??this.status.E_BADARG("global",`No global with index ${t}`)}async onGetWasmLocal(e){if("getWasmLocal"!==e.command)return this.status.E_BADARG("command","expected getWasmLocal");const t=Number(e.local);return await this.loadWasmValue(!0,this.convertWasmValue("local",t),`locals[${t}]`,e.stopId)??this.status.E_BADARG("local",`No local with index ${t}`)}async onGetWasmOp(e){if("getWasmOp"!==e.command)return this.status.E_BADARG("command","expected getWasmOp");const t=Number(e.op);return await this.loadWasmValue(!0,this.convertWasmValue("operand",t),`stack[${t}]`,e.stopId)??this.status.E_BADARG("op",`No operand with index ${t}`)}registerRecorderExtensionEndpoint(e,t){if("registerRecorderExtensionPlugin"!==e.command)return this.status.E_BADARG("command","expected registerRecorderExtensionPlugin");const{pluginName:s,mediaType:n,port:i,capabilities:r}=e;return a.RecorderPluginManager.RecorderPluginManager.instance().addPlugin(new a.RecorderExtensionEndpoint.RecorderExtensionEndpoint(s,i,r,n)),this.status.OK()}onReportResourceLoad(e){if("reportResourceLoad"!==e.command)return this.status.E_BADARG("command","expected reportResourceLoad");const{resourceUrl:t,extensionId:s,status:n}=e,i={url:t,initiator:{target:null,frameId:null,initiatorUrl:s,extensionId:s},errorMessage:n.errorMessage,success:n.success??null,size:n.size??null,duration:null};return o.PageResourceLoader.PageResourceLoader.instance().resourceLoadedThroughExtension(i),this.status.OK()}onSetFunctionRangesForScript(e,t){if("setFunctionRangesForScript"!==e.command)return this.status.E_BADARG("command","expected setFunctionRangesForScript");const{scriptUrl:s,ranges:n}=e;if(!s||!n?.length)return this.status.E_BADARG("command","expected valid scriptUrl and non-empty NamedFunctionRanges");const i=this.lookupAllowedUISourceCode(s,t);if("error"in i)return i.error;const{uiSourceCode:r}=i;if(!r.contentType().isScript()||!r.contentType().isFromSourceMap())return this.status.E_BADARG("command",`expected a source map script resource for url: ${s}`);try{l.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().setFunctionRanges(r,n)}catch(e){return this.status.E_FAILED(e)}return this.status.OK()}onShowRecorderView(e){if("showRecorderView"!==e.command)return this.status.E_BADARG("command","expected showRecorderView");a.RecorderPluginManager.RecorderPluginManager.instance().showView(e.id)}onShowNetworkPanel(e){return"showNetworkPanel"!==e.command?this.status.E_BADARG("command","expected showNetworkPanel"):(c.Revealer.reveal(new B(e.filter)),this.status.OK())}onCreateRecorderView(e,t){if("createRecorderView"!==e.command)return this.status.E_BADARG("command","expected createRecorderView");const s=e.id;if(this.clientObjects.has(s))return this.status.E_EXISTS(s);const n=L.ExtensionServer.expandResourcePath(this.getExtensionOrigin(t),e.pagePath);if(void 0===n)return this.status.E_BADARG("pagePath","Resources paths cannot point to non-extension resources");return a.RecorderPluginManager.RecorderPluginManager.instance().registerView({id:s,pagePath:n,title:e.title,onShown:()=>this.notifyViewShown(s),onHidden:()=>this.notifyViewHidden(s)}),this.status.OK()}inspectedURLChanged(e){if(!L.ExtensionServer.canInspectURL(e.data.inspectedURL()))return void this.disableExtensions();if(e.data!==o.TargetManager.TargetManager.instance().primaryPageTarget())return;this.requests=new Map,this.enableExtensions();const t=e.data.inspectedURL();this.postNotification("inspected-url-changed",[t]);this.#a.splice(0).forEach(e=>this.addExtension(e))}hasSubscribers(e){return this.subscribers.has(e)}postNotification(e,t,s){if(!this.extensionsEnabled)return;const n=this.subscribers.get(e);if(!n)return;const i={command:"notify-"+e,arguments:t};for(const e of n)if(this.extensionEnabled(e)){if(s){const t=U.get(e),n=t&&this.registeredExtensions.get(t);if(!n||!s(n))continue}e.postMessage(i)}}onSubscribe(e,t){if("subscribe"!==e.command)return this.status.E_BADARG("command","expected subscribe");const s=this.subscribers.get(e.type);if(s)s.add(t);else{this.subscribers.set(e.type,new Set([t]));const s=this.subscriptionStartHandlers.get(e.type);s&&s()}}onUnsubscribe(e,t){if("unsubscribe"!==e.command)return this.status.E_BADARG("command","expected unsubscribe");const s=this.subscribers.get(e.type);if(s&&(s.delete(t),!s.size)){this.subscribers.delete(e.type);const t=this.subscriptionStopHandlers.get(e.type);t&&t()}}onAddRequestHeaders(e){if("addRequestHeaders"!==e.command)return this.status.E_BADARG("command","expected addRequestHeaders");const t=e.extensionId;if("string"!=typeof t)return this.status.E_BADARGTYPE("extensionId",typeof t,"string");let s=this.extraHeaders.get(t);s||(s=new Map,this.extraHeaders.set(t,s));for(const t in e.headers)s.set(t,e.headers[t]);const n={};for(const e of this.extraHeaders.values())for(const[t,s]of e)"__proto__"!==t&&"string"==typeof s&&(n[t]=s);o.NetworkManager.MultitargetNetworkManager.instance().setExtraHTTPHeaders(n)}getExtensionOrigin(e){const t=U.get(e);if(!t)throw new Error("Received a message from an unregistered extension");return t}onCreatePanel(e,s){if("createPanel"!==e.command)return this.status.E_BADARG("command","expected createPanel");const i=e.id;if(this.clientObjects.has(i)||n.InspectorView.InspectorView.instance().hasPanel(i))return this.status.E_EXISTS(i);const r=L.ExtensionServer.expandResourcePath(this.getExtensionOrigin(s),e.page);if(void 0===r)return this.status.E_BADARG("page","Resources paths cannot point to non-extension resources");let o=this.getExtensionOrigin(s)+e.title;o=o.replace(/\s|:\d+/g,"");const a=new F(o,t.i18n.lockedString(e.title),new C(this,o,i,r));return this.clientObjects.set(i,a),n.InspectorView.InspectorView.instance().addPanel(a),this.status.OK()}onShowPanel(e){if("showPanel"!==e.command)return this.status.E_BADARG("command","expected showPanel");let t=e.id;const s=this.clientObjects.get(e.id);s&&s instanceof F&&(t=s.viewId()),n.InspectorView.InspectorView.instance().showPanel(t)}onCreateToolbarButton(e,t){if("createToolbarButton"!==e.command)return this.status.E_BADARG("command","expected createToolbarButton");const s=this.clientObjects.get(e.panel);if(!(s&&s instanceof F))return this.status.E_NOTFOUND(e.panel);const n=L.ExtensionServer.expandResourcePath(this.getExtensionOrigin(t),e.icon);if(void 0===n)return this.status.E_BADARG("icon","Resources paths cannot point to non-extension resources");const i=new O(this,e.id,n,e.tooltip,e.disabled);return this.clientObjects.set(e.id,i),s.widget().then(function(e){e.addToolbarItem(i.toolbarButton())}),this.status.OK()}onUpdateButton(e,t){if("updateButton"!==e.command)return this.status.E_BADARG("command","expected updateButton");const s=this.clientObjects.get(e.id);if(!(s&&s instanceof O))return this.status.E_NOTFOUND(e.id);const n=e.icon&&L.ExtensionServer.expandResourcePath(this.getExtensionOrigin(t),e.icon);return e.icon&&void 0===n?this.status.E_BADARG("icon","Resources paths cannot point to non-extension resources"):(s.update(n,e.tooltip,e.disabled),this.status.OK())}onCreateSidebarPane(e){if("createSidebarPane"!==e.command)return this.status.E_BADARG("command","expected createSidebarPane");const s=e.id,n=new P(this,e.panel,t.i18n.lockedString(e.title),s);return this.sidebarPanesInternal.push(n),this.clientObjects.set(s,n),this.dispatchEventToListeners("SidebarPaneAdded",n),this.status.OK()}sidebarPanes(){return this.sidebarPanesInternal}onSetSidebarHeight(e){if("setSidebarHeight"!==e.command)return this.status.E_BADARG("command","expected setSidebarHeight");const t=this.clientObjects.get(e.id);return t&&t instanceof P?(t.setHeight(e.height),this.status.OK()):this.status.E_NOTFOUND(e.id)}onSetSidebarContent(e,t){if("setSidebarContent"!==e.command)return this.status.E_BADARG("command","expected setSidebarContent");const{requestId:s,id:n,rootTitle:i,expression:r,evaluateOptions:o,evaluateOnPage:a}=e,c=this.clientObjects.get(n);if(!(c&&c instanceof P))return this.status.E_NOTFOUND(e.id);function d(e){const n=e?this.status.E_FAILED(e):this.status.OK();this.dispatchCallback(s,t,n)}a?c.setExpression(r,i,o,this.getExtensionOrigin(t),d.bind(this)):c.setObject(e.expression,e.rootTitle,d.bind(this))}onSetSidebarPage(e,t){if("setSidebarPage"!==e.command)return this.status.E_BADARG("command","expected setSidebarPage");const s=this.clientObjects.get(e.id);if(!(s&&s instanceof P))return this.status.E_NOTFOUND(e.id);const n=L.ExtensionServer.expandResourcePath(this.getExtensionOrigin(t),e.page);if(void 0===n)return this.status.E_BADARG("page","Resources paths cannot point to non-extension resources");s.setPage(n)}onOpenResource(e){if("openResource"!==e.command)return this.status.E_BADARG("command","expected openResource");const t=g.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(e.url);if(t)return c.Revealer.reveal(t.uiLocation(e.lineNumber,e.columnNumber)),this.status.OK();const s=l.ResourceUtils.resourceForURL(e.url);if(s)return c.Revealer.reveal(s),this.status.OK();const n=h.NetworkLog.NetworkLog.instance().requestForURL(e.url);return n?(c.Revealer.reveal(n),this.status.OK()):this.status.E_NOTFOUND(e.url)}onSetOpenResourceHandler(e,t){if("setOpenResourceHandler"!==e.command)return this.status.E_BADARG("command","expected setOpenResourceHandler");const s=this.registeredExtensions.get(this.getExtensionOrigin(t));if(!s)throw new Error("Received a message from an unregistered extension");e.urlScheme&&(s.openResourceScheme=e.urlScheme);const n=this.getExtensionOrigin(t),{name:i}=s,r={title:i,origin:n,scheme:e.urlScheme,handler:this.handleOpenURL.bind(this,t),shouldHandleOpenResource:(e,t)=>m.Linkifier.Linkifier.shouldHandleOpenResource(s.openResourceScheme,e,t)};e.handlerPresent?m.Linkifier.Linkifier.registerLinkHandler(r):m.Linkifier.Linkifier.unregisterLinkHandler(r)}onSetThemeChangeHandler(e,t){if("setThemeChangeHandler"!==e.command)return this.status.E_BADARG("command","expected setThemeChangeHandler");const s=this.getExtensionOrigin(t);if(!this.registeredExtensions.get(s))throw new Error("Received a message from an unregistered extension");e.handlerPresent?this.themeChangeHandlers.set(s,t):this.themeChangeHandlers.delete(s)}handleOpenURL(e,t,s,n){let i,r;if("string"!=typeof t)i=this.makeResource(t),r=this.extensionAllowedOnContentProvider(t,e);else{const s=t;i={url:s,type:c.ResourceType.resourceTypes.Other.name()},r=this.extensionAllowedOnURL(s,e)}r&&e.postMessage({command:"open-resource",resource:i,lineNumber:s?s+1:void 0,columnNumber:n?n+1:void 0})}extensionAllowedOnURL(e,t){const s=U.get(t),n=s&&this.registeredExtensions.get(s);return Boolean(n?.isAllowedOnTarget(e))}extensionAllowedOnContentProvider(e,t){if(!(e instanceof g.UISourceCode.UISourceCode))return this.extensionAllowedOnURL(e.contentURL(),t);if(e.contentType()!==c.ResourceType.resourceTypes.Script)return this.extensionAllowedOnURL(e.contentURL(),t);const s=l.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().scriptsForUISourceCode(e);return 0===s.length?this.extensionAllowedOnURL(e.contentURL(),t):s.every(e=>e.hasSourceURL?this.extensionAllowedOnTarget(e.target(),t):this.extensionAllowedOnURL(e.contentURL(),t))}lookupAllowedUISourceCode(e,t){const s=g.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(e);return s||this.extensionAllowedOnURL(e,t)?s?this.extensionAllowedOnContentProvider(s,t)?{uiSourceCode:s}:{error:this.status.E_FAILED("Permission denied")}:{error:this.status.E_NOTFOUND(e)}:{error:this.status.E_FAILED("Permission denied")}}extensionAllowedOnTarget(e,t){return this.extensionAllowedOnURL(e.inspectedURL(),t)}onReload(e,t){if("Reload"!==e.command)return this.status.E_BADARG("command","expected Reload");const s=e.options||{};let n;o.NetworkManager.MultitargetNetworkManager.instance().setUserAgentOverride("string"==typeof s.userAgent?s.userAgent:"",null),s.injectedScript&&(n="(function(){"+s.injectedScript+"})()");const i=o.TargetManager.TargetManager.instance().primaryPageTarget();if(!i)return this.status.OK();const r=i.model(o.ResourceTreeModel.ResourceTreeModel);return this.extensionAllowedOnTarget(i,t)?(r?.reloadPage(Boolean(s.ignoreCache),n),this.status.OK()):this.status.E_FAILED("Permission denied")}onEvaluateOnInspectedPage(e,t){if("evaluateOnInspectedPage"!==e.command)return this.status.E_BADARG("command","expected evaluateOnInspectedPage");const{requestId:s,expression:n,evaluateOptions:i}=e;return this.evaluate(n,!0,!0,i,this.getExtensionOrigin(t),function(e,n,i){let r;r=e||!n?this.status.E_PROTOCOLERROR(e?.toString()):i?{isException:!0,value:n.description}:{value:n.value},this.dispatchCallback(s,t,r)}.bind(this))}async onGetHAR(e,t){if("getHAR"!==e.command)return this.status.E_BADARG("command","expected getHAR");const s=h.NetworkLog.NetworkLog.instance().requests().filter(e=>this.extensionAllowedOnURL(e.url(),t)),n=await u.Log.Log.build(s,{sanitize:!1});for(let e=0;e<n.entries.length;++e)n.entries[e]._requestId=this.requestId(s[e]);return n}makeResource(e){let t;return e instanceof g.UISourceCode.UISourceCode&&(t=l.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().scriptsForUISourceCode(e).find(e=>Boolean(e.buildId))?.buildId??void 0),{url:e.contentURL(),type:e.contentType().name(),buildId:t}}onGetPageResources(e,t){const s=new Map;function n(e){return!s.has(e.contentURL())&&this.extensionAllowedOnContentProvider(e,t)&&s.set(e.contentURL(),this.makeResource(e)),!1}let i=g.Workspace.WorkspaceImpl.instance().uiSourceCodesForProjectType(g.Workspace.projectTypes.Network);i=i.concat(g.Workspace.WorkspaceImpl.instance().uiSourceCodesForProjectType(g.Workspace.projectTypes.ContentScripts)),i.forEach(n.bind(this));for(const e of o.TargetManager.TargetManager.instance().models(o.ResourceTreeModel.ResourceTreeModel))this.extensionAllowedOnTarget(e.target(),t)&&e.forAllResources(n.bind(this));return[...s.values()]}async getResourceContent(e,t,s){if(!this.extensionAllowedOnContentProvider(e,s))return void this.dispatchCallback(t.requestId,s,this.status.E_FAILED("Permission denied"));const n=await e.requestContentData();if(p.ContentData.ContentData.isError(n))return void this.dispatchCallback(t.requestId,s,{encoding:"",content:null});const i=n.isTextContent?"":"base64",r=n.isTextContent?n.text:n.base64;this.dispatchCallback(t.requestId,s,{encoding:i,content:r})}onGetRequestContent(e,t){if("getRequestContent"!==e.command)return this.status.E_BADARG("command","expected getRequestContent");const s=this.requestById(e.id);if(!s)return this.status.E_NOTFOUND(e.id);this.getResourceContent(s,e,t)}onGetResourceContent(e,t){if("getResourceContent"!==e.command)return this.status.E_BADARG("command","expected getResourceContent");const s=e.url,n=g.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(s)||l.ResourceUtils.resourceForURL(s);if(!n)return this.status.E_NOTFOUND(s);this.getResourceContent(n,e,t)}onAttachSourceMapToResource(e,t){if("attachSourceMapToResource"!==e.command)return this.status.E_BADARG("command","expected getResourceContent");if(!e.sourceMapURL)return this.status.E_FAILED("Expected a source map URL but got null");const s=this.lookupAllowedUISourceCode(e.contentUrl,t);if("error"in s)return s.error;const n=l.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance(),i=n.scriptsForUISourceCode(s.uiSourceCode);if(i.length>0)for(const t of i){const i=n.scriptFile(s.uiSourceCode,t.debuggerModel);i?.addSourceMapURL(e.sourceMapURL)}return this.status.OK()}onSetResourceContent(e,t){if("setResourceContent"!==e.command)return this.status.E_BADARG("command","expected setResourceContent");const{url:s,requestId:n,content:i,commit:r}=e;const a=this.lookupAllowedUISourceCode(s,t);if("error"in a)return a.error;const{uiSourceCode:c}=a;if(!c.contentType().isDocumentOrScriptOrStyleSheet()){return o.ResourceTreeModel.ResourceTreeModel.resourceForURL(s)?this.status.E_NOTSUPPORTED("Resource is not editable"):this.status.E_NOTFOUND(s)}c.setWorkingCopy(i),r&&c.commitWorkingCopy(),function(e){const s=e?this.status.E_FAILED(e):this.status.OK();this.dispatchCallback(n,t,s)}.call(this,null)}requestId(e){const t=this.requestIds.get(e);if(void 0===t){const t=++this.lastRequestId;return this.requestIds.set(e,t),this.requests.set(t,e),t}return t}requestById(e){return this.requests.get(e)}onForwardKeyboardEvent(e){if("_forwardKeyboardEvent"!==e.command)return this.status.E_BADARG("command","expected _forwardKeyboardEvent");e.entries.forEach(function(e){const t=new window.KeyboardEvent(e.eventType,{key:e.key,code:e.code,keyCode:e.keyCode,location:e.location,ctrlKey:e.ctrlKey,altKey:e.altKey,shiftKey:e.shiftKey,metaKey:e.metaKey});t.__keyCode=function(e){let t=e.keyCode;t||e.key===r.KeyboardUtilities.ESCAPE_KEY&&(t=27);return t||0}(e),document.dispatchEvent(t)})}dispatchCallback(e,t,s){e&&t.postMessage({command:"callback",requestId:e,result:s})}initExtensions(){this.registerAutosubscriptionHandler("resource-added",g.Workspace.WorkspaceImpl.instance(),g.Workspace.Events.UISourceCodeAdded,this.notifyResourceAdded),this.registerAutosubscriptionTargetManagerHandler("network-request-finished",o.NetworkManager.NetworkManager,o.NetworkManager.Events.RequestFinished,this.notifyRequestFinished),this.registerSubscriptionHandler("panel-objectSelected-elements",function(){n.Context.Context.instance().addFlavorChangeListener(o.DOMModel.DOMNode,this.notifyElementsSelectionChanged,this)}.bind(this),function(){n.Context.Context.instance().removeFlavorChangeListener(o.DOMModel.DOMNode,this.notifyElementsSelectionChanged,this)}.bind(this)),this.registerResourceContentCommittedHandler(this.notifyUISourceCodeContentCommitted),o.TargetManager.TargetManager.instance().addEventListener("InspectedURLChanged",this.inspectedURLChanged,this)}notifyResourceAdded(e){const t=e.data;this.postNotification("resource-added",[this.makeResource(t)],e=>e.isAllowedOnTarget(t.url()))}notifyUISourceCodeContentCommitted(e){const{uiSourceCode:t,content:s}=e.data;this.postNotification("resource-content-committed",[this.makeResource(t),s],e=>e.isAllowedOnTarget(t.url()))}async notifyRequestFinished(e){const t=e.data,s=await u.Log.Entry.build(t,{sanitize:!1});this.postNotification("network-request-finished",[this.requestId(t),s],e=>e.isAllowedOnTarget(s.request.url))}notifyElementsSelectionChanged(){this.postNotification("panel-objectSelected-elements",[])}sourceSelectionChanged(e,t){this.postNotification("panel-objectSelected-sources",[{startLine:t.startLine,startColumn:t.startColumn,endLine:t.endLine,endColumn:t.endColumn,url:e}],t=>t.isAllowedOnTarget(e))}setInspectedTabId(e){const t=this.inspectedTabId;this.inspectedTabId=e.data,null===t&&this.initializeExtensions()}addExtensionFrame({startPage:e,name:t}){const s=document.createElement("iframe");s.src=e,s.dataset.devtoolsExtension=t,s.style.display="none",document.body.appendChild(s)}addExtension(t){const s=t.startPage,i=o.TargetManager.TargetManager.instance().primaryPageTarget()?.inspectedURL()??"";if(""===i)return void this.#a.push(t);if(L.ExtensionServer.canInspectURL(i)||this.disableExtensions(),!this.extensionsEnabled)return void this.#a.push(t);const r=M.create(t.hostsPolicy);if(r){try{const o=new URL(s).origin,a=t.name||`Extension ${o}`,c=new _(a,r,Boolean(t.allowFileAccess));if(!c.isAllowedOnTarget(i))return void this.#a.push(t);if(!this.registeredExtensions.get(o)){const s=self.buildExtensionAPIInjectedScript(t,this.inspectedTabId,b.ThemeSupport.instance().themeName(),n.ShortcutRegistry.ShortcutRegistry.instance().globalShortcutKeys(),L.ExtensionServer.instance().extensionAPITestHook);e.InspectorFrontendHost.InspectorFrontendHostInstance.setInjectedScriptForOrigin(o,s),this.registeredExtensions.set(o,c)}this.addExtensionFrame(t)}catch(e){return console.error("Failed to initialize extension "+s+":"+e),!1}return!0}}registerExtension(e,t){this.registeredExtensions.has(e)?(U.set(t,e),t.addEventListener("message",this.onmessage.bind(this),!1),t.start()):e!==window.location.origin&&console.error("Ignoring unauthorized client request from "+e)}onWindowMessage=e=>{"registerExtension"===e.data&&this.registerExtension(e.origin,e.ports[0])};extensionEnabled(e){if(!this.extensionsEnabled)return!1;const t=U.get(e);if(!t)return!1;const s=this.registeredExtensions.get(t);return!!s&&s.isAllowedOnTarget()}async onmessage(e){const t=e.data;let s;const n=e.currentTarget,i=this.handlers.get(t.command);s=i?this.extensionEnabled(n)?await i(t,e.target):this.status.E_FAILED("Permission denied"):this.status.E_NOTSUPPORTED(t.command),s&&t.requestId&&this.dispatchCallback(t.requestId,e.target,s)}registerHandler(e,t){console.assert(Boolean(e)),this.handlers.set(e,t)}registerSubscriptionHandler(e,t,s){this.subscriptionStartHandlers.set(e,t),this.subscriptionStopHandlers.set(e,s)}registerAutosubscriptionHandler(e,t,s,n){this.registerSubscriptionHandler(e,()=>t.addEventListener(s,n,this),()=>t.removeEventListener(s,n,this))}registerAutosubscriptionTargetManagerHandler(e,t,s,n){this.registerSubscriptionHandler(e,()=>o.TargetManager.TargetManager.instance().addModelListener(t,s,n,this),()=>o.TargetManager.TargetManager.instance().removeModelListener(t,s,n,this))}registerResourceContentCommittedHandler(e){this.registerSubscriptionHandler("resource-content-committed",function(){g.Workspace.WorkspaceImpl.instance().addEventListener(g.Workspace.Events.WorkingCopyCommittedByUser,e,this),g.Workspace.WorkspaceImpl.instance().setHasResourceContentTrackingExtensions(!0)}.bind(this),function(){g.Workspace.WorkspaceImpl.instance().setHasResourceContentTrackingExtensions(!1),g.Workspace.WorkspaceImpl.instance().removeEventListener(g.Workspace.Events.WorkingCopyCommittedByUser,e,this)}.bind(this))}static expandResourcePath(e,t){const s=new URL(e).origin,n=new URL(c.ParsedURL.normalizePath(t),s);if(n.origin===s)return n.href}evaluate(e,t,s,n,i,r){let a,c;if((n=n||{}).frameURL)c=function(e){let t=null;return o.ResourceTreeModel.ResourceTreeModel.frames().some(function(s){return t=s.url===e?s:null,t}),t}(n.frameURL);else{const e=o.TargetManager.TargetManager.instance().primaryPageTarget(),t=e?.model(o.ResourceTreeModel.ResourceTreeModel);c=t?.mainFrame}if(!c)return n.frameURL?console.warn("evaluate: there is no frame with URL "+n.frameURL):console.warn("evaluate: the main frame is not yet available"),this.status.E_NOTFOUND(n.frameURL||"<top>");const d=this.registeredExtensions.get(i);if(!d?.isAllowedOnTarget(c.url))return this.status.E_FAILED("Permission denied");let l;n.useContentScriptContext?l=i:n.scriptExecutionContext&&(l=n.scriptExecutionContext);const u=c.resourceTreeModel().target().model(o.RuntimeModel.RuntimeModel),h=u?u.executionContexts():[];if(l){for(let e=0;e<h.length;++e){const t=h[e];t.frameId!==c.id||t.origin!==l||t.isDefault||(a=t)}if(!a)return console.warn("The JavaScript context "+l+" was not found in the frame "+c.url),this.status.E_NOTFOUND(l)}else{for(let e=0;e<h.length;++e){const t=h[e];t.frameId===c.id&&t.isDefault&&(a=t)}if(!a)return this.status.E_FAILED(c.url+" has no execution context")}if(!d?.isAllowedOnTarget(a.origin))return this.status.E_FAILED("Permission denied");a.evaluate({expression:e,objectGroup:"extension",includeCommandLineAPI:t,silent:!0,returnByValue:s,generatePreview:!1},!1,!1).then(function(e){if("error"in e)return void r(e.error,null,!1);r(null,e.object||null,Boolean(e.exceptionDetails))})}static canInspectURL(e){let t;try{t=new URL(e)}catch{return!1}return!!H.includes(t.protocol)&&(!(window.DevToolsAPI?.getOriginsForbiddenForExtensions?.()||[]).includes(t.origin)&&!this.isUrlFromChromeWebStore(t))}static isUrlFromChromeWebStore(e){return!!(e.protocol.startsWith("http")&&e.hostname.match(/^chrome\.google\.com\.?$/)&&e.pathname.startsWith("/webstore"))||!(!e.protocol.startsWith("http")||!e.hostname.match(/^chromewebstore\.google\.com\.?$/))}disableExtensions(){this.extensionsEnabled=!1}enableExtensions(){this.extensionsEnabled=!0}};L.ExtensionServer=D;class F extends n.View.SimpleView{name;panel;constructor(e,t,s){super({title:t,viewId:r.StringUtilities.toKebabCase(t)}),this.name=e,this.panel=s}viewId(){return this.name}widget(){return Promise.resolve(this.panel)}}class N{OK;E_EXISTS;E_BADARG;E_BADARGTYPE;E_NOTFOUND;E_NOTSUPPORTED;E_PROTOCOLERROR;E_FAILED;constructor(){function e(e,t,...s){const n={code:e,description:t,details:s};return"OK"!==e&&(n.isError=!0,console.error("Extension server error: "+r.StringUtilities.sprintf(t,...s))),n}this.OK=e.bind(null,"OK","OK"),this.E_EXISTS=e.bind(null,"E_EXISTS","Object already exists: %s"),this.E_BADARG=e.bind(null,"E_BADARG","Invalid argument %s: %s"),this.E_BADARGTYPE=e.bind(null,"E_BADARGTYPE","Invalid type for argument %s: got %s, expected %s"),this.E_NOTFOUND=e.bind(null,"E_NOTFOUND","Object not found: %s"),this.E_NOTSUPPORTED=e.bind(null,"E_NOTSUPPORTED","Object does not support requested operation: %s"),this.E_PROTOCOLERROR=e.bind(null,"E_PROTOCOLERROR","Inspector protocol error: %s"),this.E_FAILED=e.bind(null,"E_FAILED","Operation failed: %s")}}class W extends D{edge=new V;onCreatePanel(t,s){const i=!c.Settings.Settings.instance().moduleSetting("ms-focus-mode-disabled").get();i&&"createPanel"===t.command&&(t.title=t.title?.startsWith("⚛️ ")?t.title.substring(3):t.title);const r=super.onCreatePanel(t,s);if(i&&"OK"===r.code&&"createPanel"===t.command){let e=this.getExtensionOrigin(s)+t.title;e=e.replace(/\s/g,"");const i=t._icon?.trim()?`${this.getExtensionOrigin(s)}/${t._icon}`:void 0,r=n.ViewManager.ViewManager.instance().view(e);d.FocusModeHelper.appendExtensionToActivityBar(r,i),this.edge.dispatchEventToListeners("PanelAdded")}return j(e.UserMetrics.ExtensionsAction.OnCreatePanel),r}static canInspectURL(t){if(e.InspectorFrontendHost.InspectorFrontendHostInstance.isUrlInspectionDenyListed(t))return!1;let s;try{s=new URL(t)}catch{return!1}return"edge:"!==s.protocol&&"ms-hub:"!==s.protocol&&"webcapture:"!==s.protocol&&("microsoftedge.microsoft.com"!==s.hostname&&super.canInspectURL(t))}notifySearchAction(t,s,n){j(e.UserMetrics.ExtensionsAction.NotifySearchAction),super.notifySearchAction(t,s,n)}notifyButtonClicked(t){j(e.UserMetrics.ExtensionsAction.NotifyButtonClicked),super.notifyButtonClicked(t)}registerLanguageExtensionEndpoint(t,s){return j(e.UserMetrics.ExtensionsAction.RegisterLanguageExtensionEndpoint),super.registerLanguageExtensionEndpoint(t,s)}registerRecorderExtensionEndpoint(t,s){return j(e.UserMetrics.ExtensionsAction.RegisterRecorderExtensionEndpoint),super.registerRecorderExtensionEndpoint(t,s)}onAddRequestHeaders(t){return j(e.UserMetrics.ExtensionsAction.AddRequestHeaders),super.onAddRequestHeaders(t)}onShowPanel(t){return j(e.UserMetrics.ExtensionsAction.ShowPanel),super.onShowPanel(t)}onCreateToolbarButton(t,s){return j(e.UserMetrics.ExtensionsAction.CreateToolbarButton),super.onCreateToolbarButton(t,s)}onUpdateButton(t,s){return j(e.UserMetrics.ExtensionsAction.UpdateButton),super.onUpdateButton(t,s)}onCreateSidebarPane(t){return j(e.UserMetrics.ExtensionsAction.CreateSidebarPane),super.onCreateSidebarPane(t)}onSetSidebarContent(t,s){return j(e.UserMetrics.ExtensionsAction.SetSidebarContent),super.onSetSidebarContent(t,s)}onSetSidebarPage(t,s){return j(e.UserMetrics.ExtensionsAction.SetSidebarPage),super.onSetSidebarPage(t,s)}onOpenResource(t){return j(e.UserMetrics.ExtensionsAction.OpenResource),super.onOpenResource(t)}onSetOpenResourceHandler(t,s){return j(e.UserMetrics.ExtensionsAction.SetOpenResourceHandler),super.onSetOpenResourceHandler(t,s)}onSetThemeChangeHandler(t,s){return j(e.UserMetrics.ExtensionsAction.SetThemeChangeHandler),super.onSetThemeChangeHandler(t,s)}onEvaluateOnInspectedPage(t,s){return j(e.UserMetrics.ExtensionsAction.EvaluateOnInspectedPage),super.onEvaluateOnInspectedPage(t,s)}async onGetHAR(t,s){return j(e.UserMetrics.ExtensionsAction.GetHAR),await super.onGetHAR(t,s)}onGetPageResources(...t){return j(e.UserMetrics.ExtensionsAction.GetPageResources),super.onGetPageResources(...t)}onGetRequestContent(t,s){return j(e.UserMetrics.ExtensionsAction.GetRequestContent),super.onGetRequestContent(t,s)}onGetResourceContent(t,s){return j(e.UserMetrics.ExtensionsAction.GetResourceContent),super.onGetResourceContent(t,s)}onSetResourceContent(t,s){return j(e.UserMetrics.ExtensionsAction.SetResourceContent),super.onSetResourceContent(t,s)}addExtension(t){return j(e.UserMetrics.ExtensionsAction.AddExtension),super.addExtension(t)}registerExtension(t,s){return j(e.UserMetrics.ExtensionsAction.RegisterExtension),super.registerExtension(t,s)}}function j(t){e.userMetrics.recordExtensionsAction(t)}const G=W;L.ExtensionServer=G;class V extends c.ObjectWrapper.ObjectWrapper{async fireCreatePanel(){this.dispatchEventToListeners("PanelAdded")}}var q=Object.freeze({__proto__:null,EdgeExtensionServer:W,EdgeHelper:V,ExtensionServer:G,ExtensionStatus:N,HostsPolicy:M,RevealableNetworkRequestFilter:B,__scope:L});const z={linkedToSourceMapS:"Linked to source map: {PH1}",linkedToS:"Linked to {PH1}"},K=t.i18n.registerUIStrings("panels/common/PersistenceUtils.ts",z),$=t.i18n.getLocalizedString.bind(void 0,K);let X=class e{static tooltipForUISourceCode(e){const t=f.Persistence.PersistenceImpl.instance().binding(e);return t?e===t.network?f.FileSystemWorkspaceBinding.FileSystemWorkspaceBinding.tooltipForUISourceCode(t.fileSystem):t.network.contentType().isFromSourceMap()?$(z.linkedToSourceMapS,{PH1:r.StringUtilities.trimMiddle(t.network.url(),150)}):$(z.linkedToS,{PH1:r.StringUtilities.trimMiddle(t.network.url(),150)}):""}static iconForUISourceCode(t){const s=f.Persistence.PersistenceImpl.instance().binding(t);if(s){if(!c.ParsedURL.schemeIs(s.fileSystem.url(),"file:"))return null;const t=new E.Icon.Icon;return t.name="document",t.classList.add("small"),n.Tooltip.Tooltip.install(t,e.tooltipForUISourceCode(s.network)),f.NetworkPersistenceManager.NetworkPersistenceManager.instance().project()===s.fileSystem.project()?t.classList.add("dot","purple"):t.classList.add("dot","green"),t}if(t.project().type()!==g.Workspace.projectTypes.FileSystem||!c.ParsedURL.schemeIs(t.url(),"file:"))return null;if(f.NetworkPersistenceManager.NetworkPersistenceManager.instance().isActiveHeaderOverrides(t)){const e=new E.Icon.Icon;return e.name="document",e.classList.add("small"),e.classList.add("dot","purple"),e}const i=new E.Icon.Icon;return i.name="document",i.classList.add("small"),n.Tooltip.Tooltip.install(i,e.tooltipForUISourceCode(t)),i}};class Y extends c.ObjectWrapper.ObjectWrapper{constructor(e){super(),e.addEventListener(f.Persistence.Events.BindingCreated,this.bindingChanged,this),e.addEventListener(f.Persistence.Events.BindingRemoved,this.bindingChanged,this)}bindingChanged(e){const t=e.data;this.dispatchEventToListeners("LinkIconChanged",t.network)}linkIcon(e){return X.iconForUISourceCode(e)}}var J=Object.freeze({__proto__:null,LinkDecorator:Y,PersistenceUtils:X});const{html:Q}=i,Z={thingsToConsider:"Things to consider",learnMore:"Learn more",cancel:"Cancel",allow:"Allow",gotIt:"Got it"},ee=t.i18n.registerUIStrings("panels/common/common.ts",Z),te=t.i18n.getLocalizedString.bind(void 0,ee);class se{static show({header:e,reminderItems:t,onLearnMoreClick:s,ariaLabel:r,learnMoreButtonText:o}){const a=new n.Dialog.Dialog;r&&a.setAriaLabel(r);const c=Promise.withResolvers();return i.render(Q`
<div class="fre-disclaimer">
<style>
${x}
</style>
<header>
<div class="header-icon-container">
<devtools-icon name=${e.iconName}></devtools-icon>
</div>
<h2 tabindex="-1">
${e.text}
</h2>
</header>
<main class="reminder-container">
<h3>${te(Z.thingsToConsider)}</h3>
${t.map(e=>Q`
<div class="reminder-item">
<devtools-icon class="reminder-icon" name=${e.iconName}></devtools-icon>
<span>${e.content}</span>
</div>
`)}
</main>
<footer>
<devtools-button
@click=${s}
.jslogContext=${"fre-disclaimer.learn-more"}
.variant=${"outlined"}>
${o??te(Z.learnMore)}
</devtools-button>
<div class="right-buttons">
<devtools-button
@click=${()=>{c.resolve(!1),a.hide()}}
.jslogContext=${"fre-disclaimer.cancel"}
.variant=${"tonal"}>
${te(Z.cancel)}
</devtools-button>
<devtools-button
@click=${()=>{c.resolve(!0),a.hide()}}
.jslogContext=${"fre-disclaimer.continue"}
.variant=${"primary"}>
${te(Z.gotIt)}
</devtools-button>
</div>
</footer>
</div>`,a.contentElement),a.setOutsideClickCallback(e=>{e.consume(!0),a.hide(),c.resolve(!1)}),a.setOnHideCallback(()=>{c.resolve(!1)}),a.setSizeBehavior("MeasureContent"),a.setDimmed(!0),a.show(),c.promise}constructor(){}}class ne{static async show(t){const i=new n.Dialog.Dialog(t.jslogContext.dialog);i.setMaxContentSize(new s.Size(504,340)),i.setSizeBehavior("SetExactWidthMaxHeight"),i.setDimmed(!0);const r=n.UIUtils.createShadowRootWithCoreStyles(i.contentElement,{cssFile:x}).createChild("div","type-to-allow-dialog"),o=await new Promise(s=>{const o=r.createChild("div","header");o.createChild("div","title").textContent=t.header;const a=o.createChild("dt-close-button","dialog-close-button");a.setTabbable(!0),self.onInvokeElement(a,e=>{i.hide(),e.consume(!0),s(!1)}),a.setSize("SMALL"),r.createChild("div","message").textContent=t.message;const c=n.UIUtils.createInput("text-input","text",t.jslogContext.input);c.placeholder=t.inputPlaceholder,r.appendChild(c);const d=r.createChild("div","button"),l=n.UIUtils.createTextButton(te(Z.cancel),()=>s(!1),{jslogContext:"cancel"}),u=n.UIUtils.createTextButton(te(Z.allow),()=>{s(c.value===t.typePhrase)},{jslogContext:"confirm",variant:"primary"});u.disabled=!0,d.appendChild(u),d.appendChild(l),c.addEventListener("input",()=>{u.disabled=!Boolean(c.value)},!1),c.addEventListener("paste",e=>e.preventDefault()),c.addEventListener("drop",e=>e.preventDefault()),i.setOutsideClickCallback(e=>{e.consume(),s(!1)}),i.show(),e.userMetrics.actionTaken(e.UserMetrics.Action.SelfXssWarningDialogShown)});return i.hide(),o}}export{T as ExtensionPanel,q as ExtensionServer,I as ExtensionView,se as FreDialog,J as PersistenceUtils,ne as TypeToAllowDialog};
//# sourceMappingURL=common.js.map