| 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 10 matching lines...) Expand all Loading... |
| 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 "url/gurl.h" | 30 #include "url/gurl.h" |
| 31 #include "webkit/browser/blob/blob_storage_context.h" | 31 #include "storage/browser/blob/blob_storage_context.h" |
| 32 #include "webkit/browser/fileapi/file_observers.h" | 32 #include "storage/browser/fileapi/file_observers.h" |
| 33 #include "webkit/browser/fileapi/file_permission_policy.h" | 33 #include "storage/browser/fileapi/file_permission_policy.h" |
| 34 #include "webkit/browser/fileapi/file_system_context.h" | 34 #include "storage/browser/fileapi/file_system_context.h" |
| 35 #include "webkit/browser/fileapi/isolated_context.h" | 35 #include "storage/browser/fileapi/isolated_context.h" |
| 36 #include "webkit/common/blob/blob_data.h" | 36 #include "storage/common/blob/blob_data.h" |
| 37 #include "webkit/common/blob/shareable_file_reference.h" | 37 #include "storage/common/blob/shareable_file_reference.h" |
| 38 #include "webkit/common/fileapi/directory_entry.h" | 38 #include "storage/common/fileapi/directory_entry.h" |
| 39 #include "webkit/common/fileapi/file_system_info.h" | 39 #include "storage/common/fileapi/file_system_info.h" |
| 40 #include "webkit/common/fileapi/file_system_types.h" | 40 #include "storage/common/fileapi/file_system_types.h" |
| 41 #include "webkit/common/fileapi/file_system_util.h" | 41 #include "storage/common/fileapi/file_system_util.h" |
| 42 | 42 |
| 43 using fileapi::FileSystemFileUtil; | 43 using storage::FileSystemFileUtil; |
| 44 using fileapi::FileSystemBackend; | 44 using storage::FileSystemBackend; |
| 45 using fileapi::FileSystemOperation; | 45 using storage::FileSystemOperation; |
| 46 using fileapi::FileSystemURL; | 46 using storage::FileSystemURL; |
| 47 using webkit_blob::BlobData; | 47 using storage::BlobData; |
| 48 using webkit_blob::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 }; |
| 58 | 58 |
| 59 void RevokeFilePermission(int child_id, const base::FilePath& path) { | 59 void RevokeFilePermission(int child_id, const base::FilePath& path) { |
| 60 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeAllPermissionsForFile( | 60 ChildProcessSecurityPolicyImpl::GetInstance()->RevokeAllPermissionsForFile( |
| 61 child_id, path); | 61 child_id, path); |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 FileAPIMessageFilter::FileAPIMessageFilter( | 66 FileAPIMessageFilter::FileAPIMessageFilter( |
| 67 int process_id, | 67 int process_id, |
| 68 net::URLRequestContextGetter* request_context_getter, | 68 net::URLRequestContextGetter* request_context_getter, |
| 69 fileapi::FileSystemContext* file_system_context, | 69 storage::FileSystemContext* file_system_context, |
| 70 ChromeBlobStorageContext* blob_storage_context, | 70 ChromeBlobStorageContext* blob_storage_context, |
| 71 StreamContext* stream_context) | 71 StreamContext* stream_context) |
| 72 : BrowserMessageFilter( | 72 : BrowserMessageFilter(kFilteredMessageClasses, |
| 73 kFilteredMessageClasses, arraysize(kFilteredMessageClasses)), | 73 arraysize(kFilteredMessageClasses)), |
| 74 process_id_(process_id), | 74 process_id_(process_id), |
| 75 context_(file_system_context), | 75 context_(file_system_context), |
| 76 security_policy_(ChildProcessSecurityPolicyImpl::GetInstance()), | 76 security_policy_(ChildProcessSecurityPolicyImpl::GetInstance()), |
| 77 request_context_getter_(request_context_getter), | 77 request_context_getter_(request_context_getter), |
| 78 request_context_(NULL), | 78 request_context_(NULL), |
| 79 blob_storage_context_(blob_storage_context), | 79 blob_storage_context_(blob_storage_context), |
| 80 stream_context_(stream_context) { | 80 stream_context_(stream_context) { |
| 81 DCHECK(context_); | 81 DCHECK(context_); |
| 82 DCHECK(request_context_getter_.get()); | 82 DCHECK(request_context_getter_.get()); |
| 83 DCHECK(blob_storage_context); | 83 DCHECK(blob_storage_context); |
| 84 DCHECK(stream_context); | 84 DCHECK(stream_context); |
| 85 } | 85 } |
| 86 | 86 |
| 87 FileAPIMessageFilter::FileAPIMessageFilter( | 87 FileAPIMessageFilter::FileAPIMessageFilter( |
| 88 int process_id, | 88 int process_id, |
| 89 net::URLRequestContext* request_context, | 89 net::URLRequestContext* request_context, |
| 90 fileapi::FileSystemContext* file_system_context, | 90 storage::FileSystemContext* file_system_context, |
| 91 ChromeBlobStorageContext* blob_storage_context, | 91 ChromeBlobStorageContext* blob_storage_context, |
| 92 StreamContext* stream_context) | 92 StreamContext* stream_context) |
| 93 : BrowserMessageFilter( | 93 : BrowserMessageFilter(kFilteredMessageClasses, |
| 94 kFilteredMessageClasses, arraysize(kFilteredMessageClasses)), | 94 arraysize(kFilteredMessageClasses)), |
| 95 process_id_(process_id), | 95 process_id_(process_id), |
| 96 context_(file_system_context), | 96 context_(file_system_context), |
| 97 security_policy_(ChildProcessSecurityPolicyImpl::GetInstance()), | 97 security_policy_(ChildProcessSecurityPolicyImpl::GetInstance()), |
| 98 request_context_(request_context), | 98 request_context_(request_context), |
| 99 blob_storage_context_(blob_storage_context), | 99 blob_storage_context_(blob_storage_context), |
| 100 stream_context_(stream_context) { | 100 stream_context_(stream_context) { |
| 101 DCHECK(context_); | 101 DCHECK(context_); |
| 102 DCHECK(request_context_); | 102 DCHECK(request_context_); |
| 103 DCHECK(blob_storage_context); | 103 DCHECK(blob_storage_context); |
| 104 DCHECK(stream_context); | 104 DCHECK(stream_context); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 196 |
| 197 FileAPIMessageFilter::~FileAPIMessageFilter() {} | 197 FileAPIMessageFilter::~FileAPIMessageFilter() {} |
| 198 | 198 |
| 199 void FileAPIMessageFilter::BadMessageReceived() { | 199 void FileAPIMessageFilter::BadMessageReceived() { |
| 200 RecordAction(base::UserMetricsAction("BadMessageTerminate_FAMF")); | 200 RecordAction(base::UserMetricsAction("BadMessageTerminate_FAMF")); |
| 201 BrowserMessageFilter::BadMessageReceived(); | 201 BrowserMessageFilter::BadMessageReceived(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 void FileAPIMessageFilter::OnOpenFileSystem(int request_id, | 204 void FileAPIMessageFilter::OnOpenFileSystem(int request_id, |
| 205 const GURL& origin_url, | 205 const GURL& origin_url, |
| 206 fileapi::FileSystemType type) { | 206 storage::FileSystemType type) { |
| 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 208 if (type == fileapi::kFileSystemTypeTemporary) { | 208 if (type == storage::kFileSystemTypeTemporary) { |
| 209 RecordAction(base::UserMetricsAction("OpenFileSystemTemporary")); | 209 RecordAction(base::UserMetricsAction("OpenFileSystemTemporary")); |
| 210 } else if (type == fileapi::kFileSystemTypePersistent) { | 210 } else if (type == storage::kFileSystemTypePersistent) { |
| 211 RecordAction(base::UserMetricsAction("OpenFileSystemPersistent")); | 211 RecordAction(base::UserMetricsAction("OpenFileSystemPersistent")); |
| 212 } | 212 } |
| 213 fileapi::OpenFileSystemMode mode = | 213 storage::OpenFileSystemMode mode = |
| 214 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT; | 214 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT; |
| 215 context_->OpenFileSystem(origin_url, type, mode, base::Bind( | 215 context_->OpenFileSystem(origin_url, type, mode, base::Bind( |
| 216 &FileAPIMessageFilter::DidOpenFileSystem, this, request_id)); | 216 &FileAPIMessageFilter::DidOpenFileSystem, this, request_id)); |
| 217 } | 217 } |
| 218 | 218 |
| 219 void FileAPIMessageFilter::OnResolveURL( | 219 void FileAPIMessageFilter::OnResolveURL( |
| 220 int request_id, | 220 int request_id, |
| 221 const GURL& filesystem_url) { | 221 const GURL& filesystem_url) { |
| 222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 223 FileSystemURL url(context_->CrackURL(filesystem_url)); | 223 FileSystemURL url(context_->CrackURL(filesystem_url)); |
| 224 if (!ValidateFileSystemURL(request_id, url)) | 224 if (!ValidateFileSystemURL(request_id, url)) |
| 225 return; | 225 return; |
| 226 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { | 226 if (!security_policy_->CanReadFileSystemFile(process_id_, url)) { |
| 227 Send(new FileSystemMsg_DidFail(request_id, | 227 Send(new FileSystemMsg_DidFail(request_id, |
| 228 base::File::FILE_ERROR_SECURITY)); | 228 base::File::FILE_ERROR_SECURITY)); |
| 229 return; | 229 return; |
| 230 } | 230 } |
| 231 | 231 |
| 232 context_->ResolveURL(url, base::Bind( | 232 context_->ResolveURL(url, base::Bind( |
| 233 &FileAPIMessageFilter::DidResolveURL, this, request_id)); | 233 &FileAPIMessageFilter::DidResolveURL, this, request_id)); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void FileAPIMessageFilter::OnDeleteFileSystem( | 236 void FileAPIMessageFilter::OnDeleteFileSystem(int request_id, |
| 237 int request_id, | 237 const GURL& origin_url, |
| 238 const GURL& origin_url, | 238 storage::FileSystemType type) { |
| 239 fileapi::FileSystemType type) { | |
| 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 241 context_->DeleteFileSystem(origin_url, type, base::Bind( | 240 context_->DeleteFileSystem(origin_url, type, base::Bind( |
| 242 &FileAPIMessageFilter::DidDeleteFileSystem, this, request_id)); | 241 &FileAPIMessageFilter::DidDeleteFileSystem, this, request_id)); |
| 243 } | 242 } |
| 244 | 243 |
| 245 void FileAPIMessageFilter::OnMove( | 244 void FileAPIMessageFilter::OnMove( |
| 246 int request_id, const GURL& src_path, const GURL& dest_path) { | 245 int request_id, const GURL& src_path, const GURL& dest_path) { |
| 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 248 FileSystemURL src_url(context_->CrackURL(src_path)); | 247 FileSystemURL src_url(context_->CrackURL(src_path)); |
| 249 FileSystemURL dest_url(context_->CrackURL(dest_path)); | 248 FileSystemURL dest_url(context_->CrackURL(dest_path)); |
| 250 if (!ValidateFileSystemURL(request_id, src_url) || | 249 if (!ValidateFileSystemURL(request_id, src_url) || |
| 251 !ValidateFileSystemURL(request_id, dest_url)) { | 250 !ValidateFileSystemURL(request_id, dest_url)) { |
| 252 return; | 251 return; |
| 253 } | 252 } |
| 254 if (!security_policy_->CanReadFileSystemFile(process_id_, src_url) || | 253 if (!security_policy_->CanReadFileSystemFile(process_id_, src_url) || |
| 255 !security_policy_->CanDeleteFileSystemFile(process_id_, src_url) || | 254 !security_policy_->CanDeleteFileSystemFile(process_id_, src_url) || |
| 256 !security_policy_->CanCreateFileSystemFile(process_id_, dest_url)) { | 255 !security_policy_->CanCreateFileSystemFile(process_id_, dest_url)) { |
| 257 Send(new FileSystemMsg_DidFail(request_id, | 256 Send(new FileSystemMsg_DidFail(request_id, |
| 258 base::File::FILE_ERROR_SECURITY)); | 257 base::File::FILE_ERROR_SECURITY)); |
| 259 return; | 258 return; |
| 260 } | 259 } |
| 261 | 260 |
| 262 operations_[request_id] = operation_runner()->Move( | 261 operations_[request_id] = operation_runner()->Move( |
| 263 src_url, dest_url, | 262 src_url, |
| 264 fileapi::FileSystemOperation::OPTION_NONE, | 263 dest_url, |
| 264 storage::FileSystemOperation::OPTION_NONE, |
| 265 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); | 265 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); |
| 266 } | 266 } |
| 267 | 267 |
| 268 void FileAPIMessageFilter::OnCopy( | 268 void FileAPIMessageFilter::OnCopy( |
| 269 int request_id, const GURL& src_path, const GURL& dest_path) { | 269 int request_id, const GURL& src_path, const GURL& dest_path) { |
| 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 271 FileSystemURL src_url(context_->CrackURL(src_path)); | 271 FileSystemURL src_url(context_->CrackURL(src_path)); |
| 272 FileSystemURL dest_url(context_->CrackURL(dest_path)); | 272 FileSystemURL dest_url(context_->CrackURL(dest_path)); |
| 273 if (!ValidateFileSystemURL(request_id, src_url) || | 273 if (!ValidateFileSystemURL(request_id, src_url) || |
| 274 !ValidateFileSystemURL(request_id, dest_url)) { | 274 !ValidateFileSystemURL(request_id, dest_url)) { |
| 275 return; | 275 return; |
| 276 } | 276 } |
| 277 if (!security_policy_->CanReadFileSystemFile(process_id_, src_url) || | 277 if (!security_policy_->CanReadFileSystemFile(process_id_, src_url) || |
| 278 !security_policy_->CanCopyIntoFileSystemFile(process_id_, dest_url)) { | 278 !security_policy_->CanCopyIntoFileSystemFile(process_id_, dest_url)) { |
| 279 Send(new FileSystemMsg_DidFail(request_id, | 279 Send(new FileSystemMsg_DidFail(request_id, |
| 280 base::File::FILE_ERROR_SECURITY)); | 280 base::File::FILE_ERROR_SECURITY)); |
| 281 return; | 281 return; |
| 282 } | 282 } |
| 283 | 283 |
| 284 operations_[request_id] = operation_runner()->Copy( | 284 operations_[request_id] = operation_runner()->Copy( |
| 285 src_url, dest_url, | 285 src_url, |
| 286 fileapi::FileSystemOperation::OPTION_NONE, | 286 dest_url, |
| 287 fileapi::FileSystemOperationRunner::CopyProgressCallback(), | 287 storage::FileSystemOperation::OPTION_NONE, |
| 288 storage::FileSystemOperationRunner::CopyProgressCallback(), |
| 288 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); | 289 base::Bind(&FileAPIMessageFilter::DidFinish, this, request_id)); |
| 289 } | 290 } |
| 290 | 291 |
| 291 void FileAPIMessageFilter::OnRemove( | 292 void FileAPIMessageFilter::OnRemove( |
| 292 int request_id, const GURL& path, bool recursive) { | 293 int request_id, const GURL& path, bool recursive) { |
| 293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 294 FileSystemURL url(context_->CrackURL(path)); | 295 FileSystemURL url(context_->CrackURL(path)); |
| 295 if (!ValidateFileSystemURL(request_id, url)) | 296 if (!ValidateFileSystemURL(request_id, url)) |
| 296 return; | 297 return; |
| 297 if (!security_policy_->CanDeleteFileSystemFile(process_id_, url)) { | 298 if (!security_policy_->CanDeleteFileSystemFile(process_id_, url)) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 400 |
| 400 FileSystemURL url(context_->CrackURL(path)); | 401 FileSystemURL url(context_->CrackURL(path)); |
| 401 if (!ValidateFileSystemURL(request_id, url)) | 402 if (!ValidateFileSystemURL(request_id, url)) |
| 402 return; | 403 return; |
| 403 if (!security_policy_->CanWriteFileSystemFile(process_id_, url)) { | 404 if (!security_policy_->CanWriteFileSystemFile(process_id_, url)) { |
| 404 Send(new FileSystemMsg_DidFail(request_id, | 405 Send(new FileSystemMsg_DidFail(request_id, |
| 405 base::File::FILE_ERROR_SECURITY)); | 406 base::File::FILE_ERROR_SECURITY)); |
| 406 return; | 407 return; |
| 407 } | 408 } |
| 408 | 409 |
| 409 scoped_ptr<webkit_blob::BlobDataHandle> blob = | 410 scoped_ptr<storage::BlobDataHandle> blob = |
| 410 blob_storage_context_->context()->GetBlobDataFromUUID(blob_uuid); | 411 blob_storage_context_->context()->GetBlobDataFromUUID(blob_uuid); |
| 411 | 412 |
| 412 operations_[request_id] = operation_runner()->Write( | 413 operations_[request_id] = operation_runner()->Write( |
| 413 request_context_, url, blob.Pass(), offset, | 414 request_context_, url, blob.Pass(), offset, |
| 414 base::Bind(&FileAPIMessageFilter::DidWrite, this, request_id)); | 415 base::Bind(&FileAPIMessageFilter::DidWrite, this, request_id)); |
| 415 } | 416 } |
| 416 | 417 |
| 417 void FileAPIMessageFilter::OnTruncate( | 418 void FileAPIMessageFilter::OnTruncate( |
| 418 int request_id, | 419 int request_id, |
| 419 const GURL& path, | 420 const GURL& path, |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 base::FilePath())); | 720 base::FilePath())); |
| 720 } else { | 721 } else { |
| 721 Send(new FileSystemMsg_DidFail(request_id, result)); | 722 Send(new FileSystemMsg_DidFail(request_id, result)); |
| 722 } | 723 } |
| 723 operations_.erase(request_id); | 724 operations_.erase(request_id); |
| 724 } | 725 } |
| 725 | 726 |
| 726 void FileAPIMessageFilter::DidReadDirectory( | 727 void FileAPIMessageFilter::DidReadDirectory( |
| 727 int request_id, | 728 int request_id, |
| 728 base::File::Error result, | 729 base::File::Error result, |
| 729 const std::vector<fileapi::DirectoryEntry>& entries, | 730 const std::vector<storage::DirectoryEntry>& entries, |
| 730 bool has_more) { | 731 bool has_more) { |
| 731 if (result == base::File::FILE_OK) { | 732 if (result == base::File::FILE_OK) { |
| 732 if (!entries.empty() || !has_more) | 733 if (!entries.empty() || !has_more) |
| 733 Send(new FileSystemMsg_DidReadDirectory(request_id, entries, has_more)); | 734 Send(new FileSystemMsg_DidReadDirectory(request_id, entries, has_more)); |
| 734 } else { | 735 } else { |
| 735 DCHECK(!has_more); | 736 DCHECK(!has_more); |
| 736 Send(new FileSystemMsg_DidFail(request_id, result)); | 737 Send(new FileSystemMsg_DidFail(request_id, result)); |
| 737 } | 738 } |
| 738 if (!has_more) | 739 if (!has_more) |
| 739 operations_.erase(request_id); | 740 operations_.erase(request_id); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 764 request_id, filesystem_name, root)); | 765 request_id, filesystem_name, root)); |
| 765 } else { | 766 } else { |
| 766 Send(new FileSystemMsg_DidFail(request_id, result)); | 767 Send(new FileSystemMsg_DidFail(request_id, result)); |
| 767 } | 768 } |
| 768 // For OpenFileSystem we do not create a new operation, so no unregister here. | 769 // For OpenFileSystem we do not create a new operation, so no unregister here. |
| 769 } | 770 } |
| 770 | 771 |
| 771 void FileAPIMessageFilter::DidResolveURL( | 772 void FileAPIMessageFilter::DidResolveURL( |
| 772 int request_id, | 773 int request_id, |
| 773 base::File::Error result, | 774 base::File::Error result, |
| 774 const fileapi::FileSystemInfo& info, | 775 const storage::FileSystemInfo& info, |
| 775 const base::FilePath& file_path, | 776 const base::FilePath& file_path, |
| 776 fileapi::FileSystemContext::ResolvedEntryType type) { | 777 storage::FileSystemContext::ResolvedEntryType type) { |
| 777 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 778 if (result == base::File::FILE_OK && | 779 if (result == base::File::FILE_OK && |
| 779 type == fileapi::FileSystemContext::RESOLVED_ENTRY_NOT_FOUND) | 780 type == storage::FileSystemContext::RESOLVED_ENTRY_NOT_FOUND) |
| 780 result = base::File::FILE_ERROR_NOT_FOUND; | 781 result = base::File::FILE_ERROR_NOT_FOUND; |
| 781 | 782 |
| 782 if (result == base::File::FILE_OK) { | 783 if (result == base::File::FILE_OK) { |
| 783 DCHECK(info.root_url.is_valid()); | 784 DCHECK(info.root_url.is_valid()); |
| 784 Send(new FileSystemMsg_DidResolveURL( | 785 Send(new FileSystemMsg_DidResolveURL( |
| 785 request_id, info, file_path, | 786 request_id, |
| 786 type == fileapi::FileSystemContext::RESOLVED_ENTRY_DIRECTORY)); | 787 info, |
| 788 file_path, |
| 789 type == storage::FileSystemContext::RESOLVED_ENTRY_DIRECTORY)); |
| 787 } else { | 790 } else { |
| 788 Send(new FileSystemMsg_DidFail(request_id, result)); | 791 Send(new FileSystemMsg_DidFail(request_id, result)); |
| 789 } | 792 } |
| 790 // For ResolveURL we do not create a new operation, so no unregister here. | 793 // For ResolveURL we do not create a new operation, so no unregister here. |
| 791 } | 794 } |
| 792 | 795 |
| 793 void FileAPIMessageFilter::DidDeleteFileSystem( | 796 void FileAPIMessageFilter::DidDeleteFileSystem( |
| 794 int request_id, | 797 int request_id, |
| 795 base::File::Error result) { | 798 base::File::Error result) { |
| 796 if (result == base::File::FILE_OK) | 799 if (result == base::File::FILE_OK) |
| 797 Send(new FileSystemMsg_DidSucceed(request_id)); | 800 Send(new FileSystemMsg_DidSucceed(request_id)); |
| 798 else | 801 else |
| 799 Send(new FileSystemMsg_DidFail(request_id, result)); | 802 Send(new FileSystemMsg_DidFail(request_id, result)); |
| 800 // For DeleteFileSystem we do not create a new operation, | 803 // For DeleteFileSystem we do not create a new operation, |
| 801 // so no unregister here. | 804 // so no unregister here. |
| 802 } | 805 } |
| 803 | 806 |
| 804 void FileAPIMessageFilter::DidCreateSnapshot( | 807 void FileAPIMessageFilter::DidCreateSnapshot( |
| 805 int request_id, | 808 int request_id, |
| 806 const fileapi::FileSystemURL& url, | 809 const storage::FileSystemURL& url, |
| 807 base::File::Error result, | 810 base::File::Error result, |
| 808 const base::File::Info& info, | 811 const base::File::Info& info, |
| 809 const base::FilePath& platform_path, | 812 const base::FilePath& platform_path, |
| 810 const scoped_refptr<webkit_blob::ShareableFileReference>& /* unused */) { | 813 const scoped_refptr<storage::ShareableFileReference>& /* unused */) { |
| 811 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 812 operations_.erase(request_id); | 815 operations_.erase(request_id); |
| 813 | 816 |
| 814 if (result != base::File::FILE_OK) { | 817 if (result != base::File::FILE_OK) { |
| 815 Send(new FileSystemMsg_DidFail(request_id, result)); | 818 Send(new FileSystemMsg_DidFail(request_id, result)); |
| 816 return; | 819 return; |
| 817 } | 820 } |
| 818 | 821 |
| 819 scoped_refptr<webkit_blob::ShareableFileReference> file_ref = | 822 scoped_refptr<storage::ShareableFileReference> file_ref = |
| 820 webkit_blob::ShareableFileReference::Get(platform_path); | 823 storage::ShareableFileReference::Get(platform_path); |
| 821 if (!security_policy_->CanReadFile(process_id_, platform_path)) { | 824 if (!security_policy_->CanReadFile(process_id_, platform_path)) { |
| 822 // Give per-file read permission to the snapshot file if it hasn't it yet. | 825 // Give per-file read permission to the snapshot file if it hasn't it yet. |
| 823 // In order for the renderer to be able to read the file via File object, | 826 // In order for the renderer to be able to read the file via File object, |
| 824 // it must be granted per-file read permission for the file's platform | 827 // it must be granted per-file read permission for the file's platform |
| 825 // path. By now, it has already been verified that the renderer has | 828 // path. By now, it has already been verified that the renderer has |
| 826 // sufficient permissions to read the file, so giving per-file permission | 829 // sufficient permissions to read the file, so giving per-file permission |
| 827 // here must be safe. | 830 // here must be safe. |
| 828 security_policy_->GrantReadFile(process_id_, platform_path); | 831 security_policy_->GrantReadFile(process_id_, platform_path); |
| 829 | 832 |
| 830 // Revoke all permissions for the file when the last ref of the file | 833 // Revoke all permissions for the file when the last ref of the file |
| 831 // is dropped. | 834 // is dropped. |
| 832 if (!file_ref.get()) { | 835 if (!file_ref.get()) { |
| 833 // Create a reference for temporary permission handling. | 836 // Create a reference for temporary permission handling. |
| 834 file_ref = webkit_blob::ShareableFileReference::GetOrCreate( | 837 file_ref = storage::ShareableFileReference::GetOrCreate( |
| 835 platform_path, | 838 platform_path, |
| 836 webkit_blob::ShareableFileReference::DONT_DELETE_ON_FINAL_RELEASE, | 839 storage::ShareableFileReference::DONT_DELETE_ON_FINAL_RELEASE, |
| 837 context_->default_file_task_runner()); | 840 context_->default_file_task_runner()); |
| 838 } | 841 } |
| 839 file_ref->AddFinalReleaseCallback( | 842 file_ref->AddFinalReleaseCallback( |
| 840 base::Bind(&RevokeFilePermission, process_id_)); | 843 base::Bind(&RevokeFilePermission, process_id_)); |
| 841 } | 844 } |
| 842 | 845 |
| 843 if (file_ref.get()) { | 846 if (file_ref.get()) { |
| 844 // This ref is held until OnDidReceiveSnapshotFile is called. | 847 // This ref is held until OnDidReceiveSnapshotFile is called. |
| 845 in_transit_snapshot_files_[request_id] = file_ref; | 848 in_transit_snapshot_files_[request_id] = file_ref; |
| 846 } | 849 } |
| 847 | 850 |
| 848 // Return the file info and platform_path. | 851 // Return the file info and platform_path. |
| 849 Send(new FileSystemMsg_DidCreateSnapshotFile( | 852 Send(new FileSystemMsg_DidCreateSnapshotFile( |
| 850 request_id, info, platform_path)); | 853 request_id, info, platform_path)); |
| 851 } | 854 } |
| 852 | 855 |
| 853 bool FileAPIMessageFilter::ValidateFileSystemURL( | 856 bool FileAPIMessageFilter::ValidateFileSystemURL( |
| 854 int request_id, const fileapi::FileSystemURL& url) { | 857 int request_id, |
| 858 const storage::FileSystemURL& url) { |
| 855 if (!FileSystemURLIsValid(context_, url)) { | 859 if (!FileSystemURLIsValid(context_, url)) { |
| 856 Send(new FileSystemMsg_DidFail(request_id, | 860 Send(new FileSystemMsg_DidFail(request_id, |
| 857 base::File::FILE_ERROR_INVALID_URL)); | 861 base::File::FILE_ERROR_INVALID_URL)); |
| 858 return false; | 862 return false; |
| 859 } | 863 } |
| 860 | 864 |
| 861 // Deny access to files in PluginPrivate FileSystem from JavaScript. | 865 // Deny access to files in PluginPrivate FileSystem from JavaScript. |
| 862 // TODO(nhiroki): Move this filter somewhere else since this is not for | 866 // TODO(nhiroki): Move this filter somewhere else since this is not for |
| 863 // validation. | 867 // validation. |
| 864 if (url.type() == fileapi::kFileSystemTypePluginPrivate) { | 868 if (url.type() == storage::kFileSystemTypePluginPrivate) { |
| 865 Send(new FileSystemMsg_DidFail(request_id, | 869 Send(new FileSystemMsg_DidFail(request_id, |
| 866 base::File::FILE_ERROR_SECURITY)); | 870 base::File::FILE_ERROR_SECURITY)); |
| 867 return false; | 871 return false; |
| 868 } | 872 } |
| 869 | 873 |
| 870 return true; | 874 return true; |
| 871 } | 875 } |
| 872 | 876 |
| 873 scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) { | 877 scoped_refptr<Stream> FileAPIMessageFilter::GetStreamForURL(const GURL& url) { |
| 874 return stream_context_->registry()->GetStream(url); | 878 return stream_context_->registry()->GetStream(url); |
| 875 } | 879 } |
| 876 | 880 |
| 877 } // namespace content | 881 } // namespace content |
| OLD | NEW |