summaryrefslogtreecommitdiffstats
path: root/chrome/browser/renderer_host
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-17 00:52:35 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-17 00:52:35 +0000
commitdabe607133c5b62e6b0134017f35cb87d0d4f3b6 (patch)
treedb5d35947dcfa2810c7e7e19364ecaae37aa0912 /chrome/browser/renderer_host
parenta91baaa1bab5fe3de395aad464015a098290a46b (diff)
downloadchromium_src-dabe607133c5b62e6b0134017f35cb87d0d4f3b6.zip
chromium_src-dabe607133c5b62e6b0134017f35cb87d0d4f3b6.tar.gz
chromium_src-dabe607133c5b62e6b0134017f35cb87d0d4f3b6.tar.bz2
Hide the details about ResourceDispatcherHost messages from child processes. The usage of RDH is now like RD, the client sends the message to RDH to see if it should handle it. I added methods to the Receiver interface so that RDH can get to the process id/handle/type when starting requests.
Review URL: http://codereview.chromium.org/42202 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11816 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
-rw-r--r--chrome/browser/renderer_host/async_resource_handler.cc2
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host.cc225
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host.h78
-rw-r--r--chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc59
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc263
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h20
6 files changed, 349 insertions, 298 deletions
diff --git a/chrome/browser/renderer_host/async_resource_handler.cc b/chrome/browser/renderer_host/async_resource_handler.cc
index 73aa227..038fc8c 100644
--- a/chrome/browser/renderer_host/async_resource_handler.cc
+++ b/chrome/browser/renderer_host/async_resource_handler.cc
@@ -102,7 +102,7 @@ bool AsyncResourceHandler::OnReadCompleted(int request_id, int* bytes_read) {
// to fix this. We can't move this call above the WillSendData because
// it's killing our read_buffer_, and we don't want that when we pause
// the request.
- rdh_->OnDataReceivedACK(process_id_, request_id);
+ rdh_->DataReceivedACK(process_id_, request_id);
// We just unmapped the memory.
read_buffer_ = NULL;
return false;
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc
index 276693d..22d7bcb 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host.cc
+++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/download/save_file_manager.h"
#include "chrome/browser/external_protocol_handler.h"
#include "chrome/browser/plugin_service.h"
+#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/async_resource_handler.h"
#include "chrome/browser/renderer_host/buffered_resource_handler.h"
#include "chrome/browser/renderer_host/cross_site_resource_handler.h"
@@ -145,7 +146,8 @@ ResourceDispatcherHost::ResourceDispatcherHost(MessageLoop* io_loop)
ALLOW_THIS_IN_INITIALIZER_LIST(method_runner_(this)),
is_shutdown_(false),
max_outstanding_requests_cost_per_process_(
- kMaxOutstandingRequestsCostPerProcess) {
+ kMaxOutstandingRequestsCostPerProcess),
+ receiver_(NULL) {
}
ResourceDispatcherHost::~ResourceDispatcherHost() {
@@ -210,20 +212,68 @@ bool ResourceDispatcherHost::HandleExternalProtocol(int request_id,
return true;
}
-void ResourceDispatcherHost::BeginRequest(
- Receiver* receiver,
- ChildProcessInfo::ProcessType process_type,
- base::ProcessHandle process_handle,
- int process_id,
- int route_id,
+bool ResourceDispatcherHost::OnMessageReceived(const IPC::Message& message,
+ Receiver* receiver,
+ bool* message_was_ok) {
+ if (!IsResourceDispatcherHostMessage(message))
+ return false;
+
+ *message_was_ok = true;
+ receiver_ = receiver;
+
+ IPC_BEGIN_MESSAGE_MAP_EX(ResourceDispatcherHost, message, *message_was_ok)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_RequestResource, OnRequestResource)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncLoad, OnSyncLoad)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_DataReceived_ACK, OnDataReceivedACK)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_DownloadProgress_ACK, OnDownloadProgressACK)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_UploadProgress_ACK, OnUploadProgressACK)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_CancelRequest, OnCancelRequest)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ClosePage_ACK, OnClosePageACK)
+ IPC_END_MESSAGE_MAP_EX()
+
+ receiver_ = NULL;
+
+ return true;
+}
+
+void ResourceDispatcherHost::OnRequestResource(
+ const IPC::Message& message,
+ int request_id,
+ const ViewHostMsg_Resource_Request& request_data) {
+ BeginRequest(request_id, request_data, NULL, message.routing_id());
+}
+
+// Begins a resource request with the given params on behalf of the specified
+// child process. Responses will be dispatched through the given receiver. The
+// process ID is used to lookup TabContents from routing_id's in the case of a
+// request from a renderer. request_context is the cookie/cache context to be
+// used for this request.
+//
+// If sync_result is non-null, then a SyncLoad reply will be generated, else
+// a normal asynchronous set of response messages will be generated.
+void ResourceDispatcherHost::OnSyncLoad(
int request_id,
const ViewHostMsg_Resource_Request& request_data,
- URLRequestContext* request_context,
IPC::Message* sync_result) {
+ BeginRequest(request_id, request_data, sync_result, 0);
+}
+
+void ResourceDispatcherHost::BeginRequest(
+ int request_id,
+ const ViewHostMsg_Resource_Request& request_data,
+ IPC::Message* sync_result, // only valid for sync
+ int route_id) {
+ ChildProcessInfo::ProcessType process_type = receiver_->type();
+ int process_id = receiver_->pid();
+ URLRequestContext* context =
+ receiver_->GetRequestContext(request_id, request_data);
+ if (!context)
+ context = Profile::GetDefaultRequestContext();
+
if (is_shutdown_ ||
!ShouldServiceRequest(process_type, process_id, request_data)) {
// Tell the renderer that this request was disallowed.
- receiver->Send(new ViewMsg_Resource_RequestComplete(
+ receiver_->Send(new ViewMsg_Resource_RequestComplete(
route_id,
request_id,
URLRequestStatus(URLRequestStatus::FAILED, net::ERR_ABORTED),
@@ -241,12 +291,12 @@ void ResourceDispatcherHost::BeginRequest(
// Construct the event handler.
scoped_refptr<ResourceHandler> handler;
if (sync_result) {
- handler = new SyncResourceHandler(receiver, request_data.url, sync_result);
+ handler = new SyncResourceHandler(receiver_, request_data.url, sync_result);
} else {
- handler = new AsyncResourceHandler(receiver,
+ handler = new AsyncResourceHandler(receiver_,
process_id,
route_id,
- process_handle,
+ receiver_->handle(),
request_data.url,
this);
// If the resource type is ResourceType::MEDIA and LOAD_ENABLE_DOWNLOAD_FILE
@@ -254,10 +304,10 @@ void ResourceDispatcherHost::BeginRequest(
if (request_data.resource_type == ResourceType::MEDIA &&
(request_data.load_flags & net::LOAD_ENABLE_DOWNLOAD_FILE)) {
handler = new MediaResourceHandler(handler,
- receiver,
+ receiver_,
process_id,
route_id,
- process_handle,
+ receiver_->handle(),
this);
}
}
@@ -275,7 +325,7 @@ void ResourceDispatcherHost::BeginRequest(
request->set_referrer(request_data.referrer.spec());
request->SetExtraRequestHeaders(request_data.headers);
request->set_load_flags(request_data.load_flags);
- request->set_context(request_context);
+ request->set_context(context);
request->set_origin_pid(request_data.origin_pid);
// Set upload data.
@@ -326,13 +376,77 @@ void ResourceDispatcherHost::BeginRequest(
request_data.mixed_content,
request_data.resource_type,
upload_size);
- extra_info->allow_download =
- ResourceType::IsFrame(request_data.resource_type);
+ extra_info->allow_download = ResourceType::IsFrame(request_data.resource_type);
request->set_user_data(extra_info); // takes pointer ownership
BeginRequestInternal(request, request_data.mixed_content);
}
+void ResourceDispatcherHost::OnDataReceivedACK(int request_id) {
+ DataReceivedACK(receiver_->pid(), request_id);
+}
+
+void ResourceDispatcherHost::DataReceivedACK(int process_id, int request_id) {
+ PendingRequestList::iterator i = pending_requests_.find(
+ GlobalRequestID(process_id, request_id));
+ if (i == pending_requests_.end())
+ return;
+
+ ExtraRequestInfo* info = ExtraInfoForRequest(i->second);
+
+ // Decrement the number of pending data messages.
+ info->pending_data_count--;
+
+ // If the pending data count was higher than the max, resume the request.
+ if (info->pending_data_count == kMaxPendingDataMessages) {
+ // Decrement the pending data count one more time because we also
+ // incremented it before pausing the request.
+ info->pending_data_count--;
+
+ // Resume the request.
+ PauseRequest(process_id, request_id, false);
+ }
+}
+
+void ResourceDispatcherHost::OnDownloadProgressACK(int request_id) {
+ // TODO(hclam): do something to help rate limiting the message.
+}
+
+void ResourceDispatcherHost::OnUploadProgressACK(int request_id) {
+ int process_id = receiver_->pid();
+ PendingRequestList::iterator i = pending_requests_.find(
+ GlobalRequestID(process_id, request_id));
+ if (i == pending_requests_.end())
+ return;
+
+ ExtraRequestInfo* info = ExtraInfoForRequest(i->second);
+ info->waiting_for_upload_progress_ack = false;
+}
+
+void ResourceDispatcherHost::OnCancelRequest(int request_id) {
+ CancelRequest(receiver_->pid(), request_id, true, true);
+}
+
+void ResourceDispatcherHost::OnClosePageACK(int new_render_process_host_id,
+ int new_request_id) {
+ GlobalRequestID global_id(new_render_process_host_id, new_request_id);
+ PendingRequestList::iterator i = pending_requests_.find(global_id);
+ if (i == pending_requests_.end()) {
+ // If there are no matching pending requests, then this is not a
+ // cross-site navigation and we are just closing the tab/browser.
+ ui_loop_->PostTask(FROM_HERE, NewRunnableFunction(
+ &RenderViewHost::ClosePageIgnoringUnloadEvents,
+ new_render_process_host_id,
+ new_request_id));
+ return;
+ }
+
+ ExtraRequestInfo* info = ExtraInfoForRequest(i->second);
+ if (info->cross_site_handler) {
+ info->cross_site_handler->ResumeResponse();
+ }
+}
+
// We are explicitly forcing the download of 'url'.
void ResourceDispatcherHost::BeginDownload(const GURL& url,
const GURL& referrer,
@@ -502,45 +616,6 @@ void ResourceDispatcherHost::CancelRequest(int process_id,
// that.
}
-void ResourceDispatcherHost::OnDataReceivedACK(int process_id,
- int request_id) {
- PendingRequestList::iterator i = pending_requests_.find(
- GlobalRequestID(process_id, request_id));
- if (i == pending_requests_.end())
- return;
-
- ExtraRequestInfo* info = ExtraInfoForRequest(i->second);
-
- // Decrement the number of pending data messages.
- info->pending_data_count--;
-
- // If the pending data count was higher than the max, resume the request.
- if (info->pending_data_count == kMaxPendingDataMessages) {
- // Decrement the pending data count one more time because we also
- // incremented it before pausing the request.
- info->pending_data_count--;
-
- // Resume the request.
- PauseRequest(process_id, request_id, false);
- }
-}
-
-void ResourceDispatcherHost::OnDownloadProgressACK(int process_id,
- int request_id) {
- // TODO(hclam): do something to help rate limiting the message.
-}
-
-void ResourceDispatcherHost::OnUploadProgressACK(int process_id,
- int request_id) {
- PendingRequestList::iterator i = pending_requests_.find(
- GlobalRequestID(process_id, request_id));
- if (i == pending_requests_.end())
- return;
-
- ExtraRequestInfo* info = ExtraInfoForRequest(i->second);
- info->waiting_for_upload_progress_ack = false;
-}
-
bool ResourceDispatcherHost::WillSendData(int process_id,
int request_id) {
PendingRequestList::iterator i = pending_requests_.find(
@@ -602,26 +677,6 @@ int ResourceDispatcherHost::GetOutstandingRequestsMemoryCost(
0 : entry->second;
}
-void ResourceDispatcherHost::OnClosePageACK(int process_id,
- int request_id) {
- GlobalRequestID global_id(process_id, request_id);
- PendingRequestList::iterator i = pending_requests_.find(global_id);
- if (i == pending_requests_.end()) {
- // If there are no matching pending requests, then this is not a
- // cross-site navigation and we are just closing the tab/browser.
- ui_loop_->PostTask(FROM_HERE, NewRunnableFunction(
- &RenderViewHost::ClosePageIgnoringUnloadEvents,
- process_id,
- request_id));
- return;
- }
-
- ExtraRequestInfo* info = ExtraInfoForRequest(i->second);
- if (info->cross_site_handler) {
- info->cross_site_handler->ResumeResponse();
- }
-}
-
// The object died, so cancel and detach all requests associated with it except
// for downloads, which belong to the browser process even if initiated via a
// renderer.
@@ -1458,3 +1513,21 @@ void ResourceDispatcherHost::ProcessBlockedRequestsForRoute(
delete requests;
}
+
+bool ResourceDispatcherHost::IsResourceDispatcherHostMessage(
+ const IPC::Message& message) {
+ switch (message.type()) {
+ case ViewHostMsg_RequestResource::ID:
+ case ViewHostMsg_CancelRequest::ID:
+ case ViewHostMsg_ClosePage_ACK::ID:
+ case ViewHostMsg_DataReceived_ACK::ID:
+ case ViewHostMsg_UploadProgress_ACK::ID:
+ case ViewHostMsg_SyncLoad::ID:
+ return true;
+
+ default:
+ break;
+ }
+
+ return false;
+}
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h
index 3d14213..44703aa 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host.h
+++ b/chrome/browser/renderer_host/resource_dispatcher_host.h
@@ -49,7 +49,19 @@ class ResourceDispatcherHost : public URLRequest::Delegate {
// false), then the ResourceDispatcherHost assumes the receiver has failed,
// and the given request will be dropped. (This happens, for example, when a
// renderer crashes and the channel dies).
- typedef IPC::Message::Sender Receiver;
+ class Receiver : public IPC::Message::Sender,
+ public ChildProcessInfo {
+ public:
+ // Return the URLRequestContext for the given request.
+ // If NULL is returned, the default context for the profile is used.
+ virtual URLRequestContext* GetRequestContext(
+ uint32 request_id,
+ const ViewHostMsg_Resource_Request& request_data) = 0;
+
+ protected:
+ Receiver(ChildProcessInfo::ProcessType type) : ChildProcessInfo(type) { }
+ virtual ~Receiver() { }
+ };
// Holds the data we would like to associate with each request
class ExtraRequestInfo : public URLRequest::UserData {
@@ -192,23 +204,11 @@ class ResourceDispatcherHost : public URLRequest::Delegate {
// new requests). Cancels all pending requests.
void Shutdown();
- // Begins a resource request with the given params on behalf of the specified
- // child process. Responses will be dispatched through the given receiver. The
- // process ID is used to lookup TabContents from routing_id's in the case of a
- // request from a renderer. request_context is the cookie/cache context to be
- // used for this request.
- //
- // If sync_result is non-null, then a SyncLoad reply will be generated, else
- // a normal asynchronous set of response messages will be generated.
- void BeginRequest(Receiver* receiver,
- ChildProcessInfo::ProcessType process_type,
- base::ProcessHandle process_handle,
- int process_id,
- int route_id,
- int request_id,
- const ViewHostMsg_Resource_Request& request,
- URLRequestContext* request_context,
- IPC::Message* sync_result);
+ // Returns true if the message was a resource message that was processed.
+ // If it was, message_was_ok will be false iff the message was corrupt.
+ bool OnMessageReceived(const IPC::Message& message,
+ Receiver* receiver,
+ bool* message_was_ok);
// Initiates a download from the browser process (as opposed to a resource
// request from the renderer or another child process).
@@ -232,18 +232,6 @@ class ResourceDispatcherHost : public URLRequest::Delegate {
int request_id,
bool from_renderer);
- // Decrements the pending_data_count for the request and resumes
- // the request if it was paused due to too many pending data
- // messages sent.
- void OnDataReceivedACK(int process_id, int request_id);
-
- // Called when the renderer process confirms the reception of a download
- // progress message.
- void OnDownloadProgressACK(int process_id, int request_id);
-
- // Resets the waiting_for_upload_progress_ack flag.
- void OnUploadProgressACK(int process_id, int request_id);
-
// Returns true if it's ok to send the data. If there are already too many
// data messages pending, it pauses the request and returns false. In this
// case the caller should not send the data.
@@ -359,6 +347,14 @@ class ResourceDispatcherHost : public URLRequest::Delegate {
// Cancels any blocked request for the specified route id.
void CancelBlockedRequestsForRoute(int process_id, int route_id);
+ // Decrements the pending_data_count for the request and resumes
+ // the request if it was paused due to too many pending data
+ // messages sent.
+ void DataReceivedACK(int process_id, int request_id);
+
+ // Needed for the sync IPC message dispatcher macros.
+ bool Send(IPC::Message* message) { delete message; return false; }
+
private:
FRIEND_TEST(ResourceDispatcherHostTest, TestBlockedRequestsProcessDies);
FRIEND_TEST(ResourceDispatcherHostTest,
@@ -465,6 +461,24 @@ class ResourceDispatcherHost : public URLRequest::Delegate {
int route_id,
bool cancel_requests);
+ void OnRequestResource(const IPC::Message& msg,
+ int request_id,
+ const ViewHostMsg_Resource_Request& request_data);
+ void OnSyncLoad(int request_id,
+ const ViewHostMsg_Resource_Request& request_data,
+ IPC::Message* sync_result);
+ void BeginRequest(int request_id,
+ const ViewHostMsg_Resource_Request& request_data,
+ IPC::Message* sync_result, // only valid for sync
+ int route_id); // only valid for async
+ void OnDataReceivedACK(int request_id);
+ void OnDownloadProgressACK(int request_id);
+ void OnUploadProgressACK(int request_id);
+ void OnCancelRequest(int request_id);
+
+ // Returns true if the message passed in is a resource related message.
+ static bool IsResourceDispatcherHostMessage(const IPC::Message&);
+
PendingRequestList pending_requests_;
// We cache the UI message loop so we can create new UI-related objects on it.
@@ -528,6 +542,10 @@ class ResourceDispatcherHost : public URLRequest::Delegate {
// kAvgBytesPerOutstandingRequest)
int max_outstanding_requests_cost_per_process_;
+ // Used during IPC message dispatching so that the handlers can get a pointer
+ // to the source of the message.
+ Receiver* receiver_;
+
DISALLOW_COPY_AND_ASSIGN(ResourceDispatcherHost);
};
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc b/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc
index 2d05ffb..9e359a7 100644
--- a/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc
+++ b/chrome/browser/renderer_host/resource_dispatcher_host_unittest.cc
@@ -85,15 +85,23 @@ void ResourceIPCAccumulator::GetClassifiedMessages(ClassifiedMessages* msgs) {
class ResourceDispatcherHostTest : public testing::Test,
public ResourceDispatcherHost::Receiver {
public:
- ResourceDispatcherHostTest() : host_(NULL) {
+ ResourceDispatcherHostTest()
+ : Receiver(ChildProcessInfo::RENDER_PROCESS), host_(NULL) {
+ set_handle(base::GetCurrentProcessHandle());
}
- // ResourceDispatcherHost::Delegate implementation
+ // ResourceDispatcherHost::Receiver implementation
virtual bool Send(IPC::Message* msg) {
accum_.AddMessage(*msg);
delete msg;
return true;
}
+ URLRequestContext* GetRequestContext(
+ uint32 request_id,
+ const ViewHostMsg_Resource_Request& request_data) {
+ return NULL;
+ }
+
protected:
// testing::Test
virtual void SetUp() {
@@ -117,6 +125,11 @@ class ResourceDispatcherHostTest : public testing::Test,
int render_view_id,
int request_id,
const GURL& url);
+ void MakeTestRequest(ResourceDispatcherHost::Receiver* receiver,
+ int render_process_id,
+ int render_view_id,
+ int request_id,
+ const GURL& url);
void MakeCancelRequest(int request_id);
void EnsureTestSchemeIsAllowed() {
@@ -142,12 +155,23 @@ void ResourceDispatcherHostTest::MakeTestRequest(int render_process_id,
int render_view_id,
int request_id,
const GURL& url) {
- ViewHostMsg_Resource_Request request = CreateResourceRequest("GET", url);
+ MakeTestRequest(this, render_process_id, render_view_id, request_id, url);
+}
- host_.BeginRequest(this, ChildProcessInfo::RENDER_PROCESS,
- base::GetCurrentProcessHandle(), render_process_id,
- render_view_id, request_id, request, NULL, NULL);
+void ResourceDispatcherHostTest::MakeTestRequest(
+ ResourceDispatcherHost::Receiver* receiver,
+ int render_process_id,
+ int render_view_id,
+ int request_id,
+ const GURL& url) {
+ int old_pid = pid();
+ pid_ = render_process_id;
+ ViewHostMsg_Resource_Request request = CreateResourceRequest("GET", url);
+ ViewHostMsg_RequestResource msg(render_view_id, request_id, request);
+ bool msg_was_ok;
+ host_.OnMessageReceived(msg, receiver, &msg_was_ok);
KickOffRequest();
+ pid_ = old_pid;
}
void ResourceDispatcherHostTest::MakeCancelRequest(int request_id) {
@@ -267,8 +291,11 @@ TEST_F(ResourceDispatcherHostTest, TestProcessCancel) {
// pending and some canceled
class TestReceiver : public ResourceDispatcherHost::Receiver {
public:
- TestReceiver() : has_canceled_(false), received_after_canceled_(0) {
- }
+ TestReceiver()
+ : Receiver(ChildProcessInfo::RENDER_PROCESS),
+ has_canceled_(false),
+ received_after_canceled_(0) { }
+ // ResourceDispatcherHost::Receiver implementation
virtual bool Send(IPC::Message* msg) {
// no messages should be received when the process has been canceled
if (has_canceled_)
@@ -276,6 +303,11 @@ TEST_F(ResourceDispatcherHostTest, TestProcessCancel) {
delete msg;
return true;
}
+ URLRequestContext* GetRequestContext(
+ uint32 request_id,
+ const ViewHostMsg_Resource_Request& request_data) {
+ return NULL;
+ }
bool has_canceled_;
int received_after_canceled_;
};
@@ -287,20 +319,13 @@ TEST_F(ResourceDispatcherHostTest, TestProcessCancel) {
EXPECT_EQ(0, host_.GetOutstandingRequestsMemoryCost(0));
- host_.BeginRequest(&test_receiver, ChildProcessInfo::RENDER_PROCESS,
- base::GetCurrentProcessHandle(), 0, MSG_ROUTING_NONE, 1,
- request, NULL, NULL);
- KickOffRequest();
+ MakeTestRequest(&test_receiver, 0, 0, 1, URLRequestTestJob::test_url_1());
// request 2 goes to us
MakeTestRequest(0, 0, 2, URLRequestTestJob::test_url_2());
// request 3 goes to the test delegate
- request.url = URLRequestTestJob::test_url_3();
- host_.BeginRequest(&test_receiver, ChildProcessInfo::RENDER_PROCESS,
- base::GetCurrentProcessHandle(), 0, MSG_ROUTING_NONE, 3,
- request, NULL, NULL);
- KickOffRequest();
+ MakeTestRequest(&test_receiver, 0, 0, 3, URLRequestTestJob::test_url_3());
// TODO(mbelshe):
// Now that the async IO path is in place, the IO always completes on the
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 404e68b..e3b1887 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -106,14 +106,14 @@ ResourceMessageFilter::ResourceMessageFilter(
Profile* profile,
RenderWidgetHelper* render_widget_helper,
SpellChecker* spellchecker)
- : channel_(NULL),
+ : Receiver(RENDER_PROCESS),
+ channel_(NULL),
resource_dispatcher_host_(resource_dispatcher_host),
plugin_service_(plugin_service),
print_job_manager_(print_job_manager),
render_process_id_(-1),
spellchecker_(spellchecker),
ALLOW_THIS_IN_INITIALIZER_LIST(resolve_proxy_msg_helper_(this, NULL)),
- render_handle_(NULL),
request_context_(profile->GetRequestContext()),
media_request_context_(profile->GetRequestContextForMedia()),
profile_(profile),
@@ -129,8 +129,8 @@ ResourceMessageFilter::ResourceMessageFilter(
ResourceMessageFilter::~ResourceMessageFilter() {
WorkerService::GetInstance()->RendererShutdown(this);
- if (render_handle_)
- base::CloseProcessHandle(render_handle_);
+ if (handle())
+ base::CloseProcessHandle(handle());
// This function should be called on the IO thread.
DCHECK(MessageLoop::current() ==
@@ -159,9 +159,9 @@ void ResourceMessageFilter::OnFilterAdded(IPC::Channel* channel) {
// Called on the IPC thread:
void ResourceMessageFilter::OnChannelConnected(int32 peer_pid) {
- DCHECK(!render_handle_);
- render_handle_ = base::OpenProcessHandle(peer_pid);
- DCHECK(render_handle_);
+ DCHECK(!handle());
+ set_handle(base::OpenProcessHandle(peer_pid));
+ DCHECK(handle());
// Hook AudioRendererHost to this object after channel is connected so it can
// this object for sending messages.
audio_renderer_host_->IPCChannelConnected(this);
@@ -181,100 +181,93 @@ void ResourceMessageFilter::OnChannelClosing() {
// Called on the IPC thread:
bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) {
- bool handled = true;
bool msg_is_ok = true;
- IPC_BEGIN_MESSAGE_MAP_EX(ResourceMessageFilter, message, msg_is_ok)
- IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWindow, OnMsgCreateWindow)
- IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget)
- // TODO(brettw): we should get the view ID for this so the resource
- // dispatcher can prioritize things based on the visible view.
- IPC_MESSAGE_HANDLER(ViewHostMsg_RequestResource, OnRequestResource)
- IPC_MESSAGE_HANDLER(ViewHostMsg_CancelRequest, OnCancelRequest)
- IPC_MESSAGE_HANDLER(ViewHostMsg_ClosePage_ACK, OnClosePageACK)
- IPC_MESSAGE_HANDLER(ViewHostMsg_DataReceived_ACK, OnDataReceivedACK)
- IPC_MESSAGE_HANDLER(ViewHostMsg_DownloadProgress_ACK, OnDownloadProgressACK)
- IPC_MESSAGE_HANDLER(ViewHostMsg_UploadProgress_ACK, OnUploadProgressACK)
-
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncLoad, OnSyncLoad)
-
- IPC_MESSAGE_HANDLER(ViewHostMsg_SetCookie, OnSetCookie)
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetCookies, OnGetCookies)
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetDataDir, OnGetDataDir)
- IPC_MESSAGE_HANDLER(ViewHostMsg_PluginMessage, OnPluginMessage)
- IPC_MESSAGE_HANDLER(ViewHostMsg_PluginSyncMessage, OnPluginSyncMessage)
+ bool handled = resource_dispatcher_host_->OnMessageReceived(
+ message, this, &msg_is_ok);
+ if (!handled) {
+ handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(ResourceMessageFilter, message, msg_is_ok)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWindow, OnMsgCreateWindow)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_CreateWidget, OnMsgCreateWidget)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_SetCookie, OnSetCookie)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetCookies, OnGetCookies)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetDataDir, OnGetDataDir)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_PluginMessage, OnPluginMessage)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_PluginSyncMessage, OnPluginSyncMessage)
#if defined(OS_WIN) // This hack is Windows-specific.
- IPC_MESSAGE_HANDLER(ViewHostMsg_LoadFont, OnLoadFont)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_LoadFont, OnLoadFont)
#endif
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetScreenInfo, OnGetScreenInfo)
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetPlugins, OnGetPlugins)
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetPluginPath, OnGetPluginPath)
- IPC_MESSAGE_HANDLER(ViewHostMsg_DownloadUrl, OnDownloadUrl)
- IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_ContextMenu,
- OnReceiveContextMenuMsg(message))
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_OpenChannelToPlugin,
- OnOpenChannelToPlugin)
- IPC_MESSAGE_HANDLER(ViewHostMsg_CreateDedicatedWorker,
- OnCreateDedicatedWorker)
- IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardToWorker,
- OnForwardToWorker)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SpellCheck, OnSpellCheck)
- IPC_MESSAGE_HANDLER(ViewHostMsg_DnsPrefetch, OnDnsPrefetch)
- IPC_MESSAGE_HANDLER(ViewHostMsg_RendererHistograms,
- OnRendererHistograms)
- IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_PaintRect,
- render_widget_helper_->DidReceivePaintMsg(message))
- IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardWriteObjectsAsync,
- OnClipboardWriteObjects)
- IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardWriteObjectsSync,
- OnClipboardWriteObjects)
- IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardIsFormatAvailable,
- OnClipboardIsFormatAvailable)
- IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardReadText, OnClipboardReadText)
- IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardReadAsciiText,
- OnClipboardReadAsciiText)
- IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardReadHTML,
- OnClipboardReadHTML)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetScreenInfo, OnGetScreenInfo)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetPlugins, OnGetPlugins)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetPluginPath, OnGetPluginPath)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_DownloadUrl, OnDownloadUrl)
+ IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_ContextMenu,
+ OnReceiveContextMenuMsg(message))
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_OpenChannelToPlugin,
+ OnOpenChannelToPlugin)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_CreateDedicatedWorker,
+ OnCreateDedicatedWorker)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ForwardToWorker,
+ OnForwardToWorker)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SpellCheck, OnSpellCheck)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_DnsPrefetch, OnDnsPrefetch)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_RendererHistograms,
+ OnRendererHistograms)
+ IPC_MESSAGE_HANDLER_GENERIC(ViewHostMsg_PaintRect,
+ render_widget_helper_->DidReceivePaintMsg(message))
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardWriteObjectsAsync,
+ OnClipboardWriteObjects)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardWriteObjectsSync,
+ OnClipboardWriteObjects)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardIsFormatAvailable,
+ OnClipboardIsFormatAvailable)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardReadText, OnClipboardReadText)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardReadAsciiText,
+ OnClipboardReadAsciiText)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ClipboardReadHTML,
+ OnClipboardReadHTML)
#if defined(OS_WIN)|| defined(OS_LINUX)
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetWindowRect, OnGetWindowRect)
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetRootWindowRect, OnGetRootWindowRect)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetWindowRect, OnGetWindowRect)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetRootWindowRect, OnGetRootWindowRect)
#endif
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetMimeTypeFromExtension,
- OnGetMimeTypeFromExtension)
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetMimeTypeFromFile,
- OnGetMimeTypeFromFile)
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetPreferredExtensionForMimeType,
- OnGetPreferredExtensionForMimeType)
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetCPBrowsingContext,
- OnGetCPBrowsingContext)
- IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection)
- IPC_MESSAGE_HANDLER(ViewHostMsg_ResourceTypeStats, OnResourceTypeStats)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ResolveProxy, OnResolveProxy)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetDefaultPrintSettings,
- OnGetDefaultPrintSettings)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetMimeTypeFromExtension,
+ OnGetMimeTypeFromExtension)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetMimeTypeFromFile,
+ OnGetMimeTypeFromFile)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetPreferredExtensionForMimeType,
+ OnGetPreferredExtensionForMimeType)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetCPBrowsingContext,
+ OnGetCPBrowsingContext)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_DuplicateSection, OnDuplicateSection)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_ResourceTypeStats, OnResourceTypeStats)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ResolveProxy, OnResolveProxy)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetDefaultPrintSettings,
+ OnGetDefaultPrintSettings)
#if defined(OS_WIN)
- IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ScriptedPrint,
- OnScriptedPrint)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ScriptedPrint,
+ OnScriptedPrint)
#endif
- IPC_MESSAGE_HANDLER(ViewHostMsg_CreateAudioStream, OnCreateAudioStream)
- IPC_MESSAGE_HANDLER(ViewHostMsg_StartAudioStream, OnStartAudioStream)
- IPC_MESSAGE_HANDLER(ViewHostMsg_CloseAudioStream, OnCloseAudioStream)
- IPC_MESSAGE_HANDLER(ViewHostMsg_NotifyAudioPacketReady,
- OnNotifyAudioPacketReady)
- IPC_MESSAGE_HANDLER(ViewHostMsg_GetAudioVolume, OnGetAudioVolume)
- IPC_MESSAGE_HANDLER(ViewHostMsg_SetAudioVolume, OnSetAudioVolume)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_CreateAudioStream, OnCreateAudioStream)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_StartAudioStream, OnStartAudioStream)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_CloseAudioStream, OnCloseAudioStream)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_NotifyAudioPacketReady,
+ OnNotifyAudioPacketReady)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_GetAudioVolume, OnGetAudioVolume)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_SetAudioVolume, OnSetAudioVolume)
#if defined(OS_MACOSX)
- IPC_MESSAGE_HANDLER(ViewHostMsg_AllocTransportDIB,
- OnAllocTransportDIB)
- IPC_MESSAGE_HANDLER(ViewHostMsg_FreeTransportDIB,
- OnFreeTransportDIB)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_AllocTransportDIB,
+ OnAllocTransportDIB)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_FreeTransportDIB,
+ OnFreeTransportDIB)
#endif
- IPC_MESSAGE_UNHANDLED(
- handled = false)
- IPC_END_MESSAGE_MAP_EX()
+ IPC_MESSAGE_UNHANDLED(
+ handled = false)
+ IPC_END_MESSAGE_MAP_EX()
+ }
if (!msg_is_ok) {
BrowserRenderProcessHost::BadMessageTerminateProcess(message.type(),
- render_handle_);
+ handle());
}
return handled;
@@ -318,12 +311,27 @@ bool ResourceMessageFilter::Send(IPC::Message* message) {
return channel_->Send(message);
}
+URLRequestContext* ResourceMessageFilter::GetRequestContext(
+ uint32 request_id,
+ const ViewHostMsg_Resource_Request& request_data) {
+ URLRequestContext* request_context = request_context_;
+ // If the request has resource type of ResourceType::MEDIA and
+ // LOAD_ENABLE_DOWNLOAD_FILE is set as a load flag, we use a request context
+ // specific to media for handling it because these resources have specific
+ // needs for caching and data passing.
+ if (request_data.resource_type == ResourceType::MEDIA &&
+ (request_data.load_flags & net::LOAD_ENABLE_DOWNLOAD_FILE)) {
+ request_context = media_request_context_;
+ }
+ return request_context_;
+}
+
void ResourceMessageFilter::OnMsgCreateWindow(
int opener_id, bool user_gesture, int* route_id,
ModalDialogEvent* modal_dialog_event) {
render_widget_helper_->CreateNewWindow(opener_id,
user_gesture,
- render_handle_,
+ handle(),
route_id,
modal_dialog_event);
}
@@ -334,71 +342,6 @@ void ResourceMessageFilter::OnMsgCreateWidget(int opener_id,
render_widget_helper_->CreateNewWidget(opener_id, activatable, route_id);
}
-void ResourceMessageFilter::OnRequestResource(
- const IPC::Message& message,
- int request_id,
- const ViewHostMsg_Resource_Request& request) {
- URLRequestContext* request_context = request_context_;
- // If the request has resource type of ResourceType::MEDIA and
- // LOAD_ENABLE_DOWNLOAD_FILE is set as a load flag, we use a request context
- // specific to media for handling it because these resources have specific
- // needs for caching and data passing.
- if (request.resource_type == ResourceType::MEDIA &&
- (request.load_flags & net::LOAD_ENABLE_DOWNLOAD_FILE)) {
- request_context = media_request_context_;
- }
-
- resource_dispatcher_host_->BeginRequest(this,
- ChildProcessInfo::RENDER_PROCESS,
- render_handle_,
- render_process_id_,
- message.routing_id(),
- request_id,
- request,
- request_context,
- NULL);
-}
-
-void ResourceMessageFilter::OnDataReceivedACK(int request_id) {
- resource_dispatcher_host_->OnDataReceivedACK(render_process_id_, request_id);
-}
-
-void ResourceMessageFilter::OnDownloadProgressACK(int request_id) {
- resource_dispatcher_host_->OnDownloadProgressACK(render_process_id_,
- request_id);
-}
-
-void ResourceMessageFilter::OnUploadProgressACK(int request_id) {
- resource_dispatcher_host_->OnUploadProgressACK(render_process_id_,
- request_id);
-}
-
-void ResourceMessageFilter::OnCancelRequest(int request_id) {
- resource_dispatcher_host_->CancelRequest(render_process_id_, request_id,
- true);
-}
-
-void ResourceMessageFilter::OnClosePageACK(int new_render_process_host_id,
- int new_request_id) {
- resource_dispatcher_host_->OnClosePageACK(new_render_process_host_id,
- new_request_id);
-}
-
-void ResourceMessageFilter::OnSyncLoad(
- int request_id,
- const ViewHostMsg_Resource_Request& request,
- IPC::Message* sync_result) {
- resource_dispatcher_host_->BeginRequest(this,
- ChildProcessInfo::RENDER_PROCESS,
- render_handle_,
- render_process_id_,
- sync_result->routing_id(),
- request_id,
- request,
- request_context_,
- sync_result);
-}
-
void ResourceMessageFilter::OnSetCookie(const GURL& url,
const GURL& policy_url,
const std::string& cookie) {
@@ -552,11 +495,11 @@ void ResourceMessageFilter::OnClipboardWriteObjects(
// a task to perform the write on the UI thread.
Clipboard::ObjectMap* long_living_objects = new Clipboard::ObjectMap(objects);
- // We pass the render_handle_ to assist the clipboard with using shared
- // memory objects. render_handle_ is a handle to the process that would
+ // We pass the renderer handle to assist the clipboard with using shared
+ // memory objects. renderer handle is a handle to the process that would
// own any shared memory that might be in the object list.
#if defined(OS_WIN)
- Clipboard::DuplicateRemoteHandles(render_handle_, long_living_objects);
+ Clipboard::DuplicateRemoteHandles(handle(), long_living_objects);
#else
NOTIMPLEMENTED(); // TODO(port) implement this.
#endif
@@ -665,7 +608,7 @@ void ResourceMessageFilter::OnDuplicateSection(
base::SharedMemoryHandle* browser_handle) {
// Duplicate the handle in this process right now so the memory is kept alive
// (even if it is not mapped)
- base::SharedMemory shared_buf(renderer_handle, true, render_handle_);
+ base::SharedMemory shared_buf(renderer_handle, true, handle());
shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), browser_handle);
}
@@ -855,7 +798,7 @@ void ResourceMessageFilter::OnCreateAudioStream(
const IPC::Message& msg, int stream_id,
const ViewHostMsg_Audio_CreateStream& params) {
audio_renderer_host_->CreateStream(
- render_handle_, msg.routing_id(), stream_id, params.format,
+ handle(), msg.routing_id(), stream_id, params.format,
params.channels, params.sample_rate, params.bits_per_sample,
params.packet_size);
}
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index 3269c89..59ba421 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -83,9 +83,14 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
// ResourceDispatcherHost::Receiver methods:
virtual bool Send(IPC::Message* message);
+ virtual URLRequestContext* GetRequestContext(
+ uint32 request_id,
+ const ViewHostMsg_Resource_Request& request_data);
- // Access to the spell checker.
SpellChecker* spellchecker() { return spellchecker_.get(); }
+ ResourceDispatcherHost* resource_dispatcher_host() {
+ return resource_dispatcher_host_;
+ }
// NotificationObserver implementation.
virtual void Observe(NotificationType type,
@@ -96,16 +101,6 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
void OnMsgCreateWindow(int opener_id, bool user_gesture, int* route_id,
ModalDialogEvent* modal_dialog_event);
void OnMsgCreateWidget(int opener_id, bool activatable, int* route_id);
- void OnRequestResource(const IPC::Message& msg, int request_id,
- const ViewHostMsg_Resource_Request& request);
- void OnCancelRequest(int request_id);
- void OnClosePageACK(int new_render_process_host_id, int new_request_id);
- void OnDataReceivedACK(int request_id);
- void OnDownloadProgressACK(int request_id);
- void OnUploadProgressACK(int request_id);
- void OnSyncLoad(int request_id,
- const ViewHostMsg_Resource_Request& request,
- IPC::Message* result_message);
void OnSetCookie(const GURL& url, const GURL& policy_url,
const std::string& cookie);
void OnGetCookies(const GURL& url, const GURL& policy_url,
@@ -246,9 +241,6 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
// the requests to the proxy service).
ResolveProxyMsgHelper resolve_proxy_msg_helper_;
- // Process handle of the renderer process.
- base::ProcessHandle render_handle_;
-
// Contextual information to be used for requests created here.
scoped_refptr<URLRequestContext> request_context_;