-
Notifications
You must be signed in to change notification settings - Fork 1k
Add in-browser prompt to import Google Passwords #6290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4239864
Add in-browser prompt to import Google Passwords
CDRussell 2b7c13c
Add WebView capability check to the in-browser promo rule checker
CDRussell c46aaa3
Ensure available input types determined on io dispatcher
CDRussell 7fb8faa
Enable feature flag for import password in-browser promo
CDRussell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
87 changes: 87 additions & 0 deletions
87
...in/java/com/duckduckgo/autofill/impl/configuration/AutofillAvailableInputTypesProvider.kt
This file contains hidden or 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,87 @@ | ||
/* | ||
* Copyright (c) 2025 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.duckduckgo.autofill.impl.configuration | ||
|
||
import com.duckduckgo.autofill.api.AutofillCapabilityChecker | ||
import com.duckduckgo.autofill.api.domain.app.LoginCredentials | ||
import com.duckduckgo.autofill.api.email.EmailManager | ||
import com.duckduckgo.autofill.impl.configuration.AutofillAvailableInputTypesProvider.AvailableInputTypes | ||
import com.duckduckgo.autofill.impl.importing.InBrowserImportPromo | ||
import com.duckduckgo.autofill.impl.jsbridge.response.AvailableInputTypeCredentials | ||
import com.duckduckgo.autofill.impl.sharedcreds.ShareableCredentials | ||
import com.duckduckgo.autofill.impl.store.InternalAutofillStore | ||
import com.duckduckgo.common.utils.DispatcherProvider | ||
import com.duckduckgo.di.scopes.AppScope | ||
import com.squareup.anvil.annotations.ContributesBinding | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.withContext | ||
|
||
interface AutofillAvailableInputTypesProvider { | ||
suspend fun getTypes(url: String?): AvailableInputTypes | ||
|
||
data class AvailableInputTypes( | ||
val username: Boolean = false, | ||
val password: Boolean = false, | ||
val email: Boolean = false, | ||
val credentialsImport: Boolean = false, | ||
) | ||
} | ||
|
||
@ContributesBinding(AppScope::class) | ||
class RealAutofillAvailableInputTypesProvider @Inject constructor( | ||
private val emailManager: EmailManager, | ||
private val autofillStore: InternalAutofillStore, | ||
private val shareableCredentials: ShareableCredentials, | ||
private val autofillCapabilityChecker: AutofillCapabilityChecker, | ||
private val inBrowserPromo: InBrowserImportPromo, | ||
private val dispatchers: DispatcherProvider, | ||
) : AutofillAvailableInputTypesProvider { | ||
|
||
override suspend fun getTypes(url: String?): AvailableInputTypes { | ||
return withContext(dispatchers.io()) { | ||
val availableInputTypeCredentials = determineIfCredentialsAvailable(url) | ||
val credentialsAvailableOnThisPage = availableInputTypeCredentials.username || availableInputTypeCredentials.password | ||
val emailAvailable = determineIfEmailAvailable() | ||
val importPromoAvailable = inBrowserPromo.canShowPromo(credentialsAvailableOnThisPage, url) | ||
|
||
AvailableInputTypes( | ||
username = availableInputTypeCredentials.username, | ||
password = availableInputTypeCredentials.password, | ||
email = emailAvailable, | ||
credentialsImport = importPromoAvailable, | ||
) | ||
} | ||
} | ||
|
||
private suspend fun determineIfCredentialsAvailable(url: String?): AvailableInputTypeCredentials { | ||
return if (url == null || !autofillCapabilityChecker.canInjectCredentialsToWebView(url)) { | ||
AvailableInputTypeCredentials(username = false, password = false) | ||
} else { | ||
val matches = mutableListOf<LoginCredentials>() | ||
val directMatches = autofillStore.getCredentials(url) | ||
val shareableMatches = shareableCredentials.shareableCredentials(url) | ||
matches.addAll(directMatches) | ||
matches.addAll(shareableMatches) | ||
|
||
val usernameSearch = matches.find { !it.username.isNullOrEmpty() } | ||
val passwordSearch = matches.find { !it.password.isNullOrEmpty() } | ||
|
||
AvailableInputTypeCredentials(username = usernameSearch != null, password = passwordSearch != null) | ||
} | ||
} | ||
private fun determineIfEmailAvailable(): Boolean = emailManager.isSignedIn() | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.