void ResourceLoader::requestSynchronously() { OwnPtr<WebURLLoader> loader = adoptPtr(Platform::current()->createURLLoader()); ASSERT(loader); // downloadToFile is not supported for synchronous requests. ASSERT(!m_request.downloadToFile()); ResourcePtr<Resource> protectResource(m_resource); RELEASE_ASSERT(m_connectionState == ConnectionStateNew); m_connectionState = ConnectionStateStarted; WrappedResourceRequest requestIn(m_request); WebURLResponse responseOut; responseOut.initialize(); WebURLError errorOut; WebData dataOut; loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); if (errorOut.reason) { if (m_state == Terminated) { // A message dispatched while synchronously fetching the resource // can bring about the cancellation of this load. ASSERT(!m_resource); return; } didFail(0, errorOut); return; } didReceiveResponse(0, responseOut); if (m_state == Terminated) return; RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse().resourceLoadInfo(); int64_t encodedDataLength = resourceLoadInfo ? resourceLoadInfo->encodedDataLength : WebURLLoaderClient::kUnknownEncodedDataLength; // Follow the async case convention of not calling didReceiveData or // appending data to m_resource if the response body is empty. Copying the // empty buffer is a noop in most cases, but is destructive in the case of // a 304, where it will overwrite the cached data we should be reusing. if (dataOut.size()) { m_fetcher->didReceiveData(m_resource, dataOut.data(), dataOut.size(), encodedDataLength); m_resource->setResourceBuffer(dataOut); } didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); }
// static void ResourceHandle::loadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials storedCredentials, ResourceError& error, ResourceResponse& response, Vector<char>& data) { OwnPtr<WebURLLoader> loader(webKitClient()->createURLLoader()); ASSERT(loader.get()); WrappedResourceRequest requestIn(request); requestIn.setAllowStoredCredentials(storedCredentials == AllowStoredCredentials); WrappedResourceResponse responseOut(response); WebURLError errorOut; WebData dataOut; loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); error = errorOut; data.clear(); data.append(dataOut.data(), dataOut.size()); }
void ResourceLoader::requestSynchronously(const ResourceRequest& request) { // downloadToFile is not supported for synchronous requests. DCHECK(!request.downloadToFile()); DCHECK(m_loader); DCHECK_EQ(request.priority(), ResourceLoadPriorityHighest); WrappedResourceRequest requestIn(request); WebURLResponse responseOut; WebURLError errorOut; WebData dataOut; int64_t encodedDataLength = WebURLLoaderClient::kUnknownEncodedDataLength; int64_t encodedBodyLength = 0; m_loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut, encodedDataLength, encodedBodyLength); // A message dispatched while synchronously fetching the resource // can bring about the cancellation of this load. if (!m_loader) return; if (errorOut.reason) { didFail(errorOut, encodedDataLength, encodedBodyLength); return; } didReceiveResponse(responseOut); if (!m_loader) return; DCHECK_GE(responseOut.toResourceResponse().encodedBodyLength(), 0); // Follow the async case convention of not calling didReceiveData or // appending data to m_resource if the response body is empty. Copying the // empty buffer is a noop in most cases, but is destructive in the case of // a 304, where it will overwrite the cached data we should be reusing. if (dataOut.size()) { m_fetcher->didReceiveData(m_resource.get(), dataOut.data(), dataOut.size()); m_resource->setResourceBuffer(dataOut); } didFinishLoading(monotonicallyIncreasingTime(), encodedDataLength, encodedBodyLength); }
void ResourceLoader::requestSynchronously() { OwnPtr<WebURLLoader> loader = adoptPtr(Platform::current()->createURLLoader()); ASSERT(loader); // downloadToFile is not supported for synchronous requests. ASSERT(!m_request.downloadToFile()); ResourcePtr<Resource> protectResource(m_resource); RELEASE_ASSERT(m_connectionState == ConnectionStateNew); m_connectionState = ConnectionStateStarted; WrappedResourceRequest requestIn(m_request); WebURLResponse responseOut; responseOut.initialize(); WebURLError errorOut; WebData dataOut; loader->loadSynchronously(requestIn, responseOut, errorOut, dataOut); if (errorOut.reason) { if (m_state == Terminated) { // A message dispatched while synchronously fetching the resource // can bring about the cancellation of this load. ASSERT(!m_resource); return; } didFail(0, errorOut); return; } didReceiveResponse(0, responseOut); if (m_state == Terminated) return; RefPtr<ResourceLoadInfo> resourceLoadInfo = responseOut.toResourceResponse().resourceLoadInfo(); int64_t encodedDataLength = resourceLoadInfo ? resourceLoadInfo->encodedDataLength : WebURLLoaderClient::kUnknownEncodedDataLength; m_fetcher->didReceiveData(m_resource, dataOut.data(), dataOut.size(), encodedDataLength); m_resource->setResourceBuffer(dataOut); didFinishLoading(0, monotonicallyIncreasingTime(), encodedDataLength); }