disable-cors.patch 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. diff --git a/src/bootstrap-window.js b/src/bootstrap-window.js
  2. index 0cc92ec..43042d5 100644
  3. --- a/src/bootstrap-window.js
  4. +++ b/src/bootstrap-window.js
  5. @@ -24,6 +24,7 @@
  6. const bootstrapLib = bootstrap();
  7. const preloadGlobals = sandboxGlobals();
  8. const safeProcess = preloadGlobals.process;
  9. + const useCustomProtocol = safeProcess.sandboxed;
  10. /**
  11. * @typedef {import('./vs/base/parts/sandbox/common/sandboxTypes').ISandboxConfiguration} ISandboxConfiguration
  12. @@ -99,6 +100,11 @@
  13. window.document.documentElement.setAttribute('lang', locale);
  14. + // Do not advertise AMD to avoid confusing UMD modules loaded with nodejs
  15. + if (!useCustomProtocol) {
  16. + window['define'] = undefined;
  17. + }
  18. +
  19. // Replace the patched electron fs with the original node fs for all AMD code (TODO@sandbox non-sandboxed only)
  20. if (!safeProcess.sandboxed) {
  21. require.define('fs', [], function () { return require.__$__nodeRequire('original-fs'); });
  22. @@ -107,9 +113,11 @@
  23. window['MonacoEnvironment'] = {};
  24. const loaderConfig = {
  25. - baseUrl: `${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32', scheme: 'vscode-file', fallbackAuthority: 'vscode-app' })}/out`,
  26. + baseUrl: useCustomProtocol ?
  27. + `${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32', scheme: 'vscode-file', fallbackAuthority: 'vscode-app' })}/out` :
  28. + `${bootstrapLib.fileUriFromPath(configuration.appRoot, { isWindows: safeProcess.platform === 'win32' })}/out`,
  29. 'vs/nls': nlsConfig,
  30. - preferScriptTags: true
  31. + preferScriptTags: useCustomProtocol
  32. };
  33. // use a trusted types policy when loading via script tags
  34. @@ -143,6 +151,14 @@
  35. loaderConfig.amdModulesPattern = /^vs\//;
  36. }
  37. + // Cached data config (node.js loading only)
  38. + if (!useCustomProtocol && configuration.codeCachePath) {
  39. + loaderConfig.nodeCachedData = {
  40. + path: configuration.codeCachePath,
  41. + seed: modulePaths.join('')
  42. + };
  43. + }
  44. +
  45. // Signal before require.config()
  46. if (typeof options?.beforeLoaderConfig === 'function') {
  47. options.beforeLoaderConfig(loaderConfig);
  48. diff --git a/src/vs/base/common/network.ts b/src/vs/base/common/network.ts
  49. index 41a3fe9..bbb06e3 100644
  50. --- a/src/vs/base/common/network.ts
  51. +++ b/src/vs/base/common/network.ts
  52. @@ -166,16 +166,7 @@ class FileAccessImpl {
  53. }
  54. // Convert to `vscode-file` resource..
  55. - if (
  56. - // ...only ever for `file` resources
  57. - uri.scheme === Schemas.file &&
  58. - (
  59. - // ...and we run in native environments
  60. - platform.isNative ||
  61. - // ...or web worker extensions on desktop
  62. - (typeof platform.globals.importScripts === 'function' && platform.globals.origin === `${Schemas.vscodeFileResource}://${FileAccessImpl.FALLBACK_AUTHORITY}`)
  63. - )
  64. - ) {
  65. + if (uri.scheme === Schemas.file && typeof platform.globals.importScripts === 'function' && platform.globals.origin === `${Schemas.vscodeFileResource}://${FileAccessImpl.FALLBACK_AUTHORITY}`) {
  66. return uri.with({
  67. scheme: Schemas.vscodeFileResource,
  68. // We need to provide an authority here so that it can serve
  69. diff --git a/src/vs/platform/protocol/electron-main/protocolMainService.ts b/src/vs/platform/protocol/electron-main/protocolMainService.ts
  70. index bde08d8..3f09ad1 100644
  71. --- a/src/vs/platform/protocol/electron-main/protocolMainService.ts
  72. +++ b/src/vs/platform/protocol/electron-main/protocolMainService.ts
  73. @@ -72,9 +72,24 @@ export class ProtocolMainService extends Disposable implements IProtocolMainServ
  74. //#region file://
  75. private handleFileRequest(request: Electron.ProtocolRequest, callback: ProtocolCallback) {
  76. - const uri = URI.parse(request.url);
  77. + const fileUri = URI.parse(request.url);
  78. +
  79. + // first check by validRoots
  80. + if (this.validRoots.findSubstr(fileUri)) {
  81. + return callback({
  82. + path: fileUri.fsPath
  83. + });
  84. + }
  85. - this.logService.error(`Refused to load resource ${uri.fsPath} from ${Schemas.file}: protocol (original URL: ${request.url})`);
  86. + // then check by validExtensions
  87. + if (this.validExtensions.has(extname(fileUri))) {
  88. + return callback({
  89. + path: fileUri.fsPath
  90. + });
  91. + }
  92. +
  93. + // finally block to load the resource
  94. + this.logService.error(`${Schemas.file}: Refused to load resource ${fileUri.fsPath} from ${Schemas.file}: protocol (original URL: ${request.url})`);
  95. return callback({ error: -3 /* ABORTED */ });
  96. }
  97. diff --git a/src/vs/workbench/services/timer/electron-sandbox/timerService.ts b/src/vs/workbench/services/timer/electron-sandbox/timerService.ts
  98. index 7cae207..1c54ac9 100644
  99. --- a/src/vs/workbench/services/timer/electron-sandbox/timerService.ts
  100. +++ b/src/vs/workbench/services/timer/electron-sandbox/timerService.ts
  101. @@ -19,7 +19,7 @@ import { process } from 'vs/base/parts/sandbox/electron-sandbox/globals';
  102. import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
  103. import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
  104. import { IProductService } from 'vs/platform/product/common/productService';
  105. -import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
  106. +import { IStorageService } from 'vs/platform/storage/common/storage';
  107. export class TimerService extends AbstractTimerService {
  108. @@ -91,24 +91,23 @@ registerSingleton(ITimerService, TimerService);
  109. //#region cached data logic
  110. -const lastRunningCommitStorageKey = 'perf/lastRunningCommit';
  111. -let _didUseCachedData: boolean | undefined = undefined;
  112. -
  113. export function didUseCachedData(productService: IProductService, storageService: IStorageService, environmentService: INativeWorkbenchEnvironmentService): boolean {
  114. - // browser code loading: only a guess based on
  115. - // this being the first start with the commit
  116. - // or subsequent
  117. - if (typeof _didUseCachedData !== 'boolean') {
  118. - if (!environmentService.configuration.codeCachePath || !productService.commit) {
  119. - _didUseCachedData = false; // we only produce cached data whith commit and code cache path
  120. - } else if (storageService.get(lastRunningCommitStorageKey, StorageScope.GLOBAL) === productService.commit) {
  121. - _didUseCachedData = true; // subsequent start on same commit, assume cached data is there
  122. - } else {
  123. - storageService.store(lastRunningCommitStorageKey, productService.commit, StorageScope.GLOBAL, StorageTarget.MACHINE);
  124. - _didUseCachedData = false; // first time start on commit, assume cached data is not yet there
  125. + if (!Boolean((<any>window).require.getConfig().nodeCachedData)) {
  126. + return false;
  127. + }
  128. + // There are loader events that signal if cached data was missing, rejected,
  129. + // or used. The former two mean no cached data.
  130. + let cachedDataFound = 0;
  131. + for (const event of require.getStats()) {
  132. + switch (event.type) {
  133. + case LoaderEventType.CachedDataRejected:
  134. + return false;
  135. + case LoaderEventType.CachedDataFound:
  136. + cachedDataFound += 1;
  137. + break;
  138. }
  139. }
  140. - return _didUseCachedData;
  141. + return cachedDataFound > 0;
  142. }
  143. //#endregion