diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:15 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:15 -0800 |
commit | 1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353 (patch) | |
tree | 4457a7306ea5acb43fe05bfe0973b1f7faf97ba2 /WebCore/platform/cf/KURLCFNet.cpp | |
parent | 9364f22aed35e1a1e9d07c121510f80be3ab0502 (diff) | |
download | external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.zip external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.gz external_webkit-1cbdecfa9fc428ac2d8aca0fa91c9580b3d57353.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'WebCore/platform/cf/KURLCFNet.cpp')
-rw-r--r-- | WebCore/platform/cf/KURLCFNet.cpp | 58 |
1 files changed, 33 insertions, 25 deletions
diff --git a/WebCore/platform/cf/KURLCFNet.cpp b/WebCore/platform/cf/KURLCFNet.cpp index 2130667..f060b28 100644 --- a/WebCore/platform/cf/KURLCFNet.cpp +++ b/WebCore/platform/cf/KURLCFNet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004 Apple Computer, Inc. All rights reserved. + * Copyright (C) 2004, 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,7 +27,6 @@ #include "KURL.h" #include <wtf/RetainPtr.h> -#include <wtf/Vector.h> #include <CoreFoundation/CFURL.h> using namespace std; @@ -36,35 +35,46 @@ namespace WebCore { KURL::KURL(CFURLRef url) { - if (url) { - CFIndex bytesLength = CFURLGetBytes(url, 0, 0); - Vector<char, 2048> buffer(bytesLength + 6); // 6 for "file:", 1 for NUL terminator - char* bytes = &buffer[5]; - CFURLGetBytes(url, (UInt8*)bytes, bytesLength); - bytes[bytesLength] = '\0'; - if (bytes[0] == '/') { - buffer[0] = 'f'; - buffer[1] = 'i'; - buffer[2] = 'l'; - buffer[3] = 'e'; - buffer[4] = ':'; - parse(buffer.data(), 0); - } else - parse(bytes, 0); - } else - parse("", 0); + if (!url) { + parse(0, 0); + return; + } + + CFIndex bytesLength = CFURLGetBytes(url, 0, 0); + Vector<char, 512> buffer(bytesLength + 6); // 5 for "file:", 1 for null character to end C string + char* bytes = &buffer[5]; + CFURLGetBytes(url, reinterpret_cast<UInt8*>(bytes), bytesLength); + bytes[bytesLength] = '\0'; + if (bytes[0] != '/') { + parse(bytes, 0); + return; + } + + buffer[0] = 'f'; + buffer[1] = 'i'; + buffer[2] = 'l'; + buffer[3] = 'e'; + buffer[4] = ':'; + + parse(buffer.data(), 0); } CFURLRef KURL::createCFURL() const { - const UInt8 *bytes = (const UInt8 *)urlString.latin1(); + // FIXME: What should this return for invalid URLs? + // Currently it throws away the high bytes of the characters in the string in that case, + // which is clearly wrong. + + Vector<char, 512> buffer; + copyToBuffer(buffer); + // 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. - CFURLRef result = CFURLCreateAbsoluteURLWithBytes(0, bytes, urlString.length(), kCFStringEncodingUTF8, 0, true); + CFURLRef result = CFURLCreateAbsoluteURLWithBytes(0, reinterpret_cast<const UInt8*>(buffer.data()), buffer.size(), kCFStringEncodingUTF8, 0, true); if (!result) - result = CFURLCreateAbsoluteURLWithBytes(0, bytes, urlString.length(), kCFStringEncodingISOLatin1, 0, true); + result = CFURLCreateAbsoluteURLWithBytes(0, reinterpret_cast<const UInt8*>(buffer.data()), buffer.size(), kCFStringEncodingISOLatin1, 0, true); return result; } @@ -79,9 +89,7 @@ String KURL::fileSystemPath() const #else CFURLPathStyle pathStyle = kCFURLPOSIXPathStyle; #endif - - RetainPtr<CFStringRef> path(AdoptCF, CFURLCopyFileSystemPath(cfURL.get(), pathStyle)); - return path.get(); + return RetainPtr<CFStringRef>(AdoptCF, CFURLCopyFileSystemPath(cfURL.get(), pathStyle)).get(); } } |