added support for custom addon collections

This commit is contained in:
Fabian Freund
2025-09-30 13:02:17 +02:00
parent 7c4662a7be
commit 751e22ac5e
20 changed files with 423 additions and 41 deletions
@@ -17,10 +17,13 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import 'dart:convert';
import 'package:copy_with_extension/copy_with_extension.dart';
import 'package:fast_equatable/fast_equatable.dart';
import 'package:flutter_mozilla_components/flutter_mozilla_components.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:nullability/nullability.dart';
part 'engine_settings.g.dart';
@@ -60,6 +63,9 @@ class EngineSettings extends GeckoEngineSettings with FastEquatable {
final BounceTrackingProtectionMode bounceTrackingProtectionMode;
@JsonKey(fromJson: _addonCollectionFromJson, toJson: _addonCollectionToJson)
final AddonCollection? addonCollection;
@override
@JsonKey(includeFromJson: false, includeToJson: false)
ContentBlocking get contentBlocking => ContentBlocking(
@@ -85,6 +91,7 @@ class EngineSettings extends GeckoEngineSettings with FastEquatable {
required super.enterpriseRootsEnabled,
required this.queryParameterStripping,
required this.bounceTrackingProtectionMode,
required this.addonCollection,
});
EngineSettings.withDefaults({
@@ -102,6 +109,7 @@ class EngineSettings extends GeckoEngineSettings with FastEquatable {
BounceTrackingProtectionMode? bounceTrackingProtectionMode,
super.userAgent,
bool? enterpriseRootsEnabled,
this.addonCollection,
}) : queryParameterStripping =
queryParameterStripping ?? QueryParameterStripping.disabled,
bounceTrackingProtectionMode =
@@ -129,6 +137,14 @@ class EngineSettings extends GeckoEngineSettings with FastEquatable {
enterpriseRootsEnabled: enterpriseRootsEnabled ?? false,
);
static AddonCollection? _addonCollectionFromJson(String? json) =>
json.mapNotNull(
(collection) => AddonCollection.decode(jsonDecode(collection) as List),
);
static String? _addonCollectionToJson(AddonCollection? collection) =>
collection.mapNotNull((collection) => jsonEncode(collection.encode()));
factory EngineSettings.fromJson(Map<String, dynamic> json) =>
_$EngineSettingsFromJson(json);
@@ -136,19 +152,8 @@ class EngineSettings extends GeckoEngineSettings with FastEquatable {
@override
List<Object?> get hashParameters => [
super.javascriptEnabled,
super.trackingProtectionPolicy,
super.httpsOnlyMode,
super.globalPrivacyControlEnabled,
super.preferredColorScheme,
super.cookieBannerHandlingMode,
super.cookieBannerHandlingModePrivateBrowsing,
super.cookieBannerHandlingGlobalRules,
super.cookieBannerHandlingGlobalRulesSubFrames,
super.webContentIsolationStrategy,
super.userAgent,
queryParameterStripping,
bounceTrackingProtectionMode,
super.enterpriseRootsEnabled,
addonCollection,
];
}
@@ -51,6 +51,8 @@ abstract class _$EngineSettingsCWProxy {
BounceTrackingProtectionMode bounceTrackingProtectionMode,
);
EngineSettings addonCollection(AddonCollection? addonCollection);
/// Creates a new instance with the provided field values.
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `EngineSettings(...).copyWith.fieldName(value)`.
///
@@ -73,6 +75,7 @@ abstract class _$EngineSettingsCWProxy {
bool? enterpriseRootsEnabled,
QueryParameterStripping queryParameterStripping,
BounceTrackingProtectionMode bounceTrackingProtectionMode,
AddonCollection? addonCollection,
});
}
@@ -153,6 +156,10 @@ class _$EngineSettingsCWProxyImpl implements _$EngineSettingsCWProxy {
BounceTrackingProtectionMode bounceTrackingProtectionMode,
) => call(bounceTrackingProtectionMode: bounceTrackingProtectionMode);
@override
EngineSettings addonCollection(AddonCollection? addonCollection) =>
call(addonCollection: addonCollection);
@override
/// Creates a new instance with the provided field values.
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `EngineSettings(...).copyWith.fieldName(value)`.
@@ -178,6 +185,7 @@ class _$EngineSettingsCWProxyImpl implements _$EngineSettingsCWProxy {
Object? enterpriseRootsEnabled = const $CopyWithPlaceholder(),
Object? queryParameterStripping = const $CopyWithPlaceholder(),
Object? bounceTrackingProtectionMode = const $CopyWithPlaceholder(),
Object? addonCollection = const $CopyWithPlaceholder(),
}) {
return EngineSettings(
javascriptEnabled: javascriptEnabled == const $CopyWithPlaceholder()
@@ -251,6 +259,10 @@ class _$EngineSettingsCWProxyImpl implements _$EngineSettingsCWProxy {
? _value.bounceTrackingProtectionMode
// ignore: cast_nullable_to_non_nullable
: bounceTrackingProtectionMode as BounceTrackingProtectionMode,
addonCollection: addonCollection == const $CopyWithPlaceholder()
? _value.addonCollection
// ignore: cast_nullable_to_non_nullable
: addonCollection as AddonCollection?,
);
}
}
@@ -308,6 +320,9 @@ EngineSettings _$EngineSettingsFromJson(Map<String, dynamic> json) =>
),
userAgent: json['userAgent'] as String?,
enterpriseRootsEnabled: json['enterpriseRootsEnabled'] as bool?,
addonCollection: EngineSettings._addonCollectionFromJson(
json['addonCollection'] as String?,
),
);
Map<String, dynamic> _$EngineSettingsToJson(
@@ -337,6 +352,9 @@ Map<String, dynamic> _$EngineSettingsToJson(
'bounceTrackingProtectionMode':
_$BounceTrackingProtectionModeEnumMap[instance
.bounceTrackingProtectionMode]!,
'addonCollection': EngineSettings._addonCollectionToJson(
instance.addonCollection,
),
};
const _$TrackingProtectionPolicyEnumMap = {
@@ -94,6 +94,10 @@ class EngineSettingsRepository extends _$EngineSettingsRepository {
DriftSqlType.bool,
db.typeMapping,
),
'addonCollection': settings['addonCollection']?.readAs(
DriftSqlType.string,
db.typeMapping,
),
});
}
@@ -34,7 +34,7 @@ final class EngineSettingsRepositoryProvider
}
String _$engineSettingsRepositoryHash() =>
r'd0c2fbe060b5eaee7189f6cb0dd58c97cf5987b5';
r'8cf0a615f825ddc6411c2985d2cdc19ef31251cb';
abstract class _$EngineSettingsRepository
extends $StreamNotifier<EngineSettings> {