[web] Code cleanup (flutter/engine#27815)
This commit is contained in:
@@ -330,9 +330,12 @@ export 'engine/window.dart';
|
||||
/// Keep these in sync with the same constants on the framework-side under foundation/constants.dart.
|
||||
const bool kReleaseMode =
|
||||
bool.fromEnvironment('dart.vm.product', defaultValue: false);
|
||||
/// A constant that is true if the application was compiled in profile mode.
|
||||
const bool kProfileMode =
|
||||
bool.fromEnvironment('dart.vm.profile', defaultValue: false);
|
||||
/// A constant that is true if the application was compiled in debug mode.
|
||||
const bool kDebugMode = !kReleaseMode && !kProfileMode;
|
||||
/// Returns mode of the app is running in as a string.
|
||||
String get buildMode => kReleaseMode
|
||||
? 'release'
|
||||
: kProfileMode
|
||||
@@ -454,6 +457,8 @@ void _addUrlStrategyListener() {
|
||||
});
|
||||
}
|
||||
|
||||
/// Sanitizer used to convert const svg filter and clippath snippets to
|
||||
/// SvgElement without sanitization.
|
||||
class NullTreeSanitizer implements html.NodeTreeSanitizer {
|
||||
@override
|
||||
void sanitizeTree(html.Node node) {}
|
||||
|
||||
@@ -18,6 +18,8 @@ typedef TimestampFunction = DateTime Function();
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#Notes
|
||||
class AlarmClock {
|
||||
|
||||
/// Initializes Alarmclock with a closure that gets called with a timestamp.
|
||||
AlarmClock(TimestampFunction timestampFunction)
|
||||
: _timestampFunction = timestampFunction;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ class AssetManager {
|
||||
/// The directory containing the assets.
|
||||
final String assetsDir;
|
||||
|
||||
/// Initializes [AssetManager] with path to assets relative to baseUrl.
|
||||
const AssetManager({this.assetsDir = _defaultAssetsDir});
|
||||
|
||||
String? get _baseUrl {
|
||||
@@ -53,6 +54,7 @@ class AssetManager {
|
||||
return Uri.encodeFull((_baseUrl ?? '') + '$assetsDir/$asset');
|
||||
}
|
||||
|
||||
/// Loads an asset using an [html.HttpRequest] and returns data as [ByteData].
|
||||
Future<ByteData> load(String asset) async {
|
||||
final String url = getAssetUrl(asset);
|
||||
try {
|
||||
@@ -77,10 +79,14 @@ class AssetManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Thrown to indicate http failure during asset loading.
|
||||
class AssetManagerException implements Exception {
|
||||
/// Http request url for asset.
|
||||
final String url;
|
||||
/// Http status of of response.
|
||||
final int httpStatus;
|
||||
|
||||
/// Initializes exception with request url and http status.
|
||||
AssetManagerException(this.url, this.httpStatus);
|
||||
|
||||
@override
|
||||
@@ -89,8 +95,11 @@ class AssetManagerException implements Exception {
|
||||
|
||||
/// An asset manager that gives fake empty responses for assets.
|
||||
class WebOnlyMockAssetManager implements AssetManager {
|
||||
/// Mock asset directory relative to base url.
|
||||
String defaultAssetsDir = '';
|
||||
/// Mock empty asset manifest.
|
||||
String defaultAssetManifest = '{}';
|
||||
/// Mock font manifest overridable for unit testing.
|
||||
String defaultFontManifest = '''
|
||||
[
|
||||
{
|
||||
|
||||
@@ -33,9 +33,9 @@ enum BrowserEngine {
|
||||
|
||||
/// html webgl version qualifier constants.
|
||||
abstract class WebGLVersion {
|
||||
// WebGL 1.0 is based on OpenGL ES 2.0 / GLSL 1.00
|
||||
/// WebGL 1.0 is based on OpenGL ES 2.0 / GLSL 1.00
|
||||
static const int webgl1 = 1;
|
||||
// WebGL 2.0 is based on OpenGL ES 3.0 / GLSL 3.00
|
||||
/// WebGL 2.0 is based on OpenGL ES 3.0 / GLSL 3.00
|
||||
static const int webgl2 = 2;
|
||||
}
|
||||
|
||||
@@ -78,6 +78,9 @@ bool _isSamsungBrowser(String agent) {
|
||||
return exp.hasMatch(agent.toUpperCase());
|
||||
}
|
||||
|
||||
/// Detects browser engine for a given vendor and agent string.
|
||||
///
|
||||
/// Used for testing this library.
|
||||
@visibleForTesting
|
||||
BrowserEngine detectBrowserEngineByVendorAgent(String vendor, String agent) {
|
||||
if (vendor == 'Google Inc.') {
|
||||
@@ -149,6 +152,7 @@ OperatingSystem get operatingSystem {
|
||||
/// This is intended to be used for testing and debugging only.
|
||||
OperatingSystem? debugOperatingSystemOverride;
|
||||
|
||||
/// Detects operating system using platform and UA used for unit testing.
|
||||
@visibleForTesting
|
||||
OperatingSystem detectOperatingSystem({
|
||||
String? overridePlatform,
|
||||
|
||||
Reference in New Issue
Block a user