| 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 26 matching lines...) Expand all Loading... |
| 37 #include "storage/common/fileapi/directory_entry.h" | 37 #include "storage/common/fileapi/directory_entry.h" |
| 38 #include "storage/common/fileapi/file_system_info.h" | 38 #include "storage/common/fileapi/file_system_info.h" |
| 39 #include "storage/common/fileapi/file_system_types.h" | 39 #include "storage/common/fileapi/file_system_types.h" |
| 40 #include "storage/common/fileapi/file_system_util.h" | 40 #include "storage/common/fileapi/file_system_util.h" |
| 41 #include "url/gurl.h" | 41 #include "url/gurl.h" |
| 42 | 42 |
| 43 using storage::FileSystemFileUtil; | 43 using storage::FileSystemFileUtil; |
| 44 using storage::FileSystemBackend; | 44 using storage::FileSystemBackend; |
| 45 using storage::FileSystemOperation; | 45 using storage::FileSystemOperation; |
| 46 using storage::FileSystemURL; | 46 using storage::FileSystemURL; |
| 47 using storage::BlobData; | 47 using storage::BlobDataBuilder; |
| 48 using storage::BlobStorageContext; | 48 using storage::BlobStorageContext; |
| 49 | 49 |
| 50 namespace content { | 50 namespace content { |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 const uint32 kFilteredMessageClasses[] = { | 54 const uint32 kFilteredMessageClasses[] = { |
| 55 BlobMsgStart, | 55 BlobMsgStart, |
| 56 FileSystemMsgStart, | 56 FileSystemMsgStart, |
| 57 }; | 57 }; |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 513 in_transit_snapshot_files_.erase(request_id); | 513 in_transit_snapshot_files_.erase(request_id); |
| 514 } | 514 } |
| 515 | 515 |
| 516 void FileAPIMessageFilter::OnStartBuildingBlob(const std::string& uuid) { | 516 void FileAPIMessageFilter::OnStartBuildingBlob(const std::string& uuid) { |
| 517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 517 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 518 ignore_result(blob_storage_host_->StartBuildingBlob(uuid)); | 518 ignore_result(blob_storage_host_->StartBuildingBlob(uuid)); |
| 519 } | 519 } |
| 520 | 520 |
| 521 void FileAPIMessageFilter::OnAppendBlobDataItemToBlob( | 521 void FileAPIMessageFilter::OnAppendBlobDataItemToBlob( |
| 522 const std::string& uuid, const BlobData::Item& item) { | 522 const std::string& uuid, |
| 523 const storage::DataElement& item) { |
| 523 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 524 if (item.type() == BlobData::Item::TYPE_FILE_FILESYSTEM) { | 525 if (item.type() == storage::DataElement::TYPE_FILE_FILESYSTEM) { |
| 525 FileSystemURL filesystem_url(context_->CrackURL(item.filesystem_url())); | 526 FileSystemURL filesystem_url(context_->CrackURL(item.filesystem_url())); |
| 526 if (!FileSystemURLIsValid(context_, filesystem_url) || | 527 if (!FileSystemURLIsValid(context_, filesystem_url) || |
| 527 !security_policy_->CanReadFileSystemFile(process_id_, filesystem_url)) { | 528 !security_policy_->CanReadFileSystemFile(process_id_, filesystem_url)) { |
| 528 ignore_result(blob_storage_host_->CancelBuildingBlob(uuid)); | 529 ignore_result(blob_storage_host_->CancelBuildingBlob(uuid)); |
| 529 return; | 530 return; |
| 530 } | 531 } |
| 531 } | 532 } |
| 532 if (item.type() == BlobData::Item::TYPE_FILE && | 533 if (item.type() == storage::DataElement::TYPE_FILE && |
| 533 !security_policy_->CanReadFile(process_id_, item.path())) { | 534 !security_policy_->CanReadFile(process_id_, item.path())) { |
| 534 ignore_result(blob_storage_host_->CancelBuildingBlob(uuid)); | 535 ignore_result(blob_storage_host_->CancelBuildingBlob(uuid)); |
| 535 return; | 536 return; |
| 536 } | 537 } |
| 537 if (item.length() == 0) { | 538 if (item.length() == 0) { |
| 538 BadMessageReceived(); | 539 BadMessageReceived(); |
| 539 return; | 540 return; |
| 540 } | 541 } |
| 541 ignore_result(blob_storage_host_->AppendBlobDataItem(uuid, item)); | 542 ignore_result(blob_storage_host_->AppendBlobDataItem(uuid, item)); |
| 542 } | 543 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 553 #if defined(OS_WIN) | 554 #if defined(OS_WIN) |
| 554 base::SharedMemory shared_memory(handle, true, PeerHandle()); | 555 base::SharedMemory shared_memory(handle, true, PeerHandle()); |
| 555 #else | 556 #else |
| 556 base::SharedMemory shared_memory(handle, true); | 557 base::SharedMemory shared_memory(handle, true); |
| 557 #endif | 558 #endif |
| 558 if (!shared_memory.Map(buffer_size)) { | 559 if (!shared_memory.Map(buffer_size)) { |
| 559 ignore_result(blob_storage_host_->CancelBuildingBlob(uuid)); | 560 ignore_result(blob_storage_host_->CancelBuildingBlob(uuid)); |
| 560 return; | 561 return; |
| 561 } | 562 } |
| 562 | 563 |
| 563 BlobData::Item item; | 564 storage::DataElement item; |
| 564 item.SetToSharedBytes(static_cast<char*>(shared_memory.memory()), | 565 item.SetToSharedBytes(static_cast<char*>(shared_memory.memory()), |
| 565 buffer_size); | 566 buffer_size); |
| 566 ignore_result(blob_storage_host_->AppendBlobDataItem(uuid, item)); | 567 ignore_result(blob_storage_host_->AppendBlobDataItem(uuid, item)); |
| 567 } | 568 } |
| 568 | 569 |
| 569 void FileAPIMessageFilter::OnFinishBuildingBlob( | 570 void FileAPIMessageFilter::OnFinishBuildingBlob( |
| 570 const std::string& uuid, const std::string& content_type) { | 571 const std::string& uuid, const std::string& content_type) { |
| 571 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 572 ignore_result(blob_storage_host_->FinishBuildingBlob(uuid, content_type)); | 573 ignore_result(blob_storage_host_->FinishBuildingBlob(uuid, content_type)); |
| 573 // TODO(michaeln): check return values once blink has migrated, crbug/174200 | 574 // TODO(michaeln): check return values once blink has migrated, crbug/174200 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 } | 607 } |
| 607 // Use an empty security origin for now. Stream accepts a security origin | 608 // Use an empty security origin for now. Stream accepts a security origin |
| 608 // but how it's handled is not fixed yet. | 609 // but how it's handled is not fixed yet. |
| 609 new Stream(stream_context_->registry(), | 610 new Stream(stream_context_->registry(), |
| 610 NULL /* write_observer */, | 611 NULL /* write_observer */, |
| 611 url); | 612 url); |
| 612 stream_urls_.insert(url.spec()); | 613 stream_urls_.insert(url.spec()); |
| 613 } | 614 } |
| 614 | 615 |
| 615 void FileAPIMessageFilter::OnAppendBlobDataItemToStream( | 616 void FileAPIMessageFilter::OnAppendBlobDataItemToStream( |
| 616 const GURL& url, const BlobData::Item& item) { | 617 const GURL& url, |
| 618 const storage::DataElement& item) { |
| 617 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 619 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 618 | 620 |
| 619 scoped_refptr<Stream> stream(GetStreamForURL(url)); | 621 scoped_refptr<Stream> stream(GetStreamForURL(url)); |
| 620 // Stream instances may be deleted on error. Just abort if there's no Stream | 622 // Stream instances may be deleted on error. Just abort if there's no Stream |
| 621 // instance for |url| in the registry. | 623 // instance for |url| in the registry. |
| 622 if (!stream.get()) | 624 if (!stream.get()) |
| 623 return; | 625 return; |
| 624 | 626 |
| 625 // Data for stream is delivered as TYPE_BYTES item. | 627 // Data for stream is delivered as TYPE_BYTES item. |
| 626 if (item.type() != BlobData::Item::TYPE_BYTES) { | 628 if (item.type() != storage::DataElement::TYPE_BYTES) { |
| 627 BadMessageReceived(); | 629 BadMessageReceived(); |
| 628 return; | 630 return; |
| 629 } | 631 } |
| 630 stream->AddData(item.bytes(), item.length()); | 632 stream->AddData(item.bytes(), item.length()); |
| 631 } | 633 } |
| 632 | 634 |
| 633 void FileAPIMessageFilter::OnAppendSharedMemoryToStream( | 635 void FileAPIMessageFilter::OnAppendSharedMemoryToStream( |
| 634 const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size) { | 636 const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size) { |
| 635 DCHECK(base::SharedMemory::IsHandleValid(handle)); | 637 DCHECK(base::SharedMemory::IsHandleValid(handle)); |
| 636 if (!buffer_size) { | 638 if (!buffer_size) { |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 } | 882 } |
| 881 | 883 |
| 882 return true; | 884 return true; |
| 883 } | 885 } |
| 884 | 886 |
| 885 scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) { | 887 scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) { |
| 886 return stream_context_->registry()->GetStream(url); | 888 return stream_context_->registry()->GetStream(url); |
| 887 } | 889 } |
| 888 | 890 |
| 889 } // namespace content | 891 } // namespace content |
| OLD | NEW |