Reviewed by Brady.
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Aug 2006 07:09:26 +0000 (07:09 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Aug 2006 07:09:26 +0000 (07:09 +0000)
        - remove WebKit dependencies from WebSubresourceLoader, except WebFormDataStream

        (WebFormDataStream will be moved into the Loader directory soon)

        * Loader/WebFrameLoader.h:
        * Loader/WebFrameLoader.m:
        (-[WebFrameLoader _addExtraFieldsToRequest:mainResource:alwaysFromRequest:]):
        * Loader/WebSubresourceLoader.m:
        (isConditionalRequest):
        (hasCaseInsensitivePrefix):
        (isFileURLString):
        (setHTTPReferrer):
        (+[WebSubresourceLoader startLoadingResource:withRequest:customHeaders:referrer:forFrameLoader:]):

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

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

index c68e3689a1c9dbe372271b3c140d48de43c53de3..d173079c89fc069911c848c9d270d476a58ffdb9 100644 (file)
@@ -1,3 +1,21 @@
+2006-08-13  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Brady.
+        
+        - remove WebKit dependencies from WebSubresourceLoader, except WebFormDataStream
+        
+        (WebFormDataStream will be moved into the Loader directory soon)
+
+        * Loader/WebFrameLoader.h:
+        * Loader/WebFrameLoader.m:
+        (-[WebFrameLoader _addExtraFieldsToRequest:mainResource:alwaysFromRequest:]):
+        * Loader/WebSubresourceLoader.m:
+        (isConditionalRequest):
+        (hasCaseInsensitivePrefix):
+        (isFileURLString):
+        (setHTTPReferrer):
+        (+[WebSubresourceLoader startLoadingResource:withRequest:customHeaders:referrer:forFrameLoader:]):
+
 2006-08-13  Brady Eidson  <beidson@apple.com>
 
         Reviewed by Maciej
index e4ab4466cb8fbe578127f937ab33e5585f5fcf31..8777e03fcac2a61c7f9ab09b3de2eba13cbf9282 100644 (file)
 - (void)deliverArchivedResourcesAfterDelay;
 - (void)cancelPendingArchiveLoadForLoader:(WebLoader *)loader;
 - (void)clearArchivedResources;
+- (void)_addExtraFieldsToRequest:(NSMutableURLRequest *)request mainResource:(BOOL)mainResource alwaysFromRequest:(BOOL)f;
 
 @end
index 8a240a54445998f94ca3f47142322bde77b9cc01..0de4a35d4912f0a112f2b1f7c8e480a76104f9f6 100644 (file)
@@ -644,4 +644,9 @@ static BOOL isCaseInsensitiveEqual(NSString *a, NSString *b)
         [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(deliverArchivedResources) object:nil];
 }
 
+- (void)_addExtraFieldsToRequest:(NSMutableURLRequest *)request mainResource:(BOOL)mainResource alwaysFromRequest:(BOOL)f
+{
+    [webFrame _addExtraFieldsToRequest:request mainResource:mainResource alwaysFromRequest:f];
+}
+
 @end
index 3ffa4aece85935580e1fb01c4f5ef9eba003bdad..13d2e8bcb4b0a22acbcfcb5a7e962876f7f7b949 100644 (file)
 #import <WebKit/WebSubresourceLoader.h>
 
 #import <JavaScriptCore/Assertions.h>
-#import <WebKit/WebDataSourceInternal.h>
-#import <WebKit/WebFormDataStream.h>
-#import <WebKit/WebFrameInternal.h>
-#import <WebKit/WebFrameLoader.h>
-#import <WebKit/WebKitErrorsPrivate.h>
-#import <WebKit/WebNSURLRequestExtras.h>
-
 #import <Foundation/NSURLResponse.h>
-
 #import <WebCore/WebCoreResourceLoader.h>
-#import <WebKitSystemInterface.h>
+#import <WebKit/WebFormDataStream.h>
+#import <WebKit/WebFrameLoader.h>
 
 @implementation WebSubresourceLoader
 
     [super dealloc];
 }
 
+static BOOL isConditionalRequest(NSURLRequest *request)
+{
+    if ([request valueForHTTPHeaderField:@"If-Match"] ||
+        [request valueForHTTPHeaderField:@"If-Modified-Since"] ||
+        [request valueForHTTPHeaderField:@"If-None-Match"] ||
+        [request valueForHTTPHeaderField:@"If-Range"] ||
+        [request valueForHTTPHeaderField:@"If-Unmodified-Since"])
+        return YES;
+    return NO;
+}
+
+static BOOL hasCaseInsensitivePrefix(NSString *str, NSString *prefix)
+{
+    return str && ([str rangeOfString:prefix options:(NSCaseInsensitiveSearch | NSAnchoredSearch)].location != NSNotFound);
+}
+
+static BOOL isFileURLString(NSString *URL)
+{
+    return hasCaseInsensitivePrefix(URL, @"file:");
+}
+
+#define WebReferrer     (@"Referer")
+
+static void setHTTPReferrer(NSMutableURLRequest *request, NSString *theReferrer)
+{
+    // Do not set the referrer to a string that refers to a file URL.
+    // That is a potential security hole.
+    if (isFileURLString(theReferrer))
+        return;
+    
+    // Don't allow empty Referer: headers; some servers refuse them
+    if([theReferrer length] == 0)
+        theReferrer = nil;
+    
+    [request setValue:theReferrer forHTTPHeaderField:WebReferrer];
+}
+
 + (WebSubresourceLoader *)startLoadingResource:(id <WebCoreResourceLoader>)rLoader
                                    withRequest:(NSMutableURLRequest *)newRequest
                                  customHeaders:(NSDictionary *)customHeaders
     // 2. Delegates that modify the cache policy using willSendRequest: should
     //    not affect any other resources. Such changes need to be done
     //    per request.
-    if ([newRequest _web_isConditionalRequest])
+    if (isConditionalRequest(newRequest))
         [newRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
     else
         [newRequest setCachePolicy:[[fl _originalRequest] cachePolicy]];
-    [newRequest _web_setHTTPReferrer:referrer];
+    setHTTPReferrer(newRequest, referrer);
     
-    [[fl webFrame] _addExtraFieldsToRequest:newRequest mainResource:NO alwaysFromRequest:NO];
+    [fl _addExtraFieldsToRequest:newRequest mainResource:NO alwaysFromRequest:NO];
             
     if (![loader loadWithRequest:newRequest])
         loader = nil;