Bug 1499429 - 2. Set default GeckoEditableChild from native code; r=esawin

Set the default GeckoEditableChild from C++, so we can keep the same
GeckoEditableChild instance across session transfers, and only have a
different GeckoEditableParent instance after each transfer.

Differential Revision: https://phabricator.services.mozilla.com/D8995
This commit is contained in:
Jim Chen 2018-11-06 00:12:06 -05:00
Родитель e0b3022b2c
Коммит 2944534e33
7 изменённых файлов: 28 добавлений и 19 удалений

Просмотреть файл

@ -11,6 +11,9 @@ import org.mozilla.gecko.IGeckoEditableChild;
// Interface for GeckoEditable calls from child to parent
interface IGeckoEditableParent {
// Set the default child to forward events to, when there is no focused child.
void setDefaultChild(IGeckoEditableChild child);
// Notify an IME event of a type defined in GeckoEditableListener.
void notifyIME(IGeckoEditableChild child, int type);

Просмотреть файл

@ -72,11 +72,14 @@ public final class GeckoEditableChild extends JNIObject implements IGeckoEditabl
private final IGeckoEditableParent mEditableParent;
private final IGeckoEditableChild mEditableChild;
private final boolean mIsDefault;
private int mCurrentTextLength; // Used by Gecko thread
@WrapForJNI(calledFrom = "gecko")
public GeckoEditableChild(final IGeckoEditableParent editableParent) {
private GeckoEditableChild(final IGeckoEditableParent editableParent,
final boolean isDefault) {
mIsDefault = isDefault;
mEditableParent = editableParent;
final IBinder binder = editableParent.asBinder();
@ -87,6 +90,15 @@ public final class GeckoEditableChild extends JNIObject implements IGeckoEditabl
// IGeckoEditableParent is remote; i.e. we're in a content process.
mEditableChild = new RemoteChild();
}
if (mIsDefault) {
// Tell the parent we're the default child.
try {
editableParent.setDefaultChild(mEditableChild);
} catch (final RemoteException e) {
Log.e(LOGTAG, "Failed to set default child", e);
}
}
}
@WrapForJNI(dispatchTo = "proxy") @Override // IGeckoEditableChild

Просмотреть файл

@ -658,10 +658,10 @@ import android.view.inputmethod.EditorInfo;
mIcRunHandler = mIcPostHandler = ThreadUtils.getUiHandler();
}
public void setDefaultEditableChild(final IGeckoEditableChild child) {
@Override // IGeckoEditableParent
public void setDefaultChild(final IGeckoEditableChild child) {
if (DEBUG) {
// Called by SessionTextInput.
ThreadUtils.assertOnUiThread();
// On Gecko or binder thread.
Log.d(LOGTAG, "setDefaultEditableChild " + child);
}
mDefaultChild = child;

Просмотреть файл

@ -730,8 +730,7 @@ public class GeckoSession extends LayerSession
GeckoBundle initData);
@WrapForJNI(dispatchTo = "proxy")
public native void attachEditable(IGeckoEditableParent parent,
GeckoEditableChild child);
public native void attachEditable(IGeckoEditableParent parent);
@WrapForJNI(dispatchTo = "proxy")
public native void attachAccessibility(SessionAccessibility.NativeProvider sessionAccessibility);

Просмотреть файл

@ -275,7 +275,6 @@ public final class SessionTextInput {
private final GeckoSession mSession;
private final NativeQueue mQueue;
private final GeckoEditable mEditable;
private final GeckoEditableChild mEditableChild;
private InputConnectionClient mInputConnection;
private GeckoSession.TextInputDelegate mDelegate;
// Auto-fill nodes.
@ -289,8 +288,6 @@ public final class SessionTextInput {
mSession = session;
mQueue = queue;
mEditable = new GeckoEditable(session);
mEditableChild = new GeckoEditableChild(mEditable);
mEditable.setDefaultEditableChild(mEditableChild);
session.getEventDispatcher().registerUiThreadListener(
new BundleEventListener() {
@ -314,11 +311,10 @@ public final class SessionTextInput {
/* package */ void onWindowChanged(final GeckoSession.Window window) {
if (mQueue.isReady()) {
window.attachEditable(mEditable, mEditableChild);
window.attachEditable(mEditable);
} else {
mQueue.queueUntilReady(window, "attachEditable",
IGeckoEditableParent.class, mEditable,
GeckoEditableChild.class, mEditableChild);
IGeckoEditableParent.class, mEditable);
}
}

Просмотреть файл

@ -702,7 +702,8 @@ nsAppShell::Observe(nsISupports* aSubject,
contentId, tabId);
NS_ENSURE_TRUE(editableParent, NS_OK);
auto editableChild = java::GeckoEditableChild::New(editableParent);
auto editableChild = java::GeckoEditableChild::New(editableParent,
/* default */ false);
NS_ENSURE_TRUE(editableChild, NS_OK);
RefPtr<widget::GeckoEditableSupport> editableSupport =

Просмотреть файл

@ -361,8 +361,7 @@ public:
jni::Object::Param aInitData);
void AttachEditable(const GeckoSession::Window::LocalRef& inst,
jni::Object::Param aEditableParent,
jni::Object::Param aEditableChild);
jni::Object::Param aEditableParent);
void AttachAccessibility(const GeckoSession::Window::LocalRef& inst,
jni::Object::Param aSessionAccessibility);
@ -1362,11 +1361,10 @@ nsWindow::GeckoViewSupport::Transfer(const GeckoSession::Window::LocalRef& inst,
void
nsWindow::GeckoViewSupport::AttachEditable(const GeckoSession::Window::LocalRef& inst,
jni::Object::Param aEditableParent,
jni::Object::Param aEditableChild)
jni::Object::Param aEditableParent)
{
java::GeckoEditableChild::LocalRef editableChild(inst.Env());
editableChild = java::GeckoEditableChild::Ref::From(aEditableChild);
auto editableChild = java::GeckoEditableChild::New(aEditableParent,
/* default */ true);
if (window.mEditableSupport) {
window.mEditableSupport.Detach(