2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

[fenix] Move creation of GeckoRuntime to flavor-specific source set.

Since we are now able to build against GeckoView Nightly and GeckoView Beta,
we should create the GeckoRuntime from a flavor-specific source set.

Creating the runtime is not covered by the AC abstraction and so API changes
in GeckoView Nightly can break the build and leaves us with no option to fix
it from a shared code base. Separating the creation of GeckoRuntime
allows us to adapt individually and also to configure the runtimes
differently.
This commit is contained in:
Sebastian Kaspari 2019-08-26 14:48:35 +02:00
parent 2127d42c9d
commit 6ac2509131
5 changed files with 97 additions and 34 deletions

View File

@ -0,0 +1,46 @@
/* 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
import mozilla.components.lib.crash.handler.CrashHandlerService
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
fun getOrCreateRuntime(context: Context): GeckoRuntime {
if (runtime == null) {
runtime = createRuntime(context)
}
return runtime!!
}
private fun createRuntime(context: Context): GeckoRuntime {
val builder = GeckoRuntimeSettings.Builder()
testConfig?.let {
builder.extras(it)
.remoteDebuggingEnabled(true)
}
val runtimeSettings = builder
.crashHandler(CrashHandlerService::class.java)
.useContentProcessHint(true)
.build()
if (!Settings.getInstance(context).shouldUseAutoSize) {
runtimeSettings.automaticFontSizeAdjustment = false
val fontSize = Settings.getInstance(context).fontSizeFactor
runtimeSettings.fontSizeFactor = fontSize
}
return GeckoRuntime.create(context, runtimeSettings)
}
}

View File

@ -0,0 +1,46 @@
/* 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
import mozilla.components.lib.crash.handler.CrashHandlerService
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
fun getOrCreateRuntime(context: Context): GeckoRuntime {
if (runtime == null) {
runtime = createRuntime(context)
}
return runtime!!
}
private fun createRuntime(context: Context): GeckoRuntime {
val builder = GeckoRuntimeSettings.Builder()
testConfig?.let {
builder.extras(it)
.remoteDebuggingEnabled(true)
}
val runtimeSettings = builder
.crashHandler(CrashHandlerService::class.java)
.useContentProcessHint(true)
.build()
if (!Settings.getInstance(context).shouldUseAutoSize) {
runtimeSettings.automaticFontSizeAdjustment = false
val fontSize = Settings.getInstance(context).fontSizeFactor
runtimeSettings.fontSizeFactor = fontSize
}
return GeckoRuntime.create(context, runtimeSettings)
}
}

View File

@ -4,12 +4,12 @@
package org.mozilla.fenix.browser
import GeckoProvider
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.ext.components
/**
* This activity is used for performance testing with Raptor/tp6:
@ -20,7 +20,7 @@ class BrowserPerformanceTestActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
components.core.testConfig = SafeIntent(intent).extras
GeckoProvider.testConfig = SafeIntent(intent).extras
val intent = Intent(intent)

View File

@ -4,9 +4,9 @@
package org.mozilla.fenix.components
import GeckoProvider
import android.content.Context
import android.content.res.Configuration
import android.os.Bundle
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@ -27,14 +27,11 @@ import mozilla.components.feature.media.MediaFeature
import mozilla.components.feature.media.RecordingDevicesNotificationFeature
import mozilla.components.feature.media.state.MediaStateMachine
import mozilla.components.feature.session.HistoryDelegate
import mozilla.components.lib.crash.handler.CrashHandlerService
import org.mozilla.fenix.AppRequestInterceptor
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.test.Mockable
import org.mozilla.fenix.utils.Settings
import org.mozilla.geckoview.GeckoRuntime
import org.mozilla.geckoview.GeckoRuntimeSettings
import java.util.concurrent.TimeUnit
/**
@ -43,30 +40,6 @@ import java.util.concurrent.TimeUnit
@Mockable
class Core(private val context: Context) {
protected val runtime by lazy {
val builder = GeckoRuntimeSettings.Builder()
testConfig?.let {
builder.extras(it)
.remoteDebuggingEnabled(true)
}
val runtimeSettings = builder
.crashHandler(CrashHandlerService::class.java)
.useContentProcessHint(true)
.build()
if (!Settings.getInstance(context).shouldUseAutoSize) {
runtimeSettings.automaticFontSizeAdjustment = false
val fontSize = Settings.getInstance(context).fontSizeFactor
runtimeSettings.fontSizeFactor = fontSize
}
GeckoRuntime.create(context, runtimeSettings)
}
var testConfig: Bundle? = null
/**
* The browser engine component initialized based on the build
* configuration (see build variants).
@ -83,14 +56,14 @@ class Core(private val context: Context) {
suspendMediaWhenInactive = !FeatureFlags.mediaIntegration
)
GeckoEngine(context, defaultSettings, runtime)
GeckoEngine(context, defaultSettings, GeckoProvider.getOrCreateRuntime(context))
}
/**
* [Client] implementation to be used for code depending on `concept-fetch``
*/
val client: Client by lazy {
GeckoViewFetchClient(context, runtime)
GeckoViewFetchClient(context, GeckoProvider.getOrCreateRuntime(context))
}
val sessionStorage: SessionStorage by lazy {

View File

@ -9,12 +9,10 @@ import io.mockk.mockk
import kotlinx.coroutines.ObsoleteCoroutinesApi
import mozilla.components.browser.engine.gecko.GeckoEngine
import mozilla.components.browser.session.SessionManager
import org.mozilla.geckoview.GeckoRuntime
@ObsoleteCoroutinesApi
class TestCore(private val context: Context) : Core(context) {
override val runtime = mockk<GeckoRuntime>(relaxed = true)
override val engine = mockk<GeckoEngine>(relaxed = true)
override val sessionManager = SessionManager(engine)
}