summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/browser/debugger/debugger_contents.cc7
-rw-r--r--chrome/browser/download/download_manager.cc6
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc6
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h8
-rw-r--r--chrome/common/render_messages_internal.h6
-rw-r--r--chrome/renderer/renderer_glue.cc6
-rw-r--r--net/base/mime_util.cc34
-rw-r--r--net/base/mime_util.h9
-rw-r--r--net/base/mime_util_unittest.cc29
-rw-r--r--net/base/platform_mime_util.h8
-rw-r--r--net/base/platform_mime_util_linux.cc4
-rw-r--r--net/base/platform_mime_util_mac.cc10
-rw-r--r--net/base/platform_mime_util_win.cc4
-rw-r--r--net/url_request/url_request_file_job.cc2
-rw-r--r--webkit/glue/chromium_bridge_impl.cc14
-rw-r--r--webkit/glue/glue_util.cc18
-rw-r--r--webkit/glue/glue_util.h4
-rw-r--r--webkit/glue/plugins/plugin_stream.cc7
-rw-r--r--webkit/glue/webkit_glue.h7
-rwxr-xr-xwebkit/tools/test_shell/test_shell.cc7
20 files changed, 119 insertions, 77 deletions
diff --git a/chrome/browser/debugger/debugger_contents.cc b/chrome/browser/debugger/debugger_contents.cc
index 1c426f8..2756244 100644
--- a/chrome/browser/debugger/debugger_contents.cc
+++ b/chrome/browser/debugger/debugger_contents.cc
@@ -69,7 +69,12 @@ class DebuggerHTMLSource : public ChromeURLDataManager::DataSource {
// Currently but three choices {"", "debugger.js", "debugger.css"}.
// Map the extension to mime-type, defaulting to "text/html".
std::string mime_type("text/html");
- net::GetMimeTypeFromFile(ASCIIToWide(path), &mime_type);
+#if defined(OS_WIN)
+ FilePath file_path(ASCIIToWide(path));
+#elif defined(OS_POSIX)
+ FilePath file_path(path);
+#endif
+ net::GetMimeTypeFromFile(file_path, &mime_type);
return mime_type;
}
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index 5747c3b..965f2ed 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -1080,7 +1080,7 @@ void DownloadManager::GenerateExtension(
extension.assign(default_extension);
std::string mime_type_from_extension;
- net::GetMimeTypeFromFile(file_name.ToWStringHack(),
+ net::GetMimeTypeFromFile(file_name,
&mime_type_from_extension);
if (mime_type == mime_type_from_extension) {
// The hinted extension matches the mime type. It looks like a winner.
@@ -1198,11 +1198,11 @@ static const char* kExecutableBlackList[] = {
// static
bool DownloadManager::IsExecutableMimeType(const std::string& mime_type) {
- for (int i=0; i < arraysize(kExecutableWhiteList); ++i) {
+ for (size_t i = 0; i < arraysize(kExecutableWhiteList); ++i) {
if (net::MatchesMimeType(kExecutableWhiteList[i], mime_type))
return true;
}
- for (int i=0; i < arraysize(kExecutableBlackList); ++i) {
+ for (size_t i = 0; i < arraysize(kExecutableBlackList); ++i) {
if (net::MatchesMimeType(kExecutableBlackList[i], mime_type))
return false;
}
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 022a655..e7634dc 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -545,17 +545,17 @@ void ResourceMessageFilter::OnGetRootWindowRect(gfx::NativeViewId window_id,
#endif // OS_WIN
void ResourceMessageFilter::OnGetMimeTypeFromExtension(
- const std::wstring& ext, std::string* mime_type) {
+ const FilePath::StringType& ext, std::string* mime_type) {
net::GetMimeTypeFromExtension(ext, mime_type);
}
void ResourceMessageFilter::OnGetMimeTypeFromFile(
- const std::wstring& file_path, std::string* mime_type) {
+ const FilePath& file_path, std::string* mime_type) {
net::GetMimeTypeFromFile(file_path, mime_type);
}
void ResourceMessageFilter::OnGetPreferredExtensionForMimeType(
- const std::string& mime_type, std::wstring* ext) {
+ const std::string& mime_type, FilePath::StringType* ext) {
net::GetPreferredExtensionForMimeType(mime_type, ext);
}
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index c5b25f9..4133353 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -83,7 +83,7 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
int render_process_host_id() const { return render_process_host_id_;}
base::ProcessHandle renderer_handle() const { return render_handle_;}
-
+
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
const NotificationSource& source,
@@ -154,12 +154,12 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
void OnGetWindowRect(gfx::NativeViewId window, gfx::Rect *rect);
void OnGetRootWindowRect(gfx::NativeViewId window, gfx::Rect *rect);
#endif
- void OnGetMimeTypeFromExtension(const std::wstring& ext,
+ void OnGetMimeTypeFromExtension(const FilePath::StringType& ext,
std::string* mime_type);
- void OnGetMimeTypeFromFile(const std::wstring& file_path,
+ void OnGetMimeTypeFromFile(const FilePath& file_path,
std::string* mime_type);
void OnGetPreferredExtensionForMimeType(const std::string& mime_type,
- std::wstring* ext);
+ FilePath::StringType* ext);
void OnGetCPBrowsingContext(uint32* context);
void OnDuplicateSection(base::SharedMemoryHandle renderer_handle,
base::SharedMemoryHandle* browser_handle);
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index f61b122..915f8c7 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -1037,14 +1037,14 @@ IPC_BEGIN_MESSAGES(ViewHost)
// Sent to query MIME information.
IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_GetMimeTypeFromExtension,
- std::wstring /* extension */,
+ FilePath::StringType /* extension */,
std::string /* mime_type */)
IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_GetMimeTypeFromFile,
- std::wstring /* file_path */,
+ FilePath /* file_path */,
std::string /* mime_type */)
IPC_SYNC_MESSAGE_CONTROL1_1(ViewHostMsg_GetPreferredExtensionForMimeType,
std::string /* mime_type */,
- std::wstring /* extension */)
+ FilePath::StringType /* extension */)
// Get the CPBrowsingContext associated with the renderer sending this
// message.
diff --git a/chrome/renderer/renderer_glue.cc b/chrome/renderer/renderer_glue.cc
index c532f06..a8a9486 100644
--- a/chrome/renderer/renderer_glue.cc
+++ b/chrome/renderer/renderer_glue.cc
@@ -173,7 +173,7 @@ void AppendToLog(const char* file, int line, const char* msg) {
logging::LogMessage(file, line).stream() << msg;
}
-bool GetMimeTypeFromExtension(const std::wstring &ext,
+bool GetMimeTypeFromExtension(const FilePath::StringType &ext,
std::string *mime_type) {
if (IsPluginProcess())
return net::GetMimeTypeFromExtension(ext, mime_type);
@@ -186,7 +186,7 @@ bool GetMimeTypeFromExtension(const std::wstring &ext,
return !mime_type->empty();
}
-bool GetMimeTypeFromFile(const std::wstring &file_path,
+bool GetMimeTypeFromFile(const FilePath &file_path,
std::string *mime_type) {
if (IsPluginProcess())
return net::GetMimeTypeFromFile(file_path, mime_type);
@@ -200,7 +200,7 @@ bool GetMimeTypeFromFile(const std::wstring &file_path,
}
bool GetPreferredExtensionForMimeType(const std::string& mime_type,
- std::wstring* ext) {
+ FilePath::StringType* ext) {
if (IsPluginProcess())
return net::GetPreferredExtensionForMimeType(mime_type, ext);
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);
}
diff --git a/net/base/mime_util.h b/net/base/mime_util.h
index 7bfe1c3..d442e0f 100644
--- a/net/base/mime_util.h
+++ b/net/base/mime_util.h
@@ -7,21 +7,24 @@
#include <string>
+#include "base/file_path.h"
+
namespace net {
// Get the mime type (if any) that is associated with the given file extension.
// Returns true if a corresponding mime type exists.
-bool GetMimeTypeFromExtension(const std::wstring& ext, std::string* mime_type);
+bool GetMimeTypeFromExtension(const FilePath::StringType& ext,
+ std::string* mime_type);
// Get the mime type (if any) that is associated with the given file. Returns
// true if a corresponding mime type exists.
-bool GetMimeTypeFromFile(const std::wstring& file_path, std::string* mime_type);
+bool GetMimeTypeFromFile(const FilePath& file_path, std::string* mime_type);
// Get the preferred extension (if any) associated with the given mime type.
// Returns true if a corresponding file extension exists. The extension is
// returned without a prefixed dot, ex "html".
bool GetPreferredExtensionForMimeType(const std::string& mime_type,
- std::wstring* extension);
+ FilePath::StringType* extension);
// Check to see if a particular MIME type is in our list.
bool IsSupportedImageMimeType(const char* mime_type);
diff --git a/net/base/mime_util_unittest.cc b/net/base/mime_util_unittest.cc
index a49dfe3..bd7f820 100644
--- a/net/base/mime_util_unittest.cc
+++ b/net/base/mime_util_unittest.cc
@@ -13,15 +13,15 @@ namespace {
TEST(MimeUtilTest, ExtensionTest) {
const struct {
- const wchar_t* extension;
+ const FilePath::CharType* extension;
const char* mime_type;
bool valid;
} tests[] = {
- { L"png", "image/png", true },
- { L"css", "text/css", true },
- { L"pjp", "image/jpeg", true },
- { L"pjpeg", "image/jpeg", true },
- { L"not an extension / for sure", "", false },
+ { FILE_PATH_LITERAL("png"), "image/png", true },
+ { FILE_PATH_LITERAL("css"), "text/css", true },
+ { FILE_PATH_LITERAL("pjp"), "image/jpeg", true },
+ { FILE_PATH_LITERAL("pjpeg"), "image/jpeg", true },
+ { FILE_PATH_LITERAL("not an extension / for sure"), "", false },
};
std::string mime_type;
@@ -37,23 +37,24 @@ TEST(MimeUtilTest, ExtensionTest) {
TEST(MimeUtilTest, FileTest) {
const struct {
- const wchar_t* file_path;
+ const FilePath::CharType* file_path;
const char* mime_type;
bool valid;
} tests[] = {
- { L"c:\\foo\\bar.css", "text/css", true },
- { L"c:\\blah", "", false },
- { L"/usr/local/bin/mplayer", "", false },
- { L"/home/foo/bar.css", "text/css", true },
- { L"/blah.", "", false },
- { L"c:\\blah.", "", false },
+ { FILE_PATH_LITERAL("c:\\foo\\bar.css"), "text/css", true },
+ { FILE_PATH_LITERAL("c:\\blah"), "", false },
+ { FILE_PATH_LITERAL("/usr/local/bin/mplayer"), "", false },
+ { FILE_PATH_LITERAL("/home/foo/bar.css"), "text/css", true },
+ { FILE_PATH_LITERAL("/blah."), "", false },
+ { FILE_PATH_LITERAL("c:\\blah."), "", false },
};
std::string mime_type;
bool rv;
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- rv = net::GetMimeTypeFromFile(tests[i].file_path, &mime_type);
+ rv = net::GetMimeTypeFromFile(FilePath(tests[i].file_path),
+ &mime_type);
EXPECT_EQ(rv, tests[i].valid);
if (rv)
EXPECT_EQ(mime_type, tests[i].mime_type);
diff --git a/net/base/platform_mime_util.h b/net/base/platform_mime_util.h
index 6b90994..7be386a 100644
--- a/net/base/platform_mime_util.h
+++ b/net/base/platform_mime_util.h
@@ -7,6 +7,8 @@
#include <string>
+#include "base/file_path.h"
+
namespace net {
// Encapsulates the platform-specific functionality in mime_util
@@ -14,12 +16,12 @@ class PlatformMimeUtil {
public:
// See documentation for base::GetPreferredExtensionForMimeType [mime_util.h]
bool GetPreferredExtensionForMimeType(const std::string& mime_type,
- std::wstring* extension) const;
+ FilePath::StringType* extension) const;
protected:
-
+
// Get the mime type (if any) that is associated with the file extension.
// Returns true if a corresponding mime type exists.
- bool GetPlatformMimeTypeFromExtension(const std::wstring& ext,
+ bool GetPlatformMimeTypeFromExtension(const FilePath::StringType& ext,
std::string* mime_type) const;
};
diff --git a/net/base/platform_mime_util_linux.cc b/net/base/platform_mime_util_linux.cc
index 1d7dccc..874f6af 100644
--- a/net/base/platform_mime_util_linux.cc
+++ b/net/base/platform_mime_util_linux.cc
@@ -9,7 +9,7 @@
namespace net {
bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
- const std::wstring& ext, std::string* result) const {
+ const FilePath::StringType& ext, std::string* result) const {
// The correct thing to do is to interact somehow with the freedesktop shared
// mime info cache. Since Linux (and other traditional *IX systems) don't use
// file extensions; they use mime types and have multiple ways of detecting
@@ -24,7 +24,7 @@ bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
}
bool PlatformMimeUtil::GetPreferredExtensionForMimeType(
- const std::string& mime_type, std::wstring* ext) const {
+ const std::string& mime_type, FilePath::StringType* ext) const {
// Unlike GetPlatformMimeTypeFromExtension, this method doesn't have a
// default list that it uses, but for now we are also returning false since
// this doesn't really matter as much under Linux.
diff --git a/net/base/platform_mime_util_mac.cc b/net/base/platform_mime_util_mac.cc
index 221cf51..bf1cdee 100644
--- a/net/base/platform_mime_util_mac.cc
+++ b/net/base/platform_mime_util_mac.cc
@@ -12,11 +12,11 @@
namespace net {
bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
- const std::wstring& ext, std::string* result) const {
- std::wstring ext_nodot = ext;
+ const FilePath::StringType& ext, std::string* result) const {
+ std::string ext_nodot = ext;
if (ext_nodot.length() >= 1 && ext_nodot[0] == L'.')
ext_nodot.erase(ext_nodot.begin());
- scoped_cftyperef<CFStringRef> ext_ref(base::SysWideToCFStringRef(ext_nodot));
+ scoped_cftyperef<CFStringRef> ext_ref(base::SysUTF8ToCFStringRef(ext_nodot));
if (!ext_ref)
return false;
scoped_cftyperef<CFStringRef> uti(
@@ -35,7 +35,7 @@ bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
}
bool PlatformMimeUtil::GetPreferredExtensionForMimeType(
- const std::string& mime_type, std::wstring* ext) const {
+ const std::string& mime_type, FilePath::StringType* ext) const {
scoped_cftyperef<CFStringRef> mime_ref(base::SysUTF8ToCFStringRef(mime_type));
if (!mime_ref)
return false;
@@ -55,7 +55,7 @@ bool PlatformMimeUtil::GetPreferredExtensionForMimeType(
CFSTR(".%@"),
ext_ref.get()));
- *ext = base::SysCFStringRefToWide(ext_ref);
+ *ext = base::SysCFStringRefToUTF8(ext_ref);
return true;
}
diff --git a/net/base/platform_mime_util_win.cc b/net/base/platform_mime_util_win.cc
index 53600cf..b6946fd 100644
--- a/net/base/platform_mime_util_win.cc
+++ b/net/base/platform_mime_util_win.cc
@@ -12,7 +12,7 @@
namespace net {
bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
- const std::wstring& ext, std::string* result) const {
+ const FilePath::StringType& ext, std::string* result) const {
// check windows registry for file extension's mime type (registry key
// names are not case-sensitive).
std::wstring value, key = L"." + ext;
@@ -25,7 +25,7 @@ bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
}
bool PlatformMimeUtil::GetPreferredExtensionForMimeType(
- const std::string& mime_type, std::wstring* ext) const {
+ const std::string& mime_type, FilePath::StringType* ext) const {
std::wstring key(L"MIME\\Database\\Content Type\\" + UTF8ToWide(mime_type));
if (!RegKey(HKEY_CLASSES_ROOT, key.c_str()).ReadValue(L"Extension", ext))
return false;
diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc
index 2cdd109..baf94a2 100644
--- a/net/url_request/url_request_file_job.cc
+++ b/net/url_request/url_request_file_job.cc
@@ -151,7 +151,7 @@ bool URLRequestFileJob::ReadRawData(net::IOBuffer* dest, int dest_size,
bool URLRequestFileJob::GetMimeType(std::string* mime_type) {
DCHECK(request_);
- return net::GetMimeTypeFromFile(file_path_.ToWStringHack(), mime_type);
+ return net::GetMimeTypeFromFile(file_path_, mime_type);
}
void URLRequestFileJob::DidResolve(
diff --git a/webkit/glue/chromium_bridge_impl.cc b/webkit/glue/chromium_bridge_impl.cc
index 771c54b..fe2582e 100644
--- a/webkit/glue/chromium_bridge_impl.cc
+++ b/webkit/glue/chromium_bridge_impl.cc
@@ -277,7 +277,7 @@ bool ChromiumBridge::isSupportedNonImageMIMEType(const char* mime_type) {
bool ChromiumBridge::matchesMIMEType(const String& pattern,
const String& type) {
- return net::MatchesMimeType(webkit_glue::StringToStdString(pattern),
+ return net::MatchesMimeType(webkit_glue::StringToStdString(pattern),
webkit_glue::StringToStdString(type));
}
@@ -286,8 +286,8 @@ String ChromiumBridge::mimeTypeForExtension(const String& ext) {
return String();
std::string type;
- webkit_glue::GetMimeTypeFromExtension(webkit_glue::StringToStdWString(ext),
- &type);
+ webkit_glue::GetMimeTypeFromExtension(
+ webkit_glue::StringToFilePathString(ext), &type);
return webkit_glue::StdStringToString(type);
}
@@ -296,8 +296,8 @@ String ChromiumBridge::mimeTypeFromFile(const String& file_path) {
return String();
std::string type;
- webkit_glue::GetMimeTypeFromFile(webkit_glue::StringToStdWString(file_path),
- &type);
+ webkit_glue::GetMimeTypeFromFile(
+ FilePath(webkit_glue::StringToFilePathString(file_path)), &type);
return webkit_glue::StdStringToString(type);
}
@@ -305,10 +305,10 @@ String ChromiumBridge::preferredExtensionForMIMEType(const String& mime_type) {
if (mime_type.isEmpty())
return String();
- std::wstring stdext;
+ FilePath::StringType stdext;
webkit_glue::GetPreferredExtensionForMimeType(
webkit_glue::StringToStdString(mime_type), &stdext);
- return webkit_glue::StdWStringToString(stdext);
+ return webkit_glue::FilePathStringToString(stdext);
}
// Plugin ---------------------------------------------------------------------
diff --git a/webkit/glue/glue_util.cc b/webkit/glue/glue_util.cc
index 3759b2b..52ace87 100644
--- a/webkit/glue/glue_util.cc
+++ b/webkit/glue/glue_util.cc
@@ -8,7 +8,9 @@
#include "webkit/glue/glue_util.h"
#include "base/compiler_specific.h"
#include "base/gfx/rect.h"
+#include "base/string_part.h"
#include "base/string_util.h"
+#include "base/sys_string_conversions.h"
MSVC_PUSH_WARNING_LEVEL(0);
#undef LOG
@@ -75,6 +77,22 @@ WebCore::String StdStringToString(const std::string& str) {
static_cast<unsigned>(str.length()));
}
+FilePath::StringType StringToFilePathString(const WebCore::String& str) {
+#if defined(OS_WIN)
+ return StringToStdWString(str);
+#elif defined(OS_POSIX)
+ return base::SysWideToNativeMB(StringToStdWString(str));
+#endif
+}
+
+WebCore::String FilePathStringToString(const FilePath::StringType& str) {
+#if defined(OS_WIN)
+ return StdWStringToString(str);
+#elif defined(OS_POSIX)
+ return StdWStringToString(base::SysNativeMBToWide(str));
+#endif
+}
+
// URL conversions -------------------------------------------------------------
GURL KURLToGURL(const WebCore::KURL& url) {
diff --git a/webkit/glue/glue_util.h b/webkit/glue/glue_util.h
index b9ebf41..0bb7106 100644
--- a/webkit/glue/glue_util.h
+++ b/webkit/glue/glue_util.h
@@ -7,6 +7,7 @@
#include <string>
+#include "base/file_path.h"
#include "base/string16.h"
#include "googleurl/src/gurl.h"
@@ -43,6 +44,9 @@ WebCore::String String16ToString(const string16& str);
std::string StringToStdString(const WebCore::String& str);
WebCore::String StdStringToString(const std::string& str);
+FilePath::StringType StringToFilePathString(const WebCore::String& str);
+WebCore::String FilePathStringToString(const FilePath::StringType& str);
+
GURL KURLToGURL(const WebCore::KURL& url);
WebCore::KURL GURLToKURL(const GURL& url);
GURL StringToGURL(const WebCore::String& spec);
diff --git a/webkit/glue/plugins/plugin_stream.cc b/webkit/glue/plugins/plugin_stream.cc
index c5893f2..af7fbe9 100644
--- a/webkit/glue/plugins/plugin_stream.cc
+++ b/webkit/glue/plugins/plugin_stream.cc
@@ -51,7 +51,12 @@ bool PluginStream::Open(const std::string &mime_type,
char_mime_type = mime_type.c_str();
} else {
GURL gurl(stream_.url);
- std::wstring path(UTF8ToWide(gurl.path()));
+
+#if defined(OS_WIN)
+ FilePath path(UTF8ToWide(gurl.path()));
+#elif defined(OS_POSIX)
+ FilePath path(gurl.path());
+#endif
if (webkit_glue::GetMimeTypeFromFile(path, &temp_mime_type))
char_mime_type = temp_mime_type.c_str();
}
diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h
index 44dc8a4..aca3250 100644
--- a/webkit/glue/webkit_glue.h
+++ b/webkit/glue/webkit_glue.h
@@ -164,17 +164,18 @@ void AppendToLog(const char* filename, int line, const char* message);
// Get the mime type (if any) that is associated with the given file extension.
// Returns true if a corresponding mime type exists.
-bool GetMimeTypeFromExtension(const std::wstring& ext, std::string* mime_type);
+bool GetMimeTypeFromExtension(const FilePath::StringType& ext,
+ std::string* mime_type);
// Get the mime type (if any) that is associated with the given file.
// Returns true if a corresponding mime type exists.
-bool GetMimeTypeFromFile(const std::wstring& file_path, std::string* mime_type);
+bool GetMimeTypeFromFile(const FilePath& file_path, std::string* mime_type);
// Get the preferred extension (if any) associated with the given mime type.
// Returns true if a corresponding file extension exists. The extension does
// not include a prefixed dot, ex "html".
bool GetPreferredExtensionForMimeType(const std::string& mime_type,
- std::wstring* ext);
+ FilePath::StringType* ext);
// Sets a cookie string for the given URL. The policy_url argument indicates
// the URL of the topmost frame, which may be useful for determining whether or
diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc
index aa9dca7..f40dcbd 100755
--- a/webkit/tools/test_shell/test_shell.cc
+++ b/webkit/tools/test_shell/test_shell.cc
@@ -559,17 +559,18 @@ void AppendToLog(const char* file, int line, const char* msg) {
logging::LogMessage(file, line).stream() << msg;
}
-bool GetMimeTypeFromExtension(const std::wstring &ext, std::string *mime_type) {
+bool GetMimeTypeFromExtension(const FilePath::StringType& ext,
+ std::string *mime_type) {
return net::GetMimeTypeFromExtension(ext, mime_type);
}
-bool GetMimeTypeFromFile(const std::wstring &file_path,
+bool GetMimeTypeFromFile(const FilePath& file_path,
std::string *mime_type) {
return net::GetMimeTypeFromFile(file_path, mime_type);
}
bool GetPreferredExtensionForMimeType(const std::string& mime_type,
- std::wstring* ext) {
+ FilePath::StringType* ext) {
return net::GetPreferredExtensionForMimeType(mime_type, ext);
}