Skip to content

Commit

Permalink
mini-browser: use secure host pattern on electron
Browse files Browse the repository at this point in the history
There is little use to configure how the mini-browser should serve files
on Electron, as using different origins should always work.
  • Loading branch information
paul-marechal committed Jun 8, 2021
1 parent 743ae32 commit 67f0b1e
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import { Endpoint, FrontendApplicationContribution } from '@theia/core/lib/browser';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { environment } from '@theia/core/shared/@theia/application-package';
import { inject, injectable, optional, postConstruct } from '@theia/core/shared/inversify';
import { v4 } from 'uuid';
import { MiniBrowserEndpoint } from '../../common/mini-browser-endpoint';
Expand All @@ -42,8 +43,7 @@ export class MiniBrowserEnvironment implements FrontendApplicationContribution {

@postConstruct()
protected postConstruct(): void {
this._hostPatternPromise = this.environment.getValue(MiniBrowserEndpoint.HOST_PATTERN_ENV)
.then(envVar => envVar?.value || MiniBrowserEndpoint.HOST_PATTERN_DEFAULT)
this._hostPatternPromise = this.getHostPattern()
.then(pattern => this.miniBrowserConfiguration.hostPattern = pattern);
if (this.miniBrowserGuard) {
this._hostPatternPromise
Expand All @@ -68,6 +68,13 @@ export class MiniBrowserEnvironment implements FrontendApplicationContribution {
return this.getEndpoint(v4());
}

protected async getHostPattern(): Promise<string> {
return environment.electron.is()
? MiniBrowserEndpoint.HOST_PATTERN_DEFAULT
: this.environment.getValue(MiniBrowserEndpoint.HOST_PATTERN_ENV)
.then(envVar => envVar?.value || MiniBrowserEndpoint.HOST_PATTERN_DEFAULT);
}

protected getDefaultHostname(): string {
return self.location.host;
}
Expand Down

0 comments on commit 67f0b1e

Please sign in to comment.