summaryrefslogtreecommitdiffstats
path: root/net/base/mime_util.cc
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-14 01:20:41 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-14 01:20:41 +0000
commitbae0ea1f95c5c3a02761d942c0802ec877c1a106 (patch)
tree456d3b2eb7cc4fc497870385223c88312db8a914 /net/base/mime_util.cc
parent8a5deb2ef0a4cc84b06a3466b32e94375110106c (diff)
downloadchromium_src-bae0ea1f95c5c3a02761d942c0802ec877c1a106.zip
chromium_src-bae0ea1f95c5c3a02761d942c0802ec877c1a106.tar.gz
chromium_src-bae0ea1f95c5c3a02761d942c0802ec877c1a106.tar.bz2
Change mime type utils to operate on platform-specific string types for filenames/file extensions.
Review URL: http://codereview.chromium.org/21327 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9809 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/base/mime_util.cc')
-rw-r--r--net/base/mime_util.cc34
1 files changed, 18 insertions, 16 deletions
diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc
index 03d09ad..1528d3a 100644
--- a/net/base/mime_util.cc
+++ b/net/base/mime_util.cc
@@ -13,17 +13,16 @@
#include "base/string_util.h"
using std::string;
-using std::wstring;
namespace net {
// Singleton utility class for mime types.
class MimeUtil : public PlatformMimeUtil {
public:
- bool GetMimeTypeFromExtension(const std::wstring& ext,
+ bool GetMimeTypeFromExtension(const FilePath::StringType& ext,
std::string* mime_type) const;
- bool GetMimeTypeFromFile(const std::wstring& file_path,
+ bool GetMimeTypeFromFile(const FilePath& file_path,
std::string* mime_type) const;
bool IsSupportedImageMimeType(const char* mime_type) const;
@@ -111,7 +110,7 @@ static const char* FindMimeType(const MimeInfo* mappings,
return NULL;
}
-bool MimeUtil::GetMimeTypeFromExtension(const wstring& ext,
+bool MimeUtil::GetMimeTypeFromExtension(const FilePath::StringType& ext,
string* result) const {
// We implement the same algorithm as Mozilla for mapping a file extension to
// a mime type. That is, we first check a hard-coded list (that cannot be
@@ -119,11 +118,15 @@ bool MimeUtil::GetMimeTypeFromExtension(const wstring& ext,
// Finally, we scan a secondary hard-coded list to catch types that we can
// deduce but that we also want to allow the OS to override.
- string ext_utf8 = WideToUTF8(ext);
+#if defined(OS_WIN)
+ string ext_narrow_str = WideToUTF8(ext);
+#elif defined(OS_POSIX)
+ const string& ext_narrow_str = ext;
+#endif
const char* mime_type;
mime_type = FindMimeType(primary_mappings, arraysize(primary_mappings),
- ext_utf8.c_str());
+ ext_narrow_str.c_str());
if (mime_type) {
*result = mime_type;
return true;
@@ -133,7 +136,7 @@ bool MimeUtil::GetMimeTypeFromExtension(const wstring& ext,
return true;
mime_type = FindMimeType(secondary_mappings, arraysize(secondary_mappings),
- ext_utf8.c_str());
+ ext_narrow_str.c_str());
if (mime_type) {
*result = mime_type;
return true;
@@ -142,14 +145,12 @@ bool MimeUtil::GetMimeTypeFromExtension(const wstring& ext,
return false;
}
-bool MimeUtil::GetMimeTypeFromFile(const wstring& file_path,
+bool MimeUtil::GetMimeTypeFromFile(const FilePath& file_path,
string* result) const {
- // TODO(ericroman): this doesn't work properly with paths like
- // /home/foo/.ssh/known_hosts
- wstring::size_type dot = file_path.find_last_of('.');
- if (dot == wstring::npos)
+ FilePath::StringType file_name_str = file_path.Extension();
+ if (file_name_str.empty())
return false;
- return GetMimeTypeFromExtension(file_path.substr(dot + 1), result);
+ return GetMimeTypeFromExtension(file_name_str.substr(1), result);
}
// From WebKit's WebCore/platform/MIMETypeRegistry.cpp:
@@ -292,16 +293,17 @@ static MimeUtil* GetMimeUtil() {
return Singleton<MimeUtil>::get();
}
-bool GetMimeTypeFromExtension(const std::wstring& ext, std::string* mime_type) {
+bool GetMimeTypeFromExtension(const FilePath::StringType& ext,
+ std::string* mime_type) {
return GetMimeUtil()->GetMimeTypeFromExtension(ext, mime_type);
}
-bool GetMimeTypeFromFile(const std::wstring& file_path, std::string* mime_type) {
+bool GetMimeTypeFromFile(const FilePath& file_path, std::string* mime_type) {
return GetMimeUtil()->GetMimeTypeFromFile(file_path, mime_type);
}
bool GetPreferredExtensionForMimeType(const std::string& mime_type,
- std::wstring* extension) {
+ FilePath::StringType* extension) {
return GetMimeUtil()->GetPreferredExtensionForMimeType(mime_type, extension);
}