Bug 1266683 - Part 4 - Forward private browsing state to GeckoInputConnection and use it there. r?jchen draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Tue, 01 Aug 2017 20:18:05 +0200
changeset 619268 3fc673210b1a83b0645f70779f0c810938255c9d
parent 619267 faaa58028d1ade5b4063a78b687d791d7e24dd89
child 640355 8ebc07a45ddb5b4af3db51be7a2508381f09248b
push id71633
push usermozilla@buttercookie.de
push dateTue, 01 Aug 2017 20:29:32 +0000
reviewersjchen
bugs1266683
milestone56.0a1
Bug 1266683 - Part 4 - Forward private browsing state to GeckoInputConnection and use it there. r?jchen MozReview-Commit-ID: 4BxZ9HyzDh2
mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/IGeckoEditableParent.aidl
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditableChild.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditableListener.java
mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
--- a/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/IGeckoEditableParent.aidl
+++ b/mobile/android/geckoview/src/main/aidl/org/mozilla/gecko/IGeckoEditableParent.aidl
@@ -10,17 +10,18 @@ import android.view.KeyEvent;
 import org.mozilla.gecko.IGeckoEditableChild;
 
 // Interface for GeckoEditable calls from child to parent
 interface IGeckoEditableParent {
     // Notify an IME event of a type defined in GeckoEditableListener.
     void notifyIME(IGeckoEditableChild child, int type);
 
     // Notify a change in editor state or type.
-    void notifyIMEContext(int state, String typeHint, String modeHint, String actionHint);
+    void notifyIMEContext(int state, String typeHint, String modeHint, String actionHint,
+                          boolean inPrivateBrowsing);
 
     // Notify a change in editor selection.
     void onSelectionChange(IBinder token, int start, int end);
 
     // Notify a change in editor text.
     void onTextChange(IBinder token, in CharSequence text,
                       int start, int unboundedOldEnd);
 
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditable.java
@@ -1122,35 +1122,37 @@ final class GeckoEditable extends IGecko
                     mListener.notifyIME(type);
                 }
             }
         });
     }
 
     @Override // IGeckoEditableParent
     public void notifyIMEContext(final int state, final String typeHint,
-                                 final String modeHint, final String actionHint) {
+                                 final String modeHint, final String actionHint,
+                                 final boolean inPrivateBrowsing) {
         // On Gecko or binder thread.
         if (DEBUG) {
             Log.d(LOGTAG, "notifyIMEContext(" +
                           getConstantName(GeckoEditableListener.class, "IME_STATE_", state) +
-                          ", \"" + typeHint + "\", \"" + modeHint + "\", \"" + actionHint + "\")");
+                          ", \"" + typeHint + "\", \"" + modeHint + "\", \"" + actionHint + "\", " +
+                          "inPrivateBrowsing=" + inPrivateBrowsing + ")");
         }
 
         // Don't check token for notifyIMEContext, because the calls all come
         // from the parent process.
         ThreadUtils.assertOnGeckoThread();
 
         mIcPostHandler.post(new Runnable() {
             @Override
             public void run() {
                 if (mListener == null) {
                     return;
                 }
-                mListener.notifyIMEContext(state, typeHint, modeHint, actionHint);
+                mListener.notifyIMEContext(state, typeHint, modeHint, actionHint, inPrivateBrowsing);
             }
         });
     }
 
     @Override // IGeckoEditableParent
     public void onSelectionChange(final IBinder token,
                                   final int start, final int end) {
         // On Gecko or binder thread.
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditableChild.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditableChild.java
@@ -164,17 +164,17 @@ final class GeckoEditableChild extends J
             ThreadUtils.assertOnGeckoThread();
             Log.d(LOGTAG, "notifyIMEContext(" + GeckoEditable.getConstantName(
                           GeckoEditableListener.class, "IME_STATE_", state) + ", \"" +
                           typeHint + "\", \"" + modeHint + "\", \"" + actionHint + "\", " +
                           "inPrivateBrowsing=" + inPrivateBrowsing + ")");
         }
 
         try {
-            mEditableParent.notifyIMEContext(state, typeHint, modeHint, actionHint);
+            mEditableParent.notifyIMEContext(state, typeHint, modeHint, actionHint, inPrivateBrowsing);
         } catch (final RemoteException e) {
             Log.e(LOGTAG, "Remote call failed", e);
         }
     }
 
     @WrapForJNI(calledFrom = "gecko", exceptionMode = "ignore")
     private void onSelectionChange(final int start, final int end) throws RemoteException {
         if (DEBUG) {
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditableListener.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoEditableListener.java
@@ -32,14 +32,14 @@ interface GeckoEditableListener {
     int NOTIFY_IME_TO_CANCEL_COMPOSITION = 9;
     // IME enabled state for notifyIMEContext()
     int IME_STATE_DISABLED = 0;
     int IME_STATE_ENABLED = 1;
     int IME_STATE_PASSWORD = 2;
     int IME_STATE_PLUGIN = 3;
 
     void notifyIME(int type);
-    void notifyIMEContext(int state, String typeHint, String modeHint, String actionHint);
+    void notifyIMEContext(int state, String typeHint, String modeHint, String actionHint, boolean inPrivateBrowsing);
     void onSelectionChange();
     void onTextChange();
     void onDefaultKeyEvent(KeyEvent event);
     void updateCompositionRects(final RectF[] aRects);
 }
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoInputConnection.java
@@ -60,16 +60,17 @@ class GeckoInputConnection
 
     private static Handler sBackgroundHandler;
 
     // Managed only by notifyIMEContext; see comments in notifyIMEContext
     private int mIMEState;
     private String mIMETypeHint = "";
     private String mIMEModeHint = "";
     private String mIMEActionHint = "";
+    private boolean mInPrivateBrowsing;
     private boolean mFocused;
 
     private String mCurrentInputMethod = "";
 
     private final View mView;
     private final GeckoEditableClient mEditableClient;
     protected int mBatchEditCount;
     private ExtractedTextRequest mUpdateRequest;
@@ -604,16 +605,20 @@ class GeckoInputConnection
         else if (mIMEActionHint.equalsIgnoreCase("send"))
             outAttrs.imeOptions = EditorInfo.IME_ACTION_SEND;
         else if (mIMEActionHint.length() > 0) {
             if (DEBUG)
                 Log.w(LOGTAG, "Unexpected mIMEActionHint=\"" + mIMEActionHint + "\"");
             outAttrs.actionLabel = mIMEActionHint;
         }
 
+        if (mInPrivateBrowsing) {
+            outAttrs.imeOptions |= InputMethods.IME_FLAG_NO_PERSONALIZED_LEARNING;
+        }
+
         Context context = getView().getContext();
         DisplayMetrics metrics = context.getResources().getDisplayMetrics();
         if (Math.min(metrics.widthPixels, metrics.heightPixels) > INLINE_IME_MIN_DISPLAY_SIZE) {
             // prevent showing full-screen keyboard only when the screen is tall enough
             // to show some reasonable amount of the page (see bug 752709)
             outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI
                                    | EditorInfo.IME_FLAG_NO_FULLSCREEN;
         }
@@ -933,17 +938,18 @@ class GeckoInputConnection
                 if (DEBUG) {
                     throw new IllegalArgumentException("Unexpected NOTIFY_IME=" + type);
                 }
                 break;
         }
     }
 
     @Override
-    public void notifyIMEContext(int state, String typeHint, String modeHint, String actionHint) {
+    public void notifyIMEContext(int state, String typeHint, String modeHint, String actionHint,
+                                 boolean inPrivateBrowsing) {
         // For some input type we will use a widget to display the ui, for those we must not
         // display the ime. We can display a widget for date and time types and, if the sdk version
         // is 11 or greater, for datetime/month/week as well.
         if (typeHint != null &&
             (typeHint.equalsIgnoreCase("date") ||
              typeHint.equalsIgnoreCase("time") ||
              typeHint.equalsIgnoreCase("datetime") ||
              typeHint.equalsIgnoreCase("month") ||
@@ -960,16 +966,17 @@ class GeckoInputConnection
         // a notifyIMEContext call. So if we reset mIMEState inside focus, there may not
         // be another notifyIMEContext call to set mIMEState to a proper value (bug 829318)
         /* When IME is 'disabled', IME processing is disabled.
            In addition, the IME UI is hidden */
         mIMEState = state;
         mIMETypeHint = (typeHint == null) ? "" : typeHint;
         mIMEModeHint = (modeHint == null) ? "" : modeHint;
         mIMEActionHint = (actionHint == null) ? "" : actionHint;
+        mInPrivateBrowsing = inPrivateBrowsing;
 
         // These fields are reset here and will be updated when restartInput is called below
         mUpdateRequest = null;
         mCurrentInputMethod = "";
 
         View v = getView();
         if (v == null || !v.hasFocus()) {
             // When using Find In Page, we can still receive notifyIMEContext calls due to the