WebCore:
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Feb 2008 19:42:28 +0000 (19:42 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Feb 2008 19:42:28 +0000 (19:42 +0000)
        Reviewed by Darin.

        WARNING: NO TEST CASES ADDED OR CHANGED

        * ChangeLog:
        * WebCore.base.exp:
        * loader/mac/LoaderNSURLExtras.h:
        * loader/mac/LoaderNSURLExtras.m:
        Move unused functions to WebKit (where they are used)

        (vectorContainsString):
        Use const references.

        * platform/mac/WebCoreSystemInterface.h:
        * platform/mac/WebCoreSystemInterface.mm:
        Remove wkNSURLProtocolClassForReqest.

WebKit/mac:

        Reviewed by Darin.

        Move back WebKit methods that were unused in WebCore.

        * Misc/WebNSURLExtras.mm:
        (+[NSURL _web_URLWithData:]):
        (+[NSURL _web_URLWithData:relativeToURL:]):
        (-[NSURL _web_originalData]):
        (-[NSURL _web_originalDataAsString]):
        (-[NSURL _web_isEmpty]):
        (-[NSURL _webkit_canonicalize]):
        (-[NSURL _webkit_URLByRemovingComponent:]):
        (-[NSURL _webkit_URLByRemovingFragment]):
        (-[NSURL _webkit_URLByRemovingResourceSpecifier]):
        (-[NSURL _webkit_isFileURL]):
        (-[NSString _webkit_isFileURL]):
        * WebCoreSupport/WebFrameLoaderClient.mm:
        (WebFrameLoaderClient::setTitle):
        * WebCoreSupport/WebSystemInterface.m:
        (InitWebCoreSystemInterface):

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

WebCore/ChangeLog
WebCore/WebCore.base.exp
WebCore/loader/mac/LoaderNSURLExtras.h
WebCore/loader/mac/LoaderNSURLExtras.m
WebCore/platform/mac/WebCoreSystemInterface.h
WebCore/platform/mac/WebCoreSystemInterface.mm
WebKit/mac/ChangeLog
WebKit/mac/Misc/WebNSURLExtras.mm
WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm
WebKit/mac/WebCoreSupport/WebSystemInterface.m

index 304f3bd62f07876674a7d6e37ab51dfd5d46b0d4..049fe47e241eda859fd3e1a6d3dca383e9372017 100644 (file)
@@ -1,3 +1,22 @@
+2008-02-19  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Darin.
+
+        WARNING: NO TEST CASES ADDED OR CHANGED
+
+        * ChangeLog:
+        * WebCore.base.exp:
+        * loader/mac/LoaderNSURLExtras.h:
+        * loader/mac/LoaderNSURLExtras.m:
+        Move unused functions to WebKit (where they are used)
+        
+        (vectorContainsString):
+        Use const references.
+        
+        * platform/mac/WebCoreSystemInterface.h:
+        * platform/mac/WebCoreSystemInterface.mm:
+        Remove wkNSURLProtocolClassForReqest.
+        
 2008-02-19  Justin Garcia  <justin.garcia@apple.com>
 
         Reviewed by Darin Adler.
index d00d8256d88b020bd148482727d9032d3dfa4431..1b5cf3245904100d62bc24b67aa625deedaf5616 100644 (file)
@@ -704,21 +704,10 @@ __ZNK7WebCore9Selection17isContentEditableEv
 __ZNK7WebCore9Selection23isContentRichlyEditableEv
 __ZNK7WebCore9Selection7toRangeEv
 __ZNK7WebCore9TimerBase8isActiveEv
-_canonicalURL
 _filenameByFixingIllegalCharacters
 _hasCaseInsensitiveSubstring
 _hasCaseInsensitiveSuffix
-_stringIsFileURL
 _suggestedFilenameWithMIMEType
-_urlByRemovingComponent
-_urlByRemovingFragment
-_urlByRemovingResourceSpecifier
-_urlIsEmpty
-_urlIsFileURL
-_urlOriginalData
-_urlOriginalDataAsString
-_urlWithData
-_urlWithDataRelativeToURL
 _wkCGContextGetShouldSmoothFonts
 _wkClearGlyphVector
 _wkConvertCharToGlyphs
@@ -759,7 +748,6 @@ _wkGetNSURLResponseMustRevalidate
 _wkGetPreferredExtensionForMIMEType
 _wkGetWheelEventDeltas
 _wkInitializeGlyphVector
-_wkNSURLProtocolClassForReqest
 _wkPathFromFont
 _wkPopupMenu
 _wkQTMovieDataRate
index 39ef2226b93eb2665f30b94f4df144ea5e3ddbef..ce5a4909d36dd7331d1ff5b0f4efa2976040d4a0 100644 (file)
 extern "C" {
 #endif
 
-NSURL *urlByRemovingComponent(NSURL *url, CFURLComponentType component);
-NSURL *urlByRemovingFragment(NSURL *url);
-NSString *urlOriginalDataAsString(NSURL *url);
-NSData *urlOriginalData(NSURL *url);
-NSURL *urlWithData(NSData *data);
-NSURL *urlWithDataRelativeToURL(NSData *data, NSURL *baseURL);
-NSURL *urlByRemovingResourceSpecifier(NSURL *url);
-BOOL urlIsFileURL(NSURL *url);
-BOOL stringIsFileURL(NSString *urlString);
-BOOL urlIsEmpty(NSURL *url);
-NSURL *canonicalURL(NSURL *url);
 NSString *suggestedFilenameWithMIMEType(NSURL *url, NSString *MIMEType);
 
 #ifdef __cplusplus
index 8960c2fa73eb15bf8517115cb6840e8754c14226..dd4c7d26cab0b6bd12ec0ce9a8061ee0a7856546 100644 (file)
 
 using namespace WebCore;
 
-NSURL *urlByRemovingComponent(NSURL *url, CFURLComponentType component)
-{
-    if (!url)
-        return nil;
-
-    CFRange fragRg = CFURLGetByteRangeForComponent((CFURLRef)url, component, NULL);
-    // Check to see if a fragment exists before decomposing the URL.
-    if (fragRg.location == kCFNotFound)
-        return url;
-
-    UInt8 *urlBytes, buffer[2048];
-    CFIndex numBytes = CFURLGetBytes((CFURLRef)url, buffer, 2048);
-    if (numBytes == -1) {
-        numBytes = CFURLGetBytes((CFURLRef)url, NULL, 0);
-        urlBytes = static_cast<UInt8*>(malloc(numBytes));
-        CFURLGetBytes((CFURLRef)url, urlBytes, numBytes);
-    } else
-        urlBytes = buffer;
-    
-    NSURL *result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, fragRg.location - 1, kCFStringEncodingUTF8, NULL));
-    if (!result)
-        result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, fragRg.location - 1, kCFStringEncodingISOLatin1, NULL));
-    
-    if (urlBytes != buffer) free(urlBytes);
-    return result ? [result autorelease] : url;
-}
-
-NSURL *urlByRemovingFragment(NSURL *url)
-{
-    return urlByRemovingComponent(url, kCFURLComponentFragment);
-}
-
-NSString *urlOriginalDataAsString(NSURL *url)
-{
-    return [[[NSString alloc] initWithData:urlOriginalData(url) encoding:NSISOLatin1StringEncoding] autorelease];
-}
-
-#define URL_BYTES_BUFFER_LENGTH 2048
-
-NSData *urlOriginalData(NSURL *url)
-{
-    if (!url)
-        return nil;
-
-    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);
-    }
-    
-    // buffer is adopted by the NSData
-    NSData *data = [NSData dataWithBytesNoCopy:buffer length:bytesFilled freeWhenDone:YES];
-    
-    NSURL *baseURL = (NSURL *)CFURLGetBaseURL((CFURLRef)url);
-    if (baseURL)
-        return urlOriginalData(urlWithDataRelativeToURL(data, baseURL));
-    return data;
-}
-
-NSURL *urlWithData(NSData *data)
-{
-    if (data == nil)
-        return nil;
-
-    return urlWithDataRelativeToURL(data, nil);
-}      
-
-static inline id WebCFAutorelease(CFTypeRef obj)
-{
-    if (obj)
-        CFMakeCollectable(obj);
-    [(id)obj autorelease];
-    return (id)obj;
-}
-
-NSURL *urlWithDataRelativeToURL(NSData *data, NSURL *baseURL)
-{
-    if (data == nil)
-        return nil;
-    
-    NSURL *result = nil;
-    size_t length = [data length];
-    if (length > 0) {
-        // work around <rdar://4470771>: CFURLCreateAbsoluteURLWithBytes(.., TRUE) doesn't remove non-path components.
-        baseURL = urlByRemovingResourceSpecifier(baseURL);
-        
-        const UInt8 *bytes = static_cast<const UInt8*>([data bytes]);
-        // NOTE: We use UTF-8 here since this encoding is used when computing strings when returning URL components
-        // (e.g calls to NSURL -path). However, this function is not tolerant of illegal UTF-8 sequences, which
-        // could either be a malformed string or bytes in a different encoding, like shift-jis, so we fall back
-        // onto using ISO Latin 1 in those cases.
-        result = WebCFAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingUTF8, (CFURLRef)baseURL, YES));
-        if (!result)
-            result = WebCFAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingISOLatin1, (CFURLRef)baseURL, YES));
-    } else
-        result = [NSURL URLWithString:@""];
-
-    return result;
-}
-
-NSURL *urlByRemovingResourceSpecifier(NSURL *url)
-{
-    return urlByRemovingComponent(url, kCFURLComponentResourceSpecifier);
-}
-
-
-BOOL urlIsFileURL(NSURL *url)
-{
-    if (!url)
-        return false;
-
-    return stringIsFileURL(urlOriginalDataAsString(url));
-}
-
-BOOL stringIsFileURL(NSString *urlString)
-{
-    return [urlString rangeOfString:@"file:" options:(NSCaseInsensitiveSearch | NSAnchoredSearch)].location != NSNotFound;
-}
-
-BOOL urlIsEmpty(NSURL *url)
-{
-    if (!url)
-        return false;
-    if (!CFURLGetBaseURL((CFURLRef)url))
-        return CFURLGetBytes((CFURLRef)url, NULL, 0) == 0;
-    return [urlOriginalData(url) length] == 0;
-}
-
-NSURL *canonicalURL(NSURL *url)
-{
-    if (!url)
-        return nil;
-    
-    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
-    Class concreteClass = wkNSURLProtocolClassForReqest(request);
-    if (!concreteClass) {
-        [request release];
-        return url;
-    }
-    
-    // This applies NSURL's concept of canonicalization, but not KURL's concept. It would
-    // make sense to apply both, but when we tried that it caused a performance degradation
-    // (see 5315926). It might make sense to apply only the KURL concept and not the NSURL
-    // concept, but it's too risky to make that change for WebKit 3.0.
-    NSURLRequest *newRequest = [concreteClass canonicalRequestForRequest:request];
-    NSURL *newURL = [newRequest URL]; 
-    NSURL *result = [[newURL retain] autorelease]; 
-    [request release];
-    
-    return result;
-}
-
-static bool vectorContainsString(Vector<String> vector, String string)
+static bool vectorContainsString(const Vector<String>& vector, const String& string)
 {
     int size = vector.size();
     for (int i = 0; i < size; i++)
index fbbacd2510b194279b7d9e6e063242c66b9ceec7..8d318fef49621f23a476539f90e0ab46f9cedfdb 100644 (file)
@@ -138,7 +138,6 @@ extern void (*wkSignalCFReadStreamEnd)(CFReadStreamRef stream);
 extern void (*wkSignalCFReadStreamError)(CFReadStreamRef stream, CFStreamError *error);
 extern void (*wkSignalCFReadStreamHasBytes)(CFReadStreamRef stream);
 extern BOOL (*wkSupportsMultipartXMixedReplace)(NSMutableURLRequest *);
-extern Class (*wkNSURLProtocolClassForReqest)(NSURLRequest *);
 extern float (*wkSecondsSinceLastInputEvent)(void);
 #ifdef __cplusplus
 }
index 9e8856da84ed13a0ee19782490083211ca9917fc..64a7c2af2dff02a9625a2d8382bc2ea9ee566ea4 100644 (file)
@@ -91,5 +91,4 @@ void (*wkSetNSURLConnectionDefersCallbacks)(NSURLConnection *, BOOL);
 void (*wkSetNSURLRequestShouldContentSniff)(NSMutableURLRequest *, BOOL);
 id (*wkCreateNSURLConnectionDelegateProxy)(void);
 BOOL (*wkSupportsMultipartXMixedReplace)(NSMutableURLRequest *);
-Class (*wkNSURLProtocolClassForReqest)(NSURLRequest *);
 float (*wkSecondsSinceLastInputEvent)(void);
index 7868e7e73daceff499870aaee01d4bf628030dd1..8679ebb94ea50983c856f7bed35a4eda71fa1980 100644 (file)
@@ -1,3 +1,26 @@
+2008-02-19  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Darin.
+
+        Move back WebKit methods that were unused in WebCore.
+        
+        * Misc/WebNSURLExtras.mm:
+        (+[NSURL _web_URLWithData:]):
+        (+[NSURL _web_URLWithData:relativeToURL:]):
+        (-[NSURL _web_originalData]):
+        (-[NSURL _web_originalDataAsString]):
+        (-[NSURL _web_isEmpty]):
+        (-[NSURL _webkit_canonicalize]):
+        (-[NSURL _webkit_URLByRemovingComponent:]):
+        (-[NSURL _webkit_URLByRemovingFragment]):
+        (-[NSURL _webkit_URLByRemovingResourceSpecifier]):
+        (-[NSURL _webkit_isFileURL]):
+        (-[NSString _webkit_isFileURL]):
+        * WebCoreSupport/WebFrameLoaderClient.mm:
+        (WebFrameLoaderClient::setTitle):
+        * WebCoreSupport/WebSystemInterface.m:
+        (InitWebCoreSystemInterface):
+
 2008-02-18  Darin Adler  <darin@apple.com>
 
         Reviewed by Sam.
index 21fdc9d1f6b94f994f29cb9865d0a186ef1310ce..9ab96af3686e329ea63a037cb3c7b67c8f650a94 100644 (file)
@@ -411,22 +411,57 @@ static NSString *mapHostNames(NSString *string, BOOL encode)
 
 + (NSURL *)_web_URLWithData:(NSData *)data
 {
-    return urlWithData(data);
+    return [NSURL _web_URLWithData:data relativeToURL:nil];
 }      
 
 + (NSURL *)_web_URLWithData:(NSData *)data relativeToURL:(NSURL *)baseURL
 {
-    return urlWithDataRelativeToURL(data, baseURL);
+    if (data == nil)
+        return nil;
+    
+    NSURL *result = nil;
+    size_t length = [data length];
+    if (length > 0) {
+        // work around <rdar://4470771>: CFURLCreateAbsoluteURLWithBytes(.., TRUE) doesn't remove non-path components.
+        baseURL = [baseURL _webkit_URLByRemovingResourceSpecifier];
+        
+        const UInt8 *bytes = static_cast<const UInt8*>([data bytes]);
+        // NOTE: We use UTF-8 here since this encoding is used when computing strings when returning URL components
+        // (e.g calls to NSURL -path). However, this function is not tolerant of illegal UTF-8 sequences, which
+        // could either be a malformed string or bytes in a different encoding, like shift-jis, so we fall back
+        // onto using ISO Latin 1 in those cases.
+        result = WebCFAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingUTF8, (CFURLRef)baseURL, YES));
+        if (!result)
+            result = WebCFAutorelease(CFURLCreateAbsoluteURLWithBytes(NULL, bytes, length, kCFStringEncodingISOLatin1, (CFURLRef)baseURL, YES));
+    } else
+        result = [NSURL URLWithString:@""];
+    
+    return result;
 }
 
 - (NSData *)_web_originalData
 {
-    return urlOriginalData(self);
+    UInt8 *buffer = (UInt8 *)malloc(URL_BYTES_BUFFER_LENGTH);
+    CFIndex bytesFilled = CFURLGetBytes((CFURLRef)self, buffer, URL_BYTES_BUFFER_LENGTH);
+    if (bytesFilled == -1) {
+        CFIndex bytesToAllocate = CFURLGetBytes((CFURLRef)self, NULL, 0);
+        buffer = (UInt8 *)realloc(buffer, bytesToAllocate);
+        bytesFilled = CFURLGetBytes((CFURLRef)self, buffer, bytesToAllocate);
+        ASSERT(bytesFilled == bytesToAllocate);
+    }
+    
+    // buffer is adopted by the NSData
+    NSData *data = [NSData dataWithBytesNoCopy:buffer length:bytesFilled freeWhenDone:YES];
+    
+    NSURL *baseURL = (NSURL *)CFURLGetBaseURL((CFURLRef)self);
+    if (baseURL)
+        return [[NSURL _web_URLWithData:data relativeToURL:baseURL] _web_originalData];
+    return data;
 }
 
 - (NSString *)_web_originalDataAsString
 {
-    return urlOriginalDataAsString(self);
+    return [[[NSString alloc] initWithData:[self _web_originalData] encoding:NSISOLatin1StringEncoding] autorelease];
 }
 
 - (NSString *)_web_userVisibleString
@@ -511,7 +546,9 @@ static NSString *mapHostNames(NSString *string, BOOL encode)
 
 - (BOOL)_web_isEmpty
 {
-    return urlIsEmpty(self);
+    if (!CFURLGetBaseURL((CFURLRef)self))
+        return CFURLGetBytes((CFURLRef)self, NULL, 0) == 0;
+    return [[self _web_originalData] length] == 0;
 }
 
 - (const char *)_web_URLCString
@@ -523,9 +560,24 @@ static NSString *mapHostNames(NSString *string, BOOL encode)
  }
 
 - (NSURL *)_webkit_canonicalize
-{
-    InitWebCoreSystemInterface();
-    return canonicalURL(self);
+{    
+    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:self];
+    Class concreteClass = WKNSURLProtocolClassForReqest(request);
+    if (!concreteClass) {
+        [request release];
+        return self;
+    }
+    
+    // This applies NSURL's concept of canonicalization, but not KURL's concept. It would
+    // make sense to apply both, but when we tried that it caused a performance degradation
+    // (see 5315926). It might make sense to apply only the KURL concept and not the NSURL
+    // concept, but it's too risky to make that change for WebKit 3.0.
+    NSURLRequest *newRequest = [concreteClass canonicalRequestForRequest:request];
+    NSURL *newURL = [newRequest URL]; 
+    NSURL *result = [[newURL retain] autorelease]; 
+    [request release];
+    
+    return result;
 }
 
 typedef struct {
@@ -539,21 +591,38 @@ typedef struct {
     NSString *fragment;
 } WebKitURLComponents;
 
-
-
 - (NSURL *)_webkit_URLByRemovingComponent:(CFURLComponentType)component
 {
-    return urlByRemovingComponent(self, component);
+    CFRange fragRg = CFURLGetByteRangeForComponent((CFURLRef)self, component, NULL);
+    // Check to see if a fragment exists before decomposing the URL.
+    if (fragRg.location == kCFNotFound)
+        return self;
+    UInt8 *urlBytes, buffer[2048];
+    CFIndex numBytes = CFURLGetBytes((CFURLRef)self, buffer, 2048);
+    if (numBytes == -1) {
+        numBytes = CFURLGetBytes((CFURLRef)self, NULL, 0);
+        urlBytes = static_cast<UInt8*>(malloc(numBytes));
+        CFURLGetBytes((CFURLRef)self, urlBytes, numBytes);
+    } else
+        urlBytes = buffer;
+     
+    NSURL *result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, fragRg.location - 1, kCFStringEncodingUTF8, NULL));
+    if (!result)
+        result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, fragRg.location - 1, kCFStringEncodingISOLatin1, NULL));
+     
+    if (urlBytes != buffer) free(urlBytes);
+    return result ? [result autorelease] : self;
 }
 
 - (NSURL *)_webkit_URLByRemovingFragment
 {
-    return urlByRemovingFragment(self);
+    return [self _webkit_URLByRemovingComponent:kCFURLComponentFragment];
 }
 
 - (NSURL *)_webkit_URLByRemovingResourceSpecifier
 {
-    return urlByRemovingResourceSpecifier(self);
+    return [self _webkit_URLByRemovingComponent:kCFURLComponentResourceSpecifier];
 }
 
 - (BOOL)_webkit_isJavaScriptURL
@@ -567,8 +636,8 @@ typedef struct {
 }
 
 - (BOOL)_webkit_isFileURL
-{
-    return urlIsFileURL(self);
+{    
+    return [[self _web_originalDataAsString] _webkit_isFileURL];
 }
 
 - (BOOL)_webkit_isFTPDirectoryURL
@@ -797,7 +866,7 @@ typedef struct {
 
 - (BOOL)_webkit_isFileURL
 {
-    return stringIsFileURL(self);
+    return [self rangeOfString:@"file:" options:(NSCaseInsensitiveSearch | NSAnchoredSearch)].location != NSNotFound;
 }
 
 - (NSString *)_webkit_stringByReplacingValidPercentEscapes
index b926a2c8d38ca11835981097132623face0724a3..92c013fb3dffed33a2fafc390541a0bfbb57cd22 100644 (file)
@@ -944,7 +944,8 @@ PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader(const Reso
 // Once that task is complete, this will go away
 void WebFrameLoaderClient::setTitle(const String& title, const KURL& URL)
 {
-    NSURL* nsURL = canonicalURL(URL);
+    NSURL* nsURL = URL;
+    nsURL = [nsURL _webkit_canonicalize];
     if(!nsURL)
         return;
     NSString *titleNSString = title;
index e20adfdcabd30a185f468992222a934d1bcfac4b..de9b1ace328331cb63bb313d567c36b613c27c05 100644 (file)
@@ -77,7 +77,6 @@ void InitWebCoreSystemInterface(void)
     INIT(GetPreferredExtensionForMIMEType);
     INIT(GetWheelEventDeltas);
     INIT(InitializeGlyphVector);
-    INIT(NSURLProtocolClassForReqest);
     INIT(PathFromFont);
     INIT(PopupMenu);
     INIT(ReleaseStyleGroup);