Bug 1278480 - prevent null pointer dereference. r?kats draft
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Wed, 08 Jun 2016 16:12:37 +0300
changeset 376691 e63731f7e1f0e1395f132cc78ee38c03033257c5
parent 375369 3e8ee3599a67edd971770af4982ad4b0fe77f073
child 523210 8ca1472622efbd1f7dc6e1ef22861b90b783879a
push id20642
push userbpostelnicu@mozilla.com
push dateWed, 08 Jun 2016 13:13:02 +0000
reviewerskats
bugs1278480
milestone49.0a1
Bug 1278480 - prevent null pointer dereference. r?kats MozReview-Commit-ID: LhntDa5Fqqi
gfx/layers/apz/util/TouchActionHelper.cpp
--- a/gfx/layers/apz/util/TouchActionHelper.cpp
+++ b/gfx/layers/apz/util/TouchActionHelper.cpp
@@ -42,16 +42,23 @@ TouchActionHelper::UpdateAllowedBehavior
     }
   }
 }
 
 mozilla::layers::TouchBehaviorFlags
 TouchActionHelper::GetAllowedTouchBehavior(nsIWidget* aWidget, const LayoutDeviceIntPoint& aPoint)
 {
   nsView *view = nsView::GetViewFor(aWidget);
+  TouchBehaviorFlags behavior = AllowedTouchBehavior::VERTICAL_PAN | AllowedTouchBehavior::HORIZONTAL_PAN |
+                                AllowedTouchBehavior::PINCH_ZOOM | AllowedTouchBehavior::DOUBLE_TAP_ZOOM;
+
+  if (!view) {
+    return behavior;
+  }
+
   nsIFrame *viewFrame = view->GetFrame();
 
   nsPoint relativePoint =
     nsLayoutUtils::GetEventCoordinatesRelativeTo(aWidget, aPoint, viewFrame);
 
   nsIFrame *target = nsLayoutUtils::GetFrameForPoint(viewFrame, relativePoint, nsLayoutUtils::IGNORE_ROOT_SCROLL_FRAME);
   nsIScrollableFrame *nearestScrollableParent = nsLayoutUtils::GetNearestScrollableFrame(target, 0);
   nsIFrame* nearestScrollableFrame = do_QueryFrame(nearestScrollableParent);
@@ -68,18 +75,16 @@ TouchActionHelper::GetAllowedTouchBehavi
 
   // Currently we support only two touch behaviors: panning and zooming.
   // For panning we walk up until we meet the first scrollable element (the element that supports panning)
   // or root element.
   // For zooming we walk up until the root element since Firefox currently supports only zooming of the
   // root frame but not the subframes.
 
   bool considerPanning = true;
-  TouchBehaviorFlags behavior = AllowedTouchBehavior::VERTICAL_PAN | AllowedTouchBehavior::HORIZONTAL_PAN |
-                                AllowedTouchBehavior::PINCH_ZOOM | AllowedTouchBehavior::DOUBLE_TAP_ZOOM;
 
   for (nsIFrame *frame = target; frame && frame->GetContent() && behavior; frame = frame->GetParent()) {
     UpdateAllowedBehavior(nsLayoutUtils::GetTouchActionFromFrame(frame), considerPanning, behavior);
 
     if (frame == nearestScrollableFrame) {
       // We met the scrollable element, after it we shouldn't consider touch-action
       // values for the purpose of panning but only for zooming.
       considerPanning = false;