| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_file_system_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "ppapi/c/dev/ppb_file_system_dev.h" | 8 #include "ppapi/c/dev/ppb_file_system_dev.h" |
| 9 #include "ppapi/c/pp_completion_callback.h" | 9 #include "ppapi/c/pp_completion_callback.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 14 #include "webkit/fileapi/file_system_types.h" | 14 #include "webkit/fileapi/file_system_types.h" |
| 15 #include "webkit/plugins/ppapi/common.h" | 15 #include "webkit/plugins/ppapi/common.h" |
| 16 #include "webkit/plugins/ppapi/file_callbacks.h" | 16 #include "webkit/plugins/ppapi/file_callbacks.h" |
| 17 #include "webkit/plugins/ppapi/plugin_delegate.h" | 17 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 18 #include "webkit/plugins/ppapi/plugin_module.h" | 18 #include "webkit/plugins/ppapi/plugin_module.h" |
| 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 20 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" | 20 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" |
| 21 #include "webkit/plugins/ppapi/resource.h" | 21 #include "webkit/plugins/ppapi/resource.h" |
| 22 #include "webkit/plugins/ppapi/resource_tracker.h" | 22 #include "webkit/plugins/ppapi/resource_tracker.h" |
| 23 | 23 |
| 24 using ppapi::thunk::PPB_FileSystem_API; |
| 25 |
| 24 namespace webkit { | 26 namespace webkit { |
| 25 namespace ppapi { | 27 namespace ppapi { |
| 26 | 28 |
| 27 namespace { | 29 PPB_FileSystem_Impl::PPB_FileSystem_Impl(PluginInstance* instance, |
| 30 PP_FileSystemType_Dev type) |
| 31 : Resource(instance), |
| 32 instance_(instance), |
| 33 type_(type), |
| 34 opened_(false), |
| 35 called_open_(false) { |
| 36 DCHECK(type_ != PP_FILESYSTEMTYPE_INVALID); |
| 37 } |
| 28 | 38 |
| 29 PP_Resource Create(PP_Instance instance, PP_FileSystemType_Dev type) { | 39 PPB_FileSystem_Impl::~PPB_FileSystem_Impl() { |
| 40 } |
| 41 |
| 42 // static |
| 43 PP_Resource PPB_FileSystem_Impl::Create(PP_Instance instance, |
| 44 PP_FileSystemType_Dev type) { |
| 30 PluginInstance* plugin_instance = | 45 PluginInstance* plugin_instance = |
| 31 ResourceTracker::Get()->GetInstance(instance); | 46 ResourceTracker::Get()->GetInstance(instance); |
| 32 if (!plugin_instance) | 47 if (!plugin_instance) |
| 33 return 0; | 48 return 0; |
| 34 | 49 |
| 35 if (type != PP_FILESYSTEMTYPE_EXTERNAL && | 50 if (type != PP_FILESYSTEMTYPE_EXTERNAL && |
| 36 type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && | 51 type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && |
| 37 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY) | 52 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY) |
| 38 return 0; | 53 return 0; |
| 39 | 54 |
| 40 PPB_FileSystem_Impl* file_system = | 55 PPB_FileSystem_Impl* file_system = |
| 41 new PPB_FileSystem_Impl(plugin_instance, type); | 56 new PPB_FileSystem_Impl(plugin_instance, type); |
| 42 return file_system->GetReference(); | 57 return file_system->GetReference(); |
| 43 } | 58 } |
| 44 | 59 |
| 45 PP_Bool IsFileSystem(PP_Resource resource) { | 60 PPB_FileSystem_API* PPB_FileSystem_Impl::AsPPB_FileSystem_API() { |
| 46 scoped_refptr<PPB_FileSystem_Impl> file_system( | 61 return this; |
| 47 Resource::GetAs<PPB_FileSystem_Impl>(resource)); | |
| 48 return BoolToPPBool(!!file_system.get()); | |
| 49 } | 62 } |
| 50 | 63 |
| 51 int32_t Open(PP_Resource file_system_id, | 64 int32_t PPB_FileSystem_Impl::Open(int64_t expected_size, |
| 52 int64 expected_size, | 65 PP_CompletionCallback callback) { |
| 53 PP_CompletionCallback callback) { | 66 // Should not allow multiple opens. |
| 54 scoped_refptr<PPB_FileSystem_Impl> file_system( | 67 if (called_open_) |
| 55 Resource::GetAs<PPB_FileSystem_Impl>(file_system_id)); | 68 return PP_ERROR_FAILED; |
| 56 if (!file_system) | 69 called_open_ = true; |
| 57 return PP_ERROR_BADRESOURCE; | |
| 58 | 70 |
| 59 // Should not allow multiple opens. | 71 if (type_ != PP_FILESYSTEMTYPE_LOCALPERSISTENT && |
| 60 if (file_system->called_open()) | 72 type_ != PP_FILESYSTEMTYPE_LOCALTEMPORARY) |
| 61 return PP_ERROR_FAILED; | |
| 62 file_system->set_called_open(); | |
| 63 | |
| 64 if ((file_system->type() != PP_FILESYSTEMTYPE_LOCALPERSISTENT) && | |
| 65 (file_system->type() != PP_FILESYSTEMTYPE_LOCALTEMPORARY)) | |
| 66 return PP_ERROR_FAILED; | 73 return PP_ERROR_FAILED; |
| 67 | 74 |
| 68 PluginInstance* instance = file_system->instance(); | |
| 69 fileapi::FileSystemType file_system_type = | 75 fileapi::FileSystemType file_system_type = |
| 70 (file_system->type() == PP_FILESYSTEMTYPE_LOCALTEMPORARY ? | 76 (type_ == PP_FILESYSTEMTYPE_LOCALTEMPORARY ? |
| 71 fileapi::kFileSystemTypeTemporary : | 77 fileapi::kFileSystemTypeTemporary : |
| 72 fileapi::kFileSystemTypePersistent); | 78 fileapi::kFileSystemTypePersistent); |
| 73 if (!instance->delegate()->OpenFileSystem( | 79 if (!instance()->delegate()->OpenFileSystem( |
| 74 instance->container()->element().document().frame()->url(), | 80 instance()->container()->element().document().frame()->url(), |
| 75 file_system_type, expected_size, | 81 file_system_type, expected_size, |
| 76 new FileCallbacks(instance->module()->AsWeakPtr(), file_system_id, | 82 new FileCallbacks(instance()->module()->AsWeakPtr(), |
| 77 callback, NULL, file_system, NULL))) | 83 GetReferenceNoAddRef(), |
| 84 callback, NULL, |
| 85 scoped_refptr<PPB_FileSystem_Impl>(this), NULL))) |
| 78 return PP_ERROR_FAILED; | 86 return PP_ERROR_FAILED; |
| 79 | |
| 80 return PP_OK_COMPLETIONPENDING; | 87 return PP_OK_COMPLETIONPENDING; |
| 81 } | 88 } |
| 82 | 89 |
| 83 PP_FileSystemType_Dev GetType(PP_Resource resource) { | 90 PP_FileSystemType_Dev PPB_FileSystem_Impl::GetType() { |
| 84 scoped_refptr<PPB_FileSystem_Impl> file_system( | 91 return type_; |
| 85 Resource::GetAs<PPB_FileSystem_Impl>(resource)); | |
| 86 if (!file_system) | |
| 87 return PP_FILESYSTEMTYPE_INVALID; | |
| 88 return file_system->type(); | |
| 89 } | |
| 90 | |
| 91 const PPB_FileSystem_Dev ppb_filesystem = { | |
| 92 &Create, | |
| 93 &IsFileSystem, | |
| 94 &Open, | |
| 95 &GetType | |
| 96 }; | |
| 97 | |
| 98 } // namespace | |
| 99 | |
| 100 PPB_FileSystem_Impl::PPB_FileSystem_Impl(PluginInstance* instance, | |
| 101 PP_FileSystemType_Dev type) | |
| 102 : Resource(instance), | |
| 103 instance_(instance), | |
| 104 type_(type), | |
| 105 opened_(false), | |
| 106 called_open_(false) { | |
| 107 DCHECK(type_ != PP_FILESYSTEMTYPE_INVALID); | |
| 108 } | |
| 109 | |
| 110 PPB_FileSystem_Impl* PPB_FileSystem_Impl::AsPPB_FileSystem_Impl() { | |
| 111 return this; | |
| 112 } | |
| 113 | |
| 114 const PPB_FileSystem_Dev* PPB_FileSystem_Impl::GetInterface() { | |
| 115 return &ppb_filesystem; | |
| 116 } | 92 } |
| 117 | 93 |
| 118 } // namespace ppapi | 94 } // namespace ppapi |
| 119 } // namespace webkit | 95 } // namespace webkit |
| 120 | 96 |
| OLD | NEW |