[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

ddkilzer at apple.com ddkilzer at apple.com
Wed Dec 22 14:18:19 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit b58db639e4b03731639631728acc08b0224dfaf8
Author: ddkilzer at apple.com <ddkilzer at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Oct 6 16:32:18 2010 +0000

    Move WebArchive serialization code into its own file
    
    Reviewed by Adam Roben.
    
    This is the first step in making webarchive tests work on
    Windows.
    
    * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj: Added
    new files to the project.
    * DumpRenderTree/mac/DumpRenderTree.mm: Removed code that moved
    to WebArchiveDumpSupport.mm.
    * DumpRenderTree/mac/WebArchiveDumpSupport.h: Added.
    * DumpRenderTree/mac/WebArchiveDumpSupport.mm: Copied from WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm.
    (serializeWebArchiveToXML):
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@69199 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 2a31621..8e9c710 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,20 @@
+2010-10-06  David Kilzer  <ddkilzer at apple.com>
+
+        Move WebArchive serialization code into its own file
+
+        Reviewed by Adam Roben.
+
+        This is the first step in making webarchive tests work on
+        Windows.
+
+        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj: Added
+        new files to the project.
+        * DumpRenderTree/mac/DumpRenderTree.mm: Removed code that moved
+        to WebArchiveDumpSupport.mm.
+        * DumpRenderTree/mac/WebArchiveDumpSupport.h: Added.
+        * DumpRenderTree/mac/WebArchiveDumpSupport.mm: Copied from WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm.
+        (serializeWebArchiveToXML):
+
 2010-10-05  Daniel Bates  <dbates at rim.com>
 
         Reviewed by David Kilzer.
diff --git a/WebKitTools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj b/WebKitTools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj
index c01ca4e..acdac3d 100644
--- a/WebKitTools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj
+++ b/WebKitTools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj
@@ -48,6 +48,8 @@
 		29CFBA2E12273A1000BC30C0 /* AccessibilityTextMarkerMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 29CFBA2D12273A1000BC30C0 /* AccessibilityTextMarkerMac.mm */; };
 		3713EDE2115BE19300705720 /* ColorBits-A.png in Copy Font Files */ = {isa = PBXBuildFile; fileRef = 3713EDDF115BE16F00705720 /* ColorBits-A.png */; };
 		3713EDE3115BE19300705720 /* ColorBits.ttf in Copy Font Files */ = {isa = PBXBuildFile; fileRef = 3713EDE0115BE16F00705720 /* ColorBits.ttf */; };
+		4437730E125CBC3600AAE02C /* WebArchiveDumpSupport.mm in Sources */ = {isa = PBXBuildFile; fileRef = 44A997830FCDE86400580F10 /* WebArchiveDumpSupport.mm */; };
+		4437730F125CBC4D00AAE02C /* WebArchiveDumpSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = 44A997820FCDE86400580F10 /* WebArchiveDumpSupport.h */; };
 		5185F6B210714E07007AA393 /* HistoryDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5185F69F10714A57007AA393 /* HistoryDelegate.mm */; };
 		5185F6B310714E12007AA393 /* HistoryDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 5185F69E10714A57007AA393 /* HistoryDelegate.h */; };
 		5DB9AC970F722C3600684641 /* AHEM____.TTF in Copy Font Files */ = {isa = PBXBuildFile; fileRef = AA7F10C20CB3C1030003BDC9 /* AHEM____.TTF */; };
@@ -220,6 +222,8 @@
 		375F09770DAC3CB600C8B4E5 /* WebKitWeightWatcher700.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = WebKitWeightWatcher700.ttf; path = fonts/WebKitWeightWatcher700.ttf; sourceTree = "<group>"; };
 		375F09780DAC3CB600C8B4E5 /* WebKitWeightWatcher800.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = WebKitWeightWatcher800.ttf; path = fonts/WebKitWeightWatcher800.ttf; sourceTree = "<group>"; };
 		375F09790DAC3CB600C8B4E5 /* WebKitWeightWatcher900.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = WebKitWeightWatcher900.ttf; path = fonts/WebKitWeightWatcher900.ttf; sourceTree = "<group>"; };
+		44A997820FCDE86400580F10 /* WebArchiveDumpSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebArchiveDumpSupport.h; path = mac/WebArchiveDumpSupport.h; sourceTree = "<group>"; };
+		44A997830FCDE86400580F10 /* WebArchiveDumpSupport.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WebArchiveDumpSupport.mm; path = mac/WebArchiveDumpSupport.mm; sourceTree = "<group>"; };
 		5185F69E10714A57007AA393 /* HistoryDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HistoryDelegate.h; path = mac/HistoryDelegate.h; sourceTree = "<group>"; };
 		5185F69F10714A57007AA393 /* HistoryDelegate.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; name = HistoryDelegate.mm; path = mac/HistoryDelegate.mm; sourceTree = "<group>"; };
 		8465E2C60FFA8DF2003B8342 /* PixelDumpSupport.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 30; path = PixelDumpSupport.cpp; sourceTree = "<group>"; };
@@ -358,6 +362,8 @@
 				BCA18B740C9B08F100114369 /* DumpRenderTreeDraggingInfo.mm */,
 				A8D79CE80FC28B2C004AC8FE /* DumpRenderTreeFileDraggingSource.h */,
 				A8D79CE90FC28B2C004AC8FE /* DumpRenderTreeFileDraggingSource.m */,
+				44A997820FCDE86400580F10 /* WebArchiveDumpSupport.h */,
+				44A997830FCDE86400580F10 /* WebArchiveDumpSupport.mm */,
 				BC9D90210C97472D0099A4A3 /* WorkQueue.cpp */,
 				BC9D90220C97472E0099A4A3 /* WorkQueue.h */,
 				BC9D90230C97472E0099A4A3 /* WorkQueueItem.h */,
@@ -590,6 +596,7 @@
 				BCA18B670C9B08C200114369 /* ResourceLoadDelegate.h in Headers */,
 				BCA18B3C0C9B024900114369 /* TextInputController.h in Headers */,
 				BCA18B690C9B08C200114369 /* UIDelegate.h in Headers */,
+				4437730F125CBC4D00AAE02C /* WebArchiveDumpSupport.h in Headers */,
 				BC9D90250C97472E0099A4A3 /* WorkQueue.h in Headers */,
 				BC9D90260C97472E0099A4A3 /* WorkQueueItem.h in Headers */,
 				5185F6B310714E12007AA393 /* HistoryDelegate.h in Headers */,
@@ -764,6 +771,7 @@
 				BCA18B680C9B08C200114369 /* ResourceLoadDelegate.mm in Sources */,
 				BCA18B490C9B02C400114369 /* TextInputController.m in Sources */,
 				BCA18B6A0C9B08C200114369 /* UIDelegate.mm in Sources */,
+				4437730E125CBC3600AAE02C /* WebArchiveDumpSupport.mm in Sources */,
 				BC9D90240C97472E0099A4A3 /* WorkQueue.cpp in Sources */,
 				BCA18B260C9B015C00114369 /* WorkQueueItemMac.mm in Sources */,
 				5185F6B210714E07007AA393 /* HistoryDelegate.mm in Sources */,
diff --git a/WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm b/WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm
index 3732247..68765f6 100644
--- a/WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm
+++ b/WebKitTools/DumpRenderTree/mac/DumpRenderTree.mm
@@ -49,6 +49,7 @@
 #import "PolicyDelegate.h"
 #import "ResourceLoadDelegate.h"
 #import "UIDelegate.h"
+#import "WebArchiveDumpSupport.h"
 #import "WorkQueue.h"
 #import "WorkQueueItem.h"
 #import <Carbon/Carbon.h>
@@ -56,6 +57,7 @@
 #import <WebKit/DOMElement.h>
 #import <WebKit/DOMExtensions.h>
 #import <WebKit/DOMRange.h>
+#import <WebKit/WebArchive.h>
 #import <WebKit/WebBackForwardList.h>
 #import <WebKit/WebCache.h>
 #import <WebKit/WebCoreStatistics.h>
@@ -65,7 +67,6 @@
 #import <WebKit/WebDeviceOrientationProviderMock.h>
 #import <WebKit/WebEditingDelegate.h>
 #import <WebKit/WebFrameView.h>
-#import <WebKit/WebHTMLRepresentationInternal.h>
 #import <WebKit/WebHistory.h>
 #import <WebKit/WebHistoryItemPrivate.h>
 #import <WebKit/WebInspector.h>
@@ -822,176 +823,6 @@ static NSData *dumpFrameAsPDF(WebFrame *frame)
     return pdfData;
 }
 
-static void convertMIMEType(NSMutableString *mimeType)
-{
-#ifdef BUILDING_ON_LEOPARD
-    // Workaround for <rdar://problem/5539824> on Leopard
-    if ([mimeType isEqualToString:@"text/xml"])
-        [mimeType setString:@"application/xml"];
-#endif
-    // Workaround for <rdar://problem/6234318> with Dashcode 2.0
-    if ([mimeType isEqualToString:@"application/x-javascript"])
-        [mimeType setString:@"text/javascript"];
-}
-
-static void convertWebResourceDataToString(NSMutableDictionary *resource)
-{
-    NSMutableString *mimeType = [resource objectForKey:@"WebResourceMIMEType"];
-    convertMIMEType(mimeType);
-
-    if ([mimeType hasPrefix:@"text/"] || [[WebHTMLRepresentation supportedNonImageMIMETypes] containsObject:mimeType]) {
-        NSString *textEncodingName = [resource objectForKey:@"WebResourceTextEncodingName"];
-        NSStringEncoding stringEncoding;
-        if ([textEncodingName length] > 0)
-            stringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)textEncodingName));
-        else
-            stringEncoding = NSUTF8StringEncoding;
-
-        NSData *data = [resource objectForKey:@"WebResourceData"];
-        NSString *dataAsString = [[NSString alloc] initWithData:data encoding:stringEncoding];
-        if (dataAsString)
-            [resource setObject:dataAsString forKey:@"WebResourceData"];
-        [dataAsString release];
-    }
-}
-
-static void normalizeHTTPResponseHeaderFields(NSMutableDictionary *fields)
-{
-    // Normalize headers
-    if ([fields objectForKey:@"Date"])
-        [fields setObject:@"Sun, 16 Nov 2008 17:00:00 GMT" forKey:@"Date"];
-    if ([fields objectForKey:@"Last-Modified"])
-        [fields setObject:@"Sun, 16 Nov 2008 16:55:00 GMT" forKey:@"Last-Modified"];
-    if ([fields objectForKey:@"Etag"])
-        [fields setObject:@"\"301925-21-45c7d72d3e780\"" forKey:@"Etag"];
-    if ([fields objectForKey:@"Server"])
-        [fields setObject:@"Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7l PHP/5.2.6" forKey:@"Server"];
-
-    // Remove headers
-    if ([fields objectForKey:@"Connection"])
-        [fields removeObjectForKey:@"Connection"];
-    if ([fields objectForKey:@"Keep-Alive"])
-        [fields removeObjectForKey:@"Keep-Alive"];
-}
-
-static void normalizeWebResourceURL(NSMutableString *webResourceURL)
-{
-    static int fileUrlLength = [(NSString *)@"file://" length];
-    NSRange layoutTestsWebArchivePathRange = [webResourceURL rangeOfString:@"/LayoutTests/" options:NSBackwardsSearch];
-    if (layoutTestsWebArchivePathRange.location == NSNotFound)
-        return;
-    NSRange currentWorkingDirectoryRange = NSMakeRange(fileUrlLength, layoutTestsWebArchivePathRange.location - fileUrlLength);
-    [webResourceURL replaceCharactersInRange:currentWorkingDirectoryRange withString:@""];
-}
-
-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];
-    }        
-
-    NSMutableDictionary *responseDictionary = [[NSMutableDictionary alloc] init];
-
-    NSMutableString *urlString = [[[response URL] description] mutableCopy];
-    normalizeWebResourceURL(urlString);
-    [responseDictionary setObject:urlString forKey:@"URL"];
-    [urlString release];
-
-    NSMutableString *mimeTypeString = [[response MIMEType] mutableCopy];
-    convertMIMEType(mimeTypeString);
-    [responseDictionary setObject:mimeTypeString forKey:@"MIMEType"];
-    [mimeTypeString release];
-
-    NSString *textEncodingName = [response textEncodingName];
-    if (textEncodingName)
-        [responseDictionary setObject:textEncodingName forKey:@"textEncodingName"];
-    [responseDictionary setObject:[NSNumber numberWithLongLong:[response expectedContentLength]] forKey:@"expectedContentLength"];
-
-    if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
-        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
-
-        NSMutableDictionary *allHeaderFields = [[httpResponse allHeaderFields] mutableCopy];
-        normalizeHTTPResponseHeaderFields(allHeaderFields);
-        [responseDictionary setObject:allHeaderFields forKey:@"allHeaderFields"];
-        [allHeaderFields release];
-
-        [responseDictionary setObject:[NSNumber numberWithInt:[httpResponse statusCode]] forKey:@"statusCode"];
-    }
-
-    [propertyList setObject:responseDictionary forKey:@"WebResourceResponse"];
-    [responseDictionary release];
-}
-
-static NSInteger compareResourceURLs(id resource1, id resource2, void *context)
-{
-    NSString *url1 = [resource1 objectForKey:@"WebResourceURL"];
-    NSString *url2 = [resource2 objectForKey:@"WebResourceURL"];
- 
-    return [url1 compare:url2];
-}
-
-static NSString *serializeWebArchiveToXML(WebArchive *webArchive)
-{
-    NSString *errorString;
-    NSMutableDictionary *propertyList = [NSPropertyListSerialization propertyListFromData:[webArchive data]
-                                                                         mutabilityOption:NSPropertyListMutableContainersAndLeaves
-                                                                                   format:NULL
-                                                                         errorDescription:&errorString];
-    if (!propertyList)
-        return errorString;
-
-    NSMutableArray *resources = [NSMutableArray arrayWithCapacity:1];
-    [resources addObject:propertyList];
-
-    while ([resources count]) {
-        NSMutableDictionary *resourcePropertyList = [resources objectAtIndex:0];
-        [resources removeObjectAtIndex:0];
-
-        NSMutableDictionary *mainResource = [resourcePropertyList objectForKey:@"WebMainResource"];
-        normalizeWebResourceURL([mainResource objectForKey:@"WebResourceURL"]);
-        convertWebResourceDataToString(mainResource);
-
-        // Add subframeArchives to list for processing
-        NSMutableArray *subframeArchives = [resourcePropertyList objectForKey:@"WebSubframeArchives"]; // WebSubframeArchivesKey in WebArchive.m
-        if (subframeArchives)
-            [resources addObjectsFromArray:subframeArchives];
-
-        NSMutableArray *subresources = [resourcePropertyList objectForKey:@"WebSubresources"]; // WebSubresourcesKey in WebArchive.m
-        NSEnumerator *enumerator = [subresources objectEnumerator];
-        NSMutableDictionary *subresourcePropertyList;
-        while ((subresourcePropertyList = [enumerator nextObject])) {
-            normalizeWebResourceURL([subresourcePropertyList objectForKey:@"WebResourceURL"]);
-            convertWebResourceResponseToDictionary(subresourcePropertyList);
-            convertWebResourceDataToString(subresourcePropertyList);
-        }
-        
-        // Sort the subresources so they're always in a predictable order for the dump
-        if (NSArray *sortedSubresources = [subresources sortedArrayUsingFunction:compareResourceURLs context:nil])
-            [resourcePropertyList setObject:sortedSubresources forKey:@"WebSubresources"];
-    }
-
-    NSData *xmlData = [NSPropertyListSerialization dataFromPropertyList:propertyList
-                                                                 format:NSPropertyListXMLFormat_v1_0
-                                                       errorDescription:&errorString];
-    if (!xmlData)
-        return errorString;
-
-    NSMutableString *string = [[[NSMutableString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding] autorelease];
-
-    // Replace "Apple Computer" with "Apple" in the DTD declaration.
-    NSRange range = [string rangeOfString:@"-//Apple Computer//"];
-    if (range.location != NSNotFound)
-        [string replaceCharactersInRange:range withString:@"-//Apple//"];
-    
-    return string;
-}
-
 static void dumpBackForwardListForWebView(WebView *view)
 {
     printf("\n============== Back Forward List ==============\n");
diff --git a/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.h b/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.h
new file mode 100644
index 0000000..8654dd5
--- /dev/null
+++ b/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2007, 2008, 2009, 2010 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 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 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.
+ */
+
+#ifndef WebArchiveDumpSupport_h
+#define WebArchiveDumpSupport_h
+
+ at class NSString;
+ at class WebArchive;
+
+NSString *serializeWebArchiveToXML(WebArchive *webArchive);
+
+#endif /* WebArchiveDumpSupport_h */
diff --git a/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.mm b/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.mm
new file mode 100644
index 0000000..7c52c6a
--- /dev/null
+++ b/WebKitTools/DumpRenderTree/mac/WebArchiveDumpSupport.mm
@@ -0,0 +1,200 @@
+/*
+ * Copyright (C) 2007, 2008, 2009, 2010 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 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 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 "WebArchiveDumpSupport.h"
+
+#import <Foundation/Foundation.h>
+#import <WebKit/WebArchive.h>
+#import <WebKit/WebHTMLRepresentationInternal.h>
+
+static void convertMIMEType(NSMutableString *mimeType)
+{
+#ifdef BUILDING_ON_LEOPARD
+    // Workaround for <rdar://problem/5539824> on Leopard
+    if ([mimeType isEqualToString:@"text/xml"])
+        [mimeType setString:@"application/xml"];
+#endif
+    // Workaround for <rdar://problem/6234318> with Dashcode 2.0
+    if ([mimeType isEqualToString:@"application/x-javascript"])
+        [mimeType setString:@"text/javascript"];
+}
+
+static void convertWebResourceDataToString(NSMutableDictionary *resource)
+{
+    NSMutableString *mimeType = [resource objectForKey:@"WebResourceMIMEType"];
+    convertMIMEType(mimeType);
+
+    if ([mimeType hasPrefix:@"text/"] || [[WebHTMLRepresentation supportedNonImageMIMETypes] containsObject:mimeType]) {
+        NSString *textEncodingName = [resource objectForKey:@"WebResourceTextEncodingName"];
+        NSStringEncoding stringEncoding;
+        if ([textEncodingName length] > 0)
+            stringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)textEncodingName));
+        else
+            stringEncoding = NSUTF8StringEncoding;
+
+        NSData *data = [resource objectForKey:@"WebResourceData"];
+        NSString *dataAsString = [[NSString alloc] initWithData:data encoding:stringEncoding];
+        if (dataAsString)
+            [resource setObject:dataAsString forKey:@"WebResourceData"];
+        [dataAsString release];
+    }
+}
+
+static void normalizeHTTPResponseHeaderFields(NSMutableDictionary *fields)
+{
+    // Normalize headers
+    if ([fields objectForKey:@"Date"])
+        [fields setObject:@"Sun, 16 Nov 2008 17:00:00 GMT" forKey:@"Date"];
+    if ([fields objectForKey:@"Last-Modified"])
+        [fields setObject:@"Sun, 16 Nov 2008 16:55:00 GMT" forKey:@"Last-Modified"];
+    if ([fields objectForKey:@"Etag"])
+        [fields setObject:@"\"301925-21-45c7d72d3e780\"" forKey:@"Etag"];
+    if ([fields objectForKey:@"Server"])
+        [fields setObject:@"Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7l PHP/5.2.6" forKey:@"Server"];
+
+    // Remove headers
+    if ([fields objectForKey:@"Connection"])
+        [fields removeObjectForKey:@"Connection"];
+    if ([fields objectForKey:@"Keep-Alive"])
+        [fields removeObjectForKey:@"Keep-Alive"];
+}
+
+static void normalizeWebResourceURL(NSMutableString *webResourceURL)
+{
+    static int fileUrlLength = [(NSString *)@"file://" length];
+    NSRange layoutTestsWebArchivePathRange = [webResourceURL rangeOfString:@"/LayoutTests/" options:NSBackwardsSearch];
+    if (layoutTestsWebArchivePathRange.location == NSNotFound)
+        return;
+    NSRange currentWorkingDirectoryRange = NSMakeRange(fileUrlLength, layoutTestsWebArchivePathRange.location - fileUrlLength);
+    [webResourceURL replaceCharactersInRange:currentWorkingDirectoryRange withString:@""];
+}
+
+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];
+    }        
+
+    NSMutableDictionary *responseDictionary = [[NSMutableDictionary alloc] init];
+
+    NSMutableString *urlString = [[[response URL] description] mutableCopy];
+    normalizeWebResourceURL(urlString);
+    [responseDictionary setObject:urlString forKey:@"URL"];
+    [urlString release];
+
+    NSMutableString *mimeTypeString = [[response MIMEType] mutableCopy];
+    convertMIMEType(mimeTypeString);
+    [responseDictionary setObject:mimeTypeString forKey:@"MIMEType"];
+    [mimeTypeString release];
+
+    NSString *textEncodingName = [response textEncodingName];
+    if (textEncodingName)
+        [responseDictionary setObject:textEncodingName forKey:@"textEncodingName"];
+    [responseDictionary setObject:[NSNumber numberWithLongLong:[response expectedContentLength]] forKey:@"expectedContentLength"];
+
+    if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
+        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
+
+        NSMutableDictionary *allHeaderFields = [[httpResponse allHeaderFields] mutableCopy];
+        normalizeHTTPResponseHeaderFields(allHeaderFields);
+        [responseDictionary setObject:allHeaderFields forKey:@"allHeaderFields"];
+        [allHeaderFields release];
+
+        [responseDictionary setObject:[NSNumber numberWithInt:[httpResponse statusCode]] forKey:@"statusCode"];
+    }
+
+    [propertyList setObject:responseDictionary forKey:@"WebResourceResponse"];
+    [responseDictionary release];
+}
+
+static NSInteger compareResourceURLs(id resource1, id resource2, void *context)
+{
+    NSString *url1 = [resource1 objectForKey:@"WebResourceURL"];
+    NSString *url2 = [resource2 objectForKey:@"WebResourceURL"];
+ 
+    return [url1 compare:url2];
+}
+
+NSString *serializeWebArchiveToXML(WebArchive *webArchive)
+{
+    NSString *errorString;
+    NSMutableDictionary *propertyList = [NSPropertyListSerialization propertyListFromData:[webArchive data]
+                                                                         mutabilityOption:NSPropertyListMutableContainersAndLeaves
+                                                                                   format:NULL
+                                                                         errorDescription:&errorString];
+    if (!propertyList)
+        return errorString;
+
+    NSMutableArray *resources = [NSMutableArray arrayWithCapacity:1];
+    [resources addObject:propertyList];
+
+    while ([resources count]) {
+        NSMutableDictionary *resourcePropertyList = [resources objectAtIndex:0];
+        [resources removeObjectAtIndex:0];
+
+        NSMutableDictionary *mainResource = [resourcePropertyList objectForKey:@"WebMainResource"];
+        normalizeWebResourceURL([mainResource objectForKey:@"WebResourceURL"]);
+        convertWebResourceDataToString(mainResource);
+
+        // Add subframeArchives to list for processing
+        NSMutableArray *subframeArchives = [resourcePropertyList objectForKey:@"WebSubframeArchives"]; // WebSubframeArchivesKey in WebArchive.m
+        if (subframeArchives)
+            [resources addObjectsFromArray:subframeArchives];
+
+        NSMutableArray *subresources = [resourcePropertyList objectForKey:@"WebSubresources"]; // WebSubresourcesKey in WebArchive.m
+        NSEnumerator *enumerator = [subresources objectEnumerator];
+        NSMutableDictionary *subresourcePropertyList;
+        while ((subresourcePropertyList = [enumerator nextObject])) {
+            normalizeWebResourceURL([subresourcePropertyList objectForKey:@"WebResourceURL"]);
+            convertWebResourceResponseToDictionary(subresourcePropertyList);
+            convertWebResourceDataToString(subresourcePropertyList);
+        }
+        
+        // Sort the subresources so they're always in a predictable order for the dump
+        if (NSArray *sortedSubresources = [subresources sortedArrayUsingFunction:compareResourceURLs context:nil])
+            [resourcePropertyList setObject:sortedSubresources forKey:@"WebSubresources"];
+    }
+
+    NSData *xmlData = [NSPropertyListSerialization dataFromPropertyList:propertyList
+                                                                 format:NSPropertyListXMLFormat_v1_0
+                                                       errorDescription:&errorString];
+    if (!xmlData)
+        return errorString;
+
+    NSMutableString *string = [[[NSMutableString alloc] initWithData:xmlData encoding:NSUTF8StringEncoding] autorelease];
+
+    // Replace "Apple Computer" with "Apple" in the DTD declaration.
+    NSRange range = [string rangeOfString:@"-//Apple Computer//"];
+    if (range.location != NSNotFound)
+        [string replaceCharactersInRange:range withString:@"-//Apple//"];
+    
+    return string;
+}

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list