Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete support of webviews #6465

Merged
merged 21 commits into from
Nov 22, 2019
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
15c06a8
[webview] delete 'vscode.previewHtml' command
akosyakov Oct 28, 2019
95b9691
[webview] fix #5648: integrate webviews with the application shell
akosyakov Oct 28, 2019
5a1b062
[webview] secure webviews
akosyakov Oct 29, 2019
6f4879e
[webview] fix #5647: restore webviews
akosyakov Oct 30, 2019
0b43c51
[webview] open links via OpenerService
akosyakov Oct 30, 2019
a000a27
[webview] fix #5521: emulate webview focus when something is focused …
akosyakov Oct 30, 2019
64c49f8
[webview] fix #5786: unify the icon path resolution
akosyakov Oct 31, 2019
93e23c2
[wbview] fix #5518: apply theming
akosyakov Oct 31, 2019
766dfd7
[theming] #4831: color contribution point
akosyakov Oct 31, 2019
2e7fca7
[webview] retain iframe when widget is hidden only when `retainContex…
akosyakov Nov 6, 2019
ff9a58c
[plugin]: support webview port mapping and external URIs
akosyakov Nov 7, 2019
6e84132
[plugin] register command open handler
akosyakov Nov 7, 2019
ef478b4
[webview] compliance to vscode webview api tests 1.40.0
akosyakov Nov 8, 2019
e462ae7
[webivew] clarify breaking changes for adopters
akosyakov Nov 14, 2019
4a89eff
[maximized] fix #6453: send attach/detach messages to widgets
akosyakov Nov 14, 2019
cabe495
[webview] cross instance browser based resource caching
akosyakov Nov 16, 2019
73f7c56
[plugin] move vscode built-ins translation to manifest loading
akosyakov Nov 18, 2019
fa9e20e
[core] open mailto with an external window
akosyakov Nov 18, 2019
7d3856f
[webview] treat vscode-resource equally to theia-resource
akosyakov Nov 18, 2019
6831b91
[webview] translate http vscode-resource links to file links
akosyakov Nov 19, 2019
98e8bd9
[webview] fix computation of view columns
akosyakov Nov 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[webview] translate http vscode-resource links to file links
to open them with an appropriate open handler

Signed-off-by: Anton Kosyakov <anton.kosyakov@typefox.io>
akosyakov committed Nov 22, 2019
commit 6831b9173e99c99957964a3c457a3c198e9f4427
35 changes: 21 additions & 14 deletions packages/plugin-ext/src/main/browser/webview/webview.ts
Original file line number Diff line number Diff line change
@@ -272,12 +272,7 @@ export class WebviewWidget extends BaseWidget implements StatefulWidget {
/* no-op: webview loses focus only if another element gains focus in the main window */
}));
this.toHide.push(this.on(WebviewMessageChannels.doReload, () => this.reload()));
this.toHide.push(this.on(WebviewMessageChannels.loadResource, (entry: any) => {
const rawPath = entry.path;
const normalizedPath = decodeURIComponent(rawPath);
const uri = new URI(normalizedPath.replace(/^\/(\w+)\/(.+)$/, (_, scheme, path) => scheme + ':/' + path));
this.loadResource(rawPath, uri);
}));
this.toHide.push(this.on(WebviewMessageChannels.loadResource, (entry: any) => this.loadResource(entry.path)));
this.toHide.push(this.on(WebviewMessageChannels.loadLocalhost, (entry: any) =>
this.loadLocalhost(entry.origin)
));
@@ -412,20 +407,30 @@ export class WebviewWidget extends BaseWidget implements StatefulWidget {
}

protected openLink(link: URI): void {
if (this.isSupportedLink(link)) {
open(this.openerService, link);
const supported = this.toSupportedLink(link);
if (supported) {
open(this.openerService, supported);
}
}

protected isSupportedLink(link: URI): boolean {
protected toSupportedLink(link: URI): URI | undefined {
if (WebviewWidget.standardSupportedLinkSchemes.has(link.scheme)) {
return true;
const linkAsString = link.toString();
for (const resourceRoot of [this.externalEndpoint + '/theia-resource', this.externalEndpoint + '/vscode-resource']) {
if (linkAsString.startsWith(resourceRoot + '/')) {
return this.normalizeRequestUri(linkAsString.substr(resourceRoot.length));
}
}
return link;
}
if (!!this.contentOptions.enableCommandUris && link.scheme === Schemes.COMMAND) {
return link;
}
return !!this.contentOptions.enableCommandUris && link.scheme === Schemes.COMMAND;
return undefined;
}

protected async loadResource(requestPath: string, uri: URI): Promise<void> {
const normalizedUri = this.normalizeRequestUri(uri);
protected async loadResource(requestPath: string): Promise<void> {
const normalizedUri = this.normalizeRequestUri(requestPath);
// browser cache does not suppot file scheme, normalize to current endpoint scheme and host
const cacheUrl = new Endpoint({ path: normalizedUri.path.toString() }).getRestUrl().toString();

@@ -464,7 +469,9 @@ export class WebviewWidget extends BaseWidget implements StatefulWidget {
});
}

protected normalizeRequestUri(requestUri: URI): URI {
protected normalizeRequestUri(requestPath: string): URI {
const normalizedPath = decodeURIComponent(requestPath);
const requestUri = new URI(normalizedPath.replace(/^\/(\w+)\/(.+)$/, (_, scheme, path) => scheme + ':/' + path));
if (requestUri.scheme !== 'theia-resource' && requestUri.scheme !== 'vscode-resource') {
return requestUri;
}