Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Grisha Kruglov committed Feb 29, 2020
1 parent f7aec4c commit bcb1680
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 52 deletions.
11 changes: 4 additions & 7 deletions app/src/geckoBeta/java/org/mozilla/fenix/engine/GeckoProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import android.content.Context
import android.os.Bundle
import mozilla.components.browser.engine.gecko.autofill.GeckoLoginDelegateWrapper
import mozilla.components.browser.engine.gecko.glean.GeckoAdapter
import mozilla.components.concept.storage.LoginsStorage
import mozilla.components.lib.crash.handler.CrashHandlerService
import mozilla.components.lib.dataprotect.SecureAbove22Preferences
import mozilla.components.service.experiments.Experiments
import mozilla.components.service.sync.logins.AsyncLoginsStorage
import mozilla.components.service.sync.logins.GeckoLoginStorageDelegate
import org.mozilla.fenix.Config
import org.mozilla.fenix.ext.settings
Expand All @@ -24,20 +24,18 @@ object GeckoProvider {
@Synchronized
fun getOrCreateRuntime(
context: Context,
storage: AsyncLoginsStorage,
securePreferences: SecureAbove22Preferences
storage: LoginsStorage
): GeckoRuntime {
if (runtime == null) {
runtime = createRuntime(context, storage, securePreferences)
runtime = createRuntime(context, storage)
}

return runtime!!
}

private fun createRuntime(
context: Context,
storage: AsyncLoginsStorage,
securePreferences: SecureAbove22Preferences
storage: LoginsStorage
): GeckoRuntime {
val builder = GeckoRuntimeSettings.Builder()

Expand Down Expand Up @@ -69,7 +67,6 @@ object GeckoProvider {
val geckoRuntime = GeckoRuntime.create(context, runtimeSettings)
val loginStorageDelegate = GeckoLoginStorageDelegate(
storage,
securePreferences,
{ context.settings().shouldAutofillLogins && context.settings().shouldPromptToSaveLogins }
)
geckoRuntime.loginStorageDelegate = GeckoLoginDelegateWrapper(loginStorageDelegate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
customTabId = customTabSessionId,
fragmentManager = parentFragmentManager,
loginValidationDelegate = DefaultLoginValidationDelegate(
context.components.core.asyncPasswordsStorage,
context.components.core.getSecureAbove22Preferences()
context.components.core.passwordsStorage
),
isSaveLoginEnabled = {
context.settings().shouldPromptToSaveLogins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import mozilla.components.feature.accounts.push.SendTabFeature
import mozilla.components.feature.push.AutoPushFeature
import mozilla.components.feature.push.PushConfig
import mozilla.components.lib.crash.CrashReporter
import mozilla.components.lib.dataprotect.SecureAbove22Preferences
import mozilla.components.service.fxa.DeviceConfig
import mozilla.components.service.fxa.ServerConfig
import mozilla.components.service.fxa.SyncConfig
Expand All @@ -30,7 +29,7 @@ import mozilla.components.service.fxa.manager.SCOPE_SESSION
import mozilla.components.service.fxa.manager.SCOPE_SYNC
import mozilla.components.service.fxa.manager.SyncEnginesStorage
import mozilla.components.service.fxa.sync.GlobalSyncableStoreProvider
import mozilla.components.service.sync.logins.SyncableLoginsStore
import mozilla.components.service.sync.logins.PlacesLoginStorage
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags
Expand All @@ -51,8 +50,7 @@ class BackgroundServices(
crashReporter: CrashReporter,
historyStorage: PlacesHistoryStorage,
bookmarkStorage: PlacesBookmarksStorage,
passwordsStorage: SyncableLoginsStore,
secureAbove22Preferences: SecureAbove22Preferences
passwordsStorage: PlacesLoginStorage
) {
fun defaultDeviceName(context: Context): String =
context.getString(
Expand Down Expand Up @@ -88,7 +86,7 @@ class BackgroundServices(
syncPeriodInMinutes = 240L) // four hours
}

val pushService by lazy { FirebasePushService() }
private val pushService by lazy { FirebasePushService() }

val push by lazy { makePushConfig()?.let { makePush(it) } }

Expand All @@ -97,7 +95,6 @@ class BackgroundServices(
GlobalSyncableStoreProvider.configureStore(SyncEngine.History to historyStorage)
GlobalSyncableStoreProvider.configureStore(SyncEngine.Bookmarks to bookmarkStorage)
GlobalSyncableStoreProvider.configureStore(SyncEngine.Passwords to passwordsStorage)
GlobalSyncableStoreProvider.configureKeyStorage(secureAbove22Preferences)
}

private val telemetryAccountObserver = TelemetryAccountObserver(
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/org/mozilla/fenix/components/Components.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class Components(private val context: Context) {
analytics.crashReporter,
core.historyStorage,
core.bookmarksStorage,
core.syncablePasswordsStorage,
core.getSecureAbove22Preferences()
core.passwordsStorage
)
}
val services by lazy { Services(context, backgroundServices.accountManager) }
Expand Down
32 changes: 5 additions & 27 deletions app/src/main/java/org/mozilla/fenix/components/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import mozilla.components.feature.webcompat.WebCompatFeature
import mozilla.components.feature.webnotifications.WebNotificationFeature
import mozilla.components.lib.dataprotect.SecureAbove22Preferences
import mozilla.components.lib.dataprotect.generateEncryptionKey
import mozilla.components.service.sync.logins.AsyncLoginsStorageAdapter
import mozilla.components.service.sync.logins.SyncableLoginsStore
import mozilla.components.service.sync.logins.PlacesLoginStorage
import org.mozilla.fenix.AppRequestInterceptor
import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags
Expand Down Expand Up @@ -76,9 +75,7 @@ class Core(private val context: Context) {
GeckoEngine(
context,
defaultSettings,
GeckoProvider.getOrCreateRuntime(
context, asyncPasswordsStorage, getSecureAbove22Preferences()
)
GeckoProvider.getOrCreateRuntime(context, passwordsStorage)
).also {
WebCompatFeature.install(it)
}
Expand All @@ -90,11 +87,7 @@ class Core(private val context: Context) {
val client: Client by lazy {
GeckoViewFetchClient(
context,
GeckoProvider.getOrCreateRuntime(
context,
asyncPasswordsStorage,
getSecureAbove22Preferences()
)
GeckoProvider.getOrCreateRuntime(context, passwordsStorage)
)
}

Expand Down Expand Up @@ -201,6 +194,8 @@ class Core(private val context: Context) {

val bookmarksStorage by lazy { PlacesBookmarksStorage(context) }

val passwordsStorage by lazy { PlacesLoginStorage(context, passwordsEncryptionKey) }

val tabCollectionStorage by lazy { TabCollectionStorage(context, sessionManager) }

val topSiteStorage by lazy { TopSiteStorage(context) }
Expand All @@ -209,23 +204,6 @@ class Core(private val context: Context) {

val webAppManifestStorage by lazy { ManifestStorage(context) }

val asyncPasswordsStorage by lazy {
AsyncLoginsStorageAdapter.forDatabase(
File(
context.filesDir,
"logins.sqlite"
).canonicalPath
)
}

val syncablePasswordsStorage by lazy {
SyncableLoginsStore(
asyncPasswordsStorage
) {
CompletableDeferred(passwordsEncryptionKey)
}
}

/**
* Shared Preferences that encrypt/decrypt using Android KeyStore and lib-dataprotect for 23+
* only on Nightly/Debug for now, otherwise simply stored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ class SavedLoginSiteInfoFragment : Fragment(R.layout.fragment_saved_login_site_i
var deleteLoginJob: Deferred<Boolean>? = null
val deleteJob = lifecycleScope.launch(IO) {
deleteLoginJob = async {
requireContext().components.core.syncablePasswordsStorage.withUnlocked {
it.delete(args.savedLoginItem.id).await()
}
requireContext().components.core.passwordsStorage.delete(args.savedLoginItem.id)
}
deleteLoginJob?.await()
withContext(Main) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mozilla.appservices.logins.ServerPassword
import mozilla.components.concept.storage.Login
import mozilla.components.lib.state.ext.consumeFrom
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
Expand Down Expand Up @@ -103,18 +104,16 @@ class SavedLoginsFragment : Fragment() {
}

private fun loadAndMapLogins() {
var deferredLogins: Deferred<List<ServerPassword>>? = null
var deferredLogins: Deferred<List<Login>>? = null
val fetchLoginsJob = lifecycleScope.launch(IO) {
deferredLogins = async {
requireContext().components.core.syncablePasswordsStorage.withUnlocked {
it.list().await()
}
requireContext().components.core.passwordsStorage.list()
}
val logins = deferredLogins?.await()
logins?.let {
withContext(Main) {
savedLoginsStore.dispatch(SavedLoginsFragmentAction.UpdateLogins(logins.map { item ->
SavedLoginsItem(item.hostname, item.username, item.password, item.id)
SavedLoginsItem(item.origin, item.username, item.password, item.guid!!)
}))
}
}
Expand Down

0 comments on commit bcb1680

Please sign in to comment.