@theia/plugin-ext 1.75.0-next.43 → 1.75.0-next.46
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.
- package/lib/main/browser/webviews-main.d.ts +8 -1
- package/lib/main/browser/webviews-main.d.ts.map +1 -1
- package/lib/main/browser/webviews-main.js +22 -18
- package/lib/main/browser/webviews-main.js.map +1 -1
- package/lib/main/browser/webviews-main.spec.d.ts +2 -0
- package/lib/main/browser/webviews-main.spec.d.ts.map +1 -0
- package/lib/main/browser/webviews-main.spec.js +132 -0
- package/lib/main/browser/webviews-main.spec.js.map +1 -0
- package/package.json +31 -31
- package/src/main/browser/webviews-main.spec.ts +160 -0
- package/src/main/browser/webviews-main.ts +22 -19
|
@@ -33,7 +33,14 @@ export declare class WebviewsMainImpl implements WebviewsMain, Disposable {
|
|
|
33
33
|
protected restoreWidget(widget: WebviewWidget): Promise<void>;
|
|
34
34
|
protected readonly updateViewStates: import("lodash").DebouncedFunc<() => void>;
|
|
35
35
|
private updateViewState;
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Looks up the webview widget for the given handle.
|
|
38
|
+
*
|
|
39
|
+
* All `$`-methods of this class are invoked over RPC and resolve the widget asynchronously, so the webview may already
|
|
40
|
+
* have been disposed by the time they run. The plugin host declares most of them as returning `void` and therefore never
|
|
41
|
+
* attaches a rejection handler, so throwing here surfaces as an unhandled promise rejection in the plugin host. Callers
|
|
42
|
+
* must instead treat a missing webview as a no-op, the same way VS Code's `MainThreadWebviews` does.
|
|
43
|
+
*/
|
|
37
44
|
private tryGetWebview;
|
|
38
45
|
}
|
|
39
46
|
//# sourceMappingURL=webviews-main.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webviews-main.d.ts","sourceRoot":"","sources":["../../../src/main/browser/webviews-main.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE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,QAAQ,EAAE,MAAM,GAAG,IAAI;IAK3C,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;cAI7B,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IA0BnE,SAAS,CAAC,QAAQ,CAAC,gBAAgB,6CAS3B;IAER,OAAO,CAAC,eAAe;IAkBvB;;;;;;;OAOG;YACW,aAAa;CAW9B"}
|
|
@@ -123,8 +123,8 @@ class WebviewsMainImpl {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
async $reveal(handle, showOptions) {
|
|
126
|
-
const widget = await this.
|
|
127
|
-
if (widget.isDisposed) {
|
|
126
|
+
const widget = await this.tryGetWebview(handle);
|
|
127
|
+
if (!widget || widget.isDisposed) {
|
|
128
128
|
return;
|
|
129
129
|
}
|
|
130
130
|
if ((showOptions.viewColumn !== undefined && showOptions.viewColumn !== widget.viewState.position) || showOptions.area !== undefined) {
|
|
@@ -144,19 +144,24 @@ class WebviewsMainImpl {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
async $setTitle(handle, value) {
|
|
147
|
-
const webview = await this.
|
|
148
|
-
webview
|
|
147
|
+
const webview = await this.tryGetWebview(handle);
|
|
148
|
+
if (webview) {
|
|
149
|
+
webview.title.label = value;
|
|
150
|
+
}
|
|
149
151
|
}
|
|
150
152
|
async $setIconPath(handle, iconUrl) {
|
|
151
|
-
const webview = await this.
|
|
152
|
-
webview
|
|
153
|
+
const webview = await this.tryGetWebview(handle);
|
|
154
|
+
webview?.setIconUrl(iconUrl);
|
|
153
155
|
}
|
|
154
156
|
async $setHtml(handle, value) {
|
|
155
|
-
const webview = await this.
|
|
156
|
-
webview
|
|
157
|
+
const webview = await this.tryGetWebview(handle);
|
|
158
|
+
webview?.setHTML(value);
|
|
157
159
|
}
|
|
158
160
|
async $setOptions(handle, options) {
|
|
159
|
-
const webview = await this.
|
|
161
|
+
const webview = await this.tryGetWebview(handle);
|
|
162
|
+
if (!webview) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
160
165
|
const { enableScripts, enableForms, localResourceRoots, ...contentOptions } = options;
|
|
161
166
|
webview.setContentOptions({
|
|
162
167
|
allowScripts: enableScripts,
|
|
@@ -167,8 +172,6 @@ class WebviewsMainImpl {
|
|
|
167
172
|
}
|
|
168
173
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
169
174
|
async $postMessage(handle, value) {
|
|
170
|
-
// Due to async nature of $postMessage, the webview may have been disposed in the meantime.
|
|
171
|
-
// Therefore, don't throw an error if the webview is not found, but return false in this case.
|
|
172
175
|
const webview = await this.tryGetWebview(handle);
|
|
173
176
|
if (!webview) {
|
|
174
177
|
return false;
|
|
@@ -224,13 +227,14 @@ class WebviewsMainImpl {
|
|
|
224
227
|
widget.viewState = viewState;
|
|
225
228
|
this.proxy.$onDidChangeWebviewPanelViewState(widget.identifier.id, widget.viewState);
|
|
226
229
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
230
|
+
/**
|
|
231
|
+
* Looks up the webview widget for the given handle.
|
|
232
|
+
*
|
|
233
|
+
* All `$`-methods of this class are invoked over RPC and resolve the widget asynchronously, so the webview may already
|
|
234
|
+
* have been disposed by the time they run. The plugin host declares most of them as returning `void` and therefore never
|
|
235
|
+
* attaches a rejection handler, so throwing here surfaces as an unhandled promise rejection in the plugin host. Callers
|
|
236
|
+
* must instead treat a missing webview as a no-op, the same way VS Code's `MainThreadWebviews` does.
|
|
237
|
+
*/
|
|
234
238
|
async tryGetWebview(id) {
|
|
235
239
|
const webview = await this.widgetManager.findWidget(webview_1.WebviewWidget.FACTORY_ID, options => {
|
|
236
240
|
if (options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webviews-main.js","sourceRoot":"","sources":["../../../src/main/browser/webviews-main.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,+CAA+C;AAC/C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF,+DAAgE;AAChE,8DAAoD;AAEpD,gEAA4H;AAG5H,uFAAmF;AACnF,+CAA2E;AAC3E,kEAAqF;AACrF,2FAAsF;AACtF,2EAAuE;AACvE,oEAA+D;AAE/D,sEAAyE;AAEzE,gFAA2E;AAC3E,wDAA6E;AAE7E,MAAa,gBAAgB;IASzB,YAAY,GAAgB,EAAE,SAA+B;QAF5C,cAAS,GAAG,IAAI,iCAAoB,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"webviews-main.js","sourceRoot":"","sources":["../../../src/main/browser/webviews-main.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,+CAA+C;AAC/C,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF,+DAAgE;AAChE,8DAAoD;AAEpD,gEAA4H;AAG5H,uFAAmF;AACnF,+CAA2E;AAC3E,kEAAqF;AACrF,2FAAsF;AACtF,2EAAuE;AACvE,oEAA+D;AAE/D,sEAAyE;AAEzE,gFAA2E;AAC3E,wDAA6E;AAE7E,MAAa,gBAAgB;IASzB,YAAY,GAAgB,EAAE,SAA+B;QAF5C,cAAS,GAAG,IAAI,iCAAoB,EAAE,CAAC;QAgMrC,qBAAgB,GAAG,QAAQ,CAAC,GAAG,EAAE;YAChD,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,uBAAa,CAAC,UAAU,CAAC,CAAC;YACxE,MAAM,aAAa,GAAG,IAAI,CAAC,aA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E,CAAC;gBACV,OAAO,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC;YAC7B,CAAC;YACD,OAAO,KAAK,CAAC;QACjB,CAAC,CAAC;eACK,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAqB,yCAAkB,CAAC,UAAU,EAA2B,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9H,OAAO,OAAO,CAAC;IACnB,CAAC;CAEJ;AAvPD,4CAuPC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webviews-main.spec.d.ts","sourceRoot":"","sources":["../../../src/main/browser/webviews-main.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2026 EclipseSource GmbH and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const frontend_application_config_provider_1 = require("@theia/core/lib/browser/frontend-application-config-provider");
|
|
19
|
+
const jsdom_1 = require("@theia/core/lib/browser/test/jsdom");
|
|
20
|
+
// `webviews-main` transitively pulls in Lumino and several frontend modules that touch
|
|
21
|
+
// `document` and the frontend application config at module-load time.
|
|
22
|
+
const disableJSDOM = (0, jsdom_1.enableJSDOM)();
|
|
23
|
+
try {
|
|
24
|
+
frontend_application_config_provider_1.FrontendApplicationConfigProvider.set({});
|
|
25
|
+
}
|
|
26
|
+
catch { /* already set by a sibling spec */ }
|
|
27
|
+
// xterm.js (pulled in transitively via the terminal package) calls HTMLCanvasElement.prototype.getContext
|
|
28
|
+
// at module-load time. JSDOM's default impl throws 'Not implemented' without the optional `canvas`
|
|
29
|
+
// package; replace it with a no-op so the module graph evaluates. The tests below never render a terminal.
|
|
30
|
+
const canvasProto = globalThis.HTMLCanvasElement?.prototype;
|
|
31
|
+
if (canvasProto) {
|
|
32
|
+
canvasProto.getContext = () => undefined;
|
|
33
|
+
}
|
|
34
|
+
const chai_1 = require("chai");
|
|
35
|
+
const webviews_main_1 = require("./webviews-main");
|
|
36
|
+
const webview_1 = require("./webview/webview");
|
|
37
|
+
after(() => disableJSDOM());
|
|
38
|
+
function createWebviewWidget() {
|
|
39
|
+
const widget = { isDisposed: false, title: { label: '' }, messages: [] };
|
|
40
|
+
return Object.assign(widget, {
|
|
41
|
+
setHTML: (value) => { widget.html = value; },
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
setContentOptions: (options) => { widget.contentOptions = options; },
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
setIconUrl: (iconUrl) => { widget.iconUrl = iconUrl; },
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
+
sendMessage: (value) => { widget.messages.push(value); }
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Bypasses the constructor's RPC/container wiring. The methods under test only resolve
|
|
52
|
+
* the webview widget through the widget manager, so stubbing that is enough.
|
|
53
|
+
*/
|
|
54
|
+
function createWebviewsMain(widgets) {
|
|
55
|
+
const impl = Object.create(webviews_main_1.WebviewsMainImpl.prototype);
|
|
56
|
+
impl.widgetManager = {
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
+
findWidget: async (factoryId, predicate) => {
|
|
59
|
+
if (factoryId !== webview_1.WebviewWidget.FACTORY_ID) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
for (const [id, widget] of widgets) {
|
|
63
|
+
if (predicate({ id })) {
|
|
64
|
+
return widget;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
},
|
|
69
|
+
getWidget: async () => undefined
|
|
70
|
+
};
|
|
71
|
+
return impl;
|
|
72
|
+
}
|
|
73
|
+
describe('WebviewsMainImpl - late calls for a disposed webview', () => {
|
|
74
|
+
const handle = 'webview-handle';
|
|
75
|
+
let widgets;
|
|
76
|
+
let webviewsMain;
|
|
77
|
+
beforeEach(() => {
|
|
78
|
+
widgets = new Map();
|
|
79
|
+
webviewsMain = createWebviewsMain(widgets);
|
|
80
|
+
});
|
|
81
|
+
// The plugin host declares these methods as returning `void` and never attaches a rejection
|
|
82
|
+
// handler, so throwing on an unknown handle would surface as an unhandled promise rejection.
|
|
83
|
+
describe('with an unknown handle', () => {
|
|
84
|
+
it('should not reject in $setHtml', async () => {
|
|
85
|
+
await webviewsMain.$setHtml(handle, '<html></html>');
|
|
86
|
+
});
|
|
87
|
+
it('should not reject in $setOptions', async () => {
|
|
88
|
+
await webviewsMain.$setOptions(handle, { enableScripts: true });
|
|
89
|
+
});
|
|
90
|
+
it('should not reject in $setTitle', async () => {
|
|
91
|
+
await webviewsMain.$setTitle(handle, 'Title');
|
|
92
|
+
});
|
|
93
|
+
it('should not reject in $setIconPath', async () => {
|
|
94
|
+
await webviewsMain.$setIconPath(handle, undefined);
|
|
95
|
+
});
|
|
96
|
+
it('should not reject in $reveal', async () => {
|
|
97
|
+
await webviewsMain.$reveal(handle, {});
|
|
98
|
+
});
|
|
99
|
+
it('should resolve to false in $postMessage', async () => {
|
|
100
|
+
(0, chai_1.expect)(await webviewsMain.$postMessage(handle, 'message')).to.be.false;
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
describe('with a known handle', () => {
|
|
104
|
+
let widget;
|
|
105
|
+
beforeEach(() => {
|
|
106
|
+
widget = createWebviewWidget();
|
|
107
|
+
widgets.set(handle, widget);
|
|
108
|
+
});
|
|
109
|
+
it('should apply the html in $setHtml', async () => {
|
|
110
|
+
await webviewsMain.$setHtml(handle, '<html></html>');
|
|
111
|
+
(0, chai_1.expect)(widget.html).to.equal('<html></html>');
|
|
112
|
+
});
|
|
113
|
+
it('should apply the content options in $setOptions', async () => {
|
|
114
|
+
await webviewsMain.$setOptions(handle, { enableScripts: true, enableForms: false, enableCommandUris: ['a.command'] });
|
|
115
|
+
(0, chai_1.expect)(widget.contentOptions).to.deep.equal({
|
|
116
|
+
allowScripts: true,
|
|
117
|
+
allowForms: false,
|
|
118
|
+
localResourceRoots: undefined,
|
|
119
|
+
enableCommandUris: ['a.command']
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
it('should apply the title in $setTitle', async () => {
|
|
123
|
+
await webviewsMain.$setTitle(handle, 'Title');
|
|
124
|
+
(0, chai_1.expect)(widget.title.label).to.equal('Title');
|
|
125
|
+
});
|
|
126
|
+
it('should send the message in $postMessage', async () => {
|
|
127
|
+
(0, chai_1.expect)(await webviewsMain.$postMessage(handle, 'message')).to.be.true;
|
|
128
|
+
(0, chai_1.expect)(widget.messages).to.deep.equal(['message']);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
//# sourceMappingURL=webviews-main.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webviews-main.spec.js","sourceRoot":"","sources":["../../../src/main/browser/webviews-main.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDA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.0-next.46+eb558223a",
|
|
4
4
|
"description": "Theia - Plugin Extension",
|
|
5
5
|
"main": "lib/common/index.js",
|
|
6
6
|
"typings": "lib/common/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@theia/ai-core": "1.75.0-next.
|
|
9
|
-
"@theia/ai-mcp": "1.75.0-next.
|
|
10
|
-
"@theia/bulk-edit": "1.75.0-next.
|
|
11
|
-
"@theia/callhierarchy": "1.75.0-next.
|
|
12
|
-
"@theia/console": "1.75.0-next.
|
|
13
|
-
"@theia/core": "1.75.0-next.
|
|
14
|
-
"@theia/debug": "1.75.0-next.
|
|
15
|
-
"@theia/editor": "1.75.0-next.
|
|
16
|
-
"@theia/editor-preview": "1.75.0-next.
|
|
17
|
-
"@theia/file-search": "1.75.0-next.
|
|
18
|
-
"@theia/filesystem": "1.75.0-next.
|
|
19
|
-
"@theia/markers": "1.75.0-next.
|
|
20
|
-
"@theia/messages": "1.75.0-next.
|
|
21
|
-
"@theia/monaco": "1.75.0-next.
|
|
8
|
+
"@theia/ai-core": "1.75.0-next.46+eb558223a",
|
|
9
|
+
"@theia/ai-mcp": "1.75.0-next.46+eb558223a",
|
|
10
|
+
"@theia/bulk-edit": "1.75.0-next.46+eb558223a",
|
|
11
|
+
"@theia/callhierarchy": "1.75.0-next.46+eb558223a",
|
|
12
|
+
"@theia/console": "1.75.0-next.46+eb558223a",
|
|
13
|
+
"@theia/core": "1.75.0-next.46+eb558223a",
|
|
14
|
+
"@theia/debug": "1.75.0-next.46+eb558223a",
|
|
15
|
+
"@theia/editor": "1.75.0-next.46+eb558223a",
|
|
16
|
+
"@theia/editor-preview": "1.75.0-next.46+eb558223a",
|
|
17
|
+
"@theia/file-search": "1.75.0-next.46+eb558223a",
|
|
18
|
+
"@theia/filesystem": "1.75.0-next.46+eb558223a",
|
|
19
|
+
"@theia/markers": "1.75.0-next.46+eb558223a",
|
|
20
|
+
"@theia/messages": "1.75.0-next.46+eb558223a",
|
|
21
|
+
"@theia/monaco": "1.75.0-next.46+eb558223a",
|
|
22
22
|
"@theia/monaco-editor-core": "1.108.201",
|
|
23
|
-
"@theia/navigator": "1.75.0-next.
|
|
24
|
-
"@theia/notebook": "1.75.0-next.
|
|
25
|
-
"@theia/output": "1.75.0-next.
|
|
26
|
-
"@theia/plugin": "1.75.0-next.
|
|
27
|
-
"@theia/plugin-utils": "1.75.0-next.
|
|
28
|
-
"@theia/preferences": "1.75.0-next.
|
|
29
|
-
"@theia/scm": "1.75.0-next.
|
|
30
|
-
"@theia/search-in-workspace": "1.75.0-next.
|
|
31
|
-
"@theia/task": "1.75.0-next.
|
|
32
|
-
"@theia/terminal": "1.75.0-next.
|
|
33
|
-
"@theia/test": "1.75.0-next.
|
|
34
|
-
"@theia/timeline": "1.75.0-next.
|
|
35
|
-
"@theia/typehierarchy": "1.75.0-next.
|
|
36
|
-
"@theia/variable-resolver": "1.75.0-next.
|
|
37
|
-
"@theia/workspace": "1.75.0-next.
|
|
23
|
+
"@theia/navigator": "1.75.0-next.46+eb558223a",
|
|
24
|
+
"@theia/notebook": "1.75.0-next.46+eb558223a",
|
|
25
|
+
"@theia/output": "1.75.0-next.46+eb558223a",
|
|
26
|
+
"@theia/plugin": "1.75.0-next.46+eb558223a",
|
|
27
|
+
"@theia/plugin-utils": "1.75.0-next.46+eb558223a",
|
|
28
|
+
"@theia/preferences": "1.75.0-next.46+eb558223a",
|
|
29
|
+
"@theia/scm": "1.75.0-next.46+eb558223a",
|
|
30
|
+
"@theia/search-in-workspace": "1.75.0-next.46+eb558223a",
|
|
31
|
+
"@theia/task": "1.75.0-next.46+eb558223a",
|
|
32
|
+
"@theia/terminal": "1.75.0-next.46+eb558223a",
|
|
33
|
+
"@theia/test": "1.75.0-next.46+eb558223a",
|
|
34
|
+
"@theia/timeline": "1.75.0-next.46+eb558223a",
|
|
35
|
+
"@theia/typehierarchy": "1.75.0-next.46+eb558223a",
|
|
36
|
+
"@theia/variable-resolver": "1.75.0-next.46+eb558223a",
|
|
37
|
+
"@theia/workspace": "1.75.0-next.46+eb558223a",
|
|
38
38
|
"@types/mime": "^2.0.3",
|
|
39
39
|
"@vscode/debugprotocol": "^1.68.0",
|
|
40
40
|
"@vscode/proxy-agent": "^0.13.2",
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
"nyc": {
|
|
100
100
|
"extends": "../../configs/nyc.json"
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "eb558223aae4b1ebf0a64deeb51741032cb8ea50"
|
|
103
103
|
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 EclipseSource GmbH and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
|
|
18
|
+
import { enableJSDOM } from '@theia/core/lib/browser/test/jsdom';
|
|
19
|
+
// `webviews-main` transitively pulls in Lumino and several frontend modules that touch
|
|
20
|
+
// `document` and the frontend application config at module-load time.
|
|
21
|
+
const disableJSDOM = enableJSDOM();
|
|
22
|
+
try { FrontendApplicationConfigProvider.set({}); } catch { /* already set by a sibling spec */ }
|
|
23
|
+
// xterm.js (pulled in transitively via the terminal package) calls HTMLCanvasElement.prototype.getContext
|
|
24
|
+
// at module-load time. JSDOM's default impl throws 'Not implemented' without the optional `canvas`
|
|
25
|
+
// package; replace it with a no-op so the module graph evaluates. The tests below never render a terminal.
|
|
26
|
+
const canvasProto = (globalThis as { HTMLCanvasElement?: { prototype: { getContext?: unknown } } }).HTMLCanvasElement?.prototype;
|
|
27
|
+
if (canvasProto) {
|
|
28
|
+
canvasProto.getContext = () => undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
import { expect } from 'chai';
|
|
32
|
+
import { WebviewsMainImpl } from './webviews-main';
|
|
33
|
+
import { WebviewWidget } from './webview/webview';
|
|
34
|
+
|
|
35
|
+
after(() => disableJSDOM());
|
|
36
|
+
|
|
37
|
+
interface FakeWebviewWidget {
|
|
38
|
+
isDisposed: boolean;
|
|
39
|
+
title: { label: string };
|
|
40
|
+
html?: string;
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
contentOptions?: any;
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
iconUrl?: any;
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
messages: any[];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function createWebviewWidget(): FakeWebviewWidget {
|
|
50
|
+
const widget: FakeWebviewWidget = { isDisposed: false, title: { label: '' }, messages: [] };
|
|
51
|
+
return Object.assign(widget, {
|
|
52
|
+
setHTML: (value: string) => { widget.html = value; },
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
+
setContentOptions: (options: any) => { widget.contentOptions = options; },
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
+
setIconUrl: (iconUrl: any) => { widget.iconUrl = iconUrl; },
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
+
sendMessage: (value: any) => { widget.messages.push(value); }
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Bypasses the constructor's RPC/container wiring. The methods under test only resolve
|
|
64
|
+
* the webview widget through the widget manager, so stubbing that is enough.
|
|
65
|
+
*/
|
|
66
|
+
function createWebviewsMain(widgets: Map<string, FakeWebviewWidget>): WebviewsMainImpl {
|
|
67
|
+
const impl = Object.create(WebviewsMainImpl.prototype) as WebviewsMainImpl;
|
|
68
|
+
(impl as unknown as Record<string, unknown>).widgetManager = {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
70
|
+
findWidget: async (factoryId: string, predicate: (options?: any) => boolean) => {
|
|
71
|
+
if (factoryId !== WebviewWidget.FACTORY_ID) {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
for (const [id, widget] of widgets) {
|
|
75
|
+
if (predicate({ id })) {
|
|
76
|
+
return widget;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
},
|
|
81
|
+
getWidget: async () => undefined
|
|
82
|
+
};
|
|
83
|
+
return impl;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
describe('WebviewsMainImpl - late calls for a disposed webview', () => {
|
|
87
|
+
|
|
88
|
+
const handle = 'webview-handle';
|
|
89
|
+
let widgets: Map<string, FakeWebviewWidget>;
|
|
90
|
+
let webviewsMain: WebviewsMainImpl;
|
|
91
|
+
|
|
92
|
+
beforeEach(() => {
|
|
93
|
+
widgets = new Map();
|
|
94
|
+
webviewsMain = createWebviewsMain(widgets);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// The plugin host declares these methods as returning `void` and never attaches a rejection
|
|
98
|
+
// handler, so throwing on an unknown handle would surface as an unhandled promise rejection.
|
|
99
|
+
describe('with an unknown handle', () => {
|
|
100
|
+
|
|
101
|
+
it('should not reject in $setHtml', async () => {
|
|
102
|
+
await webviewsMain.$setHtml(handle, '<html></html>');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should not reject in $setOptions', async () => {
|
|
106
|
+
await webviewsMain.$setOptions(handle, { enableScripts: true });
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should not reject in $setTitle', async () => {
|
|
110
|
+
await webviewsMain.$setTitle(handle, 'Title');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should not reject in $setIconPath', async () => {
|
|
114
|
+
await webviewsMain.$setIconPath(handle, undefined);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should not reject in $reveal', async () => {
|
|
118
|
+
await webviewsMain.$reveal(handle, {});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should resolve to false in $postMessage', async () => {
|
|
122
|
+
expect(await webviewsMain.$postMessage(handle, 'message')).to.be.false;
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('with a known handle', () => {
|
|
127
|
+
|
|
128
|
+
let widget: FakeWebviewWidget;
|
|
129
|
+
|
|
130
|
+
beforeEach(() => {
|
|
131
|
+
widget = createWebviewWidget();
|
|
132
|
+
widgets.set(handle, widget);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should apply the html in $setHtml', async () => {
|
|
136
|
+
await webviewsMain.$setHtml(handle, '<html></html>');
|
|
137
|
+
expect(widget.html).to.equal('<html></html>');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should apply the content options in $setOptions', async () => {
|
|
141
|
+
await webviewsMain.$setOptions(handle, { enableScripts: true, enableForms: false, enableCommandUris: ['a.command'] });
|
|
142
|
+
expect(widget.contentOptions).to.deep.equal({
|
|
143
|
+
allowScripts: true,
|
|
144
|
+
allowForms: false,
|
|
145
|
+
localResourceRoots: undefined,
|
|
146
|
+
enableCommandUris: ['a.command']
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should apply the title in $setTitle', async () => {
|
|
151
|
+
await webviewsMain.$setTitle(handle, 'Title');
|
|
152
|
+
expect(widget.title.label).to.equal('Title');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should send the message in $postMessage', async () => {
|
|
156
|
+
expect(await webviewsMain.$postMessage(handle, 'message')).to.be.true;
|
|
157
|
+
expect(widget.messages).to.deep.equal(['message']);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
});
|
|
@@ -135,8 +135,8 @@ export class WebviewsMainImpl implements WebviewsMain, Disposable {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
async $reveal(handle: string, showOptions: WebviewPanelShowOptions): Promise<void> {
|
|
138
|
-
const widget = await this.
|
|
139
|
-
if (widget.isDisposed) {
|
|
138
|
+
const widget = await this.tryGetWebview(handle);
|
|
139
|
+
if (!widget || widget.isDisposed) {
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
142
|
if ((showOptions.viewColumn !== undefined && showOptions.viewColumn !== widget.viewState.position) || showOptions.area !== undefined) {
|
|
@@ -156,22 +156,27 @@ export class WebviewsMainImpl implements WebviewsMain, Disposable {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
async $setTitle(handle: string, value: string): Promise<void> {
|
|
159
|
-
const webview = await this.
|
|
160
|
-
webview
|
|
159
|
+
const webview = await this.tryGetWebview(handle);
|
|
160
|
+
if (webview) {
|
|
161
|
+
webview.title.label = value;
|
|
162
|
+
}
|
|
161
163
|
}
|
|
162
164
|
|
|
163
165
|
async $setIconPath(handle: string, iconUrl: IconUrl | ThemeIcon | undefined): Promise<void> {
|
|
164
|
-
const webview = await this.
|
|
165
|
-
webview
|
|
166
|
+
const webview = await this.tryGetWebview(handle);
|
|
167
|
+
webview?.setIconUrl(iconUrl);
|
|
166
168
|
}
|
|
167
169
|
|
|
168
170
|
async $setHtml(handle: string, value: string): Promise<void> {
|
|
169
|
-
const webview = await this.
|
|
170
|
-
webview
|
|
171
|
+
const webview = await this.tryGetWebview(handle);
|
|
172
|
+
webview?.setHTML(value);
|
|
171
173
|
}
|
|
172
174
|
|
|
173
175
|
async $setOptions(handle: string, options: WebviewOptions): Promise<void> {
|
|
174
|
-
const webview = await this.
|
|
176
|
+
const webview = await this.tryGetWebview(handle);
|
|
177
|
+
if (!webview) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
175
180
|
const { enableScripts, enableForms, localResourceRoots, ...contentOptions } = options;
|
|
176
181
|
webview.setContentOptions({
|
|
177
182
|
allowScripts: enableScripts,
|
|
@@ -183,8 +188,6 @@ export class WebviewsMainImpl implements WebviewsMain, Disposable {
|
|
|
183
188
|
|
|
184
189
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
185
190
|
async $postMessage(handle: string, value: any): Promise<boolean> {
|
|
186
|
-
// Due to async nature of $postMessage, the webview may have been disposed in the meantime.
|
|
187
|
-
// Therefore, don't throw an error if the webview is not found, but return false in this case.
|
|
188
191
|
const webview = await this.tryGetWebview(handle);
|
|
189
192
|
if (!webview) {
|
|
190
193
|
return false;
|
|
@@ -257,14 +260,14 @@ export class WebviewsMainImpl implements WebviewsMain, Disposable {
|
|
|
257
260
|
this.proxy.$onDidChangeWebviewPanelViewState(widget.identifier.id, widget.viewState);
|
|
258
261
|
}
|
|
259
262
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
263
|
+
/**
|
|
264
|
+
* Looks up the webview widget for the given handle.
|
|
265
|
+
*
|
|
266
|
+
* All `$`-methods of this class are invoked over RPC and resolve the widget asynchronously, so the webview may already
|
|
267
|
+
* have been disposed by the time they run. The plugin host declares most of them as returning `void` and therefore never
|
|
268
|
+
* attaches a rejection handler, so throwing here surfaces as an unhandled promise rejection in the plugin host. Callers
|
|
269
|
+
* must instead treat a missing webview as a no-op, the same way VS Code's `MainThreadWebviews` does.
|
|
270
|
+
*/
|
|
268
271
|
private async tryGetWebview(id: string): Promise<WebviewWidget | undefined> {
|
|
269
272
|
const webview = await this.widgetManager.findWidget<WebviewWidget>(WebviewWidget.FACTORY_ID, options => {
|
|
270
273
|
if (options) {
|