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
@@ -14,6 +14,7 @@ import eu.weblibre.flutter_mozilla_components.components.Features
import eu.weblibre.flutter_mozilla_components.components.Search
import eu.weblibre.flutter_mozilla_components.components.Services
import eu.weblibre.flutter_mozilla_components.components.UseCases
import eu.weblibre.flutter_mozilla_components.pigeons.AddonCollection
import eu.weblibre.flutter_mozilla_components.pigeons.BrowserExtensionEvents
import eu.weblibre.flutter_mozilla_components.pigeons.ContentBlocking
import eu.weblibre.flutter_mozilla_components.pigeons.GeckoAddonEvents
@@ -37,6 +38,7 @@ class Components(private val context: Context,
val selectionAction: SelectionActionDelegate,
val logLevel: Log.Priority,
val contentBlocking: ContentBlocking,
val addonCollection: AddonCollection?,
private val addonEvents: GeckoAddonEvents,
private val tabContentEvents: GeckoTabContentEvents,
private val extensionEvents: BrowserExtensionEvents
@@ -7,6 +7,7 @@
package eu.weblibre.flutter_mozilla_components
import android.content.Context
import eu.weblibre.flutter_mozilla_components.pigeons.AddonCollection
import eu.weblibre.flutter_mozilla_components.pigeons.BrowserExtensionEvents
import eu.weblibre.flutter_mozilla_components.pigeons.ContentBlocking
import eu.weblibre.flutter_mozilla_components.pigeons.GeckoAddonEvents
@@ -60,7 +61,8 @@ object GlobalComponents {
tabContentEvents: GeckoTabContentEvents,
extensionEvents: BrowserExtensionEvents,
logLevel: Log.Priority,
contentBlocking: ContentBlocking
contentBlocking: ContentBlocking,
addonCollection: AddonCollection?,
) {
Logger.debug("Creating new components")
@@ -71,6 +73,7 @@ object GlobalComponents {
selectionAction,
logLevel,
contentBlocking,
addonCollection,
addonEvents,
tabContentEvents,
extensionEvents,
@@ -15,6 +15,7 @@ import eu.weblibre.flutter_mozilla_components.GeckoViewFactory
import eu.weblibre.flutter_mozilla_components.GlobalComponents
import eu.weblibre.flutter_mozilla_components.activities.NotificationActivity
import eu.weblibre.flutter_mozilla_components.feature.DefaultSelectionActionDelegate
import eu.weblibre.flutter_mozilla_components.pigeons.AddonCollection
import eu.weblibre.flutter_mozilla_components.pigeons.BrowserExtensionEvents
import eu.weblibre.flutter_mozilla_components.pigeons.ContentBlocking
import eu.weblibre.flutter_mozilla_components.pigeons.GeckoAddonEvents
@@ -140,7 +141,11 @@ class GeckoBrowserApiImpl : GeckoBrowserApi {
return GeckoViewBuildConfig.MOZ_APP_VERSION + "-" + GeckoViewBuildConfig.MOZ_APP_BUILDID
}
override fun initialize(logLevel: LogLevel, contentBlocking: ContentBlocking) {
override fun initialize(
logLevel: LogLevel,
contentBlocking: ContentBlocking,
addonCollection: AddonCollection?
) {
synchronized(this) {
if(!isGeckoInitialized) {
val geckoLogging = GeckoLogging(_flutterPluginBinding.binaryMessenger)
@@ -154,7 +159,7 @@ class GeckoBrowserApiImpl : GeckoBrowserApi {
Log.addSink(PriorityAwareLogSink(level, geckoLogging))
setupGeckoEngine(level, contentBlocking)
setupGeckoEngine(level, contentBlocking, addonCollection)
isGeckoInitialized = true
}
}
@@ -170,7 +175,11 @@ class GeckoBrowserApiImpl : GeckoBrowserApi {
return false
}
private fun setupGeckoEngine(logLevel: Log.Priority, contentBlocking: ContentBlocking) {
private fun setupGeckoEngine(
logLevel: Log.Priority,
contentBlocking: ContentBlocking,
addonCollection: AddonCollection?
) {
val selectionActionEvents = GeckoSelectionActionEvents(_flutterPluginBinding.binaryMessenger)
val selectionActionDelegate = DefaultSelectionActionDelegate(selectionActionEvents) { actions ->
@@ -201,7 +210,8 @@ class GeckoBrowserApiImpl : GeckoBrowserApi {
tabContentEvents,
extensionEvents,
logLevel,
contentBlocking
contentBlocking,
addonCollection
)
GeckoEngineSettingsApi.setUp(_flutterPluginBinding.binaryMessenger, GeckoEngineSettingsApiImpl())
@@ -60,12 +60,13 @@ import mozilla.components.feature.webnotifications.WebNotificationFeature
import mozilla.components.support.base.worker.Frequency
import java.util.concurrent.TimeUnit
private const val DAY_IN_MINUTES = 24 * 60L
private const val AMO_COLLECTION_MAX_CACHE_AGE = 24 * 60L
class Core(private val context: Context,
private val components: Components,
private val flutterEvents: GeckoStateEvents,
private val extensionEvents: BrowserExtensionEvents
class Core(
private val context: Context,
private val components: Components,
private val flutterEvents: GeckoStateEvents,
private val extensionEvents: BrowserExtensionEvents
) {
val prefs by lazy {
PreferenceManager.getDefaultSharedPreferences(context)
@@ -137,22 +138,33 @@ class Core(private val context: Context,
val addonUpdater by lazy {
DefaultAddonUpdater(
context,
Frequency(1, TimeUnit.DAYS),
Frequency(12, TimeUnit.HOURS),
components.notificationsDelegate
)
}
val addonsProvider by lazy {
AMOAddonsProvider(
context,
client,
collectionName = "7dfae8669acc4312a65e8ba5553036",
maxCacheAgeInMinutes = DAY_IN_MINUTES,
)
if (components.addonCollection != null)
AMOAddonsProvider(
context,
client,
serverURL = components.addonCollection.serverURL,
collectionUser = components.addonCollection.collectionUser,
collectionName = components.addonCollection.collectionName,
maxCacheAgeInMinutes = AMO_COLLECTION_MAX_CACHE_AGE
) else
AMOAddonsProvider(
context,
client,
maxCacheAgeInMinutes = AMO_COLLECTION_MAX_CACHE_AGE
)
}
val supportedAddonsChecker by lazy {
DefaultSupportedAddonsChecker(context, Frequency(1, TimeUnit.DAYS))
DefaultSupportedAddonsChecker(
context,
Frequency(12, TimeUnit.HOURS)
)
}
val fileUploadsDirCleaner: FileUploadsDirCleaner by lazy {
@@ -164,7 +176,7 @@ class Core(private val context: Context,
BrowserStore(
middleware = listOf(
FlutterEventMiddleware(flutterEvents),
DownloadMiddleware(context, DownloadService::class.java, {false}),
DownloadMiddleware(context, DownloadService::class.java, { false }),
ThumbnailsMiddleware(thumbnailStorage),
ReaderViewMiddleware(),
UndoMiddleware(),
@@ -227,7 +239,7 @@ class Core(private val context: Context,
*/
val historyStorage by lazy { lazyHistoryStorage.value }
val permissionStorage by lazy { PermissionStorage( geckoSitePermissionsStorage ) }
val permissionStorage by lazy { PermissionStorage(geckoSitePermissionsStorage) }
/**
* Constructs a [TrackingProtectionPolicy] based on current preferences.
@@ -241,7 +253,7 @@ class Core(private val context: Context,
* @return the constructed tracking protection policy based on preferences.
*/
private fun createTrackingProtectionPolicy(
trackingPolicy: EngineSession. TrackingProtectionPolicyForSessionTypes,
trackingPolicy: EngineSession.TrackingProtectionPolicyForSessionTypes,
normalMode: Boolean = true,
privateMode: Boolean = true,
): TrackingProtectionPolicy {
@@ -2104,6 +2104,40 @@ data class ShareInternetResourceState (
override fun hashCode(): Int = toList().hashCode()
}
/** Generated class from Pigeon that represents data sent in messages. */
data class AddonCollection (
val serverURL: String,
val collectionUser: String,
val collectionName: String
)
{
companion object {
fun fromList(pigeonVar_list: List<Any?>): AddonCollection {
val serverURL = pigeonVar_list[0] as String
val collectionUser = pigeonVar_list[1] as String
val collectionName = pigeonVar_list[2] as String
return AddonCollection(serverURL, collectionUser, collectionName)
}
}
fun toList(): List<Any?> {
return listOf(
serverURL,
collectionUser,
collectionName,
)
}
override fun equals(other: Any?): Boolean {
if (other !is AddonCollection) {
return false
}
if (this === other) {
return true
}
return GeckoPigeonUtils.deepEquals(toList(), other.toList()) }
override fun hashCode(): Int = toList().hashCode()
}
private open class GeckoPigeonCodec : StandardMessageCodec() {
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
return when (type) {
@@ -2402,6 +2436,11 @@ private open class GeckoPigeonCodec : StandardMessageCodec() {
ShareInternetResourceState.fromList(it)
}
}
188.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
AddonCollection.fromList(it)
}
}
else -> super.readValueOfType(type, buffer)
}
}
@@ -2643,6 +2682,10 @@ private open class GeckoPigeonCodec : StandardMessageCodec() {
stream.write(187)
writeValue(stream, value.toList())
}
is AddonCollection -> {
stream.write(188)
writeValue(stream, value.toList())
}
else -> super.writeValue(stream, value)
}
}
@@ -2652,7 +2695,7 @@ private open class GeckoPigeonCodec : StandardMessageCodec() {
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
interface GeckoBrowserApi {
fun getGeckoVersion(): String
fun initialize(logLevel: LogLevel, contentBlocking: ContentBlocking)
fun initialize(logLevel: LogLevel, contentBlocking: ContentBlocking, addonCollection: AddonCollection?)
fun showNativeFragment(): Boolean
fun onTrimMemory(level: Long)
@@ -2687,8 +2730,9 @@ interface GeckoBrowserApi {
val args = message as List<Any?>
val logLevelArg = args[0] as LogLevel
val contentBlockingArg = args[1] as ContentBlocking
val addonCollectionArg = args[2] as AddonCollection?
val wrapped: List<Any?> = try {
api.initialize(logLevelArg, contentBlockingArg)
api.initialize(logLevelArg, contentBlockingArg, addonCollectionArg)
listOf(null)
} catch (exception: Throwable) {
GeckoPigeonUtils.wrapError(exception)