diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-20 15:06:40 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-22 11:48:58 +0000 |
commit | daa093eea7c773db06799a13bd7e4e2e2a9f8f14 (patch) | |
tree | 96cc5e7b9194c1b29eab927730bfa419e7111c25 /chromium/content/browser/appcache/appcache_url_loader_job.cc | |
parent | be59a35641616a4cf23c4a13fa0632624b021c1b (diff) | |
download | qtwebengine-chromium-daa093eea7c773db06799a13bd7e4e2e2a9f8f14.tar.gz |
BASELINE: Update Chromium to 63.0.3239.58
Change-Id: Ia93b322a00ba4dd4004f3bcf1254063ba90e1605
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/content/browser/appcache/appcache_url_loader_job.cc')
-rw-r--r-- | chromium/content/browser/appcache/appcache_url_loader_job.cc | 95 |
1 files changed, 83 insertions, 12 deletions
diff --git a/chromium/content/browser/appcache/appcache_url_loader_job.cc b/chromium/content/browser/appcache/appcache_url_loader_job.cc index 74591da9b39..0a45271126f 100644 --- a/chromium/content/browser/appcache/appcache_url_loader_job.cc +++ b/chromium/content/browser/appcache/appcache_url_loader_job.cc @@ -16,8 +16,20 @@ namespace content { +namespace { + +// Max number of http redirects to follow. Same number as gecko. +// TODO(ananta/michaeln). Avoid duplicating logic from the n/w stack and figure +// out a way to use FollowRedirect() mechanism in the network URL loader. +const int kMaxRedirects = 20; + +} // namespace + SubresourceLoadInfo::SubresourceLoadInfo() - : routing_id(-1), request_id(-1), options(0) {} + : routing_id(-1), + request_id(-1), + options(0), + redirect_limit(kMaxRedirects) {} SubresourceLoadInfo::~SubresourceLoadInfo() {} @@ -59,9 +71,7 @@ void AppCacheURLLoaderJob::DeliverAppCachedResponse(const GURL& manifest_url, is_fallback_ = is_fallback; // Handle range requests. - net::HttpRequestHeaders headers; - headers.AddHeadersFromString(request_.headers); - InitializeRangeRequestInfo(headers); + InitializeRangeRequestInfo(request_.headers); // TODO(ananta) // Implement the AppCacheServiceImpl::Observer interface or add weak pointer @@ -125,15 +135,37 @@ void AppCacheURLLoaderJob::DeliverErrorResponse() { start_time_tick_); } -const GURL& AppCacheURLLoaderJob::GetURL() const { - return request_.url; -} - AppCacheURLLoaderJob* AppCacheURLLoaderJob::AsURLLoaderJob() { return this; } void AppCacheURLLoaderJob::FollowRedirect() { + if (subresource_factory_.get()) { + if (storage_->usage_map()->find( + last_subresource_redirect_info_.new_url.GetOrigin()) != + storage_->usage_map()->end()) { + // If we hit the redirect limit then attempt to load a fallback here. + // If that succeeds we are good. If not notify the client about the + // failure. + // TODO(ananta/michaeln) + // Avoid this logic and figure out a way to reuse the network loader's + // FollowRedirect mechanism. + subresource_load_info_->redirect_limit--; + + if (subresource_load_info_->redirect_limit <= 0) { + HandleRedirectLimitHit(); + return; + } + subresource_load_info_->client = std::move(client_); + subresource_load_info_->url_loader_request = binding_.Unbind(); + subresource_factory_->Restart(last_subresource_redirect_info_, + std::move(sub_resource_handler_), + std::move(subresource_load_info_)); + base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); + return; + } + } + if (network_loader_) network_loader_->FollowRedirect(); } @@ -144,6 +176,16 @@ void AppCacheURLLoaderJob::SetPriority(net::RequestPriority priority, network_loader_->SetPriority(priority, intra_priority_value); } +void AppCacheURLLoaderJob::PauseReadingBodyFromNet() { + if (network_loader_) + network_loader_->PauseReadingBodyFromNet(); +} + +void AppCacheURLLoaderJob::ResumeReadingBodyFromNet() { + if (network_loader_) + network_loader_->ResumeReadingBodyFromNet(); +} + void AppCacheURLLoaderJob::OnReceiveResponse( const ResourceResponseHead& response_head, const base::Optional<net::SSLInfo>& ssl_info, @@ -170,18 +212,21 @@ void AppCacheURLLoaderJob::OnReceiveRedirect( const net::RedirectInfo& redirect_info, const ResourceResponseHead& response_head) { appcache_request_->set_response(response_head); + // The MaybeLoadFallbackForRedirect() call below can pass a fallback // response to us. Reset the delivery_type_ to ensure that we can // receive it delivery_type_ = AWAITING_DELIVERY_ORDERS; - if (!sub_resource_handler_->MaybeLoadFallbackForRedirect( + if (sub_resource_handler_->MaybeLoadFallbackForRedirect( nullptr, redirect_info.new_url)) { - client_->OnReceiveRedirect(redirect_info, response_head); - } else { // Disconnect from the network loader as we are delivering a fallback // response to the client. DisconnectFromNetworkLoader(); + return; } + + last_subresource_redirect_info_ = redirect_info; + client_->OnReceiveRedirect(redirect_info, response_head); } void AppCacheURLLoaderJob::OnDataDownloaded(int64_t data_len, @@ -225,6 +270,13 @@ void AppCacheURLLoaderJob::OnComplete( client_->OnComplete(status); } +void AppCacheURLLoaderJob::SetRequestHandlerAndFactory( + std::unique_ptr<AppCacheRequestHandler> handler, + AppCacheSubresourceURLFactory* subresource_factory) { + sub_resource_handler_ = std::move(handler); + subresource_factory_ = subresource_factory->GetWeakPtr(); +} + void AppCacheURLLoaderJob::BindRequest(mojom::URLLoaderClientPtr client, mojom::URLLoaderRequest request) { DCHECK(!binding_.is_bound()); @@ -264,6 +316,7 @@ AppCacheURLLoaderJob::AppCacheURLLoaderJob( if (subresource_load_info.get()) { DCHECK(loader_factory_getter); subresource_load_info_ = std::move(subresource_load_info); + request_ = subresource_load_info_->request; binding_.Bind(std::move(subresource_load_info_->url_loader_request)); binding_.set_connection_error_handler(base::BindOnce( @@ -431,8 +484,11 @@ void AppCacheURLLoaderJob::ReadMore() { auto buffer = base::MakeRefCounted<network::NetToMojoIOBuffer>(pending_write_.get()); + uint32_t bytes_to_read = + std::min<uint32_t>(num_bytes, info_->response_data_size()); + reader_->ReadData( - buffer.get(), info_->response_data_size(), + buffer.get(), bytes_to_read, base::Bind(&AppCacheURLLoaderJob::OnReadComplete, StaticAsWeakPtr(this))); } @@ -482,4 +538,19 @@ void AppCacheURLLoaderJob::DisconnectFromNetworkLoader() { network_loader_ = nullptr; } +void AppCacheURLLoaderJob::HandleRedirectLimitHit() { + DCHECK(sub_resource_handler_.get()); + // TODO(ananta/michaeln) + // Fix the IsSuccess() function in the AppCacheURLLoaderRequest class. + // Currently presence of headers in the response is treated as success. + appcache_request_->set_response(ResourceResponseHead()); + if (sub_resource_handler_->MaybeLoadFallbackForResponse(nullptr)) { + DisconnectFromNetworkLoader(); + } else { + ResourceRequestCompletionStatus result; + result.error_code = net::ERR_FAILED; + client_->OnComplete(result); + } +} + } // namespace content |