Pier Angelo Vendrame pushed to branch firefox-android-115.2.1-13.5-1 at The Tor Project / Applications / firefox-android
Commits: 8e9aca94 by Titouan Thibaud at 2024-05-13T09:31:35+02:00 Bug 1885171 - set private keyboard on Javascript prompts in private browsing r=android-reviewers,boek
Differential Revision: https://phabricator.services.mozilla.com/D208135
- - - - -
3 changed files:
- android-components/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/PromptFeature.kt - android-components/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/dialog/TextPromptDialogFragment.kt - android-components/components/feature/prompts/src/test/java/mozilla/components/feature/prompts/dialog/TextPromptDialogFragmentTest.kt
Changes:
===================================== android-components/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/PromptFeature.kt ===================================== @@ -17,6 +17,7 @@ import kotlinx.coroutines.flow.map import mozilla.components.browser.state.action.ContentAction import mozilla.components.browser.state.selector.findTabOrCustomTab import mozilla.components.browser.state.selector.findTabOrCustomTabOrSelectedTab +import mozilla.components.browser.state.selector.selectedTab import mozilla.components.browser.state.state.SessionState import mozilla.components.browser.state.store.BrowserStore import mozilla.components.concept.engine.prompt.Choice @@ -772,6 +773,7 @@ class PromptFeature private constructor( inputLabel, inputValue, promptAbuserDetector.areDialogsBeingAbused(), + store.state.selectedTab?.content?.private == true, ) } }
===================================== android-components/components/feature/prompts/src/main/java/mozilla/components/feature/prompts/dialog/TextPromptDialogFragment.kt ===================================== @@ -11,14 +11,17 @@ import android.os.Bundle import android.text.Editable import android.text.TextWatcher import android.view.LayoutInflater +import android.view.inputmethod.EditorInfo.IME_NULL import android.widget.EditText import android.widget.TextView import androidx.appcompat.app.AlertDialog +import androidx.core.view.inputmethod.EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING import mozilla.components.feature.prompts.R
private const val KEY_USER_EDIT_TEXT = "KEY_USER_EDIT_TEXT" private const val KEY_LABEL_INPUT = "KEY_LABEL_INPUT" private const val KEY_DEFAULT_INPUT_VALUE = "KEY_DEFAULT_INPUT_VALUE" +private const val KEY_PRIVATE = "KEY_PRIVATE"
/** * [androidx.fragment.app.DialogFragment] implementation to display a @@ -37,6 +40,11 @@ internal class TextPromptDialogFragment : AbstractPromptTextDialogFragment(), Te */ internal val labelInput: String? by lazy { safeArguments.getString(KEY_LABEL_INPUT) }
+ /** + * Tells if the Dialog is shown from private browsing + */ + internal val private: Boolean? by lazy { safeArguments.getBoolean(KEY_PRIVATE) } + private var userSelectionEditText: String get() = safeArguments.getString(KEY_USER_EDIT_TEXT, defaultInputValue) set(value) { @@ -72,6 +80,7 @@ internal class TextPromptDialogFragment : AbstractPromptTextDialogFragment(), Te label.text = labelInput editText.setText(defaultInputValue) editText.addTextChangedListener(this) + editText.imeOptions = if (private == true) IME_FLAG_NO_PERSONALIZED_LEARNING else IME_NULL
addCheckBoxIfNeeded(view)
@@ -99,6 +108,7 @@ internal class TextPromptDialogFragment : AbstractPromptTextDialogFragment(), Te * @param hasShownManyDialogs tells if this [sessionId] has shown many dialogs * in a short period of time, if is true a checkbox will be part of the dialog, for the user * to choose if wants to prevent this [sessionId] continuing showing dialogs. + * @param private tells if this dialog is triggered from private browsing */ @Suppress("LongParameterList") fun newInstance( @@ -109,6 +119,7 @@ internal class TextPromptDialogFragment : AbstractPromptTextDialogFragment(), Te inputLabel: String, defaultInputValue: String, hasShownManyDialogs: Boolean, + private: Boolean, ): TextPromptDialogFragment { val fragment = TextPromptDialogFragment() val arguments = fragment.arguments ?: Bundle() @@ -121,6 +132,7 @@ internal class TextPromptDialogFragment : AbstractPromptTextDialogFragment(), Te putString(KEY_LABEL_INPUT, inputLabel) putString(KEY_DEFAULT_INPUT_VALUE, defaultInputValue) putBoolean(KEY_MANY_ALERTS, hasShownManyDialogs) + putBoolean(KEY_PRIVATE, private) }
fragment.arguments = arguments
===================================== android-components/components/feature/prompts/src/test/java/mozilla/components/feature/prompts/dialog/TextPromptDialogFragmentTest.kt ===================================== @@ -6,9 +6,11 @@ package mozilla.components.feature.prompts.dialog
import android.content.DialogInterface.BUTTON_POSITIVE import android.os.Looper.getMainLooper +import android.view.inputmethod.EditorInfo.IME_NULL import android.widget.CheckBox import android.widget.TextView import androidx.appcompat.app.AlertDialog +import androidx.core.view.inputmethod.EditorInfoCompat import androidx.core.view.isVisible import androidx.test.ext.junit.runners.AndroidJUnit4 import mozilla.components.feature.prompts.R.id @@ -41,7 +43,7 @@ class TextPromptDialogFragmentTest { @Test fun `build dialog`() { val fragment = spy( - TextPromptDialogFragment.newInstance("sessionId", "uid", true, "title", "label", "defaultValue", true), + TextPromptDialogFragment.newInstance("sessionId", "uid", true, "title", "label", "defaultValue", true, false), )
doReturn(appCompatContext).`when`(fragment).requireContext() @@ -73,12 +75,14 @@ class TextPromptDialogFragmentTest {
inputValue.text = "NewValue" assertEquals(inputValue.text.toString(), "NewValue") + + assertEquals(IME_NULL, inputValue.imeOptions) }
@Test fun `TextPrompt with hasShownManyDialogs equals false should not have a checkbox`() { val fragment = spy( - TextPromptDialogFragment.newInstance("sessionId", "uid", false, "title", "label", "defaultValue", false), + TextPromptDialogFragment.newInstance("sessionId", "uid", false, "title", "label", "defaultValue", false, false), )
doReturn(appCompatContext).`when`(fragment).requireContext() @@ -95,7 +99,7 @@ class TextPromptDialogFragmentTest { @Test fun `Clicking on positive button notifies the feature`() { val fragment = spy( - TextPromptDialogFragment.newInstance("sessionId", "uid", true, "title", "label", "defaultValue", false), + TextPromptDialogFragment.newInstance("sessionId", "uid", true, "title", "label", "defaultValue", false, false), )
fragment.feature = mockFeature @@ -115,7 +119,7 @@ class TextPromptDialogFragmentTest { @Test fun `After checking no more dialogs checkbox feature onNoMoreDialogsChecked must be called`() { val fragment = spy( - TextPromptDialogFragment.newInstance("sessionId", "uid", false, "title", "label", "defaultValue", true), + TextPromptDialogFragment.newInstance("sessionId", "uid", false, "title", "label", "defaultValue", true, false), )
fragment.feature = mockFeature @@ -139,7 +143,7 @@ class TextPromptDialogFragmentTest { @Test fun `touching outside of the dialog must notify the feature onCancel`() { val fragment = spy( - TextPromptDialogFragment.newInstance("sessionId", "uid", true, "title", "label", "defaultValue", true), + TextPromptDialogFragment.newInstance("sessionId", "uid", true, "title", "label", "defaultValue", true, false), )
fragment.feature = mockFeature @@ -150,4 +154,19 @@ class TextPromptDialogFragmentTest {
verify(mockFeature).onCancel("sessionId", "uid") } + + @Test + fun `when TextPromptDialogFragment is created in private mode then keyboard is in private mode`() { + val fragment = spy( + TextPromptDialogFragment.newInstance("sessionId", "uid", true, "title", "label", "defaultValue", true, true), + ) + + fragment.feature = mockFeature + doReturn(appCompatContext).`when`(fragment).requireContext() + + val dialog = fragment.onCreateDialog(null).also { it.show() } + val editText = dialog.findViewById<TextView>(id.input_value) + + assertEquals(EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING, editText.imeOptions) + } }
View it on GitLab: https://gitlab.torproject.org/tpo/applications/firefox-android/-/commit/8e9a...