Encode/decode CFURLRequestRefs when USE(CFNETWORK) is enabled
authorpsolanki@apple.com <psolanki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Jul 2014 00:57:52 +0000 (00:57 +0000)
committerpsolanki@apple.com <psolanki@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Jul 2014 00:57:52 +0000 (00:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=134454
<rdar://problem/17510980>

Reviewed by Andreas Kling.

Source/WebKit2:
Use new helper methods to serialize/deserialize CFURLRequestRef directly so we can avoid
creating NSURLRequest.

* Shared/mac/WebCoreArgumentCodersMac.mm:
(IPC::ArgumentCoder<ResourceRequest>::encodePlatformData):
(IPC::ArgumentCoder<ResourceRequest>::decodePlatformData):

WebKitLibraries:
* WebKitSystemInterface.h:
* libWebKitSystemInterfaceMavericks.a:
* libWebKitSystemInterfaceMountainLion.a:

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

Source/WebKit2/ChangeLog
Source/WebKit2/Shared/mac/WebCoreArgumentCodersMac.mm
WebKitLibraries/ChangeLog
WebKitLibraries/WebKitSystemInterface.h
WebKitLibraries/libWebKitSystemInterfaceMavericks.a
WebKitLibraries/libWebKitSystemInterfaceMountainLion.a

index 8b1bcad..31d0b60 100644 (file)
@@ -1,3 +1,18 @@
+2014-07-01  Pratik Solanki  <psolanki@apple.com>
+
+        Encode/decode CFURLRequestRefs when USE(CFNETWORK) is enabled
+        https://bugs.webkit.org/show_bug.cgi?id=134454
+        <rdar://problem/17510980>
+
+        Reviewed by Andreas Kling.
+
+        Use new helper methods to serialize/deserialize CFURLRequestRef directly so we can avoid
+        creating NSURLRequest.
+
+        * Shared/mac/WebCoreArgumentCodersMac.mm:
+        (IPC::ArgumentCoder<ResourceRequest>::encodePlatformData):
+        (IPC::ArgumentCoder<ResourceRequest>::decodePlatformData):
+
 2014-07-01  Benjamin Poulain  <benjamin@webkit.org>
 
         [iOS][WK2] Fix a race between the short tap and long tap highlight
index edb6c8b..8362896 100644 (file)
 #import <WebCore/ResourceError.h>
 #import <WebCore/ResourceRequest.h>
 
+#if USE(CFNETWORK)
+#import <CFNetwork/CFURLRequest.h>
+#endif
+
 using namespace WebCore;
 
 namespace IPC {
 
+#if USE(CFNETWORK)
+void ArgumentCoder<ResourceRequest>::encodePlatformData(ArgumentEncoder& encoder, const ResourceRequest& resourceRequest)
+{
+    RetainPtr<CFURLRequestRef> requestToSerialize = resourceRequest.cfURLRequest(DoNotUpdateHTTPBody);
+
+    bool requestIsPresent = requestToSerialize;
+    encoder << requestIsPresent;
+
+    if (!requestIsPresent)
+        return;
+
+    // We don't send HTTP body over IPC for better performance.
+    // Also, it's not always possible to do, as streams can only be created in process that does networking.
+    RetainPtr<CFDataRef> requestHTTPBody = adoptCF(CFURLRequestCopyHTTPRequestBody(requestToSerialize.get()));
+    RetainPtr<CFReadStreamRef> requestHTTPBodyStream = adoptCF(CFURLRequestCopyHTTPRequestBodyStream(requestToSerialize.get()));
+    if (requestHTTPBody || requestHTTPBodyStream) {
+        CFMutableURLRequestRef mutableRequest = CFURLRequestCreateMutableCopy(0, requestToSerialize.get());
+        requestToSerialize = adoptCF(mutableRequest);
+        CFURLRequestSetHTTPRequestBody(mutableRequest, nil);
+        CFURLRequestSetHTTPRequestBodyStream(mutableRequest, nil);
+    }
+
+    RetainPtr<CFDictionaryRef> dictionary = adoptCF(WKCFURLRequestCreateSerializableRepresentation(requestToSerialize.get(), IPC::tokenNullTypeRef()));
+    IPC::encode(encoder, dictionary.get());
+
+    // The fallback array is part of CFURLRequest, but it is not encoded by WKCFURLRequestCreateSerializableRepresentation.
+    encoder << resourceRequest.responseContentDispositionEncodingFallbackArray();
+}
+#else
 void ArgumentCoder<ResourceRequest>::encodePlatformData(ArgumentEncoder& encoder, const ResourceRequest& resourceRequest)
 {
     RetainPtr<NSURLRequest> requestToSerialize = resourceRequest.nsURLRequest(DoNotUpdateHTTPBody);
@@ -63,6 +96,7 @@ void ArgumentCoder<ResourceRequest>::encodePlatformData(ArgumentEncoder& encoder
     // The fallback array is part of NSURLRequest, but it is not encoded by WKNSURLRequestCreateSerializableRepresentation.
     encoder << resourceRequest.responseContentDispositionEncodingFallbackArray();
 }
+#endif
 
 bool ArgumentCoder<ResourceRequest>::decodePlatformData(ArgumentDecoder& decoder, ResourceRequest& resourceRequest)
 {
@@ -79,11 +113,19 @@ bool ArgumentCoder<ResourceRequest>::decodePlatformData(ArgumentDecoder& decoder
     if (!IPC::decode(decoder, dictionary))
         return false;
 
+#if USE(CFNETWORK)
+    RetainPtr<CFURLRequestRef> cfURLRequest = adoptCF(WKCreateCFURLRequestFromSerializableRepresentation(dictionary.get(), IPC::tokenNullTypeRef()));
+    if (!cfURLRequest)
+        return false;
+
+    resourceRequest = ResourceRequest(cfURLRequest.get());
+#else
     RetainPtr<NSURLRequest> nsURLRequest = WKNSURLRequestFromSerializableRepresentation(dictionary.get(), IPC::tokenNullTypeRef());
     if (!nsURLRequest)
         return false;
 
     resourceRequest = ResourceRequest(nsURLRequest.get());
+#endif
     
     Vector<String> responseContentDispositionEncodingFallbackArray;
     if (!decoder.decode(responseContentDispositionEncodingFallbackArray))
index 683a387..46752a9 100644 (file)
@@ -1,3 +1,15 @@
+2014-07-01  Pratik Solanki  <psolanki@apple.com>
+
+        Encode/decode CFURLRequestRefs when USE(CFNETWORK) is enabled
+        https://bugs.webkit.org/show_bug.cgi?id=134454
+        <rdar://problem/17510980>
+
+        Reviewed by Andreas Kling.
+
+        * WebKitSystemInterface.h:
+        * libWebKitSystemInterfaceMavericks.a:
+        * libWebKitSystemInterfaceMountainLion.a:
+
 2014-06-25  Laszlo Gombos  <l.gombos@samsung.com>
 
         Remove build guard for progress element
index 9dbd6c3..cf80220 100644 (file)
@@ -439,6 +439,8 @@ void WKEnableSettingCursorWhenInBackground(void);
 
 CFDictionaryRef WKNSURLRequestCreateSerializableRepresentation(NSURLRequest *request, CFTypeRef tokenNull);
 NSURLRequest *WKNSURLRequestFromSerializableRepresentation(CFDictionaryRef representation, CFTypeRef tokenNull);
+CFDictionaryRef WKCFURLRequestCreateSerializableRepresentation(CFURLRequestRef cfRequest, CFTypeRef tokenNull);
+CFURLRequestRef WKCreateCFURLRequestFromSerializableRepresentation(CFDictionaryRef representation, CFTypeRef tokenNull);
 
 CFDictionaryRef WKNSURLResponseCreateSerializableRepresentation(NSURLResponse *response, CFTypeRef tokenNull);
 NSURLResponse *WKNSURLResponseFromSerializableRepresentation(CFDictionaryRef representation, CFTypeRef tokenNull);
index 0d86ae8..3dd2047 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceMavericks.a and b/WebKitLibraries/libWebKitSystemInterfaceMavericks.a differ
index fd46430..8999610 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceMountainLion.a and b/WebKitLibraries/libWebKitSystemInterfaceMountainLion.a differ