1 // Copyright (c) 2012 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.
5 #include "content/browser/renderer_host/file_utilities_message_filter.h"
7 #include "base/file_util.h"
8 #include "content/browser/child_process_security_policy_impl.h"
9 #include "content/common/file_utilities_messages.h"
13 FileUtilitiesMessageFilter::FileUtilitiesMessageFilter(int process_id)
14 : process_id_(process_id) {
17 FileUtilitiesMessageFilter::~FileUtilitiesMessageFilter() {
20 void FileUtilitiesMessageFilter::OverrideThreadForMessage(
21 const IPC::Message& message,
22 BrowserThread::ID* thread) {
23 if (IPC_MESSAGE_CLASS(message) == FileUtilitiesMsgStart)
24 *thread = BrowserThread::FILE;
27 bool FileUtilitiesMessageFilter::OnMessageReceived(const IPC::Message& message,
28 bool* message_was_ok) {
30 IPC_BEGIN_MESSAGE_MAP_EX(FileUtilitiesMessageFilter, message, *message_was_ok)
31 IPC_MESSAGE_HANDLER(FileUtilitiesMsg_GetFileInfo, OnGetFileInfo)
32 IPC_MESSAGE_UNHANDLED(handled = false)
37 void FileUtilitiesMessageFilter::OnGetFileInfo(
38 const base::FilePath& path,
39 base::PlatformFileInfo* result,
40 base::PlatformFileError* status) {
41 *result = base::PlatformFileInfo();
42 *status = base::PLATFORM_FILE_OK;
44 // Get file metadata only when the child process has been granted
45 // permission to read the file.
46 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
51 if (!file_util::GetFileInfo(path, result))
52 *status = base::PLATFORM_FILE_ERROR_FAILED;
55 } // namespace content