<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[70613] trunk/WebKitTools</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/70613">70613</a></dd>
<dt>Author</dt> <dd>ddkilzer@apple.com</dd>
<dt>Date</dt> <dd>2010-10-26 22:29:32 -0700 (Tue, 26 Oct 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Convert WebArchiveDumpSupport.mm from NS objects to CF types

Reviewed by Adam Roben.

Part 3 of 4: &lt;http://webkit.org/b/48278&gt; Convert DumpRenderTree webarchive code to CoreFoundation

In order to share WebArchive code between the Mac and Windows
ports, the code in WebArchiveDumpSupport.mm was converted from
Cocoa to C++ using CoreFoundation (CF) types.

* DumpRenderTree/mac/DumpRenderTree.mm:
(dump): Renamed serializeWebArchiveToXML() to
createXMLStringFromWebArchiveData() and added HardAutorelease()
to prevent leaks.
* DumpRenderTree/mac/WebArchiveDumpSupport.h:
(createXMLStringFromWebArchiveData): Renamed from
serializeWebArchiveToXML().  Changed to use CF types.
(createCFURLResponseFromResponseData): Renamed from
unarchiveNSURLResponseFromResponseData().  Changed to use CF
types for its parameter and return type.
* DumpRenderTree/mac/WebArchiveDumpSupport.mm: Replaced use of
NS objects with CF types.  It will be renamed to *.cpp in a
future commit.
(convertMIMEType): Changed to use case-insensitive string
comparisons.
(convertWebResourceDataToString):
(normalizeHTTPResponseHeaderFields):
(normalizeWebResourceURL):
(convertWebResourceResponseToDictionary):
(compareResourceURLs):
(createXMLStringFromWebArchiveData):
* DumpRenderTree/mac/WebArchiveDumpSupportMac.mm:
(createCFURLResponseFromResponseData): Renamed from
unarchiveNSURLResponseFromResponseData().  Changed to use CF
types for its parameter and return type.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkWebKitToolsChangeLog">trunk/WebKitTools/ChangeLog</a></li>
<li><a href="#trunkWebKitToolsDumpRenderTreemacDumpRenderTreemm">trunk/WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm</a></li>
<li><a href="#trunkWebKitToolsDumpRenderTreemacWebArchiveDumpSupporth">trunk/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.h</a></li>
<li><a href="#trunkWebKitToolsDumpRenderTreemacWebArchiveDumpSupportmm">trunk/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.mm</a></li>
<li><a href="#trunkWebKitToolsDumpRenderTreemacWebArchiveDumpSupportMacmm">trunk/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupportMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkWebKitToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/ChangeLog (70612 => 70613)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/ChangeLog        2010-10-27 05:29:25 UTC (rev 70612)
+++ trunk/WebKitTools/ChangeLog        2010-10-27 05:29:32 UTC (rev 70613)
</span><span class="lines">@@ -1,5 +1,43 @@
</span><span class="cx"> 2010-10-26  David Kilzer  &lt;ddkilzer@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Convert WebArchiveDumpSupport.mm from NS objects to CF types
+
+        Reviewed by Adam Roben.
+
+        Part 3 of 4: &lt;http://webkit.org/b/48278&gt; Convert DumpRenderTree webarchive code to CoreFoundation
+
+        In order to share WebArchive code between the Mac and Windows
+        ports, the code in WebArchiveDumpSupport.mm was converted from
+        Cocoa to C++ using CoreFoundation (CF) types.
+
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (dump): Renamed serializeWebArchiveToXML() to
+        createXMLStringFromWebArchiveData() and added HardAutorelease()
+        to prevent leaks.
+        * DumpRenderTree/mac/WebArchiveDumpSupport.h:
+        (createXMLStringFromWebArchiveData): Renamed from
+        serializeWebArchiveToXML().  Changed to use CF types.
+        (createCFURLResponseFromResponseData): Renamed from
+        unarchiveNSURLResponseFromResponseData().  Changed to use CF
+        types for its parameter and return type.
+        * DumpRenderTree/mac/WebArchiveDumpSupport.mm: Replaced use of
+        NS objects with CF types.  It will be renamed to *.cpp in a
+        future commit.
+        (convertMIMEType): Changed to use case-insensitive string
+        comparisons.
+        (convertWebResourceDataToString):
+        (normalizeHTTPResponseHeaderFields):
+        (normalizeWebResourceURL):
+        (convertWebResourceResponseToDictionary):
+        (compareResourceURLs):
+        (createXMLStringFromWebArchiveData):
+        * DumpRenderTree/mac/WebArchiveDumpSupportMac.mm:
+        (createCFURLResponseFromResponseData): Renamed from
+        unarchiveNSURLResponseFromResponseData().  Changed to use CF
+        types for its parameter and return type.
+
+2010-10-26  David Kilzer  &lt;ddkilzer@apple.com&gt;
+
</ins><span class="cx">         Extract use of NSKeyedUnarchiver from WebArchiveDumpSupport.mm
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Adam Roben.
</span></span></pre></div>
<a id="trunkWebKitToolsDumpRenderTreemacDumpRenderTreemm"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm (70612 => 70613)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm        2010-10-27 05:29:25 UTC (rev 70612)
+++ trunk/WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm        2010-10-27 05:29:32 UTC (rev 70613)
</span><span class="lines">@@ -54,6 +54,7 @@
</span><span class="cx"> #import &quot;WorkQueueItem.h&quot;
</span><span class="cx"> #import &lt;Carbon/Carbon.h&gt;
</span><span class="cx"> #import &lt;CoreFoundation/CoreFoundation.h&gt;
</span><ins>+#import &lt;WebCore/FoundationExtras.h&gt;
</ins><span class="cx"> #import &lt;WebKit/DOMElement.h&gt;
</span><span class="cx"> #import &lt;WebKit/DOMExtensions.h&gt;
</span><span class="cx"> #import &lt;WebKit/DOMRange.h&gt;
</span><span class="lines">@@ -920,11 +921,11 @@
</span><span class="cx">             resultMimeType = @&quot;application/pdf&quot;;
</span><span class="cx">         } else if (gLayoutTestController-&gt;dumpDOMAsWebArchive()) {
</span><span class="cx">             WebArchive *webArchive = [[mainFrame DOMDocument] webArchive];
</span><del>-            resultString = serializeWebArchiveToXML(webArchive);
</del><ins>+            resultString = HardAutorelease(createXMLStringFromWebArchiveData((CFDataRef)[webArchive data]));
</ins><span class="cx">             resultMimeType = @&quot;application/x-webarchive&quot;;
</span><span class="cx">         } else if (gLayoutTestController-&gt;dumpSourceAsWebArchive()) {
</span><span class="cx">             WebArchive *webArchive = [[mainFrame dataSource] webArchive];
</span><del>-            resultString = serializeWebArchiveToXML(webArchive);
</del><ins>+            resultString = HardAutorelease(createXMLStringFromWebArchiveData((CFDataRef)[webArchive data]));
</ins><span class="cx">             resultMimeType = @&quot;application/x-webarchive&quot;;
</span><span class="cx">         } else {
</span><span class="cx">             sizeWebViewForCurrentTest();
</span></span></pre></div>
<a id="trunkWebKitToolsDumpRenderTreemacWebArchiveDumpSupporth"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.h (70612 => 70613)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.h        2010-10-27 05:29:25 UTC (rev 70612)
+++ trunk/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.h        2010-10-27 05:29:32 UTC (rev 70613)
</span><span class="lines">@@ -28,17 +28,14 @@
</span><span class="cx"> 
</span><span class="cx"> #include &lt;CoreFoundation/CoreFoundation.h&gt;
</span><span class="cx"> 
</span><del>-@class NSData;
-@class NSString;
-@class NSURLResponse;
-@class WebArchive;
</del><ins>+typedef struct _CFURLResponse* CFURLResponseRef;
</ins><span class="cx"> 
</span><del>-NSString *serializeWebArchiveToXML(WebArchive *webArchive);
</del><ins>+CFStringRef createXMLStringFromWebArchiveData(CFDataRef webArchiveData);
</ins><span class="cx"> 
</span><span class="cx"> #pragma mark -
</span><span class="cx"> #pragma mark Platform-specific methods
</span><span class="cx"> 
</span><del>-NSURLResponse *unarchiveNSURLResponseFromResponseData(NSData *responseData);
</del><ins>+CFURLResponseRef createCFURLResponseFromResponseData(CFDataRef responseData);
</ins><span class="cx"> CFArrayRef supportedNonImageMIMETypes();
</span><span class="cx"> 
</span><span class="cx"> #endif /* WebArchiveDumpSupport_h */
</span></span></pre></div>
<a id="trunkWebKitToolsDumpRenderTreemacWebArchiveDumpSupportmm"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.mm (70612 => 70613)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.mm        2010-10-27 05:29:25 UTC (rev 70612)
+++ trunk/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.mm        2010-10-27 05:29:32 UTC (rev 70613)
</span><span class="lines">@@ -25,173 +25,191 @@
</span><span class="cx"> 
</span><span class="cx"> #import &quot;WebArchiveDumpSupport.h&quot;
</span><span class="cx"> 
</span><del>-#import &lt;Foundation/Foundation.h&gt;
-#import &lt;WebKit/WebArchive.h&gt;
</del><ins>+#import &lt;CoreFoundation/CoreFoundation.h&gt;
+#import &lt;CFNetwork/CFNetwork.h&gt;
+#import &lt;wtf/RetainPtr.h&gt;
</ins><span class="cx"> 
</span><del>-static void convertMIMEType(NSMutableString *mimeType)
</del><ins>+extern &quot;C&quot; {
+
+CFURLRef CFURLResponseGetURL(CFURLResponseRef response);
+CFStringRef CFURLResponseGetMIMEType(CFURLResponseRef response);
+CFStringRef CFURLResponseGetTextEncodingName(CFURLResponseRef response);
+SInt64 CFURLResponseGetExpectedContentLength(CFURLResponseRef response);
+CFHTTPMessageRef CFURLResponseGetHTTPResponse(CFURLResponseRef response);
+
+CFTypeID CFURLResponseGetTypeID(void);
+
+}
+
+static void convertMIMEType(CFMutableStringRef mimeType)
</ins><span class="cx"> {
</span><span class="cx"> #ifdef BUILDING_ON_LEOPARD
</span><span class="cx">     // Workaround for &lt;rdar://problem/5539824&gt; on Leopard
</span><del>-    if ([mimeType isEqualToString:@&quot;text/xml&quot;])
-        [mimeType setString:@&quot;application/xml&quot;];
</del><ins>+    if (CFStringCompare(mimeType, CFSTR(&quot;text/xml&quot;), kCFCompareAnchored | kCFCompareCaseInsensitive) == kCFCompareEqualTo)
+        CFStringReplaceAll(mimeType, CFSTR(&quot;application/xml&quot;));
</ins><span class="cx"> #endif
</span><span class="cx">     // Workaround for &lt;rdar://problem/6234318&gt; with Dashcode 2.0
</span><del>-    if ([mimeType isEqualToString:@&quot;application/x-javascript&quot;])
-        [mimeType setString:@&quot;text/javascript&quot;];
</del><ins>+    if (CFStringCompare(mimeType, CFSTR(&quot;application/x-javascript&quot;), kCFCompareAnchored | kCFCompareCaseInsensitive) == kCFCompareEqualTo)
+        CFStringReplaceAll(mimeType, CFSTR(&quot;text/javascript&quot;));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void convertWebResourceDataToString(NSMutableDictionary *resource)
</del><ins>+static void convertWebResourceDataToString(CFMutableDictionaryRef resource)
</ins><span class="cx"> {
</span><del>-    NSMutableString *mimeType = [resource objectForKey:@&quot;WebResourceMIMEType&quot;];
</del><ins>+    CFMutableStringRef mimeType = (CFMutableStringRef)CFDictionaryGetValue(resource, CFSTR(&quot;WebResourceMIMEType&quot;));
+    CFStringLowercase(mimeType, CFLocaleGetSystem());
</ins><span class="cx">     convertMIMEType(mimeType);
</span><span class="cx"> 
</span><del>-    if ([mimeType hasPrefix:@&quot;text/&quot;] || [(NSArray *)supportedNonImageMIMETypes() containsObject:mimeType]) {
-        NSString *textEncodingName = [resource objectForKey:@&quot;WebResourceTextEncodingName&quot;];
-        NSStringEncoding stringEncoding;
-        if ([textEncodingName length] &gt; 0)
-            stringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)textEncodingName));
</del><ins>+    CFArrayRef supportedMIMETypes = supportedNonImageMIMETypes();
+    if (CFStringHasPrefix(mimeType, CFSTR(&quot;text/&quot;)) || CFArrayContainsValue(supportedMIMETypes, CFRangeMake(0, CFArrayGetCount(supportedMIMETypes)), mimeType)) {
+        CFStringRef textEncodingName = static_cast&lt;CFStringRef&gt;(CFDictionaryGetValue(resource, CFSTR(&quot;WebResourceTextEncodingName&quot;)));
+        CFStringEncoding stringEncoding;
+        if (textEncodingName &amp;&amp; CFStringGetLength(textEncodingName))
+            stringEncoding = CFStringConvertIANACharSetNameToEncoding(textEncodingName);
</ins><span class="cx">         else
</span><del>-            stringEncoding = NSUTF8StringEncoding;
</del><ins>+            stringEncoding = kCFStringEncodingUTF8;
</ins><span class="cx"> 
</span><del>-        NSData *data = [resource objectForKey:@&quot;WebResourceData&quot;];
-        NSString *dataAsString = [[NSString alloc] initWithData:data encoding:stringEncoding];
</del><ins>+        CFDataRef data = static_cast&lt;CFDataRef&gt;(CFDictionaryGetValue(resource, CFSTR(&quot;WebResourceData&quot;)));
+        RetainPtr&lt;CFStringRef&gt; dataAsString(AdoptCF, CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, data, stringEncoding));
</ins><span class="cx">         if (dataAsString)
</span><del>-            [resource setObject:dataAsString forKey:@&quot;WebResourceData&quot;];
-        [dataAsString release];
</del><ins>+            CFDictionarySetValue(resource, CFSTR(&quot;WebResourceData&quot;), dataAsString.get());
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void normalizeHTTPResponseHeaderFields(NSMutableDictionary *fields)
</del><ins>+static void normalizeHTTPResponseHeaderFields(CFMutableDictionaryRef fields)
</ins><span class="cx"> {
</span><span class="cx">     // Normalize headers
</span><del>-    if ([fields objectForKey:@&quot;Date&quot;])
-        [fields setObject:@&quot;Sun, 16 Nov 2008 17:00:00 GMT&quot; forKey:@&quot;Date&quot;];
-    if ([fields objectForKey:@&quot;Last-Modified&quot;])
-        [fields setObject:@&quot;Sun, 16 Nov 2008 16:55:00 GMT&quot; forKey:@&quot;Last-Modified&quot;];
-    if ([fields objectForKey:@&quot;Etag&quot;])
-        [fields setObject:@&quot;\&quot;301925-21-45c7d72d3e780\&quot;&quot; forKey:@&quot;Etag&quot;];
-    if ([fields objectForKey:@&quot;Server&quot;])
-        [fields setObject:@&quot;Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7l PHP/5.2.6&quot; forKey:@&quot;Server&quot;];
</del><ins>+    if (CFDictionaryContainsKey(fields, CFSTR(&quot;Date&quot;)))
+        CFDictionarySetValue(fields, CFSTR(&quot;Date&quot;), CFSTR(&quot;Sun, 16 Nov 2008 17:00:00 GMT&quot;));
+    if (CFDictionaryContainsKey(fields, CFSTR(&quot;Last-Modified&quot;)))
+        CFDictionarySetValue(fields, CFSTR(&quot;Last-Modified&quot;), CFSTR(&quot;Sun, 16 Nov 2008 16:55:00 GMT&quot;));
+    if (CFDictionaryContainsKey(fields, CFSTR(&quot;Etag&quot;)))
+        CFDictionarySetValue(fields, CFSTR(&quot;Etag&quot;), CFSTR(&quot;\&quot;301925-21-45c7d72d3e780\&quot;&quot;));
+    if (CFDictionaryContainsKey(fields, CFSTR(&quot;Server&quot;)))
+        CFDictionarySetValue(fields, CFSTR(&quot;Server&quot;), CFSTR(&quot;Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7l PHP/5.2.6&quot;));
</ins><span class="cx"> 
</span><span class="cx">     // Remove headers
</span><del>-    if ([fields objectForKey:@&quot;Connection&quot;])
-        [fields removeObjectForKey:@&quot;Connection&quot;];
-    if ([fields objectForKey:@&quot;Keep-Alive&quot;])
-        [fields removeObjectForKey:@&quot;Keep-Alive&quot;];
</del><ins>+    CFDictionaryRemoveValue(fields, CFSTR(&quot;Connection&quot;));
+    CFDictionaryRemoveValue(fields, CFSTR(&quot;Keep-Alive&quot;));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void normalizeWebResourceURL(NSMutableString *webResourceURL)
</del><ins>+static void normalizeWebResourceURL(CFMutableStringRef webResourceURL)
</ins><span class="cx"> {
</span><del>-    static int fileUrlLength = [(NSString *)@&quot;file://&quot; length];
-    NSRange layoutTestsWebArchivePathRange = [webResourceURL rangeOfString:@&quot;/LayoutTests/&quot; options:NSBackwardsSearch];
-    if (layoutTestsWebArchivePathRange.location == NSNotFound)
</del><ins>+    static CFIndex fileUrlLength = CFStringGetLength(CFSTR(&quot;file://&quot;));
+    CFRange layoutTestsWebArchivePathRange = CFStringFind(webResourceURL, CFSTR(&quot;/LayoutTests/&quot;), kCFCompareBackwards);
+    if (layoutTestsWebArchivePathRange.location == kCFNotFound)
</ins><span class="cx">         return;
</span><del>-    NSRange currentWorkingDirectoryRange = NSMakeRange(fileUrlLength, layoutTestsWebArchivePathRange.location - fileUrlLength);
-    [webResourceURL replaceCharactersInRange:currentWorkingDirectoryRange withString:@&quot;&quot;];
</del><ins>+    CFRange currentWorkingDirectoryRange = CFRangeMake(fileUrlLength, layoutTestsWebArchivePathRange.location - fileUrlLength);
+    CFStringReplace(webResourceURL, currentWorkingDirectoryRange, CFSTR(&quot;&quot;));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void convertWebResourceResponseToDictionary(NSMutableDictionary *propertyList)
</del><ins>+static void convertWebResourceResponseToDictionary(CFMutableDictionaryRef propertyList)
</ins><span class="cx"> {
</span><del>-    NSData *responseData = [propertyList objectForKey:@&quot;WebResourceResponse&quot;]; // WebResourceResponseKey in WebResource.m
-    if (![responseData isKindOfClass:[NSData class]])
</del><ins>+    CFDataRef responseData = static_cast&lt;CFDataRef&gt;(CFDictionaryGetValue(propertyList, CFSTR(&quot;WebResourceResponse&quot;))); // WebResourceResponseKey in WebResource.m
+    if (CFGetTypeID(responseData) != CFDataGetTypeID())
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    NSURLResponse *response = unarchiveNSURLResponseFromResponseData(responseData);
</del><ins>+    RetainPtr&lt;CFURLResponseRef&gt; response(AdoptCF, createCFURLResponseFromResponseData(responseData));
</ins><span class="cx">     if (!response)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    NSMutableDictionary *responseDictionary = [[NSMutableDictionary alloc] init];
</del><ins>+    RetainPtr&lt;CFMutableDictionaryRef&gt; responseDictionary(AdoptCF, CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &amp;kCFTypeDictionaryKeyCallBacks, &amp;kCFTypeDictionaryValueCallBacks));
</ins><span class="cx"> 
</span><del>-    NSMutableString *urlString = [[[response URL] description] mutableCopy];
-    normalizeWebResourceURL(urlString);
-    [responseDictionary setObject:urlString forKey:@&quot;URL&quot;];
-    [urlString release];
</del><ins>+    RetainPtr&lt;CFMutableStringRef&gt; urlString(AdoptCF, CFStringCreateMutableCopy(kCFAllocatorDefault, 0, CFURLGetString(CFURLResponseGetURL(response.get()))));
+    normalizeWebResourceURL(urlString.get());
+    CFDictionarySetValue(responseDictionary.get(), CFSTR(&quot;URL&quot;), urlString.get());
</ins><span class="cx"> 
</span><del>-    NSMutableString *mimeTypeString = [[response MIMEType] mutableCopy];
-    convertMIMEType(mimeTypeString);
-    [responseDictionary setObject:mimeTypeString forKey:@&quot;MIMEType&quot;];
-    [mimeTypeString release];
</del><ins>+    RetainPtr&lt;CFMutableStringRef&gt; mimeTypeString(AdoptCF, CFStringCreateMutableCopy(kCFAllocatorDefault, 0, CFURLResponseGetMIMEType(response.get())));
+    convertMIMEType(mimeTypeString.get());
+    CFDictionarySetValue(responseDictionary.get(), CFSTR(&quot;MIMEType&quot;), mimeTypeString.get());
</ins><span class="cx"> 
</span><del>-    NSString *textEncodingName = [response textEncodingName];
</del><ins>+    CFStringRef textEncodingName = CFURLResponseGetTextEncodingName(response.get());
</ins><span class="cx">     if (textEncodingName)
</span><del>-        [responseDictionary setObject:textEncodingName forKey:@&quot;textEncodingName&quot;];
-    [responseDictionary setObject:[NSNumber numberWithLongLong:[response expectedContentLength]] forKey:@&quot;expectedContentLength&quot;];
</del><ins>+        CFDictionarySetValue(responseDictionary.get(), CFSTR(&quot;textEncodingName&quot;), textEncodingName);
</ins><span class="cx"> 
</span><del>-    if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
-        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
</del><ins>+    SInt64 expectedContentLength = CFURLResponseGetExpectedContentLength(response.get());
+    RetainPtr&lt;CFNumberRef&gt; expectedContentLengthNumber(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &amp;expectedContentLength));
+    CFDictionarySetValue(responseDictionary.get(), CFSTR(&quot;expectedContentLength&quot;), expectedContentLengthNumber.get());
</ins><span class="cx"> 
</span><del>-        NSMutableDictionary *allHeaderFields = [[httpResponse allHeaderFields] mutableCopy];
-        normalizeHTTPResponseHeaderFields(allHeaderFields);
-        [responseDictionary setObject:allHeaderFields forKey:@&quot;allHeaderFields&quot;];
-        [allHeaderFields release];
</del><ins>+    if (CFHTTPMessageRef httpMessage = CFURLResponseGetHTTPResponse(response.get())) {
+        RetainPtr&lt;CFDictionaryRef&gt; allHeaders(AdoptCF, CFHTTPMessageCopyAllHeaderFields(httpMessage));
+        RetainPtr&lt;CFMutableDictionaryRef&gt; allHeaderFields(AdoptCF, CFDictionaryCreateMutableCopy(kCFAllocatorDefault, 0, allHeaders.get()));
+        normalizeHTTPResponseHeaderFields(allHeaderFields.get());
+        CFDictionarySetValue(responseDictionary.get(), CFSTR(&quot;allHeaderFields&quot;), allHeaderFields.get());
</ins><span class="cx"> 
</span><del>-        [responseDictionary setObject:[NSNumber numberWithInt:[httpResponse statusCode]] forKey:@&quot;statusCode&quot;];
</del><ins>+        CFIndex statusCode = CFHTTPMessageGetResponseStatusCode(httpMessage);
+        RetainPtr&lt;CFNumberRef&gt; statusCodeNumber(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberCFIndexType, &amp;statusCode));
+        CFDictionarySetValue(responseDictionary.get(), CFSTR(&quot;statusCode&quot;), statusCodeNumber.get());
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    [propertyList setObject:responseDictionary forKey:@&quot;WebResourceResponse&quot;];
-    [responseDictionary release];
</del><ins>+    CFDictionarySetValue(propertyList, CFSTR(&quot;WebResourceResponse&quot;), responseDictionary.get());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-static NSInteger compareResourceURLs(id resource1, id resource2, void *context)
</del><ins>+static CFComparisonResult compareResourceURLs(const void *val1, const void *val2, void *context)
</ins><span class="cx"> {
</span><del>-    NSString *url1 = [resource1 objectForKey:@&quot;WebResourceURL&quot;];
-    NSString *url2 = [resource2 objectForKey:@&quot;WebResourceURL&quot;];
</del><ins>+    CFStringRef url1 = static_cast&lt;CFStringRef&gt;(CFDictionaryGetValue(static_cast&lt;CFDictionaryRef&gt;(val1), CFSTR(&quot;WebResourceURL&quot;)));
+    CFStringRef url2 = static_cast&lt;CFStringRef&gt;(CFDictionaryGetValue(static_cast&lt;CFDictionaryRef&gt;(val2), CFSTR(&quot;WebResourceURL&quot;)));
</ins><span class="cx">  
</span><del>-    return [url1 compare:url2];
</del><ins>+    return CFStringCompare(url1, url2, kCFCompareAnchored);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-NSString *serializeWebArchiveToXML(WebArchive *webArchive)
</del><ins>+CFStringRef createXMLStringFromWebArchiveData(CFDataRef webArchiveData)
</ins><span class="cx"> {
</span><del>-    NSString *errorString;
-    NSMutableDictionary *propertyList = [NSPropertyListSerialization propertyListFromData:[webArchive data]
-                                                                         mutabilityOption:NSPropertyListMutableContainersAndLeaves
-                                                                                   format:NULL
-                                                                         errorDescription:&amp;errorString];
-    if (!propertyList)
-        return errorString;
</del><ins>+    CFErrorRef error = 0;
+    CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
+    CFMutableDictionaryRef propertyList = (CFMutableDictionaryRef)CFPropertyListCreateWithData(kCFAllocatorDefault, webArchiveData, kCFPropertyListMutableContainersAndLeaves, &amp;format, &amp;error);
</ins><span class="cx"> 
</span><del>-    NSMutableArray *resources = [NSMutableArray arrayWithCapacity:1];
-    [resources addObject:propertyList];
</del><ins>+    if (!propertyList) {
+        if (error)
+            return CFErrorCopyDescription(error);
+        return static_cast&lt;CFStringRef&gt;(CFRetain(CFSTR(&quot;An unknown error occurred converting data to property list.&quot;)));
+    }
</ins><span class="cx"> 
</span><del>-    while ([resources count]) {
-        NSMutableDictionary *resourcePropertyList = [resources objectAtIndex:0];
-        [resources removeObjectAtIndex:0];
</del><ins>+    RetainPtr&lt;CFMutableArrayRef&gt; resources(AdoptCF, CFArrayCreateMutable(kCFAllocatorDefault, 0, &amp;kCFTypeArrayCallBacks));
+    CFArrayAppendValue(resources.get(), propertyList);
</ins><span class="cx"> 
</span><del>-        NSMutableDictionary *mainResource = [resourcePropertyList objectForKey:@&quot;WebMainResource&quot;];
-        normalizeWebResourceURL([mainResource objectForKey:@&quot;WebResourceURL&quot;]);
</del><ins>+    while (CFArrayGetCount(resources.get())) {
+        RetainPtr&lt;CFMutableDictionaryRef&gt; resourcePropertyList = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(resources.get(), 0);
+        CFArrayRemoveValueAtIndex(resources.get(), 0);
+
+        CFMutableDictionaryRef mainResource = (CFMutableDictionaryRef)CFDictionaryGetValue(resourcePropertyList.get(), CFSTR(&quot;WebMainResource&quot;));
+        normalizeWebResourceURL((CFMutableStringRef)CFDictionaryGetValue(mainResource, CFSTR(&quot;WebResourceURL&quot;)));
</ins><span class="cx">         convertWebResourceDataToString(mainResource);
</span><span class="cx"> 
</span><span class="cx">         // Add subframeArchives to list for processing
</span><del>-        NSMutableArray *subframeArchives = [resourcePropertyList objectForKey:@&quot;WebSubframeArchives&quot;]; // WebSubframeArchivesKey in WebArchive.m
</del><ins>+        CFMutableArrayRef subframeArchives = (CFMutableArrayRef)CFDictionaryGetValue(resourcePropertyList.get(), CFSTR(&quot;WebSubframeArchives&quot;)); // WebSubframeArchivesKey in WebArchive.m
</ins><span class="cx">         if (subframeArchives)
</span><del>-            [resources addObjectsFromArray:subframeArchives];
</del><ins>+            CFArrayAppendArray(resources.get(), subframeArchives, CFRangeMake(0, CFArrayGetCount(subframeArchives)));
</ins><span class="cx"> 
</span><del>-        NSMutableArray *subresources = [resourcePropertyList objectForKey:@&quot;WebSubresources&quot;]; // WebSubresourcesKey in WebArchive.m
-        NSEnumerator *enumerator = [subresources objectEnumerator];
-        NSMutableDictionary *subresourcePropertyList;
-        while ((subresourcePropertyList = [enumerator nextObject])) {
-            normalizeWebResourceURL([subresourcePropertyList objectForKey:@&quot;WebResourceURL&quot;]);
</del><ins>+        CFMutableArrayRef subresources = (CFMutableArrayRef)CFDictionaryGetValue(resourcePropertyList.get(), CFSTR(&quot;WebSubresources&quot;)); // WebSubresourcesKey in WebArchive.m
+        if (!subresources)
+            continue;
+
+        CFIndex subresourcesCount = CFArrayGetCount(subresources);
+        for (CFIndex i = 0; i &lt; subresourcesCount; ++i) {
+            CFMutableDictionaryRef subresourcePropertyList = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(subresources, i);
+            normalizeWebResourceURL((CFMutableStringRef)CFDictionaryGetValue(subresourcePropertyList, CFSTR(&quot;WebResourceURL&quot;)));
</ins><span class="cx">             convertWebResourceResponseToDictionary(subresourcePropertyList);
</span><span class="cx">             convertWebResourceDataToString(subresourcePropertyList);
</span><span class="cx">         }
</span><del>-        
</del><ins>+
</ins><span class="cx">         // Sort the subresources so they're always in a predictable order for the dump
</span><del>-        if (NSArray *sortedSubresources = [subresources sortedArrayUsingFunction:compareResourceURLs context:nil])
-            [resourcePropertyList setObject:sortedSubresources forKey:@&quot;WebSubresources&quot;];
</del><ins>+        CFArraySortValues(subresources, CFRangeMake(0, CFArrayGetCount(subresources)), compareResourceURLs, 0);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    NSData *xmlData = [NSPropertyListSerialization dataFromPropertyList:propertyList
-                                                                 format:NSPropertyListXMLFormat_v1_0
-                                                       errorDescription:&amp;errorString];
-    if (!xmlData)
-        return errorString;
</del><ins>+    error = 0;
+    RetainPtr&lt;CFDataRef&gt; xmlData(AdoptCF, CFPropertyListCreateData(kCFAllocatorDefault, propertyList, kCFPropertyListXMLFormat_v1_0, 0, &amp;error));
</ins><span class="cx"> 
</span><del>-    NSMutableString *string = [[[NSMutableString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding] autorelease];
</del><ins>+    if (!xmlData) {
+        if (error)
+            return CFErrorCopyDescription(error);
+        return static_cast&lt;CFStringRef&gt;(CFRetain(CFSTR(&quot;An unknown error occurred converting property list to data.&quot;)));
+    }
</ins><span class="cx"> 
</span><ins>+    RetainPtr&lt;CFStringRef&gt; xmlString(AdoptCF, CFStringCreateFromExternalRepresentation(kCFAllocatorDefault, xmlData.get(), kCFStringEncodingUTF8));
+    RetainPtr&lt;CFMutableStringRef&gt; string(AdoptCF, CFStringCreateMutableCopy(kCFAllocatorDefault, 0, xmlString.get()));
+
</ins><span class="cx">     // Replace &quot;Apple Computer&quot; with &quot;Apple&quot; in the DTD declaration.
</span><del>-    NSRange range = [string rangeOfString:@&quot;-//Apple Computer//&quot;];
-    if (range.location != NSNotFound)
-        [string replaceCharactersInRange:range withString:@&quot;-//Apple//&quot;];
-    
-    return string;
</del><ins>+    CFStringFindAndReplace(string.get(), CFSTR(&quot;-//Apple Computer//&quot;), CFSTR(&quot;-//Apple//&quot;), CFRangeMake(0, CFStringGetLength(string.get())), 0);
+
+    return string.releaseRef();
</ins><span class="cx"> }
</span></span></pre></div>
<a id="trunkWebKitToolsDumpRenderTreemacWebArchiveDumpSupportMacmm"></a>
<div class="modfile"><h4>Modified: trunk/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupportMac.mm (70612 => 70613)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupportMac.mm        2010-10-27 05:29:25 UTC (rev 70612)
+++ trunk/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupportMac.mm        2010-10-27 05:29:32 UTC (rev 70613)
</span><span class="lines">@@ -25,18 +25,49 @@
</span><span class="cx"> 
</span><span class="cx"> #import &quot;WebArchiveDumpSupport.h&quot;
</span><span class="cx"> 
</span><ins>+#import &lt;CFNetwork/CFHTTPMessage.h&gt;
</ins><span class="cx"> #import &lt;Foundation/Foundation.h&gt;
</span><span class="cx"> #import &lt;WebKit/WebHTMLRepresentation.h&gt;
</span><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> 
</span><del>-NSURLResponse *unarchiveNSURLResponseFromResponseData(NSData *responseData)
</del><ins>+extern &quot;C&quot; {
+
+enum CFURLCacheStoragePolicy {
+  kCFURLCacheStorageAllowed = 0,
+  kCFURLCacheStorageAllowedInMemoryOnly = 1,
+  kCFURLCacheStorageNotAllowed = 2
+};
+typedef enum CFURLCacheStoragePolicy CFURLCacheStoragePolicy;
+
+extern const CFStringRef kCFHTTPVersion1_1;
+
+CFURLResponseRef CFURLResponseCreate(CFAllocatorRef alloc, CFURLRef URL, CFStringRef mimeType, SInt64 expectedContentLength, CFStringRef textEncodingName, CFURLCacheStoragePolicy recommendedPolicy);
+CFURLResponseRef CFURLResponseCreateWithHTTPResponse(CFAllocatorRef alloc, CFURLRef URL, CFHTTPMessageRef httpResponse, CFURLCacheStoragePolicy recommendedPolicy);
+void CFURLResponseSetExpectedContentLength(CFURLResponseRef response, SInt64 length);
+void CFURLResponseSetMIMEType(CFURLResponseRef response, CFStringRef mimeType);
+
+}
+
+CFURLResponseRef createCFURLResponseFromResponseData(CFDataRef responseData)
</ins><span class="cx"> {
</span><span class="cx">     // Decode NSURLResponse
</span><del>-    RetainPtr&lt;NSKeyedUnarchiver&gt; unarchiver(AdoptNS, [[NSKeyedUnarchiver alloc] initForReadingWithData:responseData]);
</del><ins>+    RetainPtr&lt;NSKeyedUnarchiver&gt; unarchiver(AdoptNS, [[NSKeyedUnarchiver alloc] initForReadingWithData:(NSData *)responseData]);
</ins><span class="cx">     NSURLResponse *response = [unarchiver.get() decodeObjectForKey:@&quot;WebResourceResponse&quot;]; // WebResourceResponseKey in WebResource.m
</span><span class="cx">     [unarchiver.get() finishDecoding];
</span><span class="cx"> 
</span><del>-    return response;
</del><ins>+    if (![response isKindOfClass:[NSHTTPURLResponse class]])
+        return CFURLResponseCreate(kCFAllocatorDefault, (CFURLRef)[response URL], (CFStringRef)[response MIMEType], [response expectedContentLength], (CFStringRef)[response textEncodingName], kCFURLCacheStorageAllowed);
+
+    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
+
+    // NSURLResponse is not toll-free bridged to CFURLResponse.
+    RetainPtr&lt;CFHTTPMessageRef&gt; httpMessage(AdoptCF, CFHTTPMessageCreateResponse(kCFAllocatorDefault, [httpResponse statusCode], 0, kCFHTTPVersion1_1));
+
+    NSDictionary *headerFields = [httpResponse allHeaderFields];
+    for (NSString *headerField in [headerFields keyEnumerator])
+        CFHTTPMessageSetHeaderFieldValue(httpMessage.get(), (CFStringRef)headerField, (CFStringRef)[headerFields objectForKey:headerField]);
+
+    return CFURLResponseCreateWithHTTPResponse(kCFAllocatorDefault, (CFURLRef)[response URL], httpMessage.get(), kCFURLCacheStorageAllowed);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> CFArrayRef supportedNonImageMIMETypes()
</span></span></pre>
</div>
</div>

</body>
</html>