1 // Copyright (c) 2011 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 "content/browser/mime_registry_message_filter.h"
6
7 #include "content/common/mime_registry_messages.h"
8 #include "net/base/mime_util.h"
9
10 namespace content {
11
MimeRegistryMessageFilter()12 MimeRegistryMessageFilter::MimeRegistryMessageFilter() {
13 }
14
~MimeRegistryMessageFilter()15 MimeRegistryMessageFilter::~MimeRegistryMessageFilter() {
16 }
17
OverrideThreadForMessage(const IPC::Message & message,BrowserThread::ID * thread)18 void MimeRegistryMessageFilter::OverrideThreadForMessage(
19 const IPC::Message& message,
20 BrowserThread::ID* thread) {
21 if (IPC_MESSAGE_CLASS(message) == MimeRegistryMsgStart)
22 *thread = BrowserThread::FILE;
23 }
24
OnMessageReceived(const IPC::Message & message,bool * message_was_ok)25 bool MimeRegistryMessageFilter::OnMessageReceived(const IPC::Message& message,
26 bool* message_was_ok) {
27 bool handled = true;
28 IPC_BEGIN_MESSAGE_MAP_EX(MimeRegistryMessageFilter, message, *message_was_ok)
29 IPC_MESSAGE_HANDLER(MimeRegistryMsg_GetMimeTypeFromExtension,
30 OnGetMimeTypeFromExtension)
31 IPC_MESSAGE_HANDLER(MimeRegistryMsg_GetMimeTypeFromFile,
32 OnGetMimeTypeFromFile)
33 IPC_MESSAGE_UNHANDLED(handled = false)
34 IPC_END_MESSAGE_MAP()
35 return handled;
36 }
37
OnGetMimeTypeFromExtension(const base::FilePath::StringType & ext,std::string * mime_type)38 void MimeRegistryMessageFilter::OnGetMimeTypeFromExtension(
39 const base::FilePath::StringType& ext, std::string* mime_type) {
40 net::GetMimeTypeFromExtension(ext, mime_type);
41 }
42
OnGetMimeTypeFromFile(const base::FilePath & file_path,std::string * mime_type)43 void MimeRegistryMessageFilter::OnGetMimeTypeFromFile(
44 const base::FilePath& file_path, std::string* mime_type) {
45 net::GetMimeTypeFromFile(file_path, mime_type);
46 }
47
48 } // namespace content
49