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 9, 2021
1 parent 743ae32 commit 1755e26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 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/lib/environment';
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
5 changes: 2 additions & 3 deletions packages/mini-browser/src/browser/mini-browser-guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ export class MiniBrowserGuard {
case 'Always Prevent':
this.setMiniBrowserPreference('mini-browser.previewFile.preventUnsecure', 'alwaysPrevent');
case 'Prevent':
case undefined:
case undefined: // closed dialog
throw this.preventOpeningLocation(location);
case 'Always Open':
this.setMiniBrowserPreference('mini-browser.previewFile.preventUnsecure', 'alwaysPrevent');
this.setMiniBrowserPreference('mini-browser.previewFile.preventUnsecure', 'alwaysOpen');
case 'Open':
return;
}
}

Expand Down

0 comments on commit 1755e26

Please sign in to comment.