Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

2 changes: 1 addition & 1 deletion e2etests/web/regular_integration_tests/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dev_dependencies:
sdk: flutter
flutter_test:
sdk: flutter
integration_test: ^1.0.2+2
integration_test: ^0.9.2+2
http: 0.12.0+2
web_test_utils:
path: ../../../web_sdk/web_test_utils
Expand Down

This file was deleted.

This file was deleted.

24 changes: 2 additions & 22 deletions lib/web_ui/lib/src/engine/assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion lib/web_ui/lib/src/engine/html_image_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 7 additions & 23 deletions lib/web_ui/lib/src/engine/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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':
Expand Down