[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

cblu cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 06:12:34 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit e7ce8ad681ffa8b186e2bf443ecc8f890f04ff46
Author: cblu <cblu at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue May 14 05:43:14 2002 +0000

            Added support for setting the content policy on the location change handler
            and data source at any time instead of depending on an immediate response.
    
            * WebView.subproj/IFBaseWebController.mm:
            (-[IFBaseWebController haveContentPolicy:andPath:forLocationChangeHandler:]):
            * WebView.subproj/IFMainURLHandleClient.h:
            * WebView.subproj/IFMainURLHandleClient.mm:
            (-[IFMainURLHandleClient initWithDataSource:part:]):
            (-[IFMainURLHandleClient dealloc]):
            (-[IFMainURLHandleClient setContentPolicy:]):
            (-[IFMainURLHandleClient IFURLHandleResourceDidFinishLoading:data:]):
            (-[IFMainURLHandleClient IFURLHandle:resourceDataDidBecomeAvailable:]):
            (-[IFMainURLHandleClient IFURLHandle:resourceDidFailLoadingWithResult:]):
            (-[IFMainURLHandleClient IFURLHandle:didRedirectToURL:]):
            (-[IFMainURLHandleClient processData:isComplete:]):
            * WebView.subproj/IFWebController.h:
            * WebView.subproj/IFWebDataSourcePrivate.mm:
            (-[IFWebDataSource _setContentPolicy:]):
            * WebView.subproj/IFWebFrame.mm:
            (-[IFWebFrame setProvisionalDataSource:]):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@1142 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog
index 2798b6a..8fe22d7 100644
--- a/WebKit/ChangeLog
+++ b/WebKit/ChangeLog
@@ -1,3 +1,26 @@
+2002-05-13  System Administrator  <cblu at apple.com>
+
+	Added support for setting the content policy on the location change handler
+	and data source at any time instead of depending on an immediate response.
+
+	* WebView.subproj/IFBaseWebController.mm:
+	(-[IFBaseWebController haveContentPolicy:andPath:forLocationChangeHandler:]):
+	* WebView.subproj/IFMainURLHandleClient.h:
+	* WebView.subproj/IFMainURLHandleClient.mm:
+	(-[IFMainURLHandleClient initWithDataSource:part:]):
+	(-[IFMainURLHandleClient dealloc]):
+	(-[IFMainURLHandleClient setContentPolicy:]):
+	(-[IFMainURLHandleClient IFURLHandleResourceDidFinishLoading:data:]):
+	(-[IFMainURLHandleClient IFURLHandle:resourceDataDidBecomeAvailable:]):
+	(-[IFMainURLHandleClient IFURLHandle:resourceDidFailLoadingWithResult:]):
+	(-[IFMainURLHandleClient IFURLHandle:didRedirectToURL:]):
+	(-[IFMainURLHandleClient processData:isComplete:]):
+	* WebView.subproj/IFWebController.h:
+	* WebView.subproj/IFWebDataSourcePrivate.mm:
+	(-[IFWebDataSource _setContentPolicy:]):
+	* WebView.subproj/IFWebFrame.mm:
+	(-[IFWebFrame setProvisionalDataSource:]):
+
 2002-05-13  Maciej Stachowiak  <mjs at apple.com>
 
 	* WebKitPrefix.h: Gratuitous change to make the prefix file
diff --git a/WebKit/ChangeLog-2002-12-03 b/WebKit/ChangeLog-2002-12-03
index 2798b6a..8fe22d7 100644
--- a/WebKit/ChangeLog-2002-12-03
+++ b/WebKit/ChangeLog-2002-12-03
@@ -1,3 +1,26 @@
+2002-05-13  System Administrator  <cblu at apple.com>
+
+	Added support for setting the content policy on the location change handler
+	and data source at any time instead of depending on an immediate response.
+
+	* WebView.subproj/IFBaseWebController.mm:
+	(-[IFBaseWebController haveContentPolicy:andPath:forLocationChangeHandler:]):
+	* WebView.subproj/IFMainURLHandleClient.h:
+	* WebView.subproj/IFMainURLHandleClient.mm:
+	(-[IFMainURLHandleClient initWithDataSource:part:]):
+	(-[IFMainURLHandleClient dealloc]):
+	(-[IFMainURLHandleClient setContentPolicy:]):
+	(-[IFMainURLHandleClient IFURLHandleResourceDidFinishLoading:data:]):
+	(-[IFMainURLHandleClient IFURLHandle:resourceDataDidBecomeAvailable:]):
+	(-[IFMainURLHandleClient IFURLHandle:resourceDidFailLoadingWithResult:]):
+	(-[IFMainURLHandleClient IFURLHandle:didRedirectToURL:]):
+	(-[IFMainURLHandleClient processData:isComplete:]):
+	* WebView.subproj/IFWebController.h:
+	* WebView.subproj/IFWebDataSourcePrivate.mm:
+	(-[IFWebDataSource _setContentPolicy:]):
+	* WebView.subproj/IFWebFrame.mm:
+	(-[IFWebFrame setProvisionalDataSource:]):
+
 2002-05-13  Maciej Stachowiak  <mjs at apple.com>
 
 	* WebKitPrefix.h: Gratuitous change to make the prefix file
diff --git a/WebKit/WebView.subproj/IFBaseWebController.mm b/WebKit/WebView.subproj/IFBaseWebController.mm
index ba568a9..bdf7f91 100644
--- a/WebKit/WebView.subproj/IFBaseWebController.mm
+++ b/WebKit/WebView.subproj/IFBaseWebController.mm
@@ -262,6 +262,9 @@
 {
     IFWebDataSource *mainDataSource, *mainProvisionalDataSource, *dataSource;
     
+    if(policy == IFContentPolicyNone)
+        [NSException raise:NSInvalidArgumentException format:@"Can't set policy of IFContentPolicyNone. Use IFContentPolicyIgnore instead"];
+        
     mainProvisionalDataSource = [_private->mainFrame provisionalDataSource];
     mainDataSource = [_private->mainFrame dataSource];
     
@@ -270,8 +273,12 @@
         dataSource = [mainProvisionalDataSource _recursiveDataSourceForLocationChangeHandler:handler];
         
     if(dataSource){
-        [dataSource _setContentPolicy:policy];
-        [dataSource _setDownloadPath:path];
+        if([dataSource contentPolicy] != IFContentPolicyNone){
+            [NSException raise:NSGenericException format:@"Content policy can only be set once on a location change handler."];
+        }else{
+            [dataSource _setContentPolicy:policy];
+            [dataSource _setDownloadPath:path];
+        }
     }
 }
 
diff --git a/WebKit/WebView.subproj/IFMainURLHandleClient.h b/WebKit/WebView.subproj/IFMainURLHandleClient.h
index 2e248c9..5db1b3f 100644
--- a/WebKit/WebView.subproj/IFMainURLHandleClient.h
+++ b/WebKit/WebView.subproj/IFMainURLHandleClient.h
@@ -7,6 +7,8 @@
 */
 
 #import <WebKit/IFMIMEHandler.h>
+#import <WebKit/IFLocationChangeHandler.h>
+#import <WebFoundation/IFURLHandle.h>
 
 @class IFDownloadHandler;
 @class IFWebDataSource;
@@ -18,11 +20,18 @@ class KHTMLPart;
 {
     id dataSource;
     KHTMLPart *part;
-    BOOL sentFakeDocForNonHTMLContentType, typeChecked, downloadStarted;
+    BOOL sentFakeDocForNonHTMLContentType, checkedMIMEType, downloadStarted, loadFinished, sentInitialData;
     IFMIMEHandler *mimeHandler;
     IFMIMEHandlerType handlerType;
     IFDownloadHandler *downloadHandler;
+    IFContentPolicy contentPolicy;
+    NSData *resourceData;
+    IFURLHandle *urlHandle;
 }
 - initWithDataSource: (IFWebDataSource *)ds part: (KHTMLPart *)p;
+- (void)setContentPolicy:(IFContentPolicy)theContentPolicy;
+
+- (void) processData:(NSData *)data isComplete:(BOOL)complete;
+- (void) finishProcessingData:(NSData *)data;
 @end
 
diff --git a/WebKit/WebView.subproj/IFMainURLHandleClient.mm b/WebKit/WebView.subproj/IFMainURLHandleClient.mm
index 2ce8264..0fd5fcf 100644
--- a/WebKit/WebView.subproj/IFMainURLHandleClient.mm
+++ b/WebKit/WebView.subproj/IFMainURLHandleClient.mm
@@ -22,7 +22,6 @@
 #import <WebKit/IFWebFramePrivate.h>
 
 #import <WebFoundation/IFError.h>
-#import <WebFoundation/IFURLHandle.h>
 
 #import <khtmlview.h>
 #import <khtml_part.h>
@@ -37,7 +36,10 @@
         part->ref();
         sentFakeDocForNonHTMLContentType = NO;
         downloadStarted = NO;
-        typeChecked = NO;
+        checkedMIMEType = NO;
+        loadFinished    = NO;
+        sentInitialData = NO;
+        contentPolicy = IFContentPolicyNone;
         return self;
     }
 
@@ -49,15 +51,28 @@
     part->deref();
     [dataSource release];
     [mimeHandler release];
+    [resourceData release];
+    [urlHandle release];
     [super dealloc];
 }
 
+// This method should never get called more than once.
+// Also, this method should never be passed a IFContentPolicyNone.
+- (void)setContentPolicy:(IFContentPolicy)theContentPolicy
+{
+    contentPolicy = theContentPolicy;
+    
+    if(loadFinished)
+        [self processData:resourceData isComplete:YES];
+}
+
 
 - (void)IFURLHandleResourceDidBeginLoading:(IFURLHandle *)sender
 {
     WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s\n", [[[sender url] absoluteString] cString]);
 }
 
+
 - (void)IFURLHandleResourceDidCancelLoading:(IFURLHandle *)sender
 {
     WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s\n", [[[sender url] absoluteString] cString]);
@@ -70,34 +85,21 @@
     [loadProgress release];
 }
 
+
 - (void)IFURLHandleResourceDidFinishLoading:(IFURLHandle *)sender data: (NSData *)data
 {
-    NSString *fakeHTMLDocument;
-    const char *fakeHTMLDocumentBytes;
-    IFContentHandler *contentHandler;
-
     WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s\n", [[[sender url] absoluteString] cString]);
     
-    if([dataSource contentPolicy] == IFContentPolicyShow){
-        if(handlerType == IFMIMEHANDLERTYPE_TEXT) {
-            contentHandler = [[IFContentHandler alloc] initWithMIMEHandler:mimeHandler URL:[sender url]];
-            fakeHTMLDocument = [contentHandler textHTMLDocumentBottom];
-            fakeHTMLDocumentBytes = [fakeHTMLDocument cString];
-            part->slotData(sender, (const char *)fakeHTMLDocumentBytes, strlen(fakeHTMLDocumentBytes));
-            [contentHandler release];
-        }
-    }
+    loadFinished = YES;
     
-    else if([dataSource contentPolicy] == IFContentPolicySave || 
-            [dataSource contentPolicy] == IFContentPolicyOpenExternally){
-        // FIXME [cblu]: We shouldn't wait for the download to end to write to the disk.
-        // Will fix once we there is an IFURLHandle flag to not memory cache 
-        [downloadHandler downloadCompletedWithData:[sender resourceData]];
-        [downloadHandler release];
-    }else if([dataSource contentPolicy] == IFContentPolicyNone){
-        // do something
+    if(contentPolicy != IFContentPolicyNone){
+        [self finishProcessingData:data];
+    }else{
+        // If the content policy hasn't been set, save the data until it has.
+        resourceData = [data retain];
     }
-
+    
+    // update progress
     IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
     loadProgress->totalToLoad = [data length];
     loadProgress->bytesSoFar = [data length];
@@ -106,58 +108,111 @@
     [loadProgress release];
 }
 
+
 - (void)IFURLHandle:(IFURLHandle *)sender resourceDataDidBecomeAvailable:(NSData *)data
 {
-    NSString *fakeHTMLDocument;
-    const char *fakeHTMLDocumentBytes;
-    IFContentHandler *contentHandler;
-    IFWebFrame *frame;
-    
     WEBKITDEBUGLEVEL(WEBKIT_LOG_LOADING, "url = %s, data = %p, length %d\n", [[[sender url] absoluteString] cString], data, [data length]);
     
-    // check the mime type
-    if(!typeChecked){
+    // Check the mime type and ask the client for the content policy.
+    // This only happens once.
+    if(!checkedMIMEType){
         WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD, "main content type: %s", [[sender contentType] cString]);
         [[dataSource _locationChangeHandler] requestContentPolicyForMIMEType:[sender contentType]];
+        
+        // FIXME: Remove/replace IFMIMEHandler stuff
         mimeHandler = [[[IFMIMEDatabase sharedMIMEDatabase] MIMEHandlerForMIMEType:[sender contentType]] retain];
         handlerType = [mimeHandler handlerType];
-        typeChecked = YES;
+        checkedMIMEType = YES;
+    }
+    
+    urlHandle = [sender retain];
+    
+    if(contentPolicy != IFContentPolicyNone && contentPolicy != IFContentPolicyIgnore){
+        if(!sentInitialData){
+            // process all data that has been received 
+            //[self processData:[sender resourceData] isComplete:NO];
+            
+            //FIXME: Need we still depend on the content policy being set immediately because of 2925907.
+            [self processData:data isComplete:NO]; 
+            sentInitialData = YES;
+        }else{
+            [self processData:data isComplete:NO];
+        }
     }
     
-    if([dataSource contentPolicy] == IFContentPolicyShow){
-        // if it's html, send the data to the part
-        // FIXME: [sender contentType] still returns nil if from cache
+    if(contentPolicy == IFContentPolicyIgnore){
+        [sender cancelLoadInBackground];
+    }
+    
+    // update progress
+    IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
+    loadProgress->totalToLoad = [sender contentLength];
+    loadProgress->bytesSoFar = [sender contentLengthReceived];
+    [(IFBaseWebController *)[dataSource controller] _mainReceivedProgress: (IFLoadProgress *)loadProgress 
+        forResource: [[sender url] absoluteString] fromDataSource: dataSource];
+    [loadProgress release];
+}
+
+
+- (void)IFURLHandle:(IFURLHandle *)sender resourceDidFailLoadingWithResult:(IFError *)result
+{
+    WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s, result = %s\n", [[[sender url] absoluteString] cString], [[result errorDescription] lossyCString]);
+
+    IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
+    loadProgress->totalToLoad = [sender contentLength];
+    loadProgress->bytesSoFar = [sender contentLengthReceived];
+
+    [(IFBaseWebController *)[dataSource controller] _mainReceivedError: result forResource: [[sender url] absoluteString] 	partialProgress: loadProgress fromDataSource: dataSource];
+}
+
+
+- (void)IFURLHandle:(IFURLHandle *)sender didRedirectToURL:(NSURL *)url
+{
+    WEBKITDEBUGLEVEL (WEBKIT_LOG_REDIRECT, "url = %s\n", [[url absoluteString] cString]);
+    part->setBaseURL([[url absoluteString] cString]);
+    
+    [dataSource _setFinalURL: url];
+    
+    [[dataSource _locationChangeHandler] serverRedirectTo: url forDataSource: dataSource];
+}
+
+
+- (void) processData:(NSData *)data isComplete:(BOOL)complete
+{
+    NSString *fakeHTMLDocument;
+    const char *fakeHTMLDocumentBytes;
+    IFContentHandler *contentHandler;
+    IFWebFrame *frame;
+        
+    if(contentPolicy == IFContentPolicyShow){
+        
         if(handlerType == IFMIMEHANDLERTYPE_NIL || handlerType == IFMIMEHANDLERTYPE_HTML) {
-            part->slotData(sender, (const char *)[data bytes], [data length]);
+            // If data is html, send it to the part.
+            part->slotData(urlHandle, (const char *)[data bytes], [data length]);
         }
         
-        // for non-html documents, create html doc that embeds them
         else if(handlerType == IFMIMEHANDLERTYPE_IMAGE  || 
                 handlerType == IFMIMEHANDLERTYPE_PLUGIN || 
                 handlerType == IFMIMEHANDLERTYPE_TEXT) {
+                
+            // For a non-html document, create html doc that embeds it.
             if (!sentFakeDocForNonHTMLContentType) {
-                contentHandler = [[IFContentHandler alloc] initWithMIMEHandler:mimeHandler URL:[sender url]];
+                contentHandler = [[IFContentHandler alloc] initWithMIMEHandler:mimeHandler URL:[urlHandle url]];
                 fakeHTMLDocument = [contentHandler HTMLDocument];
                 fakeHTMLDocumentBytes = [fakeHTMLDocument cString];
-                part->slotData(sender, (const char *)fakeHTMLDocumentBytes, strlen(fakeHTMLDocumentBytes));
+                part->slotData(urlHandle, (const char *)fakeHTMLDocumentBytes, strlen(fakeHTMLDocumentBytes));
                 [contentHandler release];
                 sentFakeDocForNonHTMLContentType = YES;
             }
             
-            // for text documents, the incoming data is part of the main page
+            // For text documents, the incoming data is part of the main page.
             if(handlerType == IFMIMEHANDLERTYPE_TEXT){
-                part->slotData(sender, (const char *)[data bytes], [data length]);
+                part->slotData(urlHandle, (const char *)[data bytes], [data length]);
             }
         }
-    
-        else if(handlerType == IFMIMEHANDLERTYPE_APPLICATION){
-            // can't show a type that we don't handle
-            [[dataSource _locationChangeHandler] unableToImplementContentPolicy:[IFError errorWithCode:IFCantShowMIMEType inDomain:IFErrorCodeDomainWebFoundation isTerminal:YES]];
-        }
     }
     
-    else if([dataSource contentPolicy] == IFContentPolicySave || 
-            [dataSource contentPolicy] == IFContentPolicyOpenExternally){
+    else if(contentPolicy == IFContentPolicySave || contentPolicy == IFContentPolicyOpenExternally){
             if(!downloadStarted){
             
                 // If this is a download, detach the provisionalDataSource from the frame
@@ -166,43 +221,39 @@
                 frame = [dataSource webFrame];
                 [frame->_private setProvisionalDataSource:nil];
                 
-                // go right to locationChangeDone as the data source never get committed.
+                // go right to locationChangeDone as the data source never gets committed.
                 [[dataSource _locationChangeHandler] locationChangeDone:nil];
                 downloadStarted = YES;
             }
-            WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD, "%d of %d", [sender contentLengthReceived], [sender contentLength]);
+            WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD, "%d of %d", [urlHandle contentLengthReceived], [urlHandle contentLength]);
     }
     
-    // update progress
-
-    IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
-    loadProgress->totalToLoad = [sender contentLength];
-    loadProgress->bytesSoFar = [sender contentLengthReceived];
-    [(IFBaseWebController *)[dataSource controller] _mainReceivedProgress: (IFLoadProgress *)loadProgress 
-        forResource: [[sender url] absoluteString] fromDataSource: dataSource];
-    [loadProgress release];
+    if(complete)
+        [self finishProcessingData:data];
 }
 
-- (void)IFURLHandle:(IFURLHandle *)sender resourceDidFailLoadingWithResult:(IFError *)result
+- (void) finishProcessingData:(NSData *)data;
 {
-    WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s, result = %s\n", [[[sender url] absoluteString] cString], [[result errorDescription] lossyCString]);
-
-    IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
-    loadProgress->totalToLoad = [sender contentLength];
-    loadProgress->bytesSoFar = [sender contentLengthReceived];
-
-    [(IFBaseWebController *)[dataSource controller] _mainReceivedError: result forResource: [[sender url] absoluteString] 	partialProgress: loadProgress fromDataSource: dataSource];
-}
-
-- (void)IFURLHandle:(IFURLHandle *)sender didRedirectToURL:(NSURL *)url
-{
-    WEBKITDEBUGLEVEL (WEBKIT_LOG_REDIRECT, "url = %s\n", [[url absoluteString] cString]);
-    part->setBaseURL([[url absoluteString] cString]);
+    NSString *fakeHTMLDocument;
+    const char *fakeHTMLDocumentBytes;
+    IFContentHandler *contentHandler;
     
-    [dataSource _setFinalURL: url];
+    if(contentPolicy == IFContentPolicyShow){
+        if(handlerType == IFMIMEHANDLERTYPE_TEXT) {
+            contentHandler = [[IFContentHandler alloc] initWithMIMEHandler:mimeHandler URL:[urlHandle url]];
+            fakeHTMLDocument = [contentHandler textHTMLDocumentBottom];
+            fakeHTMLDocumentBytes = [fakeHTMLDocument cString];
+            part->slotData(urlHandle, (const char *)fakeHTMLDocumentBytes, strlen(fakeHTMLDocumentBytes));
+            [contentHandler release];
+        }
+    }
     
-    [[dataSource _locationChangeHandler] serverRedirectTo: url forDataSource: dataSource];
+    else if(contentPolicy == IFContentPolicySave || contentPolicy == IFContentPolicyOpenExternally){
+        // FIXME [cblu]: We shouldn't wait for the download to end to write to the disk.
+        // Will fix once we there is an IFURLHandle flag to not cache in memory (2903660). 
+        [downloadHandler downloadCompletedWithData:data];
+        [downloadHandler release];
+    }
 }
 
-
 @end
diff --git a/WebKit/WebView.subproj/IFWebController.h b/WebKit/WebView.subproj/IFWebController.h
index 98dcaf0..92436e9 100644
--- a/WebKit/WebView.subproj/IFWebController.h
+++ b/WebKit/WebView.subproj/IFWebController.h
@@ -91,7 +91,6 @@
 */
 
 typedef enum {
-    IFURLPolicyNone,
     IFURLPolicyUseContentPolicy,
     IFURLPolicyOpenExternally,
     IFURLPolicyIgnore
diff --git a/WebKit/WebView.subproj/IFWebDataSourcePrivate.mm b/WebKit/WebView.subproj/IFWebDataSourcePrivate.mm
index f040f64..7c63f43 100644
--- a/WebKit/WebView.subproj/IFWebDataSourcePrivate.mm
+++ b/WebKit/WebView.subproj/IFWebDataSourcePrivate.mm
@@ -290,9 +290,13 @@
     _private->downloadPath = [path retain];
 }
 
+
+// This method should only be called by haveContentPolicy in IFBaseWebController
+// and should only be called once.
 - (void) _setContentPolicy:(IFContentPolicy)policy
 {
     _private->contentPolicy = policy;
+    [_private->mainURLHandleClient setContentPolicy:policy];
 }
 
 - (IFWebDataSource *) _recursiveDataSourceForLocationChangeHandler:(id <IFLocationChangeHandler>)handler;
diff --git a/WebKit/WebView.subproj/IFWebFrame.mm b/WebKit/WebView.subproj/IFWebFrame.mm
index f029bc3..1ba960f 100644
--- a/WebKit/WebView.subproj/IFWebFrame.mm
+++ b/WebKit/WebView.subproj/IFWebFrame.mm
@@ -156,6 +156,9 @@
         [IFDownloadHandler launchURL:[newDataSource inputURL]];
     }
     
+    // Do nothing in the IFURLPolicyIgnore case.
+    
+    //FIXME: When do we return NO?
     return YES;
 }
 
diff --git a/WebKit/WebView.subproj/WebController.h b/WebKit/WebView.subproj/WebController.h
index 98dcaf0..92436e9 100644
--- a/WebKit/WebView.subproj/WebController.h
+++ b/WebKit/WebView.subproj/WebController.h
@@ -91,7 +91,6 @@
 */
 
 typedef enum {
-    IFURLPolicyNone,
     IFURLPolicyUseContentPolicy,
     IFURLPolicyOpenExternally,
     IFURLPolicyIgnore
diff --git a/WebKit/WebView.subproj/WebDataSourcePrivate.m b/WebKit/WebView.subproj/WebDataSourcePrivate.m
index f040f64..7c63f43 100644
--- a/WebKit/WebView.subproj/WebDataSourcePrivate.m
+++ b/WebKit/WebView.subproj/WebDataSourcePrivate.m
@@ -290,9 +290,13 @@
     _private->downloadPath = [path retain];
 }
 
+
+// This method should only be called by haveContentPolicy in IFBaseWebController
+// and should only be called once.
 - (void) _setContentPolicy:(IFContentPolicy)policy
 {
     _private->contentPolicy = policy;
+    [_private->mainURLHandleClient setContentPolicy:policy];
 }
 
 - (IFWebDataSource *) _recursiveDataSourceForLocationChangeHandler:(id <IFLocationChangeHandler>)handler;
diff --git a/WebKit/WebView.subproj/WebFrame.m b/WebKit/WebView.subproj/WebFrame.m
index f029bc3..1ba960f 100644
--- a/WebKit/WebView.subproj/WebFrame.m
+++ b/WebKit/WebView.subproj/WebFrame.m
@@ -156,6 +156,9 @@
         [IFDownloadHandler launchURL:[newDataSource inputURL]];
     }
     
+    // Do nothing in the IFURLPolicyIgnore case.
+    
+    //FIXME: When do we return NO?
     return YES;
 }
 
diff --git a/WebKit/WebView.subproj/WebMainResourceClient.h b/WebKit/WebView.subproj/WebMainResourceClient.h
index 2e248c9..5db1b3f 100644
--- a/WebKit/WebView.subproj/WebMainResourceClient.h
+++ b/WebKit/WebView.subproj/WebMainResourceClient.h
@@ -7,6 +7,8 @@
 */
 
 #import <WebKit/IFMIMEHandler.h>
+#import <WebKit/IFLocationChangeHandler.h>
+#import <WebFoundation/IFURLHandle.h>
 
 @class IFDownloadHandler;
 @class IFWebDataSource;
@@ -18,11 +20,18 @@ class KHTMLPart;
 {
     id dataSource;
     KHTMLPart *part;
-    BOOL sentFakeDocForNonHTMLContentType, typeChecked, downloadStarted;
+    BOOL sentFakeDocForNonHTMLContentType, checkedMIMEType, downloadStarted, loadFinished, sentInitialData;
     IFMIMEHandler *mimeHandler;
     IFMIMEHandlerType handlerType;
     IFDownloadHandler *downloadHandler;
+    IFContentPolicy contentPolicy;
+    NSData *resourceData;
+    IFURLHandle *urlHandle;
 }
 - initWithDataSource: (IFWebDataSource *)ds part: (KHTMLPart *)p;
+- (void)setContentPolicy:(IFContentPolicy)theContentPolicy;
+
+- (void) processData:(NSData *)data isComplete:(BOOL)complete;
+- (void) finishProcessingData:(NSData *)data;
 @end
 
diff --git a/WebKit/WebView.subproj/WebMainResourceClient.m b/WebKit/WebView.subproj/WebMainResourceClient.m
index 2ce8264..0fd5fcf 100644
--- a/WebKit/WebView.subproj/WebMainResourceClient.m
+++ b/WebKit/WebView.subproj/WebMainResourceClient.m
@@ -22,7 +22,6 @@
 #import <WebKit/IFWebFramePrivate.h>
 
 #import <WebFoundation/IFError.h>
-#import <WebFoundation/IFURLHandle.h>
 
 #import <khtmlview.h>
 #import <khtml_part.h>
@@ -37,7 +36,10 @@
         part->ref();
         sentFakeDocForNonHTMLContentType = NO;
         downloadStarted = NO;
-        typeChecked = NO;
+        checkedMIMEType = NO;
+        loadFinished    = NO;
+        sentInitialData = NO;
+        contentPolicy = IFContentPolicyNone;
         return self;
     }
 
@@ -49,15 +51,28 @@
     part->deref();
     [dataSource release];
     [mimeHandler release];
+    [resourceData release];
+    [urlHandle release];
     [super dealloc];
 }
 
+// This method should never get called more than once.
+// Also, this method should never be passed a IFContentPolicyNone.
+- (void)setContentPolicy:(IFContentPolicy)theContentPolicy
+{
+    contentPolicy = theContentPolicy;
+    
+    if(loadFinished)
+        [self processData:resourceData isComplete:YES];
+}
+
 
 - (void)IFURLHandleResourceDidBeginLoading:(IFURLHandle *)sender
 {
     WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s\n", [[[sender url] absoluteString] cString]);
 }
 
+
 - (void)IFURLHandleResourceDidCancelLoading:(IFURLHandle *)sender
 {
     WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s\n", [[[sender url] absoluteString] cString]);
@@ -70,34 +85,21 @@
     [loadProgress release];
 }
 
+
 - (void)IFURLHandleResourceDidFinishLoading:(IFURLHandle *)sender data: (NSData *)data
 {
-    NSString *fakeHTMLDocument;
-    const char *fakeHTMLDocumentBytes;
-    IFContentHandler *contentHandler;
-
     WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s\n", [[[sender url] absoluteString] cString]);
     
-    if([dataSource contentPolicy] == IFContentPolicyShow){
-        if(handlerType == IFMIMEHANDLERTYPE_TEXT) {
-            contentHandler = [[IFContentHandler alloc] initWithMIMEHandler:mimeHandler URL:[sender url]];
-            fakeHTMLDocument = [contentHandler textHTMLDocumentBottom];
-            fakeHTMLDocumentBytes = [fakeHTMLDocument cString];
-            part->slotData(sender, (const char *)fakeHTMLDocumentBytes, strlen(fakeHTMLDocumentBytes));
-            [contentHandler release];
-        }
-    }
+    loadFinished = YES;
     
-    else if([dataSource contentPolicy] == IFContentPolicySave || 
-            [dataSource contentPolicy] == IFContentPolicyOpenExternally){
-        // FIXME [cblu]: We shouldn't wait for the download to end to write to the disk.
-        // Will fix once we there is an IFURLHandle flag to not memory cache 
-        [downloadHandler downloadCompletedWithData:[sender resourceData]];
-        [downloadHandler release];
-    }else if([dataSource contentPolicy] == IFContentPolicyNone){
-        // do something
+    if(contentPolicy != IFContentPolicyNone){
+        [self finishProcessingData:data];
+    }else{
+        // If the content policy hasn't been set, save the data until it has.
+        resourceData = [data retain];
     }
-
+    
+    // update progress
     IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
     loadProgress->totalToLoad = [data length];
     loadProgress->bytesSoFar = [data length];
@@ -106,58 +108,111 @@
     [loadProgress release];
 }
 
+
 - (void)IFURLHandle:(IFURLHandle *)sender resourceDataDidBecomeAvailable:(NSData *)data
 {
-    NSString *fakeHTMLDocument;
-    const char *fakeHTMLDocumentBytes;
-    IFContentHandler *contentHandler;
-    IFWebFrame *frame;
-    
     WEBKITDEBUGLEVEL(WEBKIT_LOG_LOADING, "url = %s, data = %p, length %d\n", [[[sender url] absoluteString] cString], data, [data length]);
     
-    // check the mime type
-    if(!typeChecked){
+    // Check the mime type and ask the client for the content policy.
+    // This only happens once.
+    if(!checkedMIMEType){
         WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD, "main content type: %s", [[sender contentType] cString]);
         [[dataSource _locationChangeHandler] requestContentPolicyForMIMEType:[sender contentType]];
+        
+        // FIXME: Remove/replace IFMIMEHandler stuff
         mimeHandler = [[[IFMIMEDatabase sharedMIMEDatabase] MIMEHandlerForMIMEType:[sender contentType]] retain];
         handlerType = [mimeHandler handlerType];
-        typeChecked = YES;
+        checkedMIMEType = YES;
+    }
+    
+    urlHandle = [sender retain];
+    
+    if(contentPolicy != IFContentPolicyNone && contentPolicy != IFContentPolicyIgnore){
+        if(!sentInitialData){
+            // process all data that has been received 
+            //[self processData:[sender resourceData] isComplete:NO];
+            
+            //FIXME: Need we still depend on the content policy being set immediately because of 2925907.
+            [self processData:data isComplete:NO]; 
+            sentInitialData = YES;
+        }else{
+            [self processData:data isComplete:NO];
+        }
     }
     
-    if([dataSource contentPolicy] == IFContentPolicyShow){
-        // if it's html, send the data to the part
-        // FIXME: [sender contentType] still returns nil if from cache
+    if(contentPolicy == IFContentPolicyIgnore){
+        [sender cancelLoadInBackground];
+    }
+    
+    // update progress
+    IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
+    loadProgress->totalToLoad = [sender contentLength];
+    loadProgress->bytesSoFar = [sender contentLengthReceived];
+    [(IFBaseWebController *)[dataSource controller] _mainReceivedProgress: (IFLoadProgress *)loadProgress 
+        forResource: [[sender url] absoluteString] fromDataSource: dataSource];
+    [loadProgress release];
+}
+
+
+- (void)IFURLHandle:(IFURLHandle *)sender resourceDidFailLoadingWithResult:(IFError *)result
+{
+    WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s, result = %s\n", [[[sender url] absoluteString] cString], [[result errorDescription] lossyCString]);
+
+    IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
+    loadProgress->totalToLoad = [sender contentLength];
+    loadProgress->bytesSoFar = [sender contentLengthReceived];
+
+    [(IFBaseWebController *)[dataSource controller] _mainReceivedError: result forResource: [[sender url] absoluteString] 	partialProgress: loadProgress fromDataSource: dataSource];
+}
+
+
+- (void)IFURLHandle:(IFURLHandle *)sender didRedirectToURL:(NSURL *)url
+{
+    WEBKITDEBUGLEVEL (WEBKIT_LOG_REDIRECT, "url = %s\n", [[url absoluteString] cString]);
+    part->setBaseURL([[url absoluteString] cString]);
+    
+    [dataSource _setFinalURL: url];
+    
+    [[dataSource _locationChangeHandler] serverRedirectTo: url forDataSource: dataSource];
+}
+
+
+- (void) processData:(NSData *)data isComplete:(BOOL)complete
+{
+    NSString *fakeHTMLDocument;
+    const char *fakeHTMLDocumentBytes;
+    IFContentHandler *contentHandler;
+    IFWebFrame *frame;
+        
+    if(contentPolicy == IFContentPolicyShow){
+        
         if(handlerType == IFMIMEHANDLERTYPE_NIL || handlerType == IFMIMEHANDLERTYPE_HTML) {
-            part->slotData(sender, (const char *)[data bytes], [data length]);
+            // If data is html, send it to the part.
+            part->slotData(urlHandle, (const char *)[data bytes], [data length]);
         }
         
-        // for non-html documents, create html doc that embeds them
         else if(handlerType == IFMIMEHANDLERTYPE_IMAGE  || 
                 handlerType == IFMIMEHANDLERTYPE_PLUGIN || 
                 handlerType == IFMIMEHANDLERTYPE_TEXT) {
+                
+            // For a non-html document, create html doc that embeds it.
             if (!sentFakeDocForNonHTMLContentType) {
-                contentHandler = [[IFContentHandler alloc] initWithMIMEHandler:mimeHandler URL:[sender url]];
+                contentHandler = [[IFContentHandler alloc] initWithMIMEHandler:mimeHandler URL:[urlHandle url]];
                 fakeHTMLDocument = [contentHandler HTMLDocument];
                 fakeHTMLDocumentBytes = [fakeHTMLDocument cString];
-                part->slotData(sender, (const char *)fakeHTMLDocumentBytes, strlen(fakeHTMLDocumentBytes));
+                part->slotData(urlHandle, (const char *)fakeHTMLDocumentBytes, strlen(fakeHTMLDocumentBytes));
                 [contentHandler release];
                 sentFakeDocForNonHTMLContentType = YES;
             }
             
-            // for text documents, the incoming data is part of the main page
+            // For text documents, the incoming data is part of the main page.
             if(handlerType == IFMIMEHANDLERTYPE_TEXT){
-                part->slotData(sender, (const char *)[data bytes], [data length]);
+                part->slotData(urlHandle, (const char *)[data bytes], [data length]);
             }
         }
-    
-        else if(handlerType == IFMIMEHANDLERTYPE_APPLICATION){
-            // can't show a type that we don't handle
-            [[dataSource _locationChangeHandler] unableToImplementContentPolicy:[IFError errorWithCode:IFCantShowMIMEType inDomain:IFErrorCodeDomainWebFoundation isTerminal:YES]];
-        }
     }
     
-    else if([dataSource contentPolicy] == IFContentPolicySave || 
-            [dataSource contentPolicy] == IFContentPolicyOpenExternally){
+    else if(contentPolicy == IFContentPolicySave || contentPolicy == IFContentPolicyOpenExternally){
             if(!downloadStarted){
             
                 // If this is a download, detach the provisionalDataSource from the frame
@@ -166,43 +221,39 @@
                 frame = [dataSource webFrame];
                 [frame->_private setProvisionalDataSource:nil];
                 
-                // go right to locationChangeDone as the data source never get committed.
+                // go right to locationChangeDone as the data source never gets committed.
                 [[dataSource _locationChangeHandler] locationChangeDone:nil];
                 downloadStarted = YES;
             }
-            WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD, "%d of %d", [sender contentLengthReceived], [sender contentLength]);
+            WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD, "%d of %d", [urlHandle contentLengthReceived], [urlHandle contentLength]);
     }
     
-    // update progress
-
-    IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
-    loadProgress->totalToLoad = [sender contentLength];
-    loadProgress->bytesSoFar = [sender contentLengthReceived];
-    [(IFBaseWebController *)[dataSource controller] _mainReceivedProgress: (IFLoadProgress *)loadProgress 
-        forResource: [[sender url] absoluteString] fromDataSource: dataSource];
-    [loadProgress release];
+    if(complete)
+        [self finishProcessingData:data];
 }
 
-- (void)IFURLHandle:(IFURLHandle *)sender resourceDidFailLoadingWithResult:(IFError *)result
+- (void) finishProcessingData:(NSData *)data;
 {
-    WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s, result = %s\n", [[[sender url] absoluteString] cString], [[result errorDescription] lossyCString]);
-
-    IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
-    loadProgress->totalToLoad = [sender contentLength];
-    loadProgress->bytesSoFar = [sender contentLengthReceived];
-
-    [(IFBaseWebController *)[dataSource controller] _mainReceivedError: result forResource: [[sender url] absoluteString] 	partialProgress: loadProgress fromDataSource: dataSource];
-}
-
-- (void)IFURLHandle:(IFURLHandle *)sender didRedirectToURL:(NSURL *)url
-{
-    WEBKITDEBUGLEVEL (WEBKIT_LOG_REDIRECT, "url = %s\n", [[url absoluteString] cString]);
-    part->setBaseURL([[url absoluteString] cString]);
+    NSString *fakeHTMLDocument;
+    const char *fakeHTMLDocumentBytes;
+    IFContentHandler *contentHandler;
     
-    [dataSource _setFinalURL: url];
+    if(contentPolicy == IFContentPolicyShow){
+        if(handlerType == IFMIMEHANDLERTYPE_TEXT) {
+            contentHandler = [[IFContentHandler alloc] initWithMIMEHandler:mimeHandler URL:[urlHandle url]];
+            fakeHTMLDocument = [contentHandler textHTMLDocumentBottom];
+            fakeHTMLDocumentBytes = [fakeHTMLDocument cString];
+            part->slotData(urlHandle, (const char *)fakeHTMLDocumentBytes, strlen(fakeHTMLDocumentBytes));
+            [contentHandler release];
+        }
+    }
     
-    [[dataSource _locationChangeHandler] serverRedirectTo: url forDataSource: dataSource];
+    else if(contentPolicy == IFContentPolicySave || contentPolicy == IFContentPolicyOpenExternally){
+        // FIXME [cblu]: We shouldn't wait for the download to end to write to the disk.
+        // Will fix once we there is an IFURLHandle flag to not cache in memory (2903660). 
+        [downloadHandler downloadCompletedWithData:data];
+        [downloadHandler release];
+    }
 }
 
-
 @end
diff --git a/WebKit/WebView.subproj/WebMainResourceLoader.h b/WebKit/WebView.subproj/WebMainResourceLoader.h
index 2e248c9..5db1b3f 100644
--- a/WebKit/WebView.subproj/WebMainResourceLoader.h
+++ b/WebKit/WebView.subproj/WebMainResourceLoader.h
@@ -7,6 +7,8 @@
 */
 
 #import <WebKit/IFMIMEHandler.h>
+#import <WebKit/IFLocationChangeHandler.h>
+#import <WebFoundation/IFURLHandle.h>
 
 @class IFDownloadHandler;
 @class IFWebDataSource;
@@ -18,11 +20,18 @@ class KHTMLPart;
 {
     id dataSource;
     KHTMLPart *part;
-    BOOL sentFakeDocForNonHTMLContentType, typeChecked, downloadStarted;
+    BOOL sentFakeDocForNonHTMLContentType, checkedMIMEType, downloadStarted, loadFinished, sentInitialData;
     IFMIMEHandler *mimeHandler;
     IFMIMEHandlerType handlerType;
     IFDownloadHandler *downloadHandler;
+    IFContentPolicy contentPolicy;
+    NSData *resourceData;
+    IFURLHandle *urlHandle;
 }
 - initWithDataSource: (IFWebDataSource *)ds part: (KHTMLPart *)p;
+- (void)setContentPolicy:(IFContentPolicy)theContentPolicy;
+
+- (void) processData:(NSData *)data isComplete:(BOOL)complete;
+- (void) finishProcessingData:(NSData *)data;
 @end
 
diff --git a/WebKit/WebView.subproj/WebMainResourceLoader.m b/WebKit/WebView.subproj/WebMainResourceLoader.m
index 2ce8264..0fd5fcf 100644
--- a/WebKit/WebView.subproj/WebMainResourceLoader.m
+++ b/WebKit/WebView.subproj/WebMainResourceLoader.m
@@ -22,7 +22,6 @@
 #import <WebKit/IFWebFramePrivate.h>
 
 #import <WebFoundation/IFError.h>
-#import <WebFoundation/IFURLHandle.h>
 
 #import <khtmlview.h>
 #import <khtml_part.h>
@@ -37,7 +36,10 @@
         part->ref();
         sentFakeDocForNonHTMLContentType = NO;
         downloadStarted = NO;
-        typeChecked = NO;
+        checkedMIMEType = NO;
+        loadFinished    = NO;
+        sentInitialData = NO;
+        contentPolicy = IFContentPolicyNone;
         return self;
     }
 
@@ -49,15 +51,28 @@
     part->deref();
     [dataSource release];
     [mimeHandler release];
+    [resourceData release];
+    [urlHandle release];
     [super dealloc];
 }
 
+// This method should never get called more than once.
+// Also, this method should never be passed a IFContentPolicyNone.
+- (void)setContentPolicy:(IFContentPolicy)theContentPolicy
+{
+    contentPolicy = theContentPolicy;
+    
+    if(loadFinished)
+        [self processData:resourceData isComplete:YES];
+}
+
 
 - (void)IFURLHandleResourceDidBeginLoading:(IFURLHandle *)sender
 {
     WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s\n", [[[sender url] absoluteString] cString]);
 }
 
+
 - (void)IFURLHandleResourceDidCancelLoading:(IFURLHandle *)sender
 {
     WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s\n", [[[sender url] absoluteString] cString]);
@@ -70,34 +85,21 @@
     [loadProgress release];
 }
 
+
 - (void)IFURLHandleResourceDidFinishLoading:(IFURLHandle *)sender data: (NSData *)data
 {
-    NSString *fakeHTMLDocument;
-    const char *fakeHTMLDocumentBytes;
-    IFContentHandler *contentHandler;
-
     WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s\n", [[[sender url] absoluteString] cString]);
     
-    if([dataSource contentPolicy] == IFContentPolicyShow){
-        if(handlerType == IFMIMEHANDLERTYPE_TEXT) {
-            contentHandler = [[IFContentHandler alloc] initWithMIMEHandler:mimeHandler URL:[sender url]];
-            fakeHTMLDocument = [contentHandler textHTMLDocumentBottom];
-            fakeHTMLDocumentBytes = [fakeHTMLDocument cString];
-            part->slotData(sender, (const char *)fakeHTMLDocumentBytes, strlen(fakeHTMLDocumentBytes));
-            [contentHandler release];
-        }
-    }
+    loadFinished = YES;
     
-    else if([dataSource contentPolicy] == IFContentPolicySave || 
-            [dataSource contentPolicy] == IFContentPolicyOpenExternally){
-        // FIXME [cblu]: We shouldn't wait for the download to end to write to the disk.
-        // Will fix once we there is an IFURLHandle flag to not memory cache 
-        [downloadHandler downloadCompletedWithData:[sender resourceData]];
-        [downloadHandler release];
-    }else if([dataSource contentPolicy] == IFContentPolicyNone){
-        // do something
+    if(contentPolicy != IFContentPolicyNone){
+        [self finishProcessingData:data];
+    }else{
+        // If the content policy hasn't been set, save the data until it has.
+        resourceData = [data retain];
     }
-
+    
+    // update progress
     IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
     loadProgress->totalToLoad = [data length];
     loadProgress->bytesSoFar = [data length];
@@ -106,58 +108,111 @@
     [loadProgress release];
 }
 
+
 - (void)IFURLHandle:(IFURLHandle *)sender resourceDataDidBecomeAvailable:(NSData *)data
 {
-    NSString *fakeHTMLDocument;
-    const char *fakeHTMLDocumentBytes;
-    IFContentHandler *contentHandler;
-    IFWebFrame *frame;
-    
     WEBKITDEBUGLEVEL(WEBKIT_LOG_LOADING, "url = %s, data = %p, length %d\n", [[[sender url] absoluteString] cString], data, [data length]);
     
-    // check the mime type
-    if(!typeChecked){
+    // Check the mime type and ask the client for the content policy.
+    // This only happens once.
+    if(!checkedMIMEType){
         WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD, "main content type: %s", [[sender contentType] cString]);
         [[dataSource _locationChangeHandler] requestContentPolicyForMIMEType:[sender contentType]];
+        
+        // FIXME: Remove/replace IFMIMEHandler stuff
         mimeHandler = [[[IFMIMEDatabase sharedMIMEDatabase] MIMEHandlerForMIMEType:[sender contentType]] retain];
         handlerType = [mimeHandler handlerType];
-        typeChecked = YES;
+        checkedMIMEType = YES;
+    }
+    
+    urlHandle = [sender retain];
+    
+    if(contentPolicy != IFContentPolicyNone && contentPolicy != IFContentPolicyIgnore){
+        if(!sentInitialData){
+            // process all data that has been received 
+            //[self processData:[sender resourceData] isComplete:NO];
+            
+            //FIXME: Need we still depend on the content policy being set immediately because of 2925907.
+            [self processData:data isComplete:NO]; 
+            sentInitialData = YES;
+        }else{
+            [self processData:data isComplete:NO];
+        }
     }
     
-    if([dataSource contentPolicy] == IFContentPolicyShow){
-        // if it's html, send the data to the part
-        // FIXME: [sender contentType] still returns nil if from cache
+    if(contentPolicy == IFContentPolicyIgnore){
+        [sender cancelLoadInBackground];
+    }
+    
+    // update progress
+    IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
+    loadProgress->totalToLoad = [sender contentLength];
+    loadProgress->bytesSoFar = [sender contentLengthReceived];
+    [(IFBaseWebController *)[dataSource controller] _mainReceivedProgress: (IFLoadProgress *)loadProgress 
+        forResource: [[sender url] absoluteString] fromDataSource: dataSource];
+    [loadProgress release];
+}
+
+
+- (void)IFURLHandle:(IFURLHandle *)sender resourceDidFailLoadingWithResult:(IFError *)result
+{
+    WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s, result = %s\n", [[[sender url] absoluteString] cString], [[result errorDescription] lossyCString]);
+
+    IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
+    loadProgress->totalToLoad = [sender contentLength];
+    loadProgress->bytesSoFar = [sender contentLengthReceived];
+
+    [(IFBaseWebController *)[dataSource controller] _mainReceivedError: result forResource: [[sender url] absoluteString] 	partialProgress: loadProgress fromDataSource: dataSource];
+}
+
+
+- (void)IFURLHandle:(IFURLHandle *)sender didRedirectToURL:(NSURL *)url
+{
+    WEBKITDEBUGLEVEL (WEBKIT_LOG_REDIRECT, "url = %s\n", [[url absoluteString] cString]);
+    part->setBaseURL([[url absoluteString] cString]);
+    
+    [dataSource _setFinalURL: url];
+    
+    [[dataSource _locationChangeHandler] serverRedirectTo: url forDataSource: dataSource];
+}
+
+
+- (void) processData:(NSData *)data isComplete:(BOOL)complete
+{
+    NSString *fakeHTMLDocument;
+    const char *fakeHTMLDocumentBytes;
+    IFContentHandler *contentHandler;
+    IFWebFrame *frame;
+        
+    if(contentPolicy == IFContentPolicyShow){
+        
         if(handlerType == IFMIMEHANDLERTYPE_NIL || handlerType == IFMIMEHANDLERTYPE_HTML) {
-            part->slotData(sender, (const char *)[data bytes], [data length]);
+            // If data is html, send it to the part.
+            part->slotData(urlHandle, (const char *)[data bytes], [data length]);
         }
         
-        // for non-html documents, create html doc that embeds them
         else if(handlerType == IFMIMEHANDLERTYPE_IMAGE  || 
                 handlerType == IFMIMEHANDLERTYPE_PLUGIN || 
                 handlerType == IFMIMEHANDLERTYPE_TEXT) {
+                
+            // For a non-html document, create html doc that embeds it.
             if (!sentFakeDocForNonHTMLContentType) {
-                contentHandler = [[IFContentHandler alloc] initWithMIMEHandler:mimeHandler URL:[sender url]];
+                contentHandler = [[IFContentHandler alloc] initWithMIMEHandler:mimeHandler URL:[urlHandle url]];
                 fakeHTMLDocument = [contentHandler HTMLDocument];
                 fakeHTMLDocumentBytes = [fakeHTMLDocument cString];
-                part->slotData(sender, (const char *)fakeHTMLDocumentBytes, strlen(fakeHTMLDocumentBytes));
+                part->slotData(urlHandle, (const char *)fakeHTMLDocumentBytes, strlen(fakeHTMLDocumentBytes));
                 [contentHandler release];
                 sentFakeDocForNonHTMLContentType = YES;
             }
             
-            // for text documents, the incoming data is part of the main page
+            // For text documents, the incoming data is part of the main page.
             if(handlerType == IFMIMEHANDLERTYPE_TEXT){
-                part->slotData(sender, (const char *)[data bytes], [data length]);
+                part->slotData(urlHandle, (const char *)[data bytes], [data length]);
             }
         }
-    
-        else if(handlerType == IFMIMEHANDLERTYPE_APPLICATION){
-            // can't show a type that we don't handle
-            [[dataSource _locationChangeHandler] unableToImplementContentPolicy:[IFError errorWithCode:IFCantShowMIMEType inDomain:IFErrorCodeDomainWebFoundation isTerminal:YES]];
-        }
     }
     
-    else if([dataSource contentPolicy] == IFContentPolicySave || 
-            [dataSource contentPolicy] == IFContentPolicyOpenExternally){
+    else if(contentPolicy == IFContentPolicySave || contentPolicy == IFContentPolicyOpenExternally){
             if(!downloadStarted){
             
                 // If this is a download, detach the provisionalDataSource from the frame
@@ -166,43 +221,39 @@
                 frame = [dataSource webFrame];
                 [frame->_private setProvisionalDataSource:nil];
                 
-                // go right to locationChangeDone as the data source never get committed.
+                // go right to locationChangeDone as the data source never gets committed.
                 [[dataSource _locationChangeHandler] locationChangeDone:nil];
                 downloadStarted = YES;
             }
-            WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD, "%d of %d", [sender contentLengthReceived], [sender contentLength]);
+            WEBKITDEBUGLEVEL(WEBKIT_LOG_DOWNLOAD, "%d of %d", [urlHandle contentLengthReceived], [urlHandle contentLength]);
     }
     
-    // update progress
-
-    IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
-    loadProgress->totalToLoad = [sender contentLength];
-    loadProgress->bytesSoFar = [sender contentLengthReceived];
-    [(IFBaseWebController *)[dataSource controller] _mainReceivedProgress: (IFLoadProgress *)loadProgress 
-        forResource: [[sender url] absoluteString] fromDataSource: dataSource];
-    [loadProgress release];
+    if(complete)
+        [self finishProcessingData:data];
 }
 
-- (void)IFURLHandle:(IFURLHandle *)sender resourceDidFailLoadingWithResult:(IFError *)result
+- (void) finishProcessingData:(NSData *)data;
 {
-    WEBKITDEBUGLEVEL (WEBKIT_LOG_LOADING, "url = %s, result = %s\n", [[[sender url] absoluteString] cString], [[result errorDescription] lossyCString]);
-
-    IFLoadProgress *loadProgress = [[IFLoadProgress alloc] init];
-    loadProgress->totalToLoad = [sender contentLength];
-    loadProgress->bytesSoFar = [sender contentLengthReceived];
-
-    [(IFBaseWebController *)[dataSource controller] _mainReceivedError: result forResource: [[sender url] absoluteString] 	partialProgress: loadProgress fromDataSource: dataSource];
-}
-
-- (void)IFURLHandle:(IFURLHandle *)sender didRedirectToURL:(NSURL *)url
-{
-    WEBKITDEBUGLEVEL (WEBKIT_LOG_REDIRECT, "url = %s\n", [[url absoluteString] cString]);
-    part->setBaseURL([[url absoluteString] cString]);
+    NSString *fakeHTMLDocument;
+    const char *fakeHTMLDocumentBytes;
+    IFContentHandler *contentHandler;
     
-    [dataSource _setFinalURL: url];
+    if(contentPolicy == IFContentPolicyShow){
+        if(handlerType == IFMIMEHANDLERTYPE_TEXT) {
+            contentHandler = [[IFContentHandler alloc] initWithMIMEHandler:mimeHandler URL:[urlHandle url]];
+            fakeHTMLDocument = [contentHandler textHTMLDocumentBottom];
+            fakeHTMLDocumentBytes = [fakeHTMLDocument cString];
+            part->slotData(urlHandle, (const char *)fakeHTMLDocumentBytes, strlen(fakeHTMLDocumentBytes));
+            [contentHandler release];
+        }
+    }
     
-    [[dataSource _locationChangeHandler] serverRedirectTo: url forDataSource: dataSource];
+    else if(contentPolicy == IFContentPolicySave || contentPolicy == IFContentPolicyOpenExternally){
+        // FIXME [cblu]: We shouldn't wait for the download to end to write to the disk.
+        // Will fix once we there is an IFURLHandle flag to not cache in memory (2903660). 
+        [downloadHandler downloadCompletedWithData:data];
+        [downloadHandler release];
+    }
 }
 
-
 @end
diff --git a/WebKit/WebView.subproj/WebView.h b/WebKit/WebView.subproj/WebView.h
index 98dcaf0..92436e9 100644
--- a/WebKit/WebView.subproj/WebView.h
+++ b/WebKit/WebView.subproj/WebView.h
@@ -91,7 +91,6 @@
 */
 
 typedef enum {
-    IFURLPolicyNone,
     IFURLPolicyUseContentPolicy,
     IFURLPolicyOpenExternally,
     IFURLPolicyIgnore

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list