Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: webkit/plugins/ppapi/ppb_flash_impl.cc

Issue 11359097: Refactored the PPB_Flash_File_ModuleLocal/FileRef to the new ppapi resource model (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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" 11 #include "base/time.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
14 #include "ppapi/c/dev/ppb_font_dev.h" 14 #include "ppapi/c/dev/ppb_font_dev.h"
15 #include "ppapi/c/private/ppb_flash.h" 15 #include "ppapi/c/private/ppb_flash.h"
16 #include "ppapi/shared_impl/file_path.h" 16 #include "ppapi/shared_impl/file_path.h"
yzshen1 2012/11/21 00:38:59 Quite a few includes and using's are not needed. p
raymes 2012/11/21 22:44:53 Done.
17 #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" 18 #include "ppapi/shared_impl/time_conversion.h"
19 #include "ppapi/shared_impl/var.h" 19 #include "ppapi/shared_impl/var.h"
20 #include "ppapi/thunk/enter.h" 20 #include "ppapi/thunk/enter.h"
21 #include "ppapi/thunk/ppb_file_ref_api.h" 21 #include "ppapi/thunk/ppb_file_ref_api.h"
22 #include "ppapi/thunk/ppb_image_data_api.h" 22 #include "ppapi/thunk/ppb_image_data_api.h"
23 #include "ppapi/thunk/ppb_url_request_info_api.h" 23 #include "ppapi/thunk/ppb_url_request_info_api.h"
24 #include "skia/ext/platform_canvas.h" 24 #include "skia/ext/platform_canvas.h"
25 #include "third_party/skia/include/core/SkCanvas.h" 25 #include "third_party/skia/include/core/SkCanvas.h"
26 #include "third_party/skia/include/core/SkMatrix.h" 26 #include "third_party/skia/include/core/SkMatrix.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 251 }
252 } 252 }
253 253
254 PP_Bool PPB_Flash_Impl::SetCrashData(PP_Instance instance, 254 PP_Bool PPB_Flash_Impl::SetCrashData(PP_Instance instance,
255 PP_FlashCrashKey key, 255 PP_FlashCrashKey key,
256 PP_Var value) { 256 PP_Var value) {
257 // Not implemented in process. 257 // Not implemented in process.
258 return PP_FALSE; 258 return PP_FALSE;
259 } 259 }
260 260
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) { 261 PP_Bool PPB_Flash_Impl::FlashIsFullscreen(PP_Instance instance) {
482 return PP_FromBool(instance_->flash_fullscreen()); 262 return PP_FromBool(instance_->flash_fullscreen());
483 } 263 }
484 264
485 PP_Bool PPB_Flash_Impl::FlashSetFullscreen(PP_Instance instance, 265 PP_Bool PPB_Flash_Impl::FlashSetFullscreen(PP_Instance instance,
486 PP_Bool fullscreen) { 266 PP_Bool fullscreen) {
487 instance_->FlashSetFullscreen(PP_ToBool(fullscreen), true); 267 instance_->FlashSetFullscreen(PP_ToBool(fullscreen), true);
488 return PP_TRUE; 268 return PP_TRUE;
489 } 269 }
490 270
491 PP_Bool PPB_Flash_Impl::FlashGetScreenSize(PP_Instance instance, 271 PP_Bool PPB_Flash_Impl::FlashGetScreenSize(PP_Instance instance,
492 PP_Size* size) { 272 PP_Size* size) {
493 return instance_->GetScreenSize(instance, size); 273 return instance_->GetScreenSize(instance, size);
494 } 274 }
495 275
496 } // namespace ppapi 276 } // namespace ppapi
497 } // namespace webkit 277 } // namespace webkit
OLDNEW
« webkit/plugins/ppapi/plugin_delegate.h ('K') | « webkit/plugins/ppapi/ppb_flash_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698