OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/base/mime_extension_chromeos.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "net/base/mime_util.h" |
| 9 |
| 10 namespace net { |
| 11 namespace chromeos { |
| 12 |
| 13 namespace { |
| 14 |
| 15 static const net::MimeInfo mimetype_extension_mapping[] = { |
| 16 {"application/epub+zip", "epub"}, |
| 17 {"application/zip", "zip"}, |
| 18 {"text/calendar", "ics"}, |
| 19 }; |
| 20 } // namespace |
| 21 |
| 22 // On linux, chrome uses xdgmime to read extension-mimetype database (e.g. |
| 23 // /usr/share/mime) and estimate mime type from extension. However ChromeOS does |
| 24 // not have such database in it, we use |mimetype_extension_mapping| to resolve |
| 25 // mime type on ChromeOS. |
| 26 bool GetPlatformMimeTypeFromExtension(const base::FilePath::StringType& ext, |
| 27 std::string* mime_type) { |
| 28 base::FilePath path_ext(ext); |
| 29 const std::string ext_narrow_str = path_ext.AsUTF8Unsafe(); |
| 30 const char* result = net::FindMimeType(mimetype_extension_mapping, |
| 31 arraysize(mimetype_extension_mapping), |
| 32 ext_narrow_str.c_str()); |
| 33 if (result) { |
| 34 *mime_type = result; |
| 35 return true; |
| 36 } |
| 37 |
| 38 return false; |
| 39 } |
| 40 } // namespace chromeos |
| 41 } // namespace net |
OLD | NEW |