1
0
Fork 0

For #7796 - Add Gecko Beta GeckoProvider LoginStorageDelegate

master
ekager 2020-02-18 13:36:55 -08:00 committed by Emily Kager
parent 5c6e6ddfb7
commit 1944399f0e
1 changed files with 18 additions and 4 deletions

View File

@ -4,12 +4,15 @@
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.glean.GeckoAdapter import mozilla.components.browser.engine.gecko.glean.GeckoAdapter
import mozilla.components.lib.crash.handler.CrashHandlerService import mozilla.components.lib.crash.handler.CrashHandlerService
import mozilla.components.lib.dataprotect.SecureAbove22Preferences import mozilla.components.lib.dataprotect.SecureAbove22Preferences
import mozilla.components.service.experiments.Experiments import mozilla.components.service.experiments.Experiments
import mozilla.components.service.sync.logins.AsyncLoginsStorage import mozilla.components.service.sync.logins.AsyncLoginsStorage
import mozilla.components.service.sync.logins.GeckoLoginStorageDelegate
import org.mozilla.fenix.Config import org.mozilla.fenix.Config
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.utils.Settings
import org.mozilla.geckoview.GeckoRuntime import org.mozilla.geckoview.GeckoRuntime
import org.mozilla.geckoview.GeckoRuntimeSettings import org.mozilla.geckoview.GeckoRuntimeSettings
@ -19,20 +22,23 @@ object GeckoProvider {
private var runtime: GeckoRuntime? = null private var runtime: GeckoRuntime? = null
@Synchronized @Synchronized
@Suppress("UNUSED_PARAMETER") // API not yet landed in GV beta
fun getOrCreateRuntime( fun getOrCreateRuntime(
context: Context, context: Context,
storage: AsyncLoginsStorage, storage: AsyncLoginsStorage,
securePreferences: SecureAbove22Preferences securePreferences: SecureAbove22Preferences
): GeckoRuntime { ): GeckoRuntime {
if (runtime == null) { if (runtime == null) {
runtime = createRuntime(context) runtime = createRuntime(context, storage, securePreferences)
} }
return runtime!! return runtime!!
} }
private fun createRuntime(context: Context): GeckoRuntime { private fun createRuntime(
context: Context,
storage: AsyncLoginsStorage,
securePreferences: SecureAbove22Preferences
): GeckoRuntime {
val builder = GeckoRuntimeSettings.Builder() val builder = GeckoRuntimeSettings.Builder()
testConfig?.let { testConfig?.let {
@ -60,6 +66,14 @@ object GeckoProvider {
runtimeSettings.fontSizeFactor = fontSize runtimeSettings.fontSizeFactor = fontSize
} }
return GeckoRuntime.create(context, runtimeSettings) val geckoRuntime = GeckoRuntime.create(context, runtimeSettings)
val loginStorageDelegate = GeckoLoginStorageDelegate(
storage,
securePreferences,
{ context.settings().shouldAutofillLogins && context.settings().shouldPromptToSaveLogins }
)
geckoRuntime.loginStorageDelegate = GeckoLoginDelegateWrapper(loginStorageDelegate)
return geckoRuntime
} }
} }