Log Message
Merge 90308 BUG=86108 Review URL: http://codereview.chromium.org/7356002
Modified Paths
- branches/chromium/782/Source/WebCore/fileapi/File.cpp
- branches/chromium/782/Source/WebCore/platform/MIMETypeRegistry.cpp
- branches/chromium/782/Source/WebCore/platform/MIMETypeRegistry.h
- branches/chromium/782/Source/WebCore/platform/chromium/MIMETypeRegistryChromium.cpp
- branches/chromium/782/Source/WebCore/platform/chromium/PlatformBridge.h
- branches/chromium/782/Source/WebKit/chromium/public/WebMimeRegistry.h
- branches/chromium/782/Source/WebKit/chromium/src/PlatformBridge.cpp
Diff
Modified: branches/chromium/782/Source/WebCore/fileapi/File.cpp (90866 => 90867)
--- branches/chromium/782/Source/WebCore/fileapi/File.cpp 2011-07-12 23:31:05 UTC (rev 90866)
+++ branches/chromium/782/Source/WebCore/fileapi/File.cpp 2011-07-12 23:32:48 UTC (rev 90867)
@@ -33,20 +33,34 @@
namespace WebCore {
-static PassOwnPtr<BlobData> createBlobDataForFile(const String& path, const String& name = String())
+static PassOwnPtr<BlobData> createBlobDataForFileWithType(const String& path, const String& contentType)
{
- String type;
- const String& nameForMIMEType = !name.isEmpty() ? name : path;
- int index = nameForMIMEType.reverseFind('.');
- if (index != -1)
- type = MIMETypeRegistry::getMIMETypeForExtension(nameForMIMEType.substring(index + 1));
-
OwnPtr<BlobData> blobData = BlobData::create();
- blobData->setContentType(type);
+ blobData->setContentType(contentType);
blobData->appendFile(path);
return blobData.release();
}
+static PassOwnPtr<BlobData> createBlobDataForFile(const String& path)
+{
+ String type;
+ int index = path.reverseFind('.');
+ if (index != -1)
+ type = MIMETypeRegistry::getMIMETypeForExtension(path.substring(index + 1));
+ return createBlobDataForFileWithType(path, type);
+}
+
+#if ENABLE(FILE_SYSTEM)
+static PassOwnPtr<BlobData> createBlobDataForFileSystemFile(const String& path, const String& fileSystemName)
+{
+ String type;
+ int index = fileSystemName.reverseFind('.');
+ if (index != -1)
+ type = MIMETypeRegistry::getWellKnownMIMETypeForExtension(fileSystemName.substring(index + 1));
+ return createBlobDataForFileWithType(path, type);
+}
+#endif
+
#if ENABLE(DIRECTORY_UPLOAD)
PassRefPtr<File> File::createWithRelativePath(const String& path, const String& relativePath)
{
@@ -68,11 +82,14 @@
, m_path(path)
{
m_name = pathGetFileName(path);
+ // FIXME: File object serialization/deserialization does not include
+ // newer file object data members: m_name and m_relativePath.
+ // See SerializedScriptValue.cpp for js and v8.
}
#if ENABLE(FILE_SYSTEM)
File::File(const String& path, const String& name)
- : Blob(createBlobDataForFile(path, name), -1)
+ : Blob(createBlobDataForFileSystemFile(path, name), -1)
, m_path(path)
, m_name(name)
{
Modified: branches/chromium/782/Source/WebCore/platform/MIMETypeRegistry.cpp (90866 => 90867)
--- branches/chromium/782/Source/WebCore/platform/MIMETypeRegistry.cpp 2011-07-12 23:31:05 UTC (rev 90866)
+++ branches/chromium/782/Source/WebCore/platform/MIMETypeRegistry.cpp 2011-07-12 23:32:48 UTC (rev 90867)
@@ -49,6 +49,139 @@
namespace WebCore {
+namespace {
+struct TypeExtensionPair {
+ const char* type;
+ const char* extension;
+};
+}
+
+// A table of common media MIME types and file extenstions used when a platform's
+// specific MIME type lookup doesn't have a match for a media file extension.
+static const TypeExtensionPair commonMediaTypes[] = {
+
+ // Ogg
+ { "application/ogg", "ogx" },
+ { "audio/ogg", "ogg" },
+ { "audio/ogg", "oga" },
+ { "video/ogg", "ogv" },
+
+ // Annodex
+ { "application/annodex", "anx" },
+ { "audio/annodex", "axa" },
+ { "video/annodex", "axv" },
+ { "audio/speex", "spx" },
+
+ // WebM
+ { "video/webm", "webm" },
+ { "audio/webm", "webm" },
+
+ // MPEG
+ { "audio/mpeg", "m1a" },
+ { "audio/mpeg", "m2a" },
+ { "audio/mpeg", "m1s" },
+ { "audio/mpeg", "mpa" },
+ { "video/mpeg", "mpg" },
+ { "video/mpeg", "m15" },
+ { "video/mpeg", "m1s" },
+ { "video/mpeg", "m1v" },
+ { "video/mpeg", "m75" },
+ { "video/mpeg", "mpa" },
+ { "video/mpeg", "mpeg" },
+ { "video/mpeg", "mpm" },
+ { "video/mpeg", "mpv" },
+
+ // MPEG playlist
+ { "application/vnd.apple.mpegurl", "m3u8" },
+ { "application/mpegurl", "m3u8" },
+ { "application/x-mpegurl", "m3u8" },
+ { "audio/mpegurl", "m3url" },
+ { "audio/x-mpegurl", "m3url" },
+ { "audio/mpegurl", "m3u" },
+ { "audio/x-mpegurl", "m3u" },
+
+ // MPEG-4
+ { "video/x-m4v", "m4v" },
+ { "audio/x-m4a", "m4a" },
+ { "audio/x-m4b", "m4b" },
+ { "audio/x-m4p", "m4p" },
+ { "audio/mp4", "m4a" },
+
+ // MP3
+ { "audio/mp3", "mp3" },
+ { "audio/x-mp3", "mp3" },
+ { "audio/x-mpeg", "mp3" },
+
+ // MPEG-2
+ { "video/x-mpeg2", "mp2" },
+ { "video/mpeg2", "vob" },
+ { "video/mpeg2", "mod" },
+ { "video/m2ts", "m2ts" },
+ { "video/x-m2ts", "m2t" },
+ { "video/x-m2ts", "ts" },
+
+ // 3GP/3GP2
+ { "audio/3gpp", "3gpp" },
+ { "audio/3gpp2", "3g2" },
+ { "application/x-mpeg", "amc" },
+
+ // AAC
+ { "audio/aac", "aac" },
+ { "audio/aac", "adts" },
+ { "audio/x-aac", "m4r" },
+
+ // CoreAudio File
+ { "audio/x-caf", "caf" },
+ { "audio/x-gsm", "gsm" },
+
+ // ADPCM
+ { "audio/x-wav", "wav" }
+};
+
+#if ENABLE(FILE_SYSTEM)
+static const char textPlain[] = "text/plain";
+static const char textHtml[] = "text/html";
+static const char imageJpeg[] = "image/jpeg";
+static const char octetStream[] = "application/octet-stream";
+
+// A table of well known MIME types used when we don't want to leak to the
+// caller information about types known to underlying platform.
+static const TypeExtensionPair wellKnownMimeTypes[] = {
+ { textPlain, "txt" },
+ { textPlain, "text" },
+ { textHtml, "html" },
+ { textHtml, "htm" },
+ { "text/css", "css" },
+ { "text/xml", "xml" },
+ { "text/xsl", "xsl" },
+ { "image/gif", "gif" },
+ { "image/png", "png" },
+ { imageJpeg, "jpeg" },
+ { imageJpeg, "jpg" },
+ { imageJpeg, "jfif" },
+ { imageJpeg, "pjpeg" },
+ { "image/webp", "webp" },
+ { "image/bmp", "bmp" },
+ { "application/xhtml+xml", "xhtml" },
+ { "application/x-_javascript_", "js" },
+ { "application/json", "json" },
+ { octetStream, "exe" },
+ { octetStream, "com" },
+ { octetStream, "bin" },
+ { "application/zip", "zip" },
+ { "application/gzip", "gz" },
+ { "application/pdf", "pdf" },
+ { "application/postscript", "ps" },
+ { "image/x-icon", "ico" },
+ { "image/tiff", "tiff" },
+ { "image/x-xbitmap", "xbm" },
+ { "image/svg+xml", "svg" },
+ { "application/rss+xml", "rss" },
+ { "application/rdf+xml", "rdf" },
+ { "application/x-shockwave-flash", "swf" },
+};
+#endif
+
static HashSet<String>* supportedImageResourceMIMETypes;
static HashSet<String>* supportedImageMIMETypes;
static HashSet<String>* supportedImageMIMETypesForEncoding;
@@ -232,126 +365,32 @@
static MediaMIMETypeMap& mediaMIMETypeMap()
{
- struct TypeExtensionPair {
- const char* type;
- const char* extension;
- };
-
- // A table of common media MIME types and file extenstions used when a platform's
- // specific MIME type lookup doesn't have a match for a media file extension.
- static const TypeExtensionPair pairs[] = {
-
- // Ogg
- { "application/ogg", "ogx" },
- { "audio/ogg", "ogg" },
- { "audio/ogg", "oga" },
- { "video/ogg", "ogv" },
-
- // Annodex
- { "application/annodex", "anx" },
- { "audio/annodex", "axa" },
- { "video/annodex", "axv" },
- { "audio/speex", "spx" },
-
- // WebM
- { "video/webm", "webm" },
- { "audio/webm", "webm" },
-
- // MPEG
- { "audio/mpeg", "m1a" },
- { "audio/mpeg", "m2a" },
- { "audio/mpeg", "m1s" },
- { "audio/mpeg", "mpa" },
- { "video/mpeg", "mpg" },
- { "video/mpeg", "m15" },
- { "video/mpeg", "m1s" },
- { "video/mpeg", "m1v" },
- { "video/mpeg", "m75" },
- { "video/mpeg", "mpa" },
- { "video/mpeg", "mpeg" },
- { "video/mpeg", "mpm" },
- { "video/mpeg", "mpv" },
-
- // MPEG playlist
- { "application/vnd.apple.mpegurl", "m3u8" },
- { "application/mpegurl", "m3u8" },
- { "application/x-mpegurl", "m3u8" },
- { "audio/mpegurl", "m3url" },
- { "audio/x-mpegurl", "m3url" },
- { "audio/mpegurl", "m3u" },
- { "audio/x-mpegurl", "m3u" },
-
- // MPEG-4
- { "video/x-m4v", "m4v" },
- { "audio/x-m4a", "m4a" },
- { "audio/x-m4b", "m4b" },
- { "audio/x-m4p", "m4p" },
- { "audio/mp4", "m4a" },
-
- // MP3
- { "audio/mp3", "mp3" },
- { "audio/x-mp3", "mp3" },
- { "audio/x-mpeg", "mp3" },
-
- // MPEG-2
- { "video/x-mpeg2", "mp2" },
- { "video/mpeg2", "vob" },
- { "video/mpeg2", "mod" },
- { "video/m2ts", "m2ts" },
- { "video/x-m2ts", "m2t" },
- { "video/x-m2ts", "ts" },
-
- // 3GP/3GP2
- { "audio/3gpp", "3gpp" },
- { "audio/3gpp2", "3g2" },
- { "application/x-mpeg", "amc" },
-
- // AAC
- { "audio/aac", "aac" },
- { "audio/aac", "adts" },
- { "audio/x-aac", "m4r" },
-
- // CoreAudio File
- { "audio/x-caf", "caf" },
- { "audio/x-gsm", "gsm" },
-
- // ADPCM
- { "audio/x-wav", "wav" }
- };
-
DEFINE_STATIC_LOCAL(MediaMIMETypeMap, mediaMIMETypeForExtensionMap, ());
if (!mediaMIMETypeForExtensionMap.isEmpty())
return mediaMIMETypeForExtensionMap;
- const unsigned numPairs = sizeof(pairs) / sizeof(pairs[0]);
+ const unsigned numPairs = sizeof(commonMediaTypes) / sizeof(commonMediaTypes[0]);
for (unsigned ndx = 0; ndx < numPairs; ++ndx) {
- if (mediaMIMETypeForExtensionMap.contains(pairs[ndx].extension))
- mediaMIMETypeForExtensionMap.get(pairs[ndx].extension)->append(pairs[ndx].type);
+ if (mediaMIMETypeForExtensionMap.contains(commonMediaTypes[ndx].extension))
+ mediaMIMETypeForExtensionMap.get(commonMediaTypes[ndx].extension)->append(commonMediaTypes[ndx].type);
else {
Vector<String>* synonyms = new Vector<String>;
// If there is a system specific type for this extension, add it as the first type so
// getMediaMIMETypeForExtension will always return it.
- String systemType = MIMETypeRegistry::getMIMETypeForExtension(pairs[ndx].extension);
- if (!systemType.isEmpty() && pairs[ndx].type != systemType)
+ String systemType = MIMETypeRegistry::getMIMETypeForExtension(commonMediaTypes[ndx].extension);
+ if (!systemType.isEmpty() && commonMediaTypes[ndx].type != systemType)
synonyms->append(systemType);
- synonyms->append(pairs[ndx].type);
- mediaMIMETypeForExtensionMap.add(pairs[ndx].extension, synonyms);
+ synonyms->append(commonMediaTypes[ndx].type);
+ mediaMIMETypeForExtensionMap.add(commonMediaTypes[ndx].extension, synonyms);
}
}
return mediaMIMETypeForExtensionMap;
}
-#if ENABLE(FILE_SYSTEM) && ENABLE(WORKERS)
-String MIMETypeRegistry::getMIMETypeForExtension(const String& extension)
-{
- return getMIMETypeForExtensionThreadSafe(extension);
-}
-#endif
-
String MIMETypeRegistry::getMediaMIMETypeForExtension(const String& ext)
{
// Look in the system-specific registry first.
@@ -430,6 +469,28 @@
initializeUnsupportedTextMIMETypes();
}
+#if ENABLE(FILE_SYSTEM)
+static String findMimeType(const TypeExtensionPair* pairs, unsigned numPairs, const String& extension)
+{
+ if (!extension.isEmpty()) {
+ for (unsigned i = 0; i < numPairs; ++i, ++pairs) {
+ if (equalIgnoringCase(extension, pairs->extension))
+ return String(pairs->type);
+ }
+ }
+ return String();
+}
+
+String MIMETypeRegistry::getWellKnownMIMETypeForExtension(const String& extension)
+{
+ // This method must be thread safe and should not consult the OS/registry.
+ String found = findMimeType(wellKnownMimeTypes, sizeof(wellKnownMimeTypes) / sizeof(wellKnownMimeTypes[0]), extension);
+ if (!found.isEmpty())
+ return found;
+ return findMimeType(commonMediaTypes, sizeof(commonMediaTypes) / sizeof(commonMediaTypes[0]), extension);
+}
+#endif
+
String MIMETypeRegistry::getMIMETypeForPath(const String& path)
{
size_t pos = path.reverseFind('.');
Modified: branches/chromium/782/Source/WebCore/platform/MIMETypeRegistry.h (90866 => 90867)
--- branches/chromium/782/Source/WebCore/platform/MIMETypeRegistry.h 2011-07-12 23:31:05 UTC (rev 90866)
+++ branches/chromium/782/Source/WebCore/platform/MIMETypeRegistry.h 2011-07-12 23:32:48 UTC (rev 90867)
@@ -36,9 +36,10 @@
class MIMETypeRegistry {
public:
static String getMIMETypeForExtension(const String& extension);
-#if ENABLE(FILE_SYSTEM) && ENABLE(WORKERS)
- static String getMIMETypeForExtensionThreadSafe(const String& extension);
+#if ENABLE(FILE_SYSTEM)
+ static String getWellKnownMIMETypeForExtension(const String& extension);
#endif
+
static Vector<String> getExtensionsForMIMEType(const String& type);
static String getPreferredExtensionForMIMEType(const String& type);
static String getMediaMIMETypeForExtension(const String& extension);
Modified: branches/chromium/782/Source/WebCore/platform/chromium/MIMETypeRegistryChromium.cpp (90866 => 90867)
--- branches/chromium/782/Source/WebCore/platform/chromium/MIMETypeRegistryChromium.cpp 2011-07-12 23:31:05 UTC (rev 90866)
+++ branches/chromium/782/Source/WebCore/platform/chromium/MIMETypeRegistryChromium.cpp 2011-07-12 23:32:48 UTC (rev 90867)
@@ -36,27 +36,24 @@
#include "PluginDataChromium.h"
#include <wtf/text/CString.h>
-// NOTE: Unlike other ports, we don't use the shared implementation bits in
-// MIMETypeRegistry.cpp. Instead, we need to route most functions via the
-// PlatformBridge to the embedder.
+// NOTE: Unlike other ports, we don't use the shared implementation in
+// MIMETypeRegistry.cpp. Instead, we need to route most functions via
+// the PlatformBridge to the embedder.
namespace WebCore {
-#if ENABLE(FILE_SYSTEM) && ENABLE(WORKERS)
-String MIMETypeRegistry::getMIMETypeForExtensionThreadSafe(const String &ext)
+String MIMETypeRegistry::getMIMETypeForExtension(const String &ext)
{
return PlatformBridge::mimeTypeForExtension(ext);
}
-#endif
-// NOTE: We have to define getMIMETypeForExtension() here though the shared
-// implementation has getMIMETypeForExtension() since we don't use the shared
-// implementation bits in MIMETypeRegistry.cpp.
-
-String MIMETypeRegistry::getMIMETypeForExtension(const String &ext)
+#if ENABLE(FILE_SYSTEM)
+String MIMETypeRegistry::getWellKnownMIMETypeForExtension(const String &ext)
{
- return PlatformBridge::mimeTypeForExtension(ext);
+ // This method must be thread safe and should not consult the OS/registry.
+ return PlatformBridge::wellKnownMimeTypeForExtension(ext);
}
+#endif
// Returns the file extension if one is found. Does not include the dot in the
// filename. E.g., 'html'.
Modified: branches/chromium/782/Source/WebCore/platform/chromium/PlatformBridge.h (90866 => 90867)
--- branches/chromium/782/Source/WebCore/platform/chromium/PlatformBridge.h 2011-07-12 23:31:05 UTC (rev 90866)
+++ branches/chromium/782/Source/WebCore/platform/chromium/PlatformBridge.h 2011-07-12 23:32:48 UTC (rev 90867)
@@ -204,6 +204,7 @@
static bool isSupportedJavaScriptMIMEType(const String& mimeType);
static bool isSupportedNonImageMIMEType(const String& mimeType);
static String mimeTypeForExtension(const String& fileExtension);
+ static String wellKnownMimeTypeForExtension(const String& fileExtension);
static String mimeTypeFromFile(const String& filePath);
static String preferredExtensionForMIMEType(const String& mimeType);
Modified: branches/chromium/782/Source/WebKit/chromium/public/WebMimeRegistry.h (90866 => 90867)
--- branches/chromium/782/Source/WebKit/chromium/public/WebMimeRegistry.h 2011-07-12 23:31:05 UTC (rev 90866)
+++ branches/chromium/782/Source/WebKit/chromium/public/WebMimeRegistry.h 2011-07-12 23:32:48 UTC (rev 90867)
@@ -49,6 +49,7 @@
virtual SupportsType supportsNonImageMIMEType(const WebString& mimeType) = 0;
virtual WebString mimeTypeForExtension(const WebString& fileExtension) = 0;
+ virtual WebString wellKnownMimeTypeForExtension(const WebString& fileExtension) = 0;
virtual WebString mimeTypeFromFile(const WebString& filePath) = 0;
virtual WebString preferredExtensionForMIMEType(const WebString& mimeType) = 0;
Modified: branches/chromium/782/Source/WebKit/chromium/src/PlatformBridge.cpp (90866 => 90867)
--- branches/chromium/782/Source/WebKit/chromium/src/PlatformBridge.cpp 2011-07-12 23:31:05 UTC (rev 90866)
+++ branches/chromium/782/Source/WebKit/chromium/src/PlatformBridge.cpp 2011-07-12 23:32:48 UTC (rev 90867)
@@ -580,6 +580,11 @@
return webKitClient()->mimeRegistry()->mimeTypeForExtension(extension);
}
+String PlatformBridge::wellKnownMimeTypeForExtension(const String& extension)
+{
+ return webKitClient()->mimeRegistry()->wellKnownMimeTypeForExtension(extension);
+}
+
String PlatformBridge::mimeTypeFromFile(const String& path)
{
return webKitClient()->mimeRegistry()->mimeTypeFromFile(path);
_______________________________________________ webkit-changes mailing list [email protected] http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes
