OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
6 | 6 |
7 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 7 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "chrome/browser/cert_store.h" | 15 #include "chrome/browser/cert_store.h" |
16 #include "chrome/browser/child_process_security_policy.h" | 16 #include "chrome/browser/child_process_security_policy.h" |
17 #include "chrome/browser/cross_site_request_manager.h" | 17 #include "chrome/browser/cross_site_request_manager.h" |
18 #include "chrome/browser/download/download_file.h" | 18 #include "chrome/browser/download/download_file.h" |
19 #include "chrome/browser/download/download_manager.h" | 19 #include "chrome/browser/download/download_manager.h" |
20 #include "chrome/browser/download/download_request_manager.h" | 20 #include "chrome/browser/download/download_request_manager.h" |
21 #include "chrome/browser/download/save_file_manager.h" | 21 #include "chrome/browser/download/save_file_manager.h" |
22 #include "chrome/browser/external_protocol_handler.h" | 22 #include "chrome/browser/external_protocol_handler.h" |
23 #include "chrome/browser/plugin_service.h" | 23 #include "chrome/browser/plugin_service.h" |
24 #include "chrome/browser/profile.h" | 24 #include "chrome/browser/profile.h" |
25 #include "chrome/browser/renderer_host/async_resource_handler.h" | 25 #include "chrome/browser/renderer_host/async_resource_handler.h" |
26 #include "chrome/browser/renderer_host/buffered_resource_handler.h" | 26 #include "chrome/browser/renderer_host/buffered_resource_handler.h" |
27 #include "chrome/browser/renderer_host/cross_site_resource_handler.h" | 27 #include "chrome/browser/renderer_host/cross_site_resource_handler.h" |
28 #include "chrome/browser/renderer_host/download_resource_handler.h" | 28 #include "chrome/browser/renderer_host/download_resource_handler.h" |
29 #include "chrome/browser/renderer_host/media_resource_handler.h" | |
30 #include "chrome/browser/renderer_host/render_view_host.h" | 29 #include "chrome/browser/renderer_host/render_view_host.h" |
31 #include "chrome/browser/renderer_host/resource_request_details.h" | 30 #include "chrome/browser/renderer_host/resource_request_details.h" |
32 #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" | 31 #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" |
33 #include "chrome/browser/renderer_host/save_file_resource_handler.h" | 32 #include "chrome/browser/renderer_host/save_file_resource_handler.h" |
34 #include "chrome/browser/renderer_host/sync_resource_handler.h" | 33 #include "chrome/browser/renderer_host/sync_resource_handler.h" |
35 #include "chrome/browser/tab_contents/tab_util.h" | 34 #include "chrome/browser/tab_contents/tab_util.h" |
36 #include "chrome/browser/tab_contents/tab_contents.h" | 35 #include "chrome/browser/tab_contents/tab_contents.h" |
37 #include "chrome/common/notification_service.h" | 36 #include "chrome/common/notification_service.h" |
38 #include "chrome/common/render_messages.h" | 37 #include "chrome/common/render_messages.h" |
39 #include "net/base/auth.h" | 38 #include "net/base/auth.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 if (!IsResourceDispatcherHostMessage(message)) | 223 if (!IsResourceDispatcherHostMessage(message)) |
225 return false; | 224 return false; |
226 | 225 |
227 *message_was_ok = true; | 226 *message_was_ok = true; |
228 receiver_ = receiver; | 227 receiver_ = receiver; |
229 | 228 |
230 IPC_BEGIN_MESSAGE_MAP_EX(ResourceDispatcherHost, message, *message_was_ok) | 229 IPC_BEGIN_MESSAGE_MAP_EX(ResourceDispatcherHost, message, *message_was_ok) |
231 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestResource, OnRequestResource) | 230 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestResource, OnRequestResource) |
232 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncLoad, OnSyncLoad) | 231 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncLoad, OnSyncLoad) |
233 IPC_MESSAGE_HANDLER(ViewHostMsg_DataReceived_ACK, OnDataReceivedACK) | 232 IPC_MESSAGE_HANDLER(ViewHostMsg_DataReceived_ACK, OnDataReceivedACK) |
234 IPC_MESSAGE_HANDLER(ViewHostMsg_DownloadProgress_ACK, OnDownloadProgressACK) | |
235 IPC_MESSAGE_HANDLER(ViewHostMsg_UploadProgress_ACK, OnUploadProgressACK) | 233 IPC_MESSAGE_HANDLER(ViewHostMsg_UploadProgress_ACK, OnUploadProgressACK) |
236 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelRequest, OnCancelRequest) | 234 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelRequest, OnCancelRequest) |
237 IPC_MESSAGE_HANDLER(ViewHostMsg_ClosePage_ACK, OnClosePageACK) | 235 IPC_MESSAGE_HANDLER(ViewHostMsg_ClosePage_ACK, OnClosePageACK) |
238 IPC_END_MESSAGE_MAP_EX() | 236 IPC_END_MESSAGE_MAP_EX() |
239 | 237 |
240 receiver_ = NULL; | 238 receiver_ = NULL; |
241 | 239 |
242 return true; | 240 return true; |
243 } | 241 } |
244 | 242 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 scoped_refptr<ResourceHandler> handler; | 304 scoped_refptr<ResourceHandler> handler; |
307 if (sync_result) { | 305 if (sync_result) { |
308 handler = new SyncResourceHandler(receiver_, request_data.url, sync_result); | 306 handler = new SyncResourceHandler(receiver_, request_data.url, sync_result); |
309 } else { | 307 } else { |
310 handler = new AsyncResourceHandler(receiver_, | 308 handler = new AsyncResourceHandler(receiver_, |
311 process_id, | 309 process_id, |
312 route_id, | 310 route_id, |
313 receiver_->handle(), | 311 receiver_->handle(), |
314 request_data.url, | 312 request_data.url, |
315 this); | 313 this); |
316 // If the resource type is ResourceType::MEDIA and LOAD_ENABLE_DOWNLOAD_FILE | |
317 // is enabled we insert a media resource handler. | |
318 if (request_data.resource_type == ResourceType::MEDIA && | |
319 (request_data.load_flags & net::LOAD_ENABLE_DOWNLOAD_FILE)) { | |
320 handler = new MediaResourceHandler(handler, | |
321 receiver_, | |
322 process_id, | |
323 route_id, | |
324 receiver_->handle(), | |
325 this); | |
326 } | |
327 } | 314 } |
328 | 315 |
329 if (HandleExternalProtocol(request_id, process_id, route_id, | 316 if (HandleExternalProtocol(request_id, process_id, route_id, |
330 request_data.url, request_data.resource_type, | 317 request_data.url, request_data.resource_type, |
331 handler)) { | 318 handler)) { |
332 return; | 319 return; |
333 } | 320 } |
334 | 321 |
335 // Construct the request. | 322 // Construct the request. |
336 URLRequest* request = new URLRequest(request_data.url, this); | 323 URLRequest* request = new URLRequest(request_data.url, this); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 if (info->pending_data_count == kMaxPendingDataMessages) { | 415 if (info->pending_data_count == kMaxPendingDataMessages) { |
429 // Decrement the pending data count one more time because we also | 416 // Decrement the pending data count one more time because we also |
430 // incremented it before pausing the request. | 417 // incremented it before pausing the request. |
431 info->pending_data_count--; | 418 info->pending_data_count--; |
432 | 419 |
433 // Resume the request. | 420 // Resume the request. |
434 PauseRequest(process_id, request_id, false); | 421 PauseRequest(process_id, request_id, false); |
435 } | 422 } |
436 } | 423 } |
437 | 424 |
438 void ResourceDispatcherHost::OnDownloadProgressACK(int request_id) { | |
439 // TODO(hclam): do something to help rate limiting the message. | |
440 } | |
441 | |
442 void ResourceDispatcherHost::OnUploadProgressACK(int request_id) { | 425 void ResourceDispatcherHost::OnUploadProgressACK(int request_id) { |
443 int process_id = receiver_->GetProcessId(); | 426 int process_id = receiver_->GetProcessId(); |
444 PendingRequestList::iterator i = pending_requests_.find( | 427 PendingRequestList::iterator i = pending_requests_.find( |
445 GlobalRequestID(process_id, request_id)); | 428 GlobalRequestID(process_id, request_id)); |
446 if (i == pending_requests_.end()) | 429 if (i == pending_requests_.end()) |
447 return; | 430 return; |
448 | 431 |
449 ExtraRequestInfo* info = ExtraInfoForRequest(i->second); | 432 ExtraRequestInfo* info = ExtraInfoForRequest(i->second); |
450 info->waiting_for_upload_progress_ack = false; | 433 info->waiting_for_upload_progress_ack = false; |
451 } | 434 } |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 response->response_head.status = request->status(); | 892 response->response_head.status = request->status(); |
910 response->response_head.request_time = request->request_time(); | 893 response->response_head.request_time = request->request_time(); |
911 response->response_head.response_time = request->response_time(); | 894 response->response_head.response_time = request->response_time(); |
912 response->response_head.headers = request->response_headers(); | 895 response->response_head.headers = request->response_headers(); |
913 request->GetCharset(&response->response_head.charset); | 896 request->GetCharset(&response->response_head.charset); |
914 response->response_head.filter_policy = info->filter_policy; | 897 response->response_head.filter_policy = info->filter_policy; |
915 response->response_head.content_length = request->GetExpectedContentSize(); | 898 response->response_head.content_length = request->GetExpectedContentSize(); |
916 response->response_head.app_cache_id = WebAppCacheContext::kNoAppCacheId; | 899 response->response_head.app_cache_id = WebAppCacheContext::kNoAppCacheId; |
917 request->GetMimeType(&response->response_head.mime_type); | 900 request->GetMimeType(&response->response_head.mime_type); |
918 | 901 |
919 // Make sure we don't get a file handle if LOAD_ENABLE_DOWNLOAD_FILE is not | |
920 // set. | |
921 DCHECK((request->load_flags() & net::LOAD_ENABLE_DOWNLOAD_FILE) || | |
922 request->response_data_file() == base::kInvalidPlatformFileValue); | |
923 #if defined(OS_POSIX) | |
924 response->response_head.response_data_file.fd = request->response_data_file(); | |
925 #elif defined(OS_WIN) | |
926 response->response_head.response_data_file = request->response_data_file(); | |
927 #endif | |
928 | |
929 if (request->ssl_info().cert) { | 902 if (request->ssl_info().cert) { |
930 int cert_id = | 903 int cert_id = |
931 CertStore::GetSharedInstance()->StoreCert( | 904 CertStore::GetSharedInstance()->StoreCert( |
932 request->ssl_info().cert, | 905 request->ssl_info().cert, |
933 info->process_id); | 906 info->process_id); |
934 int cert_status = request->ssl_info().cert_status; | 907 int cert_status = request->ssl_info().cert_status; |
935 // EV certificate verification could be expensive. We don't want to spend | 908 // EV certificate verification could be expensive. We don't want to spend |
936 // time performing EV certificate verification on all resources because | 909 // time performing EV certificate verification on all resources because |
937 // EV status is irrelevant to sub-frames and sub-resources. So we call | 910 // EV status is irrelevant to sub-frames and sub-resources. So we call |
938 // IsEV here rather than in the network layer because the network layer | 911 // IsEV here rather than in the network layer because the network layer |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 case ViewHostMsg_UploadProgress_ACK::ID: | 1531 case ViewHostMsg_UploadProgress_ACK::ID: |
1559 case ViewHostMsg_SyncLoad::ID: | 1532 case ViewHostMsg_SyncLoad::ID: |
1560 return true; | 1533 return true; |
1561 | 1534 |
1562 default: | 1535 default: |
1563 break; | 1536 break; |
1564 } | 1537 } |
1565 | 1538 |
1566 return false; | 1539 return false; |
1567 } | 1540 } |
OLD | NEW |