Index: net/base/mime_util.cc |
diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc |
index f851ecd13785764d6b3a18825801a13411eca91a..2fd287a58b0b6616edcf783b6b450c9b95d1e3c1 100644 |
--- a/net/base/mime_util.cc |
+++ b/net/base/mime_util.cc |
@@ -337,13 +337,26 @@ static const char* const supported_non_image_types[] = { |
"application/rss+xml", |
"application/xhtml+xml", |
"application/json", |
- "application/x-x509-user-cert", |
"multipart/related", // For MHTML support. |
"multipart/x-mixed-replace" |
// Note: ADDING a new type here will probably render it AS HTML. This can |
// result in cross site scripting. |
}; |
+// Dictionary of cryptographic file mime types. |
+struct CryptoFileTypeInfo { |
+ const char* mime_type; |
+ CryptoFileType file_type; |
+}; |
+ |
+static const CryptoFileTypeInfo supported_crypto_types[] = { |
+ { "application/x-x509-user-cert", CRYPTO_FILE_TYPE_X509_USER_CERT }, |
+#if defined(OS_ANDROID) |
+ { "application/x-x509-ca-cert", CRYPTO_FILE_TYPE_X509_CA_CERT }, |
Ryan Sleevi
2012/10/24 22:01:25
Does Android not also need to handle application/x
digit1
2012/10/25 13:57:38
I've asked the Android folks responsible for this.
|
+ { "application/x-pkcs12", CRYPTO_FILE_TYPE_PKCS12_KEYCHAIN }, |
+#endif |
+}; |
+ |
// These types are excluded from the logic that allows all text/ types because |
// while they are technically text, it's very unlikely that a user expects to |
// see them rendered in text form. |
@@ -431,6 +444,8 @@ void MimeUtil::InitializeMimeTypeMaps() { |
// Initialize the supported non-image types. |
for (size_t i = 0; i < arraysize(supported_non_image_types); ++i) |
non_image_map_.insert(supported_non_image_types[i]); |
+ for (size_t i = 0; i < arraysize(supported_crypto_types); ++i) |
+ non_image_map_.insert(supported_crypto_types[i].mime_type); |
for (size_t i = 0; i < arraysize(unsupported_text_types); ++i) |
unsupported_text_map_.insert(unsupported_text_types[i]); |
for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) |
@@ -549,7 +564,7 @@ bool MimeUtil::MatchesMimeType(const std::string& mime_type_pattern, |
} |
// See http://www.iana.org/assignments/media-types/index.html |
-static const char* legal_top_level_types[] = { |
+static const char* const legal_top_level_types[] = { |
Ryan Sleevi
2012/10/24 22:01:25
unrelated change? (but good change none the less,
digit1
2012/10/25 13:57:38
Sure, I've moved this to https://codereview.chromi
|
"application/", |
"audio/", |
"example/", |
@@ -714,7 +729,7 @@ namespace { |
// From http://www.w3schools.com/media/media_mimeref.asp and |
// http://plugindoc.mozdev.org/winmime.php |
-static const char* kStandardImageTypes[] = { |
+static const char* const kStandardImageTypes[] = { |
"image/bmp", |
"image/cis-cod", |
"image/gif", |
@@ -738,7 +753,7 @@ static const char* kStandardImageTypes[] = { |
"image/x-xpixmap", |
"image/x-xwindowdump" |
}; |
-static const char* kStandardAudioTypes[] = { |
+static const char* const kStandardAudioTypes[] = { |
"audio/aac", |
"audio/aiff", |
"audio/amr", |
@@ -757,7 +772,7 @@ static const char* kStandardAudioTypes[] = { |
"audio/vnd.rn-realaudio", |
"audio/vnd.wave" |
}; |
-static const char* kStandardVideoTypes[] = { |
+static const char* const kStandardVideoTypes[] = { |
"video/avi", |
"video/divx", |
"video/flc", |
@@ -776,7 +791,7 @@ static const char* kStandardVideoTypes[] = { |
struct StandardType { |
const char* leading_mime_type; |
- const char** standard_types; |
+ const char* const* standard_types; |
size_t standard_types_len; |
}; |
static const StandardType kStandardTypes[] = { |
@@ -809,7 +824,7 @@ void GetExtensionsFromHardCodedMappings( |
} |
} |
-void GetExtensionsHelper(const char** standard_types, |
+void GetExtensionsHelper(const char* const* standard_types, |
size_t standard_types_len, |
const std::string& leading_mime_type, |
base::hash_set<FilePath::StringType>* extensions) { |
@@ -922,4 +937,20 @@ const std::string GetIANAMediaType(const std::string& mime_type) { |
return ""; |
} |
+CryptoFileType GetCryptoFileTypeForMimeType( |
+ const std::string& mime_type) { |
+ // Don't create a map, there is only one entry in the table, |
+ // except on Android. |
+ for (size_t i = 0; i < arraysize(supported_crypto_types); ++i) { |
+ if (mime_type == net::supported_crypto_types[i].mime_type) |
+ return net::supported_crypto_types[i].file_type; |
+ } |
+ return CRYPTO_FILE_TYPE_UNKNOWN; |
+} |
+ |
+bool IsSupportedCryptoMimeType(const std::string& mime_type) { |
+ CryptoFileType file_type = GetCryptoFileTypeForMimeType(mime_type); |
+ return file_type != CRYPTO_FILE_TYPE_UNKNOWN; |
+} |
+ |
} // namespace net |