diff options
-rw-r--r-- | webkit/port/platform/GKURLMac.mm | 68 | ||||
-rw-r--r-- | webkit/webkit.xcodeproj/project.pbxproj | 4 |
2 files changed, 72 insertions, 0 deletions
diff --git a/webkit/port/platform/GKURLMac.mm b/webkit/port/platform/GKURLMac.mm new file mode 100644 index 0000000..a911387 --- /dev/null +++ b/webkit/port/platform/GKURLMac.mm @@ -0,0 +1,68 @@ +// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "config.h" +#include "KURL.h" +#include "FoundationExtras.h" + +// TODO(playmobil): Write unit tests for this file. + +#ifdef USE_GOOGLE_URL_LIBRARY + +namespace WebCore { + +CFURLRef KURL::createCFURL() const { + const CString &utf8_url = m_url.utf8String(); + // 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, + reinterpret_cast<const UInt8*>(utf8_url.data()), + utf8_url.length(), + kCFStringEncodingUTF8, + 0, + true); + if (!result) + result = CFURLCreateAbsoluteURLWithBytes(0, + reinterpret_cast<const UInt8*>( + utf8_url.data()), + utf8_url.length(), + kCFStringEncodingISOLatin1, + 0, + true); + return result; +} + + +// TODO(playmobil): also implement the KURL::KURL(CFURLRef) version. +KURL::KURL(NSURL *url) { + if (!url) { + init(KURL(), String(), NULL); + } else { + CFIndex bytesLength = CFURLGetBytes(reinterpret_cast<CFURLRef>(url), 0, 0); + Vector<char, 512> buffer(bytesLength + 1); // 1 for null character to end C string + char* bytes = &buffer[0]; + CFURLGetBytes(reinterpret_cast<CFURLRef>(url), reinterpret_cast<UInt8*>(bytes), bytesLength); + bytes[bytesLength] = '\0'; + init(KURL(), String(bytes, bytesLength), 0); + } +} + +KURL::operator NSURL* () const { + if (!m_isValid) + return nil; + + // CFURL can't hold an empty URL, unlike NSURL. + if (isEmpty()) + return [NSURL URLWithString:@""]; + + return HardAutorelease(createCFURL()); +} + +} // namespace WebCore + +#endif // USE_GOOGLE_URL_LIBRARY diff --git a/webkit/webkit.xcodeproj/project.pbxproj b/webkit/webkit.xcodeproj/project.pbxproj index c12ddd0..df205e8 100644 --- a/webkit/webkit.xcodeproj/project.pbxproj +++ b/webkit/webkit.xcodeproj/project.pbxproj @@ -416,6 +416,7 @@ AB8FE8A50E9BCD3E0051E7B4 /* GKURL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB8FE8A40E9BCD3E0051E7B4 /* GKURL.cpp */; }; B507F51C0E9BE98B00D16D77 /* PluginStubsMac.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B507F51B0E9BE98B00D16D77 /* PluginStubsMac.cpp */; }; B507F54E0E9BECC300D16D77 /* HTMLPlugInImageElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B507F54D0E9BECC300D16D77 /* HTMLPlugInImageElement.cpp */; }; + B507F6E90E9C06FD00D16D77 /* GKURLMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = B507F6E70E9C06F400D16D77 /* GKURLMac.mm */; }; B50F5BE00E96D3F800AD71A6 /* WebCoreObjCExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = B50F5BDF0E96D3F800AD71A6 /* WebCoreObjCExtras.mm */; }; B51C76C00E9BC7A400D9DFC4 /* GradientCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B51C76BF0E9BC7A400D9DFC4 /* GradientCG.cpp */; }; B51C76CF0E9BC8D100D9DFC4 /* RenderMarquee.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B51C76CE0E9BC8D100D9DFC4 /* RenderMarquee.cpp */; }; @@ -3831,6 +3832,7 @@ AB8FE8A40E9BCD3E0051E7B4 /* GKURL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GKURL.cpp; sourceTree = "<group>"; }; B507F51B0E9BE98B00D16D77 /* PluginStubsMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PluginStubsMac.cpp; sourceTree = "<group>"; }; B507F54D0E9BECC300D16D77 /* HTMLPlugInImageElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLPlugInImageElement.cpp; sourceTree = "<group>"; }; + B507F6E70E9C06F400D16D77 /* GKURLMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GKURLMac.mm; sourceTree = "<group>"; }; B50F5BDF0E96D3F800AD71A6 /* WebCoreObjCExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebCoreObjCExtras.mm; path = pending/WebCoreObjCExtras.mm; sourceTree = SOURCE_ROOT; }; B51C76BF0E9BC7A400D9DFC4 /* GradientCG.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GradientCG.cpp; sourceTree = "<group>"; }; B51C76CD0E9BC8D100D9DFC4 /* RenderMarquee.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderMarquee.h; sourceTree = "<group>"; }; @@ -6851,6 +6853,7 @@ 822B1BE70DC77910005C9A96 /* graphics */, E45628270E269688005E4685 /* network */, AB8FE8A40E9BCD3E0051E7B4 /* GKURL.cpp */, + B507F6E70E9C06F400D16D77 /* GKURLMac.mm */, B507F51B0E9BE98B00D16D77 /* PluginStubsMac.cpp */, ); path = platform; @@ -8615,6 +8618,7 @@ 7B2B0A5F0E3143EC00D4C6B7 /* GIFImageDecoder.cpp in Sources */, 7B2B0A610E3143EC00D4C6B7 /* GIFImageReader.cpp in Sources */, AB8FE8A50E9BCD3E0051E7B4 /* GKURL.cpp in Sources */, + B507F6E90E9C06FD00D16D77 /* GKURLMac.mm in Sources */, E45627EB0E2694B8005E4685 /* ICOImageDecoder.cpp in Sources */, E4E4C94A0E797648009A687C /* ImageSourceCG.cpp in Sources */, 7B2B0A630E3143EC00D4C6B7 /* JPEGImageDecoder.cpp in Sources */, |