summaryrefslogtreecommitdiffstats
path: root/chrome/browser/renderer_host
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-13 17:00:42 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-13 17:00:42 +0000
commit9f547bfd7465f0bcb29ab1d0225dddf81e7ebed8 (patch)
treeb9991ef261fb6107a25947da1231c36e70919bd1 /chrome/browser/renderer_host
parentdc8caba097e35e536697f3bf6605257317640d26 (diff)
downloadchromium_src-9f547bfd7465f0bcb29ab1d0225dddf81e7ebed8.zip
chromium_src-9f547bfd7465f0bcb29ab1d0225dddf81e7ebed8.tar.gz
chromium_src-9f547bfd7465f0bcb29ab1d0225dddf81e7ebed8.tar.bz2
Switch a bunch of remaining filters to derive from BrowserMessageFilters so that ResourceMessageFilter doesn't have to know about them and vice versa. A bunch of small cleanup in the process. I've added new message files for classes that want their messages dispatched on threads other than the IO.
Review URL: http://codereview.chromium.org/5698008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69008 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
-rw-r--r--chrome/browser/renderer_host/blob_message_filter.cc (renamed from chrome/browser/renderer_host/blob_dispatcher_host.cc)27
-rw-r--r--chrome/browser/renderer_host/blob_message_filter.h (renamed from chrome/browser/renderer_host/blob_dispatcher_host.h)24
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc16
-rw-r--r--chrome/browser/renderer_host/file_utilities_dispatcher_host.cc199
-rw-r--r--chrome/browser/renderer_host/file_utilities_dispatcher_host.h63
-rw-r--r--chrome/browser/renderer_host/file_utilities_message_filter.cc106
-rw-r--r--chrome/browser/renderer_host/file_utilities_message_filter.h48
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc50
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h37
9 files changed, 197 insertions, 373 deletions
diff --git a/chrome/browser/renderer_host/blob_dispatcher_host.cc b/chrome/browser/renderer_host/blob_message_filter.cc
index 1946b68..d31d5f7 100644
--- a/chrome/browser/renderer_host/blob_dispatcher_host.cc
+++ b/chrome/browser/renderer_host/blob_message_filter.cc
@@ -2,29 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/renderer_host/blob_dispatcher_host.h"
+#include "chrome/browser/renderer_host/blob_message_filter.h"
-#include "chrome/browser/browser_thread.h"
#include "chrome/browser/child_process_security_policy.h"
#include "chrome/browser/chrome_blob_storage_context.h"
#include "chrome/common/render_messages.h"
#include "googleurl/src/gurl.h"
-#include "ipc/ipc_message.h"
#include "webkit/blob/blob_data.h"
#include "webkit/blob/blob_storage_controller.h"
-BlobDispatcherHost::BlobDispatcherHost(
+BlobMessageFilter::BlobMessageFilter(
int process_id,
ChromeBlobStorageContext* blob_storage_context)
: process_id_(process_id),
blob_storage_context_(blob_storage_context) {
}
-BlobDispatcherHost::~BlobDispatcherHost() {
+BlobMessageFilter::~BlobMessageFilter() {
}
-void BlobDispatcherHost::Shutdown() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+void BlobMessageFilter::OnChannelClosing() {
+ BrowserMessageFilter::OnChannelClosing();
// Unregister all the blob URLs that are previously registered in this
// process.
@@ -34,13 +32,12 @@ void BlobDispatcherHost::Shutdown() {
}
}
-bool BlobDispatcherHost::OnMessageReceived(const IPC::Message& message,
- bool* msg_is_ok) {
+bool BlobMessageFilter::OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- *msg_is_ok = true;
bool handled = true;
- IPC_BEGIN_MESSAGE_MAP_EX(BlobDispatcherHost, message, *msg_is_ok)
+ IPC_BEGIN_MESSAGE_MAP_EX(BlobMessageFilter, message, *message_was_ok)
IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterBlobUrl, OnRegisterBlobUrl)
IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterBlobUrlFrom, OnRegisterBlobUrlFrom)
IPC_MESSAGE_HANDLER(ViewHostMsg_UnregisterBlobUrl, OnUnregisterBlobUrl)
@@ -50,7 +47,7 @@ bool BlobDispatcherHost::OnMessageReceived(const IPC::Message& message,
}
// Check if the child process has been granted permission to register the files.
-bool BlobDispatcherHost::CheckPermission(
+bool BlobMessageFilter::CheckPermission(
webkit_blob::BlobData* blob_data) const {
ChildProcessSecurityPolicy* policy =
ChildProcessSecurityPolicy::GetInstance();
@@ -65,7 +62,7 @@ bool BlobDispatcherHost::CheckPermission(
return true;
}
-void BlobDispatcherHost::OnRegisterBlobUrl(
+void BlobMessageFilter::OnRegisterBlobUrl(
const GURL& url, const scoped_refptr<webkit_blob::BlobData>& blob_data) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!CheckPermission(blob_data.get()))
@@ -74,14 +71,14 @@ void BlobDispatcherHost::OnRegisterBlobUrl(
blob_urls_.insert(url.spec());
}
-void BlobDispatcherHost::OnRegisterBlobUrlFrom(
+void BlobMessageFilter::OnRegisterBlobUrlFrom(
const GURL& url, const GURL& src_url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
blob_storage_context_->controller()->RegisterBlobUrlFrom(url, src_url);
blob_urls_.insert(url.spec());
}
-void BlobDispatcherHost::OnUnregisterBlobUrl(const GURL& url) {
+void BlobMessageFilter::OnUnregisterBlobUrl(const GURL& url) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
blob_storage_context_->controller()->UnregisterBlobUrl(url);
blob_urls_.erase(url.spec());
diff --git a/chrome/browser/renderer_host/blob_dispatcher_host.h b/chrome/browser/renderer_host/blob_message_filter.h
index 8ba95ff..2809763 100644
--- a/chrome/browser/renderer_host/blob_dispatcher_host.h
+++ b/chrome/browser/renderer_host/blob_message_filter.h
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_RENDERER_HOST_BLOB_DISPATCHER_HOST_H_
-#define CHROME_BROWSER_RENDERER_HOST_BLOB_DISPATCHER_HOST_H_
+#ifndef CHROME_BROWSER_RENDERER_HOST_BLOB_MESSAGE_FILTER_H_
+#define CHROME_BROWSER_RENDERER_HOST_BLOB_MESSAGE_FILTER_H_
#include "base/hash_tables.h"
-#include "base/ref_counted.h"
+#include "chrome/browser/browser_message_filter.h"
class ChromeBlobStorageContext;
class GURL;
@@ -19,14 +19,16 @@ namespace webkit_blob {
class BlobData;
}
-class BlobDispatcherHost {
+class BlobMessageFilter : public BrowserMessageFilter {
public:
- BlobDispatcherHost(int process_id,
- ChromeBlobStorageContext* blob_storage_context);
- ~BlobDispatcherHost();
+ BlobMessageFilter(int process_id,
+ ChromeBlobStorageContext* blob_storage_context);
+ ~BlobMessageFilter();
- void Shutdown();
- bool OnMessageReceived(const IPC::Message& message, bool* msg_is_ok);
+ // BrowserMessageFilter implementation.
+ virtual void OnChannelClosing();
+ virtual bool OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok);
private:
void OnRegisterBlobUrl(const GURL& url,
@@ -43,7 +45,7 @@ class BlobDispatcherHost {
// all of them when the renderer process dies.
base::hash_set<std::string> blob_urls_;
- DISALLOW_IMPLICIT_CONSTRUCTORS(BlobDispatcherHost);
+ DISALLOW_IMPLICIT_CONSTRUCTORS(BlobMessageFilter);
};
-#endif // CHROME_BROWSER_RENDERER_HOST_BLOB_DISPATCHER_HOST_H_
+#endif // CHROME_BROWSER_RENDERER_HOST_BLOB_MESSAGE_FILTER_H_
diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index 7e85058..3a46d65 100644
--- a/chrome/browser/renderer_host/browser_render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -30,18 +30,23 @@
#include "chrome/browser/browser_child_process_host.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/child_process_security_policy.h"
+#include "chrome/browser/device_orientation/message_filter.h"
#include "chrome/browser/extensions/extension_event_router.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
#include "chrome/browser/extensions/extension_message_service.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/extensions/user_script_master.h"
+#include "chrome/browser/file_system/file_system_dispatcher_host.h"
#include "chrome/browser/gpu_process_host.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/io_thread.h"
+#include "chrome/browser/mime_registry_message_filter.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/plugin_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/renderer_host/audio_renderer_host.h"
+#include "chrome/browser/renderer_host/blob_message_filter.h"
+#include "chrome/browser/renderer_host/file_utilities_message_filter.h"
#include "chrome/browser/renderer_host/pepper_file_message_filter.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
@@ -50,6 +55,8 @@
#include "chrome/browser/renderer_host/resource_message_filter.h"
#include "chrome/browser/renderer_host/web_cache_manager.h"
#include "chrome/browser/safe_browsing/client_side_detection_service.h"
+#include "chrome/browser/search_engines/search_provider_install_state_message_filter.h"
+#include "chrome/browser/speech/speech_input_dispatcher_host.h"
#include "chrome/browser/spellcheck_host.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/visitedlink/visitedlink_master.h"
@@ -389,6 +396,15 @@ void BrowserRenderProcessHost::CreateMessageFilters() {
channel_->AddFilter(
new AppCacheDispatcherHost(profile()->GetRequestContext(), id()));
channel_->AddFilter(new PepperFileMessageFilter(id(), profile()));
+ channel_->AddFilter(new speech_input::SpeechInputDispatcherHost(id()));
+ channel_->AddFilter(
+ new SearchProviderInstallStateMessageFilter(id(), profile()));
+ channel_->AddFilter(new FileSystemDispatcherHost(profile()));
+ channel_->AddFilter(new device_orientation::MessageFilter());
+ channel_->AddFilter(
+ new BlobMessageFilter(id(), profile()->GetBlobStorageContext()));
+ channel_->AddFilter(new FileUtilitiesMessageFilter(id()));
+ channel_->AddFilter(new MimeRegistryMessageFilter());
}
int BrowserRenderProcessHost::GetNextRoutingID() {
diff --git a/chrome/browser/renderer_host/file_utilities_dispatcher_host.cc b/chrome/browser/renderer_host/file_utilities_dispatcher_host.cc
deleted file mode 100644
index ad6fe97..0000000
--- a/chrome/browser/renderer_host/file_utilities_dispatcher_host.cc
+++ /dev/null
@@ -1,199 +0,0 @@
-// Copyright (c) 2010 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 "chrome/browser/renderer_host/file_utilities_dispatcher_host.h"
-
-#include "base/file_util.h"
-#include "base/platform_file.h"
-#include "chrome/browser/child_process_security_policy.h"
-#include "chrome/browser/browser_thread.h"
-#include "chrome/common/render_messages.h"
-#include "chrome/common/render_messages_params.h"
-
-namespace {
-
-void WriteFileSize(IPC::Message* reply_msg,
- const base::PlatformFileInfo& file_info) {
- ViewHostMsg_GetFileSize::WriteReplyParams(reply_msg, file_info.size);
-}
-
-void WriteFileModificationTime(IPC::Message* reply_msg,
- const base::PlatformFileInfo& file_info) {
- ViewHostMsg_GetFileModificationTime::WriteReplyParams(
- reply_msg, file_info.last_modified);
-}
-
-} // namespace
-
-FileUtilitiesDispatcherHost::FileUtilitiesDispatcherHost(
- IPC::Message::Sender* sender, int process_id)
- : message_sender_(sender),
- process_id_(process_id),
- process_handle_(0),
- shutdown_(false) {
- DCHECK(message_sender_);
-}
-
-FileUtilitiesDispatcherHost::~FileUtilitiesDispatcherHost() {
-}
-
-void FileUtilitiesDispatcherHost::Init(base::ProcessHandle process_handle) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- DCHECK(!shutdown_);
- DCHECK(!process_handle_);
- DCHECK(process_handle);
- process_handle_ = process_handle;
-}
-
-void FileUtilitiesDispatcherHost::Shutdown() {
- message_sender_ = NULL;
- shutdown_ = true;
-}
-
-bool FileUtilitiesDispatcherHost::OnMessageReceived(
- const IPC::Message& message) {
- DCHECK(!shutdown_);
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(FileUtilitiesDispatcherHost, message)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetFileSize, OnGetFileSize)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetFileModificationTime,
- OnGetFileModificationTime)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_OpenFile, OnOpenFile)
- IPC_MESSAGE_UNHANDLED((handled = false))
- IPC_END_MESSAGE_MAP()
- return handled;
-}
-
-void FileUtilitiesDispatcherHost::OnGetFileSize(
- const FilePath& path, IPC::Message* reply_msg) {
- // Get file size only when the child process has been granted permission to
- // upload the file.
- if (!ChildProcessSecurityPolicy::GetInstance()->CanReadFile(
- process_id_, path)) {
- ViewHostMsg_GetFileSize::WriteReplyParams(
- reply_msg, static_cast<int64>(-1));
- Send(reply_msg);
- return;
- }
-
- // Getting file size could take long time if it lives on a network share,
- // so run it on FILE thread.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- this, &FileUtilitiesDispatcherHost::OnGetFileInfoOnFileThread, path,
- reply_msg, &WriteFileSize));
-}
-
-void FileUtilitiesDispatcherHost::OnGetFileModificationTime(
- const FilePath& path, IPC::Message* reply_msg) {
- // Get file modification time only when the child process has been granted
- // permission to upload the file.
- if (!ChildProcessSecurityPolicy::GetInstance()->CanReadFile(
- process_id_, path)) {
- ViewHostMsg_GetFileModificationTime::WriteReplyParams(reply_msg,
- base::Time());
- Send(reply_msg);
- return;
- }
-
- // Getting file modification time could take a long time if it lives on a
- // network share, so run it on the FILE thread.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- this, &FileUtilitiesDispatcherHost::OnGetFileInfoOnFileThread,
- path, reply_msg, &WriteFileModificationTime));
-}
-
-void FileUtilitiesDispatcherHost::OnGetFileInfoOnFileThread(
- const FilePath& path,
- IPC::Message* reply_msg,
- FileInfoWriteFunc write_func) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
-
- base::PlatformFileInfo file_info;
- file_info.size = 0;
- file_util::GetFileInfo(path, &file_info);
-
- (*write_func)(reply_msg, file_info);
-
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this, &FileUtilitiesDispatcherHost::Send, reply_msg));
-}
-
-void FileUtilitiesDispatcherHost::OnOpenFile(
- const FilePath& path, int mode, IPC::Message* reply_msg) {
- // Open the file only when the child process has been granted permission to
- // upload the file.
- // TODO(jianli): Do we need separate permission to control opening the file?
- if (!ChildProcessSecurityPolicy::GetInstance()->CanReadFile(
- process_id_, path)) {
- ViewHostMsg_OpenFile::WriteReplyParams(
- reply_msg,
-#if defined(OS_WIN)
- base::kInvalidPlatformFileValue
-#elif defined(OS_POSIX)
- base::FileDescriptor(base::kInvalidPlatformFileValue, true)
-#endif
- );
- Send(reply_msg);
- return;
- }
-
- // Opening the file could take a long time if it lives on a network share,
- // so run it on the FILE thread.
- BrowserThread::PostTask(
- BrowserThread::FILE, FROM_HERE,
- NewRunnableMethod(
- this, &FileUtilitiesDispatcherHost::OnOpenFileOnFileThread,
- path, mode, reply_msg));
-}
-
-void FileUtilitiesDispatcherHost::OnOpenFileOnFileThread(
- const FilePath& path, int mode, IPC::Message* reply_msg) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
-
- base::PlatformFile file_handle = base::CreatePlatformFile(
- path,
- (mode == 0) ? (base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ)
- : (base::PLATFORM_FILE_CREATE_ALWAYS |
- base::PLATFORM_FILE_WRITE),
- NULL, NULL);
-
- base::PlatformFile target_file_handle;
-#if defined(OS_WIN)
- // Duplicate the file handle so that the renderer process can access the file.
- if (!DuplicateHandle(GetCurrentProcess(), file_handle,
- process_handle_, &target_file_handle, 0, false,
- DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
- // file_handle is closed whether or not DuplicateHandle succeeds.
- target_file_handle = INVALID_HANDLE_VALUE;
- }
-#else
- target_file_handle = file_handle;
-#endif
-
- ViewHostMsg_OpenFile::WriteReplyParams(
- reply_msg,
-#if defined(OS_WIN)
- target_file_handle
-#elif defined(OS_POSIX)
- base::FileDescriptor(target_file_handle, true)
-#endif
- );
-
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- NewRunnableMethod(this, &FileUtilitiesDispatcherHost::Send, reply_msg));
-}
-
-void FileUtilitiesDispatcherHost::Send(IPC::Message* message) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (!shutdown_ && message_sender_)
- message_sender_->Send(message);
- else
- delete message;
-}
diff --git a/chrome/browser/renderer_host/file_utilities_dispatcher_host.h b/chrome/browser/renderer_host/file_utilities_dispatcher_host.h
deleted file mode 100644
index b62aff5..0000000
--- a/chrome/browser/renderer_host/file_utilities_dispatcher_host.h
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright (c) 2010 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 CHROME_BROWSER_RENDERER_HOST_FILE_UTILITIES_DISPATCHER_HOST_H_
-#define CHROME_BROWSER_RENDERER_HOST_FILE_UTILITIES_DISPATCHER_HOST_H_
-
-#include "base/basictypes.h"
-#include "base/file_path.h"
-#include "base/process.h"
-#include "base/ref_counted.h"
-#include "ipc/ipc_message.h"
-
-namespace base {
-struct PlatformFileInfo;
-}
-
-namespace IPC {
-class Message;
-}
-
-class FileUtilitiesDispatcherHost
- : public base::RefCountedThreadSafe<FileUtilitiesDispatcherHost> {
- public:
- FileUtilitiesDispatcherHost(IPC::Message::Sender* sender, int process_id);
- void Init(base::ProcessHandle process_handle);
- void Shutdown();
- bool OnMessageReceived(const IPC::Message& message);
-
- void Send(IPC::Message* message);
-
- private:
- friend class base::RefCountedThreadSafe<FileUtilitiesDispatcherHost>;
- ~FileUtilitiesDispatcherHost();
-
- typedef void (*FileInfoWriteFunc)(IPC::Message* reply_msg,
- const base::PlatformFileInfo& file_info);
-
- void OnGetFileSize(const FilePath& path, IPC::Message* reply_msg);
- void OnGetFileModificationTime(const FilePath& path, IPC::Message* reply_msg);
- void OnGetFileInfoOnFileThread(const FilePath& path,
- IPC::Message* reply_msg,
- FileInfoWriteFunc write_func);
- void OnOpenFile(const FilePath& path, int mode,IPC::Message* reply_msg);
- void OnOpenFileOnFileThread(const FilePath& path,
- int mode,
- IPC::Message* reply_msg);
-
- // The sender to be used for sending out IPC messages.
- IPC::Message::Sender* message_sender_;
-
- // The ID of this process.
- int process_id_;
-
- // The handle of this process.
- base::ProcessHandle process_handle_;
-
- bool shutdown_;
-
- DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilitiesDispatcherHost);
-};
-
-#endif // CHROME_BROWSER_RENDERER_HOST_FILE_UTILITIES_DISPATCHER_HOST_H_
diff --git a/chrome/browser/renderer_host/file_utilities_message_filter.cc b/chrome/browser/renderer_host/file_utilities_message_filter.cc
new file mode 100644
index 0000000..f49c634
--- /dev/null
+++ b/chrome/browser/renderer_host/file_utilities_message_filter.cc
@@ -0,0 +1,106 @@
+// Copyright (c) 2010 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 "chrome/browser/renderer_host/file_utilities_message_filter.h"
+
+#include "base/file_util.h"
+#include "chrome/browser/child_process_security_policy.h"
+#include "chrome/common/file_utilities_messages.h"
+
+
+FileUtilitiesMessageFilter::FileUtilitiesMessageFilter(int process_id)
+ : process_id_(process_id) {
+}
+
+FileUtilitiesMessageFilter::~FileUtilitiesMessageFilter() {
+}
+
+void FileUtilitiesMessageFilter::OverrideThreadForMessage(
+ const IPC::Message& message,
+ BrowserThread::ID* thread) {
+ if (IPC_MESSAGE_CLASS(message) == FileUtilitiesMsgStart)
+ *thread = BrowserThread::FILE;
+}
+
+bool FileUtilitiesMessageFilter::OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(FileUtilitiesMessageFilter, message, *message_was_ok)
+ IPC_MESSAGE_HANDLER(FileUtilitiesMsg_GetFileSize, OnGetFileSize)
+ IPC_MESSAGE_HANDLER(FileUtilitiesMsg_GetFileModificationTime,
+ OnGetFileModificationTime)
+ IPC_MESSAGE_HANDLER(FileUtilitiesMsg_OpenFile, OnOpenFile)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+void FileUtilitiesMessageFilter::OnGetFileSize(const FilePath& path,
+ int64* result) {
+ // Get file size only when the child process has been granted permission to
+ // upload the file.
+ if (!ChildProcessSecurityPolicy::GetInstance()->CanReadFile(
+ process_id_, path)) {
+ *result = -1;
+ return;
+ }
+
+ base::PlatformFileInfo file_info;
+ file_info.size = 0;
+ file_util::GetFileInfo(path, &file_info);
+ *result = file_info.size;
+}
+
+void FileUtilitiesMessageFilter::OnGetFileModificationTime(
+ const FilePath& path, base::Time* result) {
+ // Get file modification time only when the child process has been granted
+ // permission to upload the file.
+ if (!ChildProcessSecurityPolicy::GetInstance()->CanReadFile(
+ process_id_, path)) {
+ *result = base::Time();
+ return;
+ }
+
+ base::PlatformFileInfo file_info;
+ file_info.size = 0;
+ file_util::GetFileInfo(path, &file_info);
+ *result = file_info.last_modified;
+}
+
+void FileUtilitiesMessageFilter::OnOpenFile(
+ const FilePath& path,
+ int mode,
+ IPC::PlatformFileForTransit* result) {
+ // Open the file only when the child process has been granted permission to
+ // upload the file.
+ // TODO(jianli): Do we need separate permission to control opening the file?
+ if (!ChildProcessSecurityPolicy::GetInstance()->CanReadFile(
+ process_id_, path)) {
+#if defined(OS_WIN)
+ *result = base::kInvalidPlatformFileValue;
+#elif defined(OS_POSIX)
+ *result = base::FileDescriptor(base::kInvalidPlatformFileValue, true);
+#endif
+ return;
+ }
+
+ base::PlatformFile file_handle = base::CreatePlatformFile(
+ path,
+ (mode == 0) ? (base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ)
+ : (base::PLATFORM_FILE_CREATE_ALWAYS |
+ base::PLATFORM_FILE_WRITE),
+ NULL, NULL);
+
+#if defined(OS_WIN)
+ // Duplicate the file handle so that the renderer process can access the file.
+ if (!DuplicateHandle(GetCurrentProcess(), file_handle,
+ peer_handle(), result, 0, false,
+ DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
+ // file_handle is closed whether or not DuplicateHandle succeeds.
+ *result = INVALID_HANDLE_VALUE;
+ }
+#else
+ *result = base::FileDescriptor(file_handle, true);
+#endif
+}
diff --git a/chrome/browser/renderer_host/file_utilities_message_filter.h b/chrome/browser/renderer_host/file_utilities_message_filter.h
new file mode 100644
index 0000000..9a1c9af
--- /dev/null
+++ b/chrome/browser/renderer_host/file_utilities_message_filter.h
@@ -0,0 +1,48 @@
+// Copyright (c) 2010 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 CHROME_BROWSER_RENDERER_HOST_FILE_UTILITIES_MESSAGE_FILTER_H_
+#define CHROME_BROWSER_RENDERER_HOST_FILE_UTILITIES_MESSAGE_FILTER_H_
+
+#include "base/basictypes.h"
+#include "base/file_path.h"
+#include "chrome/browser/browser_message_filter.h"
+#include "ipc/ipc_platform_file.h"
+
+namespace base {
+struct PlatformFileInfo;
+}
+
+namespace IPC {
+class Message;
+}
+
+class FileUtilitiesMessageFilter : public BrowserMessageFilter {
+ public:
+ explicit FileUtilitiesMessageFilter(int process_id);
+
+ // BrowserMessageFilter implementation.
+ virtual void OverrideThreadForMessage(const IPC::Message& message,
+ BrowserThread::ID* thread);
+ virtual bool OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok);
+ private:
+ ~FileUtilitiesMessageFilter();
+
+ typedef void (*FileInfoWriteFunc)(IPC::Message* reply_msg,
+ const base::PlatformFileInfo& file_info);
+
+ void OnGetFileSize(const FilePath& path, int64* result);
+ void OnGetFileModificationTime(const FilePath& path, base::Time* result);
+ void OnOpenFile(const FilePath& path,
+ int mode,
+ IPC::PlatformFileForTransit* result);
+
+ // The ID of this process.
+ int process_id_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(FileUtilitiesMessageFilter);
+};
+
+#endif // CHROME_BROWSER_RENDERER_HOST_FILE_UTILITIES_MESSAGE_FILTER_H_
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index a745d91f..d762bfb 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -19,10 +19,8 @@
#include "chrome/browser/child_process_security_policy.h"
#include "chrome/browser/chrome_plugin_browsing_context.h"
#include "chrome/browser/clipboard_dispatcher.h"
-#include "chrome/browser/device_orientation/dispatcher_host.h"
#include "chrome/browser/download/download_types.h"
#include "chrome/browser/extensions/extension_message_service.h"
-#include "chrome/browser/file_system/file_system_dispatcher_host.h"
#include "chrome/browser/geolocation/geolocation_dispatcher_host_old.h"
#include "chrome/browser/geolocation/geolocation_permission_context.h"
#include "chrome/browser/gpu_process_host.h"
@@ -30,7 +28,6 @@
#include "chrome/browser/in_process_webkit/dom_storage_dispatcher_host.h"
#include "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h"
#include "chrome/browser/metrics/histogram_synchronizer.h"
-#include "chrome/browser/mime_registry_dispatcher.h"
#include "chrome/browser/nacl_host/nacl_process_host.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/net/predictor_api.h"
@@ -43,15 +40,11 @@
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/printing/printer_query.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/renderer_host/blob_dispatcher_host.h"
#include "chrome/browser/renderer_host/browser_render_process_host.h"
#include "chrome/browser/renderer_host/database_dispatcher_host.h"
-#include "chrome/browser/renderer_host/file_utilities_dispatcher_host.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/renderer_host/render_view_host_notification_task.h"
#include "chrome/browser/renderer_host/render_widget_helper.h"
-#include "chrome/browser/search_engines/search_provider_install_state_dispatcher_host.h"
-#include "chrome/browser/speech/speech_input_dispatcher_host.h"
#include "chrome/browser/spellchecker_platform_engine.h"
#include "chrome/browser/task_manager/task_manager.h"
#include "chrome/browser/worker_host/message_port_dispatcher.h"
@@ -268,26 +261,9 @@ ResourceMessageFilter::ResourceMessageFilter(
off_the_record_(profile->IsOffTheRecord()),
next_route_id_callback_(NewCallbackWithReturnValue(
render_widget_helper, &RenderWidgetHelper::GetNextRoutingID)),
- ALLOW_THIS_IN_INITIALIZER_LIST(speech_input_dispatcher_host_(
- new speech_input::SpeechInputDispatcherHost(this->id()))),
ALLOW_THIS_IN_INITIALIZER_LIST(geolocation_dispatcher_host_(
GeolocationDispatcherHostOld::New(
- this->id(), profile->GetGeolocationPermissionContext()))),
- ALLOW_THIS_IN_INITIALIZER_LIST(
- search_provider_install_state_dispatcher_host_(
- new SearchProviderInstallStateDispatcherHost(this, profile,
- child_id))),
- ALLOW_THIS_IN_INITIALIZER_LIST(device_orientation_dispatcher_host_(
- new device_orientation::DispatcherHost(this->id()))),
- ALLOW_THIS_IN_INITIALIZER_LIST(file_system_dispatcher_host_(
- new FileSystemDispatcherHost(this, profile))),
- ALLOW_THIS_IN_INITIALIZER_LIST(blob_dispatcher_host_(
- new BlobDispatcherHost(
- this->id(), profile->GetBlobStorageContext()))),
- ALLOW_THIS_IN_INITIALIZER_LIST(file_utilities_dispatcher_host_(
- new FileUtilitiesDispatcherHost(this, this->id()))),
- ALLOW_THIS_IN_INITIALIZER_LIST(mime_registry_dispatcher_(
- new MimeRegistryDispatcher(this))) {
+ this->id(), profile->GetGeolocationPermissionContext()))) {
request_context_ = profile_->GetRequestContext();
DCHECK(request_context_);
DCHECK(media_request_context_);
@@ -315,18 +291,6 @@ ResourceMessageFilter::~ResourceMessageFilter() {
// Shut down the database dispatcher host.
db_dispatcher_host_->Shutdown();
- // Shut down the async file_system dispatcher host.
- file_system_dispatcher_host_->Shutdown();
-
- // Shut down the blob dispatcher host.
- blob_dispatcher_host_->Shutdown();
-
- // Shut down the async file_utilities dispatcher host.
- file_utilities_dispatcher_host_->Shutdown();
-
- // Shut down the mime registry dispatcher host.
- mime_registry_dispatcher_->Shutdown();
-
// Let interested observers know we are being deleted.
NotificationService::current()->Notify(
NotificationType::RESOURCE_MESSAGE_FILTER_SHUTDOWN,
@@ -357,8 +321,6 @@ void ResourceMessageFilter::OnChannelConnected(int32 peer_pid) {
dom_storage_dispatcher_host_->Init(id(), handle());
indexed_db_dispatcher_host_->Init(id(), handle());
db_dispatcher_host_->Init(handle());
- file_system_dispatcher_host_->Init(handle());
- file_utilities_dispatcher_host_->Init(handle());
}
void ResourceMessageFilter::OnChannelError() {
@@ -388,15 +350,7 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) {
db_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) ||
mp_dispatcher->OnMessageReceived(
msg, this, next_route_id_callback(), &msg_is_ok) ||
- geolocation_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) ||
- speech_input_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) ||
- search_provider_install_state_dispatcher_host_->OnMessageReceived(
- msg, &msg_is_ok) ||
- device_orientation_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) ||
- file_system_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) ||
- blob_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) ||
- file_utilities_dispatcher_host_->OnMessageReceived(msg) ||
- mime_registry_dispatcher_->OnMessageReceived(msg);
+ geolocation_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) ;
if (!handled) {
DCHECK(msg_is_ok); // It should have been marked handled if it wasn't OK.
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index ce23137..9986262 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -31,22 +31,17 @@
#include "third_party/WebKit/WebKit/chromium/public/WebCache.h"
#include "third_party/WebKit/WebKit/chromium/public/WebPopupType.h"
-class BlobDispatcherHost;
class ChromeURLRequestContext;
class DatabaseDispatcherHost;
class DOMStorageDispatcherHost;
-class FileSystemDispatcherHost;
-class FileUtilitiesDispatcherHost;
struct FontDescriptor;
class GeolocationDispatcherHostOld;
class HostZoomMap;
class IndexedDBDispatcherHost;
-class MimeRegistryDispatcher;
class NotificationsPrefsCache;
class PpapiPluginProcessHost;
class Profile;
class RenderWidgetHelper;
-class SearchProviderInstallStateDispatcherHost;
class URLRequestContextGetter;
struct ViewHostMsg_CreateWindow_Params;
struct ViewHostMsg_CreateWorker_Params;
@@ -57,10 +52,6 @@ struct PlatformFileInfo;
class SharedMemory;
}
-namespace device_orientation {
-class DispatcherHost;
-}
-
namespace net {
class CookieStore;
}
@@ -70,10 +61,6 @@ class PrinterQuery;
class PrintJobManager;
}
-namespace speech_input {
-class SpeechInputDispatcherHost;
-}
-
namespace webkit_glue {
struct WebCookie;
}
@@ -473,33 +460,9 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
// A callback to create a routing id for the associated renderer process.
scoped_ptr<CallbackWithReturnValue<int>::Type> next_route_id_callback_;
- // Used to handle speech input related messages.
- scoped_refptr<speech_input::SpeechInputDispatcherHost>
- speech_input_dispatcher_host_;
-
// Used to handle geolocation-related messages.
scoped_refptr<GeolocationDispatcherHostOld> geolocation_dispatcher_host_;
- // Used to handle search provider related messages.
- scoped_ptr<SearchProviderInstallStateDispatcherHost>
- search_provider_install_state_dispatcher_host_;
-
- // Used to handle device orientation related messages.
- scoped_refptr<device_orientation::DispatcherHost>
- device_orientation_dispatcher_host_;
-
- // Handles FileSystem API related messages
- scoped_refptr<FileSystemDispatcherHost> file_system_dispatcher_host_;
-
- // Handles blob related messages.
- scoped_ptr<BlobDispatcherHost> blob_dispatcher_host_;
-
- // Handles file utilities messages.
- scoped_refptr<FileUtilitiesDispatcherHost> file_utilities_dispatcher_host_;
-
- // Handles mime registry requests.
- scoped_refptr<MimeRegistryDispatcher> mime_registry_dispatcher_;
-
DISALLOW_COPY_AND_ASSIGN(ResourceMessageFilter);
};