mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Revert "[web] Catch image load failures in --release builds (#25602)" (flutter/engine#26073)
This reverts commit 68aaf6df0a808f3cd407cc109172bb360d077d29.
This commit is contained in:
parent
c5b6ecbb50
commit
d9ba08c67b
@ -48,34 +48,14 @@ class AssetManager {
|
||||
return Uri.encodeFull((_baseUrl ?? '') + '$assetsDir/$asset');
|
||||
}
|
||||
|
||||
/// Returns true if buffer contains html document.
|
||||
static bool _responseIsHtmlPage(ByteData data) {
|
||||
const String htmlDocTypeResponse = '<!DOCTYPE html>';
|
||||
final int testLength = htmlDocTypeResponse.length;
|
||||
if (data.lengthInBytes < testLength) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < testLength; i++) {
|
||||
if (data.getInt8(i) != htmlDocTypeResponse.codeUnitAt(i))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<ByteData> load(String asset) async {
|
||||
final String url = getAssetUrl(asset);
|
||||
try {
|
||||
final html.HttpRequest request =
|
||||
await html.HttpRequest.request(url, responseType: 'arraybuffer');
|
||||
// Development server will return index.html for invalid urls.
|
||||
// The check below makes sure when it is returned for non html assets
|
||||
// we report an error instead of silent failure.
|
||||
|
||||
final ByteBuffer response = request.response;
|
||||
final ByteData data = response.asByteData();
|
||||
if (!url.endsWith('html') && _responseIsHtmlPage(data)) {
|
||||
throw AssetManagerException(url, 404);
|
||||
}
|
||||
return data;
|
||||
return response.asByteData();
|
||||
} on html.ProgressEvent catch (e) {
|
||||
final html.EventTarget? target = e.target;
|
||||
if (target is html.HttpRequest) {
|
||||
|
||||
@ -86,7 +86,6 @@ class HtmlCodec implements ui.Codec {
|
||||
loadSubscription?.cancel();
|
||||
errorSubscription.cancel();
|
||||
completer.completeError(event);
|
||||
throw ArgumentError('Unable to load image asset: $src');
|
||||
});
|
||||
loadSubscription = imgElement.onLoad.listen((html.Event event) {
|
||||
if (chunkCallback != null) {
|
||||
|
||||
@ -314,20 +314,6 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
|
||||
};
|
||||
}
|
||||
|
||||
void _reportAssetLoadError(String url,
|
||||
ui.PlatformMessageResponseCallback? callback, String error) {
|
||||
const MethodCodec codec = JSONMethodCodec();
|
||||
final String message = 'Error while trying to load an asset $url';
|
||||
if (!assertionsEnabled) {
|
||||
/// For web/release mode log the load failure on console.
|
||||
printWarning(message);
|
||||
}
|
||||
_replyToPlatformMessage(
|
||||
callback, codec.encodeErrorEnvelope(code: 'errorCode',
|
||||
message: message,
|
||||
details: error));
|
||||
}
|
||||
|
||||
void _sendPlatformMessage(
|
||||
String name,
|
||||
ByteData? data,
|
||||
@ -349,6 +335,7 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
|
||||
}
|
||||
|
||||
switch (name) {
|
||||
|
||||
/// This should be in sync with shell/common/shell.cc
|
||||
case 'flutter/skia':
|
||||
const MethodCodec codec = JSONMethodCodec();
|
||||
@ -376,15 +363,12 @@ class EnginePlatformDispatcher extends ui.PlatformDispatcher {
|
||||
|
||||
case 'flutter/assets':
|
||||
final String url = utf8.decode(data!.buffer.asUint8List());
|
||||
ui.webOnlyAssetManager.load(url)
|
||||
.then((ByteData assetData) {
|
||||
_replyToPlatformMessage(callback, assetData);
|
||||
}, onError: (dynamic error) {
|
||||
_reportAssetLoadError(url, callback, error);
|
||||
}
|
||||
).catchError((dynamic e) {
|
||||
_reportAssetLoadError(url, callback, e);
|
||||
});
|
||||
ui.webOnlyAssetManager.load(url).then((ByteData assetData) {
|
||||
_replyToPlatformMessage(callback, assetData);
|
||||
}, onError: (dynamic error) {
|
||||
printWarning('Error while trying to load an asset: $error');
|
||||
_replyToPlatformMessage(callback, null);
|
||||
});
|
||||
return;
|
||||
|
||||
case 'flutter/platform':
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user