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/glue/plugins/pepper_file_ref.h" | 5 #include "webkit/glue/plugins/pepper_file_ref.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "webkit/glue/plugins/pepper_common.h" |
10 #include "webkit/glue/plugins/pepper_directory_reader.h" | 11 #include "webkit/glue/plugins/pepper_directory_reader.h" |
11 #include "webkit/glue/plugins/pepper_file_callbacks.h" | 12 #include "webkit/glue/plugins/pepper_file_callbacks.h" |
12 #include "webkit/glue/plugins/pepper_file_system.h" | 13 #include "webkit/glue/plugins/pepper_file_system.h" |
13 #include "webkit/glue/plugins/pepper_plugin_delegate.h" | 14 #include "webkit/glue/plugins/pepper_plugin_delegate.h" |
14 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 15 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
15 #include "webkit/glue/plugins/pepper_plugin_module.h" | 16 #include "webkit/glue/plugins/pepper_plugin_module.h" |
16 #include "webkit/glue/plugins/pepper_var.h" | 17 #include "webkit/glue/plugins/pepper_var.h" |
17 | 18 |
18 namespace pepper { | 19 namespace pepper { |
19 | 20 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 if (!IsValidLocalPath(validated_path)) | 52 if (!IsValidLocalPath(validated_path)) |
52 return 0; | 53 return 0; |
53 TrimTrailingSlash(&validated_path); | 54 TrimTrailingSlash(&validated_path); |
54 | 55 |
55 FileRef* file_ref = new FileRef(file_system->instance()->module(), | 56 FileRef* file_ref = new FileRef(file_system->instance()->module(), |
56 file_system, | 57 file_system, |
57 validated_path); | 58 validated_path); |
58 return file_ref->GetReference(); | 59 return file_ref->GetReference(); |
59 } | 60 } |
60 | 61 |
61 bool IsFileRef(PP_Resource resource) { | 62 PP_Bool IsFileRef(PP_Resource resource) { |
62 return !!Resource::GetAs<FileRef>(resource); | 63 return BoolToPPBool(!!Resource::GetAs<FileRef>(resource)); |
63 } | 64 } |
64 | 65 |
65 PP_FileSystemType_Dev GetFileSystemType(PP_Resource file_ref_id) { | 66 PP_FileSystemType_Dev GetFileSystemType(PP_Resource file_ref_id) { |
66 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 67 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); |
67 if (!file_ref) | 68 if (!file_ref) |
68 return PP_FILESYSTEMTYPE_EXTERNAL; | 69 return PP_FILESYSTEMTYPE_EXTERNAL; |
69 return file_ref->GetFileSystemType(); | 70 return file_ref->GetFileSystemType(); |
70 } | 71 } |
71 | 72 |
72 PP_Var GetName(PP_Resource file_ref_id) { | 73 PP_Var GetName(PP_Resource file_ref_id) { |
(...skipping 23 matching lines...) Expand all Loading... |
96 return 0; | 97 return 0; |
97 | 98 |
98 scoped_refptr<FileRef> parent_ref(file_ref->GetParent()); | 99 scoped_refptr<FileRef> parent_ref(file_ref->GetParent()); |
99 if (!parent_ref) | 100 if (!parent_ref) |
100 return 0; | 101 return 0; |
101 | 102 |
102 return parent_ref->GetReference(); | 103 return parent_ref->GetReference(); |
103 } | 104 } |
104 | 105 |
105 int32_t MakeDirectory(PP_Resource directory_ref_id, | 106 int32_t MakeDirectory(PP_Resource directory_ref_id, |
106 bool make_ancestors, | 107 PP_Bool make_ancestors, |
107 PP_CompletionCallback callback) { | 108 PP_CompletionCallback callback) { |
108 scoped_refptr<FileRef> directory_ref( | 109 scoped_refptr<FileRef> directory_ref( |
109 Resource::GetAs<FileRef>(directory_ref_id)); | 110 Resource::GetAs<FileRef>(directory_ref_id)); |
110 if (!directory_ref) | 111 if (!directory_ref) |
111 return PP_ERROR_BADRESOURCE; | 112 return PP_ERROR_BADRESOURCE; |
112 | 113 |
113 scoped_refptr<FileSystem> file_system = directory_ref->GetFileSystem(); | 114 scoped_refptr<FileSystem> file_system = directory_ref->GetFileSystem(); |
114 if (!file_system || !file_system->opened() || | 115 if (!file_system || !file_system->opened() || |
115 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) | 116 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
116 return PP_ERROR_NOACCESS; | 117 return PP_ERROR_NOACCESS; |
117 | 118 |
118 PluginInstance* instance = file_system->instance(); | 119 PluginInstance* instance = file_system->instance(); |
119 if (!instance->delegate()->MakeDirectory( | 120 if (!instance->delegate()->MakeDirectory( |
120 directory_ref->GetSystemPath(), make_ancestors, | 121 directory_ref->GetSystemPath(), PPBoolToBool(make_ancestors), |
121 new FileCallbacks(instance->module()->AsWeakPtr(), | 122 new FileCallbacks(instance->module()->AsWeakPtr(), |
122 callback, NULL, NULL, NULL))) | 123 callback, NULL, NULL, NULL))) |
123 return PP_ERROR_FAILED; | 124 return PP_ERROR_FAILED; |
124 | 125 |
125 return PP_ERROR_WOULDBLOCK; | 126 return PP_ERROR_WOULDBLOCK; |
126 } | 127 } |
127 | 128 |
128 int32_t Query(PP_Resource file_ref_id, | 129 int32_t Query(PP_Resource file_ref_id, |
129 PP_FileInfo_Dev* info, | 130 PP_FileInfo_Dev* info, |
130 PP_CompletionCallback callback) { | 131 PP_CompletionCallback callback) { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 #elif defined(OS_POSIX) | 324 #elif defined(OS_POSIX) |
324 virtual_path_.substr(1) | 325 virtual_path_.substr(1) |
325 #else | 326 #else |
326 #error "Unsupported platform." | 327 #error "Unsupported platform." |
327 #endif | 328 #endif |
328 ); | 329 ); |
329 return file_system_->root_path().Append(virtual_file_path); | 330 return file_system_->root_path().Append(virtual_file_path); |
330 } | 331 } |
331 | 332 |
332 } // namespace pepper | 333 } // namespace pepper |
OLD | NEW |