Changeset 25777 in webkit


Ignore:
Timestamp:
Sep 27, 2007 2:24:26 PM (17 years ago)
Author:
thatcher
Message:

Reviewed by Darin.

<rdar://problem/5199546> CrashTracer: [REGRESSION] 8216 crashes in Safari at com.apple.WebCore: WebCore::ResourceHandle::client const + 6

On Tiger CFURLConnection can sometimes call the connection:willCacheResponse: delegate method on
a secondary thread instead of the main thread. This was never an issue before, since the implementation
of this method was very simple and thread safe.

The fix is to block during connection:willCacheResponse: and perform the work on the main thread.
We need to block since this delegate method needs to return a result. If we are already on the
main thread (which sometimes we are), the method does nothing different. If we are on a secondary
thread, we make a mutable dictionary to hold all the arguments and later the result object.
Then performSelectorOnMainThread:withObject: using the _callConnectionWillCacheResponseWithInfo:
selector. This new method just pulls the arguments out for the dictionary and calls the real
connection:willCacheResponse: delegate method (this time on the main thread). The result is stored
in the dictionary, and when performSelectorOnMainThread:withObject: finishes the result is pulled
out and returned.

  • platform/network/mac/ResourceHandleMac.mm: (-[WebCoreResourceHandleAsDelegate _callConnectionWillCacheResponseWithInfo:]): (-[WebCoreResourceHandleAsDelegate connection:willCacheResponse:]):
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r25774 r25777  
     12007-09-27  Timothy Hatcher  <timothy@apple.com>
     2
     3        Reviewed by Darin.
     4
     5        <rdar://problem/5199546> CrashTracer: [REGRESSION] 8216 crashes in Safari at com.apple.WebCore: WebCore::ResourceHandle::client const + 6
     6
     7        On Tiger CFURLConnection can sometimes call the connection:willCacheResponse: delegate method on
     8        a secondary thread instead of the main thread. This was never an issue before, since the implementation
     9        of this method was very simple and thread safe.
     10
     11        The fix is to block during connection:willCacheResponse: and perform the work on the main thread.
     12        We need to block since this delegate method needs to return a result. If we are already on the
     13        main thread (which sometimes we are), the method does nothing different. If we are on a secondary
     14        thread, we make a mutable dictionary to hold all the arguments and later the result object.
     15        Then performSelectorOnMainThread:withObject: using the _callConnectionWillCacheResponseWithInfo:
     16        selector. This new method just pulls the arguments out for the dictionary and calls the real
     17        connection:willCacheResponse: delegate method (this time on the main thread). The result is stored
     18        in the dictionary, and when performSelectorOnMainThread:withObject: finishes the result is pulled
     19        out and returned.
     20
     21        * platform/network/mac/ResourceHandleMac.mm:
     22        (-[WebCoreResourceHandleAsDelegate _callConnectionWillCacheResponseWithInfo:]):
     23        (-[WebCoreResourceHandleAsDelegate connection:willCacheResponse:]):
     24
    1252007-09-27  David Hyatt  <hyatt@apple.com>
    226
  • trunk/WebCore/platform/network/mac/ResourceHandleMac.mm

    r25274 r25777  
    466466}
    467467
     468#ifdef BUILDING_ON_TIGER
     469- (void)_callConnectionWillCacheResponseWithInfo:(NSMutableDictionary *)info
     470{
     471    NSURLConnection *connection = [info objectForKey:@"connection"];
     472    NSCachedURLResponse *cachedResponse = [info objectForKey:@"cachedResponse"];
     473    NSCachedURLResponse *result = [self connection:connection willCacheResponse:cachedResponse];
     474    if (result)
     475        [info setObject:result forKey:@"result"];
     476}
     477#endif
     478
    468479- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
    469480{
     481#ifdef BUILDING_ON_TIGER
     482    // On Tiger CFURLConnection can sometimes call the connection:willCacheResponse: delegate method on
     483    // a secondary thread instead of the main thread. If this happens perform the work on the main thread.
     484    if (!pthread_main_np()) {
     485        NSMutableDictionary *info = [[NSMutableDictionary alloc] init];
     486        if (connection)
     487            [info setObject:connection forKey:@"connection"];
     488        if (cachedResponse)
     489            [info setObject:cachedResponse forKey:@"cachedResponse"];
     490
     491        [self performSelectorOnMainThread:@selector(_callConnectionWillCacheResponseWithInfo:) withObject:info waitUntilDone:YES];
     492
     493        NSCachedURLResponse *result = [[info valueForKey:@"result"] retain];
     494        [info release];
     495
     496        return [result autorelease];
     497    }
     498#endif
     499
    470500#ifndef NDEBUG
    471501    if (isInitializingConnection)
Note: See TracChangeset for help on using the changeset viewer.