- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / file_utilities_message_filter.cc
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
13 FileUtilitiesMessageFilter::FileUtilitiesMessageFilter(int process_id)
14     : process_id_(process_id) {
15 }
16
17 FileUtilitiesMessageFilter::~FileUtilitiesMessageFilter() {
18 }
19
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
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
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 (!file_util::GetFileInfo(path, result))
52     *status = base::PLATFORM_FILE_ERROR_FAILED;
53 }
54
55 }  // namespace content