void ResourceLoader::requestSynchronously() { OwnPtr<blink::WebURLLoader> loader = adoptPtr(blink::Platform::current()->createURLLoader()); ASSERT(loader); RefPtr<ResourceLoader> protect(this); RefPtr<ResourceLoaderHost> protectHost(m_host); ResourcePtr<Resource> protectResource(m_resource); RELEASE_ASSERT(m_connectionState == ConnectionStateNew); m_connectionState = ConnectionStateStarted; blink::WrappedResourceRequest requestIn(m_request); requestIn.setAllowStoredCredentials(m_options.allowCredentials == AllowStoredCredentials); blink::WebURLResponse responseOut; responseOut.initialize(); blink::WebURLError errorOut; blink::WebData dataOut; loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); if (errorOut.reason) { didFail(0, errorOut); return; } didReceiveResponse(0, responseOut); if (m_state == Terminated) return; RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse().resourceLoadInfo(); int64 encodedDataLength = resourceLoadInfo ? resourceLoadInfo->encodedDataLength : blink::WebURLLoaderClient::kUnknownEncodedDataLength; m_host->didReceiveData(m_resource, dataOut.data(), dataOut.size(), encodedDataLength); m_resource->setResourceBuffer(dataOut); didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); }
void ResourceLoader::didFail(blink::WebURLLoader*, const blink::WebURLError& error) { m_connectionState = ConnectionStateFailed; ASSERT(m_state != Terminated); WTF_LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string().latin1().data()); RefPtrWillBeRawPtr<ResourceLoader> protect(this); RefPtrWillBeRawPtr<ResourceLoaderHost> protectHost(m_host.get()); ResourcePtr<Resource> protectResource(m_resource); m_state = Finishing; m_resource->setResourceError(error); if (!m_notifiedLoadComplete) { m_notifiedLoadComplete = true; m_host->didFailLoading(m_resource, error); } if (m_state == Terminated) return; m_resource->error(Resource::LoadError); if (m_state == Terminated) return; releaseResources(); }