Changeset 243947 in webkit


Ignore:
Timestamp:
Apr 5, 2019 2:52:51 PM (5 years ago)
Author:
achristensen@apple.com
Message:

REGRESSION(AppleWebKit/605.1.15): WebDownloadDelegate delegate methods called on non-main thread
https://bugs.webkit.org/show_bug.cgi?id=190918
<rdar://problem/45603890>

Reviewed by Darin Adler.

Source/WebKitLegacy/mac:

Since we not doing networking on the main thread but WebView is to be used on the main thread,
we need to hop delegate calls to the main thread similarly to how we do it in the non-download
delegate calls in WebCoreResourceHandleAsOperationQueueDelegate.

  • Misc/WebDownload.mm:

(-[WebDownloadInternal downloadDidBegin:]):
(-[WebDownloadInternal download:willSendRequest:redirectResponse:]):
(-[WebDownloadInternal download:didReceiveAuthenticationChallenge:]):
(-[WebDownloadInternal download:didReceiveResponse:]):
(-[WebDownloadInternal download:didReceiveDataOfLength:]):
(-[WebDownloadInternal download:shouldDecodeSourceDataOfMIMEType:]):
(-[WebDownloadInternal download:decideDestinationWithSuggestedFilename:]):
(-[WebDownloadInternal download:didCreateDestination:]):
(-[WebDownloadInternal downloadDidFinish:]):
(-[WebDownloadInternal download:didFailWithError:]):

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitLegacy/mac/DownloadThread.mm: Added.

(-[DownloadThreadChecker webView:decidePolicyForMIMEType:request:frame:decisionListener:]):
(-[DownloadThreadChecker downloadDidBegin:]):
(-[DownloadThreadChecker download:shouldDecodeSourceDataOfMIMEType:]):
(-[DownloadThreadChecker download:decideDestinationWithSuggestedFilename:]):
(-[DownloadThreadChecker download:didCreateDestination:]):
(-[DownloadThreadChecker downloadDidFinish:]):
(TestWebKitAPI::TEST):

Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-607-branch/Tools/ChangeLog

    r243946 r243947  
     12019-04-05  Alex Christensen  <achristensen@webkit.org>
     2
     3        REGRESSION(AppleWebKit/605.1.15): WebDownloadDelegate delegate methods called on non-main thread
     4        https://bugs.webkit.org/show_bug.cgi?id=190918
     5        <rdar://problem/45603890>
     6
     7        Reviewed by Darin Adler.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebKitLegacy/mac/DownloadThread.mm: Added.
     11        (-[DownloadThreadChecker webView:decidePolicyForMIMEType:request:frame:decisionListener:]):
     12        (-[DownloadThreadChecker downloadDidBegin:]):
     13        (-[DownloadThreadChecker download:shouldDecodeSourceDataOfMIMEType:]):
     14        (-[DownloadThreadChecker download:decideDestinationWithSuggestedFilename:]):
     15        (-[DownloadThreadChecker download:didCreateDestination:]):
     16        (-[DownloadThreadChecker downloadDidFinish:]):
     17        (TestWebKitAPI::TEST):
     18
    1192019-04-05  Alex Christensen  <achristensen@webkit.org>
    220
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r243944 r243947  
     12019-04-05  Alex Christensen  <achristensen@webkit.org>
     2
     3        REGRESSION(AppleWebKit/605.1.15): WebDownloadDelegate delegate methods called on non-main thread
     4        https://bugs.webkit.org/show_bug.cgi?id=190918
     5        <rdar://problem/45603890>
     6
     7        Reviewed by Darin Adler.
     8
     9        Since we not doing networking on the main thread but WebView is to be used on the main thread,
     10        we need to hop delegate calls to the main thread similarly to how we do it in the non-download
     11        delegate calls in WebCoreResourceHandleAsOperationQueueDelegate.
     12
     13        * Misc/WebDownload.mm:
     14        (-[WebDownloadInternal downloadDidBegin:]):
     15        (-[WebDownloadInternal download:willSendRequest:redirectResponse:]):
     16        (-[WebDownloadInternal download:didReceiveAuthenticationChallenge:]):
     17        (-[WebDownloadInternal download:didReceiveResponse:]):
     18        (-[WebDownloadInternal download:didReceiveDataOfLength:]):
     19        (-[WebDownloadInternal download:shouldDecodeSourceDataOfMIMEType:]):
     20        (-[WebDownloadInternal download:decideDestinationWithSuggestedFilename:]):
     21        (-[WebDownloadInternal download:didCreateDestination:]):
     22        (-[WebDownloadInternal downloadDidFinish:]):
     23        (-[WebDownloadInternal download:didFailWithError:]):
     24
    1252019-04-05  Eric Carlson  <eric.carlson@apple.com>
    226
  • trunk/Source/WebKitLegacy/mac/Misc/WebDownload.mm

    r240292 r243947  
    4040#import <pal/spi/cocoa/NSURLDownloadSPI.h>
    4141#import <wtf/Assertions.h>
     42#import <wtf/MainThread.h>
    4243
    4344using namespace WebCore;
     
    8384- (void)downloadDidBegin:(NSURLDownload *)download
    8485{
    85     [realDelegate downloadDidBegin:download];
     86    callOnMainThread([realDelegate = retainPtr(realDelegate), download = retainPtr(download)] {
     87        [realDelegate downloadDidBegin:download.get()];
     88    });
    8689}
    8790
    8891- (NSURLRequest *)download:(NSURLDownload *)download willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
    8992{
    90     return [realDelegate download:download willSendRequest:request redirectResponse:redirectResponse];
     93    RetainPtr<NSURLRequest> returnValue;
     94    auto work = [&] {
     95        ASSERT(isMainThread());
     96        returnValue = [realDelegate download:download willSendRequest:request redirectResponse:redirectResponse];
     97    };
     98    if (isMainThread())
     99        work();
     100    else
     101        dispatch_sync(dispatch_get_main_queue(), work);
     102    return returnValue.autorelease();
    91103}
    92104
     
    104116
    105117    if ([realDelegate respondsToSelector:@selector(download:didReceiveAuthenticationChallenge:)]) {
    106         [realDelegate download:download didReceiveAuthenticationChallenge:challenge];
     118        callOnMainThread([realDelegate = retainPtr(realDelegate), download = retainPtr(download), challenge = retainPtr(challenge)] {
     119            [realDelegate download:download.get() didReceiveAuthenticationChallenge:challenge.get()];
     120        });
    107121    } else {
    108         NSWindow *window = nil;
    109         if ([realDelegate respondsToSelector:@selector(downloadWindowForAuthenticationSheet:)]) {
    110             window = [realDelegate downloadWindowForAuthenticationSheet:(WebDownload *)download];
    111         }
    112 
    113         [[WebPanelAuthenticationHandler sharedHandler] startAuthentication:challenge window:window];
     122        callOnMainThread([realDelegate = retainPtr(realDelegate), download = retainPtr(download), challenge = retainPtr(challenge)] {
     123            NSWindow *window = nil;
     124            if ([realDelegate respondsToSelector:@selector(downloadWindowForAuthenticationSheet:)])
     125                window = [realDelegate downloadWindowForAuthenticationSheet:(WebDownload *)download.get()];
     126
     127            [[WebPanelAuthenticationHandler sharedHandler] startAuthentication:challenge.get() window:window];
     128        });
    114129    }
    115130#endif
     
    118133- (void)download:(NSURLDownload *)download didReceiveResponse:(NSURLResponse *)response
    119134{
    120     [realDelegate download:download didReceiveResponse:response];
     135    callOnMainThread([realDelegate = retainPtr(realDelegate), download = retainPtr(download), response = retainPtr(response)] {
     136        [realDelegate download:download.get() didReceiveResponse:response.get()];
     137    });
    121138}
    122139
    123140- (void)download:(NSURLDownload *)download didReceiveDataOfLength:(NSUInteger)length
    124141{
    125     [realDelegate download:download didReceiveDataOfLength:length];
     142    callOnMainThread([realDelegate = retainPtr(realDelegate), download = retainPtr(download), length] {
     143        [realDelegate download:download.get() didReceiveDataOfLength:length];
     144    });
    126145}
    127146
    128147- (BOOL)download:(NSURLDownload *)download shouldDecodeSourceDataOfMIMEType:(NSString *)encodingType
    129148{
    130     return [realDelegate download:download shouldDecodeSourceDataOfMIMEType:encodingType];
     149    BOOL returnValue = NO;
     150    auto work = [&] {
     151        returnValue = [realDelegate download:download shouldDecodeSourceDataOfMIMEType:encodingType];
     152    };
     153    if (isMainThread())
     154        work();
     155    else
     156        dispatch_sync(dispatch_get_main_queue(), work);
     157    return returnValue;
    131158}
    132159
    133160- (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename
    134161{
    135     [realDelegate download:download decideDestinationWithSuggestedFilename:filename];
     162    callOnMainThread([realDelegate = retainPtr(realDelegate), download = retainPtr(download), filename = retainPtr(filename)] {
     163        [realDelegate download:download.get() decideDestinationWithSuggestedFilename:filename.get()];
     164    });
    136165}
    137166
    138167- (void)download:(NSURLDownload *)download didCreateDestination:(NSString *)path
    139168{
    140     [realDelegate download:download didCreateDestination:path];
     169    callOnMainThread([realDelegate = retainPtr(realDelegate), download = retainPtr(download), path = retainPtr(path)] {
     170        [realDelegate download:download.get() didCreateDestination:path.get()];
     171    });
    141172}
    142173
    143174- (void)downloadDidFinish:(NSURLDownload *)download
    144175{
    145     [realDelegate downloadDidFinish:download];
     176    callOnMainThread([realDelegate = retainPtr(realDelegate), download = retainPtr(download)] {
     177        [realDelegate downloadDidFinish:download.get()];
     178    });
    146179}
    147180
    148181- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
    149182{
    150     [realDelegate download:download didFailWithError:error];
     183    callOnMainThread([realDelegate = retainPtr(realDelegate), download = retainPtr(download), error = retainPtr(error)] {
     184        [realDelegate download:download.get() didFailWithError:error.get()];
     185    });
    151186}
    152187
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r243797 r243947  
    341341                5CE354D91E70DA5C00BEFE3B /* WKContentExtensionStore.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CE354D81E70D9C300BEFE3B /* WKContentExtensionStore.mm */; };
    342342                5CEAB5E11FA939F400A77FAA /* _WKInputDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CEAB5DF1FA937CB00A77FAA /* _WKInputDelegate.mm */; };
     343                5CF540E92257E67C00E6BC0E /* DownloadThread.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CF540E82257E64B00E6BC0E /* DownloadThread.mm */; };
    343344                5E4B1D2E1D404C6100053621 /* WKScrollViewDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5E4B1D2C1D404C6100053621 /* WKScrollViewDelegate.mm */; };
    344345                631EFFF61E7B5E8D00D2EBB8 /* Geolocation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 631EFFF51E7B5E8D00D2EBB8 /* Geolocation.mm */; };
     
    17491750                5CE354D81E70D9C300BEFE3B /* WKContentExtensionStore.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKContentExtensionStore.mm; sourceTree = "<group>"; };
    17501751                5CEAB5DF1FA937CB00A77FAA /* _WKInputDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKInputDelegate.mm; sourceTree = "<group>"; };
     1752                5CF540E82257E64B00E6BC0E /* DownloadThread.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DownloadThread.mm; sourceTree = "<group>"; };
    17511753                5E4B1D2C1D404C6100053621 /* WKScrollViewDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKScrollViewDelegate.mm; path = ../ios/WKScrollViewDelegate.mm; sourceTree = "<group>"; };
    17521754                631EFFF51E7B5E8D00D2EBB8 /* Geolocation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Geolocation.mm; sourceTree = "<group>"; };
     
    28562858                                9BD5111B1FE8E11600D2B630 /* AccessingPastedImage.mm */,
    28572859                                6B306105218A372900F5A802 /* ClosingWebView.mm */,
     2860                                5CF540E82257E64B00E6BC0E /* DownloadThread.mm */,
    28582861                                5C6E27A6224EEBEA00128736 /* URLCanonicalization.mm */,
    28592862                        );
     
    40784081                                7CCE7EEE1A411AE600447C4C /* DownloadDecideDestinationCrash.cpp in Sources */,
    40794082                                637281A721AE1386009E0DE6 /* DownloadProgress.mm in Sources */,
     4083                                5CF540E92257E67C00E6BC0E /* DownloadThread.mm in Sources */,
    40804084                                F4D4F3B61E4E2BCB00BB2767 /* DragAndDropSimulatorIOS.mm in Sources */,
    40814085                                F46128B7211C8ED500D9FADB /* DragAndDropSimulatorMac.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.