Extract use of NSKeyedUnarchiver from WebArchiveDumpSupport.mm
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Oct 2010 05:29:25 +0000 (05:29 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 27 Oct 2010 05:29:25 +0000 (05:29 +0000)
Reviewed by Adam Roben.

Part 2 of 4: <http://webkit.org/b/48278> Convert DumpRenderTree webarchive code to CoreFoundation

There is no equivalent to NSKeyedUnarchiver in CoreFoundation,
so extract it into a platform-specific source file.

* DumpRenderTree/mac/WebArchiveDumpSupport.h:
(unarchiveNSURLResponseFromResponseData): Added declaration.
* DumpRenderTree/mac/WebArchiveDumpSupport.mm:
(convertWebResourceResponseToDictionary): Extracted code to
unarchiveNSURLResponseFromResponseData() in
WebArchiveDumpSupportMac.mm.  Updated logic to return early if
nil is returned from unarchiveNSURLResponseFromResponseData().
* DumpRenderTree/mac/WebArchiveDumpSupportMac.mm:
(unarchiveNSURLResponseFromResponseData): Added.  Extracted
code from convertWebResourceResponseToDictionary() in
WebArchiveDumpSupport.mm.

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

WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.h
WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.mm
WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupportMac.mm

index 7c41875..594eca3 100644 (file)
@@ -1,5 +1,28 @@
 2010-10-26  David Kilzer  <ddkilzer@apple.com>
 
+        Extract use of NSKeyedUnarchiver from WebArchiveDumpSupport.mm
+
+        Reviewed by Adam Roben.
+
+        Part 2 of 4: <http://webkit.org/b/48278> Convert DumpRenderTree webarchive code to CoreFoundation
+
+        There is no equivalent to NSKeyedUnarchiver in CoreFoundation,
+        so extract it into a platform-specific source file.
+
+        * DumpRenderTree/mac/WebArchiveDumpSupport.h:
+        (unarchiveNSURLResponseFromResponseData): Added declaration.
+        * DumpRenderTree/mac/WebArchiveDumpSupport.mm:
+        (convertWebResourceResponseToDictionary): Extracted code to
+        unarchiveNSURLResponseFromResponseData() in
+        WebArchiveDumpSupportMac.mm.  Updated logic to return early if
+        nil is returned from unarchiveNSURLResponseFromResponseData().
+        * DumpRenderTree/mac/WebArchiveDumpSupportMac.mm:
+        (unarchiveNSURLResponseFromResponseData): Added.  Extracted
+        code from convertWebResourceResponseToDictionary() in
+        WebArchiveDumpSupport.mm.
+
+2010-10-26  David Kilzer  <ddkilzer@apple.com>
+
         Extract call to -[WebHTMLRepresentation supportedNonImageMIMETypes] from WebArchiveDumpSupport.mm
 
         Reviewed by Adam Roben.
index ab0b530..66cd369 100644 (file)
@@ -28,7 +28,9 @@
 
 #include <CoreFoundation/CoreFoundation.h>
 
+@class NSData;
 @class NSString;
+@class NSURLResponse;
 @class WebArchive;
 
 NSString *serializeWebArchiveToXML(WebArchive *webArchive);
@@ -36,6 +38,7 @@ NSString *serializeWebArchiveToXML(WebArchive *webArchive);
 #pragma mark -
 #pragma mark Platform-specific methods
 
+NSURLResponse *unarchiveNSURLResponseFromResponseData(NSData *responseData);
 CFArrayRef supportedNonImageMIMETypes();
 
 #endif /* WebArchiveDumpSupport_h */
index 8632fec..4cdcde2 100644 (file)
@@ -92,15 +92,13 @@ static void normalizeWebResourceURL(NSMutableString *webResourceURL)
 
 static void convertWebResourceResponseToDictionary(NSMutableDictionary *propertyList)
 {
-    NSURLResponse *response = nil;
     NSData *responseData = [propertyList objectForKey:@"WebResourceResponse"]; // WebResourceResponseKey in WebResource.m
-    if ([responseData isKindOfClass:[NSData class]]) {
-        // Decode NSURLResponse
-        NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:responseData];
-        response = [unarchiver decodeObjectForKey:@"WebResourceResponse"]; // WebResourceResponseKey in WebResource.m
-        [unarchiver finishDecoding];
-        [unarchiver release];
-    }        
+    if (![responseData isKindOfClass:[NSData class]])
+        return;
+
+    NSURLResponse *response = unarchiveNSURLResponseFromResponseData(responseData);
+    if (!response)
+        return;
 
     NSMutableDictionary *responseDictionary = [[NSMutableDictionary alloc] init];
 
index c3949e6..e2e3521 100644 (file)
 
 #import "WebArchiveDumpSupport.h"
 
+#import <Foundation/Foundation.h>
 #import <WebKit/WebHTMLRepresentation.h>
+#import <wtf/RetainPtr.h>
+
+NSURLResponse *unarchiveNSURLResponseFromResponseData(NSData *responseData)
+{
+    // Decode NSURLResponse
+    RetainPtr<NSKeyedUnarchiver> unarchiver(AdoptNS, [[NSKeyedUnarchiver alloc] initForReadingWithData:responseData]);
+    NSURLResponse *response = [unarchiver.get() decodeObjectForKey:@"WebResourceResponse"]; // WebResourceResponseKey in WebResource.m
+    [unarchiver.get() finishDecoding];
+
+    return response;
+}
 
 CFArrayRef supportedNonImageMIMETypes()
 {