void InspectorResourceAgent::didReceiveResponse(unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response) { RefPtr<InspectorObject> resourceResponse = buildObjectForResourceResponse(response); String type = "Other"; long cachedResourceSize = 0; if (loader) { CachedResource* cachedResource = InspectorResourceAgent::cachedResource(loader->frame(), response.url()); if (cachedResource) { type = cachedResourceTypeString(*cachedResource); cachedResourceSize = cachedResource->encodedSize(); // Use mime type from cached resource in case the one in response is empty. if (response.mimeType().isEmpty()) resourceResponse->setString("mimeType", cachedResource->response().mimeType()); } if (equalIgnoringFragmentIdentifier(response.url(), loader->frameLoader()->iconURL())) type = "Image"; else if (equalIgnoringFragmentIdentifier(response.url(), loader->url()) && type == "Other") type = "Document"; } m_frontend->didReceiveResponse(identifier, currentTime(), type, resourceResponse); // If we revalidated the resource and got Not modified, send content length following didReceiveResponse // as there will be no calls to didReceiveContentLength from the network stack. if (cachedResourceSize && response.httpStatusCode() == 304) didReceiveContentLength(identifier, cachedResourceSize); }
void CachedResource::setBodyDataFrom(const CachedResource& resource) { m_data = resource.m_data; m_response = resource.m_response; setDecodedSize(resource.decodedSize()); setEncodedSize(resource.encodedSize()); }
PassRefPtr<SharedBuffer> InspectorResourceAgent::resourceData(Frame* frame, const KURL& url, String* textEncodingName) { FrameLoader* frameLoader = frame->loader(); DocumentLoader* loader = frameLoader->documentLoader(); if (equalIgnoringFragmentIdentifier(url, loader->url())) { *textEncodingName = frame->document()->inputEncoding(); return frameLoader->documentLoader()->mainResourceData(); } CachedResource* cachedResource = InspectorResourceAgent::cachedResource(frame, url); if (!cachedResource) return 0; // Zero-sized resources don't have data at all -- so fake the empty buffer, insted of indicating error by returning 0. if (!cachedResource->encodedSize()) return SharedBuffer::create(); if (cachedResource->isPurgeable()) { // If the resource is purgeable then make it unpurgeable to get // get its data. This might fail, in which case we return an // empty String. // FIXME: should we do something else in the case of a purged // resource that informs the user why there is no data in the // inspector? if (!cachedResource->makePurgeable(false)) return 0; } *textEncodingName = cachedResource->encoding(); return cachedResource->data(); }
static PassRefPtr<InspectorObject> buildObjectForCachedResource(DocumentLoader* loader, const CachedResource& cachedResource) { RefPtr<InspectorObject> resourceObject = InspectorObject::create(); resourceObject->setString("url", cachedResource.url()); resourceObject->setString("type", cachedResourceTypeString(cachedResource)); resourceObject->setNumber("encodedSize", cachedResource.encodedSize()); resourceObject->setObject("response", buildObjectForResourceResponse(cachedResource.response())); resourceObject->setObject("loader", buildObjectForDocumentLoader(loader)); return resourceObject; }
static PassRefPtr<TypeBuilder::Network::CachedResource> buildObjectForCachedResource(const CachedResource& cachedResource, DocumentLoader* loader) { RefPtr<TypeBuilder::Network::CachedResource> resourceObject = TypeBuilder::Network::CachedResource::create() .setUrl(cachedResource.url()) .setType(InspectorPageAgent::cachedResourceTypeJson(cachedResource)) .setBodySize(cachedResource.encodedSize()); RefPtr<TypeBuilder::Network::Response> resourceResponse = buildObjectForResourceResponse(cachedResource.response(), loader); if (resourceResponse) resourceObject->setResponse(resourceResponse); return resourceObject; }
static PassRefPtr<InspectorObject> buildObjectForCachedResource(const CachedResource& cachedResource, DocumentLoader* loader) { RefPtr<InspectorObject> resourceObject = InspectorObject::create(); resourceObject->setString("url", cachedResource.url()); resourceObject->setString("type", InspectorPageAgent::cachedResourceTypeString(cachedResource)); resourceObject->setNumber("bodySize", cachedResource.encodedSize()); RefPtr<InspectorObject> resourceResponse = buildObjectForResourceResponse(cachedResource.response(), loader); if (resourceResponse) resourceObject->setObject("response", resourceResponse); return resourceObject; }
void InspectorResourceAgent::didReceiveResponse(unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response, ResourceLoader* resourceLoader) { if (m_hiddenRequestIdentifiers.contains(identifier)) return; String requestId = IdentifiersFactory::requestId(identifier); RefPtr<Inspector::Protocol::Network::Response> resourceResponse = buildObjectForResourceResponse(response, loader); bool isNotModified = response.httpStatusCode() == 304; CachedResource* cachedResource = nullptr; if (resourceLoader && resourceLoader->isSubresourceLoader() && !isNotModified) cachedResource = static_cast<SubresourceLoader*>(resourceLoader)->cachedResource(); if (!cachedResource) cachedResource = InspectorPageAgent::cachedResource(loader->frame(), response.url()); if (cachedResource) { // Use mime type from cached resource in case the one in response is empty. if (resourceResponse && response.mimeType().isEmpty()) resourceResponse->setString(Inspector::Protocol::Network::Response::MimeType, cachedResource->response().mimeType()); m_resourcesData->addCachedResource(requestId, cachedResource); } InspectorPageAgent::ResourceType type = m_resourcesData->resourceType(requestId); InspectorPageAgent::ResourceType newType = cachedResource ? InspectorPageAgent::cachedResourceType(*cachedResource) : type; // FIXME: XHRResource is returned for CachedResource::RawResource, it should be OtherResource unless it truly is an XHR. // RawResource is used for loading worker scripts, and those should stay as ScriptResource and not change to XHRResource. if (type != newType && newType != InspectorPageAgent::XHRResource && newType != InspectorPageAgent::OtherResource) type = newType; m_resourcesData->responseReceived(requestId, m_pageAgent->frameId(loader->frame()), response); m_resourcesData->setResourceType(requestId, type); m_frontendDispatcher->responseReceived(requestId, m_pageAgent->frameId(loader->frame()), m_pageAgent->loaderId(loader), currentTime(), InspectorPageAgent::resourceTypeJson(type), resourceResponse); // If we revalidated the resource and got Not modified, send content length following didReceiveResponse // as there will be no calls to didReceiveData from the network stack. if (isNotModified && cachedResource && cachedResource->encodedSize()) didReceiveData(identifier, nullptr, cachedResource->encodedSize(), 0); }
void InspectorResourceAgent::didReceiveResourceResponse(unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response, ResourceLoader* resourceLoader) { if (!loader) return; String requestId = IdentifiersFactory::requestId(identifier); RefPtr<TypeBuilder::Network::Response> resourceResponse = buildObjectForResourceResponse(response, loader); bool isNotModified = response.httpStatusCode() == 304; CachedResource* cachedResource = 0; if (resourceLoader && !isNotModified) cachedResource = resourceLoader->cachedResource(); if (!cachedResource) cachedResource = InspectorPageAgent::cachedResource(loader->frame(), response.url()); if (cachedResource) { // Use mime type from cached resource in case the one in response is empty. if (resourceResponse && response.mimeType().isEmpty()) resourceResponse->setString(TypeBuilder::Network::Response::MimeType, cachedResource->response().mimeType()); m_resourcesData->addCachedResource(requestId, cachedResource); } InspectorPageAgent::ResourceType type = cachedResource ? InspectorPageAgent::cachedResourceType(*cachedResource) : InspectorPageAgent::OtherResource; if (m_loadingXHRSynchronously || m_resourcesData->resourceType(requestId) == InspectorPageAgent::XHRResource) type = InspectorPageAgent::XHRResource; else if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::ScriptResource) type = InspectorPageAgent::ScriptResource; else if (equalIgnoringFragmentIdentifier(response.url(), loader->url()) && !loader->isCommitted()) type = InspectorPageAgent::DocumentResource; m_resourcesData->responseReceived(requestId, m_pageAgent->frameId(loader->frame()), response); m_resourcesData->setResourceType(requestId, type); m_frontend->responseReceived(requestId, m_pageAgent->frameId(loader->frame()), m_pageAgent->loaderId(loader), currentTime(), InspectorPageAgent::resourceTypeJson(type), resourceResponse); // If we revalidated the resource and got Not modified, send content length following didReceiveResponse // as there will be no calls to didReceiveData from the network stack. if (isNotModified && cachedResource && cachedResource->encodedSize()) didReceiveData(identifier, 0, cachedResource->encodedSize(), 0); }
void InspectorResourceAgent::didReceiveResponse(unsigned long identifier, DocumentLoader* loader, const ResourceResponse& response) { String requestId = IdentifiersFactory::requestId(identifier); RefPtr<InspectorObject> resourceResponse = buildObjectForResourceResponse(response, loader); InspectorPageAgent::ResourceType type = InspectorPageAgent::OtherResource; long cachedResourceSize = 0; if (loader) { CachedResource* cachedResource = InspectorPageAgent::cachedResource(loader->frame(), response.url()); if (cachedResource) { type = InspectorPageAgent::cachedResourceType(*cachedResource); cachedResourceSize = cachedResource->encodedSize(); // Use mime type from cached resource in case the one in response is empty. if (resourceResponse && response.mimeType().isEmpty()) resourceResponse->setString("mimeType", cachedResource->response().mimeType()); m_resourcesData->addCachedResource(requestId, cachedResource); } if (m_loadingXHRSynchronously || m_resourcesData->resourceType(requestId) == InspectorPageAgent::XHRResource) type = InspectorPageAgent::XHRResource; else if (m_resourcesData->resourceType(requestId) == InspectorPageAgent::ScriptResource) type = InspectorPageAgent::ScriptResource; else if (equalIgnoringFragmentIdentifier(response.url(), loader->frameLoader()->icon()->url())) type = InspectorPageAgent::ImageResource; else if (equalIgnoringFragmentIdentifier(response.url(), loader->url()) && !loader->isCommitted()) type = InspectorPageAgent::DocumentResource; m_resourcesData->responseReceived(requestId, m_pageAgent->frameId(loader->frame()), response); } m_resourcesData->setResourceType(requestId, type); m_frontend->responseReceived(requestId, m_pageAgent->frameId(loader->frame()), m_pageAgent->loaderId(loader), currentTime(), InspectorPageAgent::resourceTypeString(type), resourceResponse); // If we revalidated the resource and got Not modified, send content length following didReceiveResponse // as there will be no calls to didReceiveData from the network stack. if (cachedResourceSize && response.httpStatusCode() == 304) didReceiveData(identifier, 0, cachedResourceSize, 0); }
void MemoryCache::dumpLRULists(bool includeLive) const { printf("LRU-SP lists in eviction order (Kilobytes decoded, Kilobytes encoded, Access count, Referenced, isPurgeable, wasPurged):\n"); int size = m_allResources.size(); for (int i = size - 1; i >= 0; i--) { printf("\n\nList %d: ", i); CachedResource* current = m_allResources[i].m_tail; while (current) { CachedResource* prev = current->m_prevInAllResourcesList; if (includeLive || !current->hasClients()) printf("(%.1fK, %.1fK, %uA, %dR, %d, %d); ", current->decodedSize() / 1024.0f, (current->encodedSize() + current->overheadSize()) / 1024.0f, current->accessCount(), current->hasClients(), current->isPurgeable(), current->wasPurged()); current = prev; } } }