Title: [167284] trunk/Source/WebKit2
Revision
167284
Author
[email protected]
Date
2014-04-14 17:41:37 -0700 (Mon, 14 Apr 2014)

Log Message

Sometimes-crash under handleSwipeGesture after closing a window or quitting
https://bugs.webkit.org/show_bug.cgi?id=131648
<rdar://problem/15966106>

Reviewed by Simon Fraser.

* UIProcess/mac/ViewGestureController.h:
* UIProcess/mac/ViewGestureControllerMac.mm:
(WebKit::ViewGestureController::~ViewGestureController):
(WebKit::ViewGestureController::trackSwipeGesture):
Keep a Objective C object with a single boolean property, isCancelled, on
the ViewGestureController, and also retained by the swipe-tracking block.
When the ViewGestureController is destroyed, we set isCancelled to YES,
and the next time the block is invoked, we will cancel the swipe without
touching the destroyed ViewGestureController.

(WebKit::ViewGestureController::handleSwipeGesture):
Don't try to handle a swipe gesture if the drawing area is missing.

(WebKit::ViewGestureController::endSwipeGesture):
Clear the swipe cancellation tracker when the gesture completes.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (167283 => 167284)


--- trunk/Source/WebKit2/ChangeLog	2014-04-15 00:27:13 UTC (rev 167283)
+++ trunk/Source/WebKit2/ChangeLog	2014-04-15 00:41:37 UTC (rev 167284)
@@ -1,3 +1,27 @@
+2014-04-14  Tim Horton  <[email protected]>
+
+        Sometimes-crash under handleSwipeGesture after closing a window or quitting
+        https://bugs.webkit.org/show_bug.cgi?id=131648
+        <rdar://problem/15966106>
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/mac/ViewGestureController.h:
+        * UIProcess/mac/ViewGestureControllerMac.mm:
+        (WebKit::ViewGestureController::~ViewGestureController):
+        (WebKit::ViewGestureController::trackSwipeGesture):
+        Keep a Objective C object with a single boolean property, isCancelled, on
+        the ViewGestureController, and also retained by the swipe-tracking block.
+        When the ViewGestureController is destroyed, we set isCancelled to YES,
+        and the next time the block is invoked, we will cancel the swipe without
+        touching the destroyed ViewGestureController.
+
+        (WebKit::ViewGestureController::handleSwipeGesture):
+        Don't try to handle a swipe gesture if the drawing area is missing.
+
+        (WebKit::ViewGestureController::endSwipeGesture):
+        Clear the swipe cancellation tracker when the gesture completes.
+
 2014-04-14  Enrica Casucci  <[email protected]>
 
         REGRESSION(r166027) Menu is shown and immediately hidden after doubletap gesture.

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h (167283 => 167284)


--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h	2014-04-15 00:27:13 UTC (rev 167283)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h	2014-04-15 00:41:37 UTC (rev 167284)
@@ -41,6 +41,7 @@
 #else
 OBJC_CLASS NSEvent;
 OBJC_CLASS NSView;
+OBJC_CLASS WKSwipeCancellationTracker;
 #endif
 
 namespace WebCore {
@@ -148,6 +149,7 @@
     bool m_visibleContentRectIsValid;
     bool m_frameHandlesMagnificationGesture;
 
+    RetainPtr<WKSwipeCancellationTracker> m_swipeCancellationTracker;
     RetainPtr<CALayer> m_swipeSnapshotLayer;
     Vector<RetainPtr<CALayer>> m_currentSwipeLiveLayers;
 

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm (167283 => 167284)


--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm	2014-04-15 00:27:13 UTC (rev 167283)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm	2014-04-15 00:41:37 UTC (rev 167284)
@@ -79,6 +79,13 @@
 static const float swipeSnapshotRemovalRenderTreeSizeTargetFraction = 0.5;
 static const std::chrono::seconds swipeSnapshotRemovalWatchdogDuration = 3_s;
 
+@interface WKSwipeCancellationTracker : NSObject
+@property (nonatomic) BOOL isCancelled;
+@end
+
+@implementation WKSwipeCancellationTracker
+@end
+
 namespace WebKit {
 
 ViewGestureController::ViewGestureController(WebPageProxy& webPageProxy)
@@ -96,6 +103,9 @@
 
 ViewGestureController::~ViewGestureController()
 {
+    if (m_swipeCancellationTracker)
+        [m_swipeCancellationTracker setIsCancelled:YES];
+
     m_webPageProxy.process().removeMessageReceiver(Messages::ViewGestureController::messageReceiverName(), m_webPageProxy.pageID());
 }
 
@@ -352,7 +362,15 @@
     RefPtr<WebBackForwardListItem> targetItem = (direction == SwipeDirection::Left) ? m_webPageProxy.backForwardList().backItem() : m_webPageProxy.backForwardList().forwardItem();
     __block bool swipeCancelled = false;
 
+    ASSERT(!m_swipeCancellationTracker);
+    RetainPtr<WKSwipeCancellationTracker> swipeCancellationTracker = adoptNS([[WKSwipeCancellationTracker alloc] init]);
+    m_swipeCancellationTracker = swipeCancellationTracker;
+
     [event trackSwipeEventWithOptions:0 dampenAmountThresholdMin:minProgress max:maxProgress usingHandler:^(CGFloat progress, NSEventPhase phase, BOOL isComplete, BOOL *stop) {
+        if ([swipeCancellationTracker isCancelled]) {
+            *stop = YES;
+            return;
+        }
         if (phase == NSEventPhaseBegan)
             this->beginSwipeGesture(targetItem.get(), direction);
         CGFloat clampedProgress = std::min(std::max(progress, minProgress), maxProgress);
@@ -487,6 +505,9 @@
 {
     ASSERT(m_activeGestureType == ViewGestureType::Swipe);
 
+    if (!m_webPageProxy.drawingArea())
+        return;
+
     double width;
     if (!m_customSwipeViews.isEmpty())
         width = m_currentSwipeCustomViewBounds.width();
@@ -514,6 +535,8 @@
 {
     ASSERT(m_activeGestureType == ViewGestureType::Swipe);
 
+    m_swipeCancellationTracker = nullptr;
+
     CALayer *rootLayer = m_webPageProxy.acceleratedCompositingRootLayer();
 
     [rootLayer setShadowOpacity:0];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to