-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
15c06a8
[webview] delete 'vscode.previewHtml' command
akosyakov 95b9691
[webview] fix #5648: integrate webviews with the application shell
akosyakov 5a1b062
[webview] secure webviews
akosyakov 6f4879e
[webview] fix #5647: restore webviews
akosyakov 0b43c51
[webview] open links via OpenerService
akosyakov a000a27
[webview] fix #5521: emulate webview focus when something is focused …
akosyakov 64c49f8
[webview] fix #5786: unify the icon path resolution
akosyakov 93e23c2
[wbview] fix #5518: apply theming
akosyakov 766dfd7
[theming] #4831: color contribution point
akosyakov 2e7fca7
[webview] retain iframe when widget is hidden only when `retainContex…
akosyakov ff9a58c
[plugin]: support webview port mapping and external URIs
akosyakov 6e84132
[plugin] register command open handler
akosyakov ef478b4
[webview] compliance to vscode webview api tests 1.40.0
akosyakov e462ae7
[webivew] clarify breaking changes for adopters
akosyakov 4a89eff
[maximized] fix #6453: send attach/detach messages to widgets
akosyakov cabe495
[webview] cross instance browser based resource caching
akosyakov 73f7c56
[plugin] move vscode built-ins translation to manifest loading
akosyakov fa9e20e
[core] open mailto with an external window
akosyakov 7d3856f
[webview] treat vscode-resource equally to theia-resource
akosyakov 6831b91
[webview] translate http vscode-resource links to file links
akosyakov 98e8bd9
[webview] fix computation of view columns
akosyakov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,29 @@ Breaking changes: | |
- [core] renamed preference `list.openMode` to `workbench.list.openMode` [#6481](https://github.com/eclipse-theia/theia/pull/6481) | ||
- [task] changed `TaskSchemaUpdater.update()` from asynchronous to synchronous [#6483](https://github.com/eclipse-theia/theia/pull/6483) | ||
- [monaco] monaco prefix has been removed from commands [#5590](https://github.com/eclipse-theia/theia/pull/5590) | ||
- [plugin] webviews are reimplemented to align with [VS Code browser implementation](https://blog.mattbierner.com/vscode-webview-web-learnings/) [#6465](https://github.com/eclipse-theia/theia/pull/6465) | ||
- Security: `vscode.previewHTML` is removed, see https://code.visualstudio.com/updates/v1_33#_removing-the-vscodepreviewhtml-command | ||
- Security: Before all webviews were deployed on [the same origin](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy) | ||
allowing them to break out and manipulate shared data as cookies, local storage or even start service workers | ||
for the main window as well as for each other. Now each webview will be deployed on own origin by default. | ||
- Webview origin pattern can be configured with `THEIA_WEBVIEW_EXTERNAL_ENDPOINT` env variable. The default value is `{{uuid}}.webview.{{hostname}}`. | ||
Here `{{uuid}}` and `{{hostname}}` are placeholders which get replaced at runtime with proper webview uuid | ||
and [hostname](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/hostname) correspondingly. | ||
- To switch to unsecure mode as before configure `THEIA_WEBVIEW_EXTERNAL_ENDPOINT` with `{{hostname}}` as a value. | ||
You can also drop `{{uuid}}.` prefix, in this case, webviews still will be able to access each other but not the main window. | ||
- Remote: Local URIs are resolved by default to the host serving Theia. | ||
If you want to resolve to another host or change how remote URIs are constructed then | ||
implement [ExternalUriService.resolve](./packages/core/src/browser/external-uri-service.ts) in a frontend module. | ||
- Content loading: Webview HTTP endpoint is removed. Content loaded via [WebviewResourceLoader](./packages/plugin-ext/src/main/common/webview-protocol.ts) JSON-RPC service | ||
with properly preserved resource URIs. Content is only loaded if it's allowed by WebviewOptions.localResourceRoots, otherwise, the service won't be called. | ||
If you want to customize content loading then implement [WebviewResourceLoaderImpl](packages/plugin-ext/src/main/node/webview-resource-loader-impl.ts) in a backend module. | ||
- Theming: Theia styles are not applied to webviews anymore | ||
instead [VS Code way of styling](https://code.visualstudio.com/api/extension-guides/webview#theming-webview-content) should be used. | ||
VS Code color variables also available with `--theia` prefix. | ||
- Testing: Webview can work only in secure context because they rely on service workers to load local content and redirect local to remote requests. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AndrienkoAleksandr added a section here about local testing |
||
Most browsers define a page as served from secure context if its url has `https` scheme. For local testing `localhost` is treated as a secure context as well. | ||
Unfortunately, it does not work nicely in FireFox, since it does not treat subdomains of localhost as secure as well, compare to Chrome. | ||
If you want to test with FireFox you can configure it as described [here](https://github.com/eclipse-theia/theia/pull/6465#issuecomment-556443218). | ||
|
||
## v0.12.0 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
packages/core/src/browser/color-application-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { injectable, inject, named } from 'inversify'; | ||
import { ColorRegistry } from './color-registry'; | ||
import { Emitter } from '../common/event'; | ||
import { ThemeService } from './theming'; | ||
import { FrontendApplicationContribution } from './frontend-application'; | ||
import { ContributionProvider } from '../common/contribution-provider'; | ||
import { Disposable, DisposableCollection } from '../common/disposable'; | ||
|
||
export const ColorContribution = Symbol('ColorContribution'); | ||
export interface ColorContribution { | ||
registerColors(colors: ColorRegistry): void; | ||
} | ||
|
||
@injectable() | ||
export class ColorApplicationContribution implements FrontendApplicationContribution { | ||
|
||
protected readonly onDidChangeEmitter = new Emitter<void>(); | ||
readonly onDidChange = this.onDidChangeEmitter.event; | ||
|
||
@inject(ColorRegistry) | ||
protected readonly colors: ColorRegistry; | ||
|
||
@inject(ContributionProvider) @named(ColorContribution) | ||
protected readonly colorContributions: ContributionProvider<ColorContribution>; | ||
|
||
onStart(): void { | ||
for (const contribution of this.colorContributions.getContributions()) { | ||
contribution.registerColors(this.colors); | ||
} | ||
|
||
this.update(); | ||
ThemeService.get().onThemeChange(() => this.update()); | ||
} | ||
|
||
protected readonly toUpdate = new DisposableCollection(); | ||
protected update(): void { | ||
if (!document) { | ||
return; | ||
} | ||
this.toUpdate.dispose(); | ||
const theme = 'theia-' + ThemeService.get().getCurrentTheme().type; | ||
document.body.classList.add(theme); | ||
this.toUpdate.push(Disposable.create(() => document.body.classList.remove(theme))); | ||
|
||
const documentElement = document.documentElement; | ||
if (documentElement) { | ||
for (const id of this.colors.getColors()) { | ||
const color = this.colors.getCurrentColor(id); | ||
if (color) { | ||
const propertyName = `--theia-${id.replace('.', '-')}`; | ||
documentElement.style.setProperty(propertyName, color); | ||
this.toUpdate.push(Disposable.create(() => documentElement.style.removeProperty(propertyName))); | ||
} | ||
} | ||
} | ||
this.onDidChangeEmitter.fire(undefined); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { injectable } from 'inversify'; | ||
import { Disposable } from '../common/disposable'; | ||
|
||
export interface ColorDefaults { | ||
light?: string | ||
dark?: string | ||
hc?: string | ||
} | ||
|
||
export interface ColorOptions { | ||
defaults?: ColorDefaults | ||
description: string | ||
} | ||
|
||
/** | ||
* It should be implemented by an extension, e.g. by the monaco extension. | ||
*/ | ||
@injectable() | ||
export class ColorRegistry { | ||
|
||
*getColors(): IterableIterator<string> { } | ||
|
||
getCurrentColor(id: string): string | undefined { | ||
return undefined; | ||
} | ||
|
||
register(id: string, options: ColorOptions): Disposable { | ||
return Disposable.NULL; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/******************************************************************************** | ||
* Copyright (C) 2019 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
|
||
import { injectable } from 'inversify'; | ||
import URI from '../common/uri'; | ||
import { MaybePromise } from '../common/types'; | ||
import { Endpoint } from './endpoint'; | ||
|
||
@injectable() | ||
export class ExternalUriService { | ||
|
||
/** | ||
* Maps local to remote URLs. | ||
* Should be no-op if the given URL is not a localhost URL. | ||
* | ||
* By default maps to an origin serving Theia. | ||
* | ||
* Use `parseLocalhost` to retrive localhost address and port information. | ||
*/ | ||
resolve(uri: URI): MaybePromise<URI> { | ||
const localhost = this.parseLocalhost(uri); | ||
if (localhost) { | ||
return this.toRemoteUrl(uri, localhost); | ||
} | ||
return uri; | ||
} | ||
|
||
protected toRemoteUrl(uri: URI, localhost: { address: string, port: number }): URI { | ||
paul-marechal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const host = this.toRemoteHost(localhost); | ||
return new Endpoint({ host }).getRestUrl().withPath(uri.path).withFragment(uri.fragment).withQuery(uri.query); | ||
} | ||
|
||
protected toRemoteHost(localhost: { address: string, port: number }): string { | ||
paul-marechal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return `${window.location.hostname}:${localhost.port}`; | ||
} | ||
|
||
parseLocalhost(uri: URI): { address: string, port: number } | undefined { | ||
if (uri.scheme !== 'http' && uri.scheme !== 'https') { | ||
return undefined; | ||
} | ||
const localhostMatch = /^(localhost|127\.0\.0\.1|0\.0\.0\.0):(\d+)$/.exec(uri.authority); | ||
if (!localhostMatch) { | ||
return undefined; | ||
} | ||
return { | ||
address: localhostMatch[1], | ||
port: +localhostMatch[2], | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benoitf @olexii4 @evidolob @mmorhun I've tried to capture breaking changes required to align with VS Code here. I hope it would be helpful to adopt them in Che. If some APIs don't have enough information please do follow-up PRs during migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@amiramw @idoprz I'm not sure how it is important for you. Just pinging, since you run plugins in sidecar containers as well.