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/renderer/pepper/pepper_file_io_host.h" | 5 #include "content/renderer/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/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_util_proxy.h" | 11 #include "base/files/file_util_proxy.h" |
12 #include "content/child/child_thread.h" | 12 #include "content/child/child_thread.h" |
13 #include "content/child/fileapi/file_system_dispatcher.h" | 13 #include "content/child/fileapi/file_system_dispatcher.h" |
14 #include "content/child/quota_dispatcher.h" | 14 #include "content/child/quota_dispatcher.h" |
15 #include "content/common/fileapi/file_system_messages.h" | 15 #include "content/common/fileapi/file_system_messages.h" |
16 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
17 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
18 #include "content/public/renderer/content_renderer_client.h" | 18 #include "content/public/renderer/content_renderer_client.h" |
19 #include "content/renderer/pepper/host_globals.h" | 19 #include "content/renderer/pepper/host_globals.h" |
| 20 #include "content/renderer/pepper/pepper_file_ref_renderer_host.h" |
20 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 21 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
21 #include "content/renderer/pepper/ppb_file_ref_impl.h" | 22 #include "content/renderer/pepper/plugin_module.h" |
22 #include "content/renderer/pepper/quota_file_io.h" | 23 #include "content/renderer/pepper/quota_file_io.h" |
| 24 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
23 #include "content/renderer/render_thread_impl.h" | 25 #include "content/renderer/render_thread_impl.h" |
24 #include "ppapi/c/pp_errors.h" | 26 #include "ppapi/c/pp_errors.h" |
25 #include "ppapi/c/ppb_file_io.h" | 27 #include "ppapi/c/ppb_file_io.h" |
26 #include "ppapi/host/dispatch_host_message.h" | 28 #include "ppapi/host/dispatch_host_message.h" |
27 #include "ppapi/host/ppapi_host.h" | 29 #include "ppapi/host/ppapi_host.h" |
28 #include "ppapi/proxy/ppapi_messages.h" | 30 #include "ppapi/proxy/ppapi_messages.h" |
29 #include "ppapi/shared_impl/file_type_conversion.h" | 31 #include "ppapi/shared_impl/file_type_conversion.h" |
30 #include "ppapi/shared_impl/time_conversion.h" | 32 #include "ppapi/shared_impl/time_conversion.h" |
31 #include "ppapi/thunk/enter.h" | 33 #include "ppapi/thunk/enter.h" |
32 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 34 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
33 | 35 |
34 namespace content { | 36 namespace content { |
35 | 37 |
36 using ppapi::FileIOStateManager; | 38 using ppapi::FileIOStateManager; |
37 using ppapi::PPTimeToTime; | 39 using ppapi::PPTimeToTime; |
38 using ppapi::host::ReplyMessageContext; | 40 using ppapi::host::ReplyMessageContext; |
39 using ppapi::thunk::EnterResourceNoLock; | 41 using ppapi::thunk::EnterResourceNoLock; |
40 using ppapi::thunk::PPB_FileRef_API; | |
41 | 42 |
42 namespace { | 43 namespace { |
43 | 44 |
44 typedef base::Callback<void (base::PlatformFileError)> PlatformGeneralCallback; | 45 typedef base::Callback<void (base::PlatformFileError)> PlatformGeneralCallback; |
45 | 46 |
46 int32_t ErrorOrByteNumber(int32_t pp_error, int32_t byte_number) { | 47 int32_t ErrorOrByteNumber(int32_t pp_error, int32_t byte_number) { |
47 // On the plugin side, some callbacks expect a parameter that means different | 48 // On the plugin side, some callbacks expect a parameter that means different |
48 // things depending on whether is negative or not. We translate for those | 49 // things depending on whether is negative or not. We translate for those |
49 // callbacks here. | 50 // callbacks here. |
50 return pp_error == PP_OK ? byte_number : pp_error; | 51 return pp_error == PP_OK ? byte_number : pp_error; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 PepperFileIOHost::NotifyCloseFileCallback()); | 131 PepperFileIOHost::NotifyCloseFileCallback()); |
131 } | 132 } |
132 | 133 |
133 } // namespace | 134 } // namespace |
134 | 135 |
135 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, | 136 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, |
136 PP_Instance instance, | 137 PP_Instance instance, |
137 PP_Resource resource) | 138 PP_Resource resource) |
138 : ResourceHost(host->GetPpapiHost(), instance, resource), | 139 : ResourceHost(host->GetPpapiHost(), instance, resource), |
139 renderer_ppapi_host_(host), | 140 renderer_ppapi_host_(host), |
| 141 plugin_instance_(HostGlobals::Get()->GetInstance(instance)), |
140 file_(base::kInvalidPlatformFileValue), | 142 file_(base::kInvalidPlatformFileValue), |
141 file_system_type_(PP_FILESYSTEMTYPE_INVALID), | 143 file_system_type_(PP_FILESYSTEMTYPE_INVALID), |
142 quota_policy_(quota::kQuotaLimitTypeUnknown), | 144 quota_policy_(quota::kQuotaLimitTypeUnknown), |
143 is_running_in_process_(host->IsRunningInProcess()), | 145 is_running_in_process_(host->IsRunningInProcess()), |
144 open_flags_(0), | 146 open_flags_(0), |
145 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()), | 147 routing_id_(RenderThreadImpl::current()->GenerateRoutingID()), |
146 weak_factory_(this) { | 148 weak_factory_(this) { |
147 ChildThread::current()->AddRoute(routing_id_, this); | 149 ChildThread::current()->AddRoute(routing_id_, this); |
148 } | 150 } |
149 | 151 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 int32_t open_flags) { | 219 int32_t open_flags) { |
218 int32_t rv = state_manager_.CheckOperationState( | 220 int32_t rv = state_manager_.CheckOperationState( |
219 FileIOStateManager::OPERATION_EXCLUSIVE, false); | 221 FileIOStateManager::OPERATION_EXCLUSIVE, false); |
220 if (rv != PP_OK) | 222 if (rv != PP_OK) |
221 return rv; | 223 return rv; |
222 | 224 |
223 open_flags_ = open_flags; | 225 open_flags_ = open_flags; |
224 if (!ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, NULL)) | 226 if (!ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, NULL)) |
225 return PP_ERROR_BADARGUMENT; | 227 return PP_ERROR_BADARGUMENT; |
226 | 228 |
227 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref_resource, true); | 229 ppapi::host::ResourceHost* resource_host = |
228 if (enter.failed()) | 230 renderer_ppapi_host_->GetPpapiHost()->GetResourceHost(file_ref_resource); |
| 231 if (!resource_host || !resource_host->IsFileRefHost()) |
229 return PP_ERROR_BADRESOURCE; | 232 return PP_ERROR_BADRESOURCE; |
| 233 PepperFileRefRendererHost* file_ref_host = |
| 234 static_cast<PepperFileRefRendererHost*>(resource_host); |
230 | 235 |
231 PPB_FileRef_API* file_ref_api = enter.object(); | 236 file_system_type_ = file_ref_host->GetFileSystemType(); |
232 PP_FileSystemType type = file_ref_api->GetFileSystemType(); | 237 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) { |
233 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && | 238 file_system_url_ = file_ref_host->GetFileSystemURL(); |
234 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && | |
235 type != PP_FILESYSTEMTYPE_EXTERNAL && | |
236 type != PP_FILESYSTEMTYPE_ISOLATED) | |
237 return PP_ERROR_FAILED; | |
238 file_system_type_ = type; | |
239 | |
240 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); | |
241 if (file_ref->HasValidFileSystem()) { | |
242 file_system_url_ = file_ref->GetFileSystemURL(); | |
243 | |
244 FileSystemDispatcher* file_system_dispatcher = | 239 FileSystemDispatcher* file_system_dispatcher = |
245 ChildThread::current()->file_system_dispatcher(); | 240 ChildThread::current()->file_system_dispatcher(); |
| 241 |
246 AsyncOpenFileSystemURLCallback callback = base::Bind( | 242 AsyncOpenFileSystemURLCallback callback = base::Bind( |
247 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, | 243 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, |
248 weak_factory_.GetWeakPtr(), | 244 weak_factory_.GetWeakPtr(), |
249 context->MakeReplyMessageContext()); | 245 context->MakeReplyMessageContext()); |
250 file_system_dispatcher->OpenPepperFile( | 246 file_system_dispatcher->OpenPepperFile( |
251 file_system_url_, open_flags, | 247 file_system_url_, open_flags, |
252 base::Bind(&DidOpenFileSystemURL, callback), | 248 base::Bind(&DidOpenFileSystemURL, callback), |
253 base::Bind(&DidFailOpenFileSystemURL, callback)); | 249 base::Bind(&DidFailOpenFileSystemURL, callback)); |
254 } else { | 250 } else { |
255 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) | |
256 return PP_ERROR_FAILED; | |
257 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback( | 251 int message_id = pending_async_open_files_.Add(new AsyncOpenFileCallback( |
258 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, | 252 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, |
259 weak_factory_.GetWeakPtr(), | 253 weak_factory_.GetWeakPtr(), |
260 context->MakeReplyMessageContext()))); | 254 context->MakeReplyMessageContext()))); |
261 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile( | 255 RenderThreadImpl::current()->Send(new ViewHostMsg_AsyncOpenPepperFile( |
262 routing_id_, file_ref->GetSystemPath(), open_flags, message_id)); | 256 routing_id_, |
| 257 file_ref_host->GetExternalFilePath(), |
| 258 open_flags_, |
| 259 message_id)); |
263 } | 260 } |
264 | |
265 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 261 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
266 return PP_OK_COMPLETIONPENDING; | 262 return PP_OK_COMPLETIONPENDING; |
267 } | 263 } |
268 | 264 |
269 int32_t PepperFileIOHost::OnHostMsgTouch( | 265 int32_t PepperFileIOHost::OnHostMsgTouch( |
270 ppapi::host::HostMessageContext* context, | 266 ppapi::host::HostMessageContext* context, |
271 PP_Time last_access_time, | 267 PP_Time last_access_time, |
272 PP_Time last_modified_time) { | 268 PP_Time last_modified_time) { |
273 int32_t rv = state_manager_.CheckOperationState( | 269 int32_t rv = state_manager_.CheckOperationState( |
274 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 270 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 // On the plugin side, the callback expects a parameter with different meaning | 558 // On the plugin side, the callback expects a parameter with different meaning |
563 // depends on whether is negative or not. It is the result here. We translate | 559 // depends on whether is negative or not. It is the result here. We translate |
564 // for the callback. | 560 // for the callback. |
565 int32_t pp_error = ppapi::PlatformFileErrorToPepperError(error_code); | 561 int32_t pp_error = ppapi::PlatformFileErrorToPepperError(error_code); |
566 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); | 562 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); |
567 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); | 563 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); |
568 state_manager_.SetOperationFinished(); | 564 state_manager_.SetOperationFinished(); |
569 } | 565 } |
570 | 566 |
571 } // namespace content | 567 } // namespace content |
OLD | NEW |