OLD | NEW |
---|---|
(Empty) | |
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/renderer/pepper/pepper_file_io_host.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/callback_helpers.h" | |
11 #include "base/file_util_proxy.h" | |
12 #include "ppapi/c/pp_errors.h" | |
13 #include "ppapi/host/dispatch_host_message.h" | |
14 #include "ppapi/host/ppapi_host.h" | |
15 #include "ppapi/proxy/ppapi_messages.h" | |
16 #include "ppapi/shared_impl/file_type_conversion.h" | |
17 #include "ppapi/shared_impl/file_type_conversion.h" | |
18 #include "ppapi/shared_impl/time_conversion.h" | |
19 #include "ppapi/shared_impl/time_conversion.h" | |
20 #include "webkit/fileapi/file_system_callback_dispatcher.h" | |
21 #include "webkit/plugins/ppapi/file_callbacks.h" | |
22 #include "webkit/plugins/ppapi/host_globals.h" | |
23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | |
24 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | |
25 #include "webkit/plugins/ppapi/quota_file_io.h" | |
26 | |
27 namespace content { | |
28 | |
29 using ppapi::PPTimeToTime; | |
30 using ppapi::TimeToPPTime; | |
31 using ppapi::thunk::PPB_FileRef_API; | |
32 using webkit::ppapi::PPB_FileRef_Impl; | |
33 using webkit::ppapi::PluginDelegate; | |
34 | |
35 namespace { | |
36 | |
37 // The maximum size we'll support reading in one chunk. The renderer process | |
38 // must allocate a buffer sized according to the request of the plugin. To | |
39 // keep things from getting out of control, we cap the read size to this value. | |
40 // This should generally be OK since the API specifies that it may perform a | |
41 // partial read. | |
42 static const int32_t kMaxReadSize = 32 * 1024 * 1024; // 32MB | |
43 | |
44 typedef base::Callback<void (base::PlatformFileError)> PlatformGeneralCallback; | |
45 | |
46 class PlatformGeneralCallbackTranslator | |
47 : public fileapi::FileSystemCallbackDispatcher { | |
48 public: | |
49 PlatformGeneralCallbackTranslator( | |
50 const PlatformGeneralCallback& callback) | |
51 : callback_(callback) {} | |
52 | |
53 virtual ~PlatformGeneralCallbackTranslator() {} | |
54 | |
55 virtual void DidSucceed() OVERRIDE { | |
56 callback_.Run(base::PLATFORM_FILE_OK); | |
57 } | |
58 | |
59 virtual void DidReadMetadata( | |
60 const base::PlatformFileInfo& file_info, | |
61 const FilePath& platform_path) OVERRIDE { | |
62 NOTREACHED(); | |
63 } | |
64 | |
65 virtual void DidReadDirectory( | |
66 const std::vector<base::FileUtilProxy::Entry>& entries, | |
67 bool has_more) OVERRIDE { | |
68 NOTREACHED(); | |
69 } | |
70 | |
71 virtual void DidOpenFileSystem(const std::string& name, | |
72 const GURL& root) OVERRIDE { | |
73 NOTREACHED(); | |
74 } | |
75 | |
76 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { | |
77 callback_.Run(error_code); | |
78 } | |
79 | |
80 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE { | |
81 NOTREACHED(); | |
82 } | |
83 | |
84 virtual void DidOpenFile(base::PlatformFile file) OVERRIDE { | |
85 NOTREACHED(); | |
86 } | |
87 | |
88 private: | |
89 PlatformGeneralCallback callback_; | |
90 }; | |
91 | |
92 } // namespace | |
93 | |
94 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, | |
95 PP_Instance instance, | |
96 PP_Resource resource) | |
97 : ResourceHost(host->GetPpapiHost(), instance, resource), | |
98 ppapi::PPB_FileIO_Shared(), | |
99 file_(base::kInvalidPlatformFileValue), | |
100 file_system_type_(PP_FILESYSTEMTYPE_INVALID), | |
101 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
102 // TODO: eliminate plugin_delegate_ as it's no longer needed. | |
103 webkit::ppapi::PluginInstance* plugin_instance = | |
104 webkit::ppapi::HostGlobals::Get()->GetInstance(instance); | |
105 plugin_delegate_ = plugin_instance ? plugin_instance->delegate() : NULL; | |
106 } | |
107 | |
108 PepperFileIOHost::~PepperFileIOHost() { | |
109 } | |
110 | |
111 int32_t PepperFileIOHost::OnResourceMessageReceived( | |
112 const IPC::Message& msg, | |
113 ppapi::host::HostMessageContext* context) { | |
114 IPC_BEGIN_MESSAGE_MAP(PepperFileIOHost, msg) | |
115 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Open, | |
116 OnHostMsgOpen) | |
117 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Query, | |
118 OnHostMsgQuery) | |
119 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Touch, | |
120 OnHostMsgTouch) | |
121 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Read, | |
122 OnHostMsgRead) | |
123 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Write, | |
124 OnHostMsgWrite) | |
125 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_SetLength, | |
126 OnHostMsgSetLength) | |
127 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Flush, | |
128 OnHostMsgFlush) | |
129 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Close, | |
130 OnHostMsgClose) | |
131 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_WillWrite, | |
132 OnHostMsgWillWrite) | |
133 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_WillSetLength, | |
134 OnHostMsgWillSetLength) | |
135 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_GetOSFileDescriptor, | |
136 OnHostMsgGetOSFileDescriptor) | |
137 IPC_END_MESSAGE_MAP() | |
138 return PP_ERROR_FAILED; | |
139 } | |
140 | |
141 int32_t PepperFileIOHost::OnHostMsgOpen( | |
142 ppapi::host::HostMessageContext* context, | |
143 PP_Resource file_ref_resource, | |
144 int32_t open_flags) { | |
145 temp_reply_context_ = context->MakeReplyMessageContext(); | |
146 return DoOpen(file_ref_resource, open_flags); | |
147 } | |
148 | |
149 int32_t PepperFileIOHost::OnHostMsgQuery( | |
150 ppapi::host::HostMessageContext* context) { | |
151 temp_reply_context_ = context->MakeReplyMessageContext(); | |
152 return DoQuery(); | |
153 } | |
154 | |
155 int32_t PepperFileIOHost::OnHostMsgTouch( | |
156 ppapi::host::HostMessageContext* context, | |
157 PP_Time last_access_time, | |
158 PP_Time last_modified_time) { | |
159 temp_reply_context_ = context->MakeReplyMessageContext(); | |
160 return DoTouch(last_access_time, last_modified_time); | |
161 } | |
162 | |
163 int32_t PepperFileIOHost::OnHostMsgRead( | |
164 ppapi::host::HostMessageContext* context, | |
165 int64_t offset, | |
166 int32_t bytes_to_read) { | |
167 | |
168 // Validate bytes_to_read before allocating below. This value is coming from | |
169 // the untrusted plugin. | |
170 if (bytes_to_read < 0) { | |
171 ppapi::host::ReplyMessageContext reply_context = | |
172 context->MakeReplyMessageContext(); | |
173 reply_context.params.set_result(PP_ERROR_FAILED); | |
174 host()->SendReply(reply_context, | |
175 PpapiPluginMsg_FileIO_ReadComplete(std::string())); | |
176 return PP_OK_COMPLETIONPENDING; | |
177 } | |
178 | |
179 temp_reply_context_ = context->MakeReplyMessageContext(); | |
180 return DoRead(offset, std::min(bytes_to_read, kMaxReadSize)); | |
181 } | |
182 | |
183 int32_t PepperFileIOHost::OnHostMsgWrite( | |
184 ppapi::host::HostMessageContext* context, | |
185 int64_t offset, | |
186 const std::string& buffer) { | |
187 temp_reply_context_ = context->MakeReplyMessageContext(); | |
188 return DoWrite(offset, buffer.c_str(), buffer.size()); | |
189 } | |
190 | |
191 int32_t PepperFileIOHost::OnHostMsgSetLength( | |
192 ppapi::host::HostMessageContext* context, | |
193 int64_t length) { | |
194 temp_reply_context_ = context->MakeReplyMessageContext(); | |
195 return DoSetLength(length); | |
196 } | |
197 | |
198 int32_t PepperFileIOHost::OnHostMsgFlush( | |
199 ppapi::host::HostMessageContext* context) { | |
200 temp_reply_context_ = context->MakeReplyMessageContext(); | |
201 return DoFlush(); | |
202 } | |
203 | |
204 int32_t PepperFileIOHost::OnHostMsgClose( | |
205 ppapi::host::HostMessageContext* context) { | |
206 if (file_ != base::kInvalidPlatformFileValue && plugin_delegate_) { | |
207 base::FileUtilProxy::Close( | |
208 plugin_delegate_->GetFileThreadMessageLoopProxy(), | |
209 file_, | |
210 base::ResetAndReturn(¬ify_close_file_callback_)); | |
211 file_ = base::kInvalidPlatformFileValue; | |
212 quota_file_io_.reset(); | |
213 } | |
214 return PP_OK; | |
215 } | |
216 | |
217 int32_t PepperFileIOHost::OnHostMsgWillWrite( | |
218 ppapi::host::HostMessageContext* context, | |
219 int64_t offset, | |
220 int32_t bytes_to_write) { | |
221 int32_t rv = CommonPreCondition(true, OPERATION_EXCLUSIVE); | |
222 if (rv != PP_OK) | |
223 return rv; | |
224 | |
225 if (!quota_file_io_.get()) | |
226 return PP_OK; | |
227 | |
228 if (!quota_file_io_->WillWrite( | |
229 offset, bytes_to_write, | |
230 base::Bind(&PepperFileIOHost::ExecutePlatformWillWriteCallback, | |
231 weak_factory_.GetWeakPtr(), | |
232 context->MakeReplyMessageContext()))) | |
233 return PP_ERROR_FAILED; | |
234 | |
235 return PP_OK_COMPLETIONPENDING; | |
236 } | |
237 | |
238 int32_t PepperFileIOHost::OnHostMsgWillSetLength( | |
239 ppapi::host::HostMessageContext* context, | |
240 int64_t length) { | |
241 int32_t rv = CommonPreCondition(true, OPERATION_EXCLUSIVE); | |
242 if (rv != PP_OK) | |
243 return rv; | |
244 | |
245 if (!quota_file_io_.get()) | |
246 return PP_OK; | |
247 | |
248 if (!quota_file_io_->WillSetLength( | |
249 length, | |
250 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | |
251 weak_factory_.GetWeakPtr(), | |
252 context->MakeReplyMessageContext()))) | |
253 return PP_ERROR_FAILED; | |
254 | |
255 return PP_OK_COMPLETIONPENDING; | |
256 } | |
257 | |
258 int32_t PepperFileIOHost::OnHostMsgGetOSFileDescriptor( | |
259 ppapi::host::HostMessageContext* context) { | |
260 //if (!host()->IsRunningInProcess()) | |
victorhsieh
2012/11/27 09:44:42
Once https://codereview.chromium.org/11414171/ is
raymes
2012/11/27 16:41:30
You can also rebase on that CL to remove the comme
| |
261 // return PP_ERROR_FAILED; | |
262 int32_t fd = | |
263 #if defined(OS_POSIX) | |
264 file_; | |
265 #elif defined(OS_WIN) | |
266 reinterpret_cast<uintptr_t>(file_); | |
victorhsieh
2012/11/27 09:44:42
Sending this pointer through IPC looks weird, mayb
raymes
2012/11/27 16:41:30
I agree - sending the raw file descriptor looks ba
victorhsieh
2012/11/28 04:11:55
Left a TODO per discussion.
| |
267 #else | |
268 -1; // Platform not supported. | |
269 #endif | |
270 host()->SendReply(context->MakeReplyMessageContext(), | |
271 PpapiPluginMsg_FileIO_GetOSFileDescriptorReply(fd)); | |
272 return PP_OK_COMPLETIONPENDING; | |
273 } | |
274 | |
275 int32_t PepperFileIOHost::CommonPreCondition(bool should_be_open, | |
276 OperationType new_op) { | |
277 if (!plugin_delegate_ || !CheckOpenState(should_be_open)) | |
278 return PP_ERROR_FAILED; | |
279 return PP_OK; | |
280 } | |
281 | |
282 void PepperFileIOHost::CommonPostCondition(OperationType new_op) { | |
283 } | |
284 | |
285 int32_t PepperFileIOHost::OpenValidated( | |
286 PP_Resource file_ref_resource, | |
287 PPB_FileRef_API* file_ref_api, | |
288 int32_t open_flags) { | |
289 int flags = 0; | |
290 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, &flags)) | |
291 return PP_ERROR_BADARGUMENT; | |
292 | |
293 PP_FileSystemType type = file_ref_api->GetFileSystemType(); | |
294 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && | |
295 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && | |
296 type != PP_FILESYSTEMTYPE_EXTERNAL) | |
297 return PP_ERROR_FAILED; | |
298 file_system_type_ = type; | |
299 | |
300 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); | |
301 if (file_ref->HasValidFileSystem()) { | |
302 file_system_url_ = file_ref->GetFileSystemURL(); | |
303 if (!plugin_delegate_->AsyncOpenFileSystemURL( | |
304 file_system_url_, flags, | |
305 base::Bind( | |
306 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, | |
307 weak_factory_.GetWeakPtr(), | |
308 temp_reply_context_))) | |
309 return PP_ERROR_FAILED; | |
310 } else { | |
311 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) | |
312 return PP_ERROR_FAILED; | |
313 if (!plugin_delegate_->AsyncOpenFile( | |
314 file_ref->GetSystemPath(), flags, | |
315 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, | |
316 weak_factory_.GetWeakPtr(), | |
317 temp_reply_context_))) | |
318 return PP_ERROR_FAILED; | |
319 } | |
320 | |
321 return PP_OK_COMPLETIONPENDING; | |
322 } | |
323 | |
324 int32_t PepperFileIOHost::QueryValidated() { | |
325 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | |
326 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, | |
327 base::Bind(&PepperFileIOHost::ExecutePlatformQueryCallback, | |
328 weak_factory_.GetWeakPtr(), | |
329 temp_reply_context_))) | |
330 return PP_ERROR_FAILED; | |
331 | |
332 return PP_OK_COMPLETIONPENDING; | |
333 } | |
334 | |
335 int32_t PepperFileIOHost::TouchValidated( | |
336 PP_Time last_access_time, | |
337 PP_Time last_modified_time) { | |
338 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) { | |
339 if (!plugin_delegate_->Touch( | |
340 file_system_url_, | |
341 PPTimeToTime(last_access_time), | |
342 PPTimeToTime(last_modified_time), | |
343 new PlatformGeneralCallbackTranslator( | |
344 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | |
345 weak_factory_.GetWeakPtr(), | |
346 temp_reply_context_)))) | |
347 return PP_ERROR_FAILED; | |
348 return PP_OK_COMPLETIONPENDING; | |
349 } | |
350 | |
351 // TODO(nhiroki): fix a failure of FileIO.Touch for an external filesystem on | |
352 // Mac and Linux due to sandbox restrictions (http://crbug.com/101128). | |
353 if (!base::FileUtilProxy::Touch( | |
354 plugin_delegate_->GetFileThreadMessageLoopProxy(), | |
355 file_, PPTimeToTime(last_access_time), | |
356 PPTimeToTime(last_modified_time), | |
357 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | |
358 weak_factory_.GetWeakPtr(), | |
359 temp_reply_context_))) | |
360 return PP_ERROR_FAILED; | |
361 | |
362 return PP_OK_COMPLETIONPENDING; | |
363 } | |
364 | |
365 int32_t PepperFileIOHost::ReadValidated( | |
366 int64_t offset, | |
367 int32_t max_read_length) { | |
368 if (!base::FileUtilProxy::Read( | |
369 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, offset, | |
370 max_read_length, | |
371 base::Bind(&PepperFileIOHost::ExecutePlatformReadCallback, | |
372 weak_factory_.GetWeakPtr(), | |
373 temp_reply_context_))) | |
374 return PP_ERROR_FAILED; | |
375 | |
376 return PP_OK_COMPLETIONPENDING; | |
377 } | |
378 | |
379 int32_t PepperFileIOHost::WriteValidated( | |
380 int64_t offset, | |
381 const char* buffer, | |
382 int32_t bytes_to_write) { | |
383 if (quota_file_io_.get()) { | |
384 if (!quota_file_io_->Write( | |
385 offset, buffer, bytes_to_write, | |
386 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback, | |
387 weak_factory_.GetWeakPtr(), | |
388 temp_reply_context_))) | |
389 return PP_ERROR_FAILED; | |
390 } else { | |
391 if (!base::FileUtilProxy::Write( | |
392 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, offset, | |
393 buffer, bytes_to_write, | |
394 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback, | |
395 weak_factory_.GetWeakPtr(), | |
396 temp_reply_context_))) | |
397 return PP_ERROR_FAILED; | |
398 } | |
399 | |
400 return PP_OK_COMPLETIONPENDING; | |
401 } | |
402 | |
403 int32_t PepperFileIOHost::SetLengthValidated( | |
404 int64_t length) { | |
405 if (quota_file_io_.get()) { | |
406 if (!quota_file_io_->SetLength( | |
407 length, | |
408 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | |
409 weak_factory_.GetWeakPtr(), | |
410 temp_reply_context_))) | |
411 return PP_ERROR_FAILED; | |
412 } else { | |
413 if (!base::FileUtilProxy::Truncate( | |
414 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, length, | |
415 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | |
416 weak_factory_.GetWeakPtr(), | |
417 temp_reply_context_))) | |
418 return PP_ERROR_FAILED; | |
419 } | |
420 | |
421 return PP_OK_COMPLETIONPENDING; | |
422 } | |
423 | |
424 int32_t PepperFileIOHost::FlushValidated() { | |
425 if (!base::FileUtilProxy::Flush( | |
426 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, | |
427 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | |
428 weak_factory_.GetWeakPtr(), | |
429 temp_reply_context_))) | |
430 return PP_ERROR_FAILED; | |
431 | |
432 return PP_OK_COMPLETIONPENDING; | |
433 } | |
434 | |
435 void PepperFileIOHost::ExecutePlatformGeneralCallback( | |
436 ppapi::host::ReplyMessageContext reply_context, | |
437 base::PlatformFileError error_code) { | |
438 reply_context.params.set_result( | |
439 ::ppapi::PlatformFileErrorToPepperError(error_code)); | |
440 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralComplete()); | |
441 } | |
442 | |
443 void PepperFileIOHost::ExecutePlatformOpenFileCallback( | |
444 ppapi::host::ReplyMessageContext reply_context, | |
445 base::PlatformFileError error_code, | |
446 base::PassPlatformFile file) { | |
447 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
448 if (pp_error == PP_OK) | |
449 SetOpenSucceed(); | |
450 | |
451 DCHECK(file_ == base::kInvalidPlatformFileValue); | |
452 file_ = file.ReleaseValue(); | |
453 | |
454 DCHECK(!quota_file_io_.get()); | |
455 if (file_ != base::kInvalidPlatformFileValue && | |
456 (file_system_type_ == PP_FILESYSTEMTYPE_LOCALTEMPORARY || | |
457 file_system_type_ == PP_FILESYSTEMTYPE_LOCALPERSISTENT)) { | |
458 quota_file_io_.reset(new webkit::ppapi::QuotaFileIO( | |
459 pp_instance(), file_, file_system_url_, file_system_type_)); | |
460 } | |
461 | |
462 reply_context.params.set_result(pp_error); | |
463 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_OpenFileComplete()); | |
464 } | |
465 | |
466 void PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback( | |
467 ppapi::host::ReplyMessageContext reply_context, | |
468 base::PlatformFileError error_code, | |
469 base::PassPlatformFile file, | |
470 const PluginDelegate::NotifyCloseFileCallback& callback) { | |
471 if (error_code == base::PLATFORM_FILE_OK) | |
472 notify_close_file_callback_ = callback; | |
473 ExecutePlatformOpenFileCallback(reply_context, error_code, file); | |
474 } | |
475 | |
476 void PepperFileIOHost::ExecutePlatformQueryCallback( | |
477 ppapi::host::ReplyMessageContext reply_context, | |
478 base::PlatformFileError error_code, | |
479 const base::PlatformFileInfo& file_info) { | |
480 PP_FileInfo pp_info; | |
481 pp_info.size = file_info.size; | |
482 pp_info.creation_time = TimeToPPTime(file_info.creation_time); | |
483 pp_info.last_access_time = TimeToPPTime(file_info.last_accessed); | |
484 pp_info.last_modified_time = TimeToPPTime(file_info.last_modified); | |
485 pp_info.system_type = file_system_type_; | |
486 if (file_info.is_directory) | |
487 pp_info.type = PP_FILETYPE_DIRECTORY; | |
488 else | |
489 pp_info.type = PP_FILETYPE_REGULAR; | |
490 | |
491 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
492 reply_context.params.set_result(pp_error); | |
493 host()->SendReply(reply_context, | |
494 PpapiPluginMsg_FileIO_QueryComplete(pp_info)); | |
495 } | |
496 | |
497 void PepperFileIOHost::ExecutePlatformReadCallback( | |
498 ppapi::host::ReplyMessageContext reply_context, | |
499 base::PlatformFileError error_code, | |
500 const char* data, int bytes_read) { | |
501 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
502 | |
503 // Only send the amount of data in the string that was actually read. | |
504 std::string buffer; | |
505 if (pp_error == PP_OK) | |
506 buffer.append(data, bytes_read); | |
507 // On the plugin side, the callback expects a parameter with different meaning | |
508 // depends on whether is negative or not. It is the result here. We | |
509 // translate for the callback. | |
510 reply_context.params.set_result(pp_error == PP_OK ? bytes_read : pp_error); | |
511 host()->SendReply(reply_context, | |
512 PpapiPluginMsg_FileIO_ReadComplete(buffer)); | |
513 } | |
514 | |
515 void PepperFileIOHost::ExecutePlatformWriteCallback( | |
516 ppapi::host::ReplyMessageContext reply_context, | |
517 base::PlatformFileError error_code, | |
518 int bytes_written) { | |
519 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
520 // On the plugin side, the callback expects a parameter with different meaning | |
521 // depends on whether is negative or not. It is the result here. We | |
522 // translate for the callback. | |
523 reply_context.params.set_result(pp_error == PP_OK ? bytes_written : pp_error); | |
524 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralComplete()); | |
525 } | |
526 | |
527 void PepperFileIOHost::ExecutePlatformWillWriteCallback( | |
528 ppapi::host::ReplyMessageContext reply_context, | |
529 base::PlatformFileError error_code, | |
530 int bytes_written) { | |
531 // On the plugin side, the callback expects a parameter with different meaning | |
532 // depends on whether is negative or not. It is the result here. We | |
533 // translate for the callback. | |
534 if (error_code != base::PLATFORM_FILE_OK) | |
535 reply_context.params.set_result( | |
536 ::ppapi::PlatformFileErrorToPepperError(error_code)); | |
537 else | |
538 reply_context.params.set_result(bytes_written); | |
539 host()->SendReply(reply_context, | |
540 PpapiPluginMsg_FileIO_GeneralComplete()); | |
541 } | |
542 | |
543 } // namespace content | |
OLD | NEW |