void ResourceHandleInternal::didReceiveResponse(WebURLLoader*, const WebURLResponse& response) { ASSERT(m_client); ASSERT(!response.isNull()); bool isMultipart = response.isMultipartPayload(); bool isValidStateTransition = (m_state == ConnectionStateStarted || m_state == ConnectionStateReceivedResponse); // In the case of multipart loads, calls to didReceiveData & didReceiveResponse can be interleaved. if (!isMultipart && !isValidStateTransition) CRASH(); m_state = ConnectionStateReceivedResponse; m_client->didReceiveResponse(m_owner, response.toResourceResponse()); }
void ResourceLoader::didReceiveResponse(WebURLLoader*, const WebURLResponse& response, WebDataConsumerHandle* rawHandle) { ASSERT(!response.isNull()); ASSERT(m_state == Initialized); // |rawHandle|'s ownership is transferred to the callee. OwnPtr<WebDataConsumerHandle> handle = adoptPtr(rawHandle); bool isMultipartPayload = response.isMultipartPayload(); bool isValidStateTransition = (m_connectionState == ConnectionStateStarted || m_connectionState == ConnectionStateReceivedResponse); // In the case of multipart loads, calls to didReceiveData & didReceiveResponse can be interleaved. RELEASE_ASSERT(isMultipartPayload || isValidStateTransition); m_connectionState = ConnectionStateReceivedResponse; const ResourceResponse& resourceResponse = response.toResourceResponse(); if (responseNeedsAccessControlCheck()) { if (response.wasFetchedViaServiceWorker()) { if (response.wasFallbackRequiredByServiceWorker()) { m_loader->cancel(); m_loader.clear(); m_connectionState = ConnectionStateStarted; m_loader = adoptPtr(Platform::current()->createURLLoader()); ASSERT(m_loader); ASSERT(!m_request.skipServiceWorker()); m_request.setSkipServiceWorker(true); WrappedResourceRequest wrappedRequest(m_request); m_loader->loadAsynchronously(wrappedRequest, this); return; } } else { // If the response successfully validated a cached resource, perform // the access control with respect to it. Need to do this right here // before the resource switches clients over to that validated resource. Resource* resource = m_resource; if (!resource->isCacheValidator() || resourceResponse.httpStatusCode() != 304) m_resource->setResponse(resourceResponse); if (!m_fetcher->canAccessResource(resource, m_options.securityOrigin.get(), response.url(), ResourceFetcher::ShouldLogAccessControlErrors)) { m_fetcher->didReceiveResponse(m_resource, resourceResponse); cancel(ResourceError::cancelledDueToAccessCheckError(KURL(response.url()))); return; } } } m_resource->responseReceived(resourceResponse, handle.release()); if (m_state == Terminated) return; m_fetcher->didReceiveResponse(m_resource, resourceResponse); if (m_state == Terminated) return; if (response.toResourceResponse().isMultipart()) { // We only support multipart for images, though the image may be loaded // as a main resource that we end up displaying through an ImageDocument. if (!m_resource->isImage() && m_resource->type() != Resource::MainResource) { cancel(); return; } m_loadingMultipartContent = true; } else if (isMultipartPayload) { // Since a subresource loader does not load multipart sections progressively, data was delivered to the loader all at once. // After the first multipart section is complete, signal to delegates that this load is "finished" m_fetcher->subresourceLoaderFinishedLoadingOnePart(this); didFinishLoadingOnePart(0, WebURLLoaderClient::kUnknownEncodedDataLength); } if (m_state == Terminated) return; if (m_resource->response().httpStatusCode() < 400 || m_resource->shouldIgnoreHTTPStatusCodeErrors()) return; m_state = Finishing; if (!m_notifiedLoadComplete) { m_notifiedLoadComplete = true; m_fetcher->didFailLoading(m_resource, ResourceError::cancelledError(m_request.url())); } ASSERT(m_state != Terminated); m_resource->error(Resource::LoadError); cancel(); }