diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-24 20:53:52 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-24 20:53:52 +0000 |
commit | 92d5641ac0562e48fc2b4dfba487b235a25177b8 (patch) | |
tree | 286b4c808e1e93948c47e36da64049ba01bc408e /chrome | |
parent | 4c87e0a3e1436f4206881afed09981283feb2d29 (diff) | |
download | chromium_src-92d5641ac0562e48fc2b4dfba487b235a25177b8.zip chromium_src-92d5641ac0562e48fc2b4dfba487b235a25177b8.tar.gz chromium_src-92d5641ac0562e48fc2b4dfba487b235a25177b8.tar.bz2 |
Add a ChromeRenderMessageFilter, which is like RenderMessageFilter but outside the content module. We'll dispatch Chrome specific messages on the IO thread there. Also convert one more message that's only used for printing.
Review URL: http://codereview.chromium.org/6713108
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79318 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/nacl_host/nacl_process_host.cc | 21 | ||||
-rw-r--r-- | chrome/browser/nacl_host/nacl_process_host.h | 10 | ||||
-rw-r--r-- | chrome/browser/printing/printing_message_filter.cc | 2 | ||||
-rw-r--r-- | chrome/browser/renderer_host/browser_render_process_host.cc | 3 | ||||
-rw-r--r-- | chrome/browser/renderer_host/chrome_render_message_filter.cc | 40 | ||||
-rw-r--r-- | chrome/browser/renderer_host/chrome_render_message_filter.h | 39 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/common/print_messages.h | 8 | ||||
-rw-r--r-- | chrome/renderer/mock_render_thread.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_win.cc | 5 |
10 files changed, 112 insertions, 20 deletions
diff --git a/chrome/browser/nacl_host/nacl_process_host.cc b/chrome/browser/nacl_host/nacl_process_host.cc index 2b97881..333cc3e 100644 --- a/chrome/browser/nacl_host/nacl_process_host.cc +++ b/chrome/browser/nacl_host/nacl_process_host.cc @@ -19,7 +19,7 @@ #include "chrome/common/nacl_cmd_line.h" #include "chrome/common/nacl_messages.h" #include "chrome/common/render_messages.h" -#include "content/browser/renderer_host/render_message_filter.h" +#include "chrome/browser/renderer_host/chrome_render_message_filter.h" #include "ipc/ipc_switches.h" #include "native_client/src/shared/imc/nacl_imc.h" @@ -82,12 +82,13 @@ NaClProcessHost::~NaClProcessHost() { // OnProcessLaunched didn't get called because the process couldn't launch. // Don't keep the renderer hanging. reply_msg_->set_reply_error(); - render_message_filter_->Send(reply_msg_); + chrome_render_message_filter_->Send(reply_msg_); } -bool NaClProcessHost::Launch(RenderMessageFilter* render_message_filter, - int socket_count, - IPC::Message* reply_msg) { +bool NaClProcessHost::Launch( + ChromeRenderMessageFilter* chrome_render_message_filter, + int socket_count, + IPC::Message* reply_msg) { #ifdef DISABLE_NACL NOTIMPLEMENTED() << "Native Client disabled at build time"; return false; @@ -124,7 +125,7 @@ bool NaClProcessHost::Launch(RenderMessageFilter* render_message_filter, return false; } UmaNaclHistogramEnumeration(NACL_STARTED); - render_message_filter_ = render_message_filter; + chrome_render_message_filter_ = chrome_render_message_filter; reply_msg_ = reply_msg; return true; @@ -198,7 +199,7 @@ void NaClProcessHost::OnProcessLaunched() { DuplicateHandle(base::GetCurrentProcessHandle(), reinterpret_cast<HANDLE>( internal_->sockets_for_renderer[i]), - render_message_filter_->peer_handle(), + chrome_render_message_filter_->peer_handle(), &handle_in_renderer, GENERIC_READ | GENERIC_WRITE, FALSE, @@ -219,7 +220,7 @@ void NaClProcessHost::OnProcessLaunched() { // Copy the process handle into the renderer process. DuplicateHandle(base::GetCurrentProcessHandle(), handle(), - render_message_filter_->peer_handle(), + chrome_render_message_filter_->peer_handle(), &nacl_process_handle, PROCESS_DUP_HANDLE, FALSE, @@ -234,8 +235,8 @@ void NaClProcessHost::OnProcessLaunched() { ViewHostMsg_LaunchNaCl::WriteReplyParams( reply_msg_, handles_for_renderer, nacl_process_handle, nacl_process_id); - render_message_filter_->Send(reply_msg_); - render_message_filter_ = NULL; + chrome_render_message_filter_->Send(reply_msg_); + chrome_render_message_filter_ = NULL; reply_msg_ = NULL; internal_->sockets_for_renderer.clear(); diff --git a/chrome/browser/nacl_host/nacl_process_host.h b/chrome/browser/nacl_host/nacl_process_host.h index b4deaea..3eaee90 100644 --- a/chrome/browser/nacl_host/nacl_process_host.h +++ b/chrome/browser/nacl_host/nacl_process_host.h @@ -12,7 +12,7 @@ #include "chrome/common/nacl_types.h" #include "content/browser/browser_child_process_host.h" -class RenderMessageFilter; +class ChromeRenderMessageFilter; // Represents the browser side of the browser <--> NaCl communication // channel. There will be one NaClProcessHost per NaCl process @@ -27,7 +27,7 @@ class NaClProcessHost : public BrowserChildProcessHost { ~NaClProcessHost(); // Initialize the new NaCl process, returning true on success. - bool Launch(RenderMessageFilter* render_message_filter, + bool Launch(ChromeRenderMessageFilter* chrome_render_message_filter, int socket_count, IPC::Message* reply_msg); @@ -57,9 +57,9 @@ class NaClProcessHost : public BrowserChildProcessHost { private: ResourceDispatcherHost* resource_dispatcher_host_; - // The RenderMessageFilter that requested this NaCl process. We use this - // for sending the reply once the process has started. - scoped_refptr<RenderMessageFilter> render_message_filter_; + // The ChromeRenderMessageFilter that requested this NaCl process. We use + // this for sending the reply once the process has started. + scoped_refptr<ChromeRenderMessageFilter> chrome_render_message_filter_; // The reply message to send. IPC::Message* reply_msg_; diff --git a/chrome/browser/printing/printing_message_filter.cc b/chrome/browser/printing/printing_message_filter.cc index c4519c3..f74fdc0 100644 --- a/chrome/browser/printing/printing_message_filter.cc +++ b/chrome/browser/printing/printing_message_filter.cc @@ -88,7 +88,7 @@ bool PrintingMessageFilter::OnMessageReceived(const IPC::Message& message, bool handled = true; IPC_BEGIN_MESSAGE_MAP_EX(PrintingMessageFilter, message, *message_was_ok) #if defined(OS_WIN) - IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection) + IPC_MESSAGE_HANDLER(PrintHostMsg_DuplicateSection, OnDuplicateSection) #endif #if defined(OS_CHROMEOS) IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting, diff --git a/chrome/browser/renderer_host/browser_render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc index ddb20f8..2ffa5f2 100644 --- a/chrome/browser/renderer_host/browser_render_process_host.cc +++ b/chrome/browser/renderer_host/browser_render_process_host.cc @@ -40,6 +40,7 @@ #include "chrome/browser/platform_util.h" #include "chrome/browser/printing/printing_message_filter.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/renderer_host/chrome_render_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" @@ -451,6 +452,8 @@ void BrowserRenderProcessHost::CreateMessageFilters() { widget_helper_)); channel_->AddFilter(render_message_filter); + channel_->AddFilter(new ChromeRenderMessageFilter()); + scoped_refptr<RendererURLRequestContextOverride> url_request_context_override( new RendererURLRequestContextOverride(profile(), installed_app_)); diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.cc b/chrome/browser/renderer_host/chrome_render_message_filter.cc new file mode 100644 index 0000000..8d3f5a2 --- /dev/null +++ b/chrome/browser/renderer_host/chrome_render_message_filter.cc @@ -0,0 +1,40 @@ +// 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. + +#include "chrome/browser/renderer_host/chrome_render_message_filter.h" + +#include "chrome/browser/browser_process.h" +#include "chrome/browser/nacl_host/nacl_process_host.h" +#include "chrome/common/render_messages.h" +#include "content/browser/renderer_host/resource_dispatcher_host.h" + +ChromeRenderMessageFilter::ChromeRenderMessageFilter() + : resource_dispatcher_host_(g_browser_process->resource_dispatcher_host()) { +} + +ChromeRenderMessageFilter::~ChromeRenderMessageFilter() { + // This function should be called on the IO thread. + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); +} + +bool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message, + bool* message_was_ok) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP_EX(ChromeRenderMessageFilter, message, *message_was_ok) + IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_LaunchNaCl, OnLaunchNaCl) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + + return handled; +} + +void ChromeRenderMessageFilter::OnDestruct() const { + BrowserThread::DeleteOnIOThread::Destruct(this); +} + +void ChromeRenderMessageFilter::OnLaunchNaCl( + const std::wstring& url, int channel_descriptor, IPC::Message* reply_msg) { + NaClProcessHost* host = new NaClProcessHost(resource_dispatcher_host_, url); + host->Launch(this, channel_descriptor, reply_msg); +} diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.h b/chrome/browser/renderer_host/chrome_render_message_filter.h new file mode 100644 index 0000000..1ab51fc --- /dev/null +++ b/chrome/browser/renderer_host/chrome_render_message_filter.h @@ -0,0 +1,39 @@ +// 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 CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_ +#define CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_ +#pragma once + +#include "content/browser/browser_message_filter.h" + +class ResourceDispatcherHost; + +// This class filters out incoming Chrome-specific IPC messages for the renderer +// process on the IPC thread. +class ChromeRenderMessageFilter : public BrowserMessageFilter { + public: + ChromeRenderMessageFilter(); + + // BrowserMessageFilter methods: + virtual bool OnMessageReceived(const IPC::Message& message, + bool* message_was_ok); + virtual void OnDestruct() const; + + private: + friend class BrowserThread; + friend class DeleteTask<ChromeRenderMessageFilter>; + + virtual ~ChromeRenderMessageFilter(); + + void OnLaunchNaCl(const std::wstring& url, + int channel_descriptor, + IPC::Message* reply_msg); + + ResourceDispatcherHost* resource_dispatcher_host_; + + DISALLOW_COPY_AND_ASSIGN(ChromeRenderMessageFilter); +}; + +#endif // CHROME_BROWSER_RENDERER_HOST_CHROME_RENDER_MESSAGE_FILTER_H_ diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 6f81865..5535580 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1678,6 +1678,8 @@ 'browser/remove_rows_table_model.h', 'browser/renderer_host/browser_render_process_host.cc', 'browser/renderer_host/browser_render_process_host.h', + 'browser/renderer_host/chrome_render_message_filter.cc', + 'browser/renderer_host/chrome_render_message_filter.h', 'browser/renderer_host/download_resource_handler.cc', 'browser/renderer_host/download_resource_handler.h', 'browser/renderer_host/download_throttling_resource_handler.cc', diff --git a/chrome/common/print_messages.h b/chrome/common/print_messages.h index a9fd701..81e903e 100644 --- a/chrome/common/print_messages.h +++ b/chrome/common/print_messages.h @@ -152,6 +152,14 @@ IPC_MESSAGE_ROUTED0(PrintMsg_ResetScriptedPrintCount) // Messages sent from the renderer to the browser. +#if defined(OS_WIN) +// Duplicates a shared memory handle from the renderer to the browser. Then +// the renderer can flush the handle. +IPC_SYNC_MESSAGE_ROUTED1_1(PrintHostMsg_DuplicateSection, + base::SharedMemoryHandle /* renderer handle */, + base::SharedMemoryHandle /* browser handle */) +#endif + // Tells the browser that the renderer is done calculating the number of // rendered pages according to the specified settings. IPC_MESSAGE_ROUTED2(PrintHostMsg_DidGetPrintedPagesCount, diff --git a/chrome/renderer/mock_render_thread.cc b/chrome/renderer/mock_render_thread.cc index 335f523..aa45dba 100644 --- a/chrome/renderer/mock_render_thread.cc +++ b/chrome/renderer/mock_render_thread.cc @@ -116,7 +116,7 @@ bool MockRenderThread::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) #endif #if defined(OS_WIN) - IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection) + IPC_MESSAGE_HANDLER(PrintHostMsg_DuplicateSection, OnDuplicateSection) #endif IPC_MESSAGE_HANDLER(ViewHostMsg_AllocateSharedMemoryBuffer, OnAllocateSharedMemoryBuffer) diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc index 04da522..f733062 100644 --- a/chrome/renderer/print_web_view_helper_win.cc +++ b/chrome/renderer/print_web_view_helper_win.cc @@ -7,7 +7,6 @@ #include "base/logging.h" #include "base/process_util.h" #include "chrome/common/print_messages.h" -#include "content/common/view_messages.h" #include "printing/native_metafile_factory.h" #include "printing/native_metafile.h" #include "printing/units.h" @@ -111,7 +110,7 @@ void PrintWebViewHelper::PrintPage(const PrintMsg_PrintPage_Params& params, &(page_params.metafile_data_handle))) { page_params.data_size = 0; } - if (!Send(new ViewHostMsg_DuplicateSection( + if (!Send(new PrintHostMsg_DuplicateSection( routing_id(), page_params.metafile_data_handle, &page_params.metafile_data_handle))) { @@ -183,7 +182,7 @@ void PrintWebViewHelper::CreatePreviewDocument( preview_params.data_size = 0; preview_params.expected_pages_count = 0; } - if (!Send(new ViewHostMsg_DuplicateSection( + if (!Send(new PrintHostMsg_DuplicateSection( routing_id(), preview_params.metafile_data_handle, &preview_params.metafile_data_handle))) { |