Skip to content

Commit

Permalink
[web] Code cleanup (#27815)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferhatb authored Jul 30, 2021
1 parent f18a930 commit 230dead
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/web_ui/lib/src/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {}
Expand Down
2 changes: 2 additions & 0 deletions lib/web_ui/lib/src/engine/alarm_clock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions lib/web_ui/lib/src/engine/assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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 = '''
[
{
Expand Down
8 changes: 6 additions & 2 deletions lib/web_ui/lib/src/engine/browser_detection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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.') {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 230dead

Please sign in to comment.