-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
164 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/vs/workbench/contrib/url/common/trustedDomainsFileSystemProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { Event } from 'vs/base/common/event'; | ||
import { parse } from 'vs/base/common/json'; | ||
import { IDisposable } from 'vs/base/common/lifecycle'; | ||
import { URI } from 'vs/base/common/uri'; | ||
import { | ||
FileDeleteOptions, | ||
FileOverwriteOptions, | ||
FileSystemProviderCapabilities, | ||
FileType, | ||
FileWriteOptions, | ||
IFileService, | ||
IFileSystemProvider, | ||
IStat, | ||
IWatchOptions | ||
} from 'vs/platform/files/common/files'; | ||
import { IProductService } from 'vs/platform/product/common/product'; | ||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage'; | ||
import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; | ||
|
||
const TRUSTED_DOMAINS_SCHEMA = 'trustedDomains'; | ||
|
||
const TRUSTED_DOMAINS_STAT: IStat = { | ||
type: FileType.File, | ||
ctime: Date.now(), | ||
mtime: Date.now(), | ||
size: 0 | ||
}; | ||
|
||
const CONFIG_HELP_TEXT = `// Configure trusted domains by editing and saving this file | ||
// You can use \`*\` to match subdomains. For example https://*.visualstudio.com would match: | ||
// - https://code.visualstudio.com | ||
// - https://update.code.visualstudio.com | ||
`; | ||
|
||
export class TrustedDomainsFileSystemProvider implements IFileSystemProvider, IWorkbenchContribution { | ||
readonly capabilities = FileSystemProviderCapabilities.FileReadWrite; | ||
|
||
readonly onDidChangeCapabilities = Event.None; | ||
readonly onDidChangeFile = Event.None; | ||
|
||
constructor( | ||
@IFileService private readonly fileService: IFileService, | ||
@IProductService private readonly productService: IProductService, | ||
@IStorageService private readonly storageService: IStorageService | ||
) { | ||
this.fileService.registerProvider(TRUSTED_DOMAINS_SCHEMA, this); | ||
} | ||
|
||
stat(resource: URI): Promise<IStat> { | ||
return Promise.resolve(TRUSTED_DOMAINS_STAT); | ||
} | ||
|
||
readFile(resource: URI): Promise<Uint8Array> { | ||
let trustedDomains: string[] = this.productService.linkProtectionTrustedDomains | ||
? [...this.productService.linkProtectionTrustedDomains] | ||
: []; | ||
|
||
try { | ||
const trustedDomainsSrc = this.storageService.get('http.linkProtectionTrustedDomains', StorageScope.GLOBAL); | ||
if (trustedDomainsSrc) { | ||
trustedDomains = JSON.parse(trustedDomainsSrc); | ||
} | ||
} catch (err) { } | ||
|
||
const trustedDomainsContent = CONFIG_HELP_TEXT + JSON.stringify(trustedDomains, null, 2); | ||
|
||
const buffer = Buffer.from(trustedDomainsContent, 'utf-8'); | ||
return Promise.resolve(buffer); | ||
} | ||
|
||
writeFile(resource: URI, content: Uint8Array, opts: FileWriteOptions): Promise<void> { | ||
let trustedDomainsd = []; | ||
|
||
try { | ||
trustedDomainsd = parse(content.toString()); | ||
} catch (err) { } | ||
|
||
this.storageService.store( | ||
'http.linkProtectionTrustedDomains', | ||
JSON.stringify(trustedDomainsd), | ||
StorageScope.GLOBAL | ||
); | ||
|
||
return Promise.resolve(); | ||
} | ||
|
||
watch(resource: URI, opts: IWatchOptions): IDisposable { | ||
return { | ||
dispose() { | ||
return; | ||
} | ||
}; | ||
} | ||
mkdir(resource: URI): Promise<void> { | ||
return Promise.resolve(undefined!); | ||
} | ||
readdir(resource: URI): Promise<[string, FileType][]> { | ||
return Promise.resolve(undefined!); | ||
} | ||
delete(resource: URI, opts: FileDeleteOptions): Promise<void> { | ||
return Promise.resolve(undefined!); | ||
} | ||
rename(from: URI, to: URI, opts: FileOverwriteOptions): Promise<void> { | ||
return Promise.resolve(undefined!); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.