| 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/command_line.h" |
| 11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 12 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 13 #include "base/stl_util-inl.h" | 14 #include "base/stl_util-inl.h" |
| 14 #include "base/time.h" | 15 #include "base/time.h" |
| 15 #include "chrome/browser/cert_store.h" | 16 #include "chrome/browser/cert_store.h" |
| 16 #include "chrome/browser/child_process_security_policy.h" | 17 #include "chrome/browser/child_process_security_policy.h" |
| 17 #include "chrome/browser/cross_site_request_manager.h" | 18 #include "chrome/browser/cross_site_request_manager.h" |
| 18 #include "chrome/browser/download/download_file.h" | 19 #include "chrome/browser/download/download_file.h" |
| 19 #include "chrome/browser/download/download_manager.h" | 20 #include "chrome/browser/download/download_manager.h" |
| 20 #include "chrome/browser/download/download_request_manager.h" | 21 #include "chrome/browser/download/download_request_manager.h" |
| 21 #include "chrome/browser/download/save_file_manager.h" | 22 #include "chrome/browser/download/save_file_manager.h" |
| 22 #include "chrome/browser/external_protocol_handler.h" | 23 #include "chrome/browser/external_protocol_handler.h" |
| 23 #include "chrome/browser/plugin_service.h" | 24 #include "chrome/browser/plugin_service.h" |
| 24 #include "chrome/browser/profile.h" | 25 #include "chrome/browser/profile.h" |
| 25 #include "chrome/browser/renderer_host/async_resource_handler.h" | 26 #include "chrome/browser/renderer_host/async_resource_handler.h" |
| 26 #include "chrome/browser/renderer_host/buffered_resource_handler.h" | 27 #include "chrome/browser/renderer_host/buffered_resource_handler.h" |
| 27 #include "chrome/browser/renderer_host/cross_site_resource_handler.h" | 28 #include "chrome/browser/renderer_host/cross_site_resource_handler.h" |
| 28 #include "chrome/browser/renderer_host/download_resource_handler.h" | 29 #include "chrome/browser/renderer_host/download_resource_handler.h" |
| 29 #include "chrome/browser/renderer_host/render_view_host.h" | 30 #include "chrome/browser/renderer_host/render_view_host.h" |
| 30 #include "chrome/browser/renderer_host/resource_request_details.h" | 31 #include "chrome/browser/renderer_host/resource_request_details.h" |
| 31 #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" | 32 #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" |
| 32 #include "chrome/browser/renderer_host/save_file_resource_handler.h" | 33 #include "chrome/browser/renderer_host/save_file_resource_handler.h" |
| 33 #include "chrome/browser/renderer_host/sync_resource_handler.h" | 34 #include "chrome/browser/renderer_host/sync_resource_handler.h" |
| 34 #include "chrome/browser/tab_contents/tab_util.h" | 35 #include "chrome/browser/tab_contents/tab_util.h" |
| 35 #include "chrome/browser/tab_contents/tab_contents.h" | 36 #include "chrome/browser/tab_contents/tab_contents.h" |
| 37 #include "chrome/common/chrome_switches.h" |
| 36 #include "chrome/common/notification_service.h" | 38 #include "chrome/common/notification_service.h" |
| 37 #include "chrome/common/render_messages.h" | 39 #include "chrome/common/render_messages.h" |
| 38 #include "net/base/auth.h" | 40 #include "net/base/auth.h" |
| 39 #include "net/base/cert_status_flags.h" | 41 #include "net/base/cert_status_flags.h" |
| 40 #include "net/base/load_flags.h" | 42 #include "net/base/load_flags.h" |
| 41 #include "net/base/mime_util.h" | 43 #include "net/base/mime_util.h" |
| 42 #include "net/base/net_errors.h" | 44 #include "net/base/net_errors.h" |
| 45 #include "net/base/ssl_cert_request_info.h" |
| 43 #include "net/url_request/url_request.h" | 46 #include "net/url_request/url_request.h" |
| 44 #include "webkit/glue/webappcachecontext.h" | 47 #include "webkit/glue/webappcachecontext.h" |
| 45 | 48 |
| 46 // TODO(port): Move these includes to the above section when porting is done. | 49 // TODO(port): Move these includes to the above section when porting is done. |
| 47 #if defined(OS_POSIX) | 50 #if defined(OS_POSIX) |
| 48 #include "chrome/common/temp_scaffolding_stubs.h" | 51 #include "chrome/common/temp_scaffolding_stubs.h" |
| 49 #elif defined(OS_WIN) | 52 #elif defined(OS_WIN) |
| 50 #include "chrome/browser/login_prompt.h" | 53 #include "chrome/browser/login_prompt.h" |
| 51 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 54 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
| 52 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 55 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 // Consults the RendererSecurity policy to determine whether the | 104 // Consults the RendererSecurity policy to determine whether the |
| 102 // ResourceDispatcherHost should service this request. A request might be | 105 // ResourceDispatcherHost should service this request. A request might be |
| 103 // disallowed if the renderer is not authorized to restrive the request URL or | 106 // disallowed if the renderer is not authorized to restrive the request URL or |
| 104 // if the renderer is attempting to upload an unauthorized file. | 107 // if the renderer is attempting to upload an unauthorized file. |
| 105 bool ShouldServiceRequest(ChildProcessInfo::ProcessType process_type, | 108 bool ShouldServiceRequest(ChildProcessInfo::ProcessType process_type, |
| 106 int process_id, | 109 int process_id, |
| 107 const ViewHostMsg_Resource_Request& request_data) { | 110 const ViewHostMsg_Resource_Request& request_data) { |
| 108 if (process_type == ChildProcessInfo::PLUGIN_PROCESS) | 111 if (process_type == ChildProcessInfo::PLUGIN_PROCESS) |
| 109 return true; | 112 return true; |
| 110 | 113 |
| 111 ChildProcessSecurityPolicy* policy = ChildProcessSecurityPolicy::GetInstance()
; | 114 ChildProcessSecurityPolicy* policy = |
| 115 ChildProcessSecurityPolicy::GetInstance(); |
| 112 | 116 |
| 113 // Check if the renderer is permitted to request the requested URL. | 117 // Check if the renderer is permitted to request the requested URL. |
| 114 if (!policy->CanRequestURL(process_id, request_data.url)) { | 118 if (!policy->CanRequestURL(process_id, request_data.url)) { |
| 115 LOG(INFO) << "Denied unauthorized request for " << | 119 LOG(INFO) << "Denied unauthorized request for " << |
| 116 request_data.url.possibly_invalid_spec(); | 120 request_data.url.possibly_invalid_spec(); |
| 117 return false; | 121 return false; |
| 118 } | 122 } |
| 119 | 123 |
| 120 // Check if the renderer is permitted to upload the requested files. | 124 // Check if the renderer is permitted to upload the requested files. |
| 121 if (request_data.upload_data) { | 125 if (request_data.upload_data) { |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 // In this case, ignore the cancel since we handle downloads in the browser. | 617 // In this case, ignore the cancel since we handle downloads in the browser. |
| 614 ExtraRequestInfo* info = ExtraInfoForRequest(i->second); | 618 ExtraRequestInfo* info = ExtraInfoForRequest(i->second); |
| 615 if (!from_renderer || !info->is_download) { | 619 if (!from_renderer || !info->is_download) { |
| 616 if (info->login_handler) { | 620 if (info->login_handler) { |
| 617 info->login_handler->OnRequestCancelled(); | 621 info->login_handler->OnRequestCancelled(); |
| 618 info->login_handler = NULL; | 622 info->login_handler = NULL; |
| 619 } | 623 } |
| 620 if (!i->second->is_pending() && allow_delete) { | 624 if (!i->second->is_pending() && allow_delete) { |
| 621 // No io is pending, canceling the request won't notify us of anything, | 625 // No io is pending, canceling the request won't notify us of anything, |
| 622 // so we explicitly remove it. | 626 // so we explicitly remove it. |
| 623 // TODO: removing the request in this manner means we're not notifying | 627 // TODO(sky): removing the request in this manner means we're not |
| 624 // anyone. We need make sure the event handlers and others are notified | 628 // notifying anyone. We need make sure the event handlers and others are |
| 625 // so that everything is cleaned up properly. | 629 // notified so that everything is cleaned up properly. |
| 626 RemovePendingRequest(info->process_id, info->request_id); | 630 RemovePendingRequest(info->process_id, info->request_id); |
| 627 } else { | 631 } else { |
| 628 i->second->Cancel(); | 632 i->second->Cancel(); |
| 629 } | 633 } |
| 630 } | 634 } |
| 631 | 635 |
| 632 // Do not remove from the pending requests, as the request will still | 636 // Do not remove from the pending requests, as the request will still |
| 633 // call AllDataReceived, and may even have more data before it does | 637 // call AllDataReceived, and may even have more data before it does |
| 634 // that. | 638 // that. |
| 635 } | 639 } |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 // TODO(mpcomplete): We should block the parent tab while waiting for | 843 // TODO(mpcomplete): We should block the parent tab while waiting for |
| 840 // authentication. | 844 // authentication. |
| 841 // That would also solve the problem of the URLRequest being cancelled | 845 // That would also solve the problem of the URLRequest being cancelled |
| 842 // before we receive authentication. | 846 // before we receive authentication. |
| 843 ExtraRequestInfo* info = ExtraInfoForRequest(request); | 847 ExtraRequestInfo* info = ExtraInfoForRequest(request); |
| 844 DCHECK(!info->login_handler) << | 848 DCHECK(!info->login_handler) << |
| 845 "OnAuthRequired called with login_handler pending"; | 849 "OnAuthRequired called with login_handler pending"; |
| 846 info->login_handler = CreateLoginPrompt(auth_info, request, ui_loop_); | 850 info->login_handler = CreateLoginPrompt(auth_info, request, ui_loop_); |
| 847 } | 851 } |
| 848 | 852 |
| 853 void ResourceDispatcherHost::OnCertificateRequested( |
| 854 URLRequest* request, |
| 855 net::SSLCertRequestInfo* cert_request_info) { |
| 856 DCHECK(request); |
| 857 |
| 858 bool select_first_cert = CommandLine::ForCurrentProcess()->HasSwitch( |
| 859 switches::kAutoSSLClientAuth); |
| 860 net::X509Certificate* cert = |
| 861 select_first_cert && !cert_request_info->client_certs.empty() ? |
| 862 cert_request_info->client_certs[0] : NULL; |
| 863 request->ContinueWithCertificate(cert); |
| 864 } |
| 865 |
| 849 void ResourceDispatcherHost::OnSSLCertificateError( | 866 void ResourceDispatcherHost::OnSSLCertificateError( |
| 850 URLRequest* request, | 867 URLRequest* request, |
| 851 int cert_error, | 868 int cert_error, |
| 852 net::X509Certificate* cert) { | 869 net::X509Certificate* cert) { |
| 853 DCHECK(request); | 870 DCHECK(request); |
| 854 SSLManager::OnSSLCertificateError(this, request, cert_error, cert, ui_loop_); | 871 SSLManager::OnSSLCertificateError(this, request, cert_error, cert, ui_loop_); |
| 855 } | 872 } |
| 856 | 873 |
| 857 void ResourceDispatcherHost::OnResponseStarted(URLRequest* request) { | 874 void ResourceDispatcherHost::OnResponseStarted(URLRequest* request) { |
| 858 RESOURCE_LOG("OnResponseStarted: " << request->url().spec()); | 875 RESOURCE_LOG("OnResponseStarted: " << request->url().spec()); |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 case ViewHostMsg_UploadProgress_ACK::ID: | 1552 case ViewHostMsg_UploadProgress_ACK::ID: |
| 1536 case ViewHostMsg_SyncLoad::ID: | 1553 case ViewHostMsg_SyncLoad::ID: |
| 1537 return true; | 1554 return true; |
| 1538 | 1555 |
| 1539 default: | 1556 default: |
| 1540 break; | 1557 break; |
| 1541 } | 1558 } |
| 1542 | 1559 |
| 1543 return false; | 1560 return false; |
| 1544 } | 1561 } |
| OLD | NEW |