| 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 "webkit/plugins/ppapi/ppb_file_system_impl.h" | |
| 6 | |
| 7 #include "base/memory/ref_counted.h" | |
| 8 #include "ppapi/c/pp_completion_callback.h" | |
| 9 #include "ppapi/c/ppb_file_system.h" | |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | |
| 14 #include "webkit/fileapi/file_system_types.h" | |
| 15 #include "webkit/plugins/ppapi/common.h" | |
| 16 #include "webkit/plugins/ppapi/file_callbacks.h" | |
| 17 #include "webkit/plugins/ppapi/plugin_delegate.h" | |
| 18 #include "webkit/plugins/ppapi/plugin_module.h" | |
| 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | |
| 20 #include "webkit/plugins/ppapi/resource_helper.h" | |
| 21 | |
| 22 using ppapi::thunk::PPB_FileSystem_API; | |
| 23 using ppapi::TrackedCallback; | |
| 24 | |
| 25 namespace webkit { | |
| 26 namespace ppapi { | |
| 27 | |
| 28 PPB_FileSystem_Impl::PPB_FileSystem_Impl(PP_Instance instance, | |
| 29 PP_FileSystemType type) | |
| 30 : Resource(::ppapi::OBJECT_IS_IMPL, instance), | |
| 31 type_(type), | |
| 32 opened_(false), | |
| 33 called_open_(false) { | |
| 34 DCHECK(type_ != PP_FILESYSTEMTYPE_INVALID); | |
| 35 } | |
| 36 | |
| 37 PPB_FileSystem_Impl::~PPB_FileSystem_Impl() { | |
| 38 } | |
| 39 | |
| 40 // static | |
| 41 PP_Resource PPB_FileSystem_Impl::Create(PP_Instance instance, | |
| 42 PP_FileSystemType type) { | |
| 43 if (type != PP_FILESYSTEMTYPE_EXTERNAL && | |
| 44 type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && | |
| 45 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY) | |
| 46 return 0; | |
| 47 return (new PPB_FileSystem_Impl(instance, type))->GetReference(); | |
| 48 } | |
| 49 | |
| 50 PPB_FileSystem_API* PPB_FileSystem_Impl::AsPPB_FileSystem_API() { | |
| 51 return this; | |
| 52 } | |
| 53 | |
| 54 int32_t PPB_FileSystem_Impl::Open(int64_t expected_size, | |
| 55 scoped_refptr<TrackedCallback> callback) { | |
| 56 // Should not allow multiple opens. | |
| 57 if (called_open_) | |
| 58 return PP_ERROR_INPROGRESS; | |
| 59 called_open_ = true; | |
| 60 | |
| 61 fileapi::FileSystemType file_system_type; | |
| 62 switch (type_) { | |
| 63 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: | |
| 64 file_system_type = fileapi::kFileSystemTypeTemporary; | |
| 65 break; | |
| 66 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: | |
| 67 file_system_type = fileapi::kFileSystemTypePersistent; | |
| 68 break; | |
| 69 case PP_FILESYSTEMTYPE_EXTERNAL: | |
| 70 file_system_type = fileapi::kFileSystemTypeExternal; | |
| 71 break; | |
| 72 default: | |
| 73 return PP_ERROR_FAILED; | |
| 74 } | |
| 75 | |
| 76 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | |
| 77 if (!plugin_instance) | |
| 78 return PP_ERROR_FAILED; | |
| 79 | |
| 80 if (!plugin_instance->delegate()->OpenFileSystem( | |
| 81 GURL(plugin_instance->container()->element().document().url()). | |
| 82 GetOrigin(), | |
| 83 file_system_type, expected_size, | |
| 84 new FileCallbacks(this, callback, NULL, | |
| 85 scoped_refptr<PPB_FileSystem_Impl>(this)))) | |
| 86 return PP_ERROR_FAILED; | |
| 87 return PP_OK_COMPLETIONPENDING; | |
| 88 } | |
| 89 | |
| 90 PP_FileSystemType PPB_FileSystem_Impl::GetType() { | |
| 91 return type_; | |
| 92 } | |
| 93 | |
| 94 } // namespace ppapi | |
| 95 } // namespace webkit | |
| OLD | NEW |