Index: net/base/mime_util.cc |
diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc |
index 8ff58e6d579b674bddb20da134a4aaf7f7e0e8bf..d97983b5348809f4afd980b9a6bd58df22a34eb8 100644 |
--- a/net/base/mime_util.cc |
+++ b/net/base/mime_util.cc |
@@ -43,6 +43,8 @@ class MimeUtil : public PlatformMimeUtil { |
bool MatchesMimeType(const std::string &mime_type_pattern, |
const std::string &mime_type) const; |
+ bool IsStringMimeType(const std::string& type_string) const; |
+ |
bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) const; |
void ParseCodecString(const std::string& codecs, |
@@ -486,6 +488,40 @@ bool MimeUtil::MatchesMimeType(const std::string& mime_type_pattern, |
return true; |
} |
+bool MimeUtil::IsStringMimeType(const std::string& type_string) const { |
rvargas (doing something else)
2012/06/01 01:51:14
Shouldn't this build upon IsSupportedMimeType inst
Greg Billock
2012/06/01 04:58:22
How so? I think this function would basically have
rvargas (doing something else)
2012/06/01 19:11:25
You're right, the "supported" part makes all the d
|
+ // MIME types are always ASCII and case-insensitive (at least, the top-level |
+ // and secondary types we care about). |
+ if (!IsStringASCII(type_string)) |
+ return false; |
+ std::string raw_type = type_string; |
+ StringToLowerASCII(&raw_type); |
rvargas (doing something else)
2012/06/01 19:11:25
either this is not needed, or the comparisons shou
Greg Billock
2012/06/05 01:08:56
Done.
|
+ |
+ // See http://www.iana.org/assignments/media-types/index.html |
+ if (StartsWithASCII(raw_type, "application/", false) || |
rvargas (doing something else)
2012/06/01 19:11:25
Then let's follow the pattern of this class and ma
Greg Billock
2012/06/05 01:08:56
Done.
|
+ StartsWithASCII(raw_type, "audio/", false) || |
+ StartsWithASCII(raw_type, "example/", false) || |
+ StartsWithASCII(raw_type, "image/", false) || |
+ StartsWithASCII(raw_type, "message/", false) || |
+ StartsWithASCII(raw_type, "model/", false) || |
+ StartsWithASCII(raw_type, "multipart/", false) || |
+ StartsWithASCII(raw_type, "text/", false) || |
+ StartsWithASCII(raw_type, "video/", false) || |
+ raw_type == "*/*" || raw_type == "*") { |
+ return true; |
+ } |
+ |
+ // If there's a "/" separator character, and the token before it is |
rvargas (doing something else)
2012/06/01 01:51:14
If we have no code to cover this case maybe we can
|
+ // "x-" + (ascii characters), it is also a MIME type. |
+ size_t slash = raw_type.find('/'); |
+ if (slash < 3 || slash == std::string::npos || slash == raw_type.length() - 1) |
+ return false; |
+ |
+ if (StartsWithASCII(raw_type, "x-", false)) |
+ return true; |
+ |
+ return false; |
+} |
+ |
bool MimeUtil::AreSupportedMediaCodecs( |
const std::vector<std::string>& codecs) const { |
return AreSupportedCodecs(codecs_map_, codecs); |
@@ -578,6 +614,10 @@ bool MatchesMimeType(const std::string& mime_type_pattern, |
return g_mime_util.Get().MatchesMimeType(mime_type_pattern, mime_type); |
} |
+bool IsStringMimeType(const std::string& type_string) { |
+ return g_mime_util.Get().IsStringMimeType(type_string); |
+} |
+ |
bool AreSupportedMediaCodecs(const std::vector<std::string>& codecs) { |
return g_mime_util.Get().AreSupportedMediaCodecs(codecs); |
} |