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_ref_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_file_ref_impl.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 "googleurl/src/gurl.h" |
9 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
10 #include "webkit/plugins/ppapi/common.h" | 11 #include "webkit/plugins/ppapi/common.h" |
11 #include "webkit/plugins/ppapi/file_callbacks.h" | 12 #include "webkit/plugins/ppapi/file_callbacks.h" |
12 #include "webkit/plugins/ppapi/plugin_delegate.h" | 13 #include "webkit/plugins/ppapi/plugin_delegate.h" |
13 #include "webkit/plugins/ppapi/plugin_module.h" | 14 #include "webkit/plugins/ppapi/plugin_module.h" |
14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
15 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" | 16 #include "webkit/plugins/ppapi/ppb_directory_reader_impl.h" |
16 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" | 17 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" |
17 #include "webkit/plugins/ppapi/var.h" | 18 #include "webkit/plugins/ppapi/var.h" |
18 | 19 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 return PP_ERROR_BADRESOURCE; | 120 return PP_ERROR_BADRESOURCE; |
120 | 121 |
121 scoped_refptr<PPB_FileSystem_Impl> file_system = | 122 scoped_refptr<PPB_FileSystem_Impl> file_system = |
122 directory_ref->GetFileSystem(); | 123 directory_ref->GetFileSystem(); |
123 if (!file_system || !file_system->opened() || | 124 if (!file_system || !file_system->opened() || |
124 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) | 125 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
125 return PP_ERROR_NOACCESS; | 126 return PP_ERROR_NOACCESS; |
126 | 127 |
127 PluginInstance* instance = file_system->instance(); | 128 PluginInstance* instance = file_system->instance(); |
128 if (!instance->delegate()->MakeDirectory( | 129 if (!instance->delegate()->MakeDirectory( |
129 directory_ref->GetSystemPath(), PPBoolToBool(make_ancestors), | 130 directory_ref->GetFileSystemURL(), PPBoolToBool(make_ancestors), |
130 new FileCallbacks(instance->module()->AsWeakPtr(), directory_ref_id, | 131 new FileCallbacks(instance->module()->AsWeakPtr(), directory_ref_id, |
131 callback, NULL, NULL, NULL))) | 132 callback, NULL, NULL, NULL))) |
132 return PP_ERROR_FAILED; | 133 return PP_ERROR_FAILED; |
133 | 134 |
134 return PP_ERROR_WOULDBLOCK; | 135 return PP_ERROR_WOULDBLOCK; |
135 } | 136 } |
136 | 137 |
137 int32_t Touch(PP_Resource file_ref_id, | 138 int32_t Touch(PP_Resource file_ref_id, |
138 PP_Time last_access_time, | 139 PP_Time last_access_time, |
139 PP_Time last_modified_time, | 140 PP_Time last_modified_time, |
140 PP_CompletionCallback callback) { | 141 PP_CompletionCallback callback) { |
141 scoped_refptr<PPB_FileRef_Impl> file_ref( | 142 scoped_refptr<PPB_FileRef_Impl> file_ref( |
142 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); | 143 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
143 if (!file_ref) | 144 if (!file_ref) |
144 return PP_ERROR_BADRESOURCE; | 145 return PP_ERROR_BADRESOURCE; |
145 | 146 |
146 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); | 147 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); |
147 if (!file_system || !file_system->opened() || | 148 if (!file_system || !file_system->opened() || |
148 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) | 149 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
149 return PP_ERROR_NOACCESS; | 150 return PP_ERROR_NOACCESS; |
150 | 151 |
151 PluginInstance* instance = file_system->instance(); | 152 PluginInstance* instance = file_system->instance(); |
152 if (!instance->delegate()->Touch( | 153 if (!instance->delegate()->Touch( |
153 file_ref->GetSystemPath(), base::Time::FromDoubleT(last_access_time), | 154 file_ref->GetFileSystemURL(), |
| 155 base::Time::FromDoubleT(last_access_time), |
154 base::Time::FromDoubleT(last_modified_time), | 156 base::Time::FromDoubleT(last_modified_time), |
155 new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id, | 157 new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id, |
156 callback, NULL, NULL, NULL))) | 158 callback, NULL, NULL, NULL))) |
157 return PP_ERROR_FAILED; | 159 return PP_ERROR_FAILED; |
158 | 160 |
159 return PP_ERROR_WOULDBLOCK; | 161 return PP_ERROR_WOULDBLOCK; |
160 } | 162 } |
161 | 163 |
162 int32_t Delete(PP_Resource file_ref_id, | 164 int32_t Delete(PP_Resource file_ref_id, |
163 PP_CompletionCallback callback) { | 165 PP_CompletionCallback callback) { |
164 scoped_refptr<PPB_FileRef_Impl> file_ref( | 166 scoped_refptr<PPB_FileRef_Impl> file_ref( |
165 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); | 167 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
166 if (!file_ref) | 168 if (!file_ref) |
167 return PP_ERROR_BADRESOURCE; | 169 return PP_ERROR_BADRESOURCE; |
168 | 170 |
169 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); | 171 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); |
170 if (!file_system || !file_system->opened() || | 172 if (!file_system || !file_system->opened() || |
171 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) | 173 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
172 return PP_ERROR_NOACCESS; | 174 return PP_ERROR_NOACCESS; |
173 | 175 |
174 PluginInstance* instance = file_system->instance(); | 176 PluginInstance* instance = file_system->instance(); |
175 if (!instance->delegate()->Delete( | 177 if (!instance->delegate()->Delete( |
176 file_ref->GetSystemPath(), | 178 file_ref->GetFileSystemURL(), |
177 new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id, | 179 new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id, |
178 callback, NULL, NULL, NULL))) | 180 callback, NULL, NULL, NULL))) |
179 return PP_ERROR_FAILED; | 181 return PP_ERROR_FAILED; |
180 | 182 |
181 return PP_ERROR_WOULDBLOCK; | 183 return PP_ERROR_WOULDBLOCK; |
182 } | 184 } |
183 | 185 |
184 int32_t Rename(PP_Resource file_ref_id, | 186 int32_t Rename(PP_Resource file_ref_id, |
185 PP_Resource new_file_ref_id, | 187 PP_Resource new_file_ref_id, |
186 PP_CompletionCallback callback) { | 188 PP_CompletionCallback callback) { |
(...skipping 10 matching lines...) Expand all Loading... |
197 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); | 199 scoped_refptr<PPB_FileSystem_Impl> file_system = file_ref->GetFileSystem(); |
198 if (!file_system || !file_system->opened() || | 200 if (!file_system || !file_system->opened() || |
199 (file_system != new_file_ref->GetFileSystem()) || | 201 (file_system != new_file_ref->GetFileSystem()) || |
200 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) | 202 (file_system->type() == PP_FILESYSTEMTYPE_EXTERNAL)) |
201 return PP_ERROR_NOACCESS; | 203 return PP_ERROR_NOACCESS; |
202 | 204 |
203 // TODO(viettrungluu): Also cancel when the new file ref is destroyed? | 205 // TODO(viettrungluu): Also cancel when the new file ref is destroyed? |
204 // http://crbug.com/67624 | 206 // http://crbug.com/67624 |
205 PluginInstance* instance = file_system->instance(); | 207 PluginInstance* instance = file_system->instance(); |
206 if (!instance->delegate()->Rename( | 208 if (!instance->delegate()->Rename( |
207 file_ref->GetSystemPath(), new_file_ref->GetSystemPath(), | 209 file_ref->GetFileSystemURL(), new_file_ref->GetFileSystemURL(), |
208 new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id, | 210 new FileCallbacks(instance->module()->AsWeakPtr(), file_ref_id, |
209 callback, NULL, NULL, NULL))) | 211 callback, NULL, NULL, NULL))) |
210 return PP_ERROR_FAILED; | 212 return PP_ERROR_FAILED; |
211 | 213 |
212 return PP_ERROR_WOULDBLOCK; | 214 return PP_ERROR_WOULDBLOCK; |
213 } | 215 } |
214 | 216 |
215 const PPB_FileRef_Dev ppb_fileref = { | 217 const PPB_FileRef_Dev ppb_fileref = { |
216 &Create, | 218 &Create, |
217 &IsFileRef, | 219 &IsFileRef, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 return PP_FILESYSTEMTYPE_EXTERNAL; | 315 return PP_FILESYSTEMTYPE_EXTERNAL; |
314 | 316 |
315 return file_system_->type(); | 317 return file_system_->type(); |
316 } | 318 } |
317 | 319 |
318 std::string PPB_FileRef_Impl::GetPath() const { | 320 std::string PPB_FileRef_Impl::GetPath() const { |
319 return virtual_path_; | 321 return virtual_path_; |
320 } | 322 } |
321 | 323 |
322 FilePath PPB_FileRef_Impl::GetSystemPath() const { | 324 FilePath PPB_FileRef_Impl::GetSystemPath() const { |
323 if (GetFileSystemType() == PP_FILESYSTEMTYPE_EXTERNAL) | 325 if (GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL) { |
324 return system_path_; | 326 NOTREACHED(); |
| 327 return FilePath(); |
| 328 } |
| 329 return system_path_; |
| 330 } |
325 | 331 |
326 // Since |virtual_path_| starts with a '/', it is considered an absolute path | 332 GURL PPB_FileRef_Impl::GetFileSystemURL() const { |
327 // on POSIX systems. We need to remove the '/' before calling Append() or we | 333 if (GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALPERSISTENT && |
328 // will run into a DCHECK. | 334 GetFileSystemType() != PP_FILESYSTEMTYPE_LOCALTEMPORARY) { |
329 FilePath virtual_file_path( | 335 NOTREACHED(); |
330 #if defined(OS_WIN) | 336 return GURL(); |
331 UTF8ToWide(virtual_path_.substr(1)) | 337 } |
332 #elif defined(OS_POSIX) | 338 if (!virtual_path_.size()) |
333 virtual_path_.substr(1) | 339 return file_system_->root_url(); |
334 #else | 340 // Since |virtual_path_| starts with a '/', it looks like an absolute path. |
335 #error "Unsupported platform." | 341 // We need to trim off the '/' before calling Resolve, as FileSystem URLs |
336 #endif | 342 // start with a storage type identifier that looks like a path segment. |
337 ); | 343 return file_system_->root_url().Resolve(virtual_path_.substr(1)); |
338 return file_system_->root_path().Append(virtual_file_path); | |
339 } | 344 } |
340 | 345 |
341 } // namespace ppapi | 346 } // namespace ppapi |
342 } // namespace webkit | 347 } // namespace webkit |
343 | 348 |
OLD | NEW |