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 { ...@@ -131,9 +131,6 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
// True if ImeAdapter is connected to render process. // True if ImeAdapter is connected to render process.
private boolean mIsConnected; 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 * {@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. * editable node at the right timing, which is after input method window shows up.
...@@ -181,7 +178,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver { ...@@ -181,7 +178,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
} }
private boolean initialized() { private boolean initialized() {
return mInitialized; return mNativeImeAdapterAndroid != 0;
} }
/** /**
...@@ -244,7 +241,6 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver { ...@@ -244,7 +241,6 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
mCursorAnchorInfoController = null; mCursorAnchorInfoController = null;
} }
mNativeImeAdapterAndroid = nativeInit(mWebContents); mNativeImeAdapterAndroid = nativeInit(mWebContents);
mInitialized = true;
} }
@Override @Override
...@@ -468,6 +464,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver { ...@@ -468,6 +464,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
* Show soft keyboard only if it is the current keyboard configuration. * Show soft keyboard only if it is the current keyboard configuration.
*/ */
private void showSoftKeyboard() { private void showSoftKeyboard() {
if (!isValid()) return;
if (DEBUG_LOGS) Log.i(TAG, "showSoftKeyboard"); if (DEBUG_LOGS) Log.i(TAG, "showSoftKeyboard");
mInputMethodManagerWrapper.showSoftInput(mContainerView, 0, getNewShowKeyboardReceiver()); mInputMethodManagerWrapper.showSoftInput(mContainerView, 0, getNewShowKeyboardReceiver());
if (mContainerView.getResources().getConfiguration().keyboard if (mContainerView.getResources().getConfiguration().keyboard
...@@ -531,6 +528,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver { ...@@ -531,6 +528,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
* Hide soft keyboard. * Hide soft keyboard.
*/ */
private void hideKeyboard() { private void hideKeyboard() {
if (!isValid()) return;
if (DEBUG_LOGS) Log.i(TAG, "hideKeyboard"); if (DEBUG_LOGS) Log.i(TAG, "hideKeyboard");
View view = mContainerView; View view = mContainerView;
if (mInputMethodManagerWrapper.isActive(view)) { if (mInputMethodManagerWrapper.isActive(view)) {
...@@ -553,6 +551,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver { ...@@ -553,6 +551,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
* Call this when keyboard configuration has changed. * Call this when keyboard configuration has changed.
*/ */
public void onKeyboardConfigurationChanged(Configuration newConfig) { public void onKeyboardConfigurationChanged(Configuration newConfig) {
if (!isValid()) return;
// If configuration unchanged, do nothing. // If configuration unchanged, do nothing.
if (mCurrentConfig.keyboard == newConfig.keyboard if (mCurrentConfig.keyboard == newConfig.keyboard
&& mCurrentConfig.keyboardHidden == newConfig.keyboardHidden && mCurrentConfig.keyboardHidden == newConfig.keyboardHidden
...@@ -675,6 +674,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver { ...@@ -675,6 +674,7 @@ public class ImeAdapterImpl implements ImeAdapter, WindowEventObserver {
* Restart input (finish composition and change EditorInfo, such as input type). * Restart input (finish composition and change EditorInfo, such as input type).
*/ */
void restartInput() { void restartInput() {
if (!isValid()) return;
// This will eventually cause input method manager to call View#onCreateInputConnection(). // This will eventually cause input method manager to call View#onCreateInputConnection().
mInputMethodManagerWrapper.restartInput(mContainerView); mInputMethodManagerWrapper.restartInput(mContainerView);
if (mInputConnection != null) mInputConnection.onRestartInputOnUiThread(); 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