Reviewed by Darin.
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jan 2007 14:15:23 +0000 (14:15 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Jan 2007 14:15:23 +0000 (14:15 +0000)
        - move WebDataProtocol load handling from ResourceLoader to MainResourceLoader

        (it's only ever used for main resources)

        * loader/ResourceLoader.h:
        (WebCore::ResourceLoader::setRequest):
        * loader/mac/MainResourceLoaderMac.mm:
        (WebCore::MainResourceLoader::willSendRequest):
        (WebCore::MainResourceLoader::continueAfterContentPolicy):
        * loader/mac/ResourceLoaderMac.mm:
        (WebCore::ResourceLoader::willSendRequest):
        (WebCore::ResourceLoader::didReceiveResponse):

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

WebCore/ChangeLog
WebCore/loader/ResourceLoader.h
WebCore/loader/mac/MainResourceLoaderMac.mm
WebCore/loader/mac/ResourceLoaderMac.mm

index a915bc128400e8ca1e50154885a628fb8255c308..3dddabf11693940224e1e0aea41a5f8e2e967a28 100644 (file)
@@ -1,3 +1,20 @@
+2007-01-09  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Darin.
+
+        - move WebDataProtocol load handling from ResourceLoader to MainResourceLoader
+        
+        (it's only ever used for main resources)
+
+        * loader/ResourceLoader.h:
+        (WebCore::ResourceLoader::setRequest):
+        * loader/mac/MainResourceLoaderMac.mm:
+        (WebCore::MainResourceLoader::willSendRequest):
+        (WebCore::MainResourceLoader::continueAfterContentPolicy):
+        * loader/mac/ResourceLoaderMac.mm:
+        (WebCore::ResourceLoader::willSendRequest):
+        (WebCore::ResourceLoader::didReceiveResponse):
+
 2007-01-09  Rob Buis  <buis@kde.org>
 
         Reviewed by Eric.
index 4640b2d61410cdf8a3fa20502f50bcc32bb4006f..983fe3a86c85c1bfaa413d79eafe5319e2eabc16 100644 (file)
@@ -142,6 +142,7 @@ namespace WebCore {
         void didFinishLoadingOnePart();
 
         const ResourceRequest& request() const { return m_request; }
+        void setRequest(const ResourceRequest& request) { m_request = request; }
 #endif
         bool reachedTerminalState() const { return m_reachedTerminalState; }
         bool cancelled() const { return m_cancelled; }
index 2dd6c7cb5bb6eef4fe801e3dbab4e14bd1adb145..57f54d06536c7c9ec07092a30383ac77c7d89877 100644 (file)
@@ -168,6 +168,14 @@ void MainResourceLoader::willSendRequest(ResourceRequest& newRequest, const Reso
     if (newRequest.cachePolicy() == UseProtocolCachePolicy && isPostOrRedirectAfterPost(newRequest, redirectResponse))
         newRequest.setCachePolicy(ReloadIgnoringCacheData);
 
+#if PLATFORM(MAC)
+    ResourceRequest r([newRequest.nsURLRequest() _webDataRequestExternalRequest]);
+    if (!r.isNull()) {
+        ResourceLoader::willSendRequest(r, redirectResponse);
+        if (request() == r)
+            setRequest(newRequest);
+    } else
+#endif
     ResourceLoader::willSendRequest(newRequest, redirectResponse);
     
     // Don't set this on the first request. It is set when the main load was started.
@@ -235,8 +243,17 @@ void MainResourceLoader::continueAfterContentPolicy(PolicyAction contentPolicy,
     }
 
     // we may have cancelled this load as part of switching to fallback content
-    if (!reachedTerminalState())
+    if (!reachedTerminalState()) {
+#if PLATFORM(MAC) 
+        // If the URL is one of our whacky applewebdata URLs then
+        // fake up a substitute URL to present to the delegate.
+        if ([WebDataProtocol _webIsDataProtocolURL:[r.nsURLResponse() URL]]) 
+            ResourceLoader::didReceiveResponse([[[NSURLResponse alloc] initWithURL:[request().nsURLRequest() _webDataRequestExternalURL] MIMEType:r.mimeType()
+                                                 expectedContentLength:r.expectedContentLength() textEncodingName:r.textEncodingName()] autorelease]);
+        else
+#endif
         ResourceLoader::didReceiveResponse(r);
+    }
 
     if (frameLoader() && !frameLoader()->isStopping()
             && (shouldLoadAsEmptyDocument(url)
index 6c4a6708458223c76d4cf8a8b9a33710561acebd..59eccdff60dd9d5d35b4e9d5dc498f938256d0e3 100644 (file)
@@ -38,7 +38,6 @@
 #import "ResourceResponse.h"
 #import "SharedBuffer.h"
 #import "WebCoreSystemInterface.h"
-#import "WebDataProtocol.h"
 #import <Foundation/NSURLAuthenticationChallenge.h>
 #import <Foundation/NSURLConnection.h>
 #import <Foundation/NSURLRequest.h>
@@ -150,7 +149,7 @@ void ResourceLoader::clearResourceData()
     m_resourceData->clear();
 }
 
-void ResourceLoader::willSendRequest(ResourceRequest& newRequest, const ResourceResponse& redirectResponse)
+void ResourceLoader::willSendRequest(ResourceRequest& request, const ResourceResponse& redirectResponse)
 {
     // Protect this in this delegate method since the additional processing can do
     // anything including possibly derefing this; one example of this is Radar 3266216.
@@ -158,43 +157,13 @@ void ResourceLoader::willSendRequest(ResourceRequest& newRequest, const Resource
         
     ASSERT(!m_reachedTerminalState);
     
-    // If we have a special "applewebdata" scheme URL we send a fake request to the delegate.
-    bool haveDataSchemeRequest = false;
-    ResourceRequest clientRequest;
-    
-#if PLATFORM(MAC)
-    clientRequest = [newRequest.nsURLRequest() _webDataRequestExternalRequest];
-#endif
-    
-    if (!clientRequest.isNull())
-        haveDataSchemeRequest = true;
-    else
-       clientRequest = newRequest;
-    
     if (!m_identifier)
-        m_identifier = frameLoader()->identifierForInitialRequest(clientRequest);
+        m_identifier = frameLoader()->identifierForInitialRequest(request);
     
-    ResourceRequest updatedRequest(clientRequest);
+    ResourceRequest updatedRequest(request);
     frameLoader()->willSendRequest(this, updatedRequest, redirectResponse);
-    
-    if (!haveDataSchemeRequest)
-        newRequest = updatedRequest;
-    else {
-        // If the delegate modified the request use that instead of
-        // our applewebdata request, otherwise use the original
-        // applewebdata request.
-        if (updatedRequest != clientRequest) {
-            newRequest = updatedRequest;
-            
-            if ([newRequest.nsURLRequest() isKindOfClass:[NSMutableURLRequest class]]) {
-                NSMutableURLRequest *mr = (NSMutableURLRequest *)newRequest.nsURLRequest();
-                [NSURLProtocol _removePropertyForKey:[NSURLRequest _webDataRequestPropertyKey] inRequest:mr];
-            }
-        }
-    }
-    
-    // Store a copy of the request.
-    m_request = newRequest;
+
+    m_request = updatedRequest;
 }
 
 void ResourceLoader::didReceiveAuthenticationChallenge(NSURLAuthenticationChallenge *challenge)
@@ -238,15 +207,7 @@ void ResourceLoader::didReceiveResponse(const ResourceResponse& r)
     // anything including possibly derefing this; one example of this is Radar 3266216.
     RefPtr<ResourceLoader> protector(this);
 
-#if PLATFORM(MAC) 
-    // If the URL is one of our whacky applewebdata URLs then
-    // fake up a substitute URL to present to the delegate.
-    if ([WebDataProtocol _webIsDataProtocolURL:[r.nsURLResponse() URL]]) 
-        m_response = [[[NSURLResponse alloc] initWithURL:[m_request.nsURLRequest() _webDataRequestExternalURL] MIMEType:r.mimeType()
-                                   expectedContentLength:r.expectedContentLength() textEncodingName:r.textEncodingName()] autorelease];
-    else
-#endif
-        m_response = r;
+    m_response = r;
 
     frameLoader()->didReceiveResponse(this, m_response);
 }