2019-08-26 14:48:35 +02:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
import android.content.Context
|
2020-01-14 01:18:41 +01:00
|
|
|
import mozilla.components.browser.engine.gecko.autofill.GeckoLoginDelegateWrapper
|
2020-07-09 21:15:58 +02:00
|
|
|
import mozilla.components.browser.engine.gecko.ext.toContentBlockingSetting
|
2019-09-05 18:58:35 +02:00
|
|
|
import mozilla.components.browser.engine.gecko.glean.GeckoAdapter
|
2020-07-09 21:15:58 +02:00
|
|
|
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy
|
2020-02-29 01:21:12 +01:00
|
|
|
import mozilla.components.concept.storage.LoginsStorage
|
2019-08-26 14:48:35 +02:00
|
|
|
import mozilla.components.lib.crash.handler.CrashHandlerService
|
2020-01-14 01:18:41 +01:00
|
|
|
import mozilla.components.service.sync.logins.GeckoLoginStorageDelegate
|
2019-12-20 22:27:05 +01:00
|
|
|
import org.mozilla.fenix.Config
|
2020-07-21 19:47:10 +02:00
|
|
|
import org.mozilla.fenix.ext.components
|
2019-08-26 14:48:35 +02:00
|
|
|
import org.mozilla.geckoview.GeckoRuntime
|
|
|
|
import org.mozilla.geckoview.GeckoRuntimeSettings
|
|
|
|
|
|
|
|
object GeckoProvider {
|
|
|
|
private var runtime: GeckoRuntime? = null
|
|
|
|
|
|
|
|
@Synchronized
|
2020-01-14 01:18:41 +01:00
|
|
|
fun getOrCreateRuntime(
|
|
|
|
context: Context,
|
2020-07-09 21:15:58 +02:00
|
|
|
storage: Lazy<LoginsStorage>,
|
|
|
|
trackingProtectionPolicy: TrackingProtectionPolicy
|
2020-01-14 01:18:41 +01:00
|
|
|
): GeckoRuntime {
|
2019-08-26 14:48:35 +02:00
|
|
|
if (runtime == null) {
|
2020-07-09 21:15:58 +02:00
|
|
|
runtime = createRuntime(context, storage, trackingProtectionPolicy)
|
2019-08-26 14:48:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return runtime!!
|
|
|
|
}
|
|
|
|
|
2020-01-14 01:18:41 +01:00
|
|
|
private fun createRuntime(
|
|
|
|
context: Context,
|
2020-07-09 21:15:58 +02:00
|
|
|
storage: Lazy<LoginsStorage>,
|
|
|
|
policy: TrackingProtectionPolicy
|
2020-01-14 01:18:41 +01:00
|
|
|
): GeckoRuntime {
|
2019-08-26 14:48:35 +02:00
|
|
|
val builder = GeckoRuntimeSettings.Builder()
|
|
|
|
|
|
|
|
val runtimeSettings = builder
|
|
|
|
.crashHandler(CrashHandlerService::class.java)
|
2019-09-05 18:58:35 +02:00
|
|
|
.telemetryDelegate(GeckoAdapter())
|
2020-07-09 21:15:58 +02:00
|
|
|
.contentBlocking(policy.toContentBlockingSetting())
|
2019-12-20 22:27:05 +01:00
|
|
|
.debugLogging(Config.channel.isDebug)
|
2019-09-25 19:53:47 +02:00
|
|
|
.aboutConfigEnabled(true)
|
2019-08-26 14:48:35 +02:00
|
|
|
.build()
|
|
|
|
|
2020-07-21 19:47:10 +02:00
|
|
|
val settings = context.components.settings
|
|
|
|
if (!settings.shouldUseAutoSize) {
|
2019-08-26 14:48:35 +02:00
|
|
|
runtimeSettings.automaticFontSizeAdjustment = false
|
2020-07-21 19:47:10 +02:00
|
|
|
val fontSize = settings.fontSizeFactor
|
2019-08-26 14:48:35 +02:00
|
|
|
runtimeSettings.fontSizeFactor = fontSize
|
|
|
|
}
|
|
|
|
|
2020-01-14 01:18:41 +01:00
|
|
|
val geckoRuntime = GeckoRuntime.create(context, runtimeSettings)
|
2020-07-03 01:35:21 +02:00
|
|
|
val loginStorageDelegate = GeckoLoginStorageDelegate(storage)
|
2020-01-14 01:18:41 +01:00
|
|
|
geckoRuntime.loginStorageDelegate = GeckoLoginDelegateWrapper(loginStorageDelegate)
|
|
|
|
|
|
|
|
return geckoRuntime
|
2019-08-26 14:48:35 +02:00
|
|
|
}
|
|
|
|
}
|