Commit 5a8524b6 authored by mitz@apple.com's avatar mitz@apple.com

Use createCFURLFromBuffer when converting a String to a CFURL

https://bugs.webkit.org/show_bug.cgi?id=124113

Reviewed by Anders Carlsson.

* Shared/API/c/cf/WKURLCF.mm:
(WKURLCopyCFURL): Replaced some code with a call to createCFURLFromBuffer(), which does the
same thing.

* Shared/Cocoa/WKNSURLExtras.h: Added.
* Shared/Cocoa/WKNSURLExtras.mm: Added.
(+[NSURL _web_URLWithWTFString:relativeToURL:]): Added. Returns nil for the null String,
otherwise returns the result of createCFURLFromBuffer().

* UIProcess/API/Cocoa/WKBackForwardListItem.mm:
(-[WKBackForwardListItem URL]): Changed to use +_web_URLWithWTFString:relativeToURL:.
(-[WKBackForwardListItem originalURL]): Ditto.

* UIProcess/API/Cocoa/WKNavigationData.mm:
(-[WKNavigationData destinationURL]): Ditto.

* UIProcess/API/mac/WKBrowsingContextController.mm:
(-[WKBrowsingContextController unreachableURL]): Ditto.

* WebKit2.xcodeproj/project.pbxproj: Added references to new files.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159016 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c1f684f8
2013-11-09 Dan Bernstein <mitz@apple.com>
Use createCFURLFromBuffer when converting a String to a CFURL
https://bugs.webkit.org/show_bug.cgi?id=124113
Reviewed by Anders Carlsson.
* Shared/API/c/cf/WKURLCF.mm:
(WKURLCopyCFURL): Replaced some code with a call to createCFURLFromBuffer(), which does the
same thing.
* Shared/Cocoa/WKNSURLExtras.h: Added.
* Shared/Cocoa/WKNSURLExtras.mm: Added.
(+[NSURL _web_URLWithWTFString:relativeToURL:]): Added. Returns nil for the null String,
otherwise returns the result of createCFURLFromBuffer().
* UIProcess/API/Cocoa/WKBackForwardListItem.mm:
(-[WKBackForwardListItem URL]): Changed to use +_web_URLWithWTFString:relativeToURL:.
(-[WKBackForwardListItem originalURL]): Ditto.
* UIProcess/API/Cocoa/WKNavigationData.mm:
(-[WKNavigationData destinationURL]): Ditto.
* UIProcess/API/mac/WKBrowsingContextController.mm:
(-[WKBrowsingContextController unreachableURL]): Ditto.
* WebKit2.xcodeproj/project.pbxproj: Added references to new files.
2013-11-09 Anders Carlsson <andersca@apple.com>
Encode form data using the KeyedEncoder
......
......@@ -30,10 +30,7 @@
#import "WKNSURL.h"
#import <WebCore/CFURLExtras.h>
#import <objc/runtime.h>
#import <wtf/PassRefPtr.h>
#import <wtf/RefPtr.h>
#import <wtf/text/CString.h>
#import <wtf/text/WTFString.h>
using namespace WebCore;
using namespace WebKit;
......@@ -75,13 +72,6 @@ CFURLRef WKURLCopyCFURL(CFAllocatorRef allocatorRef, WKURLRef URLRef)
// We first create a CString and then create the CFURL from it. This will ensure that the CFURL is stored in
// UTF-8 which uses less memory and is what WebKit clients might expect.
// This pattern of using UTF-8 and then falling back to Latin1 on failure matches URL::createCFString with the
// major differnce being that URL does not do a UTF-8 conversion and instead chops off the high bits of the UTF-16
// character sequence.
CString buffer = toImpl(URLRef)->string().utf8();
CFURLRef result = CFURLCreateAbsoluteURLWithBytes(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(buffer.data()), buffer.length(), kCFStringEncodingUTF8, 0, true);
if (!result)
result = CFURLCreateAbsoluteURLWithBytes(kCFAllocatorDefault, reinterpret_cast<const UInt8*>(buffer.data()), buffer.length(), kCFStringEncodingISOLatin1, 0, true);
return result;
return createCFURLFromBuffer(buffer.data(), buffer.length(), 0).leakRef();
}
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#import <wtf/Forward.h>
@interface NSURL (WKExtras)
+ (instancetype)_web_URLWithWTFString:(const WTF::String&)string relativeToURL:(NSURL *)baseURL;
@end
/*
* Copyright (C) 2013 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#import "config.h"
#import "WKNSURLExtras.h"
#import <WebCore/CFURLExtras.h>
#import <wtf/text/CString.h>
#import <wtf/text/WTFString.h>
using namespace WebCore;
@implementation NSURL (WKExtras)
+ (instancetype)_web_URLWithWTFString:(const WTF::String&)string relativeToURL:(NSURL *)baseURL
{
if (!string)
return nil;
CString buffer = string.utf8();
return CFBridgingRelease(createCFURLFromBuffer(buffer.data(), buffer.length(), (CFURLRef)baseURL).leakRef());
}
@end
......@@ -28,7 +28,7 @@
#if WK_API_ENABLED
#import "WebString.h"
#import "WKNSURLExtras.h"
using namespace WebKit;
......@@ -45,10 +45,7 @@ using namespace WebKit;
- (NSURL *)URL
{
if (!reinterpret_cast<WebBackForwardListItem*>(&_item)->url())
return nil;
return [NSURL URLWithString:reinterpret_cast<WebBackForwardListItem*>(&_item)->url()];
return [NSURL _web_URLWithWTFString:reinterpret_cast<WebBackForwardListItem*>(&_item)->url() relativeToURL:nil];
}
- (NSString *)title
......@@ -61,10 +58,7 @@ using namespace WebKit;
- (NSURL *)originalURL
{
if (!reinterpret_cast<WebBackForwardListItem*>(&_item)->originalURL())
return nil;
return [NSURL URLWithString:reinterpret_cast<WebBackForwardListItem*>(&_item)->originalURL()];
return [NSURL _web_URLWithWTFString:reinterpret_cast<WebBackForwardListItem*>(&_item)->originalURL() relativeToURL:nil];
}
#pragma mark WKObject protocol implementation
......
......@@ -28,6 +28,7 @@
#if WK_API_ENABLED
#import "WKNSURLExtras.h"
#import <WebCore/ResourceRequest.h>
#import <WebCore/ResourceResponse.h>
......@@ -56,7 +57,7 @@ using namespace WebKit;
- (NSURL *)destinationURL
{
return [NSURL URLWithString:reinterpret_cast<WebNavigationData*>(&_data)->url()];
return [NSURL _web_URLWithWTFString:reinterpret_cast<WebNavigationData*>(&_data)->url() relativeToURL:nil];
}
- (NSURLResponse *)response
......
......@@ -33,6 +33,7 @@
#import "WKFrame.h"
#import "WKFramePolicyListener.h"
#import "WKNSArray.h"
#import "WKNSURLExtras.h"
#import "WKPagePrivate.h"
#import "WKRetainPtr.h"
#import "WKStringCF.h"
......@@ -332,11 +333,7 @@ static void releaseNSData(unsigned char*, const void* data)
- (NSURL *)unreachableURL
{
const String& unreachableURL = toImpl(_data->_pageRef.get())->unreachableURL();
if (!unreachableURL)
return nil;
return !unreachableURL ? nil : [NSURL URLWithString:unreachableURL];
return [NSURL _web_URLWithWTFString:toImpl(_data->_pageRef.get())->unreachableURL() relativeToURL:nil];
}
- (double)estimatedProgress
......
......@@ -407,6 +407,8 @@
370F34A31829BE1E009027C8 /* WKNavigationData.h in Headers */ = {isa = PBXBuildFile; fileRef = 370F34A11829BE1E009027C8 /* WKNavigationData.h */; settings = {ATTRIBUTES = (Private, ); }; };
370F34A51829BEA3009027C8 /* WKNavigationDataInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 370F34A41829BEA3009027C8 /* WKNavigationDataInternal.h */; };
370F34A71829CFF3009027C8 /* WKBrowsingContextHistoryDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 370F34A61829CFF3009027C8 /* WKBrowsingContextHistoryDelegate.h */; settings = {ATTRIBUTES = (Private, ); }; };
37183D56182F4E700080C811 /* WKNSURLExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37183D54182F4E700080C811 /* WKNSURLExtras.mm */; };
37183D57182F4E700080C811 /* WKNSURLExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = 37183D55182F4E700080C811 /* WKNSURLExtras.h */; };
371A19411824D29300F32A5E /* WKNSDictionary.mm in Sources */ = {isa = PBXBuildFile; fileRef = 371A193F1824D29300F32A5E /* WKNSDictionary.mm */; };
371A19421824D29300F32A5E /* WKNSDictionary.h in Headers */ = {isa = PBXBuildFile; fileRef = 371A19401824D29300F32A5E /* WKNSDictionary.h */; };
374436881820E7240049579F /* WKObject.mm in Sources */ = {isa = PBXBuildFile; fileRef = 374436871820E7240049579F /* WKObject.mm */; };
......@@ -1912,6 +1914,8 @@
370F34A11829BE1E009027C8 /* WKNavigationData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNavigationData.h; sourceTree = "<group>"; };
370F34A41829BEA3009027C8 /* WKNavigationDataInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNavigationDataInternal.h; sourceTree = "<group>"; };
370F34A61829CFF3009027C8 /* WKBrowsingContextHistoryDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKBrowsingContextHistoryDelegate.h; sourceTree = "<group>"; };
37183D54182F4E700080C811 /* WKNSURLExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSURLExtras.mm; sourceTree = "<group>"; };
37183D55182F4E700080C811 /* WKNSURLExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSURLExtras.h; sourceTree = "<group>"; };
371A193F1824D29300F32A5E /* WKNSDictionary.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKNSDictionary.mm; sourceTree = "<group>"; };
371A19401824D29300F32A5E /* WKNSDictionary.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKNSDictionary.h; sourceTree = "<group>"; };
374436871820E7240049579F /* WKObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKObject.mm; sourceTree = "<group>"; };
......@@ -3717,6 +3721,8 @@
378E1A4718208CD60031007A /* WKNSString.mm */,
378E1A4C18208D700031007A /* WKNSURL.h */,
378E1A4B18208D700031007A /* WKNSURL.mm */,
37183D55182F4E700080C811 /* WKNSURLExtras.h */,
37183D54182F4E700080C811 /* WKNSURLExtras.mm */,
378E1A3F181EDA010031007A /* WKObject.h */,
374436871820E7240049579F /* WKObject.mm */,
);
......@@ -5912,6 +5918,7 @@
BCB9E24B1120E15C00A137E0 /* WKContext.h in Headers */,
51A555F6128C6C47009ABCEC /* WKContextMenuItem.h in Headers */,
51A55601128C6D92009ABCEC /* WKContextMenuItemTypes.h in Headers */,
37183D57182F4E700080C811 /* WKNSURLExtras.h in Headers */,
BCC938E11180DE440085E5FE /* WKContextPrivate.h in Headers */,
9FB5F395169E6A80002C25BF /* WKContextPrivateMac.h in Headers */,
1AE00D5D182DADE100087DD7 /* KeyedEncoder.h in Headers */,
......@@ -7006,6 +7013,7 @@
1AAF263814687C39004A1E8A /* TiledCoreAnimationDrawingArea.mm in Sources */,
1AF05D8614688348008B1E81 /* TiledCoreAnimationDrawingAreaProxy.mm in Sources */,
1A64245F12DE29A100CAAE2C /* UpdateInfo.cpp in Sources */,
37183D56182F4E700080C811 /* WKNSURLExtras.mm in Sources */,
374436881820E7240049579F /* WKObject.mm in Sources */,
1A0F29E3120B44420053D1B9 /* VisitedLinkProvider.cpp in Sources */,
1A0F29CB120B37160053D1B9 /* VisitedLinkTable.cpp in Sources */,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment