forked from mozilla-mobile/android-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue mozilla-mobile#10140 - Part 2: Make a copy of GeckoLoginDelegat…
…eWrapper as GeckoAutocompleteStorageDelegate We make a copy of GeckoLoginDelegateWrapper to not break the deprecated usage of `Autocomplete.LoginStorageDelegate` until we are ready to replace with `GeckoStorageDelegate` which will use the new GV API `Autocomplete.StorageDelegate`.
- Loading branch information
1 parent
3b52fdb
commit 90ef4bf
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...java/mozilla/components/browser/engine/gecko/autofill/GeckoAutocompleteStorageDelegate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/. */ | ||
|
||
package mozilla.components.browser.engine.gecko.autofill | ||
|
||
import kotlinx.coroutines.Dispatchers.IO | ||
import kotlinx.coroutines.GlobalScope | ||
import kotlinx.coroutines.launch | ||
import mozilla.components.browser.engine.gecko.ext.toLogin | ||
import mozilla.components.browser.engine.gecko.ext.toLoginEntry | ||
import mozilla.components.concept.storage.Login | ||
import mozilla.components.concept.storage.LoginStorageDelegate | ||
import org.mozilla.geckoview.Autocomplete | ||
import org.mozilla.geckoview.GeckoResult | ||
|
||
/** | ||
* This class exists only to convert incoming [LoginEntry] arguments into [Login]s, then forward | ||
* them to [storageDelegate]. This allows us to avoid duplicating [LoginStorageDelegate] code | ||
* between different versions of GeckoView, by duplicating this wrapper instead. | ||
*/ | ||
@Suppress("Deprecation") | ||
// This will be addressed in https://github.com/mozilla-mobile/android-components/issues/10093 | ||
class GeckoLoginDelegate(private val storageDelegate: LoginStorageDelegate) : | ||
Autocomplete.LoginStorageDelegate { | ||
|
||
override fun onLoginSave(login: Autocomplete.LoginEntry) { | ||
storageDelegate.onLoginSave(login.toLogin()) | ||
} | ||
|
||
override fun onLoginFetch(domain: String): GeckoResult<Array<Autocomplete.LoginEntry>>? { | ||
val result = GeckoResult<Array<Autocomplete.LoginEntry>>() | ||
|
||
GlobalScope.launch(IO) { | ||
val storedLogins = storageDelegate.onLoginFetch(domain) | ||
|
||
val logins = storedLogins.await() | ||
.map { it.toLoginEntry() } | ||
.toTypedArray() | ||
|
||
result.complete(logins) | ||
} | ||
|
||
return result | ||
} | ||
} |