Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: Source/WebCore/platform/MIMETypeRegistry.cpp

Issue 7356002: Merge 90308 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/782/
Patch Set: Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 3 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include <qimagereader.h> 42 #include <qimagereader.h>
43 #include <qimagewriter.h> 43 #include <qimagewriter.h>
44 #endif 44 #endif
45 45
46 #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) 46 #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
47 #include "ArchiveFactory.h" 47 #include "ArchiveFactory.h"
48 #endif 48 #endif
49 49
50 namespace WebCore { 50 namespace WebCore {
51 51
52 namespace {
53 struct TypeExtensionPair {
54 const char* type;
55 const char* extension;
56 };
57 }
58
59 // A table of common media MIME types and file extenstions used when a platform' s
60 // specific MIME type lookup doesn't have a match for a media file extension.
61 static const TypeExtensionPair commonMediaTypes[] = {
62
63 // Ogg
64 { "application/ogg", "ogx" },
65 { "audio/ogg", "ogg" },
66 { "audio/ogg", "oga" },
67 { "video/ogg", "ogv" },
68
69 // Annodex
70 { "application/annodex", "anx" },
71 { "audio/annodex", "axa" },
72 { "video/annodex", "axv" },
73 { "audio/speex", "spx" },
74
75 // WebM
76 { "video/webm", "webm" },
77 { "audio/webm", "webm" },
78
79 // MPEG
80 { "audio/mpeg", "m1a" },
81 { "audio/mpeg", "m2a" },
82 { "audio/mpeg", "m1s" },
83 { "audio/mpeg", "mpa" },
84 { "video/mpeg", "mpg" },
85 { "video/mpeg", "m15" },
86 { "video/mpeg", "m1s" },
87 { "video/mpeg", "m1v" },
88 { "video/mpeg", "m75" },
89 { "video/mpeg", "mpa" },
90 { "video/mpeg", "mpeg" },
91 { "video/mpeg", "mpm" },
92 { "video/mpeg", "mpv" },
93
94 // MPEG playlist
95 { "application/vnd.apple.mpegurl", "m3u8" },
96 { "application/mpegurl", "m3u8" },
97 { "application/x-mpegurl", "m3u8" },
98 { "audio/mpegurl", "m3url" },
99 { "audio/x-mpegurl", "m3url" },
100 { "audio/mpegurl", "m3u" },
101 { "audio/x-mpegurl", "m3u" },
102
103 // MPEG-4
104 { "video/x-m4v", "m4v" },
105 { "audio/x-m4a", "m4a" },
106 { "audio/x-m4b", "m4b" },
107 { "audio/x-m4p", "m4p" },
108 { "audio/mp4", "m4a" },
109
110 // MP3
111 { "audio/mp3", "mp3" },
112 { "audio/x-mp3", "mp3" },
113 { "audio/x-mpeg", "mp3" },
114
115 // MPEG-2
116 { "video/x-mpeg2", "mp2" },
117 { "video/mpeg2", "vob" },
118 { "video/mpeg2", "mod" },
119 { "video/m2ts", "m2ts" },
120 { "video/x-m2ts", "m2t" },
121 { "video/x-m2ts", "ts" },
122
123 // 3GP/3GP2
124 { "audio/3gpp", "3gpp" },
125 { "audio/3gpp2", "3g2" },
126 { "application/x-mpeg", "amc" },
127
128 // AAC
129 { "audio/aac", "aac" },
130 { "audio/aac", "adts" },
131 { "audio/x-aac", "m4r" },
132
133 // CoreAudio File
134 { "audio/x-caf", "caf" },
135 { "audio/x-gsm", "gsm" },
136
137 // ADPCM
138 { "audio/x-wav", "wav" }
139 };
140
141 #if ENABLE(FILE_SYSTEM)
142 static const char textPlain[] = "text/plain";
143 static const char textHtml[] = "text/html";
144 static const char imageJpeg[] = "image/jpeg";
145 static const char octetStream[] = "application/octet-stream";
146
147 // A table of well known MIME types used when we don't want to leak to the
148 // caller information about types known to underlying platform.
149 static const TypeExtensionPair wellKnownMimeTypes[] = {
150 { textPlain, "txt" },
151 { textPlain, "text" },
152 { textHtml, "html" },
153 { textHtml, "htm" },
154 { "text/css", "css" },
155 { "text/xml", "xml" },
156 { "text/xsl", "xsl" },
157 { "image/gif", "gif" },
158 { "image/png", "png" },
159 { imageJpeg, "jpeg" },
160 { imageJpeg, "jpg" },
161 { imageJpeg, "jfif" },
162 { imageJpeg, "pjpeg" },
163 { "image/webp", "webp" },
164 { "image/bmp", "bmp" },
165 { "application/xhtml+xml", "xhtml" },
166 { "application/x-javascript", "js" },
167 { "application/json", "json" },
168 { octetStream, "exe" },
169 { octetStream, "com" },
170 { octetStream, "bin" },
171 { "application/zip", "zip" },
172 { "application/gzip", "gz" },
173 { "application/pdf", "pdf" },
174 { "application/postscript", "ps" },
175 { "image/x-icon", "ico" },
176 { "image/tiff", "tiff" },
177 { "image/x-xbitmap", "xbm" },
178 { "image/svg+xml", "svg" },
179 { "application/rss+xml", "rss" },
180 { "application/rdf+xml", "rdf" },
181 { "application/x-shockwave-flash", "swf" },
182 };
183 #endif
184
52 static HashSet<String>* supportedImageResourceMIMETypes; 185 static HashSet<String>* supportedImageResourceMIMETypes;
53 static HashSet<String>* supportedImageMIMETypes; 186 static HashSet<String>* supportedImageMIMETypes;
54 static HashSet<String>* supportedImageMIMETypesForEncoding; 187 static HashSet<String>* supportedImageMIMETypesForEncoding;
55 static HashSet<String>* supportedJavaScriptMIMETypes; 188 static HashSet<String>* supportedJavaScriptMIMETypes;
56 static HashSet<String>* supportedNonImageMIMETypes; 189 static HashSet<String>* supportedNonImageMIMETypes;
57 static HashSet<String>* supportedMediaMIMETypes; 190 static HashSet<String>* supportedMediaMIMETypes;
58 static HashSet<String>* unsupportedTextMIMETypes; 191 static HashSet<String>* unsupportedTextMIMETypes;
59 192
60 typedef HashMap<String, Vector<String>*, CaseFoldingHash> MediaMIMETypeMap; 193 typedef HashMap<String, Vector<String>*, CaseFoldingHash> MediaMIMETypeMap;
61 194
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 for (size_t i = 0; i < WTF_ARRAY_LENGTH(types); ++i) 358 for (size_t i = 0; i < WTF_ARRAY_LENGTH(types); ++i)
226 supportedNonImageMIMETypes->add(types[i]); 359 supportedNonImageMIMETypes->add(types[i]);
227 360
228 #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML) 361 #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
229 ArchiveFactory::registerKnownArchiveMIMETypes(); 362 ArchiveFactory::registerKnownArchiveMIMETypes();
230 #endif 363 #endif
231 } 364 }
232 365
233 static MediaMIMETypeMap& mediaMIMETypeMap() 366 static MediaMIMETypeMap& mediaMIMETypeMap()
234 { 367 {
235 struct TypeExtensionPair {
236 const char* type;
237 const char* extension;
238 };
239
240 // A table of common media MIME types and file extenstions used when a platf orm's
241 // specific MIME type lookup doesn't have a match for a media file extension .
242 static const TypeExtensionPair pairs[] = {
243
244 // Ogg
245 { "application/ogg", "ogx" },
246 { "audio/ogg", "ogg" },
247 { "audio/ogg", "oga" },
248 { "video/ogg", "ogv" },
249
250 // Annodex
251 { "application/annodex", "anx" },
252 { "audio/annodex", "axa" },
253 { "video/annodex", "axv" },
254 { "audio/speex", "spx" },
255
256 // WebM
257 { "video/webm", "webm" },
258 { "audio/webm", "webm" },
259
260 // MPEG
261 { "audio/mpeg", "m1a" },
262 { "audio/mpeg", "m2a" },
263 { "audio/mpeg", "m1s" },
264 { "audio/mpeg", "mpa" },
265 { "video/mpeg", "mpg" },
266 { "video/mpeg", "m15" },
267 { "video/mpeg", "m1s" },
268 { "video/mpeg", "m1v" },
269 { "video/mpeg", "m75" },
270 { "video/mpeg", "mpa" },
271 { "video/mpeg", "mpeg" },
272 { "video/mpeg", "mpm" },
273 { "video/mpeg", "mpv" },
274
275 // MPEG playlist
276 { "application/vnd.apple.mpegurl", "m3u8" },
277 { "application/mpegurl", "m3u8" },
278 { "application/x-mpegurl", "m3u8" },
279 { "audio/mpegurl", "m3url" },
280 { "audio/x-mpegurl", "m3url" },
281 { "audio/mpegurl", "m3u" },
282 { "audio/x-mpegurl", "m3u" },
283
284 // MPEG-4
285 { "video/x-m4v", "m4v" },
286 { "audio/x-m4a", "m4a" },
287 { "audio/x-m4b", "m4b" },
288 { "audio/x-m4p", "m4p" },
289 { "audio/mp4", "m4a" },
290
291 // MP3
292 { "audio/mp3", "mp3" },
293 { "audio/x-mp3", "mp3" },
294 { "audio/x-mpeg", "mp3" },
295
296 // MPEG-2
297 { "video/x-mpeg2", "mp2" },
298 { "video/mpeg2", "vob" },
299 { "video/mpeg2", "mod" },
300 { "video/m2ts", "m2ts" },
301 { "video/x-m2ts", "m2t" },
302 { "video/x-m2ts", "ts" },
303
304 // 3GP/3GP2
305 { "audio/3gpp", "3gpp" },
306 { "audio/3gpp2", "3g2" },
307 { "application/x-mpeg", "amc" },
308
309 // AAC
310 { "audio/aac", "aac" },
311 { "audio/aac", "adts" },
312 { "audio/x-aac", "m4r" },
313
314 // CoreAudio File
315 { "audio/x-caf", "caf" },
316 { "audio/x-gsm", "gsm" },
317
318 // ADPCM
319 { "audio/x-wav", "wav" }
320 };
321
322 DEFINE_STATIC_LOCAL(MediaMIMETypeMap, mediaMIMETypeForExtensionMap, ()); 368 DEFINE_STATIC_LOCAL(MediaMIMETypeMap, mediaMIMETypeForExtensionMap, ());
323 369
324 if (!mediaMIMETypeForExtensionMap.isEmpty()) 370 if (!mediaMIMETypeForExtensionMap.isEmpty())
325 return mediaMIMETypeForExtensionMap; 371 return mediaMIMETypeForExtensionMap;
326 372
327 const unsigned numPairs = sizeof(pairs) / sizeof(pairs[0]); 373 const unsigned numPairs = sizeof(commonMediaTypes) / sizeof(commonMediaTypes [0]);
328 for (unsigned ndx = 0; ndx < numPairs; ++ndx) { 374 for (unsigned ndx = 0; ndx < numPairs; ++ndx) {
329 375
330 if (mediaMIMETypeForExtensionMap.contains(pairs[ndx].extension)) 376 if (mediaMIMETypeForExtensionMap.contains(commonMediaTypes[ndx].extensio n))
331 mediaMIMETypeForExtensionMap.get(pairs[ndx].extension)->append(pairs [ndx].type); 377 mediaMIMETypeForExtensionMap.get(commonMediaTypes[ndx].extension)->a ppend(commonMediaTypes[ndx].type);
332 else { 378 else {
333 Vector<String>* synonyms = new Vector<String>; 379 Vector<String>* synonyms = new Vector<String>;
334 380
335 // If there is a system specific type for this extension, add it as the first type so 381 // If there is a system specific type for this extension, add it as the first type so
336 // getMediaMIMETypeForExtension will always return it. 382 // getMediaMIMETypeForExtension will always return it.
337 String systemType = MIMETypeRegistry::getMIMETypeForExtension(pairs[ ndx].extension); 383 String systemType = MIMETypeRegistry::getMIMETypeForExtension(common MediaTypes[ndx].extension);
338 if (!systemType.isEmpty() && pairs[ndx].type != systemType) 384 if (!systemType.isEmpty() && commonMediaTypes[ndx].type != systemTyp e)
339 synonyms->append(systemType); 385 synonyms->append(systemType);
340 synonyms->append(pairs[ndx].type); 386 synonyms->append(commonMediaTypes[ndx].type);
341 mediaMIMETypeForExtensionMap.add(pairs[ndx].extension, synonyms); 387 mediaMIMETypeForExtensionMap.add(commonMediaTypes[ndx].extension, sy nonyms);
342 } 388 }
343 } 389 }
344 390
345 return mediaMIMETypeForExtensionMap; 391 return mediaMIMETypeForExtensionMap;
346 } 392 }
347 393
348 #if ENABLE(FILE_SYSTEM) && ENABLE(WORKERS)
349 String MIMETypeRegistry::getMIMETypeForExtension(const String& extension)
350 {
351 return getMIMETypeForExtensionThreadSafe(extension);
352 }
353 #endif
354
355 String MIMETypeRegistry::getMediaMIMETypeForExtension(const String& ext) 394 String MIMETypeRegistry::getMediaMIMETypeForExtension(const String& ext)
356 { 395 {
357 // Look in the system-specific registry first. 396 // Look in the system-specific registry first.
358 String type = getMIMETypeForExtension(ext); 397 String type = getMIMETypeForExtension(ext);
359 if (!type.isEmpty()) 398 if (!type.isEmpty())
360 return type; 399 return type;
361 400
362 Vector<String>* typeList = mediaMIMETypeMap().get(ext); 401 Vector<String>* typeList = mediaMIMETypeMap().get(ext);
363 if (typeList) 402 if (typeList)
364 return (*typeList)[0]; 403 return (*typeList)[0];
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 initializeSupportedNonImageMimeTypes(); 462 initializeSupportedNonImageMimeTypes();
424 463
425 supportedImageResourceMIMETypes = new HashSet<String>; 464 supportedImageResourceMIMETypes = new HashSet<String>;
426 supportedImageMIMETypes = new HashSet<String>; 465 supportedImageMIMETypes = new HashSet<String>;
427 initializeSupportedImageMIMETypes(); 466 initializeSupportedImageMIMETypes();
428 467
429 unsupportedTextMIMETypes = new HashSet<String>; 468 unsupportedTextMIMETypes = new HashSet<String>;
430 initializeUnsupportedTextMIMETypes(); 469 initializeUnsupportedTextMIMETypes();
431 } 470 }
432 471
472 #if ENABLE(FILE_SYSTEM)
473 static String findMimeType(const TypeExtensionPair* pairs, unsigned numPairs, co nst String& extension)
474 {
475 if (!extension.isEmpty()) {
476 for (unsigned i = 0; i < numPairs; ++i, ++pairs) {
477 if (equalIgnoringCase(extension, pairs->extension))
478 return String(pairs->type);
479 }
480 }
481 return String();
482 }
483
484 String MIMETypeRegistry::getWellKnownMIMETypeForExtension(const String& extensio n)
485 {
486 // This method must be thread safe and should not consult the OS/registry.
487 String found = findMimeType(wellKnownMimeTypes, sizeof(wellKnownMimeTypes) / sizeof(wellKnownMimeTypes[0]), extension);
488 if (!found.isEmpty())
489 return found;
490 return findMimeType(commonMediaTypes, sizeof(commonMediaTypes) / sizeof(comm onMediaTypes[0]), extension);
491 }
492 #endif
493
433 String MIMETypeRegistry::getMIMETypeForPath(const String& path) 494 String MIMETypeRegistry::getMIMETypeForPath(const String& path)
434 { 495 {
435 size_t pos = path.reverseFind('.'); 496 size_t pos = path.reverseFind('.');
436 if (pos != notFound) { 497 if (pos != notFound) {
437 String extension = path.substring(pos + 1); 498 String extension = path.substring(pos + 1);
438 String result = getMIMETypeForExtension(extension); 499 String result = getMIMETypeForExtension(extension);
439 if (result.length()) 500 if (result.length())
440 return result; 501 return result;
441 } 502 }
442 return "application/octet-stream"; 503 return "application/octet-stream";
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 return *unsupportedTextMIMETypes; 621 return *unsupportedTextMIMETypes;
561 } 622 }
562 623
563 const String& defaultMIMEType() 624 const String& defaultMIMEType()
564 { 625 {
565 DEFINE_STATIC_LOCAL(const String, defaultMIMEType, ("application/octet-strea m")); 626 DEFINE_STATIC_LOCAL(const String, defaultMIMEType, ("application/octet-strea m"));
566 return defaultMIMEType; 627 return defaultMIMEType;
567 } 628 }
568 629
569 } // namespace WebCore 630 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/WebCore/platform/MIMETypeRegistry.h ('k') | Source/WebCore/platform/chromium/MIMETypeRegistryChromium.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698