diff options
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/file_system/file_and_blob_message_filter.cc (renamed from content/browser/file_system/file_system_dispatcher_host.cc) | 199 | ||||
-rw-r--r-- | content/browser/file_system/file_and_blob_message_filter.h (renamed from content/browser/file_system/file_system_dispatcher_host.h) | 43 | ||||
-rw-r--r-- | content/browser/renderer_host/blob_message_filter.cc | 111 | ||||
-rw-r--r-- | content/browser/renderer_host/blob_message_filter.h | 51 | ||||
-rw-r--r-- | content/browser/renderer_host/render_process_host_impl.cc | 8 | ||||
-rw-r--r-- | content/browser/worker_host/worker_process_host.cc | 10 | ||||
-rw-r--r-- | content/content_browser.gypi | 6 |
7 files changed, 171 insertions, 257 deletions
diff --git a/content/browser/file_system/file_system_dispatcher_host.cc b/content/browser/file_system/file_and_blob_message_filter.cc index d1f3119..c05f645 100644 --- a/content/browser/file_system/file_system_dispatcher_host.cc +++ b/content/browser/file_system/file_and_blob_message_filter.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/browser/file_system/file_system_dispatcher_host.h" +#include "content/browser/file_system/file_and_blob_message_filter.h" #include <string> #include <vector> @@ -13,8 +13,10 @@ #include "base/platform_file.h" #include "base/threading/thread.h" #include "base/time.h" +#include "content/browser/child_process_security_policy_impl.h" #include "content/browser/chrome_blob_storage_context.h" #include "content/common/file_system_messages.h" +#include "content/common/webblob_messages.h" #include "content/public/browser/user_metrics.h" #include "googleurl/src/gurl.h" #include "ipc/ipc_platform_file.h" @@ -39,44 +41,39 @@ using fileapi::FileSystemOperationInterface; using webkit_blob::BlobData; using webkit_blob::BlobStorageController; -FileSystemDispatcherHost::FileSystemDispatcherHost( +FileAndBlobMessageFilter::FileAndBlobMessageFilter( + int process_id, net::URLRequestContextGetter* request_context_getter, fileapi::FileSystemContext* file_system_context, ChromeBlobStorageContext* blob_storage_context) - : context_(file_system_context), + : process_id_(process_id), + context_(file_system_context), request_context_getter_(request_context_getter), request_context_(NULL), blob_storage_context_(blob_storage_context) { DCHECK(context_); DCHECK(request_context_getter_); + DCHECK(blob_storage_context); } -FileSystemDispatcherHost::FileSystemDispatcherHost( +FileAndBlobMessageFilter::FileAndBlobMessageFilter( + int process_id, net::URLRequestContext* request_context, fileapi::FileSystemContext* file_system_context, ChromeBlobStorageContext* blob_storage_context) - : context_(file_system_context), + : process_id_(process_id), + context_(file_system_context), request_context_(request_context), blob_storage_context_(blob_storage_context) { DCHECK(context_); DCHECK(request_context_); + DCHECK(blob_storage_context); } -FileSystemDispatcherHost::~FileSystemDispatcherHost() { +FileAndBlobMessageFilter::~FileAndBlobMessageFilter() { } -void FileSystemDispatcherHost::OnChannelClosing() { - BrowserMessageFilter::OnChannelClosing(); - - // Unregister all the blob URLs that are previously registered in this - // process. - for (base::hash_set<std::string>::const_iterator iter = blob_urls_.begin(); - iter != blob_urls_.end(); ++iter) { - blob_storage_context_->controller()->RemoveBlob(GURL(*iter)); - } -} - -void FileSystemDispatcherHost::OnChannelConnected(int32 peer_pid) { +void FileAndBlobMessageFilter::OnChannelConnected(int32 peer_pid) { BrowserMessageFilter::OnChannelConnected(peer_pid); if (request_context_getter_.get()) { @@ -87,18 +84,29 @@ void FileSystemDispatcherHost::OnChannelConnected(int32 peer_pid) { } } -void FileSystemDispatcherHost::OverrideThreadForMessage( +void FileAndBlobMessageFilter::OnChannelClosing() { + BrowserMessageFilter::OnChannelClosing(); + + // Unregister all the blob URLs that are previously registered in this + // process. + for (base::hash_set<std::string>::const_iterator iter = blob_urls_.begin(); + iter != blob_urls_.end(); ++iter) { + blob_storage_context_->controller()->RemoveBlob(GURL(*iter)); + } +} + +void FileAndBlobMessageFilter::OverrideThreadForMessage( const IPC::Message& message, BrowserThread::ID* thread) { if (message.type() == FileSystemHostMsg_SyncGetPlatformPath::ID) *thread = BrowserThread::FILE; } -bool FileSystemDispatcherHost::OnMessageReceived( +bool FileAndBlobMessageFilter::OnMessageReceived( const IPC::Message& message, bool* message_was_ok) { *message_was_ok = true; bool handled = true; - IPC_BEGIN_MESSAGE_MAP_EX(FileSystemDispatcherHost, message, *message_was_ok) + IPC_BEGIN_MESSAGE_MAP_EX(FileAndBlobMessageFilter, message, *message_was_ok) IPC_MESSAGE_HANDLER(FileSystemHostMsg_Open, OnOpen) IPC_MESSAGE_HANDLER(FileSystemHostMsg_Move, OnMove) IPC_MESSAGE_HANDLER(FileSystemHostMsg_Copy, OnCopy) @@ -118,12 +126,19 @@ bool FileSystemDispatcherHost::OnMessageReceived( IPC_MESSAGE_HANDLER(FileSystemHostMsg_DidUpdate, OnDidUpdate) IPC_MESSAGE_HANDLER(FileSystemHostMsg_SyncGetPlatformPath, OnSyncGetPlatformPath) + IPC_MESSAGE_HANDLER(BlobHostMsg_StartBuildingBlob, OnStartBuildingBlob) + IPC_MESSAGE_HANDLER(BlobHostMsg_AppendBlobDataItem, OnAppendBlobDataItem) + IPC_MESSAGE_HANDLER(BlobHostMsg_SyncAppendSharedMemory, + OnAppendSharedMemory) + IPC_MESSAGE_HANDLER(BlobHostMsg_FinishBuildingBlob, OnFinishBuildingBlob) + IPC_MESSAGE_HANDLER(BlobHostMsg_CloneBlob, OnCloneBlob) + IPC_MESSAGE_HANDLER(BlobHostMsg_RemoveBlob, OnRemoveBlob) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() return handled; } -void FileSystemDispatcherHost::OnOpen( +void FileAndBlobMessageFilter::OnOpen( int request_id, const GURL& origin_url, fileapi::FileSystemType type, int64 requested_size, bool create) { if (type == fileapi::kFileSystemTypeTemporary) { @@ -132,72 +147,72 @@ void FileSystemDispatcherHost::OnOpen( content::RecordAction(UserMetricsAction("OpenFileSystemPersistent")); } context_->OpenFileSystem(origin_url, type, create, base::Bind( - &FileSystemDispatcherHost::DidOpenFileSystem, this, request_id)); + &FileAndBlobMessageFilter::DidOpenFileSystem, this, request_id)); } -void FileSystemDispatcherHost::OnMove( +void FileAndBlobMessageFilter::OnMove( int request_id, const GURL& src_path, const GURL& dest_path) { GetNewOperation(src_path, request_id)->Move( src_path, dest_path, - base::Bind(&FileSystemDispatcherHost::DidFinish, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidFinish, this, request_id)); } -void FileSystemDispatcherHost::OnCopy( +void FileAndBlobMessageFilter::OnCopy( int request_id, const GURL& src_path, const GURL& dest_path) { GetNewOperation(src_path, request_id)->Copy( src_path, dest_path, - base::Bind(&FileSystemDispatcherHost::DidFinish, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidFinish, this, request_id)); } -void FileSystemDispatcherHost::OnRemove( +void FileAndBlobMessageFilter::OnRemove( int request_id, const GURL& path, bool recursive) { GetNewOperation(path, request_id)->Remove( path, recursive, - base::Bind(&FileSystemDispatcherHost::DidFinish, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidFinish, this, request_id)); } -void FileSystemDispatcherHost::OnReadMetadata( +void FileAndBlobMessageFilter::OnReadMetadata( int request_id, const GURL& path) { GetNewOperation(path, request_id)->GetMetadata( path, - base::Bind(&FileSystemDispatcherHost::DidGetMetadata, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidGetMetadata, this, request_id)); } -void FileSystemDispatcherHost::OnCreate( +void FileAndBlobMessageFilter::OnCreate( int request_id, const GURL& path, bool exclusive, bool is_directory, bool recursive) { if (is_directory) { GetNewOperation(path, request_id)->CreateDirectory( path, exclusive, recursive, - base::Bind(&FileSystemDispatcherHost::DidFinish, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidFinish, this, request_id)); } else { GetNewOperation(path, request_id)->CreateFile( path, exclusive, - base::Bind(&FileSystemDispatcherHost::DidFinish, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidFinish, this, request_id)); } } -void FileSystemDispatcherHost::OnExists( +void FileAndBlobMessageFilter::OnExists( int request_id, const GURL& path, bool is_directory) { if (is_directory) { GetNewOperation(path, request_id)->DirectoryExists( path, - base::Bind(&FileSystemDispatcherHost::DidFinish, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidFinish, this, request_id)); } else { GetNewOperation(path, request_id)->FileExists( path, - base::Bind(&FileSystemDispatcherHost::DidFinish, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidFinish, this, request_id)); } } -void FileSystemDispatcherHost::OnReadDirectory( +void FileAndBlobMessageFilter::OnReadDirectory( int request_id, const GURL& path) { GetNewOperation(path, request_id)->ReadDirectory( - path, base::Bind(&FileSystemDispatcherHost::DidReadDirectory, + path, base::Bind(&FileAndBlobMessageFilter::DidReadDirectory, this, request_id)); } -void FileSystemDispatcherHost::OnWrite( +void FileAndBlobMessageFilter::OnWrite( int request_id, const GURL& path, const GURL& blob_url, @@ -209,29 +224,29 @@ void FileSystemDispatcherHost::OnWrite( } GetNewOperation(path, request_id)->Write( request_context_, path, blob_url, offset, - base::Bind(&FileSystemDispatcherHost::DidWrite, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidWrite, this, request_id)); } -void FileSystemDispatcherHost::OnTruncate( +void FileAndBlobMessageFilter::OnTruncate( int request_id, const GURL& path, int64 length) { GetNewOperation(path, request_id)->Truncate( path, length, - base::Bind(&FileSystemDispatcherHost::DidFinish, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidFinish, this, request_id)); } -void FileSystemDispatcherHost::OnTouchFile( +void FileAndBlobMessageFilter::OnTouchFile( int request_id, const GURL& path, const base::Time& last_access_time, const base::Time& last_modified_time) { GetNewOperation(path, request_id)->TouchFile( path, last_access_time, last_modified_time, - base::Bind(&FileSystemDispatcherHost::DidFinish, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidFinish, this, request_id)); } -void FileSystemDispatcherHost::OnCancel( +void FileAndBlobMessageFilter::OnCancel( int request_id, int request_id_to_cancel) { FileSystemOperationInterface* write = operations_.Lookup( @@ -240,7 +255,7 @@ void FileSystemDispatcherHost::OnCancel( // The cancel will eventually send both the write failure and the cancel // success. write->Cancel( - base::Bind(&FileSystemDispatcherHost::DidCancel, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidCancel, this, request_id)); } else { // The write already finished; report that we failed to stop it. Send(new FileSystemMsg_DidFail( @@ -248,14 +263,14 @@ void FileSystemDispatcherHost::OnCancel( } } -void FileSystemDispatcherHost::OnOpenFile( +void FileAndBlobMessageFilter::OnOpenFile( int request_id, const GURL& path, int file_flags) { GetNewOperation(path, request_id)->OpenFile( path, file_flags, peer_handle(), - base::Bind(&FileSystemDispatcherHost::DidOpenFile, this, request_id)); + base::Bind(&FileAndBlobMessageFilter::DidOpenFile, this, request_id)); } -void FileSystemDispatcherHost::OnWillUpdate(const GURL& path) { +void FileAndBlobMessageFilter::OnWillUpdate(const GURL& path) { GURL origin_url; fileapi::FileSystemType type; if (!CrackFileSystemURL(path, &origin_url, &type, NULL)) @@ -266,7 +281,7 @@ void FileSystemDispatcherHost::OnWillUpdate(const GURL& path) { quota_util->proxy()->StartUpdateOrigin(origin_url, type); } -void FileSystemDispatcherHost::OnDidUpdate(const GURL& path, int64 delta) { +void FileAndBlobMessageFilter::OnDidUpdate(const GURL& path, int64 delta) { GURL origin_url; fileapi::FileSystemType type; if (!CrackFileSystemURL(path, &origin_url, &type, NULL)) @@ -279,7 +294,7 @@ void FileSystemDispatcherHost::OnDidUpdate(const GURL& path, int64 delta) { quota_util->proxy()->EndUpdateOrigin(origin_url, type); } -void FileSystemDispatcherHost::OnSyncGetPlatformPath( +void FileAndBlobMessageFilter::OnSyncGetPlatformPath( const GURL& path, FilePath* platform_path) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); DCHECK(platform_path); @@ -307,16 +322,72 @@ void FileSystemDispatcherHost::OnSyncGetPlatformPath( operation->SyncGetPlatformPath(path, platform_path); } -void FileSystemDispatcherHost::OnCreateSnapshotFile( +void FileAndBlobMessageFilter::OnCreateSnapshotFile( int request_id, const GURL& blob_url, const GURL& path) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); GetNewOperation(path, request_id)->CreateSnapshotFile( path, - base::Bind(&FileSystemDispatcherHost::DidCreateSnapshot, + base::Bind(&FileAndBlobMessageFilter::DidCreateSnapshot, this, request_id, blob_url)); } -void FileSystemDispatcherHost::DidFinish(int request_id, +void FileAndBlobMessageFilter::OnStartBuildingBlob(const GURL& url) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + blob_storage_context_->controller()->StartBuildingBlob(url); + blob_urls_.insert(url.spec()); +} + +void FileAndBlobMessageFilter::OnAppendBlobDataItem( + const GURL& url, const BlobData::Item& item) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + if (item.type == BlobData::TYPE_FILE && + !ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( + process_id_, item.file_path)) { + OnRemoveBlob(url); + return; + } + blob_storage_context_->controller()->AppendBlobDataItem(url, item); +} + +void FileAndBlobMessageFilter::OnAppendSharedMemory( + const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size) { + DCHECK(base::SharedMemory::IsHandleValid(handle)); +#if defined(OS_WIN) + base::SharedMemory shared_memory(handle, true, peer_handle()); +#else + base::SharedMemory shared_memory(handle, true); +#endif + if (!shared_memory.Map(buffer_size)) { + OnRemoveBlob(url); + return; + } + + BlobData::Item item; + item.SetToDataExternal(static_cast<char*>(shared_memory.memory()), + buffer_size); + blob_storage_context_->controller()->AppendBlobDataItem(url, item); +} + +void FileAndBlobMessageFilter::OnFinishBuildingBlob( + const GURL& url, const std::string& content_type) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + blob_storage_context_->controller()->FinishBuildingBlob(url, content_type); +} + +void FileAndBlobMessageFilter::OnCloneBlob( + const GURL& url, const GURL& src_url) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + blob_storage_context_->controller()->CloneBlob(url, src_url); + blob_urls_.insert(url.spec()); +} + +void FileAndBlobMessageFilter::OnRemoveBlob(const GURL& url) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + blob_storage_context_->controller()->RemoveBlob(url); + blob_urls_.erase(url.spec()); +} + +void FileAndBlobMessageFilter::DidFinish(int request_id, base::PlatformFileError result) { if (result == base::PLATFORM_FILE_OK) Send(new FileSystemMsg_DidSucceed(request_id)); @@ -325,7 +396,7 @@ void FileSystemDispatcherHost::DidFinish(int request_id, UnregisterOperation(request_id); } -void FileSystemDispatcherHost::DidCancel(int request_id, +void FileAndBlobMessageFilter::DidCancel(int request_id, base::PlatformFileError result) { if (result == base::PLATFORM_FILE_OK) Send(new FileSystemMsg_DidSucceed(request_id)); @@ -334,7 +405,7 @@ void FileSystemDispatcherHost::DidCancel(int request_id, // For Cancel we do not create a new operation, so no unregister here. } -void FileSystemDispatcherHost::DidGetMetadata( +void FileAndBlobMessageFilter::DidGetMetadata( int request_id, base::PlatformFileError result, const base::PlatformFileInfo& info, @@ -346,7 +417,7 @@ void FileSystemDispatcherHost::DidGetMetadata( UnregisterOperation(request_id); } -void FileSystemDispatcherHost::DidReadDirectory( +void FileAndBlobMessageFilter::DidReadDirectory( int request_id, base::PlatformFileError result, const std::vector<base::FileUtilProxy::Entry>& entries, @@ -358,7 +429,7 @@ void FileSystemDispatcherHost::DidReadDirectory( UnregisterOperation(request_id); } -void FileSystemDispatcherHost::DidOpenFile(int request_id, +void FileAndBlobMessageFilter::DidOpenFile(int request_id, base::PlatformFileError result, base::PlatformFile file, base::ProcessHandle peer_handle) { @@ -374,7 +445,7 @@ void FileSystemDispatcherHost::DidOpenFile(int request_id, UnregisterOperation(request_id); } -void FileSystemDispatcherHost::DidWrite(int request_id, +void FileAndBlobMessageFilter::DidWrite(int request_id, base::PlatformFileError result, int64 bytes, bool complete) { @@ -388,7 +459,7 @@ void FileSystemDispatcherHost::DidWrite(int request_id, } } -void FileSystemDispatcherHost::DidOpenFileSystem(int request_id, +void FileAndBlobMessageFilter::DidOpenFileSystem(int request_id, base::PlatformFileError result, const std::string& name, const GURL& root) { @@ -401,7 +472,7 @@ void FileSystemDispatcherHost::DidOpenFileSystem(int request_id, // For OpenFileSystem we do not create a new operation, so no unregister here. } -void FileSystemDispatcherHost::DidCreateSnapshot( +void FileAndBlobMessageFilter::DidCreateSnapshot( int request_id, const GURL& blob_url, base::PlatformFileError result, @@ -436,7 +507,7 @@ void FileSystemDispatcherHost::DidCreateSnapshot( Send(new FileSystemMsg_DidReadMetadata(request_id, info, platform_path)); } -FileSystemOperationInterface* FileSystemDispatcherHost::GetNewOperation( +FileSystemOperationInterface* FileAndBlobMessageFilter::GetNewOperation( const GURL& target_path, int request_id) { FileSystemOperationInterface* operation = @@ -448,7 +519,7 @@ FileSystemOperationInterface* FileSystemDispatcherHost::GetNewOperation( return operation; } -void FileSystemDispatcherHost::UnregisterOperation(int request_id) { +void FileAndBlobMessageFilter::UnregisterOperation(int request_id) { DCHECK(operations_.Lookup(request_id)); operations_.Remove(request_id); } diff --git a/content/browser/file_system/file_system_dispatcher_host.h b/content/browser/file_system/file_and_blob_message_filter.h index 040a10a..fb347ac 100644 --- a/content/browser/file_system/file_system_dispatcher_host.h +++ b/content/browser/file_system/file_and_blob_message_filter.h @@ -2,16 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_BROWSER_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_HOST_H_ -#define CONTENT_BROWSER_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_HOST_H_ +#ifndef CONTENT_BROWSER_FILE_SYSTEM_FILE_AND_BLOB_MESSAGE_FILTER_H_ +#define CONTENT_BROWSER_FILE_SYSTEM_FILE_AND_BLOB_MESSAGE_FILTER_H_ -#include <set> +#include <string> #include "base/basictypes.h" #include "base/file_util_proxy.h" +#include "base/hash_tables.h" #include "base/id_map.h" #include "base/platform_file.h" +#include "base/shared_memory.h" #include "content/public/browser/browser_message_filter.h" +#include "webkit/blob/blob_data.h" #include "webkit/fileapi/file_system_types.h" class ChromeBlobStorageContext; @@ -36,23 +39,25 @@ namespace webkit_blob { class DeletableFileReference; } -class FileSystemDispatcherHost : public content::BrowserMessageFilter { +class FileAndBlobMessageFilter : public content::BrowserMessageFilter { public: // Used by the renderer process host on the UI thread. - FileSystemDispatcherHost( + FileAndBlobMessageFilter( + int process_id, net::URLRequestContextGetter* request_context_getter, fileapi::FileSystemContext* file_system_context, ChromeBlobStorageContext* blob_storage_context); // Used by the worker process host on the IO thread. - FileSystemDispatcherHost( + FileAndBlobMessageFilter( + int process_id, net::URLRequestContext* request_context, fileapi::FileSystemContext* file_system_context, ChromeBlobStorageContext* blob_storage_context); - virtual ~FileSystemDispatcherHost(); + virtual ~FileAndBlobMessageFilter(); // content::BrowserMessageFilter implementation. - virtual void OnChannelClosing() OVERRIDE; virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; + virtual void OnChannelClosing() OVERRIDE; virtual void OverrideThreadForMessage( const IPC::Message& message, content::BrowserThread::ID* thread) OVERRIDE; @@ -101,6 +106,15 @@ class FileSystemDispatcherHost : public content::BrowserMessageFilter { const GURL& blob_url, const GURL& path); + void OnStartBuildingBlob(const GURL& url); + void OnAppendBlobDataItem(const GURL& url, + const webkit_blob::BlobData::Item& item); + void OnAppendSharedMemory(const GURL& url, base::SharedMemoryHandle handle, + size_t buffer_size); + void OnFinishBuildingBlob(const GURL& url, const std::string& content_type); + void OnCloneBlob(const GURL& url, const GURL& src_url); + void OnRemoveBlob(const GURL& url); + // Callback functions to be used when each file operation is finished. void DidFinish(int request_id, base::PlatformFileError result); void DidCancel(int request_id, base::PlatformFileError result); @@ -138,6 +152,8 @@ class FileSystemDispatcherHost : public content::BrowserMessageFilter { const GURL& target_path, int request_id); + int process_id_; + fileapi::FileSystemContext* context_; // Keeps ongoing file system operations. @@ -149,16 +165,13 @@ class FileSystemDispatcherHost : public content::BrowserMessageFilter { scoped_refptr<net::URLRequestContextGetter> request_context_getter_; net::URLRequestContext* request_context_; - // We access BlobStorageContext to construct an internal blob for - // snapshot files. scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; - // Keeps track of internal blob URLs for temporary snapshot files. - // (As we do for regular blobs in BlobMessageFilter.) - // TODO(kinuko,tzik): merge this with the one in BlobMessageFilter. + // Keep track of blob URLs registered in this process. Need to unregister + // all of them when the renderer process dies. base::hash_set<std::string> blob_urls_; - DISALLOW_COPY_AND_ASSIGN(FileSystemDispatcherHost); + DISALLOW_COPY_AND_ASSIGN(FileAndBlobMessageFilter); }; -#endif // CONTENT_BROWSER_FILE_SYSTEM_FILE_SYSTEM_DISPATCHER_HOST_H_ +#endif // CONTENT_BROWSER_FILE_SYSTEM_FILE_AND_BLOB_MESSAGE_FILTER_H_ diff --git a/content/browser/renderer_host/blob_message_filter.cc b/content/browser/renderer_host/blob_message_filter.cc deleted file mode 100644 index e227c50..0000000 --- a/content/browser/renderer_host/blob_message_filter.cc +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/browser/renderer_host/blob_message_filter.h" - -#include "content/browser/child_process_security_policy_impl.h" -#include "content/browser/chrome_blob_storage_context.h" -#include "content/common/webblob_messages.h" -#include "googleurl/src/gurl.h" -#include "webkit/blob/blob_data.h" -#include "webkit/blob/blob_storage_controller.h" - -using content::BrowserMessageFilter; -using content::BrowserThread; -using webkit_blob::BlobData; - -BlobMessageFilter::BlobMessageFilter( - int process_id, - ChromeBlobStorageContext* blob_storage_context) - : process_id_(process_id), - blob_storage_context_(blob_storage_context) { -} - -BlobMessageFilter::~BlobMessageFilter() { -} - -void BlobMessageFilter::OnChannelClosing() { - BrowserMessageFilter::OnChannelClosing(); - - // Unregister all the blob URLs that are previously registered in this - // process. - for (base::hash_set<std::string>::const_iterator iter = blob_urls_.begin(); - iter != blob_urls_.end(); ++iter) { - blob_storage_context_->controller()->RemoveBlob(GURL(*iter)); - } -} - -bool BlobMessageFilter::OnMessageReceived(const IPC::Message& message, - bool* message_was_ok) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - - bool handled = true; - IPC_BEGIN_MESSAGE_MAP_EX(BlobMessageFilter, message, *message_was_ok) - IPC_MESSAGE_HANDLER(BlobHostMsg_StartBuildingBlob, OnStartBuildingBlob) - IPC_MESSAGE_HANDLER(BlobHostMsg_AppendBlobDataItem, OnAppendBlobDataItem) - IPC_MESSAGE_HANDLER(BlobHostMsg_SyncAppendSharedMemory, - OnAppendSharedMemory) - IPC_MESSAGE_HANDLER(BlobHostMsg_FinishBuildingBlob, OnFinishBuildingBlob) - IPC_MESSAGE_HANDLER(BlobHostMsg_CloneBlob, OnCloneBlob) - IPC_MESSAGE_HANDLER(BlobHostMsg_RemoveBlob, OnRemoveBlob) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void BlobMessageFilter::OnStartBuildingBlob(const GURL& url) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - blob_storage_context_->controller()->StartBuildingBlob(url); - blob_urls_.insert(url.spec()); -} - -void BlobMessageFilter::OnAppendBlobDataItem( - const GURL& url, const BlobData::Item& item) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (item.type == BlobData::TYPE_FILE && - !ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFile( - process_id_, item.file_path)) { - OnRemoveBlob(url); - return; - } - blob_storage_context_->controller()->AppendBlobDataItem(url, item); -} - -void BlobMessageFilter::OnAppendSharedMemory( - const GURL& url, base::SharedMemoryHandle handle, size_t buffer_size) { - DCHECK(base::SharedMemory::IsHandleValid(handle)); -#if defined(OS_WIN) - base::SharedMemory shared_memory(handle, true, peer_handle()); -#else - base::SharedMemory shared_memory(handle, true); -#endif - if (!shared_memory.Map(buffer_size)) { - OnRemoveBlob(url); - return; - } - - BlobData::Item item; - item.SetToDataExternal(static_cast<char*>(shared_memory.memory()), - buffer_size); - blob_storage_context_->controller()->AppendBlobDataItem(url, item); -} - -void BlobMessageFilter::OnFinishBuildingBlob( - const GURL& url, const std::string& content_type) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - blob_storage_context_->controller()->FinishBuildingBlob(url, content_type); -} - -void BlobMessageFilter::OnCloneBlob( - const GURL& url, const GURL& src_url) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - blob_storage_context_->controller()->CloneBlob(url, src_url); - blob_urls_.insert(url.spec()); -} - -void BlobMessageFilter::OnRemoveBlob(const GURL& url) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - blob_storage_context_->controller()->RemoveBlob(url); - blob_urls_.erase(url.spec()); -} diff --git a/content/browser/renderer_host/blob_message_filter.h b/content/browser/renderer_host/blob_message_filter.h deleted file mode 100644 index d8ddf07..0000000 --- a/content/browser/renderer_host/blob_message_filter.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_BROWSER_RENDERER_HOST_BLOB_MESSAGE_FILTER_H_ -#define CONTENT_BROWSER_RENDERER_HOST_BLOB_MESSAGE_FILTER_H_ - -#include "base/hash_tables.h" -#include "base/shared_memory.h" -#include "content/public/browser/browser_message_filter.h" -#include "webkit/blob/blob_data.h" - -class ChromeBlobStorageContext; -class GURL; - -namespace IPC { -class Message; -} - -class BlobMessageFilter : public content::BrowserMessageFilter { - public: - BlobMessageFilter(int process_id, - ChromeBlobStorageContext* blob_storage_context); - virtual ~BlobMessageFilter(); - - // content::BrowserMessageFilter implementation. - virtual void OnChannelClosing() OVERRIDE; - virtual bool OnMessageReceived(const IPC::Message& message, - bool* message_was_ok) OVERRIDE; - - private: - void OnStartBuildingBlob(const GURL& url); - void OnAppendBlobDataItem(const GURL& url, - const webkit_blob::BlobData::Item& item); - void OnAppendSharedMemory(const GURL& url, base::SharedMemoryHandle handle, - size_t buffer_size); - void OnFinishBuildingBlob(const GURL& url, const std::string& content_type); - void OnCloneBlob(const GURL& url, const GURL& src_url); - void OnRemoveBlob(const GURL& url); - - int process_id_; - scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; - - // Keep track of blob URLs registered in this process. Need to unregister - // all of them when the renderer process dies. - base::hash_set<std::string> blob_urls_; - - DISALLOW_IMPLICIT_CONSTRUCTORS(BlobMessageFilter); -}; - -#endif // CONTENT_BROWSER_RENDERER_HOST_BLOB_MESSAGE_FILTER_H_ diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc index 90dc78d..2717a4e 100644 --- a/content/browser/renderer_host/render_process_host_impl.cc +++ b/content/browser/renderer_host/render_process_host_impl.cc @@ -46,7 +46,7 @@ #include "content/browser/chrome_blob_storage_context.h" #include "content/browser/device_orientation/message_filter.h" #include "content/browser/download/mhtml_generation_manager.h" -#include "content/browser/file_system/file_system_dispatcher_host.h" +#include "content/browser/file_system/file_and_blob_message_filter.h" #include "content/browser/geolocation/geolocation_dispatcher_host.h" #include "content/browser/gpu/gpu_data_manager_impl.h" #include "content/browser/gpu/gpu_process_host.h" @@ -57,7 +57,6 @@ #include "content/browser/mime_registry_message_filter.h" #include "content/browser/plugin_service_impl.h" #include "content/browser/profiler_message_filter.h" -#include "content/browser/renderer_host/blob_message_filter.h" #include "content/browser/renderer_host/clipboard_message_filter.h" #include "content/browser/renderer_host/database_message_filter.h" #include "content/browser/renderer_host/file_utilities_message_filter.h" @@ -500,13 +499,12 @@ void RenderProcessHostImpl::CreateMessageFilters() { browser_context->GetSpeechInputPreferences(), content::BrowserMainLoop::GetAudioManager())); #endif - channel_->AddFilter(new FileSystemDispatcherHost( + channel_->AddFilter(new FileAndBlobMessageFilter( + GetID(), browser_context->GetRequestContext(), BrowserContext::GetFileSystemContext(browser_context), ChromeBlobStorageContext::GetFor(browser_context))); channel_->AddFilter(new device_orientation::MessageFilter()); - channel_->AddFilter(new BlobMessageFilter(GetID(), - ChromeBlobStorageContext::GetFor(browser_context))); channel_->AddFilter(new FileUtilitiesMessageFilter(GetID())); channel_->AddFilter(new MimeRegistryMessageFilter()); channel_->AddFilter(new DatabaseMessageFilter( diff --git a/content/browser/worker_host/worker_process_host.cc b/content/browser/worker_host/worker_process_host.cc index 39e1a8e..647ee82 100644 --- a/content/browser/worker_host/worker_process_host.cc +++ b/content/browser/worker_host/worker_process_host.cc @@ -22,10 +22,9 @@ #include "content/browser/child_process_security_policy_impl.h" #include "content/browser/debugger/worker_devtools_manager.h" #include "content/browser/debugger/worker_devtools_message_filter.h" -#include "content/browser/file_system/file_system_dispatcher_host.h" +#include "content/browser/file_system/file_and_blob_message_filter.h" #include "content/browser/in_process_webkit/indexed_db_dispatcher_host.h" #include "content/browser/mime_registry_message_filter.h" -#include "content/browser/renderer_host/blob_message_filter.h" #include "content/browser/renderer_host/database_message_filter.h" #include "content/browser/renderer_host/file_utilities_message_filter.h" #include "content/browser/renderer_host/render_view_host.h" @@ -263,17 +262,14 @@ void WorkerProcessHost::CreateMessageFilters(int render_process_id) { static_cast<ChromeAppCacheService*>( ResourceContext::GetAppCacheService(resource_context_)), process_->GetData().id)); - process_->GetHost()->AddFilter(new FileSystemDispatcherHost( + process_->GetHost()->AddFilter(new FileAndBlobMessageFilter( + process_->GetData().id, request_context, ResourceContext::GetFileSystemContext(resource_context_), content::GetChromeBlobStorageContextForResourceContext( resource_context_))); process_->GetHost()->AddFilter(new FileUtilitiesMessageFilter( process_->GetData().id)); - process_->GetHost()->AddFilter(new BlobMessageFilter( - process_->GetData().id, - content::GetChromeBlobStorageContextForResourceContext( - resource_context_))); process_->GetHost()->AddFilter(new MimeRegistryMessageFilter()); process_->GetHost()->AddFilter(new DatabaseMessageFilter( content::GetDatabaseTrackerForResourceContext(resource_context_))); diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 9e56c02..093e816 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -263,8 +263,8 @@ 'browser/file_metadata_mac.mm', 'browser/file_system/browser_file_system_helper.cc', 'browser/file_system/browser_file_system_helper.h', - 'browser/file_system/file_system_dispatcher_host.cc', - 'browser/file_system/file_system_dispatcher_host.h', + 'browser/file_system/file_and_blob_message_filter.cc', + 'browser/file_system/file_and_blob_message_filter.h', 'browser/find_pasteboard.h', 'browser/find_pasteboard.mm', 'browser/font_list_async.cc', @@ -435,8 +435,6 @@ 'browser/renderer_host/backing_store_skia.h', 'browser/renderer_host/backing_store_win.cc', 'browser/renderer_host/backing_store_win.h', - 'browser/renderer_host/blob_message_filter.cc', - 'browser/renderer_host/blob_message_filter.h', 'browser/renderer_host/buffered_resource_handler.cc', 'browser/renderer_host/buffered_resource_handler.h', 'browser/renderer_host/clipboard_message_filter.cc', |