Skip to content

Commit

Permalink
Add new feature flag canIntegrateWebMessageBasedAutofillInWebView (#5111
Browse files Browse the repository at this point in the history
)

Task/Issue URL:
https://app.asana.com/0/1202552961248957/1208502642610048/f

### Description
Introduces new feature flag for autofill integration, specifically for
the _modern_ approach based on WebMessages`. This is deliberately
different from the existing `canIntegrateAutofillInWebView` feature flag
which will continue to serve older clients for now.

This gives us the ability to selectively disable the modern autofill
integration without impacting the older clients that are still using the
class autofill integration.


### Steps to test this PR

- [x] Smoke test autofill
  • Loading branch information
CDRussell authored Oct 8, 2024
1 parent 04e63ab commit e2031f5
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ interface AutofillFeature {
/**
* Kill switch for if we should inject Autofill javascript into the browser.
*
* @return `true` when the remote config has the global "canIntegrateAutofillInWebView" autofill sub-feature flag enabled
* @return `true` when the remote config has the global "canIntegrateWebMessageBasedAutofillInWebView" autofill sub-feature flag enabled
* If the remote feature is not present defaults to `true`
*/
@Toggle.DefaultValue(true)
fun canIntegrateAutofillInWebView(): Toggle
fun canIntegrateWebMessageBasedAutofillInWebView(): Toggle

/**
* @return `true` when the remote config has the global "canInjectCredentials" autofill sub-feature flag enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class AutofillGlobalCapabilityCheckerImpl @Inject constructor(
override suspend fun isAutofillEnabledByConfiguration(url: String): Boolean {
return withContext(dispatcherProvider.io()) {
val enabledAtTopLevel = isInternalTester() || isGlobalFeatureEnabled()
val canIntegrateAutofill = autofillFeature.canIntegrateAutofillInWebView().isEnabled()
val canIntegrateAutofill = autofillFeature.canIntegrateWebMessageBasedAutofillInWebView().isEnabled()
enabledAtTopLevel && canIntegrateAutofill && !isAnException(url)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ class AutofillWebMessageAttacherImpl @Inject constructor(
private val safeWebMessageHandler: SafeWebMessageHandler,
) : AutofillWebMessageAttacher {

@SuppressLint("AddWebMessageListenerUsage")
// suppress AddWebMessageListenerUsage, we don't have access to DuckDuckGoWebView here.
override suspend fun addListener(
webView: WebView,
listener: AutofillWebMessageListener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class AutofillGlobalCapabilityCheckerImplGlobalFeatureTest(
private fun configureCanIntegrateAutofillSubfeature(isEnabled: Boolean) {
val toggle: Toggle = mock()
whenever(toggle.isEnabled()).thenReturn(isEnabled)
whenever(autofillFeature.canIntegrateAutofillInWebView()).thenReturn(toggle)
whenever(autofillFeature.canIntegrateWebMessageBasedAutofillInWebView()).thenReturn(toggle)
}

private fun configureIfUrlIsException(isException: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class InlineBrowserAutofillTest {
canSaveCredentials: Boolean = true,
canGeneratePassword: Boolean = true,
canAccessCredentialManagement: Boolean = true,
canIntegrateAutofillInWebView: Boolean = true,
canIntegrateWebMessageBasedAutofillInWebView: Boolean = true,
deviceWebViewSupportsAutofill: Boolean = true,
): InlineBrowserAutofill {
val autofillFeature = FakeFeatureToggleFactory.create(AutofillFeature::class.java)
Expand All @@ -104,10 +104,10 @@ class InlineBrowserAutofillTest {
autofillFeature.canSaveCredentials().setRawStoredState(State(enable = canSaveCredentials))
autofillFeature.canGeneratePasswords().setRawStoredState(State(enable = canGeneratePassword))
autofillFeature.canAccessCredentialManagement().setRawStoredState(State(enable = canAccessCredentialManagement))
autofillFeature.canIntegrateAutofillInWebView().setRawStoredState(State(enable = canIntegrateAutofillInWebView))
autofillFeature.canIntegrateWebMessageBasedAutofillInWebView().setRawStoredState(State(enable = canIntegrateWebMessageBasedAutofillInWebView))

whenever(capabilityChecker.webViewSupportsAutofill()).thenReturn(deviceWebViewSupportsAutofill)
whenever(capabilityChecker.canInjectCredentialsToWebView(any())).thenReturn(canIntegrateAutofillInWebView)
whenever(capabilityChecker.canInjectCredentialsToWebView(any())).thenReturn(canInjectCredentials)

return InlineBrowserAutofill(
autofillCapabilityChecker = capabilityChecker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class AutofillInternalSettingsActivity : DuckDuckGoActivity() {
val autofillEnabled = autofillFeature.self()
val onByDefault = autofillFeature.onByDefault()
val onForExistingUsers = autofillFeature.onForExistingUsers()
val canIntegrateAutofill = autofillFeature.canIntegrateAutofillInWebView()
val canIntegrateAutofill = autofillFeature.canIntegrateWebMessageBasedAutofillInWebView()
val canSaveCredentials = autofillFeature.canSaveCredentials()
val canInjectCredentials = autofillFeature.canInjectCredentials()
val canGeneratePasswords = autofillFeature.canGeneratePasswords()
Expand Down

0 comments on commit e2031f5

Please sign in to comment.