OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/file_utilities_message_filter.h" | 5 #include "content/browser/renderer_host/file_utilities_message_filter.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "content/browser/child_process_security_policy_impl.h" | 8 #include "content/browser/child_process_security_policy_impl.h" |
9 #include "content/common/file_utilities_messages.h" | 9 #include "content/common/file_utilities_messages.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 FileUtilitiesMessageFilter::FileUtilitiesMessageFilter(int process_id) | 13 FileUtilitiesMessageFilter::FileUtilitiesMessageFilter(int process_id) |
14 : BrowserMessageFilter(FileUtilitiesMsgStart), | 14 : BrowserMessageFilter(FileUtilitiesMsgStart), |
15 process_id_(process_id) { | 15 process_id_(process_id) { |
16 } | 16 } |
17 | 17 |
18 FileUtilitiesMessageFilter::~FileUtilitiesMessageFilter() { | 18 FileUtilitiesMessageFilter::~FileUtilitiesMessageFilter() { |
19 } | 19 } |
20 | 20 |
21 void FileUtilitiesMessageFilter::OverrideThreadForMessage( | 21 void FileUtilitiesMessageFilter::OverrideThreadForMessage( |
22 const IPC::Message& message, | 22 const IPC::Message& message, |
23 BrowserThread::ID* thread) { | 23 BrowserThread::ID* thread) { |
24 if (IPC_MESSAGE_CLASS(message) == FileUtilitiesMsgStart) | 24 if (IPC_MESSAGE_CLASS(message) == FileUtilitiesMsgStart) |
25 *thread = BrowserThread::FILE; | 25 *thread = BrowserThread::FILE; |
26 } | 26 } |
27 | 27 |
28 bool FileUtilitiesMessageFilter::OnMessageReceived(const IPC::Message& message, | 28 bool FileUtilitiesMessageFilter::OnMessageReceived( |
29 bool* message_was_ok) { | 29 const IPC::Message& message) { |
30 bool handled = true; | 30 bool handled = true; |
31 IPC_BEGIN_MESSAGE_MAP_EX(FileUtilitiesMessageFilter, message, *message_was_ok) | 31 IPC_BEGIN_MESSAGE_MAP(FileUtilitiesMessageFilter, message) |
32 IPC_MESSAGE_HANDLER(FileUtilitiesMsg_GetFileInfo, OnGetFileInfo) | 32 IPC_MESSAGE_HANDLER(FileUtilitiesMsg_GetFileInfo, OnGetFileInfo) |
33 IPC_MESSAGE_UNHANDLED(handled = false) | 33 IPC_MESSAGE_UNHANDLED(handled = false) |
34 IPC_END_MESSAGE_MAP() | 34 IPC_END_MESSAGE_MAP() |
35 return handled; | 35 return handled; |
36 } | 36 } |
37 | 37 |
38 void FileUtilitiesMessageFilter::OnGetFileInfo( | 38 void FileUtilitiesMessageFilter::OnGetFileInfo( |
39 const base::FilePath& path, | 39 const base::FilePath& path, |
40 base::File::Info* result, | 40 base::File::Info* result, |
41 base::File::Error* status) { | 41 base::File::Error* status) { |
42 *result = base::File::Info(); | 42 *result = base::File::Info(); |
43 *status = base::File::FILE_OK; | 43 *status = base::File::FILE_OK; |
44 | 44 |
45 // Get file metadata only when the child process has been granted | 45 // Get file metadata only when the child process has been granted |
46 // permission to read the file. | 46 // permission to read the file. |
47 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( | 47 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( |
48 process_id_, path)) { | 48 process_id_, path)) { |
49 return; | 49 return; |
50 } | 50 } |
51 | 51 |
52 if (!base::GetFileInfo(path, result)) | 52 if (!base::GetFileInfo(path, result)) |
53 *status = base::File::FILE_ERROR_FAILED; | 53 *status = base::File::FILE_ERROR_FAILED; |
54 } | 54 } |
55 | 55 |
56 } // namespace content | 56 } // namespace content |
OLD | NEW |