OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/base/platform_mime_util.h" | 5 #include "net/base/platform_mime_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
| 9 #include "build/build_config.h" |
| 10 |
| 11 #if defined(OS_ANDROID) |
| 12 #include "net/android/network_library.h" |
| 13 #else |
9 #include "base/mime_util.h" | 14 #include "base/mime_util.h" |
| 15 #endif |
10 | 16 |
11 namespace net { | 17 namespace net { |
12 | 18 |
| 19 #if defined(OS_ANDROID) |
| 20 |
| 21 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( |
| 22 const FilePath::StringType& ext, std::string* result) const { |
| 23 return android::GetMimeTypeFromExtension(ext, result); |
| 24 } |
| 25 |
| 26 #else |
| 27 |
13 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( | 28 bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension( |
14 const FilePath::StringType& ext, std::string* result) const { | 29 const FilePath::StringType& ext, std::string* result) const { |
15 // TODO(thestig) This is a temporary hack until we can fix this | 30 // TODO(thestig) This is a temporary hack until we can fix this |
16 // properly in test shell / webkit. | 31 // properly in test shell / webkit. |
17 // We have to play dumb and not return application/x-perl here | 32 // We have to play dumb and not return application/x-perl here |
18 // to make the reload-subframe-object layout test happy. | 33 // to make the reload-subframe-object layout test happy. |
19 if (ext == "pl") | 34 if (ext == "pl") |
20 return false; | 35 return false; |
21 | 36 |
22 FilePath dummy_path("foo." + ext); | 37 FilePath dummy_path("foo." + ext); |
23 std::string out = mime_util::GetFileMimeType(dummy_path); | 38 std::string out = mime_util::GetFileMimeType(dummy_path); |
24 | 39 |
25 // GetFileMimeType likes to return application/octet-stream | 40 // GetFileMimeType likes to return application/octet-stream |
26 // for everything it doesn't know - ignore that. | 41 // for everything it doesn't know - ignore that. |
27 if (out == "application/octet-stream" || out.empty()) | 42 if (out == "application/octet-stream" || out.empty()) |
28 return false; | 43 return false; |
29 | 44 |
30 // GetFileMimeType returns image/x-ico because that's what's in the XDG | 45 // GetFileMimeType returns image/x-ico because that's what's in the XDG |
31 // mime database. That database is the merger of the Gnome and KDE mime | 46 // mime database. That database is the merger of the Gnome and KDE mime |
32 // databases. Apparently someone working on KDE in 2001 decided .ico | 47 // databases. Apparently someone working on KDE in 2001 decided .ico |
33 // resolves to image/x-ico, whereas the rest of the world uses image/x-icon. | 48 // resolves to image/x-ico, whereas the rest of the world uses image/x-icon. |
34 // FWIW, image/vnd.microsoft.icon is the official IANA assignment. | 49 // FWIW, image/vnd.microsoft.icon is the official IANA assignment. |
35 if (out == "image/x-ico") | 50 if (out == "image/x-ico") |
36 out = "image/x-icon"; | 51 out = "image/x-icon"; |
37 | 52 |
38 *result = out; | 53 *result = out; |
39 return true; | 54 return true; |
40 } | 55 } |
41 | 56 |
| 57 #endif // defined(OS_ANDROID) |
| 58 |
42 struct MimeToExt { | 59 struct MimeToExt { |
43 const char* mime_type; | 60 const char* mime_type; |
44 const char* ext; | 61 const char* ext; |
45 }; | 62 }; |
46 | 63 |
47 const struct MimeToExt mime_type_ext_map[] = { | 64 const struct MimeToExt mime_type_ext_map[] = { |
48 {"application/pdf", "pdf"}, | 65 {"application/pdf", "pdf"}, |
49 {"application/x-tar", "tar"}, | 66 {"application/x-tar", "tar"}, |
50 {"audio/mpeg", "mp3"}, | 67 {"audio/mpeg", "mp3"}, |
51 {"image/gif", "gif"}, | 68 {"image/gif", "gif"}, |
(...skipping 25 matching lines...) Expand all Loading... |
77 // | 94 // |
78 // If we wanted to do this properly, we would read the mime.cache file which | 95 // If we wanted to do this properly, we would read the mime.cache file which |
79 // has a section where they assign a glob (*.gif) to a mimetype | 96 // has a section where they assign a glob (*.gif) to a mimetype |
80 // (image/gif). We look up the "heaviest" glob for a certain mime type and | 97 // (image/gif). We look up the "heaviest" glob for a certain mime type and |
81 // then then try to chop off "*.". | 98 // then then try to chop off "*.". |
82 | 99 |
83 return false; | 100 return false; |
84 } | 101 } |
85 | 102 |
86 } // namespace net | 103 } // namespace net |
OLD | NEW |