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

Unified Diff: apps/launcher.cc

Issue 224883008: Sniff MIME type for files which have unknown extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing header (<vector>). Created 6 years, 8 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
Index: apps/launcher.cc
diff --git a/apps/launcher.cc b/apps/launcher.cc
index ba7c829b07d81746846a13804659d220ed369acc..37f92cfdddce68f1ae924ba75165543940af6323 100644
--- a/apps/launcher.cc
+++ b/apps/launcher.cc
@@ -29,6 +29,8 @@
#include "extensions/common/extension.h"
#include "extensions/common/extension_messages.h"
#include "extensions/common/manifest_handlers/kiosk_mode_info.h"
+#include "net/base/filename_util.h"
+#include "net/base/mime_sniffer.h"
#include "net/base/mime_util.h"
#include "net/base/net_util.h"
#include "url/gurl.h"
@@ -181,8 +183,21 @@ class PlatformAppPathLauncher
}
std::string mime_type;
- if (!net::GetMimeTypeFromFile(file_path_, &mime_type))
- mime_type = kFallbackMimeType;
+ if (!net::GetMimeTypeFromFile(file_path_, &mime_type)) {
+ // If MIME type can't be determined by the file path,
+ // Try to sniff by its content.
+ std::vector<char> content(net::kMaxBytesToSniff);
+ int bytes_read = base::ReadFile(file_path_, &content[0], content.size());
+ if (bytes_read >= 0) {
+ net::SniffMimeType(&content[0],
+ bytes_read,
+ net::FilePathToFileURL(file_path_),
+ std::string(),
hashimoto 2014/04/10 09:29:12 nit: How about adding a comment like "// type_hit"
fukino 2014/04/10 11:12:06 Done.
+ &mime_type);
+ }
+ if (mime_type.empty())
+ mime_type = kFallbackMimeType;
+ }
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind(
&PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type));

Powered by Google App Engine
This is Rietveld 408576698