[web] DRY up access to headers required for multi-threaded WebAssembly (#163555)
This commit is contained in:
parent
e0617ac362
commit
7819cee8d6
@ -41,6 +41,7 @@ import '../web/chrome.dart';
|
||||
import '../web/compile.dart';
|
||||
import '../web/memory_fs.dart';
|
||||
import '../web/module_metadata.dart';
|
||||
import '../web/web_constants.dart';
|
||||
import '../web_template.dart';
|
||||
|
||||
typedef DwdsLauncher =
|
||||
@ -1315,11 +1316,8 @@ class ReleaseAssetServer {
|
||||
'Content-Type': mimeType,
|
||||
'Cross-Origin-Resource-Policy': 'cross-origin',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
if (_needsCoopCoep &&
|
||||
_fileSystem.path.extension(file.path) == '.html') ...<String, String>{
|
||||
'Cross-Origin-Opener-Policy': 'same-origin',
|
||||
'Cross-Origin-Embedder-Policy': 'credentialless',
|
||||
},
|
||||
if (_needsCoopCoep && _fileSystem.path.extension(file.path) == '.html')
|
||||
...kMultiThreadedHeaders,
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -1329,10 +1327,7 @@ class ReleaseAssetServer {
|
||||
file.readAsBytesSync(),
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'text/html',
|
||||
if (_needsCoopCoep) ...<String, String>{
|
||||
'Cross-Origin-Opener-Policy': 'same-origin',
|
||||
'Cross-Origin-Embedder-Policy': 'credentialless',
|
||||
},
|
||||
if (_needsCoopCoep) ...kMultiThreadedHeaders,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import '../web/bootstrap.dart';
|
||||
import '../web/chrome.dart';
|
||||
import '../web/compile.dart';
|
||||
import '../web/memory_fs.dart';
|
||||
import '../web/web_constants.dart';
|
||||
import 'test_compiler.dart';
|
||||
import 'test_golden_comparator.dart';
|
||||
import 'test_time_recorder.dart';
|
||||
@ -57,10 +58,7 @@ shelf.Handler createDirectoryHandler(Directory directory, {required bool crossOr
|
||||
file.openRead(),
|
||||
headers: <String, String>{
|
||||
if (contentType != null) 'Content-Type': contentType,
|
||||
if (needsCrossOriginIsolated) ...<String, String>{
|
||||
'Cross-Origin-Opener-Policy': 'same-origin',
|
||||
'Cross-Origin-Embedder-Policy': 'credentialless',
|
||||
},
|
||||
if (needsCrossOriginIsolated) ...kMultiThreadedHeaders,
|
||||
},
|
||||
);
|
||||
};
|
||||
@ -551,10 +549,7 @@ class FlutterWebPlatform extends PlatformPlugin {
|
||||
''',
|
||||
headers: <String, String>{
|
||||
'Content-Type': 'text/html',
|
||||
if (webRenderer == WebRendererMode.skwasm) ...<String, String>{
|
||||
'Cross-Origin-Opener-Policy': 'same-origin',
|
||||
'Cross-Origin-Embedder-Policy': 'credentialless',
|
||||
},
|
||||
if (webRenderer == WebRendererMode.skwasm) ...kMultiThreadedHeaders,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -3,3 +3,12 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
const String kWasmMoreInfo = 'See https://flutter.dev/to/wasm for more information.';
|
||||
|
||||
/// Headers required to run Wasm-compiled applications with multi-threading.
|
||||
///
|
||||
/// See https://developer.chrome.com/blog/coep-credentialless-origin-trial
|
||||
/// for more information.
|
||||
const Map<String, String> kMultiThreadedHeaders = <String, String>{
|
||||
'Cross-Origin-Opener-Policy': 'same-origin',
|
||||
'Cross-Origin-Embedder-Policy': 'credentialless',
|
||||
};
|
||||
|
@ -7,6 +7,7 @@ import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/isolated/devfs_web.dart';
|
||||
import 'package:flutter_tools/src/web/web_constants.dart';
|
||||
import 'package:shelf/shelf.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
@ -236,8 +237,9 @@ void main() {
|
||||
|
||||
expect(response.statusCode, HttpStatus.ok);
|
||||
final Map<String, String> headers = response.headers;
|
||||
expect(headers['Cross-Origin-Opener-Policy'], 'same-origin');
|
||||
expect(headers['Cross-Origin-Embedder-Policy'], 'credentialless');
|
||||
for (final MapEntry<String, String> entry in kMultiThreadedHeaders.entries) {
|
||||
expect(headers, containsPair(entry.key, entry.value));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user