disable-cors.patch 6.2 KB

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