Bug 1266683 - Part 1 - Try harder to prevent awesome bar keyboard text prediction during private browsing.
In order to avoid sensitive content ending up in the keyboard's user dictionary during private browsing, we're setting InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS on the awesome bar to prevent text prediction in the awesome bar from working within that context.
Some keyboards however will ignore this and activate their input prediction regardless. As a workaround, we therefore now use InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD instead, which should reliably work on all keyboards. However because this solution is not compatible with InputType.TYPE_TEXT_VARIATION_URI, we only apply this workaround for keyboards that are known to be problematic, so as not to lose the special URI input mode on unaffected keyboards.
MozReview-Commit-ID: DRaJVQr95vF
--- a/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarEditText.java
+++ b/mobile/android/base/java/org/mozilla/gecko/toolbar/ToolbarEditText.java
@@ -422,17 +422,24 @@ public class ToolbarEditText extends Cus
@Override
public InputConnection onCreateInputConnection(final EditorInfo outAttrs) {
final InputConnection ic = super.onCreateInputConnection(outAttrs);
if (ic == null) {
return null;
}
if (isPrivateMode()) {
- outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
+ if (InputMethods.needsHackToTurnOffSuggestions(mContext)) {
+ // Some keyboards ignore InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS, so we
+ // have to use something else to make sure private mode data stays private.
+ outAttrs.inputType &= ~InputType.TYPE_MASK_VARIATION;
+ outAttrs.inputType |= InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
+ } else {
+ outAttrs.inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
+ }
}
return new InputConnectionWrapper(ic, false) {
@Override
public boolean deleteSurroundingText(final int beforeLength, final int afterLength) {
if (removeAutocomplete(getText())) {
// If we have autocomplete text, the cursor is at the boundary between
// regular and autocomplete text. So regardless of which direction we
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/InputMethods.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/InputMethods.java
@@ -68,9 +68,15 @@ final public class InputMethods {
String inputMethod = getCurrentInputMethod(context);
return (Versions.feature17Plus &&
(METHOD_ANDROID_LATINIME.equals(inputMethod) ||
METHOD_GOOGLE_LATINIME.equals(inputMethod))) ||
METHOD_SWYPE.equals(inputMethod) ||
METHOD_SWYPE_BETA.equals(inputMethod) ||
METHOD_TOUCHPAL_KEYBOARD.equals(inputMethod);
}
+
+ public static boolean needsHackToTurnOffSuggestions(Context context) {
+ String inputMethod = getCurrentInputMethod(context);
+ return (METHOD_SAMSUNG.equals(inputMethod) ||
+ METHOD_SWIFTKEY.equals(inputMethod));
+ }
}