OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/pepper/pepper_file_io_host.h" | 5 #include "content/browser/renderer_host/pepper/pepper_file_io_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/files/file_util_proxy.h" | 10 #include "base/files/file_util_proxy.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 namespace content { | 37 namespace content { |
38 | 38 |
39 using ppapi::FileIOStateManager; | 39 using ppapi::FileIOStateManager; |
40 using ppapi::PPTimeToTime; | 40 using ppapi::PPTimeToTime; |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 PepperFileIOHost::UIThreadStuff | 44 PepperFileIOHost::UIThreadStuff |
45 GetUIThreadStuffForInternalFileSystems(int render_process_id) { | 45 GetUIThreadStuffForInternalFileSystems(int render_process_id) { |
46 PepperFileIOHost::UIThreadStuff stuff; | 46 PepperFileIOHost::UIThreadStuff stuff; |
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
48 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); | 48 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); |
49 if (host) { | 49 if (host) { |
50 stuff.resolved_render_process_id = base::GetProcId(host->GetHandle()); | 50 stuff.resolved_render_process_id = base::GetProcId(host->GetHandle()); |
51 StoragePartition* storage_partition = host->GetStoragePartition(); | 51 StoragePartition* storage_partition = host->GetStoragePartition(); |
52 if (storage_partition) | 52 if (storage_partition) |
53 stuff.file_system_context = storage_partition->GetFileSystemContext(); | 53 stuff.file_system_context = storage_partition->GetFileSystemContext(); |
54 } | 54 } |
55 return stuff; | 55 return stuff; |
56 } | 56 } |
57 | 57 |
58 base::ProcessId GetResolvedRenderProcessId(int render_process_id) { | 58 base::ProcessId GetResolvedRenderProcessId(int render_process_id) { |
59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 59 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
60 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); | 60 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); |
61 if (!host) | 61 if (!host) |
62 return base::kNullProcessId; | 62 return base::kNullProcessId; |
63 return base::GetProcId(host->GetHandle()); | 63 return base::GetProcId(host->GetHandle()); |
64 } | 64 } |
65 | 65 |
66 bool GetPluginAllowedToCallRequestOSFileHandle(int render_process_id, | 66 bool GetPluginAllowedToCallRequestOSFileHandle(int render_process_id, |
67 const GURL& document_url) { | 67 const GURL& document_url) { |
68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 68 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
69 ContentBrowserClient* client = GetContentClient()->browser(); | 69 ContentBrowserClient* client = GetContentClient()->browser(); |
70 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); | 70 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); |
71 if (!host) | 71 if (!host) |
72 return false; | 72 return false; |
73 return client->IsPluginAllowedToCallRequestOSFileHandle( | 73 return client->IsPluginAllowedToCallRequestOSFileHandle( |
74 host->GetBrowserContext(), document_url); | 74 host->GetBrowserContext(), document_url); |
75 } | 75 } |
76 | 76 |
77 bool FileOpenForWrite(int32_t open_flags) { | 77 bool FileOpenForWrite(int32_t open_flags) { |
78 return (open_flags & (PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_APPEND)) != 0; | 78 return (open_flags & (PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_APPEND)) != 0; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 platform_file_flags)); | 192 platform_file_flags)); |
193 } | 193 } |
194 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 194 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
195 return PP_OK_COMPLETIONPENDING; | 195 return PP_OK_COMPLETIONPENDING; |
196 } | 196 } |
197 | 197 |
198 void PepperFileIOHost::GotUIThreadStuffForInternalFileSystems( | 198 void PepperFileIOHost::GotUIThreadStuffForInternalFileSystems( |
199 ppapi::host::ReplyMessageContext reply_context, | 199 ppapi::host::ReplyMessageContext reply_context, |
200 int platform_file_flags, | 200 int platform_file_flags, |
201 UIThreadStuff ui_thread_stuff) { | 201 UIThreadStuff ui_thread_stuff) { |
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 202 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
203 file_system_context_ = ui_thread_stuff.file_system_context; | 203 file_system_context_ = ui_thread_stuff.file_system_context; |
204 resolved_render_process_id_ = ui_thread_stuff.resolved_render_process_id; | 204 resolved_render_process_id_ = ui_thread_stuff.resolved_render_process_id; |
205 if (resolved_render_process_id_ == base::kNullProcessId || | 205 if (resolved_render_process_id_ == base::kNullProcessId || |
206 !file_system_context_.get()) { | 206 !file_system_context_.get()) { |
207 reply_context.params.set_result(PP_ERROR_FAILED); | 207 reply_context.params.set_result(PP_ERROR_FAILED); |
208 SendOpenErrorReply(reply_context); | 208 SendOpenErrorReply(reply_context); |
209 return; | 209 return; |
210 } | 210 } |
211 | 211 |
212 if (!file_system_context_->GetFileSystemBackend(file_system_url_.type())) { | 212 if (!file_system_context_->GetFileSystemBackend(file_system_url_.type())) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 248 |
249 ExecutePlatformOpenFileCallback( | 249 ExecutePlatformOpenFileCallback( |
250 reply_context, result, base::PassPlatformFile(&file), true); | 250 reply_context, result, base::PassPlatformFile(&file), true); |
251 } | 251 } |
252 | 252 |
253 void PepperFileIOHost::GotResolvedRenderProcessId( | 253 void PepperFileIOHost::GotResolvedRenderProcessId( |
254 ppapi::host::ReplyMessageContext reply_context, | 254 ppapi::host::ReplyMessageContext reply_context, |
255 base::FilePath path, | 255 base::FilePath path, |
256 int platform_file_flags, | 256 int platform_file_flags, |
257 base::ProcessId resolved_render_process_id) { | 257 base::ProcessId resolved_render_process_id) { |
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 258 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
259 resolved_render_process_id_ = resolved_render_process_id; | 259 resolved_render_process_id_ = resolved_render_process_id; |
260 base::FileUtilProxy::CreateOrOpen( | 260 base::FileUtilProxy::CreateOrOpen( |
261 file_message_loop_, | 261 file_message_loop_, |
262 path, | 262 path, |
263 platform_file_flags, | 263 platform_file_flags, |
264 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, | 264 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, |
265 weak_factory_.GetWeakPtr(), | 265 weak_factory_.GetWeakPtr(), |
266 reply_context)); | 266 reply_context)); |
267 } | 267 } |
268 | 268 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 document_url), | 387 document_url), |
388 base::Bind(&PepperFileIOHost::GotPluginAllowedToCallRequestOSFileHandle, | 388 base::Bind(&PepperFileIOHost::GotPluginAllowedToCallRequestOSFileHandle, |
389 weak_factory_.GetWeakPtr(), | 389 weak_factory_.GetWeakPtr(), |
390 context->MakeReplyMessageContext())); | 390 context->MakeReplyMessageContext())); |
391 return PP_OK_COMPLETIONPENDING; | 391 return PP_OK_COMPLETIONPENDING; |
392 } | 392 } |
393 | 393 |
394 void PepperFileIOHost::GotPluginAllowedToCallRequestOSFileHandle( | 394 void PepperFileIOHost::GotPluginAllowedToCallRequestOSFileHandle( |
395 ppapi::host::ReplyMessageContext reply_context, | 395 ppapi::host::ReplyMessageContext reply_context, |
396 bool plugin_allowed) { | 396 bool plugin_allowed) { |
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 397 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
398 if (!browser_ppapi_host_->external_plugin() || | 398 if (!browser_ppapi_host_->external_plugin() || |
399 host()->permissions().HasPermission(ppapi::PERMISSION_PRIVATE) || | 399 host()->permissions().HasPermission(ppapi::PERMISSION_PRIVATE) || |
400 plugin_allowed) { | 400 plugin_allowed) { |
401 if (!AddFileToReplyContext(open_flags_, &reply_context)) | 401 if (!AddFileToReplyContext(open_flags_, &reply_context)) |
402 reply_context.params.set_result(PP_ERROR_FAILED); | 402 reply_context.params.set_result(PP_ERROR_FAILED); |
403 } else { | 403 } else { |
404 reply_context.params.set_result(PP_ERROR_NOACCESS); | 404 reply_context.params.set_result(PP_ERROR_NOACCESS); |
405 } | 405 } |
406 host()->SendReply(reply_context, | 406 host()->SendReply(reply_context, |
407 PpapiPluginMsg_FileIO_RequestOSFileHandleReply()); | 407 PpapiPluginMsg_FileIO_RequestOSFileHandleReply()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 | 464 |
465 ppapi::proxy::SerializedHandle file_handle; | 465 ppapi::proxy::SerializedHandle file_handle; |
466 // A non-zero resource id signals NaClIPCAdapter to create a NaClQuotaDesc. | 466 // A non-zero resource id signals NaClIPCAdapter to create a NaClQuotaDesc. |
467 PP_Resource quota_file_io = check_quota_ ? pp_resource() : 0; | 467 PP_Resource quota_file_io = check_quota_ ? pp_resource() : 0; |
468 file_handle.set_file_handle(transit_file, open_flags, quota_file_io); | 468 file_handle.set_file_handle(transit_file, open_flags, quota_file_io); |
469 reply_context->params.AppendHandle(file_handle); | 469 reply_context->params.AppendHandle(file_handle); |
470 return true; | 470 return true; |
471 } | 471 } |
472 | 472 |
473 } // namespace content | 473 } // namespace content |
OLD | NEW |