void SubresourceLoader::didFinishLoading(double finishTime) { if (m_state != Initialized) return; ASSERT(!reachedTerminalState()); ASSERT(!m_resource->resourceToRevalidate()); ASSERT(!m_resource->errorOccurred()); LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1().data()); Ref<SubresourceLoader> protect(*this); CachedResourceHandle<CachedResource> protectResource(m_resource); m_state = Finishing; m_activityAssertion.clear(); m_resource->setLoadFinishTime(finishTime); m_resource->finishLoading(resourceData()); if (wasCancelled()) return; m_resource->finish(); ASSERT(!reachedTerminalState()); didFinishLoadingOnePart(finishTime); notifyDone(); if (reachedTerminalState()) return; releaseResources(); }
void SubresourceLoader::didFinishLoading(double finishTime) { if (m_state != Initialized) return; ASSERT(!reachedTerminalState()); ASSERT(!m_resource->resourceToRevalidate()); // FIXME (129394): We should cancel the load when a decode error occurs instead of continuing the load to completion. ASSERT(!m_resource->errorOccurred() || m_resource->status() == CachedResource::DecodeError); LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1().data()); logResourceLoaded(m_frame.get(), m_resource->type()); Ref<SubresourceLoader> protectedThis(*this); CachedResourceHandle<CachedResource> protectResource(m_resource); m_state = Finishing; m_resource->setLoadFinishTime(finishTime); m_resource->finishLoading(resourceData()); if (wasCancelled()) return; m_resource->finish(); ASSERT(!reachedTerminalState()); didFinishLoadingOnePart(finishTime); notifyDone(); if (reachedTerminalState()) return; releaseResources(); }
void SubresourceLoader::didFinishLoading(double finishTime) { if (m_state != Initialized) return; ASSERT(!reachedTerminalState()); ASSERT(!m_resource->resourceToRevalidate()); ASSERT(!m_resource->errorOccurred()); LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1().data()); Ref<SubresourceLoader> protect(*this); #if PLATFORM(IOS) if (resourceData()) resourceData()->setShouldUsePurgeableMemory(true); #endif CachedResourceHandle<CachedResource> protectResource(m_resource); m_state = Finishing; m_resource->setLoadFinishTime(finishTime); m_resource->finishLoading(resourceData()); if (wasCancelled()) return; m_resource->finish(); ASSERT(!reachedTerminalState()); didFinishLoadingOnePart(finishTime); notifyDone(); if (reachedTerminalState()) return; releaseResources(); }
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(); }
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 SubresourceLoader::didFail(const ResourceError& error) { if (m_state != Initialized) return; ASSERT(!reachedTerminalState()); ASSERT(!m_resource->resourceToRevalidate()); LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string().latin1().data()); RefPtr<SubresourceLoader> protect(this); CachedResourceHandle<CachedResource> protectResource(m_resource); m_state = Finishing; m_resource->error(CachedResource::LoadError); if (!m_resource->isPreloaded()) memoryCache()->remove(m_resource); ResourceLoader::didFail(error); }
void SubresourceLoader::didFinishLoading(double finishTime) { if (m_state != Initialized) return; ASSERT(!reachedTerminalState()); ASSERT(!m_resource->resourceToRevalidate()); ASSERT(!m_resource->errorOccurred()); LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1().data()); RefPtr<SubresourceLoader> protect(this); CachedResourceHandle<CachedResource> protectResource(m_resource); m_state = Finishing; m_resource->setLoadFinishTime(finishTime); m_resource->data(resourceData(), true); m_resource->finish(); ResourceLoader::didFinishLoading(finishTime); }
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); }
void ResourceLoader::didFinishLoading(ResourceHandle*, double finishTime) { if (m_state != Initialized) return; ASSERT(m_state != Terminated); LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1().data()); RefPtr<ResourceLoader> protect(this); CachedResourceHandle<CachedResource> protectResource(m_resource); m_state = Finishing; m_resource->finish(finishTime); didFinishLoadingOnePart(finishTime); // If the load has been cancelled by a delegate in response to didFinishLoad(), do not release // the resources a second time, they have been released by cancel. if (m_state == Terminated) return; releaseResources(); }
void SubresourceLoader::didFinishLoading(double finishTime) { if (m_state != Initialized) return; ASSERT(!reachedTerminalState()); ASSERT(!m_resource->resourceToRevalidate()); // FIXME (129394): We should cancel the load when a decode error occurs instead of continuing the load to completion. ASSERT(!m_resource->errorOccurred() || m_resource->status() == CachedResource::DecodeError); LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1().data()); logResourceLoaded(m_frame.get(), m_resource->type()); Ref<SubresourceLoader> protectedThis(*this); CachedResourceHandle<CachedResource> protectResource(m_resource); // FIXME: The finishTime that is passed in is from the NetworkProcess and is more accurate. // However, all other load times are generated from the web process or offsets. // Mixing times from different processes can cause the finish time to be earlier than // the response received time due to inter-process communication lag. UNUSED_PARAM(finishTime); double responseEndTime = monotonicallyIncreasingTime(); m_loadTiming.setResponseEnd(responseEndTime); #if ENABLE(WEB_TIMING) if (m_documentLoader->cachedResourceLoader().document() && RuntimeEnabledFeatures::sharedFeatures().resourceTimingEnabled()) m_documentLoader->cachedResourceLoader().resourceTimingInformation().addResourceTiming(m_resource, *m_documentLoader->cachedResourceLoader().document(), m_resource->loader()->loadTiming()); #endif m_state = Finishing; m_resource->setLoadFinishTime(responseEndTime); // FIXME: Users of the loadFinishTime should use the LoadTiming struct instead. m_resource->finishLoading(resourceData()); if (wasCancelled()) return; m_resource->finish(); ASSERT(!reachedTerminalState()); didFinishLoadingOnePart(responseEndTime); notifyDone(); if (reachedTerminalState()) return; releaseResources(); }
void ResourceLoader::didFinishLoading(WebKit::WebURLLoader*, double finishTime) { RELEASE_ASSERT(m_connectionState == ConnectionStateReceivedResponse || m_connectionState == ConnectionStateReceivingData); m_connectionState = ConnectionStateFinishedLoading; if (m_state != Initialized) return; ASSERT(m_state != Terminated); LOG(ResourceLoading, "Received '%s'.", m_resource->url().string().latin1().data()); RefPtr<ResourceLoader> protect(this); ResourcePtr<Resource> protectResource(m_resource); m_state = Finishing; m_resource->finish(finishTime); didFinishLoadingOnePart(finishTime); // If the load has been cancelled by a delegate in response to didFinishLoad(), do not release // the resources a second time, they have been released by cancel. if (m_state == Terminated) return; releaseResources(); }
void SubresourceLoader::didFail(const ResourceError& error) { if (m_state != Initialized) return; ASSERT(!reachedTerminalState()); LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string().latin1().data()); Ref<SubresourceLoader> protectedThis(*this); CachedResourceHandle<CachedResource> protectResource(m_resource); m_state = Finishing; if (m_resource->resourceToRevalidate()) MemoryCache::singleton().revalidationFailed(*m_resource); m_resource->setResourceError(error); if (!m_resource->isPreloaded()) MemoryCache::singleton().remove(*m_resource); m_resource->error(CachedResource::LoadError); cleanupForError(error); notifyDone(); if (reachedTerminalState()) return; releaseResources(); }
void ResourceLoader::didFail(ResourceHandle*, const ResourceError& error) { ASSERT(m_state != Terminated); LOG(ResourceLoading, "Failed to load '%s'.\n", m_resource->url().string().latin1().data()); RefPtr<ResourceLoader> protect(this); CachedResourceHandle<CachedResource> protectResource(m_resource); m_state = Finishing; m_resource->setResourceError(error); m_resource->error(CachedResource::LoadError); if (m_state == Terminated) return; if (!m_notifiedLoadComplete) { m_notifiedLoadComplete = true; if (m_options.sendLoadCallbacks == SendCallbacks) frameLoader()->notifier()->dispatchDidFail(m_documentLoader.get(), m_resource->identifier(), error); } releaseResources(); }
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); }