Reviewed by Adele (preliminary version) and later by Kevin.
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Aug 2006 03:53:18 +0000 (03:53 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 16 Aug 2006 03:53:18 +0000 (03:53 +0000)
        - remove most WebKit dependencies from WebMainResourceLoader.

        * Loader/WebFrameLoader.h:
        * Loader/WebFrameLoader.m:
        (-[WebFrameLoader cannotShowMIMETypeForURL:]):
        (-[WebFrameLoader interruptForPolicyChangeErrorWithRequest:]):
        (-[WebFrameLoader isHostedByObjectElement]):
        (-[WebFrameLoader isLoadingMainFrame]):
        (+[WebFrameLoader _canShowMIMEType:]):
        (+[WebFrameLoader _representationExistsForURLScheme:]):
        (+[WebFrameLoader _generatedMIMETypeForURLScheme:]):
        * Loader/WebMainResourceLoader.h:
        * Loader/WebMainResourceLoader.m:
        (-[WebMainResourceLoader interruptForPolicyChangeError]):
        (-[WebMainResourceLoader willSendRequest:redirectResponse:]):
        (isCaseInsensitiveEqual):
        (shouldLoadAsEmptyDocument):
        (-[WebMainResourceLoader continueAfterContentPolicy:response:]):
        (-[WebMainResourceLoader didReceiveResponse:]):
        (-[WebMainResourceLoader didReceiveData:lengthReceived:allAtOnce:]):
        (-[WebMainResourceLoader didFinishLoading]):
        (-[WebMainResourceLoader loadWithRequestNow:]):
        (-[WebMainResourceLoader loadWithRequest:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@15903 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/ChangeLog
WebKit/Loader/WebFrameLoader.h
WebKit/Loader/WebFrameLoader.m
WebKit/Loader/WebMainResourceLoader.h
WebKit/Loader/WebMainResourceLoader.m

index 3c7373373fb309ec3ae49894810bac2c7d8fd76d..5276def8abdca27ae1667859360d531529ea8f97 100644 (file)
@@ -1,3 +1,31 @@
+2006-08-15  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Adele (preliminary version) and later by Kevin.
+        
+        - remove most WebKit dependencies from WebMainResourceLoader.
+
+        * Loader/WebFrameLoader.h:
+        * Loader/WebFrameLoader.m:
+        (-[WebFrameLoader cannotShowMIMETypeForURL:]):
+        (-[WebFrameLoader interruptForPolicyChangeErrorWithRequest:]):
+        (-[WebFrameLoader isHostedByObjectElement]):
+        (-[WebFrameLoader isLoadingMainFrame]):
+        (+[WebFrameLoader _canShowMIMEType:]):
+        (+[WebFrameLoader _representationExistsForURLScheme:]):
+        (+[WebFrameLoader _generatedMIMETypeForURLScheme:]):
+        * Loader/WebMainResourceLoader.h:
+        * Loader/WebMainResourceLoader.m:
+        (-[WebMainResourceLoader interruptForPolicyChangeError]):
+        (-[WebMainResourceLoader willSendRequest:redirectResponse:]):
+        (isCaseInsensitiveEqual):
+        (shouldLoadAsEmptyDocument):
+        (-[WebMainResourceLoader continueAfterContentPolicy:response:]):
+        (-[WebMainResourceLoader didReceiveResponse:]):
+        (-[WebMainResourceLoader didReceiveData:lengthReceived:allAtOnce:]):
+        (-[WebMainResourceLoader didFinishLoading]):
+        (-[WebMainResourceLoader loadWithRequestNow:]):
+        (-[WebMainResourceLoader loadWithRequest:]):
+
 2006-08-15  Tim Omernick  <timo@apple.com>
 
         Reviewed by Kevin Decker.
index bb77325d7df2f7ac4841f80c859eef1fb15aecf4..3def63719b436a58e07f95c9dced9ec8efdb1c8e 100644 (file)
 - (void)cancelPendingArchiveLoadForLoader:(WebLoader *)loader;
 - (void)clearArchivedResources;
 - (void)_addExtraFieldsToRequest:(NSMutableURLRequest *)request mainResource:(BOOL)mainResource alwaysFromRequest:(BOOL)f;
-
+- (void)cannotShowMIMETypeForURL:(NSURL *)URL;
+- (NSError *)interruptForPolicyChangeErrorWithRequest:(NSURLRequest *)request;
+- (BOOL)isHostedByObjectElement;
+- (BOOL)isLoadingMainFrame;
++ (BOOL)_canShowMIMEType:(NSString *)MIMEType;
++ (BOOL)_representationExistsForURLScheme:(NSString *)URLScheme;
++ (NSString *)_generatedMIMETypeForURLScheme:(NSString *)URLScheme;
+                                                                                                      
 @end
index ae282b9d12eea83c5c6e0c08073190c0c4a5ed77..43620ab8ed777d3d70e70a091ae8bb87ee81ab50 100644 (file)
@@ -37,6 +37,7 @@
 #import <WebKit/WebViewInternal.h>
 #import <WebKit/WebKitErrorsPrivate.h>
 #import <WebKit/WebResourcePrivate.h>
+#import <WebKit/DOMHTML.h>
 
 @implementation WebFrameLoader
 
@@ -656,4 +657,41 @@ static BOOL isCaseInsensitiveEqual(NSString *a, NSString *b)
     [webFrame _addExtraFieldsToRequest:request mainResource:mainResource alwaysFromRequest:f];
 }
 
+- (void)cannotShowMIMETypeForURL:(NSURL *)URL
+{
+    [webFrame _handleUnimplementablePolicyWithErrorCode:WebKitErrorCannotShowMIMEType forURL:URL];    
+}
+
+- (NSError *)interruptForPolicyChangeErrorWithRequest:(NSURLRequest *)request
+{
+    return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorFrameLoadInterruptedByPolicyChange URL:[request URL]];
+}
+
+- (BOOL)isHostedByObjectElement
+{
+    // Handle <object> fallback for error cases.            
+    DOMHTMLElement *hostElement = [webFrame frameElement];
+    return hostElement && [hostElement isKindOfClass:[DOMHTMLObjectElement class]];
+}
+
+- (BOOL)isLoadingMainFrame
+{
+    return [webFrame _isMainFrame];
+}
+
++ (BOOL)_canShowMIMEType:(NSString *)MIMEType
+{
+    return [WebDataSource _canShowMIMEType:MIMEType];
+}
+
++ (BOOL)_representationExistsForURLScheme:(NSString *)URLScheme
+{
+    return [WebDataSource _representationExistsForURLScheme:URLScheme];
+}
+
++ (NSString *)_generatedMIMETypeForURLScheme:(NSString *)URLScheme
+{
+    return [WebDataSource _generatedMIMETypeForURLScheme:URLScheme];
+}
+
 @end
index 794c3162bcccb09af9dde247d27d2d26e63fa353..b46dbdd852750e4b127fcdc5214e397e878e844b 100644 (file)
@@ -32,7 +32,6 @@
 #import <WebKitSystemInterface.h>
 
 @class WebPolicyDecisionListener;
-@class WebDataSource;
 
 @interface WebMainResourceLoader : WebLoader
 {
index 0c90ffad06a3c0f040f15222beb5ea8c8057c310..7090e89ef8186d7452f4f56d79cc7c6551805f28 100644 (file)
 #import <Foundation/NSURLConnection.h>
 #import <Foundation/NSURLRequest.h>
 #import <Foundation/NSURLResponse.h>
+#import <JavaScriptCore/Assertions.h>
 
-#import <WebKit/DOMHTML.h>
 #import <WebKit/WebDataProtocol.h>
-#import <WebKit/WebDataSourceInternal.h>
-#import <WebKit/WebDocument.h>
-#import <WebKit/WebFrameView.h>
-#import <WebKit/WebFrameLoader.h>
-#import <WebKit/WebFrameInternal.h>
-#import <WebKit/WebKitErrors.h>
-#import <WebKit/WebKitErrorsPrivate.h>
-#import <WebKit/WebKitLogging.h>
-#import <WebKit/WebKitNSStringExtras.h>
-#import <WebKit/WebNSObjectExtras.h>
 #import <WebKit/WebNSURLExtras.h>
-#import <WebKit/WebViewInternal.h>
+#import <WebKit/WebFrameLoader.h>
 
 // FIXME: More that is in common with WebSubresourceLoader should move up into WebLoader.
 
 
 - (NSError *)interruptForPolicyChangeError
 {
-    return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorFrameLoadInterruptedByPolicyChange URL:[request URL]];
+    return [frameLoader interruptForPolicyChangeErrorWithRequest:request];
 }
 
 -(void)stopLoadingForPolicyChange
 
     NSURL *URL = [newRequest URL];
 
-    LOG(Redirect, "URL = %@", URL);
-
     NSMutableURLRequest *mutableRequest = nil;
     // Update cookie policy base URL as URL changes, except for subframes, which use the
     // URL of the main frame which doesn't change when we redirect.
-    if ([[frameLoader webFrame] _isMainFrame]) {
+    if ([frameLoader isLoadingMainFrame]) {
         mutableRequest = [newRequest mutableCopy];
         [mutableRequest setMainDocumentURL:URL];
     }
     return newRequest;
 }
 
+static BOOL isCaseInsensitiveEqual(NSString *a, NSString *b)
+{
+    return [a caseInsensitiveCompare:b] == NSOrderedSame;
+}
+
+#define URL_BYTES_BUFFER_LENGTH 2048
+
+static BOOL shouldLoadAsEmptyDocument(NSURL *url)
+{
+    UInt8 *buffer = (UInt8 *)malloc(URL_BYTES_BUFFER_LENGTH);
+    CFIndex bytesFilled = CFURLGetBytes((CFURLRef)url, buffer, URL_BYTES_BUFFER_LENGTH);
+    if (bytesFilled == -1) {
+        CFIndex bytesToAllocate = CFURLGetBytes((CFURLRef)url, NULL, 0);
+        buffer = (UInt8 *)realloc(buffer, bytesToAllocate);
+        bytesFilled = CFURLGetBytes((CFURLRef)url, buffer, bytesToAllocate);
+        ASSERT(bytesFilled == bytesToAllocate);
+    }
+    
+    BOOL result = (bytesFilled == 0) || (bytesFilled > 5 && strncmp((char *)buffer, "about:", 6) == 0);
+    free(buffer);
+
+    return result;
+}
+
 -(void)continueAfterContentPolicy:(WebPolicyAction)contentPolicy response:(NSURLResponse *)r
 {
     NSURL *URL = [request URL];
     {
         // Prevent remote web archives from loading because they can claim to be from any domain and thus avoid cross-domain security checks (4120255).
         BOOL isRemote = ![URL isFileURL] && ![WebDataProtocol _webIsDataProtocolURL:URL];
-        BOOL isRemoteWebArchive = isRemote && [MIMEType _webkit_isCaseInsensitiveEqualToString:@"application/x-webarchive"];
-        if (![WebDataSource _canShowMIMEType:MIMEType] || isRemoteWebArchive) {
-            [[frameLoader webFrame] _handleUnimplementablePolicyWithErrorCode:WebKitErrorCannotShowMIMEType forURL:URL];
+        BOOL isRemoteWebArchive = isRemote && isCaseInsensitiveEqual(@"application/x-webarchive", MIMEType);
+        if (![WebFrameLoader _canShowMIMEType:MIMEType] || isRemoteWebArchive) {
+            [frameLoader cannotShowMIMETypeForURL:URL];
             // Check reachedTerminalState since the load may have already been cancelled inside of _handleUnimplementablePolicyWithErrorCode::.
             if (!reachedTerminalState) {
                 [self stopLoadingForPolicyChange];
     if ([r isKindOfClass:[NSHTTPURLResponse class]]) {
         int status = [(NSHTTPURLResponse *)r statusCode];
         if (status < 200 || status >= 300) {
-            // Handle <object> fallback for error cases.
-            DOMHTMLElement *hostElement = [[frameLoader webFrame] frameElement];
+            BOOL hostedByObject = [frameLoader isHostedByObjectElement];
+
             [frameLoader _handleFallbackContent];
-            if (hostElement && [hostElement isKindOfClass:[DOMHTMLObjectElement class]])
-                // object elements are no longer rendered after we fallback, so don't
-                // keep trying to process data from their load
+            // object elements are no longer rendered after we fallback, so don't
+            // keep trying to process data from their load
+
+            if (hostedByObject)
                 [self cancel];
         }
     }
         [super didReceiveResponse:r];
     }
 
-    if (![frameLoader _isStopping] && ([URL _webkit_shouldLoadAsEmptyDocument] || [WebView _representationExistsForURLScheme:[URL scheme]])) {
+    if (![frameLoader _isStopping] && (shouldLoadAsEmptyDocument(URL) || [WebFrameLoader _representationExistsForURLScheme:[URL scheme]])) {
         [self didFinishLoading];
     }
     
 
 - (void)didReceiveResponse:(NSURLResponse *)r
 {
-    ASSERT([[r URL] _webkit_shouldLoadAsEmptyDocument] || ![self defersCallbacks]);
-    ASSERT([[r URL] _webkit_shouldLoadAsEmptyDocument] || ![frameLoader _defersCallbacks]);
+    ASSERT(shouldLoadAsEmptyDocument([r URL]) || ![self defersCallbacks]);
+    ASSERT(shouldLoadAsEmptyDocument([r URL]) || ![frameLoader _defersCallbacks]);
 
-    LOG(Loading, "main content type: %@", [r MIMEType]);
-    
     if (loadingMultipartContent) {
         [frameLoader _setupForReplaceByMIMEType:[r MIMEType]];
         [self clearResourceData];
     if ([[r MIMEType] isEqualToString:@"multipart/x-mixed-replace"])
         loadingMultipartContent = YES;
         
-    // FIXME: This is a workaround to make web archive files work with Foundations that
-    // are too old to know about web archive files. We should remove this before we ship.
-    NSURL *URL = [r URL];
-    if ([[[URL path] pathExtension] _webkit_isCaseInsensitiveEqualToString:@"webarchive"]) {
-        r = [[[NSURLResponse alloc] initWithURL:URL 
-                                       MIMEType:@"application/x-webarchive"
-                          expectedContentLength:[r expectedContentLength] 
-                               textEncodingName:[r textEncodingName]] autorelease];
-    }
-    
     // retain/release self in this delegate method since the additional processing can do
     // anything including possibly releasing self; one example of this is 3266216
     [self retain];
     ASSERT(![self defersCallbacks]);
     ASSERT(![frameLoader _defersCallbacks]);
  
-    LOG(Loading, "URL = %@, data = %p, length %d", [frameLoader _URL], data, [data length]);
-
     // retain/release self in this delegate method since the additional processing can do
     // anything including possibly releasing self; one example of this is 3266216
     [self retain];
     [super didReceiveData:data lengthReceived:lengthReceived allAtOnce:allAtOnce];
     _bytesReceived += [data length];
 
-    LOG(Loading, "%d of %d", _bytesReceived, _contentLength);
     [self release];
 }
 
 - (void)didFinishLoading
 {
-    ASSERT([[frameLoader _URL] _webkit_shouldLoadAsEmptyDocument] || ![self defersCallbacks]);
-    ASSERT([[frameLoader _URL] _webkit_shouldLoadAsEmptyDocument] || ![frameLoader _defersCallbacks]);
+    ASSERT(shouldLoadAsEmptyDocument([frameLoader _URL]) || ![self defersCallbacks]);
+    ASSERT(shouldLoadAsEmptyDocument([frameLoader _URL]) || ![frameLoader _defersCallbacks]);
 
-    LOG(Loading, "URL = %@", [frameLoader _URL]);
-        
     // Calls in this method will most likely result in a call to release, so we must retain.
     [self retain];
 
 
 - (NSURLRequest *)loadWithRequestNow:(NSURLRequest *)r
 {
-    BOOL shouldLoadEmptyBeforeRedirect = [[r URL] _webkit_shouldLoadAsEmptyDocument];
+    BOOL shouldLoadEmptyBeforeRedirect = shouldLoadAsEmptyDocument([r URL]);
 
     ASSERT(connection == nil);
     ASSERT(shouldLoadEmptyBeforeRedirect || ![self defersCallbacks]);
     // initial requests.
     r = [self willSendRequest:r redirectResponse:nil];
     NSURL *URL = [r URL];
-    BOOL shouldLoadEmpty = [URL _webkit_shouldLoadAsEmptyDocument];
+    BOOL shouldLoadEmpty = shouldLoadAsEmptyDocument(URL);
 
     if (shouldLoadEmptyBeforeRedirect && !shouldLoadEmpty && [self defersCallbacks]) {
         return r;
     }
 
-    if (shouldLoadEmpty || [WebDataSource _representationExistsForURLScheme:[URL scheme]]) {
+    if (shouldLoadEmpty || [WebFrameLoader _representationExistsForURLScheme:[URL scheme]]) {
         NSString *MIMEType;
         if (shouldLoadEmpty) {
             MIMEType = @"text/html";
         } else {
-            MIMEType = [WebDataSource _generatedMIMETypeForURLScheme:[URL scheme]];
+            MIMEType = [WebFrameLoader _generatedMIMETypeForURLScheme:[URL scheme]];
         }
 
         NSURLResponse *resp = [[NSURLResponse alloc] initWithURL:URL MIMEType:MIMEType
     BOOL defer = [self defersCallbacks];
     if (defer) {
         NSURL *URL = [r URL];
-        BOOL shouldLoadEmpty = [URL _webkit_shouldLoadAsEmptyDocument];
+        BOOL shouldLoadEmpty = shouldLoadAsEmptyDocument(URL);
         if (shouldLoadEmpty) {
             defer = NO;
         }