From bfdb4ce5accbfa52cb402f59a4634510f6854931 Mon Sep 17 00:00:00 2001 From: Kartikaya Gupta Date: Fri, 25 Jan 2013 13:51:41 -0500 Subject: [PATCH] Bug 834414 - Remove a dangling reference to the LayerView in the IME code when the activity is destroyed. r=jchen --- mobile/android/base/GeckoApp.java | 2 ++ mobile/android/base/GeckoEditable.java | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index ae99d73e750..965a1cfe06f 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -1569,6 +1569,8 @@ abstract public class GeckoApp LayerView layerView = (LayerView) findViewById(R.id.layer_view); layerView.initializeView(GeckoAppShell.getEventDispatcher()); mLayerView = layerView; + // bind the GeckoEditable instance to the new LayerView + GeckoAppShell.notifyIMEEnabled(GeckoEditableListener.IME_STATE_DISABLED, "", "", "", false); } } diff --git a/mobile/android/base/GeckoEditable.java b/mobile/android/base/GeckoEditable.java index b86ecfd2ea4..2628f9be9e9 100644 --- a/mobile/android/base/GeckoEditable.java +++ b/mobile/android/base/GeckoEditable.java @@ -20,6 +20,7 @@ import android.text.TextPaint; import android.text.TextUtils; import android.text.style.CharacterStyle; import android.util.Log; +import android.view.View; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; @@ -77,9 +78,10 @@ final class GeckoEditable private final SpannableStringBuilder mText; private final SpannableStringBuilder mChangedText; private final Editable mProxy; - private final GeckoEditableListener mListener; private final ActionQueue mActionQueue; + private View mCurrentView; + private GeckoEditableListener mListener; private int mSavedSelectionStart; private volatile int mGeckoUpdateSeqno; private int mUIUpdateSeqno; @@ -256,8 +258,8 @@ final class GeckoEditable Editable.class.getClassLoader(), PROXY_INTERFACES, this); - LayerView v = GeckoApp.mAppContext.getLayerView(); - mListener = GeckoInputConnection.create(v, this); + mCurrentView = GeckoApp.mAppContext.getLayerView(); + mListener = GeckoInputConnection.create(mCurrentView, this); } private static void geckoPostToUI(Runnable runnable) { @@ -545,10 +547,8 @@ final class GeckoEditable @Override public void notifyIMEEnabled(final int state, final String typeHint, final String modeHint, final String actionHint) { - if (DEBUG) { - // GeckoEditableListener methods should all be called from the Gecko thread - GeckoApp.assertOnGeckoThread(); - } + // Because we want to be able to bind GeckoEditable to the newest LayerView instance, + // this can be called from the Java UI thread in addition to the Gecko thread. geckoPostToUI(new Runnable() { public void run() { // Make sure there are no other things going on @@ -558,10 +558,13 @@ final class GeckoEditable // InputConnectionHandler.onCreateInputConnection LayerView v = GeckoApp.mAppContext.getLayerView(); if (v != null) { - v.setInputConnectionHandler((InputConnectionHandler)mListener); + if (v != mCurrentView) { + mCurrentView = v; + mListener = GeckoInputConnection.create(v, GeckoEditable.this); + v.setInputConnectionHandler((InputConnectionHandler)mListener); + } + mListener.notifyIMEEnabled(state, typeHint, modeHint, actionHint); } - mListener.notifyIMEEnabled(state, typeHint, - modeHint, actionHint); } }); }