void SubresourceLoader::didReceiveResponse(const ResourceResponse& response) { ASSERT(!response.isNull()); ASSERT(m_state == Initialized); // Reference the object in this method since the additional processing can do // anything including removing the last reference to this object; one example of this is 3266216. Ref<SubresourceLoader> protect(*this); if (m_resource->resourceToRevalidate()) { if (response.httpStatusCode() == 304) { // 304 Not modified / Use local copy // Existing resource is ok, just use it updating the expiration time. m_resource->setResponse(response); memoryCache()->revalidationSucceeded(m_resource, response); if (!reachedTerminalState()) ResourceLoader::didReceiveResponse(response); return; } // Did not get 304 response, continue as a regular resource load. memoryCache()->revalidationFailed(m_resource); } m_resource->responseReceived(response); if (reachedTerminalState()) return; ResourceLoader::didReceiveResponse(response); if (reachedTerminalState()) return; // FIXME: Main resources have a different set of rules for multipart than images do. // Hopefully we can merge those 2 paths. if (response.isMultipart() && m_resource->type() != CachedResource::MainResource) { m_loadingMultipartContent = true; // We don't count multiParts in a CachedResourceLoader's request count m_requestCountTracker.clear(); if (!m_resource->isImage()) { cancel(); return; } } RefPtr<ResourceBuffer> buffer = resourceData(); if (m_loadingMultipartContent && buffer && buffer->size()) { // The resource data will change as the next part is loaded, so we need to make a copy. RefPtr<ResourceBuffer> copiedData = ResourceBuffer::create(buffer->data(), buffer->size()); m_resource->finishLoading(copiedData.get()); clearResourceData(); // 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_documentLoader->subresourceLoaderFinishedLoadingOnePart(this); didFinishLoadingOnePart(0); } checkForHTTPStatusCodeError(); }
void SubresourceLoader::didReceiveDataArray(CFArrayRef dataArray) { // Reference the object in this method since the additional processing can do // anything including removing the last reference to this object; one example of this is 3266216. RefPtr<SubresourceLoader> protect(this); ResourceLoader::didReceiveDataArray(dataArray); if (checkForHTTPStatusCodeError()) return; // A subresource loader does not load multipart sections progressively. // So don't deliver any data to the loader yet. if (!m_loadingMultipartContent) { CFIndex arrayCount = CFArrayGetCount(dataArray); for (CFIndex i = 0; i < arrayCount; ++i) { CFDataRef data = reinterpret_cast<CFDataRef>(CFArrayGetValueAtIndex(dataArray, i)); sendDataToResource(reinterpret_cast<const char *>(CFDataGetBytePtr(data)), static_cast<int>(CFDataGetLength(data))); } } }
void SubresourceLoader::didReceiveResponse(const ResourceResponse& response) { ASSERT(!response.isNull()); ASSERT(m_state == Initialized); // Reference the object in this method since the additional processing can do // anything including removing the last reference to this object; one example of this is 3266216. Ref<SubresourceLoader> protectedThis(*this); if (shouldIncludeCertificateInfo()) response.includeCertificateInfo(); if (response.isHttpVersion0_9()) { if (m_frame) { String message = "Sandboxing '" + response.url().string() + "' because it is using HTTP/0.9."; m_frame->document()->addConsoleMessage(MessageSource::Security, MessageLevel::Error, message, identifier()); frameLoader()->forceSandboxFlags(SandboxScripts | SandboxPlugins); } } if (m_resource->resourceToRevalidate()) { if (response.httpStatusCode() == 304) { // 304 Not modified / Use local copy // Existing resource is ok, just use it updating the expiration time. m_resource->setResponse(response); MemoryCache::singleton().revalidationSucceeded(*m_resource, response); if (m_frame && m_frame->page()) m_frame->page()->diagnosticLoggingClient().logDiagnosticMessageWithResult(DiagnosticLoggingKeys::cachedResourceRevalidationKey(), emptyString(), DiagnosticLoggingResultPass, ShouldSample::Yes); if (!reachedTerminalState()) ResourceLoader::didReceiveResponse(response); return; } // Did not get 304 response, continue as a regular resource load. MemoryCache::singleton().revalidationFailed(*m_resource); if (m_frame && m_frame->page()) m_frame->page()->diagnosticLoggingClient().logDiagnosticMessageWithResult(DiagnosticLoggingKeys::cachedResourceRevalidationKey(), emptyString(), DiagnosticLoggingResultFail, ShouldSample::Yes); } m_resource->responseReceived(response); if (reachedTerminalState()) return; ResourceLoader::didReceiveResponse(response); if (reachedTerminalState()) return; // FIXME: Main resources have a different set of rules for multipart than images do. // Hopefully we can merge those 2 paths. if (response.isMultipart() && m_resource->type() != CachedResource::MainResource) { m_loadingMultipartContent = true; // We don't count multiParts in a CachedResourceLoader's request count m_requestCountTracker = Nullopt; if (!m_resource->isImage()) { cancel(); return; } } auto* buffer = resourceData(); if (m_loadingMultipartContent && buffer && buffer->size()) { // The resource data will change as the next part is loaded, so we need to make a copy. m_resource->finishLoading(buffer->copy().ptr()); clearResourceData(); // 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_documentLoader->subresourceLoaderFinishedLoadingOnePart(this); didFinishLoadingOnePart(0); } checkForHTTPStatusCodeError(); }