Changeset 207397 in webkit


Ignore:
Timestamp:
Oct 16, 2016 6:28:51 PM (8 years ago)
Author:
Chris Dumez
Message:

REGRESSION (r206750): Crash when pressing Caps Lock if “Use the Caps Lock key to switch to and from U.S.” is selected in Input Sources preferences
https://bugs.webkit.org/show_bug.cgi?id=163506
<rdar://problem/28792483>

Reviewed by Darin Adler.

As per the NSEvent documentation [1], calling [NSEvent characters] is only
valid on key up / key down events and will raise an NSInternalInconsistencyException
if accessed on any other kind of event object. The crash happens when keyForKeyEvent()
is called with the third kind of key event (NSFlagsChanged) which is used for
detecting modifier keys. We normally detect the modifier key and return early before
calling [NSEvent characters]. However, in some rare cases, we fail to detect the
modifier key and we fall through.

To address the issue, we now return "Unidentified" for NSFlagsChanged events, if we
fail to detect the modifier key and before calling [NSEvent characters].

[1] https://developer.apple.com/reference/appkit/nsevent/1534183-characters

No new test, not easily testable.

  • platform/mac/PlatformEventFactoryMac.mm:

(WebCore::keyForKeyEvent):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r207396 r207397  
     12016-10-16  Chris Dumez  <cdumez@apple.com>
     2
     3        REGRESSION (r206750): Crash when pressing Caps Lock if “Use the Caps Lock key to switch to and from U.S.” is selected in Input Sources preferences
     4        https://bugs.webkit.org/show_bug.cgi?id=163506
     5        <rdar://problem/28792483>
     6
     7        Reviewed by Darin Adler.
     8
     9        As per the NSEvent documentation [1], calling [NSEvent characters] is only
     10        valid on key up / key down events and will raise an NSInternalInconsistencyException
     11        if accessed on any other kind of event object. The crash happens when keyForKeyEvent()
     12        is called with the third kind of key event (NSFlagsChanged) which is used for
     13        detecting modifier keys. We normally detect the modifier key and return early before
     14        calling [NSEvent characters]. However, in some rare cases, we fail to detect the
     15        modifier key and we fall through.
     16
     17        To address the issue, we now return "Unidentified" for NSFlagsChanged events, if we
     18        fail to detect the modifier key and before calling [NSEvent characters].
     19
     20        [1] https://developer.apple.com/reference/appkit/nsevent/1534183-characters
     21
     22        No new test, not easily testable.
     23
     24        * platform/mac/PlatformEventFactoryMac.mm:
     25        (WebCore::keyForKeyEvent):
     26
    1272016-10-16  Darin Adler  <darin@apple.com>
    228
  • trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm

    r206828 r207397  
    3737#import <mach/mach_time.h>
    3838#import <wtf/ASCIICType.h>
     39#import <wtf/mac/AppKitCompatibilityDeclarations.h>
    3940
    4041namespace WebCore {
     
    222223static inline String textFromEvent(NSEvent* event)
    223224{
    224 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
    225225    if ([event type] == NSEventTypeFlagsChanged)
    226 #else
    227     if ([event type] == NSFlagsChanged)
    228 #endif
    229226        return emptyString();
    230227    return String([event characters]);
     
    233230static inline String unmodifiedTextFromEvent(NSEvent* event)
    234231{
    235 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
    236232    if ([event type] == NSEventTypeFlagsChanged)
    237 #else
    238     if ([event type] == NSFlagsChanged)
    239 #endif
    240233        return emptyString();
    241234    return String([event charactersIgnoringModifiers]);
     
    265258    }
    266259
     260    // If the event is an NSEventTypeFlagsChanged events and we have not returned yet then this means we could not
     261    // identify the modifier key. We return now and report the key as "Unidentified".
     262    // Note that [event characters] below raises an exception if called on an NSEventTypeFlagsChanged event.
     263    if ([event type] == NSEventTypeFlagsChanged)
     264        return ASCIILiteral("Unidentified");
     265
    267266    // If more than one key is being pressed and the key combination includes one or more modifier keys
    268267    // that result in the key no longer producing a printable character (e.g., Control + a), then the
     
    270269    // typed with the default keyboard layout with no modifier keys except for Shift and AltGr applied.
    271270    // https://w3c.github.io/uievents/#keys-guidelines
    272 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
    273271    bool isControlDown = ([event modifierFlags] & NSEventModifierFlagControl);
    274 #else
    275     bool isControlDown = ([event modifierFlags] & NSControlKeyMask);
    276 #endif
    277272    NSString *s = isControlDown ? [event charactersIgnoringModifiers] : [event characters];
    278273    auto length = [s length];
     
    501496String keyIdentifierForKeyEvent(NSEvent* event)
    502497{
    503 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
    504498    if ([event type] == NSEventTypeFlagsChanged) {
    505 #else
    506     if ([event type] == NSFlagsChanged) {
    507 #endif
    508499        switch ([event keyCode]) {
    509500            case 54: // Right Command
     
    693684    OptionSet<PlatformEvent::Modifier> modifiers;
    694685
    695 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
    696686    if (event.modifierFlags & NSEventModifierFlagShift)
    697687        modifiers |= PlatformEvent::Modifier::ShiftKey;
     
    704694    if (event.modifierFlags & NSEventModifierFlagCapsLock)
    705695        modifiers |= PlatformEvent::Modifier::CapsLockKey;
    706 #else
    707     if (event.modifierFlags & NSShiftKeyMask)
    708         modifiers |= PlatformEvent::Modifier::ShiftKey;
    709     if (event.modifierFlags & NSControlKeyMask)
    710         modifiers |= PlatformEvent::Modifier::CtrlKey;
    711     if (event.modifierFlags & NSAlternateKeyMask)
    712         modifiers |= PlatformEvent::Modifier::AltKey;
    713     if (event.modifierFlags & NSCommandKeyMask)
    714         modifiers |= PlatformEvent::Modifier::MetaKey;
    715     if (event.modifierFlags & NSAlphaShiftKeyMask)
    716         modifiers |= PlatformEvent::Modifier::CapsLockKey;
    717 #endif
    718696
    719697    return modifiers;
Note: See TracChangeset for help on using the changeset viewer.