workspaceTrust.ts ×35

Frontier kind: Code frontier

unlabeled · c_729dae7ee7ed

6 tests · 25430 LOC · 136 files · introduces 0 tests · 148 LOC · 2 files

Introduces — evidence that enters the hierarchy at this concept

Code
36 ranges148 lines · 2 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
3225 ranges25430 lines · 136 files · Browse complete extent
All tests (intent)
6 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.

2 files ranked by introduced lines: 148 introduced LOC across 36 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/services/workspaces/common/workspaceTrust.ts 146 introduced LOC · 35 ranges

Open complete file

38 export class CanonicalWorkspace implements IWorkspace {
39 constructor(
40 > private readonly originalWorkspace: IWorkspace, workspaceTrust.ts
41 > private readonly canonicalFolderUris: URI[],
42 > private readonly canonicalConfiguration: URI | null | undefined
43 > ) { }
44
45
117
118 constructor(
119 > @IConfigurationService private readonly configurationService: IConfigurationService, workspaceTrust.ts
120 > @IRemoteAuthorityResolverService private readonly remoteAuthorityResolverService: IRemoteAuthorityResolverService,
121 > @IStorageService private readonly storageService: IStorageService,
122 > @IUriIdentityService private readonly uriIdentityService: IUriIdentityService,
123 > @IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
124 > @IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService,
125 > @IWorkspaceTrustEnablementService private readonly workspaceTrustEnablementService: IWorkspaceTrustEnablementService,
126 > @IFileService private readonly fileService: IFileService
127 > ) {
128 > super();
129 >
130 > this._canonicalUrisResolved = false;
131 > this._canonicalWorkspace = this.workspaceService.getWorkspace();
132 >
133 > ({ promise: this._workspaceResolvedPromise, resolve: this._workspaceResolvedPromiseResolve } = promiseWithResolvers());
134 > ({ promise: this._workspaceTrustInitializedPromise, resolve: this._workspaceTrustInitializedPromiseResolve } = promiseWithResolvers());
135 >
136 > this._storedTrustState = new WorkspaceTrustMemento(isWeb && this.isEmptyWorkspace() ? undefined : this.storageService);
137 > this._trustTransitionManager = this._register(new WorkspaceTrustTransitionManager());
138 >
139 > this._trustStateInfo = this.loadTrustInfo();
140 > this._isTrusted = this.calculateWorkspaceTrust();
141 >
142 > this.initializeWorkspaceTrust();
143 > this.registerListeners();
144 > }
145
146 //#region initialize
147
148 private initializeWorkspaceTrust(): void {
149 > // Resolve canonical Uris workspaceTrust.ts
150 > this.resolveCanonicalUris()
151 > .then(async () => {
152 > this._canonicalUrisResolved = true;
153 > await this.updateWorkspaceTrust();
154 > })
155 > .finally(() => {
156 > this._workspaceResolvedPromiseResolve();
157 >
158 > if (!this.environmentService.remoteAuthority) {
159 > this._workspaceTrustInitializedPromiseResolve();
160 > }
161 > });
162 >
163 > // Remote - resolve remote authority
164 > if (this.environmentService.remoteAuthority) {
165 this.remoteAuthorityResolverService.resolveAuthority(this.environmentService.remoteAuthority)
166 .then(async result => {
173 });
174 }
176 > // Empty workspace - save initial state to memento
177 > if (this.isEmptyWorkspace()) {
178 > this._workspaceTrustInitializedPromise.then(() => {
179 > if (this._storedTrustState.isEmptyWorkspaceTrusted === undefined) {
180 this._storedTrustState.isEmptyWorkspaceTrusted = this.isWorkspaceTrusted();
181 }
182 > }); workspaceTrust.ts
183 > }
184 > }
185
186 //#endregion
189
190 private registerListeners(): void {
191 > this._register(this.workspaceService.onDidChangeWorkspaceFolders(async () => await this.updateWorkspaceTrust())); workspaceTrust.ts
192 > this._register(this.storageService.onDidChangeValue(StorageScope.APPLICATION_SHARED, this.storageKey, this._store)(async () => {
193 /* This will only execute if storage was changed by a user action in a separate window */
194 if (JSON.stringify(this._trustStateInfo) !== JSON.stringify(this.loadTrustInfo())) {
198 await this.updateWorkspaceTrust();
199 }
200 > })); workspaceTrust.ts
201 > }
202
203 private async getCanonicalUri(uri: URI): Promise<URI> {
217
218 private async resolveCanonicalUris(): Promise<void> {
219 > // Open editors workspaceTrust.ts
220 > const filesToOpen: IPath[] = [];
221 > if (this.environmentService.filesToOpenOrCreate) {
222 filesToOpen.push(...this.environmentService.filesToOpenOrCreate);
223 }
225 > if (this.environmentService.filesToDiff) {
226 filesToOpen.push(...this.environmentService.filesToDiff);
227 }
229 > if (this.environmentService.filesToMerge) {
230 filesToOpen.push(...this.environmentService.filesToMerge);
231 }
233 > if (filesToOpen.length) {
234 const filesToOpenOrCreateUris = filesToOpen.filter(f => !!f.fileUri).map(f => f.fileUri!);
235 const canonicalFilesToOpen = await Promise.all(filesToOpenOrCreateUris.map(uri => this.getCanonicalUri(uri)));
237 this._canonicalStartupFiles.push(...canonicalFilesToOpen.filter(uri => this._canonicalStartupFiles.every(u => !this.uriIdentityService.extUri.isEqual(uri, u))));
238 }
240 > // Workspace
241 > const workspaceUris = this.workspaceService.getWorkspace().folders.map(f => f.uri);
242 > const canonicalWorkspaceFolders = await Promise.all(workspaceUris.map(uri => this.getCanonicalUri(uri)));
243 >
244 > let canonicalWorkspaceConfiguration = this.workspaceService.getWorkspace().configuration;
245 > if (canonicalWorkspaceConfiguration && isSavedWorkspace(canonicalWorkspaceConfiguration, this.environmentService)) {
246 canonicalWorkspaceConfiguration = await this.getCanonicalUri(canonicalWorkspaceConfiguration);
247 }
249 > this._canonicalWorkspace = new CanonicalWorkspace(this.workspaceService.getWorkspace(), canonicalWorkspaceFolders, canonicalWorkspaceConfiguration);
250 > }
251
252 private loadTrustInfo(): IWorkspaceTrustInfo {
253 > const infoAsString = this.storageService.get(this.storageKey, StorageScope.APPLICATION_SHARED); workspaceTrust.ts
254 >
255 > let result: IWorkspaceTrustInfo | undefined;
256 > try {
257 > if (infoAsString) {
258 result = JSON.parse(infoAsString);
259 }
260 > } catch { } workspaceTrust.ts
261 >
262 > if (!result) {
263 result = {
264 uriTrustInfo: []
265 };
266 }
268 > if (!result.uriTrustInfo) {
269 result.uriTrustInfo = [];
270 }
272 > result.uriTrustInfo = result.uriTrustInfo.map(info => { return { uri: URI.revive(info.uri), trusted: info.trusted }; });
273 > result.uriTrustInfo = result.uriTrustInfo.filter(info => info.trusted);
274 >
275 > return result;
276 > }
277
278 private async saveTrustInfo(): Promise<void> {
294
295 private calculateWorkspaceTrust(): boolean {
296 > // Feature is disabled workspaceTrust.ts
297 > if (!this.workspaceTrustEnablementService.isWorkspaceTrustEnabled()) {
298 return true;
299 }
301 > // Canonical Uris not yet resolved
302 > if (!this._canonicalUrisResolved) {
303 > return false;
304 > }
305 >
306 > // Remote - resolver explicitly sets workspace trust to TRUE
307 > if (this.environmentService.remoteAuthority && this._remoteAuthority?.options?.isTrusted) {
308 return this._remoteAuthority.options.isTrusted;
309 }
311 > // Empty workspace - use memento, open ediors, or user setting
312 > if (this.isEmptyWorkspace()) {
313 > // Use memento if present
314 > if (this._storedTrustState.isEmptyWorkspaceTrusted !== undefined) {
315 return this._storedTrustState.isEmptyWorkspaceTrusted;
316 }
318 > // Startup files
319 > if (this._canonicalStartupFiles.length) {
320 return this.getUrisTrust(this._canonicalStartupFiles);
321 }
326
327 return this.getUrisTrust(this.getWorkspaceUris());
329
330 private async updateWorkspaceTrust(trusted?: boolean): Promise<void> {
331 > if (!this.workspaceTrustEnablementService.isWorkspaceTrustEnabled()) { workspaceTrust.ts
332 return;
333 }
335 > if (trusted === undefined) {
336 > await this.resolveCanonicalUris();
337 > trusted = this.calculateWorkspaceTrust();
338 > }
339 >
340 > if (this.isWorkspaceTrusted() === trusted) { return; }
341
342 // Update workspace trust
348 // Fire workspace trust change event
349 this._onDidChangeTrust.fire(trusted);
351
352 private getUrisTrust(uris: URI[]): boolean {
435
436 private isEmptyWorkspace(): boolean {
437 > if (this.workspaceService.getWorkbenchState() === WorkbenchState.EMPTY) { workspaceTrust.ts
438 > return true;
439 > }
440
441 const workspace = this.workspaceService.getWorkspace();
445
446 return false;
448
449 private isTrustedVirtualResource(uri: URI): boolean {
490
491 get workspaceTrustInitialized(): Promise<void> {
492 > return this._workspaceTrustInitializedPromise; workspaceTrust.ts
493 > }
494
495 get acceptsOutOfWorkspaceFiles(): boolean {
502
503 isWorkspaceTrusted(): boolean {
504 > return this._isTrusted; workspaceTrust.ts
505 > }
506
507 isWorkspaceTrustForced(): boolean {
889 }
890
891 > class WorkspaceTrustTransitionManager extends Disposable { workspaceTrust.ts
892 >
893 > private readonly participants = new LinkedList<IWorkspaceTrustTransitionParticipant>();
894
895 addWorkspaceTrustTransitionParticipant(participant: IWorkspaceTrustTransitionParticipant): IDisposable {
905
906 override dispose(): void {
907 > this.participants.clear(); workspaceTrust.ts
908 > super.dispose();
909 > }
910 }
911
924
925 constructor(storageService?: IStorageService) {
926 > if (storageService) { workspaceTrust.ts
927 > this._memento = new Memento('workspaceTrust', storageService);
928 > this._mementoObject = this._memento.getMemento(StorageScope.WORKSPACE, StorageTarget.MACHINE);
929 > } else {
930 this._mementoObject = {};
931 }
933
934 get acceptsOutOfWorkspaceFiles(): boolean {
943
944 get isEmptyWorkspaceTrusted(): boolean | undefined {
945 > return this._mementoObject[this._isEmptyWorkspaceTrustedKey]; workspaceTrust.ts
946 > }
947
948 set isEmptyWorkspaceTrusted(value: boolean | undefined) {
949 > this._mementoObject[this._isEmptyWorkspaceTrustedKey] = value; workspaceTrust.ts
950 >
951 > this._memento?.saveMemento();
952 > }
953 }
954
src/vs/workbench/test/common/workbenchTestServices.ts 2 introduced LOC · 1 range

Open complete file