6
6
import { onUnexpectedError } from 'vs/base/common/errors' ;
7
7
import { Disposable , DisposableMap } from 'vs/base/common/lifecycle' ;
8
8
import { URI } from 'vs/base/common/uri' ;
9
+ import { generateUuid } from 'vs/base/common/uuid' ;
9
10
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
11
+ import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions' ;
12
+ import { IStorageService , StorageScope , StorageTarget } from 'vs/platform/storage/common/storage' ;
10
13
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
11
14
import { MainThreadWebviews , reviveWebviewContentOptions , reviveWebviewExtension } from 'vs/workbench/api/browser/mainThreadWebviews' ;
12
15
import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol' ;
13
16
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput' ;
14
17
import { EditorInput } from 'vs/workbench/common/editor/editorInput' ;
18
+ import { Memento , MementoObject } from 'vs/workbench/common/memento' ;
15
19
import { WebviewOptions } from 'vs/workbench/contrib/webview/browser/webview' ;
16
20
import { WebviewInput } from 'vs/workbench/contrib/webviewPanel/browser/webviewEditorInput' ;
17
21
import { WebviewIcons } from 'vs/workbench/contrib/webviewPanel/browser/webviewIconManager' ;
@@ -75,6 +79,43 @@ class WebviewViewTypeTransformer {
75
79
}
76
80
}
77
81
82
+ /**
83
+ * Stores the unique origins for webviews.
84
+ *
85
+ * These are randomly generated, but keyed on extension and webview viewType.
86
+ */
87
+ class WebviewOriginStore {
88
+
89
+ private readonly memento : Memento ;
90
+ private readonly state : MementoObject ;
91
+
92
+ constructor (
93
+ storageKey : string ,
94
+ @IStorageService storageService : IStorageService ,
95
+ ) {
96
+ this . memento = new Memento ( storageKey , storageService ) ;
97
+ this . state = this . memento . getMemento ( StorageScope . APPLICATION , StorageTarget . MACHINE ) ;
98
+ }
99
+
100
+ public getOrigin ( extId : ExtensionIdentifier , viewType : string ) : string {
101
+ const key = this . getKey ( extId , viewType ) ;
102
+
103
+ const existing = this . state [ key ] ;
104
+ if ( existing && typeof existing === 'string' ) {
105
+ return existing ;
106
+ }
107
+
108
+ const newOrigin = generateUuid ( ) ;
109
+ this . state [ key ] = newOrigin ;
110
+ this . memento . saveMemento ( ) ;
111
+ return newOrigin ;
112
+ }
113
+
114
+ private getKey ( extId : ExtensionIdentifier , viewType : string ) : string {
115
+ return JSON . stringify ( [ extId . value , viewType ] ) ;
116
+ }
117
+ }
118
+
78
119
export class MainThreadWebviewPanels extends Disposable implements extHostProtocol . MainThreadWebviewPanelsShape {
79
120
80
121
private readonly webviewPanelViewType = new WebviewViewTypeTransformer ( 'mainThreadWebview-' ) ;
@@ -85,18 +126,23 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc
85
126
86
127
private readonly _revivers = this . _register ( new DisposableMap < string > ( ) ) ;
87
128
129
+ private readonly webviewOriginStore : WebviewOriginStore ;
130
+
88
131
constructor (
89
132
context : IExtHostContext ,
90
133
private readonly _mainThreadWebviews : MainThreadWebviews ,
91
134
@IConfigurationService private readonly _configurationService : IConfigurationService ,
92
135
@IEditorGroupsService private readonly _editorGroupService : IEditorGroupsService ,
93
136
@IEditorService private readonly _editorService : IEditorService ,
94
137
@IExtensionService extensionService : IExtensionService ,
138
+ @IStorageService storageService : IStorageService ,
95
139
@ITelemetryService private readonly _telemetryService : ITelemetryService ,
96
140
@IWebviewWorkbenchService private readonly _webviewWorkbenchService : IWebviewWorkbenchService ,
97
141
) {
98
142
super ( ) ;
99
143
144
+ this . webviewOriginStore = new WebviewOriginStore ( 'mainThreadWebviewPanel.origins' , storageService ) ;
145
+
100
146
this . _proxy = context . getProxy ( extHostProtocol . ExtHostContext . ExtHostWebviewPanels ) ;
101
147
102
148
this . _register ( _editorService . onDidActiveEditorChange ( ( ) => {
@@ -152,9 +198,11 @@ export class MainThreadWebviewPanels extends Disposable implements extHostProtoc
152
198
} : { } ;
153
199
154
200
const extension = reviveWebviewExtension ( extensionData ) ;
201
+ const origin = this . webviewOriginStore . getOrigin ( extension . id , viewType ) ;
155
202
156
203
const webview = this . _webviewWorkbenchService . openWebview ( {
157
204
id : handle ,
205
+ origin,
158
206
providedViewType : viewType ,
159
207
options : reviveWebviewOptions ( initData . panelOptions ) ,
160
208
contentOptions : reviveWebviewContentOptions ( initData . webviewOptions ) ,
0 commit comments