void NetworkResourcesData::reuseXHRReplayData(const String& requestId, const String& reusedRequestId) { ResourceData* reusedResourceData = resourceDataForRequestId(reusedRequestId); ResourceData* resourceData = resourceDataForRequestId(requestId); if (!reusedResourceData || !resourceData) { m_reusedXHRReplayDataRequestIds.set(requestId, reusedRequestId); return; } resourceData->setXHRReplayData(reusedResourceData->xhrReplayData()); }
void NetworkResourcesData::addCachedResource(const String& requestId, CachedResource* cachedResource) { ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) return; resourceData->setCachedResource(cachedResource); }
InspectorPageAgent::ResourceType NetworkResourcesData::resourceType(const String& requestId) { ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) return InspectorPageAgent::OtherResource; return resourceData->type(); }
void NetworkResourcesData::setResourceType(const String& requestId, InspectorPageAgent::ResourceType type) { ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) return; resourceData->setType(type); }
void NetworkResourcesData::responseReceived(const String& requestId, const String& frameId, const ResourceResponse& response) { ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) return; resourceData->setFrameId(frameId); resourceData->setUrl(response.url()); resourceData->setMimeType(response.mimeType()); resourceData->setTextEncodingName(response.textEncodingName()); resourceData->setDecoder(InspectorPageAgent::createResourceTextDecoder(response.mimeType(), response.textEncodingName())); resourceData->setHTTPStatusCode(response.httpStatusCode()); String filePath = response.downloadedFilePath(); if (!filePath.isEmpty()) { OwnPtr<BlobData> blobData = BlobData::create(); blobData->appendFile(filePath); AtomicString mimeType; if (response.isHTTP()) mimeType = extractMIMETypeFromMediaType(response.httpHeaderField("Content-Type")); if (mimeType.isEmpty()) mimeType = response.mimeType(); if (mimeType.isEmpty()) mimeType = AtomicString("text/plain", AtomicString::ConstructFromLiteral); blobData->setContentType(mimeType); resourceData->setDownloadedFileBlob(BlobDataHandle::create(blobData.release(), -1)); } }
void NetworkResourcesData::addResourceSharedBuffer(const String& requestId, RefPtr<SharedBuffer>&& buffer, const String& textEncodingName) { ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) return; resourceData->setBuffer(WTFMove(buffer)); resourceData->setTextEncodingName(textEncodingName); }
void NetworkResourcesData::ensureNoDataForRequestId(const String& requestId) { ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) return; if (resourceData->hasContent() || resourceData->hasData()) m_contentSize -= resourceData->evictContent(); delete resourceData; m_requestIdToResourceDataMap.remove(requestId); }
void NetworkResourcesData::responseReceived(const String& requestId, const String& frameId, const ResourceResponse& response) { ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) return; resourceData->setFrameId(frameId); resourceData->setUrl(response.url()); resourceData->setDecoder(createOtherResourceTextDecoder(response.mimeType(), response.textEncodingName())); resourceData->setHTTPStatusCode(response.httpStatusCode()); }
XHRReplayData* NetworkResourcesData::xhrReplayData(const String& requestId) { if (m_reusedXHRReplayDataRequestIds.contains(requestId)) return xhrReplayData(m_reusedXHRReplayDataRequestIds.get(requestId)); ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) return nullptr; return resourceData->xhrReplayData(); }
void NetworkResourcesData::maybeDecodeDataToContent(const String& requestId) { ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) return; if (!resourceData->hasData()) return; m_contentSize += resourceData->decodeDataToContent(); size_t dataLength = contentSizeInBytes(resourceData->content()); if (dataLength > m_maximumSingleResourceContentSize) m_contentSize -= resourceData->evictContent(); }
bool NetworkResourcesData::ensureFreeSpace(size_t size) { if (size > m_maximumResourcesContentSize) return false; while (size > m_maximumResourcesContentSize - m_contentSize) { String requestId = m_requestIdsDeque.takeFirst(); ResourceData* resourceData = resourceDataForRequestId(requestId); if (resourceData) m_contentSize -= resourceData->evictContent(); } return true; }
void NetworkResourcesData::setXHRReplayData(const String& requestId, XHRReplayData* xhrReplayData) { ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) { Vector<String> result; for (auto& request : m_reusedXHRReplayDataRequestIds) { if (request.value == requestId) setXHRReplayData(request.key, xhrReplayData); } return; } resourceData->setXHRReplayData(xhrReplayData); }
void NetworkResourcesData::setXHRReplayData(const String& requestId, XHRReplayData* xhrReplayData) { ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) { Vector<String> result; ReusedRequestIds::iterator it; ReusedRequestIds::iterator end = m_reusedXHRReplayDataRequestIds.end(); for (it = m_reusedXHRReplayDataRequestIds.begin(); it != end; ++it) { if (it->value == requestId) setXHRReplayData(it->key, xhrReplayData); } return; } resourceData->setXHRReplayData(xhrReplayData); }
void NetworkResourcesData::maybeAddResourceData(const String& requestId, const char* data, size_t dataLength) { ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) return; if (!resourceData->decoder()) return; if (resourceData->dataLength() + dataLength > m_maximumSingleResourceContentSize) m_contentSize -= resourceData->evictContent(); if (resourceData->isContentEvicted()) return; if (ensureFreeSpace(dataLength) && !resourceData->isContentEvicted()) { m_requestIdsDeque.append(requestId); resourceData->appendData(data, dataLength); m_contentSize += dataLength; } }
void NetworkResourcesData::setResourceContent(const String& requestId, const String& content, bool base64Encoded) { ResourceData* resourceData = resourceDataForRequestId(requestId); if (!resourceData) return; size_t dataLength = contentSizeInBytes(content); if (dataLength > m_maximumSingleResourceContentSize) return; if (resourceData->isContentEvicted()) return; if (ensureFreeSpace(dataLength) && !resourceData->isContentEvicted()) { // We can not be sure that we didn't try to save this request data while it was loading, so remove it, if any. if (resourceData->hasContent() || resourceData->hasData()) m_contentSize -= resourceData->removeContent(); m_requestIdsDeque.append(requestId); resourceData->setContent(content, base64Encoded); m_contentSize += dataLength; } }
NetworkResourcesData::ResourceData const* NetworkResourcesData::data(const String& requestId) { return resourceDataForRequestId(requestId); }