Changeset 47509 in webkit


Ignore:
Timestamp:
Aug 19, 2009 10:33:32 AM (15 years ago)
Author:
kdecker@apple.com
Message:

Reviewed by Kevin Decker.

<rdar://problem/7042555> Loading certain pages on Tiger will start a spurious download


Get rid of method swizzling entirely. This created problems when lower level
Foundation code would call into our own swizzled method.


  • platform/network/mac/ResourceHandleMac.mm: (-[WebCoreResourceHandleAsDelegate connection:didReceiveResponse:]):
  • platform/network/mac/WebCoreURLResponse.h:
  • platform/network/mac/WebCoreURLResponse.mm: (-[NSURLResponse adjustMIMETypeIfNecessary]):
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r47508 r47509  
     12009-08-19  Brady Eidson <beidson@apple.com>
     2
     3        Reviewed by Kevin Decker.
     4
     5        <rdar://problem/7042555> Loading certain pages on Tiger will start a spurious download
     6       
     7        Get rid of method swizzling entirely. This created problems when lower level
     8        Foundation code would call into our own swizzled method.
     9       
     10        * platform/network/mac/ResourceHandleMac.mm:
     11        (-[WebCoreResourceHandleAsDelegate connection:didReceiveResponse:]):
     12        * platform/network/mac/WebCoreURLResponse.h:
     13        * platform/network/mac/WebCoreURLResponse.mm:
     14        (-[NSURLResponse adjustMIMETypeIfNecessary]):
     15
    1162009-08-19  Adam Roben  <aroben@apple.com>
    217
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r47481 r47509  
    1755217552                        runOnlyForDeploymentPostprocessing = 0;
    1755317553                        shellPath = /bin/sh;
    17554                         shellScript = "if [ \"${ACTION}\" = \"installhdrs\" ]; then\n    exit 0;\nfi\n\nif [ -f ../WebKitTools/Scripts/check-for-global-initializers ]; then\n    ../WebKitTools/Scripts/check-for-global-initializers || exit $?\nfi";
     17554                        shellScript = "";
    1755517555                };
    1755617556                DD041FBD09D9DDBE0010AF2A /* Generate Derived Sources */ = {
  • trunk/WebCore/platform/network/mac/ResourceHandleMac.mm

    r46548 r47509  
    11/*
    2  * Copyright (C) 2004, 2006 Apple Inc. All rights reserved.
     2 * Copyright (C) 2004, 2006-2009 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    6565@end
    6666
    67 @interface NSURLResponse (Details)
    68 - (void)_setMIMEType:(NSString *)type;
    69 @end
    70 
    7167@interface NSURLRequest (Details)
    7268- (id)_propertyForKey:(NSString *)key;
     
    636632    UNUSED_PARAM(connection);
    637633
    638     LOG(Network, "Handle %p delegate connection:%p didReceiveResponse:%p (HTTP status %d, MIMEType '%s', reported MIMEType '%s')", m_handle, connection, r, [r respondsToSelector:@selector(statusCode)] ? [(id)r statusCode] : 0, [[r MIMEType] UTF8String], [[r _webcore_reportedMIMEType] UTF8String]);
     634    LOG(Network, "Handle %p delegate connection:%p didReceiveResponse:%p (HTTP status %d, reported MIMEType '%s')", m_handle, connection, r, [r respondsToSelector:@selector(statusCode)] ? [(id)r statusCode] : 0, [[r MIMEType] UTF8String]);
    639635
    640636    if (!m_handle || !m_handle->client())
     
    642638    CallbackGuard guard;
    643639
    644     swizzleMIMETypeMethodIfNecessary();
     640    [r adjustMIMETypeIfNecessary];
    645641
    646642    if ([m_handle->request().nsURLRequest() _propertyForKey:@"ForceHTMLMIMEType"])
  • trunk/WebCore/platform/network/mac/WebCoreURLResponse.h

    r45476 r47509  
    11/*
    2  * Copyright (C) 2008 Apple Inc. All rights reserved.
     2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828
    2929@interface NSURLResponse (WebCoreURLResponse)
    30 -(NSString *)_webcore_reportedMIMEType;
     30-(void)adjustMIMETypeIfNecessary;
    3131@end
    3232
    33 void swizzleMIMETypeMethodIfNecessary();
     33@interface NSURLResponse (Details)
     34- (void)_setMIMEType:(NSString *)type;
     35@end
  • trunk/WebCore/platform/network/mac/WebCoreURLResponse.mm

    r45499 r47509  
    11/*
    2  * Copyright (C) 2008 Apple Inc. All rights reserved.
     2 * Copyright (C) 2008, 2009 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    328328}
    329329
    330 static IMP oldNSURLResponseMIMETypeIMP = 0;
    331 static NSString *webNSURLResponseMIMEType(id, SEL);
    332 
    333 void swizzleMIMETypeMethodIfNecessary()
    334 {
    335     if (!oldNSURLResponseMIMETypeIMP) {
    336         Method nsURLResponseMIMETypeMethod = class_getInstanceMethod([NSURLResponse class], @selector(MIMEType));
    337         ASSERT(nsURLResponseMIMETypeMethod);
    338 #ifdef BUILDING_ON_TIGER
    339         oldNSURLResponseMIMETypeIMP = nsURLResponseMIMETypeMethod->method_imp;
    340         nsURLResponseMIMETypeMethod->method_imp = (IMP)webNSURLResponseMIMEType;
    341 #else
    342         oldNSURLResponseMIMETypeIMP = method_setImplementation(nsURLResponseMIMETypeMethod, (IMP)webNSURLResponseMIMEType);
    343 #endif
    344     }
    345 }
    346 
    347330static NSString *mimeTypeFromUTITree(CFStringRef uti)
    348331{
     
    380363}
    381364
    382 static NSString *webNSURLResponseMIMEType(id self, SEL _cmd)
     365@implementation NSURLResponse (WebCoreURLResponse)
     366
     367-(void)adjustMIMETypeIfNecessary
    383368{
    384     ASSERT(oldNSURLResponseMIMETypeIMP);
    385     NSString *result = oldNSURLResponseMIMETypeIMP(self, _cmd);
     369    NSString *result = [self MIMEType];
     370    NSString *originalResult = result;
    386371
    387372#ifdef BUILDING_ON_TIGER
     
    419404    // <rdar://problem/5321972> Plain text document from HTTP server detected as application/octet-stream
    420405    // Make the best guess when deciding between "generic binary" and "generic text" using a table of known binary MIME types.
    421     if ([result isEqualToString:@"application/octet-stream"] && [self respondsToSelector:@selector(allHeaderFields)] && [[[self allHeaderFields] objectForKey:@"Content-Type"] hasPrefix:@"text/plain"]) {
     406    if ([result isEqualToString:@"application/octet-stream"] && [self respondsToSelector:@selector(allHeaderFields)] && [[[self performSelector:@selector(allHeaderFields)] objectForKey:@"Content-Type"] hasPrefix:@"text/plain"]) {
    422407        static NSSet *binaryExtensions = createBinaryExtensionsSet();
    423408        if (![binaryExtensions containsObject:[[[self suggestedFilename] pathExtension] lowercaseString]])
     
    433418#endif
    434419
    435     return result;
     420    if (result != originalResult)
     421        [self _setMIMEType:result];
    436422}
    437423
    438 @implementation NSURLResponse (WebCoreURLResponse)
    439 
    440 -(NSString *)_webcore_reportedMIMEType
    441 {
    442     swizzleMIMETypeMethodIfNecessary();
    443     return oldNSURLResponseMIMETypeIMP(self, @selector(_webcore_realMIMEType));
    444 }
    445 
    446424@end
Note: See TracChangeset for help on using the changeset viewer.