extensionResourceLoader.ts ×12

Frontier kind: Code frontier

unlabeled · c_1663463cb3ef

14 tests · 22898 LOC · 135 files · introduces 0 tests · 89 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
12 ranges89 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
2587 ranges22898 lines · 135 files · Browse complete extent
All tests (intent)
14 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 89 introduced LOC across 12 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/extensionResourceLoader/common/extensionResourceLoader.ts 89 introduced LOC · 12 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- extensionResourceLoader.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { isWeb } from '../../../base/common/platform.js';
7 > import { format2 } from '../../../base/common/strings.js';
8 > import { URI } from '../../../base/common/uri.js';
9 > import { IConfigurationService } from '../../configuration/common/configuration.js';
10 > import { IEnvironmentService } from '../../environment/common/environment.js';
11 > import { IFileService } from '../../files/common/files.js';
12 > import { createDecorator } from '../../instantiation/common/instantiation.js';
13 > import { IProductService } from '../../product/common/productService.js';
14 > import { getServiceMachineId } from '../../externalServices/common/serviceMachineId.js';
15 > import { IStorageService } from '../../storage/common/storage.js';
16 > import { TelemetryLevel } from '../../telemetry/common/telemetry.js';
17 > import { getTelemetryLevel, supportsTelemetry } from '../../telemetry/common/telemetryUtils.js';
18 > import { RemoteAuthorities } from '../../../base/common/network.js';
19 > import { TargetPlatform } from '../../extensions/common/extensions.js';
20 > import { ExtensionGalleryResourceType, getExtensionGalleryManifestResourceUri, IExtensionGalleryManifest, IExtensionGalleryManifestService } from '../../extensionManagement/common/extensionGalleryManifest.js';
21 > import { ILogService } from '../../log/common/log.js';
22 > import { Disposable } from '../../../base/common/lifecycle.js';
23 >
24 > const WEB_EXTENSION_RESOURCE_END_POINT_SEGMENT = '/web-extension-resource/';
25 >
26 > export const IExtensionResourceLoaderService = createDecorator<IExtensionResourceLoaderService>('extensionResourceLoaderService');
27 >
28 > /**
29 > * A service useful for reading resources from within extensions.
30 > */
31 > export interface IExtensionResourceLoaderService {
32 > readonly _serviceBrand: undefined;
33 >
34 > /**
35 > * Read a certain resource within an extension.
36 > */
37 > readExtensionResource(uri: URI): Promise<string>;
38 >
39 > /**
40 > * Returns whether the gallery provides extension resources.
41 > */
42 > supportsExtensionGalleryResources(): Promise<boolean>;
43 >
44 > /**
45 > * Return true if the given URI is a extension gallery resource.
46 > */
47 > isExtensionGalleryResource(uri: URI): Promise<boolean>;
48 >
49 > /**
50 > * Computes the URL of a extension gallery resource. Returns `undefined` if gallery does not provide extension resources.
51 > */
52 > getExtensionGalleryResourceURL(galleryExtension: { publisher: string; name: string; version: string; targetPlatform?: TargetPlatform }, path?: string): Promise<URI | undefined>;
53 > }
54 >
55 > export function migratePlatformSpecificExtensionGalleryResourceURL(resource: URI, targetPlatform: TargetPlatform): URI | undefined {
56 if (resource.query !== `target=${targetPlatform}`) {
57 return undefined;
64 return resource.with({ query: null, path: paths.join('/') });
65 }
67 > export abstract class AbstractExtensionResourceLoaderService extends Disposable implements IExtensionResourceLoaderService {
68 >
69 > readonly _serviceBrand: undefined;
70 >
71 > private readonly _initPromise: Promise<void>;
72 >
73 > private _extensionGalleryResourceUrlTemplate: string | undefined;
74 > private _extensionGalleryAuthority: string | undefined;
75 >
76 > constructor(
77 protected readonly _fileService: IFileService,
78 private readonly _storageService: IStorageService,
86 this._initPromise = this._init();
87 }
89 > private async _init(): Promise<void> {
90 try {
91 const manifest = await this._extensionGalleryManifestService.getExtensionGalleryManifest();
96 }
97 }
99 > private resolve(manifest: IExtensionGalleryManifest | null): void {
100 this._extensionGalleryResourceUrlTemplate = manifest ? getExtensionGalleryManifestResourceUri(manifest, ExtensionGalleryResourceType.ExtensionResourceUri) : undefined;
101 this._extensionGalleryAuthority = this._extensionGalleryResourceUrlTemplate ? this._getExtensionGalleryAuthority(URI.parse(this._extensionGalleryResourceUrlTemplate)) : undefined;
102 }
104 > public async supportsExtensionGalleryResources(): Promise<boolean> {
105 await this._initPromise;
106 return this._extensionGalleryResourceUrlTemplate !== undefined;
107 }
109 > public async getExtensionGalleryResourceURL({ publisher, name, version, targetPlatform }: { publisher: string; name: string; version: string; targetPlatform?: TargetPlatform }, path?: string): Promise<URI | undefined> {
110 await this._initPromise;
111 if (this._extensionGalleryResourceUrlTemplate) {
125 return undefined;
126 }
128 > public abstract readExtensionResource(uri: URI): Promise<string>;
129 >
130 > async isExtensionGalleryResource(uri: URI): Promise<boolean> {
131 await this._initPromise;
132 return !!this._extensionGalleryAuthority && this._extensionGalleryAuthority === this._getExtensionGalleryAuthority(uri);
133 }
135 > protected async getExtensionGalleryRequestHeaders(): Promise<Record<string, string>> {
136 const headers: Record<string, string> = {
137 'X-Client-Name': `${this._productService.applicationName}${isWeb ? '-web' : ''}`,
146 return headers;
147 }
149 > private _serviceMachineIdPromise: Promise<string> | undefined;
150 > private _getServiceMachineId(): Promise<string> {
151 if (!this._serviceMachineIdPromise) {
152 this._serviceMachineIdPromise = getServiceMachineId(this._environmentService, this._fileService, this._storageService);
154 return this._serviceMachineIdPromise;
155 }
157 > private _getExtensionGalleryAuthority(uri: URI): string | undefined {
158 if (this._isWebExtensionResourceEndPoint(uri)) {
159 return uri.authority;
162 return index !== -1 ? uri.authority.substring(index + 1) : undefined;
163 }
165 > protected _isWebExtensionResourceEndPoint(uri: URI): boolean {
166 const uriPath = uri.path, serverRootPath = RemoteAuthorities.getServerRootPath();
167 // test if the path starts with the server root path followed by the web extension resource end point segment
168 return uriPath.startsWith(serverRootPath) && uriPath.startsWith(WEB_EXTENSION_RESOURCE_END_POINT_SEGMENT, serverRootPath.length);
169 }
171 > }