blob: 6c079a420f9acdff2bc7b5f94008646b6ead0b58 [file] [log] [blame]
[email protected]01651e6f2012-05-08 22:12:441// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]085cb5a2008-09-08 21:45:052// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]31de2b52011-02-25 02:47:065#include "net/base/platform_mime_util.h"
6
[email protected]085cb5a2008-09-08 21:45:057#include <string>
8
[email protected]6dbdaa82011-08-11 16:05:569#include "build/build_config.h"
Yuta Hijikata101ed2a2020-11-18 07:50:3910#include "build/chromeos_buildflags.h"
[email protected]6dbdaa82011-08-11 16:05:5611
Xiaohan Wang2a6845b2022-01-08 04:40:5712#if BUILDFLAG(IS_ANDROID)
[email protected]6dbdaa82011-08-11 16:05:5613#include "net/android/network_library.h"
14#else
[email protected]e52858922011-11-11 20:41:2115#include "base/nix/mime_util_xdg.h"
[email protected]6dbdaa82011-08-11 16:05:5616#endif
[email protected]085cb5a2008-09-08 21:45:0517
18namespace net {
19
Xiaohan Wang2a6845b2022-01-08 04:40:5720#if BUILDFLAG(IS_ANDROID)
[email protected]6dbdaa82011-08-11 16:05:5621bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
Sergey Ulanov77132a22017-07-21 02:34:0522 const base::FilePath::StringType& ext,
23 std::string* result) const {
[email protected]6dbdaa82011-08-11 16:05:5624 return android::GetMimeTypeFromExtension(ext, result);
25}
Yuta Hijikata101ed2a2020-11-18 07:50:3926#elif BUILDFLAG(IS_CHROMEOS_ASH)
yawanoc8297362015-05-19 05:47:5927bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
28 const base::FilePath::StringType& ext,
29 std::string* result) const {
Sergey Ulanov77132a22017-07-21 02:34:0530 return false;
yawanoc8297362015-05-19 05:47:5931}
[email protected]6dbdaa82011-08-11 16:05:5632#else
[email protected]085cb5a2008-09-08 21:45:0533bool PlatformMimeUtil::GetPlatformMimeTypeFromExtension(
Sergey Ulanov77132a22017-07-21 02:34:0534 const base::FilePath::StringType& ext,
35 std::string* result) const {
[email protected]6cdfd7f2013-02-08 20:40:1536 base::FilePath dummy_path("foo." + ext);
[email protected]e52858922011-11-11 20:41:2137 std::string out = base::nix::GetFileMimeType(dummy_path);
[email protected]449c5e762009-05-16 06:54:0638
[email protected]bff1ddf82009-05-16 04:30:0539 // GetFileMimeType likes to return application/octet-stream
40 // for everything it doesn't know - ignore that.
[email protected]dcefa302009-05-20 00:24:3941 if (out == "application/octet-stream" || out.empty())
[email protected]bff1ddf82009-05-16 04:30:0542 return false;
[email protected]449c5e762009-05-16 06:54:0643
44 // GetFileMimeType returns image/x-ico because that's what's in the XDG
45 // mime database. That database is the merger of the Gnome and KDE mime
46 // databases. Apparently someone working on KDE in 2001 decided .ico
47 // resolves to image/x-ico, whereas the rest of the world uses image/x-icon.
48 // FWIW, image/vnd.microsoft.icon is the official IANA assignment.
49 if (out == "image/x-ico")
50 out = "image/x-icon";
51
[email protected]bff1ddf82009-05-16 04:30:0552 *result = out;
53 return true;
[email protected]085cb5a2008-09-08 21:45:0554}
55
Xiaohan Wang2a6845b2022-01-08 04:40:5756#endif // BUILDFLAG(IS_ANDROID)
[email protected]6dbdaa82011-08-11 16:05:5657
Sergey Ulanov77132a22017-07-21 02:34:0558bool PlatformMimeUtil::GetPlatformPreferredExtensionForMimeType(
59 const std::string& mime_type,
60 base::FilePath::StringType* ext) const {
61 // xdg_mime doesn't provide an API to get extension from a MIME type, so we
62 // rely on the mappings hardcoded in mime_util.cc .
[email protected]085cb5a2008-09-08 21:45:0563 return false;
64}
65
[email protected]01651e6f2012-05-08 22:12:4466void PlatformMimeUtil::GetPlatformExtensionsForMimeType(
67 const std::string& mime_type,
davidben1e912ea2016-04-20 19:17:0768 std::unordered_set<base::FilePath::StringType>* extensions) const {
Sergey Ulanov77132a22017-07-21 02:34:0569 // xdg_mime doesn't provide an API to get extension from a MIME type, so we
70 // rely on the mappings hardcoded in mime_util.cc .
[email protected]01651e6f2012-05-08 22:12:4471}
72
[email protected]085cb5a2008-09-08 21:45:0573} // namespace net