REGRESSION (r103859): WKViews leak
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / mac / WKView.mm
index 0bb1743372c795a0798661d6976638e4a368ab17..1e2509ba697e5da91badb59cc54042e7ec873355 100644 (file)
@@ -225,7 +225,6 @@ struct WKViewInterpretKeyEventsParameters {
 - (void)dealloc
 {
     _data->_page->close();
-    [NSEvent removeMonitor:_data->_flagsChangedEventMonitor];
 
     ASSERT(!_data->_inSecureInputState);
 
@@ -1823,12 +1822,20 @@ static NSString * const backingPropertyOldScaleFactorKey = @"NSBackingPropertyOl
         _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible | WebPageProxy::ViewIsInWindow);
         [self _updateWindowVisibility];
         [self _updateWindowAndViewFrames];
-        
-        [self _accessibilityRegisterUIProcessTokens];            
+
+        _data->_flagsChangedEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSFlagsChangedMask handler:^(NSEvent *flagsChangedEvent) {
+            [self _postFakeMouseMovedEventForFlagsChangedEvent:flagsChangedEvent];
+            return flagsChangedEvent;
+        }];
+
+        [self _accessibilityRegisterUIProcessTokens];
     } else {
         _data->_page->viewStateDidChange(WebPageProxy::ViewIsVisible);
         _data->_page->viewStateDidChange(WebPageProxy::ViewWindowIsActive | WebPageProxy::ViewIsInWindow);
 
+        [NSEvent removeMonitor:_data->_flagsChangedEventMonitor];
+        _data->_flagsChangedEventMonitor = nil;
+
 #if ENABLE(GESTURE_EVENTS)
         if (_data->_endGestureMonitor) {
             [NSEvent removeMonitor:_data->_endGestureMonitor];
@@ -2703,10 +2710,6 @@ static void drawPageBackground(CGContextRef context, WebPageProxy* page, const I
 #endif
     _data->_mouseDownEvent = nil;
     _data->_ignoringMouseDraggedEvents = NO;
-    _data->_flagsChangedEventMonitor = [NSEvent addLocalMonitorForEventsMatchingMask:NSFlagsChangedMask handler:^(NSEvent *flagsChangedEvent) {
-        [self _postFakeMouseMovedEventForFlagsChangedEvent:flagsChangedEvent];
-        return flagsChangedEvent;
-    }];
 
     [self _registerDraggedTypes];