summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-08 19:27:28 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-08 19:27:28 +0000
commitdc6ee2482d239e37b1fb7e0619df2c058ce91bfd (patch)
tree6bdb36815910ee8d49a706a2ca5d7049004244c1 /net
parent505115c27f5454df0878407c7706c7f1c3744b0d (diff)
downloadchromium_src-dc6ee2482d239e37b1fb7e0619df2c058ce91bfd.zip
chromium_src-dc6ee2482d239e37b1fb7e0619df2c058ce91bfd.tar.gz
chromium_src-dc6ee2482d239e37b1fb7e0619df2c058ce91bfd.tar.bz2
Break out windows specific parts of mime_util.cc into mime_util_win.cc
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@582 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/SConscript1
-rw-r--r--net/base/mime_util.cc23
-rw-r--r--net/base/mime_util_win.cc59
-rw-r--r--net/build/net.vcproj4
4 files changed, 70 insertions, 17 deletions
diff --git a/net/SConscript b/net/SConscript
index b10bd56..7a7fb14 100644
--- a/net/SConscript
+++ b/net/SConscript
@@ -73,6 +73,7 @@ input_files = [
'base/listen_socket.cc',
'base/mime_sniffer.cc',
'base/mime_util.cc',
+ 'base/mime_util_win.cc',
'base/net_errors.cc',
'base/net_module.cc',
'base/net_util.cc',
diff --git a/net/base/mime_util.cc b/net/base/mime_util.cc
index 8595311..1277957 100644
--- a/net/base/mime_util.cc
+++ b/net/base/mime_util.cc
@@ -31,10 +31,7 @@
#include <string.h>
#include "net/base/mime_util.h"
-
-#include "base/basictypes.h"
#include "base/logging.h"
-#include "base/registry.h"
#include "base/string_util.h"
using std::string;
@@ -42,6 +39,11 @@ using std::wstring;
namespace net {
+// Helper used by GetMimeTypeFromExtension() to lookup the
+// platform specific mappings. Defined in mime_util_{win,mac}.cc
+bool GetPlatformMimeTypeFromExtension(const std::wstring& ext,
+ std::string* mime_type);
+
struct MimeInfo {
const char* mime_type;
const char* extensions; // comma separated list
@@ -115,14 +117,8 @@ bool GetMimeTypeFromExtension(const wstring& ext, string* result) {
return true;
}
- // check windows registry for file extension's mime type (registry key
- // names are not case-sensitive).
- wstring value, key = L"." + ext;
- RegKey(HKEY_CLASSES_ROOT, key.c_str()).ReadValue(L"Content Type", &value);
- if (!value.empty()) {
- *result = WideToUTF8(value);
+ if (GetPlatformMimeTypeFromExtension(ext, result))
return true;
- }
mime_type = FindMimeType(secondary_mappings, arraysize(secondary_mappings),
ext_utf8.c_str());
@@ -141,13 +137,6 @@ bool GetMimeTypeFromFile(const wstring& file_path, string* result) {
return GetMimeTypeFromExtension(file_path.substr(dot + 1), result);
}
-bool GetPreferredExtensionForMimeType(const std::string& mime_type,
- std::wstring* ext) {
- wstring key(L"MIME\\Database\\Content Type\\" + UTF8ToWide(mime_type));
- return RegKey(HKEY_CLASSES_ROOT, key.c_str()).ReadValue(L"Extension", ext);
-}
-
-
// From WebKit's WebCore/platform/MIMETypeRegistry.cpp:
static const char* supported_image_types[] = {
diff --git a/net/base/mime_util_win.cc b/net/base/mime_util_win.cc
new file mode 100644
index 0000000..dae5238
--- /dev/null
+++ b/net/base/mime_util_win.cc
@@ -0,0 +1,59 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <string.h>
+
+#include "base/registry.h"
+#include "base/string_util.h"
+
+namespace net {
+
+// Helper used by GetMimeTypeFromExtension() to lookup the
+// platform specific mappings. Declared in mime_util.cc
+bool GetPlatformMimeTypeFromExtension(const std::wstring& ext,
+ std::string* result) {
+ // check windows registry for file extension's mime type (registry key
+ // names are not case-sensitive).
+ std::wstring value, key = L"." + ext;
+ RegKey(HKEY_CLASSES_ROOT, key.c_str()).ReadValue(L"Content Type", &value);
+ if (!value.empty()) {
+ *result = WideToUTF8(value);
+ return true;
+ }
+
+ return false;
+}
+
+bool GetPreferredExtensionForMimeType(const std::string& mime_type,
+ std::wstring* ext) {
+ std::wstring key(L"MIME\\Database\\Content Type\\" + UTF8ToWide(mime_type));
+ return RegKey(HKEY_CLASSES_ROOT, key.c_str()).ReadValue(L"Extension", ext);
+}
+
+} // namespace net
diff --git a/net/build/net.vcproj b/net/build/net.vcproj
index 3da1c7b..b605946 100644
--- a/net/build/net.vcproj
+++ b/net/build/net.vcproj
@@ -325,6 +325,10 @@
>
</File>
<File
+ RelativePath="..\base\mime_util_win.cc"
+ >
+ </File>
+ <File
RelativePath="..\base\mime_util.h"
>
</File>