@codingame/monaco-vscode-view-common-service-override 4.5.0-improve-code-splitting.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/assets/fake.html +10 -0
  2. package/assets/index-no-csp.html +1230 -0
  3. package/assets/index.html +1231 -0
  4. package/assets/service-worker.js +457 -0
  5. package/index.d.ts +1 -0
  6. package/index.js +1 -0
  7. package/override/vs/workbench/browser/parts/editor/textEditor.js +5 -0
  8. package/override/vs/workbench/browser/parts/editor/textEditor.weak.js +11 -0
  9. package/package.json +32 -0
  10. package/tools/editorAssets.js +4 -0
  11. package/tools/url.js +10 -0
  12. package/viewCommon.d.ts +5 -0
  13. package/viewCommon.js +105 -0
  14. package/vscode/src/vs/base/browser/deviceAccess.js +61 -0
  15. package/vscode/src/vs/base/browser/ui/centered/centeredViewLayout.js +180 -0
  16. package/vscode/src/vs/base/browser/ui/grid/grid.js +494 -0
  17. package/vscode/src/vs/base/browser/ui/grid/gridview.css.js +6 -0
  18. package/vscode/src/vs/base/browser/ui/grid/gridview.js +1113 -0
  19. package/vscode/src/vs/platform/languagePacks/common/localizedStrings.js +12 -0
  20. package/vscode/src/vs/platform/webview/common/mimeTypes.js +24 -0
  21. package/vscode/src/vs/platform/webview/common/webviewPortMapping.js +64 -0
  22. package/vscode/src/vs/workbench/api/browser/viewsExtensionPoint.js +907 -0
  23. package/vscode/src/vs/workbench/browser/actions/listCommands.js +764 -0
  24. package/vscode/src/vs/workbench/browser/actions/navigationActions.js +301 -0
  25. package/vscode/src/vs/workbench/browser/media/style.css.js +6 -0
  26. package/vscode/src/vs/workbench/browser/parts/activitybar/activitybarPart.js +671 -0
  27. package/vscode/src/vs/workbench/browser/parts/activitybar/media/activityaction.css.js +6 -0
  28. package/vscode/src/vs/workbench/browser/parts/activitybar/media/activitybarpart.css.js +6 -0
  29. package/vscode/src/vs/workbench/browser/parts/auxiliarybar/auxiliaryBarPart.js +229 -0
  30. package/vscode/src/vs/workbench/browser/parts/auxiliarybar/media/auxiliaryBarPart.css.js +6 -0
  31. package/vscode/src/vs/workbench/browser/parts/compositeBar.js +606 -0
  32. package/vscode/src/vs/workbench/browser/parts/compositePart.js +346 -0
  33. package/vscode/src/vs/workbench/browser/parts/editor/auxiliaryEditorPart.js +246 -0
  34. package/vscode/src/vs/workbench/browser/parts/editor/editor.contribution.js +1403 -0
  35. package/vscode/src/vs/workbench/browser/parts/editor/editorConfiguration.js +188 -0
  36. package/vscode/src/vs/workbench/browser/parts/editor/editorDropTarget.js +523 -0
  37. package/vscode/src/vs/workbench/browser/parts/editor/editorPart.js +1030 -0
  38. package/vscode/src/vs/workbench/browser/parts/editor/editorParts.js +391 -0
  39. package/vscode/src/vs/workbench/browser/parts/editor/media/editordroptarget.css.js +6 -0
  40. package/vscode/src/vs/workbench/browser/parts/media/compositepart.css.js +6 -0
  41. package/vscode/src/vs/workbench/browser/parts/media/paneCompositePart.css.js +6 -0
  42. package/vscode/src/vs/workbench/browser/parts/paneCompositeBar.js +643 -0
  43. package/vscode/src/vs/workbench/browser/parts/paneCompositePart.js +472 -0
  44. package/vscode/src/vs/workbench/browser/parts/paneCompositePartService.js +68 -0
  45. package/vscode/src/vs/workbench/browser/parts/panel/panelPart.js +160 -0
  46. package/vscode/src/vs/workbench/browser/parts/sidebar/media/sidebarpart.css.js +6 -0
  47. package/vscode/src/vs/workbench/browser/parts/sidebar/sidebarActions.js +39 -0
  48. package/vscode/src/vs/workbench/browser/parts/sidebar/sidebarPart.js +238 -0
  49. package/vscode/src/vs/workbench/browser/style.js +54 -0
  50. package/vscode/src/vs/workbench/browser/window.js +381 -0
  51. package/vscode/src/vs/workbench/contrib/callHierarchy/browser/callHierarchy.contribution.js +300 -0
  52. package/vscode/src/vs/workbench/contrib/callHierarchy/browser/callHierarchyPeek.js +367 -0
  53. package/vscode/src/vs/workbench/contrib/callHierarchy/browser/callHierarchyTree.js +135 -0
  54. package/vscode/src/vs/workbench/contrib/callHierarchy/browser/media/callHierarchy.css.js +6 -0
  55. package/vscode/src/vs/workbench/contrib/customEditor/browser/customEditor.contribution.js +18 -0
  56. package/vscode/src/vs/workbench/contrib/customEditor/browser/customEditorInputFactory.js +146 -0
  57. package/vscode/src/vs/workbench/contrib/customEditor/browser/customEditors.js +215 -0
  58. package/vscode/src/vs/workbench/contrib/customEditor/browser/media/customEditor.css.js +6 -0
  59. package/vscode/src/vs/workbench/contrib/customEditor/common/contributedCustomEditors.js +78 -0
  60. package/vscode/src/vs/workbench/contrib/customEditor/common/customEditor.js +56 -0
  61. package/vscode/src/vs/workbench/contrib/customEditor/common/customEditorModelManager.js +63 -0
  62. package/vscode/src/vs/workbench/contrib/customEditor/common/extensionPoint.js +183 -0
  63. package/vscode/src/vs/workbench/contrib/externalUriOpener/common/externalUriOpener.contribution.js +8 -0
  64. package/vscode/src/vs/workbench/contrib/languageStatus/browser/languageStatus.contribution.js +408 -0
  65. package/vscode/src/vs/workbench/contrib/languageStatus/browser/media/languageStatus.css.js +6 -0
  66. package/vscode/src/vs/workbench/contrib/limitIndicator/browser/limitIndicator.contribution.js +147 -0
  67. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/commands/commands.js +635 -0
  68. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/commands/devCommands.js +230 -0
  69. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/mergeEditor.contribution.js +75 -0
  70. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/mergeEditorSerializer.js +42 -0
  71. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/colors.js +81 -0
  72. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/conflictActions.js +350 -0
  73. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/editorGutter.js +100 -0
  74. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/editors/baseCodeEditorView.js +148 -0
  75. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/editors/codeEditorView.js +106 -0
  76. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/editors/inputCodeEditorView.js +403 -0
  77. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/editors/resultCodeEditorView.js +199 -0
  78. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/fixedZoneWidget.js +41 -0
  79. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/lineAlignment.js +128 -0
  80. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/media/mergeEditor.css.js +6 -0
  81. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/mergeEditor.js +619 -0
  82. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/scrollSynchronizer.js +161 -0
  83. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/viewModel.js +266 -0
  84. package/vscode/src/vs/workbench/contrib/mergeEditor/browser/view/viewZones.js +173 -0
  85. package/vscode/src/vs/workbench/contrib/preferences/browser/keyboardLayoutPicker.js +195 -0
  86. package/vscode/src/vs/workbench/contrib/sash/browser/sash.contribution.js +38 -0
  87. package/vscode/src/vs/workbench/contrib/sash/browser/sash.js +41 -0
  88. package/vscode/src/vs/workbench/contrib/typeHierarchy/browser/media/typeHierarchy.css.js +6 -0
  89. package/vscode/src/vs/workbench/contrib/typeHierarchy/browser/typeHierarchy.contribution.js +283 -0
  90. package/vscode/src/vs/workbench/contrib/typeHierarchy/browser/typeHierarchyPeek.js +362 -0
  91. package/vscode/src/vs/workbench/contrib/typeHierarchy/browser/typeHierarchyTree.js +133 -0
  92. package/vscode/src/vs/workbench/contrib/webview/browser/overlayWebview.js +314 -0
  93. package/vscode/src/vs/workbench/contrib/webview/browser/resourceLoading.js +96 -0
  94. package/vscode/src/vs/workbench/contrib/webview/browser/themeing.js +98 -0
  95. package/vscode/src/vs/workbench/contrib/webview/browser/webviewElement.js +656 -0
  96. package/vscode/src/vs/workbench/contrib/webview/browser/webviewFindWidget.js +65 -0
  97. package/vscode/src/vs/workbench/contrib/webview/browser/webviewService.js +59 -0
  98. package/vscode/src/vs/workbench/contrib/webviewPanel/browser/webviewCommands.js +143 -0
  99. package/vscode/src/vs/workbench/contrib/webviewPanel/browser/webviewEditorInputSerializer.js +121 -0
  100. package/vscode/src/vs/workbench/contrib/webviewPanel/browser/webviewPanel.contribution.js +67 -0
  101. package/vscode/src/vs/workbench/contrib/webviewView/browser/webviewViewPane.js +234 -0
  102. package/vscode/src/vs/workbench/contrib/webviewView/browser/webviewViewService.js +45 -0
  103. package/vscode/src/vs/workbench/services/activity/browser/activityService.js +145 -0
  104. package/vscode/src/vs/workbench/services/auxiliaryWindow/browser/auxiliaryWindowService.js +341 -0
  105. package/vscode/src/vs/workbench/services/driver/browser/driver.js +186 -0
  106. package/vscode/src/vs/workbench/services/editor/browser/editorPaneService.js +13 -0
  107. package/vscode/src/vs/workbench/services/editor/browser/editorResolverService.js +676 -0
  108. package/vscode/src/vs/workbench/services/history/browser/historyService.js +1516 -0
  109. package/vscode/src/vs/workbench/services/progress/browser/media/progressService.css.js +6 -0
  110. package/vscode/src/vs/workbench/services/progress/browser/progressService.js +527 -0
  111. package/vscode/src/vs/workbench/services/untitled/common/untitledTextEditorHandler.js +102 -0
  112. package/vscode/src/vs/workbench/services/untitled/common/untitledTextEditorService.js +133 -0
  113. package/vscode/src/vs/workbench/services/views/browser/viewDescriptorService.js +711 -0
  114. package/vscode/src/vs/workbench/services/views/common/viewContainerModel.js +603 -0
@@ -0,0 +1,656 @@
1
+ import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
2
+ import { isFirefox } from 'vscode/vscode/vs/base/browser/browser';
3
+ import { getWindowById, EventType, addDisposableListener } from 'vscode/vscode/vs/base/browser/dom';
4
+ import { ThrottledDelayer, promiseWithResolvers } from 'vscode/vscode/vs/base/common/async';
5
+ import { streamToBuffer } from 'vscode/vscode/vs/base/common/buffer';
6
+ import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
7
+ import { Emitter, Event } from 'vscode/vscode/vs/base/common/event';
8
+ import { Disposable, toDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
9
+ import { FileAccess, COI } from 'vscode/vscode/vs/base/common/network';
10
+ import { URI } from 'vscode/vscode/vs/base/common/uri';
11
+ import { generateUuid } from 'vscode/vscode/vs/base/common/uuid';
12
+ import { localizeWithPath } from 'vscode/vscode/vs/nls';
13
+ import { IAccessibilityService } from 'vscode/vscode/vs/platform/accessibility/common/accessibility.service';
14
+ import { MenuId } from 'vscode/vscode/vs/platform/actions/common/actions';
15
+ import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration.service';
16
+ import { IContextMenuService } from 'vscode/vscode/vs/platform/contextview/browser/contextView.service';
17
+ import { IFileService } from 'vscode/vscode/vs/platform/files/common/files.service';
18
+ import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
19
+ import { ILogService } from 'vscode/vscode/vs/platform/log/common/log.service';
20
+ import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification.service';
21
+ import { IRemoteAuthorityResolverService } from 'vscode/vscode/vs/platform/remote/common/remoteAuthorityResolver.service';
22
+ import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry.service';
23
+ import { ITunnelService } from 'vscode/vscode/vs/platform/tunnel/common/tunnel.service';
24
+ import { WebviewPortMappingManager } from '../../../../platform/webview/common/webviewPortMapping.js';
25
+ import { parentOriginHash } from 'vscode/vscode/vs/base/browser/iframe';
26
+ import { loadLocalResource, WebviewResourceResponse } from './resourceLoading.js';
27
+ import { areWebviewContentOptionsEqual } from 'vscode/vscode/vs/workbench/contrib/webview/browser/webview';
28
+ import { WebviewFindWidget } from './webviewFindWidget.js';
29
+ import { decodeAuthority, webviewRootResourceAuthority, webviewGenericCspSource } from 'vscode/vscode/vs/workbench/contrib/webview/common/webview';
30
+ import { IWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/common/environmentService.service';
31
+
32
+ var WebviewState;
33
+ ( (function(WebviewState) {
34
+ ( (function(Type) {
35
+ Type[Type["Initializing"] = 0] = "Initializing";
36
+ Type[Type["Ready"] = 1] = "Ready";
37
+ })(WebviewState.Type || (WebviewState.Type = {})));
38
+ class Initializing {
39
+ constructor(pendingMessages) {
40
+ this.pendingMessages = pendingMessages;
41
+ this.type = 0 ;
42
+ }
43
+ }
44
+ WebviewState.Initializing = Initializing;
45
+ WebviewState.Ready = { type: 1 };
46
+ })(WebviewState || (WebviewState = {})));
47
+ const webviewIdContext = 'webviewId';
48
+ let WebviewElement = class WebviewElement extends Disposable {
49
+ get window() { return typeof this._windowId === 'number' ? getWindowById(this._windowId)?.window : undefined; }
50
+ get platform() { return 'browser'; }
51
+ get element() { return this._element; }
52
+ get isFocused() {
53
+ if (!this._focused) {
54
+ return false;
55
+ }
56
+ if (!this.window) {
57
+ return false;
58
+ }
59
+ if (this.window.document.activeElement && this.window.document.activeElement !== this.element) {
60
+ return false;
61
+ }
62
+ return true;
63
+ }
64
+ constructor(initInfo, webviewThemeDataProvider, configurationService, contextMenuService, notificationService, _environmentService, _fileService, _logService, _remoteAuthorityResolverService, _telemetryService, _tunnelService, instantiationService, _accessibilityService) {
65
+ super();
66
+ this.webviewThemeDataProvider = webviewThemeDataProvider;
67
+ this._environmentService = _environmentService;
68
+ this._fileService = _fileService;
69
+ this._logService = _logService;
70
+ this._remoteAuthorityResolverService = _remoteAuthorityResolverService;
71
+ this._telemetryService = _telemetryService;
72
+ this._tunnelService = _tunnelService;
73
+ this._accessibilityService = _accessibilityService;
74
+ this.id = generateUuid();
75
+ this._windowId = undefined;
76
+ this._expectedServiceWorkerVersion = 4;
77
+ this._state = new WebviewState.Initializing([]);
78
+ this._resourceLoadingCts = this._register(( new CancellationTokenSource()));
79
+ this._focusDelayer = this._register(( new ThrottledDelayer(50)));
80
+ this._onDidHtmlChange = this._register(( new Emitter()));
81
+ this.onDidHtmlChange = this._onDidHtmlChange.event;
82
+ this._messageHandlers = ( new Map());
83
+ this.checkImeCompletionState = true;
84
+ this._disposed = false;
85
+ this._onMissingCsp = this._register(( new Emitter()));
86
+ this.onMissingCsp = this._onMissingCsp.event;
87
+ this._onDidClickLink = this._register(( new Emitter()));
88
+ this.onDidClickLink = this._onDidClickLink.event;
89
+ this._onDidReload = this._register(( new Emitter()));
90
+ this.onDidReload = this._onDidReload.event;
91
+ this._onMessage = this._register(( new Emitter()));
92
+ this.onMessage = this._onMessage.event;
93
+ this._onDidScroll = this._register(( new Emitter()));
94
+ this.onDidScroll = this._onDidScroll.event;
95
+ this._onDidWheel = this._register(( new Emitter()));
96
+ this.onDidWheel = this._onDidWheel.event;
97
+ this._onDidUpdateState = this._register(( new Emitter()));
98
+ this.onDidUpdateState = this._onDidUpdateState.event;
99
+ this._onDidFocus = this._register(( new Emitter()));
100
+ this.onDidFocus = this._onDidFocus.event;
101
+ this._onDidBlur = this._register(( new Emitter()));
102
+ this.onDidBlur = this._onDidBlur.event;
103
+ this._onFatalError = this._register(( new Emitter()));
104
+ this.onFatalError = this._onFatalError.event;
105
+ this._onDidDispose = this._register(( new Emitter()));
106
+ this.onDidDispose = this._onDidDispose.event;
107
+ this._hasAlertedAboutMissingCsp = false;
108
+ this._hasFindResult = this._register(( new Emitter()));
109
+ this.hasFindResult = this._hasFindResult.event;
110
+ this._onDidStopFind = this._register(( new Emitter()));
111
+ this.onDidStopFind = this._onDidStopFind.event;
112
+ this.providedViewType = initInfo.providedViewType;
113
+ this.origin = initInfo.origin ?? this.id;
114
+ this._options = initInfo.options;
115
+ this.extension = initInfo.extension;
116
+ this._content = {
117
+ html: '',
118
+ title: initInfo.title,
119
+ options: initInfo.contentOptions,
120
+ state: undefined
121
+ };
122
+ this._portMappingManager = this._register(( new WebviewPortMappingManager(
123
+ () => this.extension?.location,
124
+ () => this._content.options.portMapping || [],
125
+ this._tunnelService
126
+ )));
127
+ this._element = this._createElement(initInfo.options, initInfo.contentOptions);
128
+ this._register(this.on('no-csp-found', () => {
129
+ this.handleNoCspFound();
130
+ }));
131
+ this._register(this.on('did-click-link', ({ uri }) => {
132
+ this._onDidClickLink.fire(uri);
133
+ }));
134
+ this._register(this.on('onmessage', ({ message, transfer }) => {
135
+ this._onMessage.fire({ message, transfer });
136
+ }));
137
+ this._register(this.on('did-scroll', ({ scrollYPercentage }) => {
138
+ this._onDidScroll.fire({ scrollYPercentage });
139
+ }));
140
+ this._register(this.on('do-reload', () => {
141
+ this.reload();
142
+ }));
143
+ this._register(this.on('do-update-state', (state) => {
144
+ this.state = state;
145
+ this._onDidUpdateState.fire(state);
146
+ }));
147
+ this._register(this.on('did-focus', () => {
148
+ this.handleFocusChange(true);
149
+ }));
150
+ this._register(this.on('did-blur', () => {
151
+ this.handleFocusChange(false);
152
+ }));
153
+ this._register(this.on('did-scroll-wheel', (event) => {
154
+ this._onDidWheel.fire(event);
155
+ }));
156
+ this._register(this.on('did-find', ({ didFind }) => {
157
+ this._hasFindResult.fire(didFind);
158
+ }));
159
+ this._register(this.on('fatal-error', (e) => {
160
+ notificationService.error(( localizeWithPath(
161
+ 'vs/workbench/contrib/webview/browser/webviewElement',
162
+ 'fatalErrorMessage',
163
+ "Error loading webview: {0}",
164
+ e.message
165
+ )));
166
+ this._onFatalError.fire({ message: e.message });
167
+ }));
168
+ this._register(this.on('did-keydown', (data) => {
169
+ this.handleKeyEvent('keydown', data);
170
+ }));
171
+ this._register(this.on('did-keyup', (data) => {
172
+ this.handleKeyEvent('keyup', data);
173
+ }));
174
+ this._register(this.on('did-context-menu', (data) => {
175
+ if (!this.element) {
176
+ return;
177
+ }
178
+ if (!this._contextKeyService) {
179
+ return;
180
+ }
181
+ const elementBox = this.element.getBoundingClientRect();
182
+ const contextKeyService = this._contextKeyService.createOverlay([
183
+ ...Object.entries(data.context),
184
+ [webviewIdContext, this.providedViewType],
185
+ ]);
186
+ contextMenuService.showContextMenu({
187
+ menuId: MenuId.WebviewContext,
188
+ menuActionOptions: { shouldForwardArgs: true },
189
+ contextKeyService,
190
+ getActionsContext: () => ({ ...data.context, webview: this.providedViewType }),
191
+ getAnchor: () => ({
192
+ x: elementBox.x + data.clientX,
193
+ y: elementBox.y + data.clientY
194
+ })
195
+ });
196
+ }));
197
+ this._register(this.on('load-resource', async (entry) => {
198
+ try {
199
+ const authority = decodeAuthority(entry.authority);
200
+ const uri = ( URI.from({
201
+ scheme: entry.scheme,
202
+ authority: authority,
203
+ path: decodeURIComponent(entry.path),
204
+ query: entry.query ? decodeURIComponent(entry.query) : entry.query,
205
+ }));
206
+ this.loadResource(entry.id, uri, entry.ifNoneMatch);
207
+ }
208
+ catch (e) {
209
+ this._send('did-load-resource', {
210
+ id: entry.id,
211
+ status: 404,
212
+ path: entry.path,
213
+ });
214
+ }
215
+ }));
216
+ this._register(this.on('load-localhost', (entry) => {
217
+ this.localLocalhost(entry.id, entry.origin);
218
+ }));
219
+ this._register(Event.runAndSubscribe(webviewThemeDataProvider.onThemeDataChanged, () => this.style()));
220
+ this._register(_accessibilityService.onDidChangeReducedMotion(() => this.style()));
221
+ this._register(_accessibilityService.onDidChangeScreenReaderOptimized(() => this.style()));
222
+ this._register(contextMenuService.onDidShowContextMenu(() => this._send('set-context-menu-visible', { visible: true })));
223
+ this._register(contextMenuService.onDidHideContextMenu(() => this._send('set-context-menu-visible', { visible: false })));
224
+ this._confirmBeforeClose = configurationService.getValue('window.confirmBeforeClose');
225
+ this._register(configurationService.onDidChangeConfiguration(e => {
226
+ if (e.affectsConfiguration('window.confirmBeforeClose')) {
227
+ this._confirmBeforeClose = configurationService.getValue('window.confirmBeforeClose');
228
+ this._send('set-confirm-before-close', this._confirmBeforeClose);
229
+ }
230
+ }));
231
+ this._register(this.on('drag-start', () => {
232
+ this._startBlockingIframeDragEvents();
233
+ }));
234
+ if (initInfo.options.enableFindWidget) {
235
+ this._webviewFindWidget = this._register(instantiationService.createInstance(WebviewFindWidget, this));
236
+ }
237
+ }
238
+ dispose() {
239
+ this._disposed = true;
240
+ this.element?.remove();
241
+ this._element = undefined;
242
+ this._messagePort = undefined;
243
+ if (this._state.type === 0 ) {
244
+ for (const message of this._state.pendingMessages) {
245
+ message.resolve(false);
246
+ }
247
+ this._state.pendingMessages = [];
248
+ }
249
+ this._onDidDispose.fire();
250
+ this._resourceLoadingCts.dispose(true);
251
+ super.dispose();
252
+ }
253
+ setContextKeyService(contextKeyService) {
254
+ this._contextKeyService = contextKeyService;
255
+ }
256
+ postMessage(message, transfer) {
257
+ return this._send('message', { message, transfer });
258
+ }
259
+ async _send(channel, data, _createElement = []) {
260
+ if (this._state.type === 0 ) {
261
+ const { promise, resolve } = promiseWithResolvers();
262
+ this._state.pendingMessages.push({ channel, data, transferable: _createElement, resolve });
263
+ return promise;
264
+ }
265
+ else {
266
+ return this.doPostMessage(channel, data, _createElement);
267
+ }
268
+ }
269
+ _createElement(options, _contentOptions) {
270
+ const element = document.createElement('iframe');
271
+ element.name = this.id;
272
+ element.className = `webview ${options.customClasses || ''}`;
273
+ element.sandbox.add('allow-scripts', 'allow-same-origin', 'allow-forms', 'allow-pointer-lock', 'allow-downloads');
274
+ const allowRules = ['cross-origin-isolated', 'autoplay'];
275
+ if (!isFirefox) {
276
+ allowRules.push('clipboard-read', 'clipboard-write');
277
+ }
278
+ element.setAttribute('allow', allowRules.join('; '));
279
+ element.style.border = 'none';
280
+ element.style.width = '100%';
281
+ element.style.height = '100%';
282
+ element.focus = () => {
283
+ this._doFocus();
284
+ };
285
+ return element;
286
+ }
287
+ _initElement(encodedWebviewOrigin, extension, options, targetWindow) {
288
+ const params = {
289
+ id: this.id,
290
+ origin: this.origin,
291
+ swVersion: String(this._expectedServiceWorkerVersion),
292
+ extensionId: extension?.id.value ?? '',
293
+ platform: this.platform,
294
+ 'vscode-resource-base-authority': webviewRootResourceAuthority,
295
+ parentOrigin: targetWindow.origin,
296
+ };
297
+ if (this._options.disableServiceWorker) {
298
+ params.disableServiceWorker = 'true';
299
+ }
300
+ if (this._environmentService.remoteAuthority) {
301
+ params.remoteAuthority = this._environmentService.remoteAuthority;
302
+ }
303
+ if (options.purpose) {
304
+ params.purpose = options.purpose;
305
+ }
306
+ params.serviceWorkerUri = ( ( FileAccess.asBrowserUri('vs/workbench/contrib/webview/browser/pre/service-worker.js')).toString(true));
307
+ params.fakeHtmlUri = ( ( FileAccess.asBrowserUri('vs/workbench/contrib/webview/browser/pre/fake.html')).toString(true));
308
+ COI.addSearchParam(params, true, true);
309
+ const queryString = ( ( new URLSearchParams(params)).toString());
310
+ const fileName = isFirefox ? 'index-no-csp.html' : 'index.html';
311
+ const relativeIframeSrc = ( FileAccess.asBrowserUri(`vs/workbench/contrib/webview/browser/pre/${fileName}`));
312
+ this.element.setAttribute('src', `${( relativeIframeSrc.toString(true))}?${queryString}`);
313
+ }
314
+ mountTo(element, targetWindow) {
315
+ if (!this.element) {
316
+ return;
317
+ }
318
+ this._windowId = targetWindow.vscodeWindowId;
319
+ this._encodedWebviewOriginPromise = parentOriginHash(targetWindow.origin, this.origin).then(id => this._encodedWebviewOrigin = id);
320
+ this._encodedWebviewOriginPromise.then(encodedWebviewOrigin => {
321
+ if (!this._disposed) {
322
+ this._initElement(encodedWebviewOrigin, this.extension, this._options, targetWindow);
323
+ }
324
+ });
325
+ this._registerMessageHandler(targetWindow);
326
+ if (this._webviewFindWidget) {
327
+ element.appendChild(this._webviewFindWidget.getDomNode());
328
+ }
329
+ for (const eventName of [EventType.MOUSE_DOWN, EventType.MOUSE_MOVE, EventType.DROP]) {
330
+ this._register(addDisposableListener(element, eventName, () => {
331
+ this._stopBlockingIframeDragEvents();
332
+ }));
333
+ }
334
+ for (const node of [element, targetWindow]) {
335
+ this._register(addDisposableListener(node, EventType.DRAG_END, () => {
336
+ this._stopBlockingIframeDragEvents();
337
+ }));
338
+ }
339
+ element.id = this.id;
340
+ element.appendChild(this.element);
341
+ }
342
+ _registerMessageHandler(targetWindow) {
343
+ const subscription = this._register(addDisposableListener(targetWindow, 'message', (e) => {
344
+ if (!this._encodedWebviewOrigin || e?.data?.target !== this.id) {
345
+ return;
346
+ }
347
+ if (e.data.channel === 'webview-ready') {
348
+ if (this._messagePort) {
349
+ return;
350
+ }
351
+ this._logService.debug(`Webview(${this.id}): webview ready`);
352
+ this._messagePort = e.ports[0];
353
+ this._messagePort.onmessage = (e) => {
354
+ const handlers = this._messageHandlers.get(e.data.channel);
355
+ if (!handlers) {
356
+ console.log(`No handlers found for '${e.data.channel}'`);
357
+ return;
358
+ }
359
+ handlers?.forEach(handler => handler(e.data.data, e));
360
+ };
361
+ this.element?.classList.add('ready');
362
+ if (this._state.type === 0 ) {
363
+ this._state.pendingMessages.forEach(({ channel, data, resolve }) => resolve(this.doPostMessage(channel, data)));
364
+ }
365
+ this._state = WebviewState.Ready;
366
+ subscription.dispose();
367
+ }
368
+ }));
369
+ }
370
+ _startBlockingIframeDragEvents() {
371
+ if (this.element) {
372
+ this.element.style.pointerEvents = 'none';
373
+ }
374
+ }
375
+ _stopBlockingIframeDragEvents() {
376
+ if (this.element) {
377
+ this.element.style.pointerEvents = 'auto';
378
+ }
379
+ }
380
+ webviewContentEndpoint(encodedWebviewOrigin) {
381
+ const webviewExternalEndpoint = this._environmentService.webviewExternalEndpoint;
382
+ if (!webviewExternalEndpoint) {
383
+ throw new Error(`'webviewExternalEndpoint' has not been configured. Webviews will not work!`);
384
+ }
385
+ const endpoint = webviewExternalEndpoint.replace('{{uuid}}', encodedWebviewOrigin);
386
+ if (endpoint[endpoint.length - 1] === '/') {
387
+ return endpoint.slice(0, endpoint.length - 1);
388
+ }
389
+ return endpoint;
390
+ }
391
+ doPostMessage(channel, data, transferable = []) {
392
+ if (this.element && this._messagePort) {
393
+ this._messagePort.postMessage({ channel, args: data }, transferable);
394
+ return true;
395
+ }
396
+ return false;
397
+ }
398
+ on(channel, handler) {
399
+ let handlers = this._messageHandlers.get(channel);
400
+ if (!handlers) {
401
+ handlers = ( new Set());
402
+ this._messageHandlers.set(channel, handlers);
403
+ }
404
+ handlers.add(handler);
405
+ return toDisposable(() => {
406
+ this._messageHandlers.get(channel)?.delete(handler);
407
+ });
408
+ }
409
+ handleNoCspFound() {
410
+ if (this._hasAlertedAboutMissingCsp) {
411
+ return;
412
+ }
413
+ this._hasAlertedAboutMissingCsp = true;
414
+ if (this.extension?.id) {
415
+ if (this._environmentService.isExtensionDevelopment) {
416
+ this._onMissingCsp.fire(this.extension.id);
417
+ }
418
+ const payload = {
419
+ extension: this.extension.id.value
420
+ };
421
+ this._telemetryService.publicLog2('webviewMissingCsp', payload);
422
+ }
423
+ }
424
+ reload() {
425
+ this.doUpdateContent(this._content);
426
+ const subscription = this._register(this.on('did-load', () => {
427
+ this._onDidReload.fire();
428
+ subscription.dispose();
429
+ }));
430
+ }
431
+ setHtml(html) {
432
+ this.doUpdateContent({ ...this._content, html });
433
+ this._onDidHtmlChange.fire(html);
434
+ }
435
+ setTitle(title) {
436
+ this._content = { ...this._content, title };
437
+ this._send('set-title', title);
438
+ }
439
+ set contentOptions(options) {
440
+ this._logService.debug(`Webview(${this.id}): will update content options`);
441
+ if (areWebviewContentOptionsEqual(options, this._content.options)) {
442
+ this._logService.debug(`Webview(${this.id}): skipping content options update`);
443
+ return;
444
+ }
445
+ this.doUpdateContent({ ...this._content, options });
446
+ }
447
+ set localResourcesRoot(resources) {
448
+ this._content = {
449
+ ...this._content,
450
+ options: { ...this._content.options, localResourceRoots: resources }
451
+ };
452
+ }
453
+ set state(state) {
454
+ this._content = { ...this._content, state };
455
+ }
456
+ set initialScrollProgress(value) {
457
+ this._send('initial-scroll-position', value);
458
+ }
459
+ doUpdateContent(newContent) {
460
+ this._logService.debug(`Webview(${this.id}): will update content`);
461
+ this._content = newContent;
462
+ const allowScripts = !!this._content.options.allowScripts;
463
+ this._send('content', {
464
+ contents: this._content.html,
465
+ title: this._content.title,
466
+ options: {
467
+ allowMultipleAPIAcquire: !!this._content.options.allowMultipleAPIAcquire,
468
+ allowScripts: allowScripts,
469
+ allowForms: this._content.options.allowForms ?? allowScripts,
470
+ },
471
+ state: this._content.state,
472
+ cspSource: webviewGenericCspSource,
473
+ confirmBeforeClose: this._confirmBeforeClose,
474
+ });
475
+ }
476
+ style() {
477
+ let { styles, activeTheme, themeLabel, themeId } = this.webviewThemeDataProvider.getWebviewThemeData();
478
+ if (this._options.transformCssVariables) {
479
+ styles = this._options.transformCssVariables(styles);
480
+ }
481
+ const reduceMotion = this._accessibilityService.isMotionReduced();
482
+ const screenReader = this._accessibilityService.isScreenReaderOptimized();
483
+ this._send('styles', { styles, activeTheme, themeId, themeLabel, reduceMotion, screenReader });
484
+ }
485
+ handleFocusChange(isFocused) {
486
+ this._focused = isFocused;
487
+ if (isFocused) {
488
+ this._onDidFocus.fire();
489
+ }
490
+ else {
491
+ this._onDidBlur.fire();
492
+ }
493
+ }
494
+ handleKeyEvent(type, event) {
495
+ const emulatedKeyboardEvent = ( new KeyboardEvent(type, event));
496
+ Object.defineProperty(emulatedKeyboardEvent, 'target', {
497
+ get: () => this.element,
498
+ });
499
+ this.window?.dispatchEvent(emulatedKeyboardEvent);
500
+ }
501
+ windowDidDragStart() {
502
+ this._startBlockingIframeDragEvents();
503
+ }
504
+ windowDidDragEnd() {
505
+ this._stopBlockingIframeDragEvents();
506
+ }
507
+ selectAll() {
508
+ this.execCommand('selectAll');
509
+ }
510
+ copy() {
511
+ this.execCommand('copy');
512
+ }
513
+ paste() {
514
+ this.execCommand('paste');
515
+ }
516
+ cut() {
517
+ this.execCommand('cut');
518
+ }
519
+ undo() {
520
+ this.execCommand('undo');
521
+ }
522
+ redo() {
523
+ this.execCommand('redo');
524
+ }
525
+ execCommand(command) {
526
+ if (this.element) {
527
+ this._send('execCommand', command);
528
+ }
529
+ }
530
+ async loadResource(id, uri, ifNoneMatch) {
531
+ try {
532
+ const result = await loadLocalResource(uri, {
533
+ ifNoneMatch,
534
+ roots: this._content.options.localResourceRoots || [],
535
+ }, this._fileService, this._logService, this._resourceLoadingCts.token);
536
+ switch (result.type) {
537
+ case WebviewResourceResponse.Type.Success: {
538
+ const buffer = await this.streamToBuffer(result.stream);
539
+ return this._send('did-load-resource', {
540
+ id,
541
+ status: 200,
542
+ path: uri.path,
543
+ mime: result.mimeType,
544
+ data: buffer,
545
+ etag: result.etag,
546
+ mtime: result.mtime
547
+ }, [buffer]);
548
+ }
549
+ case WebviewResourceResponse.Type.NotModified: {
550
+ return this._send('did-load-resource', {
551
+ id,
552
+ status: 304,
553
+ path: uri.path,
554
+ mime: result.mimeType,
555
+ mtime: result.mtime
556
+ });
557
+ }
558
+ case WebviewResourceResponse.Type.AccessDenied: {
559
+ return this._send('did-load-resource', {
560
+ id,
561
+ status: 401,
562
+ path: uri.path,
563
+ });
564
+ }
565
+ }
566
+ }
567
+ catch {
568
+ }
569
+ return this._send('did-load-resource', {
570
+ id,
571
+ status: 404,
572
+ path: uri.path,
573
+ });
574
+ }
575
+ async streamToBuffer(stream) {
576
+ const vsBuffer = await streamToBuffer(stream);
577
+ return vsBuffer.buffer.buffer;
578
+ }
579
+ async localLocalhost(id, origin) {
580
+ const authority = this._environmentService.remoteAuthority;
581
+ const resolveAuthority = authority ? await this._remoteAuthorityResolverService.resolveAuthority(authority) : undefined;
582
+ const redirect = resolveAuthority ? await this._portMappingManager.getRedirect(resolveAuthority.authority, origin) : undefined;
583
+ return this._send('did-load-localhost', {
584
+ id,
585
+ origin,
586
+ location: redirect
587
+ });
588
+ }
589
+ focus() {
590
+ this._doFocus();
591
+ this.handleFocusChange(true);
592
+ }
593
+ _doFocus() {
594
+ if (!this.element) {
595
+ return;
596
+ }
597
+ try {
598
+ this.element.contentWindow?.focus();
599
+ }
600
+ catch {
601
+ }
602
+ this._focusDelayer.trigger(async () => {
603
+ if (!this.isFocused || !this.element) {
604
+ return;
605
+ }
606
+ if (this.window?.document.activeElement && this.window.document.activeElement !== this.element && this.window.document.activeElement?.tagName !== 'BODY') {
607
+ return;
608
+ }
609
+ this.window?.document.body?.focus();
610
+ this._send('focus', undefined);
611
+ });
612
+ }
613
+ find(value, previous) {
614
+ if (!this.element) {
615
+ return;
616
+ }
617
+ this._send('find', { value, previous });
618
+ }
619
+ updateFind(value) {
620
+ if (!value || !this.element) {
621
+ return;
622
+ }
623
+ this._send('find', { value });
624
+ }
625
+ stopFind(keepSelection) {
626
+ if (!this.element) {
627
+ return;
628
+ }
629
+ this._send('find-stop', { clearSelection: !keepSelection });
630
+ this._onDidStopFind.fire();
631
+ }
632
+ showFind(animated = true) {
633
+ this._webviewFindWidget?.reveal(undefined, animated);
634
+ }
635
+ hideFind(animated = true) {
636
+ this._webviewFindWidget?.hide(animated);
637
+ }
638
+ runFindAction(previous) {
639
+ this._webviewFindWidget?.find(previous);
640
+ }
641
+ };
642
+ WebviewElement = ( __decorate([
643
+ ( __param(2, IConfigurationService)),
644
+ ( __param(3, IContextMenuService)),
645
+ ( __param(4, INotificationService)),
646
+ ( __param(5, IWorkbenchEnvironmentService)),
647
+ ( __param(6, IFileService)),
648
+ ( __param(7, ILogService)),
649
+ ( __param(8, IRemoteAuthorityResolverService)),
650
+ ( __param(9, ITelemetryService)),
651
+ ( __param(10, ITunnelService)),
652
+ ( __param(11, IInstantiationService)),
653
+ ( __param(12, IAccessibilityService))
654
+ ], WebviewElement));
655
+
656
+ export { WebviewElement };