diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts index 3967d3b3f08..1639bb949fe 100644 --- a/src/vs/base/browser/dom.ts +++ b/src/vs/base/browser/dom.ts @@ -1186,22 +1186,14 @@ export function animate(fn: () => void): IDisposable { return toDisposable(() => stepDisposable.dispose()); } - - -const _location = URI.parse(window.location.href); +RemoteAuthorities.setPreferredWebSchema(/^https:/.test(window.location.href) ? 'https' : 'http'); export function asDomUri(uri: URI): URI { if (!uri) { return uri; } if (Schemas.vscodeRemote === uri.scheme) { - if (platform.isWeb) { - // rewrite vscode-remote-uris to uris of the window location - // so that they can be intercepted by the service worker - return _location.with({ path: '/vscode-remote', query: JSON.stringify(uri) }); - } else { - return RemoteAuthorities.rewrite(uri.authority, uri.path); - } + return RemoteAuthorities.rewrite(uri.authority, uri.path); } return uri; } diff --git a/src/vs/base/common/network.ts b/src/vs/base/common/network.ts index 9c83d42dc7c..4f93e06df0b 100644 --- a/src/vs/base/common/network.ts +++ b/src/vs/base/common/network.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { URI } from 'vs/base/common/uri'; +import * as platform from 'vs/base/common/platform'; export namespace Schemas { @@ -58,11 +59,17 @@ class RemoteAuthoritiesImpl { private readonly _hosts: { [authority: string]: string; }; private readonly _ports: { [authority: string]: number; }; private readonly _connectionTokens: { [authority: string]: string; }; + private _preferredWebSchema: 'http' | 'https'; constructor() { this._hosts = Object.create(null); this._ports = Object.create(null); this._connectionTokens = Object.create(null); + this._preferredWebSchema = 'http'; + } + + public setPreferredWebSchema(schema: 'http' | 'https') { + this._preferredWebSchema = schema; } public set(authority: string, host: string, port: number): void { @@ -79,9 +86,9 @@ class RemoteAuthoritiesImpl { const port = this._ports[authority]; const connectionToken = this._connectionTokens[authority]; return URI.from({ - scheme: Schemas.vscodeRemoteResource, + scheme: platform.isWeb ? this._preferredWebSchema : Schemas.vscodeRemoteResource, authority: `${host}:${port}`, - path: `/vscode-remote2`, + path: `/vscode-remote-resource`, query: `path=${encodeURIComponent(path)}&tkn=${encodeURIComponent(connectionToken)}` }); } diff --git a/src/vs/code/browser/workbench/workbench.html b/src/vs/code/browser/workbench/workbench.html index 8f8f45fb15f..9bf87281e2c 100644 --- a/src/vs/code/browser/workbench/workbench.html +++ b/src/vs/code/browser/workbench/workbench.html @@ -25,8 +25,8 @@ - + - + diff --git a/src/vs/code/browser/workbench/workbench.js b/src/vs/code/browser/workbench/workbench.js index 240ca34df05..5050cb4e5b4 100644 --- a/src/vs/code/browser/workbench/workbench.js +++ b/src/vs/code/browser/workbench/workbench.js @@ -8,15 +8,15 @@ (function () { require.config({ - baseUrl: `${window.location.origin}/out`, + baseUrl: `${window.location.origin}/static/out`, paths: { - 'vscode-textmate': `${window.location.origin}/node_modules/vscode-textmate/release/main`, - 'onigasm-umd': `${window.location.origin}/node_modules/onigasm-umd/release/main`, - 'xterm': `${window.location.origin}/node_modules/xterm/lib/xterm.js`, - 'xterm-addon-search': `${window.location.origin}/node_modules/xterm-addon-search/lib/xterm-addon-search.js`, - 'xterm-addon-web-links': `${window.location.origin}/node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js`, - 'semver-umd': `${window.location.origin}/node_modules/semver-umd/lib/semver-umd.js`, - '@microsoft/applicationinsights-web': `${window.location.origin}/node_modules/@microsoft/applicationinsights-web/dist/applicationinsights-web.js`, + 'vscode-textmate': `${window.location.origin}/static/node_modules/vscode-textmate/release/main`, + 'onigasm-umd': `${window.location.origin}/static/node_modules/onigasm-umd/release/main`, + 'xterm': `${window.location.origin}/static/node_modules/xterm/lib/xterm.js`, + 'xterm-addon-search': `${window.location.origin}/static/node_modules/xterm-addon-search/lib/xterm-addon-search.js`, + 'xterm-addon-web-links': `${window.location.origin}/static/node_modules/xterm-addon-web-links/lib/xterm-addon-web-links.js`, + 'semver-umd': `${window.location.origin}/static/node_modules/semver-umd/lib/semver-umd.js`, + '@microsoft/applicationinsights-web': `${window.location.origin}/static/node_modules/@microsoft/applicationinsights-web/dist/applicationinsights-web.js`, } }); diff --git a/src/vs/platform/remote/browser/remoteAuthorityResolverService.ts b/src/vs/platform/remote/browser/remoteAuthorityResolverService.ts index 5db4ac5683e..3f8958b7235 100644 --- a/src/vs/platform/remote/browser/remoteAuthorityResolverService.ts +++ b/src/vs/platform/remote/browser/remoteAuthorityResolverService.ts @@ -4,6 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import { ResolvedAuthority, IRemoteAuthorityResolverService, ResolverResult } from 'vs/platform/remote/common/remoteAuthorityResolver'; +import { RemoteAuthorities } from 'vs/base/common/network'; export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverService { @@ -15,13 +16,14 @@ export class RemoteAuthorityResolverService implements IRemoteAuthorityResolverS resolveAuthority(authority: string): Promise { if (authority.indexOf(':') >= 0) { const pieces = authority.split(':'); - return Promise.resolve({ - authority: { authority, host: pieces[0], port: parseInt(pieces[1], 10) } - }); + return Promise.resolve(this._createResolvedAuthority(authority, pieces[0], parseInt(pieces[1], 10))); } - return Promise.resolve({ - authority: { authority, host: authority, port: 80 } - }); + return Promise.resolve(this._createResolvedAuthority(authority, authority, 80)); + } + + private _createResolvedAuthority(authority: string, host: string, port: number): ResolverResult { + RemoteAuthorities.set(authority, host, port); + return { authority: { authority, host, port } }; } clearResolvedAuthority(authority: string): void { diff --git a/src/vs/workbench/api/worker/extHostExtensionService.ts b/src/vs/workbench/api/worker/extHostExtensionService.ts index a40ce65b7bf..4fcb6db76f8 100644 --- a/src/vs/workbench/api/worker/extHostExtensionService.ts +++ b/src/vs/workbench/api/worker/extHostExtensionService.ts @@ -8,7 +8,6 @@ import { ExtensionActivationTimesBuilder } from 'vs/workbench/api/common/extHost import { AbstractExtHostExtensionService } from 'vs/workbench/api/common/extHostExtensionService'; import { endsWith, startsWith } from 'vs/base/common/strings'; import { URI } from 'vs/base/common/uri'; -import { Schemas } from 'vs/base/common/network'; import { joinPath } from 'vs/base/common/resources'; import { RequireInterceptor } from 'vs/workbench/api/common/extHostRequireInterceptor'; @@ -128,7 +127,7 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService { const next = joinPath(parent, '..', ensureSuffix(mod, '.js')); moduleStack.push(next); const trap = ExportsTrap.Instance.add(next.toString()); - importScripts(asDomUri(next).toString(true)); + importScripts(next.toString(true)); moduleStack.pop(); return trap.claim(); @@ -139,7 +138,7 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService { module = module.with({ path: ensureSuffix(module.path, '.js') }); moduleStack.push(module); const trap = ExportsTrap.Instance.add(module.toString()); - importScripts(asDomUri(module).toString(true)); + importScripts(module.toString(true)); moduleStack.pop(); return Promise.resolve(trap.claim()); @@ -153,16 +152,6 @@ export class ExtHostExtensionService extends AbstractExtHostExtensionService { } } -// todo@joh this is a copy of `dom.ts#asDomUri` -function asDomUri(uri: URI): URI { - if (Schemas.vscodeRemote === uri.scheme) { - // rewrite vscode-remote-uris to uris of the window location - // so that they can be intercepted by the service worker - return URI.parse(window.location.href).with({ path: '/vscode-remote', query: JSON.stringify(uri) }); - } - return uri; -} - function ensureSuffix(path: string, suffix: string): string { return endsWith(path, suffix) ? path : path + suffix; } diff --git a/src/vs/workbench/browser/web.simpleservices.ts b/src/vs/workbench/browser/web.simpleservices.ts index df37618b471..78d9281c010 100644 --- a/src/vs/workbench/browser/web.simpleservices.ts +++ b/src/vs/workbench/browser/web.simpleservices.ts @@ -31,7 +31,6 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur import { ParsedArgs } from 'vs/platform/environment/common/environment'; import { IProcessEnvironment } from 'vs/base/common/platform'; import { toStoreData, restoreRecentlyOpened } from 'vs/platform/history/common/historyStorage'; -import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService'; import { IDialogService } from 'vs/platform/dialogs/common/dialogs'; import { IProductService } from 'vs/platform/product/common/product'; import Severity from 'vs/base/common/severity'; @@ -176,7 +175,6 @@ export class SimpleWindowService extends Disposable implements IWindowService { @IStorageService private readonly storageService: IStorageService, @IWorkspaceContextService private readonly workspaceService: IWorkspaceContextService, @ILogService private readonly logService: ILogService, - @IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService ) { super(); @@ -372,7 +370,7 @@ export class SimpleWindowService extends Disposable implements IWindowService { for (let i = 0; i < _uris.length; i++) { const uri = _uris[i]; if ('folderUri' in uri) { - const newAddress = `${document.location.origin}/?folder=${uri.folderUri.path}${this.workbenchEnvironmentService.configuration.connectionToken ? `&tkn=${this.workbenchEnvironmentService.configuration.connectionToken}` : ''}`; + const newAddress = `${document.location.origin}/?folder=${uri.folderUri.path}`; if (openFolderInNewWindow) { window.open(newAddress); } else { @@ -459,7 +457,6 @@ export class SimpleWindowsService implements IWindowsService { readonly onRecentlyOpenedChange: Event = Event.None; constructor( - @IWorkbenchEnvironmentService private readonly workbenchEnvironmentService: IWorkbenchEnvironmentService, @IDialogService private readonly dialogService: IDialogService, @IProductService private readonly productService: IProductService, @IClipboardService private readonly clipboardService: IClipboardService @@ -651,11 +648,6 @@ export class SimpleWindowsService implements IWindowsService { addQueryParameter('ibe', ibe); } - // add connection token - if (this.workbenchEnvironmentService.configuration.connectionToken) { - addQueryParameter('tkn', this.workbenchEnvironmentService.configuration.connectionToken); - } - window.open(newAddress); return Promise.resolve(); diff --git a/src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts b/src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts index 48b238d10f3..3534ef147df 100644 --- a/src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts +++ b/src/vs/workbench/contrib/resources/browser/resourceServiceWorker.ts @@ -34,7 +34,7 @@ self.addEventListener('activate', event => { //#region --- fetching/caching const _cacheName = 'vscode-extension-resources'; -const _resourcePrefix = '/vscode-remote'; +const _resourcePrefix = '/vscode-remote-resource'; const _pendingFetch = new Map(); self.addEventListener('message', event => { diff --git a/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerMain.ts b/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerMain.ts index 0dc883addcc..89e7d32eae6 100644 --- a/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerMain.ts +++ b/src/vs/workbench/contrib/resources/browser/resourceServiceWorkerMain.ts @@ -10,7 +10,7 @@ // statement. // trigger service worker updates -const _tag = '52278406-3ca9-48af-a8fb-8495add5bb4e'; +const _tag = '23549971-9b8d-41bb-92ae-d7f6a68c9702'; // loader world const baseUrl = '../../../../../'; diff --git a/src/vs/workbench/services/environment/browser/environmentService.ts b/src/vs/workbench/services/environment/browser/environmentService.ts index bdac4d340ef..ec7417e7e7b 100644 --- a/src/vs/workbench/services/environment/browser/environmentService.ts +++ b/src/vs/workbench/services/environment/browser/environmentService.ts @@ -88,7 +88,7 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment this.localeResource = joinPath(this.userRoamingDataHome, 'locale.json'); this.backupHome = joinPath(this.userRoamingDataHome, BACKUPS); this.configuration.backupWorkspaceResource = joinPath(this.backupHome, options.workspaceId); - this.configuration.connectionToken = options.connectionToken || this.getConnectionTokenFromLocation(); + this.configuration.connectionToken = options.connectionToken || getCookieValue('vscode-tkn'); this.logsPath = '/web/logs'; @@ -191,21 +191,12 @@ export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironment get webviewCspSource(): string { return this.webviewEndpoint ? this.webviewEndpoint : 'vscode-resource:'; } - - private getConnectionTokenFromLocation(): string | undefined { - // TODO: Check with @alexd where the token will be: search or hash? - let connectionToken: string | undefined = undefined; - if (document.location.search) { - connectionToken = this.getConnectionToken(document.location.search); - } - if (!connectionToken && document.location.hash) { - connectionToken = this.getConnectionToken(document.location.hash); - } - return connectionToken; - } - - private getConnectionToken(str: string): string | undefined { - const m = str.match(/[#&?]tkn=([^&]+)/); - return m ? m[1] : undefined; - } +} + +/** + * See https://stackoverflow.com/a/25490531 + */ +function getCookieValue(name: string): string | undefined { + const m = document.cookie.match('(^|[^;]+)\\s*' + name + '\\s*=\\s*([^;]+)'); + return m ? m.pop() : undefined; }