diff options
author | yoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-16 09:56:49 +0000 |
---|---|---|
committer | yoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-16 09:56:49 +0000 |
commit | 2c7f8cf810963623e5d0f4fd6fe40ba8c96a94c8 (patch) | |
tree | b1241d4a20fd791feb787d42ff6b576c039e31f4 /apps | |
parent | bae2377a6c40e1b8c8f168999965523d55e2e8d2 (diff) | |
download | chromium_src-2c7f8cf810963623e5d0f4fd6fe40ba8c96a94c8.zip chromium_src-2c7f8cf810963623e5d0f4fd6fe40ba8c96a94c8.tar.gz chromium_src-2c7f8cf810963623e5d0f4fd6fe40ba8c96a94c8.tar.bz2 |
Sniff MIME type for files which have unknown extensions.
What I want to do:
Open text files which have unknown extensions(e.g. access.log.1) using packaged apps which can handle 'text/plain'(e.g. Text, Caret,...).
Current situation:
By following reasons, text files with unknow extension can't be opened.
1. FileManager guess the MIME type as empty, so 'text/plain'-supporting apps are not shown as handlers.
2. PlatformAppLauncher guess the MIME type as 'application/octet-stream', and it launch apps with no data because those apps don't handle 'application/octet-stream'.
What I changed:
Modified FileManager and PlatformAppLauncher to sniff MIME types if they are unknown based on extensions.
BUG=352250
R=benwells@chromium.org, hashimoto@chromium.org, jorgelo@chromium.org
Review URL: https://codereview.chromium.org/224883008
Patch from Naoki Fukino <fukino@chromium.org>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264167 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps')
-rw-r--r-- | apps/launcher.cc | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/apps/launcher.cc b/apps/launcher.cc index ba7c829..8d31a01 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); + 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(), // 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)); |