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
|
|
|
|
import android.os.Bundle
|
2020-02-18 22:36:55 +01:00
|
|
|
import mozilla.components.browser.engine.gecko.autofill.GeckoLoginDelegateWrapper
|
2019-09-05 18:58:35 +02:00
|
|
|
import mozilla.components.browser.engine.gecko.glean.GeckoAdapter
|
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.lib.dataprotect.SecureAbove22Preferences
|
2020-01-03 01:41:00 +01:00
|
|
|
import mozilla.components.service.experiments.Experiments
|
2020-01-14 01:18:41 +01:00
|
|
|
import mozilla.components.service.sync.logins.AsyncLoginsStorage
|
2020-02-18 22:36:55 +01:00
|
|
|
import mozilla.components.service.sync.logins.GeckoLoginStorageDelegate
|
2019-12-20 22:27:05 +01:00
|
|
|
import org.mozilla.fenix.Config
|
2020-02-18 22:36:55 +01:00
|
|
|
import org.mozilla.fenix.ext.settings
|
2019-08-26 14:48:35 +02:00
|
|
|
import org.mozilla.fenix.utils.Settings
|
|
|
|
import org.mozilla.geckoview.GeckoRuntime
|
|
|
|
import org.mozilla.geckoview.GeckoRuntimeSettings
|
|
|
|
|
|
|
|
object GeckoProvider {
|
|
|
|
var testConfig: Bundle? = null
|
|
|
|
private var runtime: GeckoRuntime? = null
|
|
|
|
|
|
|
|
@Synchronized
|
2020-01-14 01:18:41 +01:00
|
|
|
fun getOrCreateRuntime(
|
|
|
|
context: Context,
|
|
|
|
storage: AsyncLoginsStorage,
|
|
|
|
securePreferences: SecureAbove22Preferences
|
|
|
|
): GeckoRuntime {
|
2019-08-26 14:48:35 +02:00
|
|
|
if (runtime == null) {
|
2020-02-18 22:36:55 +01:00
|
|
|
runtime = createRuntime(context, storage, securePreferences)
|
2019-08-26 14:48:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return runtime!!
|
|
|
|
}
|
|
|
|
|
2020-02-18 22:36:55 +01:00
|
|
|
private fun createRuntime(
|
|
|
|
context: Context,
|
|
|
|
storage: AsyncLoginsStorage,
|
|
|
|
securePreferences: SecureAbove22Preferences
|
|
|
|
): GeckoRuntime {
|
2019-08-26 14:48:35 +02:00
|
|
|
val builder = GeckoRuntimeSettings.Builder()
|
|
|
|
|
|
|
|
testConfig?.let {
|
|
|
|
builder.extras(it)
|
|
|
|
.remoteDebuggingEnabled(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
val runtimeSettings = builder
|
|
|
|
.crashHandler(CrashHandlerService::class.java)
|
|
|
|
.useContentProcessHint(true)
|
2019-09-05 18:58:35 +02:00
|
|
|
.telemetryDelegate(GeckoAdapter())
|
2020-01-23 00:12:24 +01:00
|
|
|
.aboutConfigEnabled(Config.channel.isBeta)
|
2019-12-20 22:27:05 +01:00
|
|
|
.debugLogging(Config.channel.isDebug)
|
2019-08-26 14:48:35 +02:00
|
|
|
.build()
|
|
|
|
|
2020-01-10 19:54:39 +01:00
|
|
|
Experiments.withExperiment("webrender-performance-comparison-experiment") { branchName ->
|
2020-01-03 20:07:01 +01:00
|
|
|
if (branchName == "disable_webrender") {
|
2020-01-10 19:54:39 +01:00
|
|
|
runtimeSettings.extras.putInt("forcedisablewebrender", 1)
|
2020-01-03 20:07:01 +01:00
|
|
|
}
|
2020-01-03 01:41:00 +01:00
|
|
|
}
|
|
|
|
|
2019-08-26 14:48:35 +02:00
|
|
|
if (!Settings.getInstance(context).shouldUseAutoSize) {
|
|
|
|
runtimeSettings.automaticFontSizeAdjustment = false
|
|
|
|
val fontSize = Settings.getInstance(context).fontSizeFactor
|
|
|
|
runtimeSettings.fontSizeFactor = fontSize
|
|
|
|
}
|
|
|
|
|
2020-02-18 22:36:55 +01:00
|
|
|
val geckoRuntime = GeckoRuntime.create(context, runtimeSettings)
|
|
|
|
val loginStorageDelegate = GeckoLoginStorageDelegate(
|
|
|
|
storage,
|
|
|
|
securePreferences,
|
|
|
|
{ context.settings().shouldAutofillLogins && context.settings().shouldPromptToSaveLogins }
|
|
|
|
)
|
|
|
|
geckoRuntime.loginStorageDelegate = GeckoLoginDelegateWrapper(loginStorageDelegate)
|
|
|
|
|
|
|
|
return geckoRuntime
|
2019-08-26 14:48:35 +02:00
|
|
|
}
|
|
|
|
}
|