Bug 844913 - Null-check getEditable() results in GeckoInputConnection; r=cpeterson
authorJim Chen <nchen@mozilla.com>
Tue, 26 Feb 2013 12:48:32 -0500
changeset 123042 c862b0b9a898fca9549bbd778961ea639dd2f13e
parent 123041 6e195e29b4d6b35993e977a37658386b1fc8157d
child 123043 85e419239adb0778263514b2aff5900415a29011
push id24372
push useremorley@mozilla.com
push dateWed, 27 Feb 2013 13:22:59 +0000
treeherdermozilla-central@0a91da5f5eab [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpeterson
bugs844913
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 844913 - Null-check getEditable() results in GeckoInputConnection; r=cpeterson
mobile/android/base/GeckoInputConnection.java
--- a/mobile/android/base/GeckoInputConnection.java
+++ b/mobile/android/base/GeckoInputConnection.java
@@ -246,16 +246,19 @@ class GeckoInputConnection
     @Override
     public Editable getEditable() {
         return mEditableClient.getEditable();
     }
 
     @Override
     public boolean performContextMenuAction(int id) {
         Editable editable = getEditable();
+        if (editable == null) {
+            return false;
+        }
         int selStart = Selection.getSelectionStart(editable);
         int selEnd = Selection.getSelectionEnd(editable);
 
         switch (id) {
             case R.id.selectAll:
                 setSelection(0, editable.length());
                 break;
             case R.id.cut:
@@ -291,16 +294,19 @@ class GeckoInputConnection
     public ExtractedText getExtractedText(ExtractedTextRequest req, int flags) {
         if (req == null)
             return null;
 
         if ((flags & GET_EXTRACTED_TEXT_MONITOR) != 0)
             mUpdateRequest = req;
 
         Editable editable = getEditable();
+        if (editable == null) {
+            return null;
+        }
         int selStart = Selection.getSelectionStart(editable);
         int selEnd = Selection.getSelectionEnd(editable);
 
         ExtractedText extract = new ExtractedText();
         extract.flags = 0;
         extract.partialStartOffset = -1;
         extract.partialEndOffset = -1;
         extract.selectionStart = selStart;
@@ -401,22 +407,21 @@ class GeckoInputConnection
             return;
         }
         notifyTextChange();
     }
 
     private void notifyTextChange() {
 
         final InputMethodManager imm = getInputMethodManager();
-        if (imm == null) {
+        final View v = getView();
+        final Editable editable = getEditable();
+        if (imm == null || v == null || editable == null) {
             return;
         }
-        final View v = getView();
-        final Editable editable = getEditable();
-
         mUpdateExtract.flags = 0;
         // Update the entire Editable range
         mUpdateExtract.partialStartOffset = -1;
         mUpdateExtract.partialEndOffset = -1;
         mUpdateExtract.selectionStart =
                 Selection.getSelectionStart(editable);
         mUpdateExtract.selectionEnd =
                 Selection.getSelectionEnd(editable);
@@ -435,21 +440,21 @@ class GeckoInputConnection
             return;
         }
         notifySelectionChange(start, end);
     }
 
     private void notifySelectionChange(int start, int end) {
 
         final InputMethodManager imm = getInputMethodManager();
-        if (imm == null) {
+        final View v = getView();
+        final Editable editable = getEditable();
+        if (imm == null || v == null || editable == null) {
             return;
         }
-        final View v = getView();
-        final Editable editable = getEditable();
         imm.updateSelection(v, start, end, getComposingSpanStart(editable),
                             getComposingSpanEnd(editable));
     }
 
     private static synchronized Handler getBackgroundHandler() {
         if (sBackgroundHandler != null) {
             return sBackgroundHandler;
         }