OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/fileapi/fileapi_message_filter.h" | 5 #include "content/browser/fileapi/fileapi_message_filter.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 void FileAPIMessageFilter::OnResolveURL( | 214 void FileAPIMessageFilter::OnResolveURL( |
215 int request_id, | 215 int request_id, |
216 const GURL& filesystem_url) { | 216 const GURL& filesystem_url) { |
217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
218 FileSystemURL url(context_->CrackURL(filesystem_url)); | 218 FileSystemURL url(context_->CrackURL(filesystem_url)); |
219 if (!ValidateFileSystemURL(request_id, url)) | 219 if (!ValidateFileSystemURL(request_id, url)) |
220 return; | 220 return; |
221 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { | 221 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { |
222 Send(new FileSystemMsg_DidFail(request_id, | 222 Send(new FileSystemMsg_DidFail(request_id, |
223 base::PLATFORM_FILE_ERROR_SECURITY)); | 223 base::File::FILE_ERROR_SECURITY)); |
224 return; | 224 return; |
225 } | 225 } |
226 | 226 |
227 context_->ResolveURL(url, base::Bind( | 227 context_->ResolveURL(url, base::Bind( |
228 &FileAPIMessageFilter::DidResolveURL, this, request_id)); | 228 &FileAPIMessageFilter::DidResolveURL, this, request_id)); |
229 } | 229 } |
230 | 230 |
231 void FileAPIMessageFilter::OnDeleteFileSystem( | 231 void FileAPIMessageFilter::OnDeleteFileSystem( |
232 int request_id, | 232 int request_id, |
233 const GURL& origin_url, | 233 const GURL& origin_url, |
234 fileapi::FileSystemType type) { | 234 fileapi::FileSystemType type) { |
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
236 context_->DeleteFileSystem(origin_url, type, base::Bind( | 236 context_->DeleteFileSystem(origin_url, type, base::Bind( |
237 &FileAPIMessageFilter::DidDeleteFileSystem, this, request_id)); | 237 &FileAPIMessageFilter::DidDeleteFileSystem, this, request_id)); |
238 } | 238 } |
239 | 239 |
240 void FileAPIMessageFilter::OnMove( | 240 void FileAPIMessageFilter::OnMove( |
241 int request_id, const GURL& src_path, const GURL& dest_path) { | 241 int request_id, const GURL& src_path, const GURL& dest_path) { |
242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
243 FileSystemURL src_url(context_->CrackURL(src_path)); | 243 FileSystemURL src_url(context_->CrackURL(src_path)); |
244 FileSystemURL dest_url(context_->CrackURL(dest_path)); | 244 FileSystemURL dest_url(context_->CrackURL(dest_path)); |
245 if (!ValidateFileSystemURL(request_id, src_url) || | 245 if (!ValidateFileSystemURL(request_id, src_url) || |
246 !ValidateFileSystemURL(request_id, dest_url)) { | 246 !ValidateFileSystemURL(request_id, dest_url)) { |
247 return; | 247 return; |
248 } | 248 } |
249 if (!security_policy_->CanReadFileSystemFile(process_id_, src_url) || | 249 if (!security_policy_->CanReadFileSystemFile(process_id_, src_url) || |
250 !security_policy_->CanDeleteFileSystemFile(process_id_, src_url) || | 250 !security_policy_->CanDeleteFileSystemFile(process_id_, src_url) || |
251 !security_policy_->CanCreateFileSystemFile(process_id_, dest_url)) { | 251 !security_policy_->CanCreateFileSystemFile(process_id_, dest_url)) { |
252 Send(new FileSystemMsg_DidFail(request_id, | 252 Send(new FileSystemMsg_DidFail(request_id, |
253 base::PLATFORM_FILE_ERROR_SECURITY)); | 253 base::File::FILE_ERROR_SECURITY)); |
254 return; | 254 return; |
255 } | 255 } |
256 | 256 |
257 operations_[request_id] = operation_runner()->Move( | 257 operations_[request_id] = operation_runner()->Move( |
258 src_url, dest_url, | 258 src_url, dest_url, |
259 fileapi::FileSystemOperation::OPTION_NONE, | 259 fileapi::FileSystemOperation::OPTION_NONE, |
260 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); | 260 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); |
261 } | 261 } |
262 | 262 |
263 void FileAPIMessageFilter::OnCopy( | 263 void FileAPIMessageFilter::OnCopy( |
264 int request_id, const GURL& src_path, const GURL& dest_path) { | 264 int request_id, const GURL& src_path, const GURL& dest_path) { |
265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
266 FileSystemURL src_url(context_->CrackURL(src_path)); | 266 FileSystemURL src_url(context_->CrackURL(src_path)); |
267 FileSystemURL dest_url(context_->CrackURL(dest_path)); | 267 FileSystemURL dest_url(context_->CrackURL(dest_path)); |
268 if (!ValidateFileSystemURL(request_id, src_url) || | 268 if (!ValidateFileSystemURL(request_id, src_url) || |
269 !ValidateFileSystemURL(request_id, dest_url)) { | 269 !ValidateFileSystemURL(request_id, dest_url)) { |
270 return; | 270 return; |
271 } | 271 } |
272 if (!security_policy_->CanReadFileSystemFile(process_id_, src_url) || | 272 if (!security_policy_->CanReadFileSystemFile(process_id_, src_url) || |
273 !security_policy_->CanCopyIntoFileSystemFile(process_id_, dest_url)) { | 273 !security_policy_->CanCopyIntoFileSystemFile(process_id_, dest_url)) { |
274 Send(new FileSystemMsg_DidFail(request_id, | 274 Send(new FileSystemMsg_DidFail(request_id, |
275 base::PLATFORM_FILE_ERROR_SECURITY)); | 275 base::File::FILE_ERROR_SECURITY)); |
276 return; | 276 return; |
277 } | 277 } |
278 | 278 |
279 operations_[request_id] = operation_runner()->Copy( | 279 operations_[request_id] = operation_runner()->Copy( |
280 src_url, dest_url, | 280 src_url, dest_url, |
281 fileapi::FileSystemOperation::OPTION_NONE, | 281 fileapi::FileSystemOperation::OPTION_NONE, |
282 fileapi::FileSystemOperationRunner::CopyProgressCallback(), | 282 fileapi::FileSystemOperationRunner::CopyProgressCallback(), |
283 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); | 283 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); |
284 } | 284 } |
285 | 285 |
286 void FileAPIMessageFilter::OnRemove( | 286 void FileAPIMessageFilter::OnRemove( |
287 int request_id, const GURL& path, bool recursive) { | 287 int request_id, const GURL& path, bool recursive) { |
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
289 FileSystemURL url(context_->CrackURL(path)); | 289 FileSystemURL url(context_->CrackURL(path)); |
290 if (!ValidateFileSystemURL(request_id, url)) | 290 if (!ValidateFileSystemURL(request_id, url)) |
291 return; | 291 return; |
292 if (!security_policy_->CanDeleteFileSystemFile(process_id_, url)) { | 292 if (!security_policy_->CanDeleteFileSystemFile(process_id_, url)) { |
293 Send(new FileSystemMsg_DidFail(request_id, | 293 Send(new FileSystemMsg_DidFail(request_id, |
294 base::PLATFORM_FILE_ERROR_SECURITY)); | 294 base::File::FILE_ERROR_SECURITY)); |
295 return; | 295 return; |
296 } | 296 } |
297 | 297 |
298 operations_[request_id] = operation_runner()->Remove( | 298 operations_[request_id] = operation_runner()->Remove( |
299 url, recursive, | 299 url, recursive, |
300 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); | 300 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); |
301 } | 301 } |
302 | 302 |
303 void FileAPIMessageFilter::OnReadMetadata( | 303 void FileAPIMessageFilter::OnReadMetadata( |
304 int request_id, const GURL& path) { | 304 int request_id, const GURL& path) { |
305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
306 FileSystemURL url(context_->CrackURL(path)); | 306 FileSystemURL url(context_->CrackURL(path)); |
307 if (!ValidateFileSystemURL(request_id, url)) | 307 if (!ValidateFileSystemURL(request_id, url)) |
308 return; | 308 return; |
309 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { | 309 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { |
310 Send(new FileSystemMsg_DidFail(request_id, | 310 Send(new FileSystemMsg_DidFail(request_id, |
311 base::PLATFORM_FILE_ERROR_SECURITY)); | 311 base::File::FILE_ERROR_SECURITY)); |
312 return; | 312 return; |
313 } | 313 } |
314 | 314 |
315 operations_[request_id] = operation_runner()->GetMetadata( | 315 operations_[request_id] = operation_runner()->GetMetadata( |
316 url, base::Bind(&FileAPIMessageFilter::DidGetMetadata, this, request_id)); | 316 url, base::Bind(&FileAPIMessageFilter::DidGetMetadata, this, request_id)); |
317 } | 317 } |
318 | 318 |
319 void FileAPIMessageFilter::OnCreate( | 319 void FileAPIMessageFilter::OnCreate( |
320 int request_id, const GURL& path, bool exclusive, | 320 int request_id, const GURL& path, bool exclusive, |
321 bool is_directory, bool recursive) { | 321 bool is_directory, bool recursive) { |
322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
323 FileSystemURL url(context_->CrackURL(path)); | 323 FileSystemURL url(context_->CrackURL(path)); |
324 if (!ValidateFileSystemURL(request_id, url)) | 324 if (!ValidateFileSystemURL(request_id, url)) |
325 return; | 325 return; |
326 if (!security_policy_->CanCreateFileSystemFile(process_id_, url)) { | 326 if (!security_policy_->CanCreateFileSystemFile(process_id_, url)) { |
327 Send(new FileSystemMsg_DidFail(request_id, | 327 Send(new FileSystemMsg_DidFail(request_id, |
328 base::PLATFORM_FILE_ERROR_SECURITY)); | 328 base::File::FILE_ERROR_SECURITY)); |
329 return; | 329 return; |
330 } | 330 } |
331 | 331 |
332 if (is_directory) { | 332 if (is_directory) { |
333 operations_[request_id] = operation_runner()->CreateDirectory( | 333 operations_[request_id] = operation_runner()->CreateDirectory( |
334 url, exclusive, recursive, | 334 url, exclusive, recursive, |
335 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); | 335 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); |
336 } else { | 336 } else { |
337 operations_[request_id] = operation_runner()->CreateFile( | 337 operations_[request_id] = operation_runner()->CreateFile( |
338 url, exclusive, | 338 url, exclusive, |
339 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); | 339 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); |
340 } | 340 } |
341 } | 341 } |
342 | 342 |
343 void FileAPIMessageFilter::OnExists( | 343 void FileAPIMessageFilter::OnExists( |
344 int request_id, const GURL& path, bool is_directory) { | 344 int request_id, const GURL& path, bool is_directory) { |
345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
346 FileSystemURL url(context_->CrackURL(path)); | 346 FileSystemURL url(context_->CrackURL(path)); |
347 if (!ValidateFileSystemURL(request_id, url)) | 347 if (!ValidateFileSystemURL(request_id, url)) |
348 return; | 348 return; |
349 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { | 349 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { |
350 Send(new FileSystemMsg_DidFail(request_id, | 350 Send(new FileSystemMsg_DidFail(request_id, |
351 base::PLATFORM_FILE_ERROR_SECURITY)); | 351 base::File::FILE_ERROR_SECURITY)); |
352 return; | 352 return; |
353 } | 353 } |
354 | 354 |
355 if (is_directory) { | 355 if (is_directory) { |
356 operations_[request_id] = operation_runner()->DirectoryExists( | 356 operations_[request_id] = operation_runner()->DirectoryExists( |
357 url, | 357 url, |
358 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); | 358 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); |
359 } else { | 359 } else { |
360 operations_[request_id] = operation_runner()->FileExists( | 360 operations_[request_id] = operation_runner()->FileExists( |
361 url, | 361 url, |
362 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); | 362 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); |
363 } | 363 } |
364 } | 364 } |
365 | 365 |
366 void FileAPIMessageFilter::OnReadDirectory( | 366 void FileAPIMessageFilter::OnReadDirectory( |
367 int request_id, const GURL& path) { | 367 int request_id, const GURL& path) { |
368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
369 FileSystemURL url(context_->CrackURL(path)); | 369 FileSystemURL url(context_->CrackURL(path)); |
370 if (!ValidateFileSystemURL(request_id, url)) | 370 if (!ValidateFileSystemURL(request_id, url)) |
371 return; | 371 return; |
372 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { | 372 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { |
373 Send(new FileSystemMsg_DidFail(request_id, | 373 Send(new FileSystemMsg_DidFail(request_id, |
374 base::PLATFORM_FILE_ERROR_SECURITY)); | 374 base::File::FILE_ERROR_SECURITY)); |
375 return; | 375 return; |
376 } | 376 } |
377 | 377 |
378 operations_[request_id] = operation_runner()->ReadDirectory( | 378 operations_[request_id] = operation_runner()->ReadDirectory( |
379 url, base::Bind(&FileAPIMessageFilter::DidReadDirectory, | 379 url, base::Bind(&FileAPIMessageFilter::DidReadDirectory, |
380 this, request_id)); | 380 this, request_id)); |
381 } | 381 } |
382 | 382 |
383 void FileAPIMessageFilter::OnWrite( | 383 void FileAPIMessageFilter::OnWrite( |
384 int request_id, | 384 int request_id, |
385 const GURL& path, | 385 const GURL& path, |
386 const std::string& blob_uuid, | 386 const std::string& blob_uuid, |
387 int64 offset) { | 387 int64 offset) { |
388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
389 if (!request_context_) { | 389 if (!request_context_) { |
390 // We can't write w/o a request context, trying to do so will crash. | 390 // We can't write w/o a request context, trying to do so will crash. |
391 NOTREACHED(); | 391 NOTREACHED(); |
392 return; | 392 return; |
393 } | 393 } |
394 | 394 |
395 FileSystemURL url(context_->CrackURL(path)); | 395 FileSystemURL url(context_->CrackURL(path)); |
396 if (!ValidateFileSystemURL(request_id, url)) | 396 if (!ValidateFileSystemURL(request_id, url)) |
397 return; | 397 return; |
398 if (!security_policy_->CanWriteFileSystemFile(process_id_, url)) { | 398 if (!security_policy_->CanWriteFileSystemFile(process_id_, url)) { |
399 Send(new FileSystemMsg_DidFail(request_id, | 399 Send(new FileSystemMsg_DidFail(request_id, |
400 base::PLATFORM_FILE_ERROR_SECURITY)); | 400 base::File::FILE_ERROR_SECURITY)); |
401 return; | 401 return; |
402 } | 402 } |
403 | 403 |
404 scoped_ptr<webkit_blob::BlobDataHandle> blob = | 404 scoped_ptr<webkit_blob::BlobDataHandle> blob = |
405 blob_storage_context_->context()->GetBlobDataFromUUID(blob_uuid); | 405 blob_storage_context_->context()->GetBlobDataFromUUID(blob_uuid); |
406 | 406 |
407 operations_[request_id] = operation_runner()->Write( | 407 operations_[request_id] = operation_runner()->Write( |
408 request_context_, url, blob.Pass(), offset, | 408 request_context_, url, blob.Pass(), offset, |
409 base::Bind(&FileAPIMessageFilter::DidWrite, this, request_id)); | 409 base::Bind(&FileAPIMessageFilter::DidWrite, this, request_id)); |
410 } | 410 } |
411 | 411 |
412 void FileAPIMessageFilter::OnTruncate( | 412 void FileAPIMessageFilter::OnTruncate( |
413 int request_id, | 413 int request_id, |
414 const GURL& path, | 414 const GURL& path, |
415 int64 length) { | 415 int64 length) { |
416 FileSystemURL url(context_->CrackURL(path)); | 416 FileSystemURL url(context_->CrackURL(path)); |
417 if (!ValidateFileSystemURL(request_id, url)) | 417 if (!ValidateFileSystemURL(request_id, url)) |
418 return; | 418 return; |
419 if (!security_policy_->CanWriteFileSystemFile(process_id_, url)) { | 419 if (!security_policy_->CanWriteFileSystemFile(process_id_, url)) { |
420 Send(new FileSystemMsg_DidFail(request_id, | 420 Send(new FileSystemMsg_DidFail(request_id, |
421 base::PLATFORM_FILE_ERROR_SECURITY)); | 421 base::File::FILE_ERROR_SECURITY)); |
422 return; | 422 return; |
423 } | 423 } |
424 | 424 |
425 operations_[request_id] = operation_runner()->Truncate( | 425 operations_[request_id] = operation_runner()->Truncate( |
426 url, length, | 426 url, length, |
427 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); | 427 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); |
428 } | 428 } |
429 | 429 |
430 void FileAPIMessageFilter::OnTouchFile( | 430 void FileAPIMessageFilter::OnTouchFile( |
431 int request_id, | 431 int request_id, |
432 const GURL& path, | 432 const GURL& path, |
433 const base::Time& last_access_time, | 433 const base::Time& last_access_time, |
434 const base::Time& last_modified_time) { | 434 const base::Time& last_modified_time) { |
435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
436 FileSystemURL url(context_->CrackURL(path)); | 436 FileSystemURL url(context_->CrackURL(path)); |
437 if (!ValidateFileSystemURL(request_id, url)) | 437 if (!ValidateFileSystemURL(request_id, url)) |
438 return; | 438 return; |
439 if (!security_policy_->CanCreateFileSystemFile(process_id_, url)) { | 439 if (!security_policy_->CanCreateFileSystemFile(process_id_, url)) { |
440 Send(new FileSystemMsg_DidFail(request_id, | 440 Send(new FileSystemMsg_DidFail(request_id, |
441 base::PLATFORM_FILE_ERROR_SECURITY)); | 441 base::File::FILE_ERROR_SECURITY)); |
442 return; | 442 return; |
443 } | 443 } |
444 | 444 |
445 operations_[request_id] = operation_runner()->TouchFile( | 445 operations_[request_id] = operation_runner()->TouchFile( |
446 url, last_access_time, last_modified_time, | 446 url, last_access_time, last_modified_time, |
447 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); | 447 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); |
448 } | 448 } |
449 | 449 |
450 void FileAPIMessageFilter::OnCancel( | 450 void FileAPIMessageFilter::OnCancel( |
451 int request_id, | 451 int request_id, |
452 int request_id_to_cancel) { | 452 int request_id_to_cancel) { |
453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 453 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
454 | 454 |
455 OperationsMap::iterator found = operations_.find(request_id_to_cancel); | 455 OperationsMap::iterator found = operations_.find(request_id_to_cancel); |
456 if (found != operations_.end()) { | 456 if (found != operations_.end()) { |
457 // The cancel will eventually send both the write failure and the cancel | 457 // The cancel will eventually send both the write failure and the cancel |
458 // success. | 458 // success. |
459 operation_runner()->Cancel( | 459 operation_runner()->Cancel( |
460 found->second, | 460 found->second, |
461 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); | 461 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); |
462 } else { | 462 } else { |
463 // The write already finished; report that we failed to stop it. | 463 // The write already finished; report that we failed to stop it. |
464 Send(new FileSystemMsg_DidFail( | 464 Send(new FileSystemMsg_DidFail( |
465 request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION)); | 465 request_id, base::File::FILE_ERROR_INVALID_OPERATION)); |
466 } | 466 } |
467 } | 467 } |
468 | 468 |
469 void FileAPIMessageFilter::OnSyncGetPlatformPath( | 469 void FileAPIMessageFilter::OnSyncGetPlatformPath( |
470 const GURL& path, base::FilePath* platform_path) { | 470 const GURL& path, base::FilePath* platform_path) { |
471 SyncGetPlatformPath(context_, process_id_, path, platform_path); | 471 SyncGetPlatformPath(context_, process_id_, path, platform_path); |
472 } | 472 } |
473 | 473 |
474 void FileAPIMessageFilter::OnCreateSnapshotFile( | 474 void FileAPIMessageFilter::OnCreateSnapshotFile( |
475 int request_id, const GURL& path) { | 475 int request_id, const GURL& path) { |
476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
477 FileSystemURL url(context_->CrackURL(path)); | 477 FileSystemURL url(context_->CrackURL(path)); |
478 | 478 |
479 // Make sure if this file can be read by the renderer as this is | 479 // Make sure if this file can be read by the renderer as this is |
480 // called when the renderer is about to create a new File object | 480 // called when the renderer is about to create a new File object |
481 // (for reading the file). | 481 // (for reading the file). |
482 if (!ValidateFileSystemURL(request_id, url)) | 482 if (!ValidateFileSystemURL(request_id, url)) |
483 return; | 483 return; |
484 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { | 484 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { |
485 Send(new FileSystemMsg_DidFail(request_id, | 485 Send(new FileSystemMsg_DidFail(request_id, |
486 base::PLATFORM_FILE_ERROR_SECURITY)); | 486 base::File::FILE_ERROR_SECURITY)); |
487 return; | 487 return; |
488 } | 488 } |
489 | 489 |
490 operations_[request_id] = operation_runner()->CreateSnapshotFile( | 490 operations_[request_id] = operation_runner()->CreateSnapshotFile( |
491 url, | 491 url, |
492 base::Bind(&FileAPIMessageFilter::DidCreateSnapshot, | 492 base::Bind(&FileAPIMessageFilter::DidCreateSnapshot, |
493 this, request_id, url)); | 493 this, request_id, url)); |
494 } | 494 } |
495 | 495 |
496 void FileAPIMessageFilter::OnDidReceiveSnapshotFile(int request_id) { | 496 void FileAPIMessageFilter::OnDidReceiveSnapshotFile(int request_id) { |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
670 | 670 |
671 if (!GetStreamForURL(url).get()) | 671 if (!GetStreamForURL(url).get()) |
672 return; | 672 return; |
673 | 673 |
674 stream_context_->registry()->UnregisterStream(url); | 674 stream_context_->registry()->UnregisterStream(url); |
675 stream_urls_.erase(url.spec()); | 675 stream_urls_.erase(url.spec()); |
676 } | 676 } |
677 | 677 |
678 void FileAPIMessageFilter::DidFinish(int request_id, | 678 void FileAPIMessageFilter::DidFinish(int request_id, |
679 base::PlatformFileError result) { | 679 base::File::Error result) { |
680 if (result == base::PLATFORM_FILE_OK) | 680 if (result == base::File::FILE_OK) |
681 Send(new FileSystemMsg_DidSucceed(request_id)); | 681 Send(new FileSystemMsg_DidSucceed(request_id)); |
682 else | 682 else |
683 Send(new FileSystemMsg_DidFail(request_id, result)); | 683 Send(new FileSystemMsg_DidFail(request_id, result)); |
684 operations_.erase(request_id); | 684 operations_.erase(request_id); |
685 } | 685 } |
686 | 686 |
687 void FileAPIMessageFilter::DidGetMetadata( | 687 void FileAPIMessageFilter::DidGetMetadata( |
688 int request_id, | 688 int request_id, |
689 base::PlatformFileError result, | 689 base::File::Error result, |
690 const base::PlatformFileInfo& info) { | 690 const base::File::Info& info) { |
691 if (result == base::PLATFORM_FILE_OK) | 691 if (result == base::File::FILE_OK) |
692 Send(new FileSystemMsg_DidReadMetadata(request_id, info)); | 692 Send(new FileSystemMsg_DidReadMetadata(request_id, info)); |
693 else | 693 else |
694 Send(new FileSystemMsg_DidFail(request_id, result)); | 694 Send(new FileSystemMsg_DidFail(request_id, result)); |
695 operations_.erase(request_id); | 695 operations_.erase(request_id); |
696 } | 696 } |
697 | 697 |
698 void FileAPIMessageFilter::DidReadDirectory( | 698 void FileAPIMessageFilter::DidReadDirectory( |
699 int request_id, | 699 int request_id, |
700 base::PlatformFileError result, | 700 base::File::Error result, |
701 const std::vector<fileapi::DirectoryEntry>& entries, | 701 const std::vector<fileapi::DirectoryEntry>& entries, |
702 bool has_more) { | 702 bool has_more) { |
703 if (result == base::PLATFORM_FILE_OK) | 703 if (result == base::File::FILE_OK) |
704 Send(new FileSystemMsg_DidReadDirectory(request_id, entries, has_more)); | 704 Send(new FileSystemMsg_DidReadDirectory(request_id, entries, has_more)); |
705 else | 705 else |
706 Send(new FileSystemMsg_DidFail(request_id, result)); | 706 Send(new FileSystemMsg_DidFail(request_id, result)); |
707 operations_.erase(request_id); | 707 operations_.erase(request_id); |
708 } | 708 } |
709 | 709 |
710 void FileAPIMessageFilter::DidWrite(int request_id, | 710 void FileAPIMessageFilter::DidWrite(int request_id, |
711 base::PlatformFileError result, | 711 base::File::Error result, |
712 int64 bytes, | 712 int64 bytes, |
713 bool complete) { | 713 bool complete) { |
714 if (result == base::PLATFORM_FILE_OK) { | 714 if (result == base::File::FILE_OK) { |
715 Send(new FileSystemMsg_DidWrite(request_id, bytes, complete)); | 715 Send(new FileSystemMsg_DidWrite(request_id, bytes, complete)); |
716 if (complete) | 716 if (complete) |
717 operations_.erase(request_id); | 717 operations_.erase(request_id); |
718 } else { | 718 } else { |
719 Send(new FileSystemMsg_DidFail(request_id, result)); | 719 Send(new FileSystemMsg_DidFail(request_id, result)); |
720 operations_.erase(request_id); | 720 operations_.erase(request_id); |
721 } | 721 } |
722 } | 722 } |
723 | 723 |
724 void FileAPIMessageFilter::DidOpenFileSystem(int request_id, | 724 void FileAPIMessageFilter::DidOpenFileSystem(int request_id, |
725 const GURL& root, | 725 const GURL& root, |
726 const std::string& filesystem_name, | 726 const std::string& filesystem_name, |
727 base::PlatformFileError result) { | 727 base::File::Error result) { |
728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
729 if (result == base::PLATFORM_FILE_OK) { | 729 if (result == base::File::FILE_OK) { |
730 DCHECK(root.is_valid()); | 730 DCHECK(root.is_valid()); |
731 Send(new FileSystemMsg_DidOpenFileSystem( | 731 Send(new FileSystemMsg_DidOpenFileSystem( |
732 request_id, filesystem_name, root)); | 732 request_id, filesystem_name, root)); |
733 } else { | 733 } else { |
734 Send(new FileSystemMsg_DidFail(request_id, result)); | 734 Send(new FileSystemMsg_DidFail(request_id, result)); |
735 } | 735 } |
736 // For OpenFileSystem we do not create a new operation, so no unregister here. | 736 // For OpenFileSystem we do not create a new operation, so no unregister here. |
737 } | 737 } |
738 | 738 |
739 void FileAPIMessageFilter::DidResolveURL(int request_id, | 739 void FileAPIMessageFilter::DidResolveURL(int request_id, |
740 base::PlatformFileError result, | 740 base::File::Error result, |
741 const fileapi::FileSystemInfo& info, | 741 const fileapi::FileSystemInfo& info, |
742 const base::FilePath& file_path, | 742 const base::FilePath& file_path, |
743 bool is_directory) { | 743 bool is_directory) { |
744 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 744 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
745 if (result == base::PLATFORM_FILE_OK) { | 745 if (result == base::File::FILE_OK) { |
746 DCHECK(info.root_url.is_valid()); | 746 DCHECK(info.root_url.is_valid()); |
747 Send(new FileSystemMsg_DidResolveURL( | 747 Send(new FileSystemMsg_DidResolveURL( |
748 request_id, info, file_path, is_directory)); | 748 request_id, info, file_path, is_directory)); |
749 } else { | 749 } else { |
750 Send(new FileSystemMsg_DidFail(request_id, result)); | 750 Send(new FileSystemMsg_DidFail(request_id, result)); |
751 } | 751 } |
752 // For ResolveURL we do not create a new operation, so no unregister here. | 752 // For ResolveURL we do not create a new operation, so no unregister here. |
753 } | 753 } |
754 | 754 |
755 void FileAPIMessageFilter::DidDeleteFileSystem( | 755 void FileAPIMessageFilter::DidDeleteFileSystem( |
756 int request_id, | 756 int request_id, |
757 base::PlatformFileError result) { | 757 base::File::Error result) { |
758 if (result == base::PLATFORM_FILE_OK) | 758 if (result == base::File::FILE_OK) |
759 Send(new FileSystemMsg_DidSucceed(request_id)); | 759 Send(new FileSystemMsg_DidSucceed(request_id)); |
760 else | 760 else |
761 Send(new FileSystemMsg_DidFail(request_id, result)); | 761 Send(new FileSystemMsg_DidFail(request_id, result)); |
762 // For DeleteFileSystem we do not create a new operation, | 762 // For DeleteFileSystem we do not create a new operation, |
763 // so no unregister here. | 763 // so no unregister here. |
764 } | 764 } |
765 | 765 |
766 void FileAPIMessageFilter::DidCreateSnapshot( | 766 void FileAPIMessageFilter::DidCreateSnapshot( |
767 int request_id, | 767 int request_id, |
768 const fileapi::FileSystemURL& url, | 768 const fileapi::FileSystemURL& url, |
769 base::PlatformFileError result, | 769 base::File::Error result, |
770 const base::PlatformFileInfo& info, | 770 const base::File::Info& info, |
771 const base::FilePath& platform_path, | 771 const base::FilePath& platform_path, |
772 const scoped_refptr<webkit_blob::ShareableFileReference>& /* unused */) { | 772 const scoped_refptr<webkit_blob::ShareableFileReference>& /* unused */) { |
773 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 773 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
774 operations_.erase(request_id); | 774 operations_.erase(request_id); |
775 | 775 |
776 if (result != base::PLATFORM_FILE_OK) { | 776 if (result != base::File::FILE_OK) { |
777 Send(new FileSystemMsg_DidFail(request_id, result)); | 777 Send(new FileSystemMsg_DidFail(request_id, result)); |
778 return; | 778 return; |
779 } | 779 } |
780 | 780 |
781 // TODO(tommycli): This allows streaming blobs to use a 'fake' snapshot file | 781 // TODO(tommycli): This allows streaming blobs to use a 'fake' snapshot file |
782 // with an empty path. We want to eventually have explicit plumbing for | 782 // with an empty path. We want to eventually have explicit plumbing for |
783 // the creation of Blobs without snapshot files, probably called something | 783 // the creation of Blobs without snapshot files, probably called something |
784 // like GetMetadataForStreaming. | 784 // like GetMetadataForStreaming. |
785 if (platform_path.empty()) { | 785 if (platform_path.empty()) { |
786 Send(new FileSystemMsg_DidCreateSnapshotFile(request_id, info, | 786 Send(new FileSystemMsg_DidCreateSnapshotFile(request_id, info, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 | 819 |
820 // Return the file info and platform_path. | 820 // Return the file info and platform_path. |
821 Send(new FileSystemMsg_DidCreateSnapshotFile( | 821 Send(new FileSystemMsg_DidCreateSnapshotFile( |
822 request_id, info, platform_path)); | 822 request_id, info, platform_path)); |
823 } | 823 } |
824 | 824 |
825 bool FileAPIMessageFilter::ValidateFileSystemURL( | 825 bool FileAPIMessageFilter::ValidateFileSystemURL( |
826 int request_id, const fileapi::FileSystemURL& url) { | 826 int request_id, const fileapi::FileSystemURL& url) { |
827 if (!FileSystemURLIsValid(context_, url)) { | 827 if (!FileSystemURLIsValid(context_, url)) { |
828 Send(new FileSystemMsg_DidFail(request_id, | 828 Send(new FileSystemMsg_DidFail(request_id, |
829 base::PLATFORM_FILE_ERROR_INVALID_URL)); | 829 base::File::FILE_ERROR_INVALID_URL)); |
830 return false; | 830 return false; |
831 } | 831 } |
832 | 832 |
833 // Deny access to files in PluginPrivate FileSystem from JavaScript. | 833 // Deny access to files in PluginPrivate FileSystem from JavaScript. |
834 // TODO(nhiroki): Move this filter somewhere else since this is not for | 834 // TODO(nhiroki): Move this filter somewhere else since this is not for |
835 // validation. | 835 // validation. |
836 if (url.type() == fileapi::kFileSystemTypePluginPrivate) { | 836 if (url.type() == fileapi::kFileSystemTypePluginPrivate) { |
837 Send(new FileSystemMsg_DidFail(request_id, | 837 Send(new FileSystemMsg_DidFail(request_id, |
838 base::PLATFORM_FILE_ERROR_SECURITY)); | 838 base::File::FILE_ERROR_SECURITY)); |
839 return false; | 839 return false; |
840 } | 840 } |
841 | 841 |
842 return true; | 842 return true; |
843 } | 843 } |
844 | 844 |
845 scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) { | 845 scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) { |
846 return stream_context_->registry()->GetStream(url); | 846 return stream_context_->registry()->GetStream(url); |
847 } | 847 } |
848 | 848 |
849 } // namespace content | 849 } // namespace content |
OLD | NEW |