OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/ref_counted.h" | 7 #include "base/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/file_callbacks.h" | 16 #include "webkit/plugins/ppapi/file_callbacks.h" |
16 #include "webkit/plugins/ppapi/plugin_delegate.h" | 17 #include "webkit/plugins/ppapi/plugin_delegate.h" |
17 #include "webkit/plugins/ppapi/plugin_module.h" | 18 #include "webkit/plugins/ppapi/plugin_module.h" |
18 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
19 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" | 20 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" |
20 #include "webkit/plugins/ppapi/resource.h" | 21 #include "webkit/plugins/ppapi/resource.h" |
21 #include "webkit/plugins/ppapi/resource_tracker.h" | 22 #include "webkit/plugins/ppapi/resource_tracker.h" |
22 | 23 |
23 namespace webkit { | 24 namespace webkit { |
24 namespace ppapi { | 25 namespace ppapi { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 PP_Resource Create(PP_Instance instance, PP_FileSystemType_Dev type) { | 29 PP_Resource Create(PP_Instance instance, PP_FileSystemType_Dev type) { |
29 PluginInstance* plugin_instance = | 30 PluginInstance* plugin_instance = |
30 ResourceTracker::Get()->GetInstance(instance); | 31 ResourceTracker::Get()->GetInstance(instance); |
31 if (!plugin_instance) | 32 if (!plugin_instance) |
32 return 0; | 33 return 0; |
33 | 34 |
35 if (type != PP_FILESYSTEMTYPE_EXTERNAL && | |
36 type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && | |
37 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY) | |
38 return 0; | |
39 | |
34 PPB_FileSystem_Impl* file_system = | 40 PPB_FileSystem_Impl* file_system = |
35 new PPB_FileSystem_Impl(plugin_instance, type); | 41 new PPB_FileSystem_Impl(plugin_instance, type); |
36 return file_system->GetReference(); | 42 return file_system->GetReference(); |
37 } | 43 } |
38 | 44 |
45 PP_Bool IsFileSystem(PP_Resource resource) { | |
46 scoped_refptr<PPB_FileSystem_Impl> file_system( | |
47 Resource::GetAs<PPB_FileSystem_Impl>(resource)); | |
48 return BoolToPPBool(!!file_system.get()); | |
49 } | |
50 | |
39 int32_t Open(PP_Resource file_system_id, | 51 int32_t Open(PP_Resource file_system_id, |
40 int64 expected_size, | 52 int64 expected_size, |
41 PP_CompletionCallback callback) { | 53 PP_CompletionCallback callback) { |
42 scoped_refptr<PPB_FileSystem_Impl> file_system( | 54 scoped_refptr<PPB_FileSystem_Impl> file_system( |
43 Resource::GetAs<PPB_FileSystem_Impl>(file_system_id)); | 55 Resource::GetAs<PPB_FileSystem_Impl>(file_system_id)); |
44 if (!file_system) | 56 if (!file_system) |
45 return PP_ERROR_BADRESOURCE; | 57 return PP_ERROR_BADRESOURCE; |
46 | 58 |
47 if (file_system->opened()) | 59 if (file_system->opened()) |
48 return PP_OK; | 60 return PP_OK; |
(...skipping 10 matching lines...) Expand all Loading... | |
59 if (!instance->delegate()->OpenFileSystem( | 71 if (!instance->delegate()->OpenFileSystem( |
60 instance->container()->element().document().frame()->url(), | 72 instance->container()->element().document().frame()->url(), |
61 file_system_type, expected_size, | 73 file_system_type, expected_size, |
62 new FileCallbacks(instance->module()->AsWeakPtr(), file_system_id, | 74 new FileCallbacks(instance->module()->AsWeakPtr(), file_system_id, |
63 callback, NULL, file_system, NULL))) | 75 callback, NULL, file_system, NULL))) |
64 return PP_ERROR_FAILED; | 76 return PP_ERROR_FAILED; |
65 | 77 |
66 return PP_ERROR_WOULDBLOCK; | 78 return PP_ERROR_WOULDBLOCK; |
67 } | 79 } |
68 | 80 |
81 PP_FileSystemType_Dev GetType(PP_Resource resource) { | |
82 scoped_refptr<PPB_FileSystem_Impl> file_system( | |
83 Resource::GetAs<PPB_FileSystem_Impl>(resource)); | |
84 if (!file_system) | |
85 return PP_FILESYSTEMTYPE_NONE; | |
vtl
2011/02/21 19:06:00
Maybe PP_FILESYSTEMTYPE_INVALID would be more appr
brettw
2011/02/21 19:19:10
Done.
| |
86 return file_system->type(); | |
87 } | |
88 | |
69 const PPB_FileSystem_Dev ppb_filesystem = { | 89 const PPB_FileSystem_Dev ppb_filesystem = { |
70 &Create, | 90 &Create, |
71 &Open | 91 &IsFileSystem, |
92 &Open, | |
93 &GetType | |
72 }; | 94 }; |
73 | 95 |
74 } // namespace | 96 } // namespace |
75 | 97 |
76 PPB_FileSystem_Impl::PPB_FileSystem_Impl(PluginInstance* instance, | 98 PPB_FileSystem_Impl::PPB_FileSystem_Impl(PluginInstance* instance, |
77 PP_FileSystemType_Dev type) | 99 PP_FileSystemType_Dev type) |
78 : Resource(instance), | 100 : Resource(instance), |
79 instance_(instance), | 101 instance_(instance), |
80 type_(type), | 102 type_(type), |
81 opened_(false) { | 103 opened_(false) { |
104 DCHECK(type_ != PP_FILESYSTEMTYPE_NONE); | |
82 } | 105 } |
83 | 106 |
84 PPB_FileSystem_Impl* PPB_FileSystem_Impl::AsPPB_FileSystem_Impl() { | 107 PPB_FileSystem_Impl* PPB_FileSystem_Impl::AsPPB_FileSystem_Impl() { |
85 return this; | 108 return this; |
86 } | 109 } |
87 | 110 |
88 const PPB_FileSystem_Dev* PPB_FileSystem_Impl::GetInterface() { | 111 const PPB_FileSystem_Dev* PPB_FileSystem_Impl::GetInterface() { |
89 return &ppb_filesystem; | 112 return &ppb_filesystem; |
90 } | 113 } |
91 | 114 |
92 } // namespace ppapi | 115 } // namespace ppapi |
93 } // namespace webkit | 116 } // namespace webkit |
94 | 117 |
OLD | NEW |