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