{"version":3,"file":"WebViewExecutionService.cjs","sourceRoot":"","sources":["../../../src/services/webview/WebViewExecutionService.ts"],"names":[],"mappings":";;;AACA,qEAA8D;AAC9D,8DAAuD;AAWvD,MAAa,uBAAwB,SAAQ,mCAAkC;IACpE,cAAc,CAAC;IAEf,cAAc,CAAC;IAExB,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,GAAG,IAAI,EACqB;QAC5B,KAAK,CAAC;YACJ,GAAG,IAAI;YACP,SAAS;YACT,iBAAiB;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACO,KAAK,CAAC,aAAa,CAAC,MAAc;QAC1C,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QAE3C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAElD,MAAM,MAAM,GAAG,IAAI,2CAAoB,CAAC;YACtC,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,OAAO;YACf,OAAO;SACR,CAAC,CAAC;QAEH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IACrC,CAAC;IAES,KAAK,CAAC,YAAY,CAC1B,UAA8C;QAE9C,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IACrC,CAAC;CACF;AA/CD,0DA+CC","sourcesContent":["import type { WebViewInterface } from './WebViewMessageStream';\nimport { WebViewMessageStream } from './WebViewMessageStream';\nimport { ExecutionService } from '../ExecutionService';\nimport type {\n  ExecutionServiceArgs,\n  TerminateJobArgs,\n} from '../ExecutionService';\n\nexport type WebViewExecutionServiceArgs = ExecutionServiceArgs & {\n  createWebView: (jobId: string) => Promise<WebViewInterface>;\n  removeWebView: (jobId: string) => void;\n};\n\nexport class WebViewExecutionService extends ExecutionService<WebViewInterface> {\n  readonly #createWebView;\n\n  readonly #removeWebView;\n\n  constructor({\n    messenger,\n    setupSnapProvider,\n    createWebView,\n    removeWebView,\n    ...args\n  }: WebViewExecutionServiceArgs) {\n    super({\n      ...args,\n      messenger,\n      setupSnapProvider,\n    });\n    this.#createWebView = createWebView;\n    this.#removeWebView = removeWebView;\n  }\n\n  /**\n   * Create a new stream for the specified Snap. This wraps the runtime stream\n   * in a stream specific to the Snap.\n   *\n   * @param snapId - The Snap ID.\n   * @returns An object with the webview and stream.\n   */\n  protected async initEnvStream(snapId: string) {\n    this.setSnapStatus(snapId, 'initializing');\n\n    const webView = await this.#createWebView(snapId);\n\n    const stream = new WebViewMessageStream({\n      name: 'parent',\n      target: 'child',\n      webView,\n    });\n\n    return { worker: webView, stream };\n  }\n\n  protected async terminateJob(\n    jobWrapper: TerminateJobArgs<WebViewInterface>,\n  ): Promise<void> {\n    this.#removeWebView(jobWrapper.id);\n  }\n}\n"]}