| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- /*---------------------------------------------------------------------------------------------
- * Copyright (c) Microsoft Corporation. All rights reserved.
- * Licensed under the MIT License. See License.txt in the project root for license information.
- *--------------------------------------------------------------------------------------------*/
- import * as errors from './errors.js';
- import * as platform from './platform.js';
- import { URI } from './uri.js';
- export var Schemas;
- (function (Schemas) {
- /**
- * A schema that is used for models that exist in memory
- * only and that have no correspondence on a server or such.
- */
- Schemas.inMemory = 'inmemory';
- /**
- * A schema that is used for setting files
- */
- Schemas.vscode = 'vscode';
- /**
- * A schema that is used for internal private files
- */
- Schemas.internal = 'private';
- /**
- * A walk-through document.
- */
- Schemas.walkThrough = 'walkThrough';
- /**
- * An embedded code snippet.
- */
- Schemas.walkThroughSnippet = 'walkThroughSnippet';
- Schemas.http = 'http';
- Schemas.https = 'https';
- Schemas.file = 'file';
- Schemas.mailto = 'mailto';
- Schemas.untitled = 'untitled';
- Schemas.data = 'data';
- Schemas.command = 'command';
- Schemas.vscodeRemote = 'vscode-remote';
- Schemas.vscodeRemoteResource = 'vscode-remote-resource';
- Schemas.vscodeUserData = 'vscode-userdata';
- Schemas.vscodeCustomEditor = 'vscode-custom-editor';
- Schemas.vscodeNotebookCell = 'vscode-notebook-cell';
- Schemas.vscodeNotebookCellMetadata = 'vscode-notebook-cell-metadata';
- Schemas.vscodeNotebookCellOutput = 'vscode-notebook-cell-output';
- Schemas.vscodeInteractive = 'vscode-interactive';
- Schemas.vscodeInteractiveInput = 'vscode-interactive-input';
- Schemas.vscodeSettings = 'vscode-settings';
- Schemas.vscodeWorkspaceTrust = 'vscode-workspace-trust';
- Schemas.vscodeTerminal = 'vscode-terminal';
- Schemas.vscodeInteractiveSesssion = 'vscode-chat-editor';
- /**
- * Scheme used internally for webviews that aren't linked to a resource (i.e. not custom editors)
- */
- Schemas.webviewPanel = 'webview-panel';
- /**
- * Scheme used for loading the wrapper html and script in webviews.
- */
- Schemas.vscodeWebview = 'vscode-webview';
- /**
- * Scheme used for extension pages
- */
- Schemas.extension = 'extension';
- /**
- * Scheme used as a replacement of `file` scheme to load
- * files with our custom protocol handler (desktop only).
- */
- Schemas.vscodeFileResource = 'vscode-file';
- /**
- * Scheme used for temporary resources
- */
- Schemas.tmp = 'tmp';
- /**
- * Scheme used vs live share
- */
- Schemas.vsls = 'vsls';
- /**
- * Scheme used for the Source Control commit input's text document
- */
- Schemas.vscodeSourceControl = 'vscode-scm';
- })(Schemas || (Schemas = {}));
- export const connectionTokenQueryName = 'tkn';
- class RemoteAuthoritiesImpl {
- constructor() {
- this._hosts = Object.create(null);
- this._ports = Object.create(null);
- this._connectionTokens = Object.create(null);
- this._preferredWebSchema = 'http';
- this._delegate = null;
- this._remoteResourcesPath = `/${Schemas.vscodeRemoteResource}`;
- }
- setPreferredWebSchema(schema) {
- this._preferredWebSchema = schema;
- }
- rewrite(uri) {
- if (this._delegate) {
- try {
- return this._delegate(uri);
- }
- catch (err) {
- errors.onUnexpectedError(err);
- return uri;
- }
- }
- const authority = uri.authority;
- let host = this._hosts[authority];
- if (host && host.indexOf(':') !== -1 && host.indexOf('[') === -1) {
- host = `[${host}]`;
- }
- const port = this._ports[authority];
- const connectionToken = this._connectionTokens[authority];
- let query = `path=${encodeURIComponent(uri.path)}`;
- if (typeof connectionToken === 'string') {
- query += `&${connectionTokenQueryName}=${encodeURIComponent(connectionToken)}`;
- }
- return URI.from({
- scheme: platform.isWeb ? this._preferredWebSchema : Schemas.vscodeRemoteResource,
- authority: `${host}:${port}`,
- path: this._remoteResourcesPath,
- query
- });
- }
- }
- export const RemoteAuthorities = new RemoteAuthoritiesImpl();
- class FileAccessImpl {
- /**
- * Returns a URI to use in contexts where the browser is responsible
- * for loading (e.g. fetch()) or when used within the DOM.
- *
- * **Note:** use `dom.ts#asCSSUrl` whenever the URL is to be used in CSS context.
- */
- uriToBrowserUri(uri) {
- // Handle remote URIs via `RemoteAuthorities`
- if (uri.scheme === Schemas.vscodeRemote) {
- return RemoteAuthorities.rewrite(uri);
- }
- // Convert to `vscode-file` resource..
- if (
- // ...only ever for `file` resources
- uri.scheme === Schemas.file &&
- (
- // ...and we run in native environments
- platform.isNative ||
- // ...or web worker extensions on desktop
- (platform.isWebWorker && platform.globals.origin === `${Schemas.vscodeFileResource}://${FileAccessImpl.FALLBACK_AUTHORITY}`))) {
- return uri.with({
- scheme: Schemas.vscodeFileResource,
- // We need to provide an authority here so that it can serve
- // as origin for network and loading matters in chromium.
- // If the URI is not coming with an authority already, we
- // add our own
- authority: uri.authority || FileAccessImpl.FALLBACK_AUTHORITY,
- query: null,
- fragment: null
- });
- }
- return uri;
- }
- }
- FileAccessImpl.FALLBACK_AUTHORITY = 'vscode-app';
- export const FileAccess = new FileAccessImpl();
- export var COI;
- (function (COI) {
- const coiHeaders = new Map([
- ['1', { 'Cross-Origin-Opener-Policy': 'same-origin' }],
- ['2', { 'Cross-Origin-Embedder-Policy': 'require-corp' }],
- ['3', { 'Cross-Origin-Opener-Policy': 'same-origin', 'Cross-Origin-Embedder-Policy': 'require-corp' }],
- ]);
- COI.CoopAndCoep = Object.freeze(coiHeaders.get('3'));
- const coiSearchParamName = 'vscode-coi';
- /**
- * Extract desired headers from `vscode-coi` invocation
- */
- function getHeadersFromQuery(url) {
- let params;
- if (typeof url === 'string') {
- params = new URL(url).searchParams;
- }
- else if (url instanceof URL) {
- params = url.searchParams;
- }
- else if (URI.isUri(url)) {
- params = new URL(url.toString(true)).searchParams;
- }
- const value = params === null || params === void 0 ? void 0 : params.get(coiSearchParamName);
- if (!value) {
- return undefined;
- }
- return coiHeaders.get(value);
- }
- COI.getHeadersFromQuery = getHeadersFromQuery;
- /**
- * Add the `vscode-coi` query attribute based on wanting `COOP` and `COEP`. Will be a noop when `crossOriginIsolated`
- * isn't enabled the current context
- */
- function addSearchParam(urlOrSearch, coop, coep) {
- if (!globalThis.crossOriginIsolated) {
- // depends on the current context being COI
- return;
- }
- const value = coop && coep ? '3' : coep ? '2' : '1';
- if (urlOrSearch instanceof URLSearchParams) {
- urlOrSearch.set(coiSearchParamName, value);
- }
- else {
- urlOrSearch[coiSearchParamName] = value;
- }
- }
- COI.addSearchParam = addSearchParam;
- })(COI || (COI = {}));
|