Chromium Code Reviews| Index: apps/launcher.cc |
| diff --git a/apps/launcher.cc b/apps/launcher.cc |
| index ba7c829b07d81746846a13804659d220ed369acc..8d31a0115c46e671d56a953aa194942a20f388df 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 of the file can't be determined by its path, |
| + // try to sniff it by its content. |
| + std::vector<char> content(net::kMaxBytesToSniff); |
|
benwells
2014/04/11 23:22:35
Is there a reason not to use char buf[net::kMaxByt
fukino
2014/04/12 06:21:15
I thought net::kMaxBytesToSniff was somewhat big a
benwells
2014/04/14 05:47:42
ok, fair enough.
|
| + int bytes_read = base::ReadFile(file_path_, &content[0], content.size()); |
| + if (bytes_read >= 0) { |
|
Jorge Lucangeli Obes
2014/04/10 20:36:08
Why do we want to sniff if bytes_read == 0?
fukino
2014/04/10 23:50:33
When we call sniffMimeFile() to empty file, its MI
|
| + net::SniffMimeType(&content[0], |
| + bytes_read, |
| + net::FilePathToFileURL(file_path_), |
| + std::string(), // type_hint (passes no hint) |
| + &mime_type); |
| + } |
| + if (mime_type.empty()) |
| + mime_type = kFallbackMimeType; |
| + } |
| BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| &PlatformAppPathLauncher::LaunchWithMimeType, this, mime_type)); |