Bug 797705: Check for null pointers and return early from java event handling if Gecko hasn't started to prevent crashes. [r=kats][a=bajaj]
authorScott Johnson <sjohnson@mozilla.com>
Tue, 06 Nov 2012 14:33:24 -0600
changeset 113987 b3a817168571b3d08daf6decd6d9e2be317fba50
parent 113986 2b0ab957d9da557a2828abf81d991373cd601bdd
child 113988 db23dcb2f68d21322372bf8db46a7693bc80d9a7
push id2592
push usersjohnson@mozilla.com
push dateTue, 06 Nov 2012 20:40:50 +0000
treeherdermozilla-aurora@b3a817168571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats, bajaj
bugs797705
milestone18.0a2
Bug 797705: Check for null pointers and return early from java event handling if Gecko hasn't started to prevent crashes. [r=kats][a=bajaj]
mobile/android/base/GeckoEvent.java
mobile/android/base/ui/PanZoomController.java
--- a/mobile/android/base/GeckoEvent.java
+++ b/mobile/android/base/GeckoEvent.java
@@ -268,16 +268,22 @@ public class GeckoEvent {
     public static GeckoEvent createNativeGestureEvent(int action, PointF pt, double size) {
         GeckoEvent event = new GeckoEvent(NATIVE_GESTURE_EVENT);
         event.mAction = action;
         event.mCount = 1;
         event.mPoints = new Point[1];
 
         PointF geckoPoint = new PointF(pt.x, pt.y);
         geckoPoint = GeckoApp.mAppContext.getLayerView().convertViewPointToLayerPoint(geckoPoint);
+
+        if (geckoPoint == null) {
+            // This could happen if Gecko isn't ready yet.
+            return null;
+        }
+
         event.mPoints[0] = new Point(Math.round(geckoPoint.x), Math.round(geckoPoint.y));
 
         event.mX = size;
         event.mTime = System.currentTimeMillis();
         return event;
     }
 
     public static GeckoEvent createMotionEvent(MotionEvent m) {
--- a/mobile/android/base/ui/PanZoomController.java
+++ b/mobile/android/base/ui/PanZoomController.java
@@ -954,16 +954,21 @@ public class PanZoomController
         // switch back to the touching state
         startTouch(detector.getFocusX(), detector.getFocusY(), detector.getEventTime());
 
         // Force a viewport synchronisation
         mTarget.setForceRedraw();
 
         PointF point = new PointF(detector.getFocusX(), detector.getFocusY());
         GeckoEvent event = GeckoEvent.createNativeGestureEvent(GeckoEvent.ACTION_MAGNIFY_END, point, getMetrics().zoomFactor);
+
+        if (event == null) {
+            return;
+        }
+
         GeckoAppShell.sendEventToGecko(event);
     }
 
     /**
      * Scales the viewport, keeping the given focus point in the same place before and after the
      * scale operation. You must hold the monitor while calling this.
      */
     private void scaleWithFocus(float zoomFactor, PointF focus) {