Skip to content

Commit

Permalink
pipe workspace boolean for opener service validator
Browse files Browse the repository at this point in the history
fixes #150828
  • Loading branch information
sbatten committed Jul 18, 2022
1 parent ce2b88b commit c3db98c
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/vs/editor/browser/services/openerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class OpenerService implements IOpenerService {
// validate against the original URI that this URI resolves to, if one exists
const validationTarget = this._resolvedUriTargets.get(targetURI) ?? target;
for (const validator of this._validators) {
if (!(await validator.shouldOpen(validationTarget))) {
if (!(await validator.shouldOpen(validationTarget, options))) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/editor/contrib/links/browser/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class LinkDetector extends Disposable implements IEditorContribution {
}
}

return this.openerService.open(uri, { openToSide, fromUserGesture, allowContributedOpeners: true, allowCommands: true });
return this.openerService.open(uri, { openToSide, fromUserGesture, allowContributedOpeners: true, allowCommands: true, fromWorkspace: true });

}, err => {
const messageOrError =
Expand Down
3 changes: 2 additions & 1 deletion src/vs/platform/opener/common/opener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type OpenExternalOptions = {
readonly openExternal?: boolean;
readonly allowTunneling?: boolean;
readonly allowContributedOpeners?: boolean | string;
readonly fromWorkspace?: boolean;
};

export type OpenOptions = OpenInternalOptions & OpenExternalOptions;
Expand All @@ -61,7 +62,7 @@ export interface IExternalOpener {
}

export interface IValidator {
shouldOpen(resource: URI | string): Promise<boolean>;
shouldOpen(resource: URI | string, openOptions?: OpenOptions): Promise<boolean>;
}

export interface IExternalUriResolver {
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/browser/mainThreadWebviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class MainThreadWebviews extends Disposable implements extHostProtocol.Ma
private onDidClickLink(handle: extHostProtocol.WebviewHandle, link: string): void {
const webview = this.getWebview(handle);
if (this.isSupportedLink(webview, URI.parse(link))) {
this._openerService.open(link, { fromUserGesture: true, allowContributedOpeners: true, allowCommands: true });
this._openerService.open(link, { fromUserGesture: true, allowContributedOpeners: true, allowCommands: true, fromWorkspace: true });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Severity from 'vs/base/common/severity';
import { URI } from 'vs/base/common/uri';
import { localize } from 'vs/nls';
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IOpenerService, matchesScheme } from 'vs/platform/opener/common/opener';
import { IOpenerService, matchesScheme, OpenOptions } from 'vs/platform/opener/common/opener';
import { IProductService } from 'vs/platform/product/common/productService';
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
import { IStorageService } from 'vs/platform/storage/common/storage';
Expand Down Expand Up @@ -45,7 +45,7 @@ export class OpenerValidatorContributions implements IWorkbenchContribution {
@IConfigurationService private readonly _configurationService: IConfigurationService,
@IWorkspaceTrustManagementService private readonly _workspaceTrustService: IWorkspaceTrustManagementService,
) {
this._openerService.registerValidator({ shouldOpen: r => this.validateLink(r) });
this._openerService.registerValidator({ shouldOpen: (uri, options) => this.validateLink(uri, options) });

this._readAuthenticationTrustedDomainsResult = new IdleValue(() =>
this._instantiationService.invokeFunction(readAuthenticationTrustedDomains));
Expand All @@ -64,12 +64,12 @@ export class OpenerValidatorContributions implements IWorkbenchContribution {
});
}

async validateLink(resource: URI | string): Promise<boolean> {
async validateLink(resource: URI | string, openOptions?: OpenOptions): Promise<boolean> {
if (!matchesScheme(resource, Schemas.http) && !matchesScheme(resource, Schemas.https)) {
return true;
}

if (this._workspaceTrustService.isWorkspaceTrusted() && !this._configurationService.getValue('workbench.trustedDomains.promptInTrustedWorkspace')) {
if (openOptions?.fromWorkspace && this._workspaceTrustService.isWorkspaceTrusted() && !this._configurationService.getValue('workbench.trustedDomains.promptInTrustedWorkspace')) {
return true;
}

Expand Down

0 comments on commit c3db98c

Please sign in to comment.