Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <algorithm> | 5 #include <algorithm> |
| 6 #include <iterator> | 6 #include <iterator> |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 using std::string; | 24 using std::string; |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 struct MediaType { | 28 struct MediaType { |
| 29 const char name[12]; | 29 const char name[12]; |
| 30 const char matcher[13]; | 30 const char matcher[13]; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 static const MediaType kIanaMediaTypes[] = { | 33 static const MediaType kIanaMediaTypes[] = { |
| 34 { "application", "application/" }, | 34 {"application", "application/"}, |
| 35 { "audio", "audio/" }, | 35 {"audio", "audio/"}, |
| 36 { "example", "example/" }, | 36 {"example", "example/"}, |
| 37 { "image", "image/" }, | 37 {"image", "image/"}, |
| 38 { "message", "message/" }, | 38 {"message", "message/"}, |
| 39 { "model", "model/" }, | 39 {"model", "model/"}, |
| 40 { "multipart", "multipart/" }, | 40 {"multipart", "multipart/"}, |
| 41 { "text", "text/" }, | 41 {"text", "text/"}, |
| 42 { "video", "video/" }, | 42 {"video", "video/"}, |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 namespace net { | 47 namespace net { |
| 48 | 48 |
| 49 // Singleton utility class for mime types. | 49 // Singleton utility class for mime types. |
| 50 class MimeUtil : public PlatformMimeUtil { | 50 class MimeUtil : public PlatformMimeUtil { |
| 51 public: | 51 public: |
| 52 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, | 52 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, |
| 53 std::string* mime_type) const; | 53 std::string* mime_type) const; |
| 54 | 54 |
| 55 bool GetMimeTypeFromFile(const base::FilePath& file_path, | 55 bool GetMimeTypeFromFile(const base::FilePath& file_path, |
| 56 std::string* mime_type) const; | 56 std::string* mime_type) const; |
| 57 | 57 |
| 58 bool GetWellKnownMimeTypeFromExtension(const base::FilePath::StringType& ext, | 58 bool GetWellKnownMimeTypeFromExtension(const base::FilePath::StringType& ext, |
| 59 std::string* mime_type) const; | 59 std::string* mime_type) const; |
| 60 | 60 |
| 61 bool IsSupportedImageMimeType(const std::string& mime_type) const; | 61 bool IsSupportedImageMimeType(const std::string& mime_type) const; |
| 62 bool IsSupportedMediaMimeType(const std::string& mime_type) const; | 62 bool IsSupportedMediaMimeType(const std::string& mime_type) const; |
| 63 bool IsSupportedNonImageMimeType(const std::string& mime_type) const; | 63 bool IsSupportedNonImageMimeType(const std::string& mime_type) const; |
| 64 bool IsUnsupportedTextMimeType(const std::string& mime_type) const; | 64 bool IsUnsupportedTextMimeType(const std::string& mime_type) const; |
| 65 bool IsSupportedJavascriptMimeType(const std::string& mime_type) const; | 65 bool IsSupportedJavascriptMimeType(const std::string& mime_type) const; |
| 66 | 66 |
| 67 bool IsSupportedMimeType(const std::string& mime_type) const; | 67 bool IsSupportedMimeType(const std::string& mime_type) const; |
| 68 | 68 |
| 69 bool MatchesMimeType(const std::string &mime_type_pattern, | 69 bool MatchesMimeType(const std::string& mime_type_pattern, |
| 70 const std::string &mime_type) const; | 70 const std::string& mime_type) const; |
| 71 | 71 |
| 72 bool IsMimeType(const std::string& type_string) const; | 72 bool IsMimeType(const std::string& type_string) const; |
| 73 | 73 |
| 74 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; | 74 bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; |
| 75 | 75 |
| 76 void ParseCodecString(const std::string& codecs, | 76 void ParseCodecString(const std::string& codecs, |
| 77 std::vector<std::string>* codecs_out, | 77 std::vector<std::string>* codecs_out, |
| 78 bool strip); | 78 bool strip); |
| 79 | 79 |
| 80 bool IsStrictMediaMimeType(const std::string& mime_type) const; | 80 bool IsStrictMediaMimeType(const std::string& mime_type) const; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 // This variable is Leaky because we need to access it from WorkerPool threads. | 117 // This variable is Leaky because we need to access it from WorkerPool threads. |
| 118 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = | 118 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = |
| 119 LAZY_INSTANCE_INITIALIZER; | 119 LAZY_INSTANCE_INITIALIZER; |
| 120 | 120 |
| 121 struct MimeInfo { | 121 struct MimeInfo { |
| 122 const char* mime_type; | 122 const char* mime_type; |
| 123 const char* extensions; // comma separated list | 123 const char* extensions; // comma separated list |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 static const MimeInfo primary_mappings[] = { | 126 static const MimeInfo primary_mappings[] = { |
| 127 { "text/html", "html,htm,shtml,shtm" }, | 127 {"text/html", "html,htm,shtml,shtm"}, |
| 128 { "text/css", "css" }, | 128 {"text/css", "css"}, |
| 129 { "text/xml", "xml" }, | 129 {"text/xml", "xml"}, |
| 130 { "image/gif", "gif" }, | 130 {"image/gif", "gif"}, |
| 131 { "image/jpeg", "jpeg,jpg" }, | 131 {"image/jpeg", "jpeg,jpg"}, |
| 132 { "image/webp", "webp" }, | 132 {"image/webp", "webp"}, |
| 133 { "image/png", "png" }, | 133 {"image/png", "png"}, |
| 134 { "video/mp4", "mp4,m4v" }, | 134 {"video/mp4", "mp4,m4v"}, |
| 135 { "audio/x-m4a", "m4a" }, | 135 {"audio/x-m4a", "m4a"}, |
| 136 { "audio/mp3", "mp3" }, | 136 {"audio/mp3", "mp3"}, |
| 137 { "video/ogg", "ogv,ogm" }, | 137 {"video/ogg", "ogv,ogm"}, |
| 138 { "audio/ogg", "ogg,oga,opus" }, | 138 {"audio/ogg", "ogg,oga,opus"}, |
| 139 { "video/webm", "webm" }, | 139 {"video/webm", "webm"}, |
| 140 { "audio/webm", "webm" }, | 140 {"audio/webm", "webm"}, |
| 141 { "audio/wav", "wav" }, | 141 {"audio/wav", "wav"}, |
| 142 { "application/xhtml+xml", "xhtml,xht,xhtm" }, | 142 {"application/xhtml+xml", "xhtml,xht,xhtm"}, |
| 143 { "application/x-chrome-extension", "crx" }, | 143 {"application/x-chrome-extension", "crx"}, |
| 144 { "multipart/related", "mhtml,mht" } | 144 {"multipart/related", "mhtml,mht"}}; |
| 145 }; | |
| 146 | 145 |
| 147 static const MimeInfo secondary_mappings[] = { | 146 static const MimeInfo secondary_mappings[] = { |
| 148 { "application/octet-stream", "exe,com,bin" }, | 147 {"application/octet-stream", "exe,com,bin"}, |
| 149 { "application/gzip", "gz" }, | 148 {"application/gzip", "gz"}, |
| 150 { "application/pdf", "pdf" }, | 149 {"application/pdf", "pdf"}, |
| 151 { "application/postscript", "ps,eps,ai" }, | 150 {"application/postscript", "ps,eps,ai"}, |
| 152 { "application/javascript", "js" }, | 151 {"application/javascript", "js"}, |
| 153 { "application/font-woff", "woff" }, | 152 {"application/font-woff", "woff"}, |
| 154 { "image/bmp", "bmp" }, | 153 {"image/bmp", "bmp"}, |
| 155 { "image/x-icon", "ico" }, | 154 {"image/x-icon", "ico"}, |
| 156 { "image/vnd.microsoft.icon", "ico" }, | 155 {"image/vnd.microsoft.icon", "ico"}, |
| 157 { "image/jpeg", "jfif,pjpeg,pjp" }, | 156 {"image/jpeg", "jfif,pjpeg,pjp"}, |
| 158 { "image/tiff", "tiff,tif" }, | 157 {"image/tiff", "tiff,tif"}, |
| 159 { "image/x-xbitmap", "xbm" }, | 158 {"image/x-xbitmap", "xbm"}, |
| 160 { "image/svg+xml", "svg,svgz" }, | 159 {"image/svg+xml", "svg,svgz"}, |
| 161 { "message/rfc822", "eml" }, | 160 {"message/rfc822", "eml"}, |
| 162 { "text/plain", "txt,text" }, | 161 {"text/plain", "txt,text"}, |
| 163 { "text/html", "ehtml" }, | 162 {"text/html", "ehtml"}, |
| 164 { "application/rss+xml", "rss" }, | 163 {"application/rss+xml", "rss"}, |
| 165 { "application/rdf+xml", "rdf" }, | 164 {"application/rdf+xml", "rdf"}, |
| 166 { "text/xml", "xsl,xbl,xslt" }, | 165 {"text/xml", "xsl,xbl,xslt"}, |
| 167 { "application/vnd.mozilla.xul+xml", "xul" }, | 166 {"application/vnd.mozilla.xul+xml", "xul"}, |
| 168 { "application/x-shockwave-flash", "swf,swl" }, | 167 {"application/x-shockwave-flash", "swf,swl"}, |
| 169 { "application/pkcs7-mime", "p7m,p7c,p7z" }, | 168 {"application/pkcs7-mime", "p7m,p7c,p7z"}, |
| 170 { "application/pkcs7-signature", "p7s" } | 169 {"application/pkcs7-signature", "p7s"}}; |
| 171 }; | |
| 172 | 170 |
| 173 static const char* FindMimeType(const MimeInfo* mappings, | 171 static const char* FindMimeType(const MimeInfo* mappings, |
| 174 size_t mappings_len, | 172 size_t mappings_len, |
| 175 const char* ext) { | 173 const char* ext) { |
| 176 size_t ext_len = strlen(ext); | 174 size_t ext_len = strlen(ext); |
| 177 | 175 |
| 178 for (size_t i = 0; i < mappings_len; ++i) { | 176 for (size_t i = 0; i < mappings_len; ++i) { |
| 179 const char* extensions = mappings[i].extensions; | 177 const char* extensions = mappings[i].extensions; |
| 180 for (;;) { | 178 for (;;) { |
| 181 size_t end_pos = strcspn(extensions, ","); | 179 size_t end_pos = strcspn(extensions, ","); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 return false; | 218 return false; |
| 221 | 219 |
| 222 // We implement the same algorithm as Mozilla for mapping a file extension to | 220 // We implement the same algorithm as Mozilla for mapping a file extension to |
| 223 // a mime type. That is, we first check a hard-coded list (that cannot be | 221 // a mime type. That is, we first check a hard-coded list (that cannot be |
| 224 // overridden), and then if not found there, we defer to the system registry. | 222 // overridden), and then if not found there, we defer to the system registry. |
| 225 // Finally, we scan a secondary hard-coded list to catch types that we can | 223 // Finally, we scan a secondary hard-coded list to catch types that we can |
| 226 // deduce but that we also want to allow the OS to override. | 224 // deduce but that we also want to allow the OS to override. |
| 227 | 225 |
| 228 base::FilePath path_ext(ext); | 226 base::FilePath path_ext(ext); |
| 229 const string ext_narrow_str = path_ext.AsUTF8Unsafe(); | 227 const string ext_narrow_str = path_ext.AsUTF8Unsafe(); |
| 230 const char* mime_type = FindMimeType(primary_mappings, | 228 const char* mime_type = FindMimeType( |
| 231 arraysize(primary_mappings), | 229 primary_mappings, arraysize(primary_mappings), ext_narrow_str.c_str()); |
| 232 ext_narrow_str.c_str()); | |
| 233 if (mime_type) { | 230 if (mime_type) { |
| 234 *result = mime_type; | 231 *result = mime_type; |
| 235 return true; | 232 return true; |
| 236 } | 233 } |
| 237 | 234 |
| 238 if (include_platform_types && GetPlatformMimeTypeFromExtension(ext, result)) | 235 if (include_platform_types && GetPlatformMimeTypeFromExtension(ext, result)) |
| 239 return true; | 236 return true; |
| 240 | 237 |
| 241 mime_type = FindMimeType(secondary_mappings, arraysize(secondary_mappings), | 238 mime_type = FindMimeType(secondary_mappings, |
| 239 arraysize(secondary_mappings), | |
| 242 ext_narrow_str.c_str()); | 240 ext_narrow_str.c_str()); |
| 243 if (mime_type) { | 241 if (mime_type) { |
| 244 *result = mime_type; | 242 *result = mime_type; |
| 245 return true; | 243 return true; |
| 246 } | 244 } |
| 247 | 245 |
| 248 return false; | 246 return false; |
| 249 } | 247 } |
| 250 | 248 |
| 251 // From WebKit's WebCore/platform/MIMETypeRegistry.cpp: | 249 // From WebKit's WebCore/platform/MIMETypeRegistry.cpp: |
| 252 | 250 |
| 253 static const char* const supported_image_types[] = { | 251 static const char* const supported_image_types[] = { |
| 254 "image/jpeg", | 252 "image/jpeg", "image/pjpeg", "image/jpg", "image/webp", |
| 255 "image/pjpeg", | 253 "image/png", "image/gif", "image/bmp", |
|
mmenke
2014/10/10 18:12:39
This is kinda weird.
| |
| 256 "image/jpg", | 254 "image/vnd.microsoft.icon", // ico |
| 257 "image/webp", | 255 "image/x-icon", // ico |
| 258 "image/png", | 256 "image/x-xbitmap" // xbm |
| 259 "image/gif", | |
| 260 "image/bmp", | |
| 261 "image/vnd.microsoft.icon", // ico | |
| 262 "image/x-icon", // ico | |
| 263 "image/x-xbitmap" // xbm | |
| 264 }; | 257 }; |
| 265 | 258 |
| 266 // A list of media types: http://en.wikipedia.org/wiki/Internet_media_type | 259 // A list of media types: http://en.wikipedia.org/wiki/Internet_media_type |
| 267 // A comprehensive mime type list: http://plugindoc.mozdev.org/winmime.php | 260 // A comprehensive mime type list: http://plugindoc.mozdev.org/winmime.php |
| 268 // This set of codecs is supported by all variations of Chromium. | 261 // This set of codecs is supported by all variations of Chromium. |
| 269 static const char* const common_media_types[] = { | 262 static const char* const common_media_types[] = { |
| 270 // Ogg. | 263 // Ogg. |
| 271 "audio/ogg", | 264 "audio/ogg", "application/ogg", |
| 272 "application/ogg", | |
| 273 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora. | 265 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora. |
| 274 "video/ogg", | 266 "video/ogg", |
| 275 #endif | 267 #endif |
| 276 | 268 |
| 277 // WebM. | 269 // WebM. |
| 278 "video/webm", | 270 "video/webm", "audio/webm", |
| 279 "audio/webm", | |
| 280 | 271 |
| 281 // Wav. | 272 // Wav. |
| 282 "audio/wav", | 273 "audio/wav", "audio/x-wav", |
| 283 "audio/x-wav", | |
| 284 | 274 |
| 285 #if defined(OS_ANDROID) | 275 #if defined(OS_ANDROID) |
| 286 // HLS. Supported by Android ICS and above. | 276 // HLS. Supported by Android ICS and above. |
| 287 "application/vnd.apple.mpegurl", | 277 "application/vnd.apple.mpegurl", "application/x-mpegurl", |
| 288 "application/x-mpegurl", | |
| 289 #endif | 278 #endif |
| 290 }; | 279 }; |
| 291 | 280 |
| 292 // List of proprietary types only supported by Google Chrome. | 281 // List of proprietary types only supported by Google Chrome. |
| 293 static const char* const proprietary_media_types[] = { | 282 static const char* const proprietary_media_types[] = { |
| 294 // MPEG-4. | 283 // MPEG-4. |
| 295 "video/mp4", | 284 "video/mp4", "video/x-m4v", "audio/mp4", "audio/x-m4a", |
| 296 "video/x-m4v", | |
| 297 "audio/mp4", | |
| 298 "audio/x-m4a", | |
| 299 | 285 |
| 300 // MP3. | 286 // MP3. |
| 301 "audio/mp3", | 287 "audio/mp3", "audio/x-mp3", "audio/mpeg", |
| 302 "audio/x-mp3", | |
| 303 "audio/mpeg", | |
| 304 }; | 288 }; |
| 305 | 289 |
| 306 // List of supported codecs when passed in with <source type="...">. | 290 // List of supported codecs when passed in with <source type="...">. |
| 307 // This set of codecs is supported by all variations of Chromium. | 291 // This set of codecs is supported by all variations of Chromium. |
| 308 // | 292 // |
| 309 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support | 293 // Refer to http://wiki.whatwg.org/wiki/Video_type_parameters#Browser_Support |
| 310 // for more information. | 294 // for more information. |
| 311 // | 295 // |
| 312 // The codecs for WAV are integers as defined in Appendix A of RFC2361: | 296 // The codecs for WAV are integers as defined in Appendix A of RFC2361: |
| 313 // http://tools.ietf.org/html/rfc2361 | 297 // http://tools.ietf.org/html/rfc2361 |
| 314 static const char* const common_media_codecs[] = { | 298 static const char* const common_media_codecs[] = { |
| 315 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora. | 299 #if !defined(OS_ANDROID) // Android doesn't support Ogg Theora. |
| 316 "theora", | 300 "theora", |
| 317 #endif | 301 #endif |
| 318 "opus", | 302 "opus", "vorbis", "vp8", "vp9", |
| 319 "vorbis", | 303 "1" // WAVE_FORMAT_PCM. |
| 320 "vp8", | |
| 321 "vp9", | |
| 322 "1" // WAVE_FORMAT_PCM. | |
| 323 }; | 304 }; |
| 324 | 305 |
| 325 // List of proprietary codecs only supported by Google Chrome. | 306 // List of proprietary codecs only supported by Google Chrome. |
| 326 static const char* const proprietary_media_codecs[] = { | 307 static const char* const proprietary_media_codecs[] = {"avc1", "avc3", "mp4a"}; |
| 327 "avc1", | |
| 328 "avc3", | |
| 329 "mp4a" | |
| 330 }; | |
| 331 | 308 |
| 332 // Note: | 309 // Note: |
| 333 // - does not include javascript types list (see supported_javascript_types) | 310 // - does not include javascript types list (see supported_javascript_types) |
| 334 // - does not include types starting with "text/" (see | 311 // - does not include types starting with "text/" (see |
| 335 // IsSupportedNonImageMimeType()) | 312 // IsSupportedNonImageMimeType()) |
| 336 static const char* const supported_non_image_types[] = { | 313 static const char* const supported_non_image_types[] = { |
| 337 "image/svg+xml", // SVG is text-based XML, even though it has an image/ type | 314 "image/svg+xml", // SVG is text-based XML, even though it has an image/ |
| 338 "application/xml", | 315 // type |
| 339 "application/atom+xml", | 316 "application/xml", "application/atom+xml", "application/rss+xml", |
| 340 "application/rss+xml", | 317 "application/xhtml+xml", "application/json", |
| 341 "application/xhtml+xml", | 318 "multipart/related", // For MHTML support. |
| 342 "application/json", | 319 "multipart/x-mixed-replace" |
| 343 "multipart/related", // For MHTML support. | 320 // Note: ADDING a new type here will probably render it AS HTML. This can |
| 344 "multipart/x-mixed-replace" | 321 // result in cross site scripting. |
| 345 // Note: ADDING a new type here will probably render it AS HTML. This can | |
| 346 // result in cross site scripting. | |
| 347 }; | 322 }; |
| 348 | 323 |
| 349 // Dictionary of cryptographic file mime types. | 324 // Dictionary of cryptographic file mime types. |
| 350 struct CertificateMimeTypeInfo { | 325 struct CertificateMimeTypeInfo { |
| 351 const char* mime_type; | 326 const char* mime_type; |
| 352 CertificateMimeType cert_type; | 327 CertificateMimeType cert_type; |
| 353 }; | 328 }; |
| 354 | 329 |
| 355 static const CertificateMimeTypeInfo supported_certificate_types[] = { | 330 static const CertificateMimeTypeInfo supported_certificate_types[] = { |
| 356 { "application/x-x509-user-cert", | 331 {"application/x-x509-user-cert", CERTIFICATE_MIME_TYPE_X509_USER_CERT}, |
| 357 CERTIFICATE_MIME_TYPE_X509_USER_CERT }, | |
| 358 #if defined(OS_ANDROID) | 332 #if defined(OS_ANDROID) |
| 359 { "application/x-x509-ca-cert", CERTIFICATE_MIME_TYPE_X509_CA_CERT }, | 333 {"application/x-x509-ca-cert", CERTIFICATE_MIME_TYPE_X509_CA_CERT}, |
| 360 { "application/x-pkcs12", CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE }, | 334 {"application/x-pkcs12", CERTIFICATE_MIME_TYPE_PKCS12_ARCHIVE}, |
| 361 #endif | 335 #endif |
| 362 }; | 336 }; |
| 363 | 337 |
| 364 // These types are excluded from the logic that allows all text/ types because | 338 // These types are excluded from the logic that allows all text/ types because |
| 365 // while they are technically text, it's very unlikely that a user expects to | 339 // while they are technically text, it's very unlikely that a user expects to |
| 366 // see them rendered in text form. | 340 // see them rendered in text form. |
| 367 static const char* const unsupported_text_types[] = { | 341 static const char* const unsupported_text_types[] = { |
| 368 "text/calendar", | 342 "text/calendar", "text/x-calendar", |
| 369 "text/x-calendar", | 343 "text/x-vcalendar", "text/vcalendar", |
| 370 "text/x-vcalendar", | 344 "text/vcard", "text/x-vcard", |
| 371 "text/vcalendar", | 345 "text/directory", "text/ldif", |
| 372 "text/vcard", | 346 "text/qif", "text/x-qif", |
| 373 "text/x-vcard", | 347 "text/x-csv", "text/x-vcf", |
| 374 "text/directory", | 348 "text/rtf", "text/comma-separated-values", |
| 375 "text/ldif", | 349 "text/csv", "text/tab-separated-values", |
| 376 "text/qif", | 350 "text/tsv", |
| 377 "text/x-qif", | 351 "text/ofx", // http://crbug.com/162238 |
| 378 "text/x-csv", | 352 "text/vnd.sun.j2me.app-descriptor" // http://crbug.com/176450 |
| 379 "text/x-vcf", | |
| 380 "text/rtf", | |
| 381 "text/comma-separated-values", | |
| 382 "text/csv", | |
| 383 "text/tab-separated-values", | |
| 384 "text/tsv", | |
| 385 "text/ofx", // http://crbug.com/162238 | |
| 386 "text/vnd.sun.j2me.app-descriptor" // http://crbug.com/176450 | |
| 387 }; | 353 }; |
| 388 | 354 |
| 389 // Mozilla 1.8 and WinIE 7 both accept text/javascript and text/ecmascript. | 355 // Mozilla 1.8 and WinIE 7 both accept text/javascript and text/ecmascript. |
| 390 // Mozilla 1.8 accepts application/javascript, application/ecmascript, and | 356 // Mozilla 1.8 accepts application/javascript, application/ecmascript, and |
| 391 // application/x-javascript, but WinIE 7 doesn't. | 357 // application/x-javascript, but WinIE 7 doesn't. |
| 392 // WinIE 7 accepts text/javascript1.1 - text/javascript1.3, text/jscript, and | 358 // WinIE 7 accepts text/javascript1.1 - text/javascript1.3, text/jscript, and |
| 393 // text/livescript, but Mozilla 1.8 doesn't. | 359 // text/livescript, but Mozilla 1.8 doesn't. |
| 394 // Mozilla 1.8 allows leading and trailing whitespace, but WinIE 7 doesn't. | 360 // Mozilla 1.8 allows leading and trailing whitespace, but WinIE 7 doesn't. |
| 395 // Mozilla 1.8 and WinIE 7 both accept the empty string, but neither accept a | 361 // Mozilla 1.8 and WinIE 7 both accept the empty string, but neither accept a |
| 396 // whitespace-only string. | 362 // whitespace-only string. |
| 397 // We want to accept all the values that either of these browsers accept, but | 363 // We want to accept all the values that either of these browsers accept, but |
| 398 // not other values. | 364 // not other values. |
| 399 static const char* const supported_javascript_types[] = { | 365 static const char* const supported_javascript_types[] = { |
| 400 "text/javascript", | 366 "text/javascript", "text/ecmascript", |
| 401 "text/ecmascript", | 367 "application/javascript", "application/ecmascript", |
| 402 "application/javascript", | 368 "application/x-javascript", "text/javascript1.1", |
| 403 "application/ecmascript", | 369 "text/javascript1.2", "text/javascript1.3", |
| 404 "application/x-javascript", | 370 "text/jscript", "text/livescript"}; |
| 405 "text/javascript1.1", | |
| 406 "text/javascript1.2", | |
| 407 "text/javascript1.3", | |
| 408 "text/jscript", | |
| 409 "text/livescript" | |
| 410 }; | |
| 411 | 371 |
| 412 #if defined(OS_ANDROID) | 372 #if defined(OS_ANDROID) |
| 413 static bool IsCodecSupportedOnAndroid(const std::string& codec) { | 373 static bool IsCodecSupportedOnAndroid(const std::string& codec) { |
| 414 // VP9 is supported only in KitKat+ (API Level 19). | 374 // VP9 is supported only in KitKat+ (API Level 19). |
| 415 if ((!codec.compare("vp9") || !codec.compare("vp9.0")) && | 375 if ((!codec.compare("vp9") || !codec.compare("vp9.0")) && |
| 416 base::android::BuildInfo::GetInstance()->sdk_int() < 19) { | 376 base::android::BuildInfo::GetInstance()->sdk_int() < 19) { |
| 417 return false; | 377 return false; |
| 418 } | 378 } |
| 419 | 379 |
| 420 // TODO(vigneshv): Change this similar to the VP9 check once Opus is | 380 // TODO(vigneshv): Change this similar to the VP9 check once Opus is |
| 421 // supported on Android (http://crbug.com/318436). | 381 // supported on Android (http://crbug.com/318436). |
| 422 if (!codec.compare("opus")) { | 382 if (!codec.compare("opus")) { |
| 423 return false; | 383 return false; |
| 424 } | 384 } |
| 425 return true; | 385 return true; |
| 426 } | 386 } |
| 427 #endif | 387 #endif |
| 428 | 388 |
| 429 struct MediaFormatStrict { | 389 struct MediaFormatStrict { |
| 430 const char* mime_type; | 390 const char* mime_type; |
| 431 const char* codecs_list; | 391 const char* codecs_list; |
| 432 }; | 392 }; |
| 433 | 393 |
| 434 static const MediaFormatStrict format_codec_mappings[] = { | 394 static const MediaFormatStrict format_codec_mappings[] = { |
| 435 { "video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0" }, | 395 {"video/webm", "opus,vorbis,vp8,vp8.0,vp9,vp9.0"}, |
| 436 { "audio/webm", "opus,vorbis" }, | 396 {"audio/webm", "opus,vorbis"}, |
| 437 { "audio/wav", "1" }, | 397 {"audio/wav", "1"}, |
| 438 { "audio/x-wav", "1" }, | 398 {"audio/x-wav", "1"}, |
| 439 { "video/ogg", "opus,theora,vorbis" }, | 399 {"video/ogg", "opus,theora,vorbis"}, |
| 440 { "audio/ogg", "opus,vorbis" }, | 400 {"audio/ogg", "opus,vorbis"}, |
| 441 { "application/ogg", "opus,theora,vorbis" }, | 401 {"application/ogg", "opus,theora,vorbis"}, |
| 442 { "audio/mpeg", "" }, | 402 {"audio/mpeg", ""}, |
| 443 { "audio/mp3", "" }, | 403 {"audio/mp3", ""}, |
| 444 { "audio/x-mp3", "" } | 404 {"audio/x-mp3", ""}}; |
| 445 }; | |
| 446 | 405 |
| 447 MimeUtil::MimeUtil() { | 406 MimeUtil::MimeUtil() { |
| 448 InitializeMimeTypeMaps(); | 407 InitializeMimeTypeMaps(); |
| 449 } | 408 } |
| 450 | 409 |
| 451 // static | 410 // static |
| 452 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, | 411 bool MimeUtil::AreSupportedCodecs(const MimeMappings& supported_codecs, |
| 453 const std::vector<std::string>& codecs) { | 412 const std::vector<std::string>& codecs) { |
| 454 if (supported_codecs.empty()) | 413 if (supported_codecs.empty()) |
| 455 return codecs.empty(); | 414 return codecs.empty(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 500 codecs_map_.insert(common_media_codecs[i]); | 459 codecs_map_.insert(common_media_codecs[i]); |
| 501 } | 460 } |
| 502 #if defined(USE_PROPRIETARY_CODECS) | 461 #if defined(USE_PROPRIETARY_CODECS) |
| 503 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 462 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) |
| 504 codecs_map_.insert(proprietary_media_codecs[i]); | 463 codecs_map_.insert(proprietary_media_codecs[i]); |
| 505 #endif | 464 #endif |
| 506 | 465 |
| 507 // Initialize the strict supported media types. | 466 // Initialize the strict supported media types. |
| 508 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { | 467 for (size_t i = 0; i < arraysize(format_codec_mappings); ++i) { |
| 509 std::vector<std::string> mime_type_codecs; | 468 std::vector<std::string> mime_type_codecs; |
| 510 ParseCodecString(format_codec_mappings[i].codecs_list, | 469 ParseCodecString( |
| 511 &mime_type_codecs, | 470 format_codec_mappings[i].codecs_list, &mime_type_codecs, false); |
| 512 false); | |
| 513 | 471 |
| 514 MimeMappings codecs; | 472 MimeMappings codecs; |
| 515 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { | 473 for (size_t j = 0; j < mime_type_codecs.size(); ++j) { |
| 516 #if defined(OS_ANDROID) | 474 #if defined(OS_ANDROID) |
| 517 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j])) | 475 if (!IsCodecSupportedOnAndroid(mime_type_codecs[j])) |
| 518 continue; | 476 continue; |
| 519 #endif | 477 #endif |
| 520 codecs.insert(mime_type_codecs[j]); | 478 codecs.insert(mime_type_codecs[j]); |
| 521 } | 479 } |
| 522 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; | 480 strict_format_map_[format_codec_mappings[i].mime_type] = codecs; |
| 523 } | 481 } |
| 524 } | 482 } |
| 525 | 483 |
| 526 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { | 484 bool MimeUtil::IsSupportedImageMimeType(const std::string& mime_type) const { |
| 527 return image_map_.find(mime_type) != image_map_.end(); | 485 return image_map_.find(mime_type) != image_map_.end(); |
| 528 } | 486 } |
| 529 | 487 |
| 530 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { | 488 bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { |
| 531 return media_map_.find(mime_type) != media_map_.end(); | 489 return media_map_.find(mime_type) != media_map_.end(); |
| 532 } | 490 } |
| 533 | 491 |
| 534 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { | 492 bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { |
| 535 return non_image_map_.find(mime_type) != non_image_map_.end() || | 493 return non_image_map_.find(mime_type) != non_image_map_.end() || |
| 536 (mime_type.compare(0, 5, "text/") == 0 && | 494 (mime_type.compare(0, 5, "text/") == 0 && |
| 537 !IsUnsupportedTextMimeType(mime_type)) || | 495 !IsUnsupportedTextMimeType(mime_type)) || |
| 538 (mime_type.compare(0, 12, "application/") == 0 && | 496 (mime_type.compare(0, 12, "application/") == 0 && |
| 539 MatchesMimeType("application/*+json", mime_type)); | 497 MatchesMimeType("application/*+json", mime_type)); |
| 540 } | 498 } |
| 541 | 499 |
| 542 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { | 500 bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { |
| 543 return unsupported_text_map_.find(mime_type) != unsupported_text_map_.end(); | 501 return unsupported_text_map_.find(mime_type) != unsupported_text_map_.end(); |
| 544 } | 502 } |
| 545 | 503 |
| 546 bool MimeUtil::IsSupportedJavascriptMimeType( | 504 bool MimeUtil::IsSupportedJavascriptMimeType( |
| 547 const std::string& mime_type) const { | 505 const std::string& mime_type) const { |
| 548 return javascript_map_.find(mime_type) != javascript_map_.end(); | 506 return javascript_map_.find(mime_type) != javascript_map_.end(); |
| 549 } | 507 } |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 560 // parameters in the pattern, the match is a success. | 518 // parameters in the pattern, the match is a success. |
| 561 bool MatchesMimeTypeParameters(const std::string& mime_type_pattern, | 519 bool MatchesMimeTypeParameters(const std::string& mime_type_pattern, |
| 562 const std::string& mime_type) { | 520 const std::string& mime_type) { |
| 563 const std::string::size_type semicolon = mime_type_pattern.find(';'); | 521 const std::string::size_type semicolon = mime_type_pattern.find(';'); |
| 564 const std::string::size_type test_semicolon = mime_type.find(';'); | 522 const std::string::size_type test_semicolon = mime_type.find(';'); |
| 565 if (semicolon != std::string::npos) { | 523 if (semicolon != std::string::npos) { |
| 566 if (test_semicolon == std::string::npos) | 524 if (test_semicolon == std::string::npos) |
| 567 return false; | 525 return false; |
| 568 | 526 |
| 569 std::vector<std::string> pattern_parameters; | 527 std::vector<std::string> pattern_parameters; |
| 570 base::SplitString(mime_type_pattern.substr(semicolon + 1), | 528 base::SplitString( |
| 571 ';', &pattern_parameters); | 529 mime_type_pattern.substr(semicolon + 1), ';', &pattern_parameters); |
| 572 | 530 |
| 573 std::vector<std::string> test_parameters; | 531 std::vector<std::string> test_parameters; |
| 574 base::SplitString(mime_type.substr(test_semicolon + 1), | 532 base::SplitString( |
| 575 ';', &test_parameters); | 533 mime_type.substr(test_semicolon + 1), ';', &test_parameters); |
| 576 | 534 |
| 577 sort(pattern_parameters.begin(), pattern_parameters.end()); | 535 sort(pattern_parameters.begin(), pattern_parameters.end()); |
| 578 sort(test_parameters.begin(), test_parameters.end()); | 536 sort(test_parameters.begin(), test_parameters.end()); |
| 579 std::vector<std::string> difference = | 537 std::vector<std::string> difference = |
| 580 base::STLSetDifference<std::vector<std::string> >(pattern_parameters, | 538 base::STLSetDifference<std::vector<std::string> >(pattern_parameters, |
| 581 test_parameters); | 539 test_parameters); |
| 582 return difference.size() == 0; | 540 return difference.size() == 0; |
| 583 } | 541 } |
| 584 return true; | 542 return true; |
| 585 } | 543 } |
| 586 | 544 |
| 587 // This comparison handles absolute maching and also basic | 545 // This comparison handles absolute maching and also basic |
| 588 // wildcards. The plugin mime types could be: | 546 // wildcards. The plugin mime types could be: |
| 589 // application/x-foo | 547 // application/x-foo |
| 590 // application/* | 548 // application/* |
| 591 // application/*+xml | 549 // application/*+xml |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 629 | 587 |
| 630 if (!right.empty() && | 588 if (!right.empty() && |
| 631 base_type.rfind(right) != base_type.length() - right.length()) | 589 base_type.rfind(right) != base_type.length() - right.length()) |
| 632 return false; | 590 return false; |
| 633 | 591 |
| 634 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); | 592 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); |
| 635 } | 593 } |
| 636 | 594 |
| 637 // See http://www.iana.org/assignments/media-types/index.html | 595 // See http://www.iana.org/assignments/media-types/index.html |
| 638 static const char* legal_top_level_types[] = { | 596 static const char* legal_top_level_types[] = { |
| 639 "application/", | 597 "application/", "audio/", "example/", "image/", "message/", |
| 640 "audio/", | 598 "model/", "multipart/", "text/", "video/", |
| 641 "example/", | |
| 642 "image/", | |
| 643 "message/", | |
| 644 "model/", | |
| 645 "multipart/", | |
| 646 "text/", | |
| 647 "video/", | |
| 648 }; | 599 }; |
| 649 | 600 |
| 650 bool MimeUtil::IsMimeType(const std::string& type_string) const { | 601 bool MimeUtil::IsMimeType(const std::string& type_string) const { |
| 651 // MIME types are always ASCII and case-insensitive (at least, the top-level | 602 // MIME types are always ASCII and case-insensitive (at least, the top-level |
| 652 // and secondary types we care about). | 603 // and secondary types we care about). |
| 653 if (!IsStringASCII(type_string)) | 604 if (!IsStringASCII(type_string)) |
| 654 return false; | 605 return false; |
| 655 | 606 |
| 656 if (type_string == "*/*" || type_string == "*") | 607 if (type_string == "*/*" || type_string == "*") |
| 657 return true; | 608 return true; |
| 658 | 609 |
| 659 for (size_t i = 0; i < arraysize(legal_top_level_types); ++i) { | 610 for (size_t i = 0; i < arraysize(legal_top_level_types); ++i) { |
| 660 if (StartsWithASCII(type_string, legal_top_level_types[i], false) && | 611 if (StartsWithASCII(type_string, legal_top_level_types[i], false) && |
| 661 type_string.length() > strlen(legal_top_level_types[i])) { | 612 type_string.length() > strlen(legal_top_level_types[i])) { |
| 662 return true; | 613 return true; |
| 663 } | 614 } |
| 664 } | 615 } |
| 665 | 616 |
| 666 // If there's a "/" separator character, and the token before it is | 617 // If there's a "/" separator character, and the token before it is |
| 667 // "x-" + (ascii characters), it is also a MIME type. | 618 // "x-" + (ascii characters), it is also a MIME type. |
| 668 size_t slash = type_string.find('/'); | 619 size_t slash = type_string.find('/'); |
| 669 if (slash < 3 || | 620 if (slash < 3 || slash == std::string::npos || |
| 670 slash == std::string::npos || slash == type_string.length() - 1) { | 621 slash == type_string.length() - 1) { |
| 671 return false; | 622 return false; |
| 672 } | 623 } |
| 673 | 624 |
| 674 if (StartsWithASCII(type_string, "x-", false)) | 625 if (StartsWithASCII(type_string, "x-", false)) |
| 675 return true; | 626 return true; |
| 676 | 627 |
| 677 return false; | 628 return false; |
| 678 } | 629 } |
| 679 | 630 |
| 680 bool MimeUtil::AreSupportedMediaCodecs( | 631 bool MimeUtil::AreSupportedMediaCodecs( |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 706 if (strict_format_map_.find(mime_type) == strict_format_map_.end()) | 657 if (strict_format_map_.find(mime_type) == strict_format_map_.end()) |
| 707 return false; | 658 return false; |
| 708 return true; | 659 return true; |
| 709 } | 660 } |
| 710 | 661 |
| 711 bool MimeUtil::IsSupportedStrictMediaMimeType( | 662 bool MimeUtil::IsSupportedStrictMediaMimeType( |
| 712 const std::string& mime_type, | 663 const std::string& mime_type, |
| 713 const std::vector<std::string>& codecs) const { | 664 const std::vector<std::string>& codecs) const { |
| 714 StrictMappings::const_iterator it = strict_format_map_.find(mime_type); | 665 StrictMappings::const_iterator it = strict_format_map_.find(mime_type); |
| 715 return (it != strict_format_map_.end()) && | 666 return (it != strict_format_map_.end()) && |
| 716 AreSupportedCodecs(it->second, codecs); | 667 AreSupportedCodecs(it->second, codecs); |
| 717 } | 668 } |
| 718 | 669 |
| 719 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { | 670 void MimeUtil::RemoveProprietaryMediaTypesAndCodecsForTests() { |
| 720 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { | 671 for (size_t i = 0; i < arraysize(proprietary_media_types); ++i) { |
| 721 non_image_map_.erase(proprietary_media_types[i]); | 672 non_image_map_.erase(proprietary_media_types[i]); |
| 722 media_map_.erase(proprietary_media_types[i]); | 673 media_map_.erase(proprietary_media_types[i]); |
| 723 } | 674 } |
| 724 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) | 675 for (size_t i = 0; i < arraysize(proprietary_media_codecs); ++i) |
| 725 codecs_map_.erase(proprietary_media_codecs[i]); | 676 codecs_map_.erase(proprietary_media_codecs[i]); |
| 726 } | 677 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 800 std::vector<std::string>* codecs_out, | 751 std::vector<std::string>* codecs_out, |
| 801 const bool strip) { | 752 const bool strip) { |
| 802 g_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); | 753 g_mime_util.Get().ParseCodecString(codecs, codecs_out, strip); |
| 803 } | 754 } |
| 804 | 755 |
| 805 namespace { | 756 namespace { |
| 806 | 757 |
| 807 // From http://www.w3schools.com/media/media_mimeref.asp and | 758 // From http://www.w3schools.com/media/media_mimeref.asp and |
| 808 // http://plugindoc.mozdev.org/winmime.php | 759 // http://plugindoc.mozdev.org/winmime.php |
| 809 static const char* const kStandardImageTypes[] = { | 760 static const char* const kStandardImageTypes[] = { |
| 810 "image/bmp", | 761 "image/bmp", "image/cis-cod", |
| 811 "image/cis-cod", | 762 "image/gif", "image/ief", |
| 812 "image/gif", | 763 "image/jpeg", "image/webp", |
| 813 "image/ief", | 764 "image/pict", "image/pipeg", |
| 814 "image/jpeg", | 765 "image/png", "image/svg+xml", |
| 815 "image/webp", | 766 "image/tiff", "image/vnd.microsoft.icon", |
| 816 "image/pict", | 767 "image/x-cmu-raster", "image/x-cmx", |
| 817 "image/pipeg", | 768 "image/x-icon", "image/x-portable-anymap", |
| 818 "image/png", | 769 "image/x-portable-bitmap", "image/x-portable-graymap", |
| 819 "image/svg+xml", | 770 "image/x-portable-pixmap", "image/x-rgb", |
| 820 "image/tiff", | 771 "image/x-xbitmap", "image/x-xpixmap", |
| 821 "image/vnd.microsoft.icon", | 772 "image/x-xwindowdump"}; |
| 822 "image/x-cmu-raster", | |
| 823 "image/x-cmx", | |
| 824 "image/x-icon", | |
| 825 "image/x-portable-anymap", | |
| 826 "image/x-portable-bitmap", | |
| 827 "image/x-portable-graymap", | |
| 828 "image/x-portable-pixmap", | |
| 829 "image/x-rgb", | |
| 830 "image/x-xbitmap", | |
| 831 "image/x-xpixmap", | |
| 832 "image/x-xwindowdump" | |
| 833 }; | |
| 834 static const char* const kStandardAudioTypes[] = { | 773 static const char* const kStandardAudioTypes[] = { |
| 835 "audio/aac", | 774 "audio/aac", "audio/aiff", "audio/amr", "audio/basic", |
| 836 "audio/aiff", | 775 "audio/midi", "audio/mp3", "audio/mp4", "audio/mpeg", |
| 837 "audio/amr", | 776 "audio/mpeg3", "audio/ogg", "audio/vorbis", "audio/wav", |
| 838 "audio/basic", | 777 "audio/webm", "audio/x-m4a", "audio/x-ms-wma", "audio/vnd.rn-realaudio", |
| 839 "audio/midi", | 778 "audio/vnd.wave"}; |
| 840 "audio/mp3", | |
| 841 "audio/mp4", | |
| 842 "audio/mpeg", | |
| 843 "audio/mpeg3", | |
| 844 "audio/ogg", | |
| 845 "audio/vorbis", | |
| 846 "audio/wav", | |
| 847 "audio/webm", | |
| 848 "audio/x-m4a", | |
| 849 "audio/x-ms-wma", | |
| 850 "audio/vnd.rn-realaudio", | |
| 851 "audio/vnd.wave" | |
| 852 }; | |
| 853 static const char* const kStandardVideoTypes[] = { | 779 static const char* const kStandardVideoTypes[] = { |
| 854 "video/avi", | 780 "video/avi", "video/divx", "video/flc", "video/mp4", |
| 855 "video/divx", | 781 "video/mpeg", "video/ogg", "video/quicktime", "video/sd-video", |
| 856 "video/flc", | 782 "video/webm", "video/x-dv", "video/x-m4v", "video/x-mpeg", |
| 857 "video/mp4", | 783 "video/x-ms-asf", "video/x-ms-wmv"}; |
| 858 "video/mpeg", | |
| 859 "video/ogg", | |
| 860 "video/quicktime", | |
| 861 "video/sd-video", | |
| 862 "video/webm", | |
| 863 "video/x-dv", | |
| 864 "video/x-m4v", | |
| 865 "video/x-mpeg", | |
| 866 "video/x-ms-asf", | |
| 867 "video/x-ms-wmv" | |
| 868 }; | |
| 869 | 784 |
| 870 struct StandardType { | 785 struct StandardType { |
| 871 const char* leading_mime_type; | 786 const char* leading_mime_type; |
| 872 const char* const* standard_types; | 787 const char* const* standard_types; |
| 873 size_t standard_types_len; | 788 size_t standard_types_len; |
| 874 }; | 789 }; |
| 875 static const StandardType kStandardTypes[] = { | 790 static const StandardType kStandardTypes[] = { |
| 876 { "image/", kStandardImageTypes, arraysize(kStandardImageTypes) }, | 791 {"image/", kStandardImageTypes, arraysize(kStandardImageTypes)}, |
| 877 { "audio/", kStandardAudioTypes, arraysize(kStandardAudioTypes) }, | 792 {"audio/", kStandardAudioTypes, arraysize(kStandardAudioTypes)}, |
| 878 { "video/", kStandardVideoTypes, arraysize(kStandardVideoTypes) }, | 793 {"video/", kStandardVideoTypes, arraysize(kStandardVideoTypes)}, |
| 879 { NULL, NULL, 0 } | 794 {NULL, NULL, 0}}; |
| 880 }; | |
| 881 | 795 |
| 882 void GetExtensionsFromHardCodedMappings( | 796 void GetExtensionsFromHardCodedMappings( |
| 883 const MimeInfo* mappings, | 797 const MimeInfo* mappings, |
| 884 size_t mappings_len, | 798 size_t mappings_len, |
| 885 const std::string& leading_mime_type, | 799 const std::string& leading_mime_type, |
| 886 base::hash_set<base::FilePath::StringType>* extensions) { | 800 base::hash_set<base::FilePath::StringType>* extensions) { |
| 887 base::FilePath::StringType extension; | 801 base::FilePath::StringType extension; |
| 888 for (size_t i = 0; i < mappings_len; ++i) { | 802 for (size_t i = 0; i < mappings_len; ++i) { |
| 889 if (StartsWithASCII(mappings[i].mime_type, leading_mime_type, false)) { | 803 if (StartsWithASCII(mappings[i].mime_type, leading_mime_type, false)) { |
| 890 std::vector<string> this_extensions; | 804 std::vector<string> this_extensions; |
| 891 base::SplitStringUsingSubstr(mappings[i].extensions, ",", | 805 base::SplitStringUsingSubstr( |
| 892 &this_extensions); | 806 mappings[i].extensions, ",", &this_extensions); |
| 893 for (size_t j = 0; j < this_extensions.size(); ++j) { | 807 for (size_t j = 0; j < this_extensions.size(); ++j) { |
| 894 #if defined(OS_WIN) | 808 #if defined(OS_WIN) |
| 895 base::FilePath::StringType extension( | 809 base::FilePath::StringType extension( |
| 896 base::UTF8ToWide(this_extensions[j])); | 810 base::UTF8ToWide(this_extensions[j])); |
| 897 #else | 811 #else |
| 898 base::FilePath::StringType extension(this_extensions[j]); | 812 base::FilePath::StringType extension(this_extensions[j]); |
| 899 #endif | 813 #endif |
| 900 extensions->insert(extension); | 814 extensions->insert(extension); |
| 901 } | 815 } |
| 902 } | 816 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 921 extensions); | 835 extensions); |
| 922 | 836 |
| 923 GetExtensionsFromHardCodedMappings(secondary_mappings, | 837 GetExtensionsFromHardCodedMappings(secondary_mappings, |
| 924 arraysize(secondary_mappings), | 838 arraysize(secondary_mappings), |
| 925 leading_mime_type, | 839 leading_mime_type, |
| 926 extensions); | 840 extensions); |
| 927 } | 841 } |
| 928 | 842 |
| 929 // Note that the elements in the source set will be appended to the target | 843 // Note that the elements in the source set will be appended to the target |
| 930 // vector. | 844 // vector. |
| 931 template<class T> | 845 template <class T> |
| 932 void HashSetToVector(base::hash_set<T>* source, std::vector<T>* target) { | 846 void HashSetToVector(base::hash_set<T>* source, std::vector<T>* target) { |
| 933 size_t old_target_size = target->size(); | 847 size_t old_target_size = target->size(); |
| 934 target->resize(old_target_size + source->size()); | 848 target->resize(old_target_size + source->size()); |
| 935 size_t i = 0; | 849 size_t i = 0; |
| 936 for (typename base::hash_set<T>::iterator iter = source->begin(); | 850 for (typename base::hash_set<T>::iterator iter = source->begin(); |
| 937 iter != source->end(); ++iter, ++i) | 851 iter != source->end(); |
| 852 ++iter, ++i) | |
| 938 (*target)[old_target_size + i] = *iter; | 853 (*target)[old_target_size + i] = *iter; |
| 939 } | 854 } |
| 940 } | 855 } |
| 941 | 856 |
| 942 void GetExtensionsForMimeType( | 857 void GetExtensionsForMimeType( |
| 943 const std::string& unsafe_mime_type, | 858 const std::string& unsafe_mime_type, |
| 944 std::vector<base::FilePath::StringType>* extensions) { | 859 std::vector<base::FilePath::StringType>* extensions) { |
| 945 if (unsafe_mime_type == "*/*" || unsafe_mime_type == "*") | 860 if (unsafe_mime_type == "*/*" || unsafe_mime_type == "*") |
| 946 return; | 861 return; |
| 947 | 862 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1003 // Don't create a map, there is only one entry in the table, | 918 // Don't create a map, there is only one entry in the table, |
| 1004 // except on Android. | 919 // except on Android. |
| 1005 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) { | 920 for (size_t i = 0; i < arraysize(supported_certificate_types); ++i) { |
| 1006 if (mime_type == net::supported_certificate_types[i].mime_type) | 921 if (mime_type == net::supported_certificate_types[i].mime_type) |
| 1007 return net::supported_certificate_types[i].cert_type; | 922 return net::supported_certificate_types[i].cert_type; |
| 1008 } | 923 } |
| 1009 return CERTIFICATE_MIME_TYPE_UNKNOWN; | 924 return CERTIFICATE_MIME_TYPE_UNKNOWN; |
| 1010 } | 925 } |
| 1011 | 926 |
| 1012 bool IsSupportedCertificateMimeType(const std::string& mime_type) { | 927 bool IsSupportedCertificateMimeType(const std::string& mime_type) { |
| 1013 CertificateMimeType file_type = | 928 CertificateMimeType file_type = GetCertificateMimeTypeForMimeType(mime_type); |
| 1014 GetCertificateMimeTypeForMimeType(mime_type); | |
| 1015 return file_type != CERTIFICATE_MIME_TYPE_UNKNOWN; | 929 return file_type != CERTIFICATE_MIME_TYPE_UNKNOWN; |
| 1016 } | 930 } |
| 1017 | 931 |
| 1018 void AddMultipartValueForUpload(const std::string& value_name, | 932 void AddMultipartValueForUpload(const std::string& value_name, |
| 1019 const std::string& value, | 933 const std::string& value, |
| 1020 const std::string& mime_boundary, | 934 const std::string& mime_boundary, |
| 1021 const std::string& content_type, | 935 const std::string& content_type, |
| 1022 std::string* post_data) { | 936 std::string* post_data) { |
| 1023 DCHECK(post_data); | 937 DCHECK(post_data); |
| 1024 // First line is the boundary. | 938 // First line is the boundary. |
| 1025 post_data->append("--" + mime_boundary + "\r\n"); | 939 post_data->append("--" + mime_boundary + "\r\n"); |
| 1026 // Next line is the Content-disposition. | 940 // Next line is the Content-disposition. |
| 1027 post_data->append("Content-Disposition: form-data; name=\"" + | 941 post_data->append("Content-Disposition: form-data; name=\"" + value_name + |
| 1028 value_name + "\"\r\n"); | 942 "\"\r\n"); |
| 1029 if (!content_type.empty()) { | 943 if (!content_type.empty()) { |
| 1030 // If Content-type is specified, the next line is that. | 944 // If Content-type is specified, the next line is that. |
| 1031 post_data->append("Content-Type: " + content_type + "\r\n"); | 945 post_data->append("Content-Type: " + content_type + "\r\n"); |
| 1032 } | 946 } |
| 1033 // Leave an empty line and append the value. | 947 // Leave an empty line and append the value. |
| 1034 post_data->append("\r\n" + value + "\r\n"); | 948 post_data->append("\r\n" + value + "\r\n"); |
| 1035 } | 949 } |
| 1036 | 950 |
| 1037 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, | 951 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, |
| 1038 std::string* post_data) { | 952 std::string* post_data) { |
| 1039 DCHECK(post_data); | 953 DCHECK(post_data); |
| 1040 post_data->append("--" + mime_boundary + "--\r\n"); | 954 post_data->append("--" + mime_boundary + "--\r\n"); |
| 1041 } | 955 } |
| 1042 | 956 |
| 1043 } // namespace net | 957 } // namespace net |
| OLD | NEW |