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

Unified Diff: net/base/mime_sniffer.cc

Issue 6592089: Adding sniffing of MHTML files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding unit-tests Created 9 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/base/mime_sniffer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/mime_sniffer.cc
diff --git a/net/base/mime_sniffer.cc b/net/base/mime_sniffer.cc
index bd16462f159b7430508093044786e3b44deccf64..6c845ccb4c957cef5b584bd0398ad1b4c6dcbf0c 100644
--- a/net/base/mime_sniffer.cc
+++ b/net/base/mime_sniffer.cc
@@ -534,15 +534,10 @@ static bool SniffCRX(const char* content,
};
// Only consider files that have the extension ".crx".
- static const char kCRXExtension[] = ".crx";
- // Ignore null by subtracting 1.
- static const int kExtensionLength = arraysize(kCRXExtension) - 1;
- if (url.path().rfind(kCRXExtension, std::string::npos, kExtensionLength) ==
- url.path().size() - kExtensionLength) {
- counter->Add(1);
- } else {
+ if (!EndsWith(url.path(), ".crx", true))
return false;
- }
+
+ counter->Add(1);
*have_enough_content &= TruncateSize(kBytesRequiredForMagic, &size);
if (CheckForMagicNumbers(content, size,
@@ -663,6 +658,14 @@ bool SniffMimeType(const char* content, size_t content_size,
&have_enough_content, result))
return true;
+ // MHTML cannot be easily sniffed as its header might be relatively long
+ // before the "Content-Type: multipart/related".
+ std::string path = url.path();
+ if (EndsWith(path, ".mht", false) || EndsWith(path, ".mhtml", false)) {
+ result->assign("multipart/related");
+ return true;
+ }
+
// We're not interested in sniffing for magic numbers when the type_hint
// is application/octet-stream. Time to bail out.
if (type_hint == "application/octet-stream")
« no previous file with comments | « no previous file | net/base/mime_sniffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698