diff options
Diffstat (limited to 'chromium/content/browser/loader/resource_loader.cc')
-rw-r--r-- | chromium/content/browser/loader/resource_loader.cc | 112 |
1 files changed, 70 insertions, 42 deletions
diff --git a/chromium/content/browser/loader/resource_loader.cc b/chromium/content/browser/loader/resource_loader.cc index bdc9644b1dd..0becbf42a3d 100644 --- a/chromium/content/browser/loader/resource_loader.cc +++ b/chromium/content/browser/loader/resource_loader.cc @@ -8,6 +8,7 @@ #include "base/message_loop/message_loop.h" #include "base/metrics/histogram.h" #include "base/time/time.h" +#include "content/browser/appcache/appcache_interceptor.h" #include "content/browser/child_process_security_policy_impl.h" #include "content/browser/loader/cross_site_resource_handler.h" #include "content/browser/loader/detachable_resource_handler.h" @@ -29,7 +30,6 @@ #include "net/http/http_response_headers.h" #include "net/ssl/client_cert_store.h" #include "net/url_request/url_request_status.h" -#include "webkit/browser/appcache/appcache_interceptor.h" using base::TimeDelta; using base::TimeTicks; @@ -54,7 +54,7 @@ void PopulateResourceResponse(net::URLRequest* request, response->head.connection_info = response_info.connection_info; response->head.was_fetched_via_proxy = request->was_fetched_via_proxy(); response->head.socket_address = request->GetSocketAddress(); - appcache::AppCacheInterceptor::GetExtraResponseInfo( + AppCacheInterceptor::GetExtraResponseInfo( request, &response->head.appcache_id, &response->head.appcache_manifest_url); @@ -99,8 +99,7 @@ void ResourceLoader::StartRequest() { // Give the handler a chance to delay the URLRequest from being started. bool defer_start = false; - if (!handler_->OnWillStart(GetRequestInfo()->GetRequestID(), request_->url(), - &defer_start)) { + if (!handler_->OnWillStart(request_->url(), &defer_start)) { Cancel(); return; } @@ -127,8 +126,6 @@ void ResourceLoader::CancelWithError(int error_code) { } void ResourceLoader::ReportUploadProgress() { - ResourceRequestInfoImpl* info = GetRequestInfo(); - if (waiting_for_upload_progress_ack_) return; // Send one progress event at a time. @@ -152,8 +149,7 @@ void ResourceLoader::ReportUploadProgress() { if (is_finished || enough_new_progress || too_much_time_passed) { if (request_->load_flags() & net::LOAD_ENABLE_UPLOAD_PROGRESS) { - handler_->OnUploadProgress( - info->GetRequestID(), progress.position(), progress.size()); + handler_->OnUploadProgress(progress.position(), progress.size()); waiting_for_upload_progress_ack_ = true; } last_upload_ticks_ = TimeTicks::Now(); @@ -161,18 +157,19 @@ void ResourceLoader::ReportUploadProgress() { } } -void ResourceLoader::MarkAsTransferring(const GURL& target_url) { - CHECK_EQ(GetRequestInfo()->GetResourceType(), ResourceType::MAIN_FRAME) - << "Cannot transfer non-main frame navigations"; +void ResourceLoader::MarkAsTransferring() { + CHECK(ResourceType::IsFrame(GetRequestInfo()->GetResourceType())) + << "Can only transfer for navigations"; is_transferring_ = true; - - // When transferring a request to another process, the renderer doesn't get - // a chance to update the cookie policy URL. Do it here instead. - request()->set_first_party_for_cookies(target_url); } void ResourceLoader::CompleteTransfer() { - DCHECK_EQ(DEFERRED_READ, deferred_stage_); + // Although CrossSiteResourceHandler defers at OnResponseStarted + // (DEFERRED_READ), it may be seeing a replay of events via + // BufferedResourceHandler, and so the request itself is actually deferred at + // a later read stage. + DCHECK(DEFERRED_READ == deferred_stage_ || + DEFERRED_RESPONSE_COMPLETE == deferred_stage_); is_transferring_ = false; GetRequestInfo()->cross_site_handler()->ResumeResponse(); @@ -204,7 +201,7 @@ void ResourceLoader::OnReceivedRedirect(net::URLRequest* unused, ResourceRequestInfoImpl* info = GetRequestInfo(); - if (info->process_type() != PROCESS_TYPE_PLUGIN && + if (info->GetProcessType() != PROCESS_TYPE_PLUGIN && !ChildProcessSecurityPolicyImpl::GetInstance()-> CanRequestURL(info->GetChildID(), new_url)) { VLOG(1) << "Denied unauthorized request for " @@ -226,8 +223,7 @@ void ResourceLoader::OnReceivedRedirect(net::URLRequest* unused, scoped_refptr<ResourceResponse> response(new ResourceResponse()); PopulateResourceResponse(request_.get(), response.get()); - if (!handler_->OnRequestRedirected( - info->GetRequestID(), new_url, response.get(), defer)) { + if (!handler_->OnRequestRedirected(new_url, response.get(), defer)) { Cancel(); } else if (*defer) { deferred_stage_ = DEFERRED_REDIRECT; // Follow redirect when resumed. @@ -243,11 +239,6 @@ void ResourceLoader::OnAuthRequired(net::URLRequest* unused, return; } - if (!delegate_->AcceptAuthRequest(this, auth_info)) { - request_->CancelAuth(); - return; - } - // Create a login dialog on the UI thread to get authentication data, or pull // from cache and continue on the IO thread. @@ -263,7 +254,7 @@ void ResourceLoader::OnCertificateRequested( net::SSLCertRequestInfo* cert_info) { DCHECK_EQ(request_.get(), unused); - if (!delegate_->AcceptSSLClientCertificateRequest(this, cert_info)) { + if (request_->load_flags() & net::LOAD_PREFETCH) { request_->Cancel(); return; } @@ -283,8 +274,8 @@ void ResourceLoader::OnSSLCertificateError(net::URLRequest* request, ResourceRequestInfoImpl* info = GetRequestInfo(); int render_process_id; - int render_view_id; - if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) + int render_frame_id; + if (!info->GetAssociatedRenderFrame(&render_process_id, &render_frame_id)) NOTREACHED(); SSLManager::OnSSLCertificateError( @@ -293,11 +284,24 @@ void ResourceLoader::OnSSLCertificateError(net::URLRequest* request, info->GetResourceType(), request_->url(), render_process_id, - render_view_id, + render_frame_id, ssl_info, fatal); } +void ResourceLoader::OnBeforeNetworkStart(net::URLRequest* unused, + bool* defer) { + DCHECK_EQ(request_.get(), unused); + + // Give the handler a chance to delay the URLRequest from using the network. + if (!handler_->OnBeforeNetworkStart(request_->url(), defer)) { + Cancel(); + return; + } else if (*defer) { + deferred_stage_ = DEFERRED_NETWORK_START; + } +} + void ResourceLoader::OnResponseStarted(net::URLRequest* unused) { DCHECK_EQ(request_.get(), unused); @@ -352,12 +356,21 @@ void ResourceLoader::OnReadCompleted(net::URLRequest* unused, int bytes_read) { CompleteRead(bytes_read); - if (is_deferred()) + // If the handler cancelled or deferred the request, do not continue + // processing the read. If cancelled, the URLRequest has already been + // cancelled and will schedule an erroring OnReadCompleted later. If deferred, + // do nothing until resumed. + // + // Note: if bytes_read is 0 (EOF) and the handler defers, resumption will call + // ResponseCompleted(). + if (is_deferred() || !request_->status().is_success()) return; - if (request_->status().is_success() && bytes_read > 0) { + if (bytes_read > 0) { StartReading(true); // Read the next chunk. } else { + // URLRequest reported an EOF. Call ResponseCompleted. + DCHECK_EQ(0, bytes_read); ResponseCompleted(); } } @@ -400,6 +413,9 @@ void ResourceLoader::Resume() { case DEFERRED_START: StartRequestInternal(); break; + case DEFERRED_NETWORK_START: + request_->ResumeNetworkStart(); + break; case DEFERRED_REDIRECT: request_->FollowDeferredRedirect(); break; @@ -409,6 +425,12 @@ void ResourceLoader::Resume() { base::Bind(&ResourceLoader::ResumeReading, weak_ptr_factory_.GetWeakPtr())); break; + case DEFERRED_RESPONSE_COMPLETE: + base::MessageLoop::current()->PostTask( + FROM_HERE, + base::Bind(&ResourceLoader::ResponseCompleted, + weak_ptr_factory_.GetWeakPtr())); + break; case DEFERRED_FINISH: // Delay self-destruction since we don't know how we were reached. base::MessageLoop::current()->PostTask( @@ -425,6 +447,11 @@ void ResourceLoader::Cancel() { void ResourceLoader::StartRequestInternal() { DCHECK(!request_->is_pending()); + + if (!request_->status().is_success()) { + return; + } + request_->Start(); delegate_->DidStartRequest(this); @@ -483,9 +510,9 @@ void ResourceLoader::StoreSignedCertificateTimestamps( for (net::SignedCertificateTimestampAndStatusList::const_iterator iter = sct_list.begin(); iter != sct_list.end(); ++iter) { - const int sct_id(sct_store->Store(iter->sct_, process_id)); + const int sct_id(sct_store->Store(iter->sct, process_id)); sct_ids->push_back( - SignedCertificateTimestampIDAndStatus(sct_id, iter->status_)); + SignedCertificateTimestampIDAndStatus(sct_id, iter->status)); } } @@ -521,8 +548,7 @@ void ResourceLoader::CompleteResponseStarted() { delegate_->DidReceiveResponse(this); bool defer = false; - if (!handler_->OnResponseStarted( - info->GetRequestID(), response.get(), &defer)) { + if (!handler_->OnResponseStarted(response.get(), &defer)) { Cancel(); } else if (defer) { read_deferral_start_time_ = base::TimeTicks::Now(); @@ -568,7 +594,6 @@ void ResourceLoader::ResumeReading() { } void ResourceLoader::ReadMore(int* bytes_read) { - ResourceRequestInfoImpl* info = GetRequestInfo(); DCHECK(!is_deferred()); // Make sure we track the buffer in at least one place. This ensures it gets @@ -576,7 +601,7 @@ void ResourceLoader::ReadMore(int* bytes_read) { // doesn't use the buffer. scoped_refptr<net::IOBuffer> buf; int buf_size; - if (!handler_->OnWillRead(info->GetRequestID(), &buf, &buf_size, -1)) { + if (!handler_->OnWillRead(&buf, &buf_size, -1)) { Cancel(); return; } @@ -594,14 +619,18 @@ void ResourceLoader::CompleteRead(int bytes_read) { DCHECK(bytes_read >= 0); DCHECK(request_->status().is_success()); - ResourceRequestInfoImpl* info = GetRequestInfo(); - bool defer = false; - if (!handler_->OnReadCompleted(info->GetRequestID(), bytes_read, &defer)) { + if (!handler_->OnReadCompleted(bytes_read, &defer)) { Cancel(); } else if (defer) { - deferred_stage_ = DEFERRED_READ; // Read next chunk when resumed. + deferred_stage_ = + bytes_read > 0 ? DEFERRED_READ : DEFERRED_RESPONSE_COMPLETE; } + + // Note: the request may still have been cancelled while OnReadCompleted + // returns true if OnReadCompleted caused request to get cancelled + // out-of-band. (In AwResourceDispatcherHostDelegate::DownloadStarting, for + // instance.) } void ResourceLoader::ResponseCompleted() { @@ -625,8 +654,7 @@ void ResourceLoader::ResponseCompleted() { } bool defer = false; - handler_->OnResponseCompleted(info->GetRequestID(), request_->status(), - security_info, &defer); + handler_->OnResponseCompleted(request_->status(), security_info, &defer); if (defer) { // The handler is not ready to die yet. We will call DidFinishLoading when // we resume. |