added support for overriding locales

This commit is contained in:
Fabian Freund
2025-10-20 16:21:10 +02:00
parent aca0767d9a
commit 1c7e9ec741
66 changed files with 1679 additions and 7 deletions
@@ -73,6 +73,7 @@ object EngineProvider {
//builder.debugLogging(components.logLevel == Log.Priority.DEBUG)
builder.consoleOutput(components.logLevel == Log.Priority.DEBUG)
builder.contentBlocking(contentBlocking.build())
builder.locales(arrayOf("en-US", "en")) // Will be overridden later
runtime = GeckoRuntime.create(context, builder.build())
}
@@ -6,6 +6,7 @@
package eu.weblibre.flutter_mozilla_components.api
import eu.weblibre.flutter_mozilla_components.EngineProvider
import eu.weblibre.flutter_mozilla_components.GlobalComponents
import eu.weblibre.flutter_mozilla_components.pigeons.ColorScheme
import eu.weblibre.flutter_mozilla_components.pigeons.CookieBannerHandlingMode
@@ -147,6 +148,10 @@ class GeckoEngineSettingsApiImpl : GeckoEngineSettingsApi {
if(settings.fingerprintingProtectionOverrides != null) {
components.core.engineSettings.fingerprintingProtectionOverrides = settings.fingerprintingProtectionOverrides
}
if(settings.locales != null) {
// components.core.engineSettings.automaticLanguageAdjustment = false
components.core.runtime.settings.locales = settings.locales.toTypedArray()
}
}
override fun updateRuntimeSettings(settings: GeckoEngineSettings) {
@@ -14,6 +14,7 @@ import eu.weblibre.flutter_mozilla_components.Components
import eu.weblibre.flutter_mozilla_components.interceptor.AppRequestInterceptor
import eu.weblibre.flutter_mozilla_components.services.DownloadService
import eu.weblibre.flutter_mozilla_components.EngineProvider
import eu.weblibre.flutter_mozilla_components.EngineProvider.getOrCreateRuntime
import eu.weblibre.flutter_mozilla_components.PermissionStorage
import eu.weblibre.flutter_mozilla_components.services.MediaSessionService
import eu.weblibre.flutter_mozilla_components.activities.NotificationActivity
@@ -58,6 +59,7 @@ import mozilla.components.feature.session.middleware.undo.UndoMiddleware
import mozilla.components.feature.sitepermissions.OnDiskSitePermissionsStorage
import mozilla.components.feature.webnotifications.WebNotificationFeature
import mozilla.components.support.base.worker.Frequency
import org.mozilla.geckoview.GeckoRuntime
import java.util.concurrent.TimeUnit
private const val AMO_COLLECTION_MAX_CACHE_AGE = 24 * 60L
@@ -107,6 +109,10 @@ class Core(
)
}
val runtime: GeckoRuntime by lazy {
getOrCreateRuntime(context)
}
val engine: Engine by lazy {
EngineProvider.createEngine(context, engineSettings, extensionEvents)
}
@@ -1678,7 +1678,8 @@ data class GeckoEngineSettings (
val contentBlocking: ContentBlocking? = null,
val enterpriseRootsEnabled: Boolean? = null,
val dohSettings: DohSettings? = null,
val fingerprintingProtectionOverrides: String? = null
val fingerprintingProtectionOverrides: String? = null,
val locales: List<String>? = null
)
{
companion object {
@@ -1698,7 +1699,8 @@ data class GeckoEngineSettings (
val enterpriseRootsEnabled = pigeonVar_list[12] as Boolean?
val dohSettings = pigeonVar_list[13] as DohSettings?
val fingerprintingProtectionOverrides = pigeonVar_list[14] as String?
return GeckoEngineSettings(javascriptEnabled, trackingProtectionPolicy, httpsOnlyMode, globalPrivacyControlEnabled, preferredColorScheme, cookieBannerHandlingMode, cookieBannerHandlingModePrivateBrowsing, cookieBannerHandlingGlobalRules, cookieBannerHandlingGlobalRulesSubFrames, webContentIsolationStrategy, userAgent, contentBlocking, enterpriseRootsEnabled, dohSettings, fingerprintingProtectionOverrides)
val locales = pigeonVar_list[15] as List<String>?
return GeckoEngineSettings(javascriptEnabled, trackingProtectionPolicy, httpsOnlyMode, globalPrivacyControlEnabled, preferredColorScheme, cookieBannerHandlingMode, cookieBannerHandlingModePrivateBrowsing, cookieBannerHandlingGlobalRules, cookieBannerHandlingGlobalRulesSubFrames, webContentIsolationStrategy, userAgent, contentBlocking, enterpriseRootsEnabled, dohSettings, fingerprintingProtectionOverrides, locales)
}
}
fun toList(): List<Any?> {
@@ -1718,6 +1720,7 @@ data class GeckoEngineSettings (
enterpriseRootsEnabled,
dohSettings,
fingerprintingProtectionOverrides,
locales,
)
}
override fun equals(other: Any?): Boolean {
@@ -2044,6 +2044,7 @@ class GeckoEngineSettings {
this.enterpriseRootsEnabled,
this.dohSettings,
this.fingerprintingProtectionOverrides,
this.locales,
});
bool? javascriptEnabled;
@@ -2076,6 +2077,8 @@ class GeckoEngineSettings {
String? fingerprintingProtectionOverrides;
List<String>? locales;
List<Object?> _toList() {
return <Object?>[
javascriptEnabled,
@@ -2093,6 +2096,7 @@ class GeckoEngineSettings {
enterpriseRootsEnabled,
dohSettings,
fingerprintingProtectionOverrides,
locales,
];
}
@@ -2117,6 +2121,7 @@ class GeckoEngineSettings {
enterpriseRootsEnabled: result[12] as bool?,
dohSettings: result[13] as DohSettings?,
fingerprintingProtectionOverrides: result[14] as String?,
locales: (result[15] as List<Object?>?)?.cast<String>(),
);
}
@@ -667,6 +667,7 @@ class GeckoEngineSettings {
final bool? enterpriseRootsEnabled;
final DohSettings? dohSettings;
final String? fingerprintingProtectionOverrides;
final List<String>? locales;
GeckoEngineSettings(
this.javascriptEnabled,
@@ -684,6 +685,7 @@ class GeckoEngineSettings {
this.enterpriseRootsEnabled,
this.dohSettings,
this.fingerprintingProtectionOverrides,
this.locales,
);
}