[fenix] Issue https://github.com/mozilla-mobile/fenix/issues/11333: Set ContentBlocking settings directly on GeckoRuntime

We set the ContentBlockingSettings directly on the GeckoRuntime now to
improve the startup of the engine.

This change has requirements from Android Components and GeckoView, so
we would only see the full perf benefits in Nightly as the changes ride
the train, although we might start to see some of them as we're updating
the GeckoProvider for the `geckoBeta` variant as well.

Co-authored-by: Arturo Mejia <arturomejiamarmol@gmail.com>
pull/600/head
Jonathan Almeida 4 years ago committed by Arturo Mejia
parent 9153350cd2
commit bb3e5bfbf9

@ -5,7 +5,9 @@
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import mozilla.components.browser.engine.gecko.autofill.GeckoLoginDelegateWrapper import mozilla.components.browser.engine.gecko.autofill.GeckoLoginDelegateWrapper
import mozilla.components.browser.engine.gecko.ext.toContentBlockingSetting
import mozilla.components.browser.engine.gecko.glean.GeckoAdapter import mozilla.components.browser.engine.gecko.glean.GeckoAdapter
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy
import mozilla.components.concept.storage.LoginsStorage import mozilla.components.concept.storage.LoginsStorage
import mozilla.components.lib.crash.handler.CrashHandlerService import mozilla.components.lib.crash.handler.CrashHandlerService
import mozilla.components.service.sync.logins.GeckoLoginStorageDelegate import mozilla.components.service.sync.logins.GeckoLoginStorageDelegate
@ -21,10 +23,11 @@ object GeckoProvider {
@Synchronized @Synchronized
fun getOrCreateRuntime( fun getOrCreateRuntime(
context: Context, context: Context,
storage: Lazy<LoginsStorage> storage: Lazy<LoginsStorage>,
trackingProtectionPolicy: TrackingProtectionPolicy
): GeckoRuntime { ): GeckoRuntime {
if (runtime == null) { if (runtime == null) {
runtime = createRuntime(context, storage) runtime = createRuntime(context, storage, trackingProtectionPolicy)
} }
return runtime!! return runtime!!
@ -32,7 +35,8 @@ object GeckoProvider {
private fun createRuntime( private fun createRuntime(
context: Context, context: Context,
storage: Lazy<LoginsStorage> storage: Lazy<LoginsStorage>,
policy: TrackingProtectionPolicy
): GeckoRuntime { ): GeckoRuntime {
val builder = GeckoRuntimeSettings.Builder() val builder = GeckoRuntimeSettings.Builder()
@ -44,6 +48,7 @@ object GeckoProvider {
val runtimeSettings = builder val runtimeSettings = builder
.crashHandler(CrashHandlerService::class.java) .crashHandler(CrashHandlerService::class.java)
.telemetryDelegate(GeckoAdapter()) .telemetryDelegate(GeckoAdapter())
.contentBlocking(policy.toContentBlockingSetting())
.aboutConfigEnabled(Config.channel.isBeta) .aboutConfigEnabled(Config.channel.isBeta)
.debugLogging(Config.channel.isDebug) .debugLogging(Config.channel.isDebug)
.build() .build()

@ -5,7 +5,9 @@
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import mozilla.components.browser.engine.gecko.autofill.GeckoLoginDelegateWrapper import mozilla.components.browser.engine.gecko.autofill.GeckoLoginDelegateWrapper
import mozilla.components.browser.engine.gecko.ext.toContentBlockingSetting
import mozilla.components.browser.engine.gecko.glean.GeckoAdapter import mozilla.components.browser.engine.gecko.glean.GeckoAdapter
import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy
import mozilla.components.concept.storage.LoginsStorage import mozilla.components.concept.storage.LoginsStorage
import mozilla.components.lib.crash.handler.CrashHandlerService import mozilla.components.lib.crash.handler.CrashHandlerService
import mozilla.components.service.sync.logins.GeckoLoginStorageDelegate import mozilla.components.service.sync.logins.GeckoLoginStorageDelegate
@ -21,10 +23,11 @@ object GeckoProvider {
@Synchronized @Synchronized
fun getOrCreateRuntime( fun getOrCreateRuntime(
context: Context, context: Context,
storage: Lazy<LoginsStorage> storage: Lazy<LoginsStorage>,
trackingProtectionPolicy: TrackingProtectionPolicy
): GeckoRuntime { ): GeckoRuntime {
if (runtime == null) { if (runtime == null) {
runtime = createRuntime(context, storage) runtime = createRuntime(context, storage, trackingProtectionPolicy)
} }
return runtime!! return runtime!!
@ -32,7 +35,8 @@ object GeckoProvider {
private fun createRuntime( private fun createRuntime(
context: Context, context: Context,
storage: Lazy<LoginsStorage> storage: Lazy<LoginsStorage>,
policy: TrackingProtectionPolicy
): GeckoRuntime { ): GeckoRuntime {
val builder = GeckoRuntimeSettings.Builder() val builder = GeckoRuntimeSettings.Builder()
@ -44,6 +48,7 @@ object GeckoProvider {
val runtimeSettings = builder val runtimeSettings = builder
.crashHandler(CrashHandlerService::class.java) .crashHandler(CrashHandlerService::class.java)
.telemetryDelegate(GeckoAdapter()) .telemetryDelegate(GeckoAdapter())
.contentBlocking(policy.toContentBlockingSetting())
.debugLogging(Config.channel.isDebug) .debugLogging(Config.channel.isDebug)
.aboutConfigEnabled(true) .aboutConfigEnabled(true)
.build() .build()

@ -86,7 +86,11 @@ class Core(private val context: Context) {
GeckoEngine( GeckoEngine(
context, context,
defaultSettings, defaultSettings,
GeckoProvider.getOrCreateRuntime(context, lazyPasswordsStorage) GeckoProvider.getOrCreateRuntime(
context,
lazyPasswordsStorage,
trackingProtectionPolicyFactory.createTrackingProtectionPolicy()
)
).also { ).also {
WebCompatFeature.install(it) WebCompatFeature.install(it)
@ -108,7 +112,11 @@ class Core(private val context: Context) {
val client: Client by lazy { val client: Client by lazy {
GeckoViewFetchClient( GeckoViewFetchClient(
context, context,
GeckoProvider.getOrCreateRuntime(context, lazyPasswordsStorage) GeckoProvider.getOrCreateRuntime(
context,
lazyPasswordsStorage,
trackingProtectionPolicyFactory.createTrackingProtectionPolicy()
)
) )
} }

Loading…
Cancel
Save