Changeset 200278 in webkit


Ignore:
Timestamp:
Apr 29, 2016 7:37:01 PM (8 years ago)
Author:
BJ Burg
Message:

Web Automation: use a magic eventNumber as a fallback for detecting NSEvents synthesized for automation
https://bugs.webkit.org/show_bug.cgi?id=157222

Reviewed by Timothy Hatcher.

Sometimes events are copied and redelivered in a way that can't be reliably intercepted,
so use eventNumber as an alternate means of detecting synthesized mouse NSEvents.

  • UIProcess/Cocoa/WebAutomationSessionCocoa.mm:

(WebKit::WebAutomationSession::wasEventSynthesizedForAutomation):
If it's a mouse-related event, check the eventNumber if the associated object was missing.

(WebKit::WebAutomationSession::platformSimulateMouseInteraction):
Most real events from input devices fill in eventNumber with a non-zero value.
In my testing, using zero did not seem to adversely affect event delivery.

Location:
trunk/Source/WebKit2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r200276 r200278  
     12016-04-29  Brian Burg  <bburg@apple.com>
     2
     3        Web Automation: use a magic eventNumber as a fallback for detecting NSEvents synthesized for automation
     4        https://bugs.webkit.org/show_bug.cgi?id=157222
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        Sometimes events are copied and redelivered in a way that can't be reliably intercepted,
     9        so use eventNumber as an alternate means of detecting synthesized mouse NSEvents.
     10
     11        * UIProcess/Cocoa/WebAutomationSessionCocoa.mm:
     12        (WebKit::WebAutomationSession::wasEventSynthesizedForAutomation):
     13        If it's a mouse-related event, check the eventNumber if the associated object was missing.
     14
     15        (WebKit::WebAutomationSession::platformSimulateMouseInteraction):
     16        Most real events from input devices fill in eventNumber with a non-zero value.
     17        In my testing, using zero did not seem to adversely affect event delivery.
     18
    1192016-04-29  Joseph Pecoraro  <pecoraro@apple.com>
    220
  • trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm

    r198907 r200278  
    4444#if USE(APPKIT)
    4545
     46static const NSInteger synthesizedMouseEventMagicEventNumber = 0;
    4647static const void *synthesizedAutomationEventAssociatedObjectKey = &synthesizedAutomationEventAssociatedObjectKey;
    4748
     
    5960{
    6061    NSString *senderSessionIdentifier = objc_getAssociatedObject(event, &synthesizedAutomationEventAssociatedObjectKey);
    61     return [senderSessionIdentifier isEqualToString:m_sessionIdentifier];
     62    if ([senderSessionIdentifier isEqualToString:m_sessionIdentifier])
     63        return true;
     64
     65    switch (event.type) {
     66    case NSEventTypeLeftMouseDown:
     67    case NSEventTypeLeftMouseDragged:
     68    case NSEventTypeLeftMouseUp:
     69    case NSEventTypeMouseMoved:
     70    case NSEventTypeOtherMouseDown:
     71    case NSEventTypeOtherMouseDragged:
     72    case NSEventTypeOtherMouseUp:
     73    case NSEventTypeRightMouseDown:
     74    case NSEventTypeRightMouseDragged:
     75    case NSEventTypeRightMouseUp:
     76        // Use this as a backup for checking mouse events, which are frequently copied
     77        // and/or faked by AppKit, causing them to lose their associated object tag.
     78        return event.eventNumber == synthesizedMouseEventMagicEventNumber;
     79    default:
     80        break;
     81    }
     82
     83    return false;
    6284}
    6385
     
    107129    auto eventsToBeSent = adoptNS([[NSMutableArray alloc] init]);
    108130
     131    NSInteger eventNumber = synthesizedMouseEventMagicEventNumber;
     132
    109133    switch (interaction) {
    110134    case Inspector::Protocol::Automation::MouseInteraction::Move:
    111         [eventsToBeSent addObject:[NSEvent mouseEventWithType:dragEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:0 pressure:0.0f]];
     135        [eventsToBeSent addObject:[NSEvent mouseEventWithType:dragEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:0 pressure:0.0f]];
    112136        break;
    113137    case Inspector::Protocol::Automation::MouseInteraction::Down:
    114138        // Hard-code the click count to one, since clients don't expect successive simulated
    115139        // down/up events to be potentially counted as a double click event.
    116         [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:WebCore::ForceAtClick]];
     140        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:WebCore::ForceAtClick]];
    117141        break;
    118142    case Inspector::Protocol::Automation::MouseInteraction::Up:
    119143        // Hard-code the click count to one, since clients don't expect successive simulated
    120144        // down/up events to be potentially counted as a double click event.
    121         [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:0.0f]];
     145        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:0.0f]];
    122146        break;
    123147    case Inspector::Protocol::Automation::MouseInteraction::SingleClick:
    124148        // Send separate down and up events. WebCore will see this as a single-click event.
    125         [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:WebCore::ForceAtClick]];
    126         [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:0.0f]];
     149        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:WebCore::ForceAtClick]];
     150        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:0.0f]];
    127151        break;
    128152    case Inspector::Protocol::Automation::MouseInteraction::DoubleClick:
    129153        // Send multiple down and up events with proper click count.
    130154        // WebCore will see this as a single-click event then double-click event.
    131         [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:WebCore::ForceAtClick]];
    132         [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:0.0f]];
    133         [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:2 pressure:WebCore::ForceAtClick]];
    134         [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:2 pressure:0.0f]];
     155        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:WebCore::ForceAtClick]];
     156        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:0.0f]];
     157        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:2 pressure:WebCore::ForceAtClick]];
     158        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:2 pressure:0.0f]];
    135159    }
    136160
Note: See TracChangeset for help on using the changeset viewer.