Changeset 253282 in webkit


Ignore:
Timestamp:
Dec 8, 2019 11:25:00 PM (4 years ago)
Author:
timothy_horton@apple.com
Message:

REGRESSION: Crash under UIScriptControllerIOS::simulateAccessibilitySettingsChangeNotification
https://bugs.webkit.org/show_bug.cgi?id=205002

Reviewed by Wenson Hsieh.

Keep a strong reference to the UIScriptController while running async tasks.
UIScriptContext will be nulled out if the view was torn down, but this way
we keep the UIScriptController itself and can find the null UIScriptContext
reliably.

  • DumpRenderTree/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptControllerIOS::doAsyncTask):
(WTR::UIScriptControllerIOS::zoomToScale):

  • DumpRenderTree/mac/UIScriptControllerMac.mm:

(WTR::UIScriptControllerMac::doAsyncTask):
(WTR::UIScriptControllerMac::activateDataListSuggestion):
(WTR::UIScriptControllerMac::removeViewFromWindow):
(WTR::UIScriptControllerMac::addViewToWindow):

  • WebKitTestRunner/ios/UIScriptControllerIOS.mm:

(WTR::UIScriptControllerIOS::doAfterPresentationUpdate):
(WTR::UIScriptControllerIOS::doAfterNextStablePresentationUpdate):
(WTR::UIScriptControllerIOS::ensurePositionInformationIsUpToDateAt):
(WTR::UIScriptControllerIOS::doAfterVisibleContentRectUpdate):
(WTR::UIScriptControllerIOS::zoomToScale):
(WTR::UIScriptControllerIOS::retrieveSpeakSelectionContent):
(WTR::UIScriptControllerIOS::simulateAccessibilitySettingsChangeNotification):
(WTR::UIScriptControllerIOS::touchDownAtPoint):
(WTR::UIScriptControllerIOS::liftUpAtPoint):
(WTR::UIScriptControllerIOS::twoFingerSingleTapAtPoint):
(WTR::UIScriptControllerIOS::doubleTapAtPoint):
(WTR::UIScriptControllerIOS::stylusDownAtPoint):
(WTR::UIScriptControllerIOS::stylusMoveToPoint):
(WTR::UIScriptControllerIOS::stylusUpAtPoint):
(WTR::UIScriptControllerIOS::stylusTapAtPointWithModifiers):
(WTR::UIScriptControllerIOS::dragFromPointToPoint):
(WTR::UIScriptControllerIOS::longPressAtPoint):
(WTR::UIScriptControllerIOS::typeCharacterUsingHardwareKeyboard):
(WTR::UIScriptControllerIOS::dismissFilePicker):
(WTR::UIScriptControllerIOS::applyAutocorrection):
(WTR::UIScriptControllerIOS::simulateRotation):
(WTR::UIScriptControllerIOS::simulateRotationLikeSafari):
(WTR::UIScriptControllerIOS::setDidStartFormControlInteractionCallback):
(WTR::UIScriptControllerIOS::setDidEndFormControlInteractionCallback):
(WTR::UIScriptControllerIOS::setDidShowContextMenuCallback):
(WTR::UIScriptControllerIOS::setDidDismissContextMenuCallback):
(WTR::UIScriptControllerIOS::setWillBeginZoomingCallback):
(WTR::UIScriptControllerIOS::setDidEndZoomingCallback):
(WTR::UIScriptControllerIOS::setDidShowKeyboardCallback):
(WTR::UIScriptControllerIOS::setDidHideKeyboardCallback):
(WTR::UIScriptControllerIOS::setWillPresentPopoverCallback):
(WTR::UIScriptControllerIOS::setDidDismissPopoverCallback):
(WTR::UIScriptControllerIOS::setDidEndScrollingCallback):
(WTR::UIScriptControllerIOS::activateDataListSuggestion):
(WTR::UIScriptControllerIOS::doAfterDoubleTapDelay):

  • WebKitTestRunner/mac/UIScriptControllerMac.mm:

(WTR::UIScriptControllerMac::zoomToScale):
(WTR::UIScriptControllerMac::simulateAccessibilitySettingsChangeNotification):
(WTR::UIScriptControllerMac::chooseMenuAction):
(WTR::UIScriptControllerMac::activateAtPoint):

Location:
trunk/Tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r253268 r253282  
     12019-12-08  Tim Horton  <timothy_horton@apple.com>
     2
     3        REGRESSION: Crash under UIScriptControllerIOS::simulateAccessibilitySettingsChangeNotification
     4        https://bugs.webkit.org/show_bug.cgi?id=205002
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        Keep a strong reference to the UIScriptController while running async tasks.
     9        UIScriptContext will be nulled out if the view was torn down, but this way
     10        we keep the UIScriptController itself and can find the null UIScriptContext
     11        reliably.
     12
     13        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
     14        (WTR::UIScriptControllerIOS::doAsyncTask):
     15        (WTR::UIScriptControllerIOS::zoomToScale):
     16        * DumpRenderTree/mac/UIScriptControllerMac.mm:
     17        (WTR::UIScriptControllerMac::doAsyncTask):
     18        (WTR::UIScriptControllerMac::activateDataListSuggestion):
     19        (WTR::UIScriptControllerMac::removeViewFromWindow):
     20        (WTR::UIScriptControllerMac::addViewToWindow):
     21        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
     22        (WTR::UIScriptControllerIOS::doAfterPresentationUpdate):
     23        (WTR::UIScriptControllerIOS::doAfterNextStablePresentationUpdate):
     24        (WTR::UIScriptControllerIOS::ensurePositionInformationIsUpToDateAt):
     25        (WTR::UIScriptControllerIOS::doAfterVisibleContentRectUpdate):
     26        (WTR::UIScriptControllerIOS::zoomToScale):
     27        (WTR::UIScriptControllerIOS::retrieveSpeakSelectionContent):
     28        (WTR::UIScriptControllerIOS::simulateAccessibilitySettingsChangeNotification):
     29        (WTR::UIScriptControllerIOS::touchDownAtPoint):
     30        (WTR::UIScriptControllerIOS::liftUpAtPoint):
     31        (WTR::UIScriptControllerIOS::twoFingerSingleTapAtPoint):
     32        (WTR::UIScriptControllerIOS::doubleTapAtPoint):
     33        (WTR::UIScriptControllerIOS::stylusDownAtPoint):
     34        (WTR::UIScriptControllerIOS::stylusMoveToPoint):
     35        (WTR::UIScriptControllerIOS::stylusUpAtPoint):
     36        (WTR::UIScriptControllerIOS::stylusTapAtPointWithModifiers):
     37        (WTR::UIScriptControllerIOS::dragFromPointToPoint):
     38        (WTR::UIScriptControllerIOS::longPressAtPoint):
     39        (WTR::UIScriptControllerIOS::typeCharacterUsingHardwareKeyboard):
     40        (WTR::UIScriptControllerIOS::dismissFilePicker):
     41        (WTR::UIScriptControllerIOS::applyAutocorrection):
     42        (WTR::UIScriptControllerIOS::simulateRotation):
     43        (WTR::UIScriptControllerIOS::simulateRotationLikeSafari):
     44        (WTR::UIScriptControllerIOS::setDidStartFormControlInteractionCallback):
     45        (WTR::UIScriptControllerIOS::setDidEndFormControlInteractionCallback):
     46        (WTR::UIScriptControllerIOS::setDidShowContextMenuCallback):
     47        (WTR::UIScriptControllerIOS::setDidDismissContextMenuCallback):
     48        (WTR::UIScriptControllerIOS::setWillBeginZoomingCallback):
     49        (WTR::UIScriptControllerIOS::setDidEndZoomingCallback):
     50        (WTR::UIScriptControllerIOS::setDidShowKeyboardCallback):
     51        (WTR::UIScriptControllerIOS::setDidHideKeyboardCallback):
     52        (WTR::UIScriptControllerIOS::setWillPresentPopoverCallback):
     53        (WTR::UIScriptControllerIOS::setDidDismissPopoverCallback):
     54        (WTR::UIScriptControllerIOS::setDidEndScrollingCallback):
     55        (WTR::UIScriptControllerIOS::activateDataListSuggestion):
     56        (WTR::UIScriptControllerIOS::doAfterDoubleTapDelay):
     57        * WebKitTestRunner/mac/UIScriptControllerMac.mm:
     58        (WTR::UIScriptControllerMac::zoomToScale):
     59        (WTR::UIScriptControllerMac::simulateAccessibilitySettingsChangeNotification):
     60        (WTR::UIScriptControllerMac::chooseMenuAction):
     61        (WTR::UIScriptControllerMac::activateAtPoint):
     62
    1632019-12-07  Said Abou-Hallawa  <sabouhallawa@apple.com>
    264
  • trunk/Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm

    r251377 r253282  
    3333#import <JavaScriptCore/OpaqueJSString.h>
    3434#import <WebCore/FloatRect.h>
     35#import <wtf/BlockPtr.h>
    3536#import <wtf/MainThread.h>
    3637
     
    4950    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    5051
    51     dispatch_async(dispatch_get_main_queue(), ^{
     52    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
    5253        if (!m_context)
    5354            return;
    5455        m_context->asyncTaskComplete(callbackID);
    55     });
     56    }).get());
    5657}
    5758
     
    6263    RefPtr<UIScriptController> protectedThis(this);
    6364    dispatch_async(dispatch_get_main_queue(), ^{
    64         [gWebScrollView zoomToScale:scale animated:YES completionHandler:^{
     65        [gWebScrollView zoomToScale:scale animated:YES completionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
    6566            if (!m_context)
    6667                return;
    6768            m_context->asyncTaskComplete(callbackID);
    68         }];
     69        }).get()];
    6970    });
    7071}
  • trunk/Tools/DumpRenderTree/mac/UIScriptControllerMac.mm

    r252719 r253282  
    3535#import <WebKit/WebKit.h>
    3636#import <WebKit/WebViewPrivate.h>
     37#import <wtf/BlockPtr.h>
    3738
    3839#if PLATFORM(MAC)
     
    5152    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    5253
    53     dispatch_async(dispatch_get_main_queue(), ^{
     54    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
    5455        if (!m_context)
    5556            return;
    5657        m_context->asyncTaskComplete(callbackID);
    57     });
     58    }).get());
    5859}
    5960
     
    107108
    108109    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    109     dispatch_async(dispatch_get_main_queue(), ^{
     110    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
    110111        if (!m_context)
    111112            return;
    112113        m_context->asyncTaskComplete(callbackID);
    113     });
     114    }).get());
    114115}
    115116
     
    130131    [webView removeFromSuperview];
    131132
    132     dispatch_async(dispatch_get_main_queue(), ^{
     133    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
    133134        if (!m_context)
    134135            return;
    135136        m_context->asyncTaskComplete(callbackID);
    136     });
     137    }).get());
    137138}
    138139
     
    144145    [[mainWindow contentView] addSubview:webView];
    145146
    146     dispatch_async(dispatch_get_main_queue(), ^{
     147    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
    147148        if (!m_context)
    148149            return;
    149150        m_context->asyncTaskComplete(callbackID);
    150     });
     151    }).get());
    151152}
    152153
  • trunk/Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

    r252719 r253282  
    121121{
    122122    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    123     [webView() _doAfterNextPresentationUpdate:^{
    124         if (!m_context)
    125             return;
    126         m_context->asyncTaskComplete(callbackID);
    127     }];
     123    [webView() _doAfterNextPresentationUpdate:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     124        if (!m_context)
     125            return;
     126        m_context->asyncTaskComplete(callbackID);
     127    }).get()];
    128128}
    129129
     
    131131{
    132132    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    133     [webView() _doAfterNextStablePresentationUpdate:^() {
    134         if (m_context)
    135             m_context->asyncTaskComplete(callbackID);
    136     }];
     133    [webView() _doAfterNextStablePresentationUpdate:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     134        if (!m_context)
     135            return;
     136        m_context->asyncTaskComplete(callbackID);
     137    }).get()];
    137138}
    138139
     
    140141{
    141142    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    142     [webView() _requestActivatedElementAtPosition:CGPointMake(x, y) completionBlock:^(_WKActivatedElementInfo *) {
    143         if (!m_context)
    144             return;
    145         m_context->asyncTaskComplete(callbackID);
    146     }];
     143    [webView() _requestActivatedElementAtPosition:CGPointMake(x, y) completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] (_WKActivatedElementInfo *) {
     144        if (!m_context)
     145            return;
     146        m_context->asyncTaskComplete(callbackID);
     147    }).get()];
    147148}
    148149
     
    150151{
    151152    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    152     [webView() _doAfterNextVisibleContentRectUpdate:^ {
    153         if (!m_context)
    154             return;
    155         m_context->asyncTaskComplete(callbackID);
    156     }];
     153    [webView() _doAfterNextVisibleContentRectUpdate:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     154        if (!m_context)
     155            return;
     156        m_context->asyncTaskComplete(callbackID);
     157    }).get()];
    157158}
    158159
     
    161162    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    162163
    163     [webView() zoomToScale:scale animated:YES completionHandler:^{
    164         if (!m_context)
    165             return;
    166         m_context->asyncTaskComplete(callbackID);
    167     }];
     164    [webView() zoomToScale:scale animated:YES completionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     165        if (!m_context)
     166            return;
     167        m_context->asyncTaskComplete(callbackID);
     168    }).get()];
    168169}
    169170
     
    172173    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    173174   
    174     [webView() accessibilityRetrieveSpeakSelectionContentWithCompletionHandler:^() {
    175         if (!m_context)
    176             return;
    177         m_context->asyncTaskComplete(callbackID);
    178     }];
     175    [webView() accessibilityRetrieveSpeakSelectionContentWithCompletionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     176        if (!m_context)
     177            return;
     178        m_context->asyncTaskComplete(callbackID);
     179    }).get()];
    179180}
    180181
     
    192193    [center postNotificationName:UIAccessibilityInvertColorsStatusDidChangeNotification object:webView];
    193194
    194     [webView _doAfterNextPresentationUpdate: ^{
    195         if (!m_context)
    196             return;
    197         m_context->asyncTaskComplete(callbackID);
    198     }];
     195    [webView _doAfterNextPresentationUpdate:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     196        if (!m_context)
     197            return;
     198        m_context->asyncTaskComplete(callbackID);
     199    }).get()];
    199200}
    200201
     
    218219
    219220    auto location = globalToContentCoordinates(webView(), x, y);
    220     [[HIDEventGenerator sharedHIDEventGenerator] touchDown:location touchCount:touchCount completionBlock:^{
    221         if (!m_context)
    222             return;
    223         m_context->asyncTaskComplete(callbackID);
    224     }];
     221    [[HIDEventGenerator sharedHIDEventGenerator] touchDown:location touchCount:touchCount completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     222        if (!m_context)
     223            return;
     224        m_context->asyncTaskComplete(callbackID);
     225    }).get()];
    225226}
    226227
     
    230231   
    231232    auto location = globalToContentCoordinates(webView(), x, y);
    232     [[HIDEventGenerator sharedHIDEventGenerator] liftUp:location touchCount:touchCount completionBlock:^{
    233         if (!m_context)
    234             return;
    235         m_context->asyncTaskComplete(callbackID);
    236     }];
     233    [[HIDEventGenerator sharedHIDEventGenerator] liftUp:location touchCount:touchCount completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     234        if (!m_context)
     235            return;
     236        m_context->asyncTaskComplete(callbackID);
     237    }).get()];
    237238}
    238239
     
    261262
    262263    auto location = globalToContentCoordinates(webView(), x, y);
    263     [[HIDEventGenerator sharedHIDEventGenerator] twoFingerTap:location completionBlock:^{
    264         if (!m_context)
    265             return;
    266         m_context->asyncTaskComplete(callbackID);
    267     }];
     264    [[HIDEventGenerator sharedHIDEventGenerator] twoFingerTap:location completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     265        if (!m_context)
     266            return;
     267        m_context->asyncTaskComplete(callbackID);
     268    }).get()];
    268269}
    269270
     
    300301    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    301302
    302     [[HIDEventGenerator sharedHIDEventGenerator] doubleTap:globalToContentCoordinates(webView(), x, y) delay:delay completionBlock:^{
    303         if (!m_context)
    304             return;
    305         m_context->asyncTaskComplete(callbackID);
    306     }];
     303    [[HIDEventGenerator sharedHIDEventGenerator] doubleTap:globalToContentCoordinates(webView(), x, y) delay:delay completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     304        if (!m_context)
     305            return;
     306        m_context->asyncTaskComplete(callbackID);
     307    }).get()];
    307308}
    308309
     
    312313
    313314    auto location = globalToContentCoordinates(webView(), x, y);
    314     [[HIDEventGenerator sharedHIDEventGenerator] stylusDownAtPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure completionBlock:^{
    315         if (!m_context)
    316             return;
    317         m_context->asyncTaskComplete(callbackID);
    318     }];
     315    [[HIDEventGenerator sharedHIDEventGenerator] stylusDownAtPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     316        if (!m_context)
     317            return;
     318        m_context->asyncTaskComplete(callbackID);
     319    }).get()];
    319320}
    320321
     
    324325
    325326    auto location = globalToContentCoordinates(webView(), x, y);
    326     [[HIDEventGenerator sharedHIDEventGenerator] stylusMoveToPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure completionBlock:^{
    327         if (!m_context)
    328             return;
    329         m_context->asyncTaskComplete(callbackID);
    330     }];
     327    [[HIDEventGenerator sharedHIDEventGenerator] stylusMoveToPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     328        if (!m_context)
     329            return;
     330        m_context->asyncTaskComplete(callbackID);
     331    }).get()];
    331332}
    332333
     
    336337
    337338    auto location = globalToContentCoordinates(webView(), x, y);
    338     [[HIDEventGenerator sharedHIDEventGenerator] stylusUpAtPoint:location completionBlock:^{
    339         if (!m_context)
    340             return;
    341         m_context->asyncTaskComplete(callbackID);
    342     }];
     339    [[HIDEventGenerator sharedHIDEventGenerator] stylusUpAtPoint:location completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     340        if (!m_context)
     341            return;
     342        m_context->asyncTaskComplete(callbackID);
     343    }).get()];
    343344}
    344345
     
    359360
    360361    auto location = globalToContentCoordinates(webView(), x, y);
    361     [[HIDEventGenerator sharedHIDEventGenerator] stylusTapAtPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure completionBlock:^{
     362    [[HIDEventGenerator sharedHIDEventGenerator] stylusTapAtPoint:location azimuthAngle:azimuthAngle altitudeAngle:altitudeAngle pressure:pressure completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID, modifierFlags = WTFMove(modifierFlags)] {
    362363        if (!m_context)
    363364            return;
     
    366367            [[HIDEventGenerator sharedHIDEventGenerator] keyUp:modifierFlags[i]];
    367368        }
    368         [[HIDEventGenerator sharedHIDEventGenerator] sendMarkerHIDEventWithCompletionBlock:^{
     369        [[HIDEventGenerator sharedHIDEventGenerator] sendMarkerHIDEventWithCompletionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
    369370            if (!m_context)
    370371                return;
    371372            m_context->asyncTaskComplete(callbackID);
    372         }];
    373     }];
     373        }).get()];
     374    }).get()];
    374375}
    375376
     
    429430    CGPoint endPoint = globalToContentCoordinates(webView(), endX, endY);
    430431   
    431     [[HIDEventGenerator sharedHIDEventGenerator] dragWithStartPoint:startPoint endPoint:endPoint duration:durationSeconds completionBlock:^{
    432         if (!m_context)
    433             return;
    434         m_context->asyncTaskComplete(callbackID);
    435     }];
     432    [[HIDEventGenerator sharedHIDEventGenerator] dragWithStartPoint:startPoint endPoint:endPoint duration:durationSeconds completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     433        if (!m_context)
     434            return;
     435        m_context->asyncTaskComplete(callbackID);
     436    }).get()];
    436437}
    437438   
     
    440441    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    441442   
    442     [[HIDEventGenerator sharedHIDEventGenerator] longPress:globalToContentCoordinates(webView(), x, y) completionBlock:^{
    443         if (!m_context)
    444             return;
    445         m_context->asyncTaskComplete(callbackID);
    446     }];
     443    [[HIDEventGenerator sharedHIDEventGenerator] longPress:globalToContentCoordinates(webView(), x, y) completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     444        if (!m_context)
     445            return;
     446        m_context->asyncTaskComplete(callbackID);
     447    }).get()];
    447448}
    448449
     
    458459
    459460    // Assumes that the keyboard is already shown.
    460     [[HIDEventGenerator sharedHIDEventGenerator] keyPress:toWTFString(toWK(character)) completionBlock:^{
    461         if (!m_context)
    462             return;
    463         m_context->asyncTaskComplete(callbackID);
    464     }];
     461    [[HIDEventGenerator sharedHIDEventGenerator] keyPress:toWTFString(toWK(character)) completionBlock:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     462        if (!m_context)
     463            return;
     464        m_context->asyncTaskComplete(callbackID);
     465    }).get()];
    465466}
    466467
     
    523524    // Round-trip with the WebProcess to make sure it has been notified of the dismissal.
    524525    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    525     [webView evaluateJavaScript:@"" completionHandler:^(id result, NSError *error) {
    526         if (m_context)
    527             m_context->asyncTaskComplete(callbackID);
    528     }];
     526    [webView evaluateJavaScript:@"" completionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] (id result, NSError *error) {
     527        if (!m_context)
     528            return;
     529        m_context->asyncTaskComplete(callbackID);
     530    }).get()];
    529531}
    530532
     
    655657
    656658    TestRunnerWKWebView *webView = this->webView();
    657     [webView applyAutocorrection:toWTFString(toWK(newString)) toString:toWTFString(toWK(oldString)) withCompletionHandler:^ {
    658         // applyAutocorrection can call its completion handler synchronously,
    659         // which makes UIScriptController unhappy (see bug 172884).
    660         dispatch_async(dispatch_get_main_queue(), ^ {
     659    [webView applyAutocorrection:toWTFString(toWK(newString)) toString:toWTFString(toWK(oldString)) withCompletionHandler:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     660        dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     661            // applyAutocorrection can call its completion handler synchronously,
     662            // which makes UIScriptController unhappy (see bug 172884).
    661663            if (!m_context)
    662664                return;
    663665            m_context->asyncTaskComplete(callbackID);
    664         });
    665     }];
     666        }).get());
     667        if (!m_context)
     668            return;
     669        m_context->asyncTaskComplete(callbackID);
     670    }).get()];
    666671}
    667672
     
    805810    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    806811   
    807     webView.rotationDidEndCallback = ^{
    808         if (!m_context)
    809             return;
    810         m_context->asyncTaskComplete(callbackID);
    811     };
     812    webView.rotationDidEndCallback = makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     813        if (!m_context)
     814            return;
     815        m_context->asyncTaskComplete(callbackID);
     816    }).get();
    812817   
    813818    [[UIDevice currentDevice] setOrientation:toUIDeviceOrientation(orientation) animated:YES];
     
    821826    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    822827   
    823     webView.rotationDidEndCallback = ^{
    824         if (!m_context)
    825             return;
    826         m_context->asyncTaskComplete(callbackID);
    827     };
     828    webView.rotationDidEndCallback = makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     829        if (!m_context)
     830            return;
     831        m_context->asyncTaskComplete(callbackID);
     832    }).get();
    828833   
    829834    [[UIDevice currentDevice] setOrientation:toUIDeviceOrientation(orientation) animated:YES];
     
    833838{
    834839    UIScriptController::setDidStartFormControlInteractionCallback(callback);
    835     webView().didStartFormControlInteractionCallback = ^{
     840    webView().didStartFormControlInteractionCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
    836841        if (!m_context)
    837842            return;
    838843        m_context->fireCallback(CallbackTypeDidStartFormControlInteraction);
    839     };
     844    }).get();
    840845}
    841846
     
    843848{
    844849    UIScriptController::setDidEndFormControlInteractionCallback(callback);
    845     webView().didEndFormControlInteractionCallback = ^{
     850    webView().didEndFormControlInteractionCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
    846851        if (!m_context)
    847852            return;
    848853        m_context->fireCallback(CallbackTypeDidEndFormControlInteraction);
    849     };
     854    }).get();
    850855}
    851856   
     
    853858{
    854859    UIScriptController::setDidShowContextMenuCallback(callback);
    855     webView().didShowContextMenuCallback = ^{
     860    webView().didShowContextMenuCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
    856861        if (!m_context)
    857862            return;
    858863        m_context->fireCallback(CallbackTypeDidShowContextMenu);
    859     };
     864    }).get();
    860865}
    861866
     
    863868{
    864869    UIScriptController::setDidDismissContextMenuCallback(callback);
    865     webView().didDismissContextMenuCallback = ^{
     870    webView().didDismissContextMenuCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
    866871        if (!m_context)
    867872            return;
    868873        m_context->fireCallback(CallbackTypeDidEndFormControlInteraction);
    869     };
     874    }).get();
    870875}
    871876
     
    873878{
    874879    UIScriptController::setWillBeginZoomingCallback(callback);
    875     webView().willBeginZoomingCallback = ^{
     880    webView().willBeginZoomingCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
    876881        if (!m_context)
    877882            return;
    878883        m_context->fireCallback(CallbackTypeWillBeginZooming);
    879     };
     884    }).get();
    880885}
    881886
     
    883888{
    884889    UIScriptController::setDidEndZoomingCallback(callback);
    885     webView().didEndZoomingCallback = ^{
     890    webView().didEndZoomingCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
    886891        if (!m_context)
    887892            return;
    888893        m_context->fireCallback(CallbackTypeDidEndZooming);
    889     };
     894    }).get();
    890895}
    891896
     
    893898{
    894899    UIScriptController::setDidShowKeyboardCallback(callback);
    895     webView().didShowKeyboardCallback = ^{
     900    webView().didShowKeyboardCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
    896901        if (!m_context)
    897902            return;
    898903        m_context->fireCallback(CallbackTypeDidShowKeyboard);
    899     };
     904    }).get();
    900905}
    901906
     
    903908{
    904909    UIScriptController::setDidHideKeyboardCallback(callback);
    905     webView().didHideKeyboardCallback = ^{
     910    webView().didHideKeyboardCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
    906911        if (!m_context)
    907912            return;
    908913        m_context->fireCallback(CallbackTypeDidHideKeyboard);
    909     };
     914    }).get();
    910915}
    911916
     
    932937{
    933938    UIScriptController::setWillPresentPopoverCallback(callback);
    934     webView().willPresentPopoverCallback = ^{
     939    webView().willPresentPopoverCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
    935940        if (!m_context)
    936941            return;
    937942        m_context->fireCallback(CallbackTypeWillPresentPopover);
    938     };
     943    }).get();
    939944}
    940945
     
    942947{
    943948    UIScriptController::setDidDismissPopoverCallback(callback);
    944     webView().didDismissPopoverCallback = ^{
     949    webView().didDismissPopoverCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
    945950        if (!m_context)
    946951            return;
    947952        m_context->fireCallback(CallbackTypeDidDismissPopover);
    948     };
     953    }).get();
    949954}
    950955
     
    10051010{
    10061011    UIScriptController::setDidEndScrollingCallback(callback);
    1007     webView().didEndScrollingCallback = ^{
     1012    webView().didEndScrollingCallback = makeBlockPtr([this, strongThis = makeRef(*this)] {
    10081013        if (!m_context)
    10091014            return;
    10101015        m_context->fireCallback(CallbackTypeDidEndScrolling);
    1011     };
     1016    }).get();
    10121017}
    10131018
     
    10391044
    10401045    unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
    1041     dispatch_async(dispatch_get_main_queue(), ^{
    1042         if (!m_context)
    1043             return;
    1044         m_context->asyncTaskComplete(callbackID);
    1045     });
     1046    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     1047        if (!m_context)
     1048            return;
     1049        m_context->asyncTaskComplete(callbackID);
     1050    }).get());
    10461051}
    10471052
     
    11941199    }
    11951200
    1196     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(maximumIntervalBetweenSuccessiveTaps * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    1197         if (m_context)
    1198             m_context->asyncTaskComplete(callbackID);
    1199     });
     1201    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(maximumIntervalBetweenSuccessiveTaps * NSEC_PER_SEC)), dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     1202        if (!m_context)
     1203            return;
     1204        m_context->asyncTaskComplete(callbackID);
     1205    }).get());
    12001206}
    12011207
  • trunk/Tools/WebKitTestRunner/mac/UIScriptControllerMac.mm

    r252719 r253282  
    4444#import <JavaScriptCore/OpaqueJSString.h>
    4545#import <WebKit/WKWebViewPrivate.h>
     46#import <wtf/BlockPtr.h>
    4647
    4748namespace WTR {
     
    6970    [webView _setPageScale:scale withOrigin:CGPointZero];
    7071
    71     [webView _doAfterNextPresentationUpdate:^{
    72         if (!m_context)
    73             return;
    74         m_context->asyncTaskComplete(callbackID);
    75     }];
     72    [webView _doAfterNextPresentationUpdate:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     73        if (!m_context)
     74            return;
     75        m_context->asyncTaskComplete(callbackID);
     76    }).get()];
    7677}
    7778
     
    8990    [center postNotificationName:NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification object:webView];
    9091
    91     [webView _doAfterNextPresentationUpdate:^{
    92         if (!m_context)
    93             return;
    94         m_context->asyncTaskComplete(callbackID);
    95     }];
     92    [webView _doAfterNextPresentationUpdate:makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     93        if (!m_context)
     94            return;
     95        m_context->asyncTaskComplete(callbackID);
     96    }).get()];
    9697}
    9798
     
    172173    }
    173174
    174     dispatch_async(dispatch_get_main_queue(), ^{
    175         if (m_context)
    176             m_context->asyncTaskComplete(callbackID);
    177     });
     175    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     176        if (!m_context)
     177            return;
     178        m_context->asyncTaskComplete(callbackID);
     179    }).get());
    178180}
    179181
     
    248250    eventSender->mouseUp(0, 0);
    249251
    250     dispatch_async(dispatch_get_main_queue(), ^{
    251         if (m_context)
    252             m_context->asyncTaskComplete(callbackID);
    253     });
     252    dispatch_async(dispatch_get_main_queue(), makeBlockPtr([this, strongThis = makeRef(*this), callbackID] {
     253        if (!m_context)
     254            return;
     255        m_context->asyncTaskComplete(callbackID);
     256    }).get());
    254257}
    255258
Note: See TracChangeset for help on using the changeset viewer.