summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-06 20:26:16 +0000
committerdeanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-06 20:26:16 +0000
commitceac4d2624abac6f223f99e4a3a6147723b3b1e3 (patch)
tree189af1123eacab269fb18572a7749832e5c6eb53
parentb028ced8710f7cd9f4c5b4114bdba08ed94659b9 (diff)
downloadchromium_src-ceac4d2624abac6f223f99e4a3a6147723b3b1e3.zip
chromium_src-ceac4d2624abac6f223f99e4a3a6147723b3b1e3.tar.gz
chromium_src-ceac4d2624abac6f223f99e4a3a6147723b3b1e3.tar.bz2
Make the mime -> extension code return a dotless extension.
Previously we would return something like ".html", because that's how it's stored in the registry on Windows. For a variety of reasons, it's much simpler to work without the prefixed dot. In fact, the only two consumers were manually stripping of the prefix dot. There is a cooresponding change that should happen in WebKit / ChromiumBridge, but since it's checking if there is a prefix dot and removing it, the code will still work, and I'll follow up with that change. Review URL: http://codereview.chromium.org/23010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9333 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/base/mime_util.h2
-rw-r--r--net/base/platform_mime_util_win.cc9
-rw-r--r--webkit/glue/webkit_glue.h3
3 files changed, 11 insertions, 3 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
diff --git a/webkit/glue/webkit_glue.h b/webkit/glue/webkit_glue.h
index 1826876..ca30d3a 100644
--- a/webkit/glue/webkit_glue.h
+++ b/webkit/glue/webkit_glue.h
@@ -153,7 +153,8 @@ bool GetMimeTypeFromExtension(const std::wstring& ext, std::string* mime_type);
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.
+// 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);