diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/base/mime_util.h | 2 | ||||
-rw-r--r-- | net/base/platform_mime_util_win.cc | 9 |
2 files changed, 9 insertions, 2 deletions
diff --git a/net/base/mime_util.h b/net/base/mime_util.h index 3f81845..7bfe1c3 100644 --- a/net/base/mime_util.h +++ b/net/base/mime_util.h @@ -19,7 +19,7 @@ bool GetMimeTypeFromFile(const std::wstring& 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 with a prefixed dot (as stored in the registry), ex ".avi". +// returned without a prefixed dot, ex "html". bool GetPreferredExtensionForMimeType(const std::string& mime_type, std::wstring* extension); diff --git a/net/base/platform_mime_util_win.cc b/net/base/platform_mime_util_win.cc index c0219fc..53600cf 100644 --- a/net/base/platform_mime_util_win.cc +++ b/net/base/platform_mime_util_win.cc @@ -27,7 +27,14 @@ bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( bool PlatformMimeUtil::GetPreferredExtensionForMimeType( const std::string& mime_type, std::wstring* ext) const { std::wstring key(L"MIME\\Database\\Content Type\\" + UTF8ToWide(mime_type)); - return RegKey(HKEY_CLASSES_ROOT, key.c_str()).ReadValue(L"Extension", ext); + if (!RegKey(HKEY_CLASSES_ROOT, key.c_str()).ReadValue(L"Extension", ext)) + return false; + + // Strip off the leading dot, this should always be the case. + if (!ext->empty() && ext->at(0) == L'.') + ext->erase(ext->begin()); + + return true; } } // namespace net |