Cannot use NSKeyedArchiver in WK2 for ResourceResponses
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Dec 2010 01:54:17 +0000 (01:54 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 Dec 2010 01:54:17 +0000 (01:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=50792
<rdar://problem/8741799>

Reviewed by Sam Weinig.

WebKit2:

When encoding, first convert the requests and responses to the serializable dictionary representation
and use the newly added CF CoreIPC encoders. When decoding, do the opposite.

* Shared/mac/WebCoreArgumentCodersMac.mm:
(CoreIPC::encodeResourceRequest):
(CoreIPC::decodeResourceRequest):
(CoreIPC::encodeResourceResponse):
(CoreIPC::decodeResourceResponse):

WebKitLibraries:

* WebKitSystemInterface.h:
* libWebKitSystemInterfaceLeopard.a:
* libWebKitSystemInterfaceSnowLeopard.a:

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

WebKit2/ChangeLog
WebKit2/Shared/mac/WebCoreArgumentCodersMac.mm
WebKitLibraries/ChangeLog
WebKitLibraries/WebKitSystemInterface.h
WebKitLibraries/libWebKitSystemInterfaceLeopard.a
WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a

index bc863da..c29c509 100644 (file)
 
         Reviewed by Sam Weinig.
 
+        Cannot use NSKeyedArchiver in WK2 for ResourceResponses
+        https://bugs.webkit.org/show_bug.cgi?id=50792
+        <rdar://problem/8741799>
+
+        When encoding, first convert the requests and responses to the serializable dictionary representation
+        and use the newly added CF CoreIPC encoders. When decoding, do the opposite.
+
+        * Shared/mac/WebCoreArgumentCodersMac.mm:
+        (CoreIPC::encodeResourceRequest):
+        (CoreIPC::decodeResourceRequest):
+        (CoreIPC::encodeResourceResponse):
+        (CoreIPC::decodeResourceResponse):
+
+2010-12-09  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Sam Weinig.
+
         Add CoreIPC coders for CF types
         https://bugs.webkit.org/show_bug.cgi?id=50791
 
index 120dc34..8ffba8a 100644 (file)
 
 #include "WebCoreArgumentCoders.h"
 
-namespace CoreIPC {
-
-static void encodeWithNSKeyedArchiver(ArgumentEncoder* encoder, id rootObject)
-{
-    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:rootObject];
-    encoder->encodeBytes(static_cast<const uint8_t*>([data bytes]), [data length]);
-}
+#include "ArgumentCodersCF.h"
+#include "WebKitSystemInterface.h"
 
-static id decodeWithNSKeyedArchiver(ArgumentDecoder* decoder)
-{
-    Vector<uint8_t> bytes;
-    if (!decoder->decodeBytes(bytes))
-        return nil;
-
-    RetainPtr<NSData> nsData(AdoptNS, [[NSData alloc] initWithBytesNoCopy:bytes.data() length:bytes.size() freeWhenDone:NO]);
-    return [NSKeyedUnarchiver unarchiveObjectWithData:nsData.get()];
-}
+namespace CoreIPC {
 
 void encodeResourceRequest(ArgumentEncoder* encoder, const WebCore::ResourceRequest& resourceRequest)
 {
-    encodeWithNSKeyedArchiver(encoder, resourceRequest.nsURLRequest());
+    RetainPtr<CFDictionaryRef> dictionary(AdoptCF, WKNSURLRequestCreateSerializableRepresentation(resourceRequest.nsURLRequest(), CoreIPC::tokenNullTypeRef()));
+    encode(encoder, dictionary.get());
 }
 
 bool decodeResourceRequest(ArgumentDecoder* decoder, WebCore::ResourceRequest& resourceRequest)
 {
-    NSURLRequest *nsURLRequest = decodeWithNSKeyedArchiver(decoder);
+    RetainPtr<CFDictionaryRef> dictionary;
+    if (!decode(decoder, dictionary))
+        return false;
+
+    NSURLRequest *nsURLRequest = WKNSURLRequestFromSerializableRepresentation(dictionary.get(), CoreIPC::tokenNullTypeRef());
     if (!nsURLRequest)
         return false;
 
@@ -62,24 +54,33 @@ void encodeResourceResponse(ArgumentEncoder* encoder, const WebCore::ResourceRes
 {
     bool responseIsPresent = resourceResponse.nsURLResponse();
     encoder->encode(responseIsPresent);
-    
-    // FIXME: <rdar://problem/8741799> - We can't use NSKeyedArchiver here.
-    encodeWithNSKeyedArchiver(encoder, resourceResponse.nsURLResponse());
+
+    if (!responseIsPresent)
+        return;
+
+    RetainPtr<CFDictionaryRef> dictionary(AdoptCF, WKNSURLResponseCreateSerializableRepresentation(resourceResponse.nsURLResponse(), CoreIPC::tokenNullTypeRef()));
+    encode(encoder, dictionary.get());
 }
 
 bool decodeResourceResponse(ArgumentDecoder* decoder, WebCore::ResourceResponse& resourceResponse)
 {
     bool responseIsPresent;
     decoder->decode(responseIsPresent);
-    
-    // FIXME: <rdar://problem/8741799> - We can't use NSKeyedArchiver here.
-    NSURLResponse *nsURLResponse = decodeWithNSKeyedArchiver(decoder);
-    if (responseIsPresent && !nsURLResponse)
+
+    if (!responseIsPresent) {
+        resourceResponse = WebCore::ResourceResponse();
+        return true;
+    }
+
+    RetainPtr<CFDictionaryRef> dictionary;
+    if (!decode(decoder, dictionary))
         return false;
 
-    if (responseIsPresent)
-        resourceResponse = WebCore::ResourceResponse(nsURLResponse);
+    NSURLResponse* nsURLResponse = WKNSURLResponseFromSerializableRepresentation(dictionary.get(), CoreIPC::tokenNullTypeRef());
+    if (!nsURLResponse)
+        return false;
 
+    resourceResponse = WebCore::ResourceResponse(nsURLResponse);
     return true;
 }
 
index e045333..fe0d79d 100644 (file)
@@ -1,3 +1,15 @@
+2010-12-09  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Cannot use NSKeyedArchiver in WK2 for ResourceResponses
+        https://bugs.webkit.org/show_bug.cgi?id=50792
+        <rdar://problem/8741799>
+
+        * WebKitSystemInterface.h:
+        * libWebKitSystemInterfaceLeopard.a:
+        * libWebKitSystemInterfaceSnowLeopard.a:
+
 2010-12-03  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Sam Weinig.
index 1989900..7030c60 100644 (file)
@@ -330,6 +330,13 @@ void WKWindowSetScaledFrame(NSWindow *window, NSRect scaleFrame, NSRect nonScale
 void WKSyncSurfaceToView(NSView *view);
 
 void WKEnableSettingCursorWhenInBackground(void);
+
+CFDictionaryRef WKNSURLRequestCreateSerializableRepresentation(NSURLRequest *request, CFTypeRef tokenNull);
+NSURLRequest *WKNSURLRequestFromSerializableRepresentation(CFDictionaryRef representation, CFTypeRef tokenNull);
+
+CFDictionaryRef WKNSURLResponseCreateSerializableRepresentation(NSURLResponse *response, CFTypeRef tokenNull);
+NSURLResponse *WKNSURLResponseFromSerializableRepresentation(CFDictionaryRef representation, CFTypeRef tokenNull);
+    
 #endif
 
 #if defined(BUILDING_ON_TIGER) || defined(BUILDING_ON_LEOPARD) || defined(BUILDING_ON_SNOW_LEOPARD)
index 459ebe2..7efe2f9 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceLeopard.a and b/WebKitLibraries/libWebKitSystemInterfaceLeopard.a differ
index a136510..0875328 100644 (file)
Binary files a/WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a and b/WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a differ