WebCore:
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Feb 2008 21:30:48 +0000 (21:30 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Feb 2008 21:30:48 +0000 (21:30 +0000)
        Reviewed by Alexey Proskuryakov.

        - WebCore part of fixing http://bugs.webkit.org/show_bug.cgi?id=17360
          <rdar://problem/5743131> REGRESSION: mp4 file downloaded from server is downloaded as html

        Test: http/tests/loading/text-content-type-with-binary-extension.html

        Refined the workaround for <rdar://problem/5321972> to exclude files
        with extensions that are known to be associated with binary MIME types.

        * WebCore.xcodeproj/project.pbxproj: Added WebCoreURLResponse.{h,mm}.
        * platform/network/mac/ResourceResponseMac.mm:
        (WebCore::ResourceResponse::doUpdateResourceResponse): Moved the
        workaround logic into WebCoreURLResponse.
        * platform/network/mac/WebCoreURLResponse.h: Added.
        * platform/network/mac/WebCoreURLResponse.mm: Added.
        (createBinaryExtensionsSet): Returns a set of extensions known to
        belong to MIME types of binary data.
        (-[NSURLResponse _webcore_MIMEType]):
        (-[NSHTTPURLResponse _webcore_MIMEType]): Forces the MIME type from
        application/octet-stream to text/plain if that is the specified
        Content-Type, unless the extension is in the binary extensions set.

WebKit/mac:

        Reviewed by Alexey Proskuryakov.

        - WebKit part of fixing http://bugs.webkit.org/show_bug.cgi?id=17360
          <rdar://problem/5743131> REGRESSION: mp4 file downloaded from server is downloaded as html

        * WebView/WebDataSource.mm:
        (+[WebDataSource _representationClassForMIMEType:]):
        (-[WebDataSource _responseMIMEType]):
        (-[WebDataSource subresources]):
        (-[WebDataSource subresourceForURL:]):
        * WebView/WebResource.mm:
        (-[WebResource _initWithData:URL:response:]):
        * WebView/WebResourcePrivate.h:

LayoutTests:

        Reviewed by Alexey Proskuryakov.

        - test for http://bugs.webkit.org/show_bug.cgi?id=17360
          <rdar://problem/5743131> REGRESSION: mp4 file downloaded from server is downloaded as html

        * http/tests/loading/resources/.htaccess: Added.
        * http/tests/loading/resources/binaryData.m4a: Added.
        * http/tests/loading/text-content-type-with-binary-extension-expected.txt: Added.
        * http/tests/loading/text-content-type-with-binary-extension.html: Added.

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

14 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/loading/resources/.htaccess [new file with mode: 0644]
LayoutTests/http/tests/loading/resources/binaryData.m4a [new file with mode: 0644]
LayoutTests/http/tests/loading/text-content-type-with-binary-extension-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/loading/text-content-type-with-binary-extension.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/platform/network/mac/ResourceResponseMac.mm
WebCore/platform/network/mac/WebCoreURLResponse.h [new file with mode: 0644]
WebCore/platform/network/mac/WebCoreURLResponse.mm [new file with mode: 0644]
WebKit/mac/ChangeLog
WebKit/mac/WebView/WebDataSource.mm
WebKit/mac/WebView/WebResource.mm
WebKit/mac/WebView/WebResourcePrivate.h

index 56c3f22..c469d9e 100644 (file)
@@ -1,3 +1,15 @@
+2008-02-15  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Alexey Proskuryakov.
+
+        - test for http://bugs.webkit.org/show_bug.cgi?id=17360
+          <rdar://problem/5743131> REGRESSION: mp4 file downloaded from server is downloaded as html
+
+        * http/tests/loading/resources/.htaccess: Added.
+        * http/tests/loading/resources/binaryData.m4a: Added.
+        * http/tests/loading/text-content-type-with-binary-extension-expected.txt: Added.
+        * http/tests/loading/text-content-type-with-binary-extension.html: Added.
+
 2008-02-15  Samuel Weinig  <sam@webkit.org>
 
         Reviewed and rubber-stamped by Oliver Hunt.
diff --git a/LayoutTests/http/tests/loading/resources/.htaccess b/LayoutTests/http/tests/loading/resources/.htaccess
new file mode 100644 (file)
index 0000000..8c4b681
--- /dev/null
@@ -0,0 +1 @@
+AddType text/plain .m4a
diff --git a/LayoutTests/http/tests/loading/resources/binaryData.m4a b/LayoutTests/http/tests/loading/resources/binaryData.m4a
new file mode 100644 (file)
index 0000000..df1d0ad
Binary files /dev/null and b/LayoutTests/http/tests/loading/resources/binaryData.m4a differ
diff --git a/LayoutTests/http/tests/loading/text-content-type-with-binary-extension-expected.txt b/LayoutTests/http/tests/loading/text-content-type-with-binary-extension-expected.txt
new file mode 100644 (file)
index 0000000..afbb077
--- /dev/null
@@ -0,0 +1,12 @@
+main frame - didStartProvisionalLoadForFrame
+main frame - didCommitLoadForFrame
+frame "iframe" - didStartProvisionalLoadForFrame
+main frame - didFinishDocumentLoadForFrame
+main frame - didHandleOnloadEventsForFrame
+frame "iframe" - didFailProvisionalLoadWithError
+main frame - didFinishLoadForFrame
+Test for https://bugs.webkit.org/show_bug.cgi?id=17360 REGRESSION: mp4 file downloaded from server is downloaded as html.
+
+Binary data not loaded as text. Maybe PASS.
+
+
diff --git a/LayoutTests/http/tests/loading/text-content-type-with-binary-extension.html b/LayoutTests/http/tests/loading/text-content-type-with-binary-extension.html
new file mode 100644 (file)
index 0000000..2ee3abf
--- /dev/null
@@ -0,0 +1,46 @@
+<head>
+    <script>
+        var failed = false;
+
+        if (window.layoutTestController) {
+            layoutTestController.dumpAsText();
+            layoutTestController.waitUntilDone();
+        }
+
+        function iframeNotLoaded()
+        {
+            if (failed)
+                return;
+
+            if (window.layoutTestController) {
+                document.getElementById("result").innerText = "Binary data not loaded as text. Maybe PASS.";
+                layoutTestController.notifyDone();
+            } else
+                document.getElementById("result").innerText = "If Safari downloaded binaryData.m4a, then it passed the test.";
+        }
+
+        function bodyLoaded()
+        {
+            if (!failed)
+                timeout = setTimeout(iframeNotLoaded, 500);
+        }
+
+        function iframeLoaded()
+        {
+            document.getElementById("result").innerText = "FAIL";
+            failed = true;
+            if (window.layoutTestController)
+                layoutTestController.notifyDone();
+        }
+    </script>
+</head>
+<body onload="bodyLoaded()">
+    <p>
+        Test for <i><a href="https://bugs.webkit.org/show_bug.cgi?id=17360">https://bugs.webkit.org/show_bug.cgi?id=17360</a>
+        REGRESSION: mp4 file downloaded from server is downloaded as html</i>.
+    </p>
+    <p id="result">
+        Test running...
+    </p>
+    <iframe id="iframe" src="resources/binaryData.m4a" onload="iframeLoaded()"></iframe>
+</body>
index a27e888..cea3e9c 100644 (file)
@@ -1,5 +1,30 @@
 2008-02-15  Dan Bernstein  <mitz@apple.com>
 
+        Reviewed by Alexey Proskuryakov.
+
+        - WebCore part of fixing http://bugs.webkit.org/show_bug.cgi?id=17360
+          <rdar://problem/5743131> REGRESSION: mp4 file downloaded from server is downloaded as html
+
+        Test: http/tests/loading/text-content-type-with-binary-extension.html
+
+        Refined the workaround for <rdar://problem/5321972> to exclude files
+        with extensions that are known to be associated with binary MIME types.
+
+        * WebCore.xcodeproj/project.pbxproj: Added WebCoreURLResponse.{h,mm}.
+        * platform/network/mac/ResourceResponseMac.mm:
+        (WebCore::ResourceResponse::doUpdateResourceResponse): Moved the
+        workaround logic into WebCoreURLResponse.
+        * platform/network/mac/WebCoreURLResponse.h: Added.
+        * platform/network/mac/WebCoreURLResponse.mm: Added.
+        (createBinaryExtensionsSet): Returns a set of extensions known to
+        belong to MIME types of binary data.
+        (-[NSURLResponse _webcore_MIMEType]):
+        (-[NSHTTPURLResponse _webcore_MIMEType]): Forces the MIME type from
+        application/octet-stream to text/plain if that is the specified
+        Content-Type, unless the extension is in the binary extensions set.
+
+2008-02-15  Dan Bernstein  <mitz@apple.com>
+
         Reviewed by Dave Hyatt.
 
         - fix http://bugs.webkit.org/show_bug.cgi?id=17306
index 35c26f5..582e95f 100644 (file)
                371F53EA0D2704F900ECE0D5 /* CSSUnicodeRangeValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 371F53E80D2704F900ECE0D5 /* CSSUnicodeRangeValue.cpp */; };
                37919C230B7D188600A56998 /* PositionIterator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37919C210B7D188600A56998 /* PositionIterator.cpp */; };
                37919C240B7D188600A56998 /* PositionIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 37919C220B7D188600A56998 /* PositionIterator.h */; settings = {ATTRIBUTES = (); }; };
+               37F818FD0D657606005E1F05 /* WebCoreURLResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 37F818FB0D657606005E1F05 /* WebCoreURLResponse.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               37F818FE0D657606005E1F05 /* WebCoreURLResponse.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37F818FC0D657606005E1F05 /* WebCoreURLResponse.mm */; };
                441B05560CD779B6007C1F18 /* DOMCSSStyleSheetPrivate.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 4429AAEA0CB84DC7007647C5 /* DOMCSSStyleSheetPrivate.h */; };
                441B05580CD779F2007C1F18 /* DOMEventPrivate.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 4429AAF80CB84E5F007647C5 /* DOMEventPrivate.h */; };
                441B055A0CD77A14007C1F18 /* DOMHTMLCollectionPrivate.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 4429AAF10CB84E35007647C5 /* DOMHTMLCollectionPrivate.h */; };
                371F53E80D2704F900ECE0D5 /* CSSUnicodeRangeValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSUnicodeRangeValue.cpp; sourceTree = "<group>"; };
                37919C210B7D188600A56998 /* PositionIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = PositionIterator.cpp; sourceTree = "<group>"; };
                37919C220B7D188600A56998 /* PositionIterator.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PositionIterator.h; sourceTree = "<group>"; };
+               37F818FB0D657606005E1F05 /* WebCoreURLResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreURLResponse.h; sourceTree = "<group>"; };
+               37F818FC0D657606005E1F05 /* WebCoreURLResponse.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreURLResponse.mm; sourceTree = "<group>"; };
                441244D80CB853ED008F0C79 /* JSHTMLInputElementBaseTable.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 30; path = JSHTMLInputElementBaseTable.cpp; sourceTree = "<group>"; };
                4429AAEA0CB84DC7007647C5 /* DOMCSSStyleSheetPrivate.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 30; path = DOMCSSStyleSheetPrivate.h; sourceTree = "<group>"; };
                4429AAF10CB84E35007647C5 /* DOMHTMLCollectionPrivate.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMHTMLCollectionPrivate.h; sourceTree = "<group>"; };
                                514C76490CE9234E007EF3CD /* ResourceRequestMac.mm */,
                                514C764A0CE9234E007EF3CD /* ResourceResponse.h */,
                                514C764B0CE9234E007EF3CD /* ResourceResponseMac.mm */,
+                               37F818FB0D657606005E1F05 /* WebCoreURLResponse.h */,
+                               37F818FC0D657606005E1F05 /* WebCoreURLResponse.mm */,
                        );
                        path = mac;
                        sourceTree = "<group>";
                                5DCF836D0D59159800953BC6 /* PluginInfoStore.h in Headers */,
                                C0294DF40D5A6FD800CC7D6B /* UserStyleSheetLoader.h in Headers */,
                                E1DE1C080D5CE4CF0034C38F /* MessageQueue.h in Headers */,
+                               37F818FD0D657606005E1F05 /* WebCoreURLResponse.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                51A9267C0D53F0570063ECC2 /* OriginQuotaManager.cpp in Sources */,
                                51A9267E0D53F0570063ECC2 /* OriginUsageRecord.cpp in Sources */,
                                C0294DF30D5A6FD800CC7D6B /* UserStyleSheetLoader.cpp in Sources */,
+                               37F818FE0D657606005E1F05 /* WebCoreURLResponse.mm in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index da66d42..68b145e 100644 (file)
@@ -27,6 +27,7 @@
 #import "config.h"
 #import "ResourceResponse.h"
 
+#import "WebCoreURLResponse.h"
 #import <Foundation/Foundation.h>
 #import <limits>
 
@@ -64,7 +65,7 @@ void ResourceResponse::doUpdateResourceResponse()
     }
     
     m_url = [m_nsResponse.get() URL];
-    m_mimeType = [m_nsResponse.get() MIMEType];
+    m_mimeType = [m_nsResponse.get() _webcore_MIMEType];
     m_expectedContentLength = [m_nsResponse.get() expectedContentLength];
     m_textEncodingName = [m_nsResponse.get() textEncodingName];
     m_suggestedFilename = [m_nsResponse.get() suggestedFilename];
@@ -87,15 +88,6 @@ void ResourceResponse::doUpdateResourceResponse()
         NSEnumerator *e = [headers keyEnumerator];
         while (NSString *name = [e nextObject])
             m_httpHeaderFields.set(name, [headers objectForKey:name]);
-#ifndef BUILDING_ON_TIGER
-        // FIXME: This is part of a workaround for <rdar://problem/5321972> REGRESSION: Plain text document from HTTP server detected
-        // as application/octet-stream
-        if (m_mimeType == "application/octet-stream") {
-            static const String textPlainMIMEType("text/plain");
-            if (m_httpHeaderFields.get("Content-Type").startsWith(textPlainMIMEType))
-                m_mimeType = textPlainMIMEType;
-        }
-#endif
     } else {
         m_httpStatusCode = 0;
 
diff --git a/WebCore/platform/network/mac/WebCoreURLResponse.h b/WebCore/platform/network/mac/WebCoreURLResponse.h
new file mode 100644 (file)
index 0000000..a06ab70
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2008 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. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * 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.
+ */
+
+// FIXME: This is a workaround for <rdar://problem/5321972> REGRESSION: Plain text document from HTTP server detected
+// as application/octet-stream
+
+@interface NSURLResponse (WebCoreURLResponse)
+- (NSString *)_webcore_MIMEType;
+@end
diff --git a/WebCore/platform/network/mac/WebCoreURLResponse.mm b/WebCore/platform/network/mac/WebCoreURLResponse.mm
new file mode 100644 (file)
index 0000000..4464c9a
--- /dev/null
@@ -0,0 +1,215 @@
+/*
+ * Copyright (C) 2008 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. 
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission. 
+ *
+ * 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 "config.h"
+
+#import "WebCoreURLResponse.h"
+
+#ifndef BUILDING_ON_TIGER
+static NSSet *createBinaryExtensionsSet()
+{
+    return [[NSSet alloc] initWithObjects:
+        @"3g2",
+        @"3gp",
+        @"ai",
+        @"aif",
+        @"aifc",
+        @"aiff",
+        @"au",
+        @"avi",
+        @"bcpio",
+        @"bin",
+        @"bmp",
+        @"boz",
+        @"bpk",
+        @"bz",
+        @"bz2",
+        @"chm",
+        @"class",
+        @"com",
+        @"cpio",
+        @"dcr",
+        @"dir",
+        @"dist",
+        @"distz",
+        @"dll",
+        @"dmg",
+        @"dms",
+        @"doc",
+        @"dot",
+        @"dump",
+        @"dv",
+        @"dvi",
+        @"dxr",
+        @"elc",
+        @"eot",
+        @"eps",
+        @"exe",
+        @"fgd",
+        @"gif",
+        @"gtar",
+        @"h261",
+        @"h263",
+        @"h264",
+        @"ico",
+        @"ims",
+        @"indd",
+        @"iso",
+        @"jp2",
+        @"jpe",
+        @"jpeg",
+        @"jpg",
+        @"jpgm",
+        @"jpgv",
+        @"jpm",
+        @"kar",
+        @"lha",
+        @"lrm",
+        @"lzh",
+        @"m1v",
+        @"m2a",
+        @"m2v",
+        @"m3a",
+        @"m3u",
+        @"m4a",
+        @"m4p",
+        @"m4v",
+        @"mdb",
+        @"mid",
+        @"midi",
+        @"mj2",
+        @"mjp2",
+        @"mov",
+        @"movie",
+        @"mp2",
+        @"mp2a",
+        @"mp3",
+        @"mp4",
+        @"mp4a",
+        @"mp4s",
+        @"mp4v",
+        @"mpe",
+        @"mpeg",
+        @"mpg",
+        @"mpg4",
+        @"mpga",
+        @"mpp",
+        @"mpt",
+        @"msi",
+        @"ogg",
+        @"otf",
+        @"pct",
+        @"pdf",
+        @"pfa",
+        @"pfb",
+        @"pic",
+        @"pict",
+        @"pkg",
+        @"png",
+        @"pot",
+        @"pps",
+        @"ppt",
+        @"ps",
+        @"psd",
+        @"qt",
+        @"qti",
+        @"qtif",
+        @"qwd",
+        @"qwt",
+        @"qxb",
+        @"qxd",
+        @"qxl",
+        @"qxp",
+        @"qxt",
+        @"ra",
+        @"ram",
+        @"rm",
+        @"rmi",
+        @"rmp",
+        @"scpt",
+        @"sit",
+        @"sitx",
+        @"snd",
+        @"so",
+        @"swf",
+        @"tar",
+        @"tif",
+        @"tiff",
+        @"ttf",
+        @"wav",
+        @"wcm",
+        @"wdb",
+        @"wks",
+        @"wm",
+        @"wma",
+        @"wmd",
+        @"wmf",
+        @"wmv",
+        @"wmx",
+        @"wmz",
+        @"wpd",
+        @"wpl",
+        @"wps",
+        @"wvx",
+        @"xla",
+        @"xlc",
+        @"xlm",
+        @"xls",
+        @"xlt",
+        @"xlw",
+        @"xps",
+        @"zip",
+        nil
+    ];
+}
+#endif
+
+@implementation NSURLResponse (WebCoreURLResponse)
+
+- (NSString *)_webcore_MIMEType
+{
+    return [self MIMEType];
+}
+
+@end
+
+@implementation NSHTTPURLResponse (WebCoreURLResponse)
+
+- (NSString *)_webcore_MIMEType
+{
+    NSString *MIMEType = [self MIMEType];
+#ifndef BUILDING_ON_TIGER
+    if ([MIMEType isEqualToString:@"application/octet-stream"] && [[[self allHeaderFields] objectForKey:@"Content-Type"] hasPrefix:@"text/plain"]) {
+        static NSSet *binaryExtensions = createBinaryExtensionsSet();
+        return [binaryExtensions containsObject:[[[self suggestedFilename] pathExtension] lowercaseString]] ? MIMEType : @"text/plain";
+    }
+#endif
+    return MIMEType;
+}
+
+@end
index 59a011e..8789977 100644 (file)
@@ -1,3 +1,19 @@
+2008-02-15  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Alexey Proskuryakov.
+
+        - WebKit part of fixing http://bugs.webkit.org/show_bug.cgi?id=17360
+          <rdar://problem/5743131> REGRESSION: mp4 file downloaded from server is downloaded as html
+
+        * WebView/WebDataSource.mm:
+        (+[WebDataSource _representationClassForMIMEType:]):
+        (-[WebDataSource _responseMIMEType]):
+        (-[WebDataSource subresources]):
+        (-[WebDataSource subresourceForURL:]):
+        * WebView/WebResource.mm:
+        (-[WebResource _initWithData:URL:response:]):
+        * WebView/WebResourcePrivate.h:
+
 2008-02-15  Adam Roben  <aroben@apple.com>
 
         Make WebKit's FEATURE_DEFINES match WebCore's
index 615185b..383bc2a 100644 (file)
@@ -55,6 +55,7 @@
 #import <WebCore/ResourceRequest.h>
 #import <WebCore/SharedBuffer.h>
 #import <WebCore/WebCoreObjCExtras.h>
+#import <WebCore/WebCoreURLResponse.h>
 #import <WebKit/DOMHTML.h>
 #import <WebKit/DOMPrivate.h>
 #import <WebKitSystemInterface.h>
@@ -135,20 +136,6 @@ static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class objCCl
     Class repClass;
     return [WebView _viewClass:nil andRepresentationClass:&repClass forMIMEType:MIMEType] ? repClass : nil;
 }
-
-- (NSString *)_MIMETypeOfResponse:(NSURLResponse *)response
-{
-#ifdef BUILDING_ON_TIGER
-    return [response MIMEType];
-#else
-    // FIXME: This is part of a workaround for <rdar://problem/5321972> REGRESSION: Plain text document from HTTP server detected
-    // as application/octet-stream
-    NSString *MIMEType = [response MIMEType];
-    if ([MIMEType isEqualToString:@"application/octet-stream"] && [response isKindOfClass:[NSHTTPURLResponse class]] && [[[(NSHTTPURLResponse *)response allHeaderFields] objectForKey:@"Content-Type"] hasPrefix:@"text/plain"])
-        return @"text/plain";
-    return MIMEType;
-#endif
-}
 @end
 
 @implementation WebDataSource (WebPrivate)
@@ -189,11 +176,7 @@ static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class objCCl
 
 - (NSString *)_responseMIMEType
 {
-#ifdef BUILDING_ON_TIGER
-    return [[self response] MIMEType];
-#else
-    return [self _MIMETypeOfResponse:[self response]];
-#endif
+    return [[self response] _webcore_MIMEType];
 }
 
 @end
@@ -515,7 +498,7 @@ static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class objCCl
     NSMutableArray *subresources = [[NSMutableArray alloc] initWithCapacity:[datas count]];
     for (unsigned i = 0; i < [datas count]; ++i) {
         NSURLResponse *response = [responses objectAtIndex:i];
-        [subresources addObject:[[[WebResource alloc] _initWithData:[datas objectAtIndex:i] URL:[response URL] response:response MIMEType:[self _MIMETypeOfResponse:response]] autorelease]];
+        [subresources addObject:[[[WebResource alloc] _initWithData:[datas objectAtIndex:i] URL:[response URL] response:response] autorelease]];
     }
 
     return [subresources autorelease];
@@ -531,7 +514,7 @@ static inline void addTypesFromClass(NSMutableDictionary *allTypes, Class objCCl
     if (![[self _bridge] getData:&data andResponse:&response forURL:[URL _web_originalDataAsString]])
         return [self _archivedSubresourceForURL:URL];
 
-    return [[[WebResource alloc] _initWithData:data URL:URL response:response MIMEType:[self _MIMETypeOfResponse:response]] autorelease];
+    return [[[WebResource alloc] _initWithData:data URL:URL response:response] autorelease];
 }
 
 - (void)addSubresource:(WebResource *)subresource
index 5f2928d..9866d39 100644 (file)
@@ -31,6 +31,7 @@
 #import "WebFrameBridge.h"
 #import "WebNSDictionaryExtras.h"
 #import "WebNSURLExtras.h"
+#import <WebCore/WebCoreURLResponse.h>
 
 static NSString * const WebResourceDataKey =              @"WebResourceData";
 static NSString * const WebResourceFrameNameKey =         @"WebResourceFrameName";
@@ -248,13 +249,13 @@ static NSString * const WebResourceResponseKey =          @"WebResourceResponse"
     return self;
 }
 
-- (id)_initWithData:(NSData *)data URL:(NSURL *)URL response:(NSURLResponse *)response MIMEType:(NSString *)MIMEType
+- (id)_initWithData:(NSData *)data URL:(NSURL *)URL response:(NSURLResponse *)response
 {
     // Pass NO for copyData since the data doesn't need to be copied since we know that callers will no longer modify it.
     // Copying it will also cause a performance regression.
     return [self _initWithData:data
                            URL:URL
-                      MIMEType:MIMEType
+                      MIMEType:[response _webcore_MIMEType]
               textEncodingName:[response textEncodingName]
                      frameName:nil
                       response:response
index 34ae701..3a7ee41 100644 (file)
@@ -38,7 +38,7 @@
            response:(NSURLResponse *)response
            copyData:(BOOL)copyData;
 
-- (id)_initWithData:(NSData *)data URL:(NSURL *)URL response:(NSURLResponse *)response MIMEType:(NSString *)MIMEType;
+- (id)_initWithData:(NSData *)data URL:(NSURL *)URL response:(NSURLResponse *)response;
 
 - (BOOL)_shouldIgnoreWhenUnarchiving;
 - (void)_ignoreWhenUnarchiving;