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