44 *--------------------------------------------------------------------------------------------*/
55
66import { FindInPageOptions , OnBeforeRequestListenerDetails , OnHeadersReceivedListenerDetails , Response , WebContents , WebviewTag } from 'electron' ;
7- import { ipcRenderer } from 'vs/base/parts/sandbox/electron-sandbox/globals' ;
87import { addDisposableListener } from 'vs/base/browser/dom' ;
98import { equals } from 'vs/base/common/arrays' ;
109import { ThrottledDelayer } from 'vs/base/common/async' ;
@@ -14,22 +13,22 @@ import { Disposable, DisposableStore, IDisposable, toDisposable } from 'vs/base/
1413import { Schemas } from 'vs/base/common/network' ;
1514import { isMacintosh } from 'vs/base/common/platform' ;
1615import { URI } from 'vs/base/common/uri' ;
16+ import { createChannelSender } from 'vs/base/parts/ipc/common/ipc' ;
1717import * as modes from 'vs/editor/common/modes' ;
1818import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
1919import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
2020import { IFileService } from 'vs/platform/files/common/files' ;
2121import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
22+ import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService' ;
2223import { ITunnelService } from 'vs/platform/remote/common/tunnel' ;
2324import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
25+ import { IWebviewManagerService } from 'vs/platform/webview/common/webviewManagerService' ;
2426import { BaseWebview , WebviewMessageChannels } from 'vs/workbench/contrib/webview/browser/baseWebviewElement' ;
2527import { Webview , WebviewContentOptions , WebviewExtensionDescription , WebviewOptions } from 'vs/workbench/contrib/webview/browser/webview' ;
2628import { WebviewPortMappingManager } from 'vs/workbench/contrib/webview/common/portMapping' ;
2729import { WebviewThemeDataProvider } from 'vs/workbench/contrib/webview/common/themeing' ;
2830import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService' ;
2931import { WebviewFindDelegate , WebviewFindWidget } from '../browser/webviewFindWidget' ;
30- import { IWebviewManagerService } from 'vs/platform/webview/common/webviewManagerService' ;
31- import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService' ;
32- import { createChannelSender } from 'vs/base/parts/ipc/common/ipc' ;
3332
3433class WebviewTagHandle extends Disposable {
3534
@@ -127,19 +126,18 @@ class WebviewProtocolProvider extends Disposable {
127126 private readonly id : string ,
128127 private readonly extension : WebviewExtensionDescription | undefined ,
129128 initialLocalResourceRoots : ReadonlyArray < URI > ,
129+ private readonly _webviewManagerService : IWebviewManagerService ,
130130 ) {
131131 super ( ) ;
132132
133133 this . _localResourceRoots = initialLocalResourceRoots ;
134134
135- ipcRenderer . send ( 'vscode:registerWebview' , this . id , {
135+ this . _ready = _webviewManagerService . registerWebview ( this . id , {
136136 extensionLocation : this . extension ?. location . toJSON ( ) ,
137137 localResourceRoots : initialLocalResourceRoots . map ( x => x . toJSON ( ) ) ,
138138 } ) ;
139139
140- this . _ready = new Promise ( ( resolve ) => {
141- ipcRenderer . once ( `vscode:didRegisterWebview-${ this . id } ` , ( ) => resolve ( ) ) ;
142- } ) ;
140+ this . _register ( toDisposable ( ( ) => this . _webviewManagerService . unregisterWebview ( this . id ) ) ) ;
143141 }
144142
145143 public update ( localResourceRoots : ReadonlyArray < URI > ) {
@@ -149,22 +147,12 @@ class WebviewProtocolProvider extends Disposable {
149147
150148 this . _localResourceRoots = localResourceRoots ;
151149
152- ipcRenderer . send ( 'vscode:updateWebviewLocalResourceRoots' , this . id , localResourceRoots . map ( x => x . toJSON ( ) ) ) ;
153-
154- this . _ready = new Promise ( ( resolve ) => {
155- ipcRenderer . once ( `vscode:didUpdateWebviewLocalResourceRoots-${ this . id } ` , ( ) => resolve ( ) ) ;
156- } ) ;
150+ this . _ready = this . _webviewManagerService . updateLocalResourceRoots ( this . id , localResourceRoots . map ( x => x . toJSON ( ) ) ) ;
157151 }
158152
159153 async synchronize ( ) : Promise < void > {
160154 return this . _ready ;
161155 }
162-
163- dispose ( ) {
164- super . dispose ( ) ;
165-
166- ipcRenderer . send ( 'vscode:unregisterWebview' , this . id ) ;
167- }
168156}
169157
170158class WebviewPortMappingProvider extends Disposable {
@@ -286,10 +274,12 @@ export class ElectronWebviewBasedWebview extends BaseWebview<WebviewTag> impleme
286274 ) {
287275 super ( id , options , contentOptions , extension , _webviewThemeDataProvider , telemetryService , environementService , workbenchEnvironmentService ) ;
288276
277+ const webviewManagerService = createChannelSender < IWebviewManagerService > ( mainProcessService . getChannel ( 'webview' ) ) ;
278+
289279 const webviewAndContents = this . _register ( new WebviewTagHandle ( this . element ! ) ) ;
290280 const session = this . _register ( new WebviewSession ( webviewAndContents ) ) ;
291281
292- this . _protocolProvider = this . _register ( new WebviewProtocolProvider ( id , extension , this . content . options . localResourceRoots || [ ] ) ) ;
282+ this . _protocolProvider = this . _register ( new WebviewProtocolProvider ( id , extension , this . content . options . localResourceRoots || [ ] , webviewManagerService ) ) ;
293283
294284 this . _register ( new WebviewPortMappingProvider (
295285 session ,
0 commit comments