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 "webkit/plugins/ppapi/ppb_flash_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_flash_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/time.h" | |
12 #include "base/utf_string_conversions.h" | |
13 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
14 #include "ppapi/c/dev/ppb_font_dev.h" | 12 #include "ppapi/c/dev/ppb_font_dev.h" |
15 #include "ppapi/c/private/ppb_flash.h" | 13 #include "ppapi/c/private/ppb_flash.h" |
16 #include "ppapi/shared_impl/file_path.h" | |
17 #include "ppapi/shared_impl/file_type_conversion.h" | |
18 #include "ppapi/shared_impl/time_conversion.h" | 14 #include "ppapi/shared_impl/time_conversion.h" |
19 #include "ppapi/shared_impl/var.h" | 15 #include "ppapi/shared_impl/var.h" |
20 #include "ppapi/thunk/enter.h" | 16 #include "ppapi/thunk/enter.h" |
21 #include "ppapi/thunk/ppb_file_ref_api.h" | |
22 #include "ppapi/thunk/ppb_image_data_api.h" | 17 #include "ppapi/thunk/ppb_image_data_api.h" |
23 #include "ppapi/thunk/ppb_url_request_info_api.h" | 18 #include "ppapi/thunk/ppb_url_request_info_api.h" |
24 #include "skia/ext/platform_canvas.h" | 19 #include "skia/ext/platform_canvas.h" |
25 #include "third_party/skia/include/core/SkCanvas.h" | 20 #include "third_party/skia/include/core/SkCanvas.h" |
26 #include "third_party/skia/include/core/SkMatrix.h" | 21 #include "third_party/skia/include/core/SkMatrix.h" |
27 #include "third_party/skia/include/core/SkPaint.h" | 22 #include "third_party/skia/include/core/SkPaint.h" |
28 #include "third_party/skia/include/core/SkPoint.h" | 23 #include "third_party/skia/include/core/SkPoint.h" |
29 #include "third_party/skia/include/core/SkTemplates.h" | 24 #include "third_party/skia/include/core/SkTemplates.h" |
30 #include "third_party/skia/include/core/SkTypeface.h" | 25 #include "third_party/skia/include/core/SkTypeface.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
34 #include "ui/gfx/rect.h" | 29 #include "ui/gfx/rect.h" |
35 #include "webkit/plugins/ppapi/common.h" | 30 #include "webkit/plugins/ppapi/common.h" |
36 #include "webkit/plugins/ppapi/host_globals.h" | 31 #include "webkit/plugins/ppapi/host_globals.h" |
37 #include "webkit/plugins/ppapi/plugin_delegate.h" | 32 #include "webkit/plugins/ppapi/plugin_delegate.h" |
38 #include "webkit/plugins/ppapi/plugin_module.h" | 33 #include "webkit/plugins/ppapi/plugin_module.h" |
39 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 34 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
40 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | |
41 #include "webkit/plugins/ppapi/resource_helper.h" | 35 #include "webkit/plugins/ppapi/resource_helper.h" |
42 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 36 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
43 | 37 |
44 using ppapi::PPTimeToTime; | 38 using ppapi::PPTimeToTime; |
45 using ppapi::StringVar; | 39 using ppapi::StringVar; |
46 using ppapi::TimeToPPTime; | |
47 using ppapi::thunk::EnterResource; | |
48 using ppapi::thunk::EnterResourceNoLock; | 40 using ppapi::thunk::EnterResourceNoLock; |
49 using ppapi::thunk::PPB_FileRef_API; | |
50 using ppapi::thunk::PPB_ImageData_API; | 41 using ppapi::thunk::PPB_ImageData_API; |
51 using ppapi::thunk::PPB_URLRequestInfo_API; | 42 using ppapi::thunk::PPB_URLRequestInfo_API; |
52 | 43 |
53 namespace webkit { | 44 namespace webkit { |
54 namespace ppapi { | 45 namespace ppapi { |
55 | 46 |
56 PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance) | 47 PPB_Flash_Impl::PPB_Flash_Impl(PluginInstance* instance) |
57 : instance_(instance) { | 48 : instance_(instance) { |
58 } | 49 } |
59 | 50 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 242 } |
252 } | 243 } |
253 | 244 |
254 PP_Bool PPB_Flash_Impl::SetCrashData(PP_Instance instance, | 245 PP_Bool PPB_Flash_Impl::SetCrashData(PP_Instance instance, |
255 PP_FlashCrashKey key, | 246 PP_FlashCrashKey key, |
256 PP_Var value) { | 247 PP_Var value) { |
257 // Not implemented in process. | 248 // Not implemented in process. |
258 return PP_FALSE; | 249 return PP_FALSE; |
259 } | 250 } |
260 | 251 |
261 bool PPB_Flash_Impl::CreateThreadAdapterForInstance(PP_Instance instance) { | |
262 return false; // No multithreaded access allowed. | |
263 } | |
264 | |
265 void PPB_Flash_Impl::ClearThreadAdapterForInstance(PP_Instance instance) { | |
266 } | |
267 | |
268 int32_t PPB_Flash_Impl::OpenFile(PP_Instance pp_instance, | |
269 const char* path, | |
270 int32_t mode, | |
271 PP_FileHandle* file) { | |
272 int flags = 0; | |
273 if (!path || | |
274 !::ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || | |
275 !file) | |
276 return PP_ERROR_BADARGUMENT; | |
277 | |
278 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
279 if (!instance) | |
280 return PP_ERROR_FAILED; | |
281 | |
282 base::PlatformFile base_file; | |
283 base::PlatformFileError result = instance->delegate()->OpenFile( | |
284 ::ppapi::PepperFilePath::MakeModuleLocal( | |
285 instance->module()->name(), path), | |
286 flags, | |
287 &base_file); | |
288 *file = base_file; | |
289 return ::ppapi::PlatformFileErrorToPepperError(result); | |
290 } | |
291 | |
292 int32_t PPB_Flash_Impl::RenameFile(PP_Instance pp_instance, | |
293 const char* path_from, | |
294 const char* path_to) { | |
295 if (!path_from || !path_to) | |
296 return PP_ERROR_BADARGUMENT; | |
297 | |
298 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
299 if (!instance) | |
300 return PP_ERROR_FAILED; | |
301 | |
302 base::PlatformFileError result = instance->delegate()->RenameFile( | |
303 ::ppapi::PepperFilePath::MakeModuleLocal( | |
304 instance->module()->name(), path_from), | |
305 ::ppapi::PepperFilePath::MakeModuleLocal( | |
306 instance->module()->name(), path_to)); | |
307 return ::ppapi::PlatformFileErrorToPepperError(result); | |
308 } | |
309 | |
310 int32_t PPB_Flash_Impl::DeleteFileOrDir(PP_Instance pp_instance, | |
311 const char* path, | |
312 PP_Bool recursive) { | |
313 if (!path) | |
314 return PP_ERROR_BADARGUMENT; | |
315 | |
316 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
317 if (!instance) | |
318 return PP_ERROR_FAILED; | |
319 | |
320 base::PlatformFileError result = instance->delegate()->DeleteFileOrDir( | |
321 ::ppapi::PepperFilePath::MakeModuleLocal( | |
322 instance->module()->name(), path), | |
323 PPBoolToBool(recursive)); | |
324 return ::ppapi::PlatformFileErrorToPepperError(result); | |
325 } | |
326 | |
327 int32_t PPB_Flash_Impl::CreateDir(PP_Instance pp_instance, const char* path) { | |
328 if (!path) | |
329 return PP_ERROR_BADARGUMENT; | |
330 | |
331 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
332 if (!instance) | |
333 return PP_ERROR_FAILED; | |
334 | |
335 base::PlatformFileError result = instance->delegate()->CreateDir( | |
336 ::ppapi::PepperFilePath::MakeModuleLocal( | |
337 instance->module()->name(), path)); | |
338 return ::ppapi::PlatformFileErrorToPepperError(result); | |
339 } | |
340 | |
341 int32_t PPB_Flash_Impl::QueryFile(PP_Instance pp_instance, | |
342 const char* path, | |
343 PP_FileInfo* info) { | |
344 if (!path || !info) | |
345 return PP_ERROR_BADARGUMENT; | |
346 | |
347 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
348 if (!instance) | |
349 return PP_ERROR_FAILED; | |
350 | |
351 base::PlatformFileInfo file_info; | |
352 base::PlatformFileError result = instance->delegate()->QueryFile( | |
353 ::ppapi::PepperFilePath::MakeModuleLocal( | |
354 instance->module()->name(), path), | |
355 &file_info); | |
356 if (result == base::PLATFORM_FILE_OK) { | |
357 info->size = file_info.size; | |
358 info->creation_time = TimeToPPTime(file_info.creation_time); | |
359 info->last_access_time = TimeToPPTime(file_info.last_accessed); | |
360 info->last_modified_time = TimeToPPTime(file_info.last_modified); | |
361 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | |
362 if (file_info.is_directory) | |
363 info->type = PP_FILETYPE_DIRECTORY; | |
364 else | |
365 info->type = PP_FILETYPE_REGULAR; | |
366 } | |
367 return ::ppapi::PlatformFileErrorToPepperError(result); | |
368 } | |
369 | |
370 int32_t PPB_Flash_Impl::GetDirContents(PP_Instance pp_instance, | |
371 const char* path, | |
372 PP_DirContents_Dev** contents) { | |
373 if (!path || !contents) | |
374 return PP_ERROR_BADARGUMENT; | |
375 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
376 if (!instance) | |
377 return PP_ERROR_FAILED; | |
378 | |
379 *contents = NULL; | |
380 ::ppapi::DirContents pepper_contents; | |
381 base::PlatformFileError result = instance->delegate()->GetDirContents( | |
382 ::ppapi::PepperFilePath::MakeModuleLocal( | |
383 instance->module()->name(), path), | |
384 &pepper_contents); | |
385 | |
386 if (result != base::PLATFORM_FILE_OK) | |
387 return ::ppapi::PlatformFileErrorToPepperError(result); | |
388 | |
389 *contents = new PP_DirContents_Dev; | |
390 size_t count = pepper_contents.size(); | |
391 (*contents)->count = count; | |
392 (*contents)->entries = new PP_DirEntry_Dev[count]; | |
393 for (size_t i = 0; i < count; ++i) { | |
394 PP_DirEntry_Dev& entry = (*contents)->entries[i]; | |
395 #if defined(OS_WIN) | |
396 const std::string& name = UTF16ToUTF8(pepper_contents[i].name.value()); | |
397 #else | |
398 const std::string& name = pepper_contents[i].name.value(); | |
399 #endif | |
400 size_t size = name.size() + 1; | |
401 char* name_copy = new char[size]; | |
402 memcpy(name_copy, name.c_str(), size); | |
403 entry.name = name_copy; | |
404 entry.is_dir = BoolToPPBool(pepper_contents[i].is_dir); | |
405 } | |
406 return PP_OK; | |
407 } | |
408 | |
409 int32_t PPB_Flash_Impl::CreateTemporaryFile(PP_Instance instance, | |
410 PP_FileHandle* file) { | |
411 if (!file) | |
412 return PP_ERROR_BADARGUMENT; | |
413 | |
414 PluginInstance* plugin_instance = HostGlobals::Get()->GetInstance(instance); | |
415 if (!plugin_instance) { | |
416 *file = PP_kInvalidFileHandle; | |
417 return PP_ERROR_FAILED; | |
418 } | |
419 | |
420 base::PlatformFileError result = | |
421 plugin_instance->delegate()->CreateTemporaryFile(file); | |
422 return ::ppapi::PlatformFileErrorToPepperError(result); | |
423 } | |
424 | |
425 int32_t PPB_Flash_Impl::OpenFileRef(PP_Instance pp_instance, | |
426 PP_Resource file_ref_id, | |
427 int32_t mode, | |
428 PP_FileHandle* file) { | |
429 int flags = 0; | |
430 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) || !file) | |
431 return PP_ERROR_BADARGUMENT; | |
432 | |
433 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref_id, true); | |
434 if (enter.failed()) | |
435 return PP_ERROR_BADRESOURCE; | |
436 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); | |
437 | |
438 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
439 if (!instance) | |
440 return PP_ERROR_FAILED; | |
441 | |
442 base::PlatformFile base_file; | |
443 base::PlatformFileError result = instance->delegate()->OpenFile( | |
444 ::ppapi::PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), | |
445 flags, | |
446 &base_file); | |
447 *file = base_file; | |
448 return ::ppapi::PlatformFileErrorToPepperError(result); | |
449 } | |
450 | |
451 int32_t PPB_Flash_Impl::QueryFileRef(PP_Instance pp_instance, | |
452 PP_Resource file_ref_id, | |
453 PP_FileInfo* info) { | |
454 EnterResource<PPB_FileRef_API> enter(file_ref_id, true); | |
455 if (enter.failed()) | |
456 return PP_ERROR_BADRESOURCE; | |
457 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(enter.object()); | |
458 | |
459 PluginInstance* instance = HostGlobals::Get()->GetInstance(pp_instance); | |
460 if (!instance) | |
461 return PP_ERROR_FAILED; | |
462 | |
463 base::PlatformFileInfo file_info; | |
464 base::PlatformFileError result = instance->delegate()->QueryFile( | |
465 ::ppapi::PepperFilePath::MakeAbsolute(file_ref->GetSystemPath()), | |
466 &file_info); | |
467 if (result == base::PLATFORM_FILE_OK) { | |
468 info->size = file_info.size; | |
469 info->creation_time = TimeToPPTime(file_info.creation_time); | |
470 info->last_access_time = TimeToPPTime(file_info.last_accessed); | |
471 info->last_modified_time = TimeToPPTime(file_info.last_modified); | |
472 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | |
473 if (file_info.is_directory) | |
474 info->type = PP_FILETYPE_DIRECTORY; | |
475 else | |
476 info->type = PP_FILETYPE_REGULAR; | |
477 } | |
478 return ::ppapi::PlatformFileErrorToPepperError(result); | |
479 } | |
480 | |
481 PP_Bool PPB_Flash_Impl::FlashIsFullscreen(PP_Instance instance) { | 252 PP_Bool PPB_Flash_Impl::FlashIsFullscreen(PP_Instance instance) { |
482 return PP_FromBool(instance_->flash_fullscreen()); | 253 return PP_FromBool(instance_->flash_fullscreen()); |
483 } | 254 } |
484 | 255 |
485 PP_Bool PPB_Flash_Impl::FlashSetFullscreen(PP_Instance instance, | 256 PP_Bool PPB_Flash_Impl::FlashSetFullscreen(PP_Instance instance, |
486 PP_Bool fullscreen) { | 257 PP_Bool fullscreen) { |
487 instance_->FlashSetFullscreen(PP_ToBool(fullscreen), true); | 258 instance_->FlashSetFullscreen(PP_ToBool(fullscreen), true); |
488 return PP_TRUE; | 259 return PP_TRUE; |
489 } | 260 } |
490 | 261 |
491 PP_Bool PPB_Flash_Impl::FlashGetScreenSize(PP_Instance instance, | 262 PP_Bool PPB_Flash_Impl::FlashGetScreenSize(PP_Instance instance, |
492 PP_Size* size) { | 263 PP_Size* size) { |
493 return instance_->GetScreenSize(instance, size); | 264 return instance_->GetScreenSize(instance, size); |
494 } | 265 } |
495 | 266 |
496 } // namespace ppapi | 267 } // namespace ppapi |
497 } // namespace webkit | 268 } // namespace webkit |
OLD | NEW |