From 41dc697ef13fa5bad401fb41998e46aad1abb9ba Mon Sep 17 00:00:00 2001 From: Rob Lourens Date: Fri, 3 May 2024 13:33:42 -0700 Subject: [PATCH] Simplify service --- .../contrib/chat/browser/chatListRenderer.ts | 2 +- .../url/browser/trustedDomainService.ts | 19 +++---------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/src/vs/workbench/contrib/chat/browser/chatListRenderer.ts b/src/vs/workbench/contrib/chat/browser/chatListRenderer.ts index 1a177ddd8ad..a05023440ee 100644 --- a/src/vs/workbench/contrib/chat/browser/chatListRenderer.ts +++ b/src/vs/workbench/contrib/chat/browser/chatListRenderer.ts @@ -1043,7 +1043,7 @@ export class ChatListItemRenderer extends Disposable implements ITreeRenderer this.trustedDomainService.isValidSync(uri), + remoteImageIsAllowed: (uri) => this.trustedDomainService.isValid(uri), fillInIncompleteTokens, codeBlockRendererSync: (languageId, text) => { const index = codeBlockIndex++; diff --git a/src/vs/workbench/contrib/url/browser/trustedDomainService.ts b/src/vs/workbench/contrib/url/browser/trustedDomainService.ts index d35f973f31a..a89f8ceeb54 100644 --- a/src/vs/workbench/contrib/url/browser/trustedDomainService.ts +++ b/src/vs/workbench/contrib/url/browser/trustedDomainService.ts @@ -17,12 +17,7 @@ export const ITrustedDomainService = createDecorator('ITr export interface ITrustedDomainService { _serviceBrand: undefined; - isValid(resource: URI): Promise; - - /** - * This method does the validity check using the latest cached values of trusted domains, which may be slightly out of date. - */ - isValidSync(resource: URI): boolean; + isValid(resource: URI): boolean; } export class TrustedDomainService extends Disposable implements ITrustedDomainService { @@ -52,20 +47,12 @@ export class TrustedDomainService extends Disposable implements ITrustedDomainSe })); } - async isValid(resource: URI): Promise { + isValid(resource: URI): boolean { const { defaultTrustedDomains, trustedDomains, } = this._instantiationService.invokeFunction(readStaticTrustedDomains); const allTrustedDomains = [...defaultTrustedDomains, ...trustedDomains]; return isURLDomainTrusted(resource, allTrustedDomains); } - - isValidSync(resource: URI): boolean { - const allTrustedDomains = [ - ...this._staticTrustedDomainsResult.value, - ]; - - return isURLDomainTrusted(resource, allTrustedDomains); - } } const rLocalhost = /^localhost(:\d+)?$/i; @@ -98,7 +85,7 @@ function normalizeURL(url: string | URI): string { * - There's no subdomain matching. For example https://microsoft.com doesn't match https://www.microsoft.com * - Star matches all subdomains. For example https://*.microsoft.com matches https://www.microsoft.com and https://foo.bar.microsoft.com */ -export function isURLDomainTrusted(url: URI, trustedDomains: string[]) { +export function isURLDomainTrusted(url: URI, trustedDomains: string[]): boolean { url = URI.parse(normalizeURL(url)); trustedDomains = trustedDomains.map(normalizeURL);