[webkit-changes] cvs commit: WebKit/WebView.subproj WebBaseResourceHandleDelegate.m WebLoader.m WebResource.m WebResourcePrivate.h

Adele adele at opensource.apple.com
Tue Jul 12 22:26:09 PDT 2005


adele       05/07/12 22:26:09

  Modified:    .        Tag: Safari-1-3-branch ChangeLog
               WebCoreSupport.subproj Tag: Safari-1-3-branch WebBridge.m
               WebView.subproj Tag: Safari-1-3-branch
                        WebBaseResourceHandleDelegate.m WebLoader.m
                        WebResource.m WebResourcePrivate.h
  Log:
          Merged fix from TOT to Safari-1-3-branch
          <rdar://problem/4164992>
  
      2005-05-04  Chris Blumenberg  <cblu at apple.com>
  
          Fixed:
          <rdar://problem/4078417> REGRESSION (125-412): MLB gameday page doesn't update (Flash)
          <rdar://problem/4072280> XMLHttpRequest calls onReadyStateChange callback with bogus status value
  
          Reviewed by john.
  
          Our WebKit-level caching of subresources "dumbed-down" information held in NSURLResponse. This caused some loads to lack response headers and thus disabling cache directives. Status codes were also not retained and this caused XMLHttpRequest to fail frequently. The fix is to have WebResource retain the NSURLResponse and to use the NSURLResponse when we decide to load from WebResources.
  
          * WebCoreSupport.subproj/WebBridge.m:
          (-[WebBridge objectLoadedFromCacheWithURL:response:data:]): call new [WebResource _initWithData:URL:response:]
          * WebView.subproj/WebBaseResourceHandleDelegate.m:
          (-[WebBaseResourceHandleDelegate _canUseResourceWithResponse:]): new, checks response cache directives
          (-[WebBaseResourceHandleDelegate loadWithRequest:]): call _canUseResourceWithResponse:
          (-[WebBaseResourceHandleDelegate saveResource]): call new [WebResource _initWithData:URL:response:]
          * WebView.subproj/WebResource.m:
          (-[WebResourcePrivate dealloc]):
          (-[WebResource initWithData:URL:MIMEType:textEncodingName:frameName:]): call renamed _initWithData:URL:MIMEType:textEncodingName:frameName:response:copyData:
          (-[WebResource initWithCoder:]): decode the NSURLReponse
          (-[WebResource encodeWithCoder:]): encode the NSURLReponse
          (-[WebResource _initWithData:URL:MIMEType:textEncodingName:frameName:response:copyData:]): take the NSURLReponse
          (-[WebResource _initWithData:URL:response:]): new
          (-[WebResource _initWithPropertyList:]): decode the NSURLReponse
          (-[WebResource _propertyListRepresentation]): encode the NSURLReponse
          (-[WebResource _response]): return ivar if we have one
          * WebView.subproj/WebResourcePrivate.h:
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.3120.2.10 +33 -0     WebKit/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebKit/ChangeLog,v
  retrieving revision 1.3120.2.9
  retrieving revision 1.3120.2.10
  diff -u -r1.3120.2.9 -r1.3120.2.10
  --- ChangeLog	13 Jul 2005 04:38:43 -0000	1.3120.2.9
  +++ ChangeLog	13 Jul 2005 05:26:03 -0000	1.3120.2.10
  @@ -1,5 +1,38 @@
   2005-07-12  Adele Peterson  <adele at apple.com>
   
  +        Merged fix from TOT to Safari-1-3-branch
  +        <rdar://problem/4164992>
  +
  +    2005-05-04  Chris Blumenberg  <cblu at apple.com>
  +
  +	Fixed: 
  +	<rdar://problem/4078417> REGRESSION (125-412): MLB gameday page doesn't update (Flash)
  +	<rdar://problem/4072280> XMLHttpRequest calls onReadyStateChange callback with bogus status value
  +        
  +	Reviewed by john.
  +
  +	Our WebKit-level caching of subresources "dumbed-down" information held in NSURLResponse. This caused some loads to lack response headers and thus disabling cache directives. Status codes were also not retained and this caused XMLHttpRequest to fail frequently. The fix is to have WebResource retain the NSURLResponse and to use the NSURLResponse when we decide to load from WebResources.
  +
  +        * WebCoreSupport.subproj/WebBridge.m:
  +        (-[WebBridge objectLoadedFromCacheWithURL:response:data:]): call new [WebResource _initWithData:URL:response:]
  +        * WebView.subproj/WebBaseResourceHandleDelegate.m:
  +        (-[WebBaseResourceHandleDelegate _canUseResourceWithResponse:]): new, checks response cache directives
  +        (-[WebBaseResourceHandleDelegate loadWithRequest:]): call _canUseResourceWithResponse:
  +        (-[WebBaseResourceHandleDelegate saveResource]): call new [WebResource _initWithData:URL:response:]
  +        * WebView.subproj/WebResource.m:
  +        (-[WebResourcePrivate dealloc]):
  +        (-[WebResource initWithData:URL:MIMEType:textEncodingName:frameName:]): call renamed _initWithData:URL:MIMEType:textEncodingName:frameName:response:copyData:
  +        (-[WebResource initWithCoder:]): decode the NSURLReponse
  +        (-[WebResource encodeWithCoder:]): encode the NSURLReponse
  +        (-[WebResource _initWithData:URL:MIMEType:textEncodingName:frameName:response:copyData:]): take the NSURLReponse
  +        (-[WebResource _initWithData:URL:response:]): new
  +        (-[WebResource _initWithPropertyList:]): decode the NSURLReponse
  +        (-[WebResource _propertyListRepresentation]): encode the NSURLReponse
  +        (-[WebResource _response]): return ivar if we have one
  +        * WebView.subproj/WebResourcePrivate.h:
  +
  +2005-07-12  Adele Peterson  <adele at apple.com>
  +
          Merged fix from TOT to Safari-1-3-branch
          <rdar://problem/4164997>         
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.340.6.3 +1 -8      WebKit/WebCoreSupport.subproj/WebBridge.m
  
  Index: WebBridge.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebCoreSupport.subproj/WebBridge.m,v
  retrieving revision 1.340.6.2
  retrieving revision 1.340.6.3
  diff -u -r1.340.6.2 -r1.340.6.3
  --- WebBridge.m	2 Jun 2005 19:26:39 -0000	1.340.6.2
  +++ WebBridge.m	13 Jul 2005 05:26:07 -0000	1.340.6.3
  @@ -458,14 +458,7 @@
   
   - (void)objectLoadedFromCacheWithURL:(NSURL *)URL response:(NSURLResponse *)response data:(NSData *)data
   {
  -    // Pass NO for copyData since the data doesn't need to be copied since it won't be modified. 
  -    // Copying it will also cause a performance regression. 
  -    WebResource *resource = [[WebResource alloc] _initWithData:data
  -                                                           URL:URL
  -                                                      MIMEType:[response MIMEType]
  -                                              textEncodingName:[response textEncodingName]
  -                                                     frameName:nil
  -                                                      copyData:NO];
  +    WebResource *resource = [[WebResource alloc] _initWithData:data URL:URL response:response];
       ASSERT(resource != nil);
       [[self dataSource] addSubresource:resource];
       [resource release];
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.84.2.2  +22 -13    WebKit/WebView.subproj/Attic/WebBaseResourceHandleDelegate.m
  
  Index: WebBaseResourceHandleDelegate.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/Attic/WebBaseResourceHandleDelegate.m,v
  retrieving revision 1.84.2.1
  retrieving revision 1.84.2.2
  diff -u -r1.84.2.1 -r1.84.2.2
  --- WebBaseResourceHandleDelegate.m	2 Jun 2005 15:44:43 -0000	1.84.2.1
  +++ WebBaseResourceHandleDelegate.m	13 Jul 2005 05:26:08 -0000	1.84.2.2
  @@ -165,7 +165,7 @@
       }
   }
   
  -// This is copied from [NSHTTPURLProtocol _cachedResponsePassesValidityChecks] and modified for our needs.
  +// The following 2 methods are copied from [NSHTTPURLProtocol _cachedResponsePassesValidityChecks] and modified for our needs.
   // FIXME: It would be nice to eventually to share this code somehow.
   - (BOOL)_canUseResourceForRequest:(NSURLRequest *)theRequest
   {
  @@ -192,6 +192,17 @@
       }
   }
   
  +- (BOOL)_canUseResourceWithResponse:(NSURLResponse *)theResponse
  +{
  +    if ([theResponse _mustRevalidate]) {
  +        return NO;
  +    } else if ([theResponse _calculatedExpiration] - CFAbsoluteTimeGetCurrent() < 1) {
  +        return NO;
  +    } else {
  +        return YES;
  +    }
  +}
  +
   - (BOOL)loadWithRequest:(NSURLRequest *)r
   {
       ASSERT(connection == nil);
  @@ -216,11 +227,15 @@
       
       if ([[r URL] isEqual:originalURL] && [self _canUseResourceForRequest:r]) {
           resource = [dataSource subresourceForURL:originalURL];
  -        if (resource) {
  -            [resource retain];
  -            // Deliver the resource after a delay because callers don't expect to receive callbacks while calling this method.
  -            [self deliverResourceAfterDelay];
  -            return YES;
  +        if (resource != nil) {
  +            if ([self _canUseResourceWithResponse:[resource _response]]) {
  +                [resource retain];
  +                // Deliver the resource after a delay because callers don't expect to receive callbacks while calling this method.
  +                [self deliverResourceAfterDelay];
  +                return YES;
  +            } else {
  +                resource = nil;
  +            }
           }
       }
       
  @@ -306,15 +321,9 @@
       if (resource == nil) {
           NSData *data = [self resourceData];
           if ([data length] > 0) {
  -            // Don't have WebResource copy the data since the data is a NSMutableData that we know won't get modified. 
               ASSERT(originalURL);
               ASSERT([response MIMEType]);
  -            WebResource *newResource = [[WebResource alloc] _initWithData:data
  -                                                                      URL:originalURL
  -                                                                 MIMEType:[response MIMEType]
  -                                                         textEncodingName:[response textEncodingName]
  -                                                                frameName:nil
  -                                                                 copyData:NO];
  +            WebResource *newResource = [[WebResource alloc] _initWithData:data URL:originalURL response:response];
               if (newResource != nil) {
                   [dataSource addSubresource:newResource];
                   [newResource release];
  
  
  
  1.84.2.2  +22 -13    WebKit/WebView.subproj/WebLoader.m
  
  Index: WebLoader.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebLoader.m,v
  retrieving revision 1.84.2.1
  retrieving revision 1.84.2.2
  diff -u -r1.84.2.1 -r1.84.2.2
  --- WebLoader.m	2 Jun 2005 15:44:43 -0000	1.84.2.1
  +++ WebLoader.m	13 Jul 2005 05:26:08 -0000	1.84.2.2
  @@ -165,7 +165,7 @@
       }
   }
   
  -// This is copied from [NSHTTPURLProtocol _cachedResponsePassesValidityChecks] and modified for our needs.
  +// The following 2 methods are copied from [NSHTTPURLProtocol _cachedResponsePassesValidityChecks] and modified for our needs.
   // FIXME: It would be nice to eventually to share this code somehow.
   - (BOOL)_canUseResourceForRequest:(NSURLRequest *)theRequest
   {
  @@ -192,6 +192,17 @@
       }
   }
   
  +- (BOOL)_canUseResourceWithResponse:(NSURLResponse *)theResponse
  +{
  +    if ([theResponse _mustRevalidate]) {
  +        return NO;
  +    } else if ([theResponse _calculatedExpiration] - CFAbsoluteTimeGetCurrent() < 1) {
  +        return NO;
  +    } else {
  +        return YES;
  +    }
  +}
  +
   - (BOOL)loadWithRequest:(NSURLRequest *)r
   {
       ASSERT(connection == nil);
  @@ -216,11 +227,15 @@
       
       if ([[r URL] isEqual:originalURL] && [self _canUseResourceForRequest:r]) {
           resource = [dataSource subresourceForURL:originalURL];
  -        if (resource) {
  -            [resource retain];
  -            // Deliver the resource after a delay because callers don't expect to receive callbacks while calling this method.
  -            [self deliverResourceAfterDelay];
  -            return YES;
  +        if (resource != nil) {
  +            if ([self _canUseResourceWithResponse:[resource _response]]) {
  +                [resource retain];
  +                // Deliver the resource after a delay because callers don't expect to receive callbacks while calling this method.
  +                [self deliverResourceAfterDelay];
  +                return YES;
  +            } else {
  +                resource = nil;
  +            }
           }
       }
       
  @@ -306,15 +321,9 @@
       if (resource == nil) {
           NSData *data = [self resourceData];
           if ([data length] > 0) {
  -            // Don't have WebResource copy the data since the data is a NSMutableData that we know won't get modified. 
               ASSERT(originalURL);
               ASSERT([response MIMEType]);
  -            WebResource *newResource = [[WebResource alloc] _initWithData:data
  -                                                                      URL:originalURL
  -                                                                 MIMEType:[response MIMEType]
  -                                                         textEncodingName:[response textEncodingName]
  -                                                                frameName:nil
  -                                                                 copyData:NO];
  +            WebResource *newResource = [[WebResource alloc] _initWithData:data URL:originalURL response:response];
               if (newResource != nil) {
                   [dataSource addSubresource:newResource];
                   [newResource release];
  
  
  
  1.11.8.1  +61 -13    WebKit/WebView.subproj/WebResource.m
  
  Index: WebResource.m
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebResource.m,v
  retrieving revision 1.11
  retrieving revision 1.11.8.1
  diff -u -r1.11 -r1.11.8.1
  --- WebResource.m	6 Dec 2004 22:20:29 -0000	1.11
  +++ WebResource.m	13 Jul 2005 05:26:08 -0000	1.11.8.1
  @@ -14,6 +14,7 @@
   NSString *WebResourceMIMETypeKey =          @"WebResourceMIMEType";
   NSString *WebResourceURLKey =               @"WebResourceURL";
   NSString *WebResourceTextEncodingNameKey =  @"WebResourceTextEncodingName";
  +NSString *WebResourceResponseKey =          @"WebResourceResponse";
   
   #define WebResourceVersion 1
   
  @@ -25,6 +26,7 @@
       NSString *frameName;
       NSString *MIMEType;
       NSString *textEncodingName;
  +    NSURLResponse *response;
   }
   @end
   
  @@ -37,6 +39,7 @@
       [frameName release];
       [MIMEType release];
       [textEncodingName release];
  +    [response release];
       [super dealloc];
   }
   
  @@ -53,7 +56,7 @@
   
   - (id)initWithData:(NSData *)data URL:(NSURL *)URL MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName frameName:(NSString *)frameName
   {
  -    return [self _initWithData:data URL:URL MIMEType:MIMEType textEncodingName:textEncodingName frameName:frameName copyData:YES];
  +    return [self _initWithData:data URL:URL MIMEType:MIMEType textEncodingName:textEncodingName frameName:frameName response:nil copyData:YES];
   }
   
   - (id)initWithCoder:(NSCoder *)decoder
  @@ -65,6 +68,7 @@
           _private->MIMEType = [[decoder decodeObjectForKey:WebResourceMIMETypeKey] retain];
           _private->textEncodingName = [[decoder decodeObjectForKey:WebResourceTextEncodingNameKey] retain];
           _private->frameName = [[decoder decodeObjectForKey:WebResourceFrameNameKey] retain];
  +        _private->response = [[decoder decodeObjectForKey:WebResourceResponseKey] retain];
       NS_HANDLER
           [self release];
           return nil;
  @@ -78,7 +82,8 @@
       [encoder encodeObject:_private->URL forKey:WebResourceURLKey];
       [encoder encodeObject:_private->MIMEType forKey:WebResourceMIMETypeKey];
       [encoder encodeObject:_private->textEncodingName forKey:WebResourceTextEncodingNameKey];
  -    [encoder encodeObject:_private->frameName forKey:WebResourceFrameNameKey];    
  +    [encoder encodeObject:_private->frameName forKey:WebResourceFrameNameKey];
  +    [encoder encodeObject:_private->response forKey:WebResourceResponseKey];
   }
   
   - (void)dealloc
  @@ -155,7 +160,13 @@
       return propertyLists;
   }
   
  -- (id)_initWithData:(NSData *)data URL:(NSURL *)URL MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName frameName:(NSString *)frameName copyData:(BOOL)copyData
  +- (id)_initWithData:(NSData *)data 
  +                URL:(NSURL *)URL 
  +           MIMEType:(NSString *)MIMEType 
  +   textEncodingName:(NSString *)textEncodingName 
  +          frameName:(NSString *)frameName 
  +           response:(NSURLResponse *)response
  +           copyData:(BOOL)copyData
   {
       [self init];    
       
  @@ -179,23 +190,49 @@
       
       _private->textEncodingName = [textEncodingName copy];
       _private->frameName = [frameName copy];
  -    
  +    _private->response = [response retain];
  +        
       return self;
   }
   
  +- (id)_initWithData:(NSData *)data URL:(NSURL *)URL response:(NSURLResponse *)response
  +{
  +    // Pass NO for copyData since the data doesn't need to be copied since we know that callers will no longer modify it.
  +    // Copying it will also cause a performance regression.
  +    return [self _initWithData:data
  +                           URL:URL
  +                      MIMEType:[response MIMEType]
  +              textEncodingName:[response textEncodingName]
  +                     frameName:nil
  +                      response:response
  +                      copyData:NO];    
  +}
  +
   - (id)_initWithPropertyList:(id)propertyList
   {
       if (![propertyList isKindOfClass:[NSDictionary class]]) {
           [self release];
           return nil;
       }
  +    
  +    NSURLResponse *response = nil;
  +    NSData *responseData = [propertyList objectForKey:WebResourceResponseKey];
  +    if ([responseData isKindOfClass:[NSData class]]) {
  +        NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:responseData];
  +        response = [unarchiver decodeObjectForKey:WebResourceResponseKey];
  +        [unarchiver finishDecoding];
  +        [unarchiver release];    
  +    }
  +
       NSData *data = [propertyList objectForKey:WebResourceDataKey];
       NSString *URLString = [propertyList _web_stringForKey:WebResourceURLKey];
  -    return [self initWithData:[data isKindOfClass:[NSData class]] ? data : nil
  -                          URL:URLString ? [NSURL _web_URLWithDataAsString:URLString] : nil
  -                     MIMEType:[propertyList _web_stringForKey:WebResourceMIMETypeKey]
  -             textEncodingName:[propertyList _web_stringForKey:WebResourceTextEncodingNameKey]
  -                    frameName:[propertyList _web_stringForKey:WebResourceFrameNameKey]];
  +    return [self _initWithData:[data isKindOfClass:[NSData class]] ? data : nil
  +                           URL:URLString ? [NSURL _web_URLWithDataAsString:URLString] : nil
  +                      MIMEType:[propertyList _web_stringForKey:WebResourceMIMETypeKey]
  +              textEncodingName:[propertyList _web_stringForKey:WebResourceTextEncodingNameKey]
  +                     frameName:[propertyList _web_stringForKey:WebResourceFrameNameKey]
  +                      response:response
  +                      copyData:NO];
   }
   
   - (NSFileWrapper *)_fileWrapperRepresentation
  @@ -211,17 +248,29 @@
       [propertyList setObject:_private->data forKey:WebResourceDataKey];
       [propertyList setObject:[_private->URL _web_originalDataAsString] forKey:WebResourceURLKey];
       [propertyList setObject:_private->MIMEType forKey:WebResourceMIMETypeKey];
  -    if (_private->textEncodingName) {
  +    if (_private->textEncodingName != nil) {
           [propertyList setObject:_private->textEncodingName forKey:WebResourceTextEncodingNameKey];
       }
  -    if (_private->frameName) {
  +    if (_private->frameName != nil) {
           [propertyList setObject:_private->frameName forKey:WebResourceFrameNameKey];
  -    }
  +    }    
  +    if (_private->response != nil) {
  +        NSMutableData *responseData = [[NSMutableData alloc] init];
  +        NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:responseData];
  +        [archiver encodeObject:_private->response forKey:WebResourceResponseKey];
  +        [archiver finishEncoding];
  +        [archiver release];
  +        [propertyList setObject:responseData forKey:WebResourceResponseKey];
  +        [responseData release];
  +    }        
       return propertyList;
   }
   
   - (NSURLResponse *)_response
   {
  +    if (_private->response != nil) {
  +        return _private->response;
  +    }
       return [[[NSURLResponse alloc] initWithURL:_private->URL
                                         MIMEType:_private->MIMEType 
                            expectedContentLength:[_private->data length]
  @@ -240,4 +289,3 @@
   }
   
   @end
  -
  
  
  
  1.8.8.1   +9 -1      WebKit/WebView.subproj/WebResourcePrivate.h
  
  Index: WebResourcePrivate.h
  ===================================================================
  RCS file: /cvs/root/WebKit/WebView.subproj/WebResourcePrivate.h,v
  retrieving revision 1.8
  retrieving revision 1.8.8.1
  diff -u -r1.8 -r1.8.8.1
  --- WebResourcePrivate.h	6 Dec 2004 22:20:29 -0000	1.8
  +++ WebResourcePrivate.h	13 Jul 2005 05:26:08 -0000	1.8.8.1
  @@ -9,7 +9,15 @@
   
   @interface WebResource (WebResourcePrivate)
   
  -- (id)_initWithData:(NSData *)data URL:(NSURL *)URL MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName frameName:(NSString *)frameName copyData:(BOOL)copyData;
  +- (id)_initWithData:(NSData *)data 
  +                URL:(NSURL *)URL 
  +           MIMEType:(NSString *)MIMEType 
  +   textEncodingName:(NSString *)textEncodingName 
  +          frameName:(NSString *)frameName 
  +           response:(NSURLResponse *)response
  +           copyData:(BOOL)copyData;
  +
  +- (id)_initWithData:(NSData *)data URL:(NSURL *)URL response:(NSURLResponse *)response;
   
   + (NSArray *)_resourcesFromPropertyLists:(NSArray *)propertyLists;
   + (NSArray *)_propertyListsFromResources:(NSArray *)resources;
  
  
  



More information about the webkit-changes mailing list