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 SubresourceLoader::sendDataToResource(const char* data, int length) { // There are two cases where we might need to create our own SharedBuffer instead of copying the one in ResourceLoader. // (1) Multipart content: The loader delivers the data in a multipart section all at once, then sends eof. // The resource data will change as the next part is loaded, so we need to make a copy. // (2) Our client requested that the data not be buffered at the ResourceLoader level via ResourceLoaderOptions. In this case, // ResourceLoader::resourceData() will be null. However, unlike the multipart case, we don't want to tell the CachedResource // that all data has been received yet. if (m_loadingMultipartContent || !resourceData()) { RefPtr<ResourceBuffer> copiedData = ResourceBuffer::create(data, length); m_resource->data(copiedData.release(), m_loadingMultipartContent); } else m_resource->data(resourceData(), false); }
void SubresourceLoader::didReceiveResponse(const ResourceResponse& r) { ASSERT(!r.isNull()); if (r.isMultipart()) m_loadingMultipartContent = true; // 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); if (m_client) m_client->didReceiveResponse(this, r); // The loader can cancel a load if it receives a multipart response for a non-image if (reachedTerminalState()) return; ResourceLoader::didReceiveResponse(r); RefPtr<SharedBuffer> buffer = resourceData(); if (m_loadingMultipartContent && buffer && buffer->size()) { // Since a subresource loader does not load multipart sections progressively, // deliver the previously received data to the loader all at once now. // Then clear the data to make way for the next multipart section. if (m_client) m_client->didReceiveData(this, buffer->data(), buffer->size()); clearResourceData(); // After the first multipart section is complete, signal to delegates that this load is "finished" m_documentLoader->subresourceLoaderFinishedLoadingOnePart(this); didFinishLoadingOnePart(0); } }
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::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::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. RefPtr<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. // SRL: Create a network response event action. ActionLogFormat(ActionLog::ENTER_SCOPE, "recv_304:%s", m_resource->url().lastPathComponent().ascii().data()); memoryCache()->revalidationSucceeded(m_resource, response); if (!reachedTerminalState()) ResourceLoader::didReceiveResponse(response); ActionLogScopeEnd(); return; } // Did not get 304 response, continue as a regular resource load. memoryCache()->revalidationFailed(m_resource); } m_resource->setResponse(response); if (reachedTerminalState()) return; ResourceLoader::didReceiveResponse(response); if (response.isMultipart()) { m_loadingMultipartContent = true; // We don't count multiParts in a CachedResourceLoader's request count m_requestCountTracker.clear(); if (!m_resource->isImage()) { cancel(); return; } } RefPtr<SharedBuffer> buffer = resourceData(); if (m_loadingMultipartContent && buffer && buffer->size()) { sendDataToResource(buffer->data(), buffer->size()); 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); } }
void SubresourceLoader::didFinishLoading(double finishTime) { if (cancelled()) return; ASSERT(!reachedTerminalState()); // Calling removeSubresourceLoader will likely result in a call to deref, so we must protect ourselves. RefPtr<SubresourceLoader> protect(this); if (resourceData()) resourceData()->shouldUsePurgeableMemory(true); if (m_client) m_client->didFinishLoading(this, finishTime); m_handle = nullptr;//Ricardo: reemplazando 0 if (cancelled()) return; m_documentLoader->removeSubresourceLoader(this); ResourceLoader::didFinishLoading(finishTime); }
String InspectorResource::sourceString() const { if (!m_xmlHttpResponseText.isNull()) return String(m_xmlHttpResponseText); String textEncodingName; RefPtr<SharedBuffer> buffer = resourceData(&textEncodingName); if (!buffer) return String(); TextEncoding encoding(textEncodingName); if (!encoding.isValid()) encoding = WindowsLatin1Encoding(); return encoding.decode(buffer->data(), buffer->size()); }
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 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(); }
static JSchemaResolutionResult simpleResolver(JSchemaResolverRef resolver, jschema_ref *resolved) { QString resourceName = QString::fromUtf8(resolver->m_resourceToResolve.m_str, resolver->m_resourceToResolve.m_len); QFileInfo lookupPath(resolutionDir, resourceName + ".schema"); if (!lookupPath.isFile() || !lookupPath.isReadable()) { qWarning() << "Failed to resolve" << resourceName << ". Resolved path" << lookupPath.absoluteFilePath() << " isn't a file"; return SCHEMA_NOT_FOUND; } QFile resourceData(lookupPath.absoluteFilePath()); if (!resourceData.open(QIODevice::ReadOnly)) { qWarning() << "Failed to open" << resourceName << "(" << lookupPath.absoluteFilePath() << ")"; return SCHEMA_IO_ERROR; } raw_buffer readSchema; if (resourceData.size() > std::numeric_limits<typeof(readSchema.m_len)>::max()) { qWarning() << "Schema" << lookupPath.absoluteFilePath() << "is too big"; return SCHEMA_GENERIC_ERROR; } readSchema.m_len = resourceData.size(); readSchema.m_str = new char[readSchema.m_len]; QDataStream schemaReader(&resourceData); if (!readSchema.m_len == schemaReader.readRawData((char *)readSchema.m_str, readSchema.m_len)) { qWarning() << "Failed to read schema" << resourceName << "fully"; delete [] readSchema.m_str; return SCHEMA_IO_ERROR; } *resolved = jschema_parse(readSchema, DOMOPT_NOOPT, NULL); delete [] readSchema.m_str; if (*resolved == NULL) return SCHEMA_INVALID; qDebug() << "Resolved reference for" << resourceName; return SCHEMA_RESOLVED; }
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(); }
bool GetResourceAsBitmap(const char* resource, SkBitmap* dst) { SkString resourcePath = GetResourcePath(resource); SkAutoTUnref<SkData> resourceData( SkData::NewFromFileName(resourcePath.c_str())); return resourceData && SkInstallDiscardablePixelRef(resourceData, dst); }