blob: bd46a5daf22e36cd4e9fb5dae80df156ad57cb00 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2016 The Chromium Authors
sammcc0fe2742016-06-06 01:37:252// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/browser/mime_registry_impl.h"
6
7#include "base/files/file_path.h"
8#include "content/public/browser/browser_thread.h"
Avi Drissmanb7d23e82024-10-21 21:20:309#include "mojo/public/cpp/bindings/message.h"
Miyoung Shin82cc5d192019-09-03 13:59:5910#include "mojo/public/cpp/bindings/self_owned_receiver.h"
sammcc0fe2742016-06-06 01:37:2511#include "net/base/mime_util.h"
12
13namespace content {
14
rockot8e66a08d2016-09-13 00:48:2115MimeRegistryImpl::MimeRegistryImpl() = default;
16
17MimeRegistryImpl::~MimeRegistryImpl() = default;
18
sammcc0fe2742016-06-06 01:37:2519// static
bena5c972c2017-05-04 01:38:4320void MimeRegistryImpl::Create(
Miyoung Shin82cc5d192019-09-03 13:59:5921 mojo::PendingReceiver<blink::mojom::MimeRegistry> receiver) {
22 mojo::MakeSelfOwnedReceiver(std::make_unique<MimeRegistryImpl>(),
23 std::move(receiver));
sammcc0fe2742016-06-06 01:37:2524}
25
sammcc0fe2742016-06-06 01:37:2526void MimeRegistryImpl::GetMimeTypeFromExtension(
yzshen6b5ad7f22016-11-22 21:38:2127 const std::string& extension,
tzikcf7bcd652017-06-15 04:19:3028 GetMimeTypeFromExtensionCallback callback) {
Sam McNally83733882017-07-13 00:59:0129 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
Avi Drissmanb7d23e82024-10-21 21:20:3030
31 if (!extension.empty() && extension[0] == '.') {
32 // It is invalid to call this API with an extension with a leading dot.
33 mojo::ReportBadMessage("Extensions must not have a leading dot");
34 return;
35 }
36
sammcc0fe2742016-06-06 01:37:2537 std::string mime_type;
yzshen6b5ad7f22016-11-22 21:38:2138 net::GetMimeTypeFromExtension(
sammc5a2900a2017-01-05 07:45:5439 base::FilePath::FromUTF8Unsafe(extension).value(), &mime_type);
tzikcf7bcd652017-06-15 04:19:3040 std::move(callback).Run(mime_type);
sammcc0fe2742016-06-06 01:37:2541}
42
43} // namespace content