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 chromeos { |
| 11 |
| 12 namespace { |
| 13 |
| 14 static const net::MimeInfo mimetype_extension_mapping[] = { |
| 15 {"application/epub+zip", "epub"}, |
| 16 {"application/zip", "zip"}, |
| 17 {"text/calendar", "ics"}, |
| 18 }; |
| 19 } // namespace |
| 20 |
| 21 // On linux, chrome uses xdgmime to read extension-mimetype database (e.g. |
| 22 // /usr/share/mime) and estimate mime type from extension. However ChromeOS does |
| 23 // not have such database in it, we use |mimetype_extension_mapping| to resolve |
| 24 // mime type on ChromeOS. |
| 25 bool GetPlatformMimeTypeFromExtension(const base::FilePath::StringType& ext, |
| 26 std::string* mime_type) { |
| 27 base::FilePath path_ext(ext); |
| 28 const std::string ext_narrow_str = path_ext.AsUTF8Unsafe(); |
| 29 const char* result = net::FindMimeType(mimetype_extension_mapping, |
| 30 arraysize(mimetype_extension_mapping), |
| 31 ext_narrow_str.c_str()); |
| 32 if (result) { |
| 33 *mime_type = result; |
| 34 return true; |
| 35 } |
| 36 |
| 37 return false; |
| 38 } |
| 39 } // namespace chromeos |
OLD | NEW |