Commit 926d2014 authored by Changwan Ryu's avatar Changwan Ryu Committed by Commit Bot

Avoid NPE in ImeAdapterImpl

Adding missing isValid() checks from
https://codereview.chromium.org/2752113005/

Also removing mInitialized which can be misleading.

BUG=806724

Change-Id: I872b3ce27d6efb57dda65b6ae7b84abdf26c250c
Reviewed-on: https://chromium-review.googlesource.com/892106Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Changwan Ryu <changwan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532885}
parent d4ce5f78
......@@ -131,9 +131,6 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
// True if ImeAdapter is connected to render process.
private boolean mIsConnected;
// True if the instance is properly initialized with |init|.
private boolean mInitialized;
/**
* {@ResultReceiver} passed in InputMethodManager#showSoftInput}. We need this to scroll to the
* editable node at the right timing, which is after input method window shows up.
......@@ -181,7 +178,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
}
private boolean initialized() {
return mInitialized;
return mNativeImeAdapterAndroid != 0;
}
/**
......@@ -244,7 +241,6 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
mCursorAnchorInfoController = null;
}
mNativeImeAdapterAndroid = nativeInit(mWebContents);
mInitialized = true;
}
@Override
......@@ -468,6 +464,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
* Show soft keyboard only if it is the current keyboard configuration.
*/
private void showSoftKeyboard() {
if (!isValid()) return;
if (DEBUG_LOGS) Log.i(TAG, "showSoftKeyboard");
mInputMethodManagerWrapper.showSoftInput(mContainerView, 0, getNewShowKeyboardReceiver());
if (mContainerView.getResources().getConfiguration().keyboard
......@@ -531,6 +528,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
* Hide soft keyboard.
*/
private void hideKeyboard() {
if (!isValid()) return;
if (DEBUG_LOGS) Log.i(TAG, "hideKeyboard");
View view = mContainerView;
if (mInputMethodManagerWrapper.isActive(view)) {
......@@ -553,6 +551,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
* Call this when keyboard configuration has changed.
*/
public void onKeyboardConfigurationChanged(Configuration newConfig) {
if (!isValid()) return;
// If configuration unchanged, do nothing.
if (mCurrentConfig.keyboard == newConfig.keyboard
&& mCurrentConfig.keyboardHidden == newConfig.keyboardHidden
......@@ -675,6 +674,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
* Restart input (finish composition and change EditorInfo, such as input type).
*/
void restartInput() {
if (!isValid()) return;
// This will eventually cause input method manager to call View#onCreateInputConnection().
mInputMethodManagerWrapper.restartInput(mContainerView);
if (mInputConnection != null) mInputConnection.onRestartInputOnUiThread();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment