diff options
author | torne@chromium.org <torne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-23 11:47:48 +0000 |
---|---|---|
committer | torne@chromium.org <torne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-23 11:47:48 +0000 |
commit | 600bdcc590aaf6e5de01d470babaff4565d89b4b (patch) | |
tree | bd31fb4cd5f27166f326563910fe20fa8b987de4 /net/base | |
parent | 3757c7da5046110643418a88bdf31dcc5046d8ff (diff) | |
download | chromium_src-600bdcc590aaf6e5de01d470babaff4565d89b4b.zip chromium_src-600bdcc590aaf6e5de01d470babaff4565d89b4b.tar.gz chromium_src-600bdcc590aaf6e5de01d470babaff4565d89b4b.tar.bz2 |
Allow any text/* mime type to be rendered inline.
Instead of only allowing text/plain, text/css, and various other
specific MIME types to be rendered inline, allow any MIME type that
starts with text/ with the exception of certain types that don't render
in a human-readable form despite technically being textual. The list of
excepted types is the same as the list in WebKit.
WebKit renders all these as plain, preformatted text, which should be
safe. Users can still save the file to disk with "Save Page As" if they
didn't want it rendered, and downloading can still be forced with
Content-Disposition.
BUG=68648
Review URL: https://chromiumcodereview.appspot.com/10694020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147845 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base')
-rw-r--r-- | net/base/mime_util.cc | 35 | ||||
-rw-r--r-- | net/base/mime_util.h | 1 | ||||
-rw-r--r-- | net/base/mime_util_unittest.cc | 11 |
3 files changed, 44 insertions, 3 deletions
diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc index 4471b53..c398561 100644 --- a/net/base/mime_util.cc +++ b/net/base/mime_util.cc @@ -34,6 +34,7 @@ class MimeUtil : public PlatformMimeUtil { bool IsSupportedImageMimeType(const std::string& mime_type) const; bool IsSupportedMediaMimeType(const std::string& mime_type) const; bool IsSupportedNonImageMimeType(const std::string& mime_type) const; + bool IsUnsupportedTextMimeType(const std::string& mime_type) const; bool IsSupportedJavascriptMimeType(const std::string& mime_type) const; bool IsViewSourceMimeType(const std::string& mime_type) const; @@ -79,6 +80,7 @@ class MimeUtil : public PlatformMimeUtil { MimeMappings image_map_; MimeMappings media_map_; MimeMappings non_image_map_; + MimeMappings unsupported_text_map_; MimeMappings javascript_map_; MimeMappings view_source_map_; MimeMappings codecs_map_; @@ -317,6 +319,25 @@ static const char* const supported_non_image_types[] = { // result in cross site scripting. }; +// 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. +static const char* const unsupported_text_types[] = { + "text/calendar", + "text/x-calendar", + "text/x-vcalendar", + "text/vcalendar", + "text/vcard", + "text/x-vcard", + "text/directory", + "text/ldif", + "text/qif", + "text/x-qif", + "text/x-csv", + "text/x-vcf", + "text/rtf", +}; + // Mozilla 1.8 and WinIE 7 both accept text/javascript and text/ecmascript. // Mozilla 1.8 accepts application/javascript, application/ecmascript, and // application/x-javascript, but WinIE 7 doesn't. @@ -381,6 +402,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(unsupported_text_types); ++i) + unsupported_text_map_.insert(unsupported_text_types[i]); for (size_t i = 0; i < arraysize(supported_javascript_types); ++i) non_image_map_.insert(supported_javascript_types[i]); for (size_t i = 0; i < arraysize(common_media_types); ++i) @@ -434,7 +457,13 @@ bool MimeUtil::IsSupportedMediaMimeType(const std::string& mime_type) const { } bool MimeUtil::IsSupportedNonImageMimeType(const std::string& mime_type) const { - return non_image_map_.find(mime_type) != non_image_map_.end(); + return non_image_map_.find(mime_type) != non_image_map_.end() || + (mime_type.compare(0, 5, "text/") == 0 && + !IsUnsupportedTextMimeType(mime_type)); +} + +bool MimeUtil::IsUnsupportedTextMimeType(const std::string& mime_type) const { + return unsupported_text_map_.find(mime_type) != unsupported_text_map_.end(); } bool MimeUtil::IsSupportedJavascriptMimeType( @@ -608,6 +637,10 @@ bool IsSupportedNonImageMimeType(const std::string& mime_type) { return g_mime_util.Get().IsSupportedNonImageMimeType(mime_type); } +bool IsUnsupportedTextMimeType(const std::string& mime_type) { + return g_mime_util.Get().IsUnsupportedTextMimeType(mime_type); +} + bool IsSupportedJavascriptMimeType(const std::string& mime_type) { return g_mime_util.Get().IsSupportedJavascriptMimeType(mime_type); } diff --git a/net/base/mime_util.h b/net/base/mime_util.h index 64293f4..7b75f33 100644 --- a/net/base/mime_util.h +++ b/net/base/mime_util.h @@ -42,6 +42,7 @@ NET_EXPORT bool GetPreferredExtensionForMimeType( NET_EXPORT bool IsSupportedImageMimeType(const std::string& mime_type); NET_EXPORT bool IsSupportedMediaMimeType(const std::string& mime_type); NET_EXPORT bool IsSupportedNonImageMimeType(const std::string& mime_type); +NET_EXPORT bool IsUnsupportedTextMimeType(const std::string& mime_type); NET_EXPORT bool IsSupportedJavascriptMimeType(const std::string& mime_type); // Get whether this mime type should be displayed in view-source mode. diff --git a/net/base/mime_util_unittest.cc b/net/base/mime_util_unittest.cc index 1ee2862..8210b0c 100644 --- a/net/base/mime_util_unittest.cc +++ b/net/base/mime_util_unittest.cc @@ -60,15 +60,22 @@ TEST(MimeUtilTest, FileTest) { } TEST(MimeUtilTest, LookupTypes) { + EXPECT_FALSE(IsUnsupportedTextMimeType("text/banana")); + EXPECT_TRUE(IsUnsupportedTextMimeType("text/vcard")); + EXPECT_TRUE(IsSupportedImageMimeType("image/jpeg")); EXPECT_FALSE(IsSupportedImageMimeType("image/lolcat")); EXPECT_TRUE(IsSupportedNonImageMimeType("text/html")); - EXPECT_FALSE(IsSupportedNonImageMimeType("text/virus")); + EXPECT_TRUE(IsSupportedNonImageMimeType("text/banana")); + EXPECT_FALSE(IsSupportedNonImageMimeType("text/vcard")); + EXPECT_FALSE(IsSupportedNonImageMimeType("application/virus")); EXPECT_TRUE(IsSupportedMimeType("image/jpeg")); EXPECT_FALSE(IsSupportedMimeType("image/lolcat")); EXPECT_TRUE(IsSupportedMimeType("text/html")); - EXPECT_FALSE(IsSupportedMimeType("text/virus")); + EXPECT_TRUE(IsSupportedMimeType("text/banana")); + EXPECT_FALSE(IsSupportedMimeType("text/vcard")); + EXPECT_FALSE(IsSupportedMimeType("application/virus")); } TEST(MimeUtilTest, MatchesMimeType) { |