summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-24 05:28:50 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-24 05:28:50 +0000
commit65c884079fc0f2ff5d6e7b2f4bffa521cf7605e3 (patch)
tree5e3906d8ae6bb7171a3ff4e4ba33f2ec247bf3c2
parent9e3693b0a117de9e7a291659f27fdd8fdbcefb3f (diff)
downloadchromium_src-65c884079fc0f2ff5d6e7b2f4bffa521cf7605e3.zip
chromium_src-65c884079fc0f2ff5d6e7b2f4bffa521cf7605e3.tar.gz
chromium_src-65c884079fc0f2ff5d6e7b2f4bffa521cf7605e3.tar.bz2
Do some cleanup in the resource message filter. Hopefully it will compile on
Linux and Mac now. Review URL: http://codereview.chromium.org/18740 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8610 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/resource_message_filter.cc91
-rw-r--r--chrome/browser/resource_message_filter.h35
2 files changed, 86 insertions, 40 deletions
diff --git a/chrome/browser/resource_message_filter.cc b/chrome/browser/resource_message_filter.cc
index c959ae7..8dfb47a 100644
--- a/chrome/browser/resource_message_filter.cc
+++ b/chrome/browser/resource_message_filter.cc
@@ -29,6 +29,40 @@
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/webplugin.h"
+namespace {
+
+// Context menus are somewhat complicated. We need to intercept them here on
+// the I/O thread to add any spelling suggestions to them. After that's done,
+// we need to forward the modified message to the UI thread and the normal
+// message forwarding isn't set up for sending modified messages.
+//
+// Therefore, this class dispatches the IPC message to the RenderProcessHost
+// with the given ID (if possible) to emulate the normal dispatch.
+class ContextMenuMessageDispatcher : public Task {
+ public:
+ ContextMenuMessageDispatcher(
+ int render_process_host_id,
+ const ViewHostMsg_ContextMenu& context_menu_message)
+ : render_process_host_id_(render_process_host_id),
+ context_menu_message_(context_menu_message) {
+ }
+
+ void Run() {
+ RenderProcessHost* host =
+ RenderProcessHost::FromID(render_process_host_id_);
+ if (host)
+ host->OnMessageReceived(context_menu_message_);
+ }
+
+ private:
+ int render_process_host_id_;
+ const ViewHostMsg_ContextMenu context_menu_message_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContextMenuMessageDispatcher);
+};
+
+} // namespace
+
ResourceMessageFilter::ResourceMessageFilter(
ResourceDispatcherHost* resource_dispatcher_host,
PluginService* plugin_service,
@@ -61,7 +95,7 @@ ResourceMessageFilter::~ResourceMessageFilter() {
ChromeThread::GetMessageLoop(ChromeThread::IO));
NotificationService::current()->RemoveObserver(
this, NOTIFY_SPELLCHECKER_REINITIALIZED,
- Source<Profile>(profile_));
+ Source<Profile>(static_cast<Profile*>(profile_)));
}
// Called on the IPC thread:
@@ -71,7 +105,7 @@ void ResourceMessageFilter::OnFilterAdded(IPC::Channel* channel) {
// Add the observers to intercept
NotificationService::current()->AddObserver(
this, NOTIFY_SPELLCHECKER_REINITIALIZED,
- Source<Profile>(profile_));
+ Source<Profile>(static_cast<Profile*>(profile_)));
}
// Called on the IPC thread:
@@ -137,9 +171,12 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) {
OnClipboardReadAsciiText)
IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardReadHTML,
OnClipboardReadHTML)
+#if defined(OS_WIN)
IPC_MESSAGE_HANDLER(ViewHostMsg_GetWindowRect, OnGetWindowRect)
IPC_MESSAGE_HANDLER(ViewHostMsg_GetRootWindowRect, OnGetRootWindowRect)
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetRootWindowResizerRect, OnGetRootWindowResizerRect)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetRootWindowResizerRect,
+ OnGetRootWindowResizerRect)
+#endif
IPC_MESSAGE_HANDLER(ViewHostMsg_GetMimeTypeFromExtension,
OnGetMimeTypeFromExtension)
IPC_MESSAGE_HANDLER(ViewHostMsg_GetMimeTypeFromFile,
@@ -152,8 +189,10 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ViewHostMsg_ResourceTypeStats, OnResourceTypeStats)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetDefaultPrintSettings,
OnGetDefaultPrintSettings)
+#if defined(OS_WIN)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ScriptedPrint,
OnScriptedPrint)
+#endif
IPC_MESSAGE_UNHANDLED(
handled = false)
IPC_END_MESSAGE_MAP_EX()
@@ -166,28 +205,6 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) {
return handled;
}
-class ContextMenuMessageDispatcher : public Task {
- public:
- ContextMenuMessageDispatcher(
- int render_process_host_id,
- const ViewHostMsg_ContextMenu& context_menu_message)
- : render_process_host_id_(render_process_host_id),
- context_menu_message_(context_menu_message) {
- }
-
- void Run() {
- // Forward message to normal routing route.
- RenderProcessHost* host =
- RenderProcessHost::FromID(render_process_host_id_);
- if (host)
- host->OnMessageReceived(context_menu_message_);
- }
-
- private:
- int render_process_host_id_;
- const ViewHostMsg_ContextMenu context_menu_message_;
-};
-
void ResourceMessageFilter::OnReceiveContextMenuMsg(const IPC::Message& msg) {
void* iter = NULL;
ViewHostMsg_ContextMenu_Params params;
@@ -452,6 +469,8 @@ void ResourceMessageFilter::OnClipboardReadHTML(std::wstring* markup,
*src_url = GURL(src_url_str);
}
+#if defined(OS_WIN)
+
void ResourceMessageFilter::OnGetWindowRect(HWND window, gfx::Rect *rect) {
RECT window_rect = {0};
GetWindowRect(window, &window_rect);
@@ -470,6 +489,8 @@ void ResourceMessageFilter::OnGetRootWindowResizerRect(HWND window, gfx::Rect *r
*rect = window_rect;
}
+#endif // OS_WIN
+
void ResourceMessageFilter::OnGetMimeTypeFromExtension(
const std::wstring& ext, std::string* mime_type) {
net::GetMimeTypeFromExtension(ext, mime_type);
@@ -555,6 +576,8 @@ void ResourceMessageFilter::OnGetDefaultPrintSettingsReply(
}
}
+#if defined(OS_WIN)
+
void ResourceMessageFilter::OnScriptedPrint(HWND host_window,
int cookie,
int expected_pages_count,
@@ -607,6 +630,8 @@ void ResourceMessageFilter::OnScriptedPrintReply(
}
}
+#endif // OS_WIN
+
// static
ClipboardService* ResourceMessageFilter::GetClipboardService() {
// We have a static instance of the clipboard service for use by all message
@@ -630,10 +655,10 @@ ClipboardService* ResourceMessageFilter::GetClipboardService() {
// Note: This is called in the IO thread.
void ResourceMessageFilter::OnSpellCheck(const std::wstring& word,
IPC::Message* reply_msg) {
- int misspell_location = 0;
- int misspell_length = 0;
+ int misspell_location = 0;
+ int misspell_length = 0;
- if (spellchecker_ != NULL) {
+ if (spellchecker_ != NULL) {
spellchecker_->SpellCheckWord(word.c_str(),
static_cast<int>(word.length()),
&misspell_location, &misspell_length, NULL);
@@ -648,13 +673,13 @@ void ResourceMessageFilter::OnSpellCheck(const std::wstring& word,
void ResourceMessageFilter::Observe(NotificationType type,
const NotificationSource &source,
const NotificationDetails &details) {
- if (type == NOTIFY_SPELLCHECKER_REINITIALIZED) {
- spellchecker_ = Details<SpellcheckerReinitializedDetails>
- (details).ptr()->spellchecker;
- }
+ if (type == NOTIFY_SPELLCHECKER_REINITIALIZED) {
+ spellchecker_ = Details<SpellcheckerReinitializedDetails>
+ (details).ptr()->spellchecker;
+ }
}
void ResourceMessageFilter::OnDnsPrefetch(
- const std::vector<std::string>& hostnames) {
+ const std::vector<std::string>& hostnames) {
chrome_browser_net::DnsPrefetchList(hostnames);
}
diff --git a/chrome/browser/resource_message_filter.h b/chrome/browser/resource_message_filter.h
index 0d353da..09d42b6 100644
--- a/chrome/browser/resource_message_filter.h
+++ b/chrome/browser/resource_message_filter.h
@@ -2,19 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_RENDERER_RESOURCE_MSG_FILTER_H__
-#define CHROME_BROWSER_RENDERER_RESOURCE_MSG_FILTER_H__
+#ifndef CHROME_BROWSER_RENDERER_RESOURCE_MSG_FILTER_H_
+#define CHROME_BROWSER_RENDERER_RESOURCE_MSG_FILTER_H_
#include "base/clipboard.h"
#include "base/file_path.h"
#include "base/gfx/rect.h"
#include "base/gfx/native_widget_types.h"
#include "base/ref_counted.h"
+#include "build/build_config.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/common/ipc_channel_proxy.h"
#include "chrome/common/notification_service.h"
#include "webkit/glue/cache_manager.h"
+#if defined(OS_WIN)
+#include <windows.h>
+#endif
+
class ClipboardService;
class Profile;
class RenderWidgetHelper;
@@ -68,7 +73,7 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
int render_process_host_id() const { return render_process_host_id_;}
- HANDLE renderer_handle() const { return render_handle_;}
+ base::ProcessHandle renderer_handle() const { return render_handle_;}
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
@@ -136,9 +141,11 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
void OnClipboardReadText(std::wstring* result);
void OnClipboardReadAsciiText(std::string* result);
void OnClipboardReadHTML(std::wstring* markup, GURL* src_url);
+#if defined(OS_WIN)
void OnGetWindowRect(HWND window, gfx::Rect *rect);
void OnGetRootWindowRect(HWND window, gfx::Rect *rect);
void OnGetRootWindowResizerRect(HWND window, gfx::Rect *rect);
+#endif
void OnGetMimeTypeFromExtension(const std::wstring& ext,
std::string* mime_type);
void OnGetMimeTypeFromFile(const std::wstring& file_path,
@@ -157,6 +164,7 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
void OnGetDefaultPrintSettingsReply(
scoped_refptr<printing::PrinterQuery> printer_query,
IPC::Message* reply_msg);
+#if defined(OS_WIN)
// A javascript code requested to print the current page. The renderer host
// have to show to the user the print dialog and returns the selected print
// settings.
@@ -167,6 +175,7 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
void OnScriptedPrintReply(
scoped_refptr<printing::PrinterQuery> printer_query,
IPC::Message* reply_msg);
+#endif
// We have our own clipboard service because we want to access the clipboard
// on the IO thread instead of forwarding (possibly synchronous) messages to
@@ -175,6 +184,8 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
// thread.
static ClipboardService* GetClipboardService();
+ // The channel associated with the renderer connection. This pointer is not
+ // owned by this class.
IPC::Channel* channel_;
// Cached resource request dispatcher host and plugin service, guaranteed to
@@ -193,15 +204,25 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
// Our spellchecker object.
scoped_refptr<SpellChecker> spellchecker_;
- HANDLE render_handle_;
+ // Process handle of the renderer process.
+ base::ProcessHandle render_handle_;
// Contextual information to be used for requests created here.
scoped_refptr<URLRequestContext> request_context_;
- // Save the profile pointer so that notification observer can be added.
- Profile* profile_;
+ // A pointer to the profile associated with this filter.
+ //
+ // DANGER! Do not dereference this pointer! This class lives on the I/O thread
+ // and the profile may only be used on the UI thread. It is used only for
+ // determining which notifications to watch for.
+ //
+ // This is void* to prevent people from accidentally dereferencing it.
+ // When registering for observers, cast to Profile*.
+ void* profile_;
scoped_refptr<RenderWidgetHelper> render_widget_helper_;
+
+ DISALLOW_COPY_AND_ASSIGN(ResourceMessageFilter);
};
-#endif // CHROME_BROWSER_RENDERER_RESOURCE_MSG_FILTER_H__
+#endif // CHROME_BROWSER_RENDERER_RESOURCE_MSG_FILTER_H_