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/fileapi/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.h" |
6 | 6 |
7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "base/utf_string_conversions.h" |
8 #include "net/url_request/url_request_context.h" | 9 #include "net/url_request/url_request_context.h" |
9 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 10 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
10 #include "webkit/fileapi/file_system_context.h" | 11 #include "webkit/fileapi/file_system_context.h" |
11 #include "webkit/fileapi/file_system_file_util_proxy.h" | 12 #include "webkit/fileapi/file_system_file_util_proxy.h" |
12 #include "webkit/fileapi/file_system_operation_context.h" | 13 #include "webkit/fileapi/file_system_operation_context.h" |
13 #include "webkit/fileapi/file_system_path_manager.h" | 14 #include "webkit/fileapi/file_system_path_manager.h" |
14 #include "webkit/fileapi/file_system_util.h" | 15 #include "webkit/fileapi/file_system_util.h" |
15 #include "webkit/fileapi/file_writer_delegate.h" | 16 #include "webkit/fileapi/file_writer_delegate.h" |
16 #include "webkit/fileapi/local_file_system_file_util.h" | 17 #include "webkit/fileapi/local_file_system_file_util.h" |
17 | 18 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 // Also, in the future we won't need it either way, as long as we do all | 57 // Also, in the future we won't need it either way, as long as we do all |
57 // permission+quota checks beforehand. We only need it now because we have to | 58 // permission+quota checks beforehand. We only need it now because we have to |
58 // create an unpredictable directory name. Without that, we could lazily | 59 // create an unpredictable directory name. Without that, we could lazily |
59 // create the root later on the first filesystem write operation, and just | 60 // create the root later on the first filesystem write operation, and just |
60 // return GetFileSystemRootURI() here. | 61 // return GetFileSystemRootURI() here. |
61 file_system_context()->path_manager()->GetFileSystemRootPath( | 62 file_system_context()->path_manager()->GetFileSystemRootPath( |
62 origin_url, type, create, | 63 origin_url, type, create, |
63 callback_factory_.NewCallback(&FileSystemOperation::DidGetRootPath)); | 64 callback_factory_.NewCallback(&FileSystemOperation::DidGetRootPath)); |
64 } | 65 } |
65 | 66 |
66 void FileSystemOperation::CreateFile(const FilePath& path, | 67 void FileSystemOperation::CreateFile(const GURL& path, |
67 bool exclusive) { | 68 bool exclusive) { |
68 #ifndef NDEBUG | 69 #ifndef NDEBUG |
69 DCHECK(kOperationNone == pending_operation_); | 70 DCHECK(kOperationNone == pending_operation_); |
70 pending_operation_ = kOperationCreateFile; | 71 pending_operation_ = kOperationCreateFile; |
71 #endif | 72 #endif |
72 FilePath virtual_path; | 73 FilePath virtual_path; |
73 GURL origin_url; | 74 GURL origin_url; |
74 FileSystemType type; | 75 FileSystemType type; |
75 if (!VerifyFileSystemPathForWrite( | 76 if (!VerifyFileSystemPathForWrite( |
76 path, true /* create */, &origin_url, &type, &virtual_path)) { | 77 path, true /* create */, &origin_url, &type, &virtual_path)) { |
77 delete this; | 78 delete this; |
78 return; | 79 return; |
79 } | 80 } |
80 file_system_operation_context_.set_src_origin_url(origin_url); | 81 file_system_operation_context_.set_src_origin_url(origin_url); |
81 file_system_operation_context_.set_src_type(type); | 82 file_system_operation_context_.set_src_type(type); |
82 FileSystemFileUtilProxy::EnsureFileExists( | 83 FileSystemFileUtilProxy::EnsureFileExists( |
83 file_system_operation_context_, | 84 file_system_operation_context_, |
84 proxy_, virtual_path, callback_factory_.NewCallback( | 85 proxy_, virtual_path, callback_factory_.NewCallback( |
85 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive | 86 exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive |
86 : &FileSystemOperation::DidEnsureFileExistsNonExclusive)); | 87 : &FileSystemOperation::DidEnsureFileExistsNonExclusive)); |
87 } | 88 } |
88 | 89 |
89 void FileSystemOperation::CreateDirectory(const FilePath& path, | 90 void FileSystemOperation::CreateDirectory(const GURL& path, |
90 bool exclusive, | 91 bool exclusive, |
91 bool recursive) { | 92 bool recursive) { |
92 #ifndef NDEBUG | 93 #ifndef NDEBUG |
93 DCHECK(kOperationNone == pending_operation_); | 94 DCHECK(kOperationNone == pending_operation_); |
94 pending_operation_ = kOperationCreateDirectory; | 95 pending_operation_ = kOperationCreateDirectory; |
95 #endif | 96 #endif |
96 FilePath virtual_path; | 97 FilePath virtual_path; |
97 GURL origin_url; | 98 GURL origin_url; |
98 FileSystemType type; | 99 FileSystemType type; |
99 | 100 |
100 if (!VerifyFileSystemPathForWrite( | 101 if (!VerifyFileSystemPathForWrite( |
101 path, true /* create */, &origin_url, &type, &virtual_path)) { | 102 path, true /* create */, &origin_url, &type, &virtual_path)) { |
102 delete this; | 103 delete this; |
103 return; | 104 return; |
104 } | 105 } |
105 file_system_operation_context_.set_src_origin_url(origin_url); | 106 file_system_operation_context_.set_src_origin_url(origin_url); |
106 file_system_operation_context_.set_src_type(type); | 107 file_system_operation_context_.set_src_type(type); |
107 FileSystemFileUtilProxy::CreateDirectory( | 108 FileSystemFileUtilProxy::CreateDirectory( |
108 file_system_operation_context_, | 109 file_system_operation_context_, |
109 proxy_, virtual_path, exclusive, recursive, callback_factory_.NewCallback( | 110 proxy_, virtual_path, exclusive, recursive, callback_factory_.NewCallback( |
110 &FileSystemOperation::DidFinishFileOperation)); | 111 &FileSystemOperation::DidFinishFileOperation)); |
111 } | 112 } |
112 | 113 |
113 void FileSystemOperation::Copy(const FilePath& src_path, | 114 void FileSystemOperation::Copy(const GURL& src_path, |
114 const FilePath& dest_path) { | 115 const GURL& dest_path) { |
115 #ifndef NDEBUG | 116 #ifndef NDEBUG |
116 DCHECK(kOperationNone == pending_operation_); | 117 DCHECK(kOperationNone == pending_operation_); |
117 pending_operation_ = kOperationCopy; | 118 pending_operation_ = kOperationCopy; |
118 #endif | 119 #endif |
119 FilePath virtual_path_0; | 120 FilePath virtual_path_0; |
120 FilePath virtual_path_1; | 121 FilePath virtual_path_1; |
121 GURL src_origin_url; | 122 GURL src_origin_url; |
122 GURL dest_origin_url; | 123 GURL dest_origin_url; |
123 FileSystemType src_type; | 124 FileSystemType src_type; |
124 FileSystemType dest_type; | 125 FileSystemType dest_type; |
(...skipping 17 matching lines...) Expand all Loading... |
142 file_system_operation_context_.set_dest_origin_url(dest_origin_url); | 143 file_system_operation_context_.set_dest_origin_url(dest_origin_url); |
143 file_system_operation_context_.set_src_type(src_type); | 144 file_system_operation_context_.set_src_type(src_type); |
144 file_system_operation_context_.set_dest_type(dest_type); | 145 file_system_operation_context_.set_dest_type(dest_type); |
145 FileSystemFileUtilProxy::Copy( | 146 FileSystemFileUtilProxy::Copy( |
146 file_system_operation_context_, | 147 file_system_operation_context_, |
147 proxy_, virtual_path_0, virtual_path_1, | 148 proxy_, virtual_path_0, virtual_path_1, |
148 callback_factory_.NewCallback( | 149 callback_factory_.NewCallback( |
149 &FileSystemOperation::DidFinishFileOperation)); | 150 &FileSystemOperation::DidFinishFileOperation)); |
150 } | 151 } |
151 | 152 |
152 void FileSystemOperation::Move(const FilePath& src_path, | 153 void FileSystemOperation::Move(const GURL& src_path, |
153 const FilePath& dest_path) { | 154 const GURL& dest_path) { |
154 #ifndef NDEBUG | 155 #ifndef NDEBUG |
155 DCHECK(kOperationNone == pending_operation_); | 156 DCHECK(kOperationNone == pending_operation_); |
156 pending_operation_ = kOperationMove; | 157 pending_operation_ = kOperationMove; |
157 #endif | 158 #endif |
158 FilePath virtual_path_0; | 159 FilePath virtual_path_0; |
159 FilePath virtual_path_1; | 160 FilePath virtual_path_1; |
160 GURL src_origin_url; | 161 GURL src_origin_url; |
161 GURL dest_origin_url; | 162 GURL dest_origin_url; |
162 FileSystemType src_type; | 163 FileSystemType src_type; |
163 FileSystemType dest_type; | 164 FileSystemType dest_type; |
(...skipping 15 matching lines...) Expand all Loading... |
179 file_system_operation_context_.set_dest_origin_url(dest_origin_url); | 180 file_system_operation_context_.set_dest_origin_url(dest_origin_url); |
180 file_system_operation_context_.set_src_type(src_type); | 181 file_system_operation_context_.set_src_type(src_type); |
181 file_system_operation_context_.set_dest_type(dest_type); | 182 file_system_operation_context_.set_dest_type(dest_type); |
182 FileSystemFileUtilProxy::Move( | 183 FileSystemFileUtilProxy::Move( |
183 file_system_operation_context_, | 184 file_system_operation_context_, |
184 proxy_, virtual_path_0, virtual_path_1, | 185 proxy_, virtual_path_0, virtual_path_1, |
185 callback_factory_.NewCallback( | 186 callback_factory_.NewCallback( |
186 &FileSystemOperation::DidFinishFileOperation)); | 187 &FileSystemOperation::DidFinishFileOperation)); |
187 } | 188 } |
188 | 189 |
189 void FileSystemOperation::DirectoryExists(const FilePath& path) { | 190 void FileSystemOperation::DirectoryExists(const GURL& path) { |
190 #ifndef NDEBUG | 191 #ifndef NDEBUG |
191 DCHECK(kOperationNone == pending_operation_); | 192 DCHECK(kOperationNone == pending_operation_); |
192 pending_operation_ = kOperationDirectoryExists; | 193 pending_operation_ = kOperationDirectoryExists; |
193 #endif | 194 #endif |
194 | 195 |
195 FilePath virtual_path; | 196 FilePath virtual_path; |
196 GURL origin_url; | 197 GURL origin_url; |
197 FileSystemType type; | 198 FileSystemType type; |
198 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path)) { | 199 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path)) { |
199 delete this; | 200 delete this; |
200 return; | 201 return; |
201 } | 202 } |
202 file_system_operation_context_.set_src_origin_url(origin_url); | 203 file_system_operation_context_.set_src_origin_url(origin_url); |
203 file_system_operation_context_.set_src_type(type); | 204 file_system_operation_context_.set_src_type(type); |
204 FileSystemFileUtilProxy::GetFileInfo( | 205 FileSystemFileUtilProxy::GetFileInfo( |
205 file_system_operation_context_, | 206 file_system_operation_context_, |
206 proxy_, virtual_path, callback_factory_.NewCallback( | 207 proxy_, virtual_path, callback_factory_.NewCallback( |
207 &FileSystemOperation::DidDirectoryExists)); | 208 &FileSystemOperation::DidDirectoryExists)); |
208 } | 209 } |
209 | 210 |
210 void FileSystemOperation::FileExists(const FilePath& path) { | 211 void FileSystemOperation::FileExists(const GURL& path) { |
211 #ifndef NDEBUG | 212 #ifndef NDEBUG |
212 DCHECK(kOperationNone == pending_operation_); | 213 DCHECK(kOperationNone == pending_operation_); |
213 pending_operation_ = kOperationFileExists; | 214 pending_operation_ = kOperationFileExists; |
214 #endif | 215 #endif |
215 | 216 |
216 FilePath virtual_path; | 217 FilePath virtual_path; |
217 GURL origin_url; | 218 GURL origin_url; |
218 FileSystemType type; | 219 FileSystemType type; |
219 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path)) { | 220 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path)) { |
220 delete this; | 221 delete this; |
221 return; | 222 return; |
222 } | 223 } |
223 file_system_operation_context_.set_src_origin_url(origin_url); | 224 file_system_operation_context_.set_src_origin_url(origin_url); |
224 file_system_operation_context_.set_src_type(type); | 225 file_system_operation_context_.set_src_type(type); |
225 FileSystemFileUtilProxy::GetFileInfo( | 226 FileSystemFileUtilProxy::GetFileInfo( |
226 file_system_operation_context_, | 227 file_system_operation_context_, |
227 proxy_, virtual_path, callback_factory_.NewCallback( | 228 proxy_, virtual_path, callback_factory_.NewCallback( |
228 &FileSystemOperation::DidFileExists)); | 229 &FileSystemOperation::DidFileExists)); |
229 } | 230 } |
230 | 231 |
231 void FileSystemOperation::GetMetadata(const FilePath& path) { | 232 void FileSystemOperation::GetMetadata(const GURL& path) { |
232 #ifndef NDEBUG | 233 #ifndef NDEBUG |
233 DCHECK(kOperationNone == pending_operation_); | 234 DCHECK(kOperationNone == pending_operation_); |
234 pending_operation_ = kOperationGetMetadata; | 235 pending_operation_ = kOperationGetMetadata; |
235 #endif | 236 #endif |
236 | 237 |
237 FilePath virtual_path; | 238 FilePath virtual_path; |
238 GURL origin_url; | 239 GURL origin_url; |
239 FileSystemType type; | 240 FileSystemType type; |
240 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path)) { | 241 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path)) { |
241 delete this; | 242 delete this; |
242 return; | 243 return; |
243 } | 244 } |
244 file_system_operation_context_.set_src_origin_url(origin_url); | 245 file_system_operation_context_.set_src_origin_url(origin_url); |
245 file_system_operation_context_.set_src_type(type); | 246 file_system_operation_context_.set_src_type(type); |
246 FileSystemFileUtilProxy::GetFileInfo( | 247 FileSystemFileUtilProxy::GetFileInfo( |
247 file_system_operation_context_, | 248 file_system_operation_context_, |
248 proxy_, virtual_path, callback_factory_.NewCallback( | 249 proxy_, virtual_path, callback_factory_.NewCallback( |
249 &FileSystemOperation::DidGetMetadata)); | 250 &FileSystemOperation::DidGetMetadata)); |
250 } | 251 } |
251 | 252 |
252 void FileSystemOperation::ReadDirectory(const FilePath& path) { | 253 void FileSystemOperation::ReadDirectory(const GURL& path) { |
253 #ifndef NDEBUG | 254 #ifndef NDEBUG |
254 DCHECK(kOperationNone == pending_operation_); | 255 DCHECK(kOperationNone == pending_operation_); |
255 pending_operation_ = kOperationReadDirectory; | 256 pending_operation_ = kOperationReadDirectory; |
256 #endif | 257 #endif |
257 | 258 |
258 FilePath virtual_path; | 259 FilePath virtual_path; |
259 GURL origin_url; | 260 GURL origin_url; |
260 FileSystemType type; | 261 FileSystemType type; |
261 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path)) { | 262 if (!VerifyFileSystemPathForRead(path, &origin_url, &type, &virtual_path)) { |
262 delete this; | 263 delete this; |
263 return; | 264 return; |
264 } | 265 } |
265 file_system_operation_context_.set_src_origin_url(origin_url); | 266 file_system_operation_context_.set_src_origin_url(origin_url); |
266 file_system_operation_context_.set_src_type(type); | 267 file_system_operation_context_.set_src_type(type); |
267 FileSystemFileUtilProxy::ReadDirectory( | 268 FileSystemFileUtilProxy::ReadDirectory( |
268 file_system_operation_context_, | 269 file_system_operation_context_, |
269 proxy_, virtual_path, callback_factory_.NewCallback( | 270 proxy_, virtual_path, callback_factory_.NewCallback( |
270 &FileSystemOperation::DidReadDirectory)); | 271 &FileSystemOperation::DidReadDirectory)); |
271 } | 272 } |
272 | 273 |
273 void FileSystemOperation::Remove(const FilePath& path, bool recursive) { | 274 void FileSystemOperation::Remove(const GURL& path, bool recursive) { |
274 #ifndef NDEBUG | 275 #ifndef NDEBUG |
275 DCHECK(kOperationNone == pending_operation_); | 276 DCHECK(kOperationNone == pending_operation_); |
276 pending_operation_ = kOperationRemove; | 277 pending_operation_ = kOperationRemove; |
277 #endif | 278 #endif |
278 | 279 |
279 FilePath virtual_path; | 280 FilePath virtual_path; |
280 GURL origin_url; | 281 GURL origin_url; |
281 FileSystemType type; | 282 FileSystemType type; |
282 if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, | 283 if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, |
283 &type, &virtual_path)) { | 284 &type, &virtual_path)) { |
284 delete this; | 285 delete this; |
285 return; | 286 return; |
286 } | 287 } |
287 file_system_operation_context_.set_src_origin_url(origin_url); | 288 file_system_operation_context_.set_src_origin_url(origin_url); |
288 file_system_operation_context_.set_src_type(type); | 289 file_system_operation_context_.set_src_type(type); |
289 FileSystemFileUtilProxy::Delete( | 290 FileSystemFileUtilProxy::Delete( |
290 file_system_operation_context_, | 291 file_system_operation_context_, |
291 proxy_, virtual_path, recursive, callback_factory_.NewCallback( | 292 proxy_, virtual_path, recursive, callback_factory_.NewCallback( |
292 &FileSystemOperation::DidFinishFileOperation)); | 293 &FileSystemOperation::DidFinishFileOperation)); |
293 } | 294 } |
294 | 295 |
295 void FileSystemOperation::Write( | 296 void FileSystemOperation::Write( |
296 scoped_refptr<net::URLRequestContext> url_request_context, | 297 scoped_refptr<net::URLRequestContext> url_request_context, |
297 const FilePath& path, | 298 const GURL& path, |
298 const GURL& blob_url, | 299 const GURL& blob_url, |
299 int64 offset) { | 300 int64 offset) { |
300 #ifndef NDEBUG | 301 #ifndef NDEBUG |
301 DCHECK(kOperationNone == pending_operation_); | 302 DCHECK(kOperationNone == pending_operation_); |
302 pending_operation_ = kOperationWrite; | 303 pending_operation_ = kOperationWrite; |
303 #endif | 304 #endif |
304 FilePath virtual_path; | 305 FilePath virtual_path; |
305 GURL origin_url; | 306 GURL origin_url; |
306 FileSystemType type; | 307 FileSystemType type; |
307 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, | 308 if (!VerifyFileSystemPathForWrite(path, true /* create */, &origin_url, |
(...skipping 11 matching lines...) Expand all Loading... |
319 FileSystemFileUtilProxy::CreateOrOpen( | 320 FileSystemFileUtilProxy::CreateOrOpen( |
320 file_system_operation_context_, | 321 file_system_operation_context_, |
321 proxy_, | 322 proxy_, |
322 virtual_path, | 323 virtual_path, |
323 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | | 324 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | |
324 base::PLATFORM_FILE_ASYNC, | 325 base::PLATFORM_FILE_ASYNC, |
325 callback_factory_.NewCallback( | 326 callback_factory_.NewCallback( |
326 &FileSystemOperation::OnFileOpenedForWrite)); | 327 &FileSystemOperation::OnFileOpenedForWrite)); |
327 } | 328 } |
328 | 329 |
329 void FileSystemOperation::Truncate(const FilePath& path, int64 length) { | 330 void FileSystemOperation::Truncate(const GURL& path, int64 length) { |
330 #ifndef NDEBUG | 331 #ifndef NDEBUG |
331 DCHECK(kOperationNone == pending_operation_); | 332 DCHECK(kOperationNone == pending_operation_); |
332 pending_operation_ = kOperationTruncate; | 333 pending_operation_ = kOperationTruncate; |
333 #endif | 334 #endif |
334 FilePath virtual_path; | 335 FilePath virtual_path; |
335 GURL origin_url; | 336 GURL origin_url; |
336 FileSystemType type; | 337 FileSystemType type; |
337 if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, | 338 if (!VerifyFileSystemPathForWrite(path, false /* create */, &origin_url, |
338 &type, &virtual_path)) { | 339 &type, &virtual_path)) { |
339 delete this; | 340 delete this; |
340 return; | 341 return; |
341 } | 342 } |
342 file_system_operation_context_.set_src_origin_url(origin_url); | 343 file_system_operation_context_.set_src_origin_url(origin_url); |
343 file_system_operation_context_.set_src_type(type); | 344 file_system_operation_context_.set_src_type(type); |
344 FileSystemFileUtilProxy::Truncate( | 345 FileSystemFileUtilProxy::Truncate( |
345 file_system_operation_context_, | 346 file_system_operation_context_, |
346 proxy_, virtual_path, length, callback_factory_.NewCallback( | 347 proxy_, virtual_path, length, callback_factory_.NewCallback( |
347 &FileSystemOperation::DidFinishFileOperation)); | 348 &FileSystemOperation::DidFinishFileOperation)); |
348 } | 349 } |
349 | 350 |
350 void FileSystemOperation::TouchFile(const FilePath& path, | 351 void FileSystemOperation::TouchFile(const GURL& path, |
351 const base::Time& last_access_time, | 352 const base::Time& last_access_time, |
352 const base::Time& last_modified_time) { | 353 const base::Time& last_modified_time) { |
353 #ifndef NDEBUG | 354 #ifndef NDEBUG |
354 DCHECK(kOperationNone == pending_operation_); | 355 DCHECK(kOperationNone == pending_operation_); |
355 pending_operation_ = kOperationTouchFile; | 356 pending_operation_ = kOperationTouchFile; |
356 #endif | 357 #endif |
357 | 358 |
358 FilePath virtual_path; | 359 FilePath virtual_path; |
359 GURL origin_url; | 360 GURL origin_url; |
360 FileSystemType type; | 361 FileSystemType type; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 // been cancelled, report it, and report that the cancel has succeeded. | 402 // been cancelled, report it, and report that the cancel has succeeded. |
402 DCHECK(!cancel_operation_.get()); | 403 DCHECK(!cancel_operation_.get()); |
403 cancel_operation_.swap(cancel_operation); | 404 cancel_operation_.swap(cancel_operation); |
404 } | 405 } |
405 } | 406 } |
406 | 407 |
407 void FileSystemOperation::DidGetRootPath( | 408 void FileSystemOperation::DidGetRootPath( |
408 bool success, | 409 bool success, |
409 const FilePath& path, const std::string& name) { | 410 const FilePath& path, const std::string& name) { |
410 DCHECK(success || path.empty()); | 411 DCHECK(success || path.empty()); |
411 FilePath result; | 412 GURL result; |
412 // We ignore the path, and return a URL instead. The point was just to verify | 413 // We ignore the path, and return a URL instead. The point was just to verify |
413 // that we could create/find the path. | 414 // that we could create/find the path. |
414 if (success) { | 415 if (success) { |
415 GURL root_url = GetFileSystemRootURI( | 416 result = GetFileSystemRootURI( |
416 file_system_operation_context_.src_origin_url(), | 417 file_system_operation_context_.src_origin_url(), |
417 file_system_operation_context_.src_type()); | 418 file_system_operation_context_.src_type()); |
418 result = FilePath().AppendASCII(root_url.spec()); | |
419 } | 419 } |
420 dispatcher_->DidOpenFileSystem(name, result); | 420 dispatcher_->DidOpenFileSystem(name, result); |
421 delete this; | 421 delete this; |
422 } | 422 } |
423 | 423 |
424 void FileSystemOperation::DidEnsureFileExistsExclusive( | 424 void FileSystemOperation::DidEnsureFileExistsExclusive( |
425 base::PlatformFileError rv, bool created) { | 425 base::PlatformFileError rv, bool created) { |
426 if (rv == base::PLATFORM_FILE_OK && !created) { | 426 if (rv == base::PLATFORM_FILE_OK && !created) { |
427 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_EXISTS); | 427 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_EXISTS); |
428 delete this; | 428 delete this; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 bool created) { | 530 bool created) { |
531 if (base::PLATFORM_FILE_OK != rv) { | 531 if (base::PLATFORM_FILE_OK != rv) { |
532 dispatcher_->DidFail(rv); | 532 dispatcher_->DidFail(rv); |
533 delete this; | 533 delete this; |
534 return; | 534 return; |
535 } | 535 } |
536 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); | 536 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); |
537 } | 537 } |
538 | 538 |
539 bool FileSystemOperation::VerifyFileSystemPathForRead( | 539 bool FileSystemOperation::VerifyFileSystemPathForRead( |
540 const FilePath& path, GURL* origin_url, FileSystemType* type, | 540 const GURL& path, GURL* origin_url, FileSystemType* type, |
541 FilePath* virtual_path) { | 541 FilePath* virtual_path) { |
542 | 542 |
543 // If we have no context, we just allow any operations, for testing. | 543 // If we have no context, we just allow any operations, for testing. |
544 // TODO(ericu): Revisit this hack for security. | 544 // TODO(ericu): Revisit this hack for security. |
545 if (!file_system_context()) { | 545 if (!file_system_context()) { |
546 *virtual_path = path; | 546 #ifdef OS_WIN |
| 547 // On Windows, the path will look like /C:/foo/bar; we need to remove the |
| 548 // leading slash to make it valid. |
| 549 std::string temp = path.path().substr(1); |
| 550 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); |
| 551 #else |
| 552 *virtual_path = FilePath(path.path()); |
| 553 #endif |
547 *type = file_system_operation_context_.src_type(); | 554 *type = file_system_operation_context_.src_type(); |
| 555 *origin_url = file_system_operation_context_.src_origin_url(); |
548 return true; | 556 return true; |
549 } | 557 } |
550 | 558 |
551 // We may want do more checks, but for now it just checks if the given | 559 // We may want do more checks, but for now it just checks if the given |
552 // |path| is under the valid FileSystem root path for this host context. | 560 // URL is valid. |
553 if (!file_system_context()->path_manager()->CrackFileSystemPath( | 561 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { |
554 path, origin_url, type, virtual_path)) { | 562 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 563 return false; |
| 564 } |
| 565 if (!file_system_context()->path_manager()->IsAllowedFileSystemType( |
| 566 *origin_url, *type)) { |
555 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 567 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
556 return false; | 568 return false; |
557 } | 569 } |
558 | 570 |
559 return true; | 571 return true; |
560 } | 572 } |
561 | 573 |
562 bool FileSystemOperation::VerifyFileSystemPathForWrite( | 574 bool FileSystemOperation::VerifyFileSystemPathForWrite( |
563 const FilePath& path, bool create, GURL* origin_url, FileSystemType* type, | 575 const GURL& path, bool create, GURL* origin_url, FileSystemType* type, |
564 FilePath* virtual_path) { | 576 FilePath* virtual_path) { |
565 | 577 |
566 // If we have no context, we just allow any operations, for testing. | 578 // If we have no context, we just allow any operations, for testing. |
567 // TODO(ericu): Revisit this hack for security. | 579 // TODO(ericu): Revisit this hack for security. |
568 if (!file_system_context()) { | 580 if (!file_system_context()) { |
569 *virtual_path = path; | 581 #ifdef OS_WIN |
| 582 // On Windows, the path will look like /C:/foo/bar; we need to remove the |
| 583 // leading slash to make it valid. |
| 584 std::string temp = path.path().substr(1); |
| 585 *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); |
| 586 #else |
| 587 *virtual_path = FilePath(path.path()); |
| 588 #endif |
570 *type = file_system_operation_context_.dest_type(); | 589 *type = file_system_operation_context_.dest_type(); |
| 590 *origin_url = file_system_operation_context_.dest_origin_url(); |
571 return true; | 591 return true; |
572 } | 592 } |
573 | 593 |
574 if (!file_system_context()->path_manager()->CrackFileSystemPath( | 594 if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { |
575 path, origin_url, type, virtual_path)) { | 595 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
| 596 return false; |
| 597 } |
| 598 if (!file_system_context()->path_manager()->IsAllowedFileSystemType( |
| 599 *origin_url, *type)) { |
576 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 600 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
577 return false; | 601 return false; |
578 } | 602 } |
579 // Any write access is disallowed on the root path. | 603 // Any write access is disallowed on the root path. |
580 if (virtual_path->value().length() == 0 || | 604 if (virtual_path->value().length() == 0 || |
581 virtual_path->DirName().value() == virtual_path->value()) { | 605 virtual_path->DirName().value() == virtual_path->value()) { |
582 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 606 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
583 return false; | 607 return false; |
584 } | 608 } |
585 if (create && file_system_context()->path_manager()->IsRestrictedFileName( | 609 if (create && file_system_context()->path_manager()->IsRestrictedFileName( |
586 *type, virtual_path->BaseName())) { | 610 *type, virtual_path->BaseName())) { |
587 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); | 611 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_SECURITY); |
588 return false; | 612 return false; |
589 } | 613 } |
590 // TODO(kinuko): the check must be moved to QuotaFileSystemFileUtil. | 614 // TODO(kinuko): the check must be moved to QuotaFileSystemFileUtil. |
591 if (!file_system_context()->IsStorageUnlimited(*origin_url)) { | 615 if (!file_system_context()->IsStorageUnlimited(*origin_url)) { |
592 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); | 616 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NO_SPACE); |
593 return false; | 617 return false; |
594 } | 618 } |
595 return true; | 619 return true; |
596 } | 620 } |
597 | 621 |
598 } // namespace fileapi | 622 } // namespace fileapi |
OLD | NEW |