• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "content/browser/renderer_host/file_utilities_message_filter.h"
6 
7 #include "base/file_util.h"
8 #include "content/browser/child_process_security_policy_impl.h"
9 #include "content/common/file_utilities_messages.h"
10 
11 namespace content {
12 
FileUtilitiesMessageFilter(int process_id)13 FileUtilitiesMessageFilter::FileUtilitiesMessageFilter(int process_id)
14     : process_id_(process_id) {
15 }
16 
~FileUtilitiesMessageFilter()17 FileUtilitiesMessageFilter::~FileUtilitiesMessageFilter() {
18 }
19 
OverrideThreadForMessage(const IPC::Message & message,BrowserThread::ID * thread)20 void FileUtilitiesMessageFilter::OverrideThreadForMessage(
21     const IPC::Message& message,
22     BrowserThread::ID* thread) {
23   if (IPC_MESSAGE_CLASS(message) == FileUtilitiesMsgStart)
24     *thread = BrowserThread::FILE;
25 }
26 
OnMessageReceived(const IPC::Message & message,bool * message_was_ok)27 bool FileUtilitiesMessageFilter::OnMessageReceived(const IPC::Message& message,
28                                                    bool* message_was_ok) {
29   bool handled = true;
30   IPC_BEGIN_MESSAGE_MAP_EX(FileUtilitiesMessageFilter, message, *message_was_ok)
31     IPC_MESSAGE_HANDLER(FileUtilitiesMsg_GetFileInfo, OnGetFileInfo)
32     IPC_MESSAGE_UNHANDLED(handled = false)
33   IPC_END_MESSAGE_MAP()
34   return handled;
35 }
36 
OnGetFileInfo(const base::FilePath & path,base::PlatformFileInfo * result,base::PlatformFileError * status)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;
43 
44   // Get file metadata only when the child process has been granted
45   // permission to read the file.
46   if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile(
47       process_id_, path)) {
48     return;
49   }
50 
51   if (!base::GetFileInfo(path, result))
52     *status = base::PLATFORM_FILE_ERROR_FAILED;
53 }
54 
55 }  // namespace content
56