diff --git a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/ChoicePromptUpdateDelegate.kt b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/ChoicePromptDelegate.kt similarity index 92% rename from components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/ChoicePromptUpdateDelegate.kt rename to components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/ChoicePromptDelegate.kt index 2917c475398..b8353e753a6 100644 --- a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/ChoicePromptUpdateDelegate.kt +++ b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/ChoicePromptDelegate.kt @@ -19,11 +19,17 @@ import org.mozilla.geckoview.GeckoSession.PromptDelegate.PromptInstanceDelegate * with the onPromptUpdate callback. * @param previousPrompt [PromptRequest] to be updated. */ -internal class ChoicePromptUpdateDelegate( +internal class ChoicePromptDelegate( private val geckoSession: GeckoEngineSession, private var previousPrompt: PromptRequest, ) : PromptInstanceDelegate { + override fun onPromptDismiss(prompt: BasePrompt) { + geckoSession.notifyObservers { + onPromptDismissed(previousPrompt) + } + } + override fun onPromptUpdate(prompt: BasePrompt) { if (prompt is ChoicePrompt) { val promptRequest = updatePromptChoices(prompt) diff --git a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt index f5f6fcb61ea..afa3a561016 100644 --- a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt +++ b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/prompt/GeckoPromptDelegate.kt @@ -258,7 +258,7 @@ internal class GeckoPromptDelegate(private val geckoEngineSession: GeckoEngineSe else -> throw InvalidParameterException("${geckoPrompt.type} is not a valid Gecko @Choice.ChoiceType") } - geckoPrompt.delegate = ChoicePromptUpdateDelegate( + geckoPrompt.delegate = ChoicePromptDelegate( geckoEngineSession, promptRequest ) diff --git a/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/prompt/ChoicePromptUpdateDelegateTest.kt b/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/prompt/ChoicePromptDelegateTest.kt similarity index 73% rename from components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/prompt/ChoicePromptUpdateDelegateTest.kt rename to components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/prompt/ChoicePromptDelegateTest.kt index f6ca2a42e3b..7d61e3708ce 100644 --- a/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/prompt/ChoicePromptUpdateDelegateTest.kt +++ b/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/prompt/ChoicePromptDelegateTest.kt @@ -16,7 +16,7 @@ import org.junit.runner.RunWith import org.mozilla.geckoview.GeckoSession @RunWith(AndroidJUnit4::class) -class ChoicePromptUpdateDelegateTest { +class ChoicePromptDelegateTest { @Test fun `WHEN onPromptUpdate is called from GeckoView THEN notifyObservers is invoked with onPromptUpdate`() { @@ -41,7 +41,7 @@ class ChoicePromptUpdateDelegateTest { { isOnConfirmCalled = true }, { isOnDismissCalled = true } ) - val delegate = ChoicePromptUpdateDelegate(mockSession, prompt) + val delegate = ChoicePromptDelegate(mockSession, prompt) val updatedPrompt = mock() ReflectionUtils.setField(updatedPrompt, "choices", arrayOf()) @@ -55,4 +55,23 @@ class ChoicePromptUpdateDelegateTest { assertTrue(isOnDismissCalled) assertTrue(isOnConfirmCalled) } + + @Test + fun `WHEN onPromptDismiss is called from GeckoView THEN notifyObservers is invoked with onPromptDismissed`() { + val mockSession = GeckoEngineSession(mock()) + var isOnDismissCalled = false + mockSession.register(object : EngineSession.Observer { + override fun onPromptDismissed(promptRequest: PromptRequest) { + super.onPromptDismissed(promptRequest) + isOnDismissCalled = true + } + }) + val basePrompt: GeckoSession.PromptDelegate.ChoicePrompt = mock() + val prompt: PromptRequest = mock() + val delegate = ChoicePromptDelegate(mockSession, prompt) + + delegate.onPromptDismiss(basePrompt) + + assertTrue(isOnDismissCalled) + } } diff --git a/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/PromptFeature.kt b/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/PromptFeature.kt index 74a0bc7f0a3..2a812b6d796 100644 --- a/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/PromptFeature.kt +++ b/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/PromptFeature.kt @@ -319,6 +319,11 @@ class PromptFeature private constructor( activePromptRequest as SelectAddress ) } + is SingleChoice, + is MultipleChoice, + is MenuChoice -> { + (activePrompt?.get() as? ChoiceDialogFragment)?.dismissAllowingStateLoss() + } else -> { // no-op }