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.
5 #include "webkit/plugins/ppapi/ppb_file_system_impl.h"
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"
22 using ppapi::thunk::PPB_FileSystem_API
;
23 using ppapi::TrackedCallback
;
28 PPB_FileSystem_Impl::PPB_FileSystem_Impl(PP_Instance instance
,
29 PP_FileSystemType type
)
30 : Resource(::ppapi::OBJECT_IS_IMPL
, instance
),
34 DCHECK(type_
!= PP_FILESYSTEMTYPE_INVALID
);
37 PPB_FileSystem_Impl::~PPB_FileSystem_Impl() {
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
)
47 return (new PPB_FileSystem_Impl(instance
, type
))->GetReference();
50 PPB_FileSystem_API
* PPB_FileSystem_Impl::AsPPB_FileSystem_API() {
54 int32_t PPB_FileSystem_Impl::Open(int64_t expected_size
,
55 scoped_refptr
<TrackedCallback
> callback
) {
56 // Should not allow multiple opens.
58 return PP_ERROR_INPROGRESS
;
61 fileapi::FileSystemType file_system_type
;
63 case PP_FILESYSTEMTYPE_LOCALTEMPORARY
:
64 file_system_type
= fileapi::kFileSystemTypeTemporary
;
66 case PP_FILESYSTEMTYPE_LOCALPERSISTENT
:
67 file_system_type
= fileapi::kFileSystemTypePersistent
;
69 case PP_FILESYSTEMTYPE_EXTERNAL
:
70 file_system_type
= fileapi::kFileSystemTypeExternal
;
73 return PP_ERROR_FAILED
;
76 PluginInstance
* plugin_instance
= ResourceHelper::GetPluginInstance(this);
78 return PP_ERROR_FAILED
;
80 if (!plugin_instance
->delegate()->OpenFileSystem(
81 GURL(plugin_instance
->container()->element().document().url()).
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
;
90 PP_FileSystemType
PPB_FileSystem_Impl::GetType() {