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; 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(); }
PassRefPtr<SharedBuffer> InspectorResource::resourceData(String* textEncodingName) const { if (m_requestURL == m_loader->requestURL()) { *textEncodingName = m_frame->document()->inputEncoding(); return m_loader->mainResourceData(); } CachedResource* cachedResource = this->cachedResource(); if (!cachedResource) return 0; 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(); }
String InspectorResource::sourceString() const { if (!m_xmlHttpResponseText.isNull()) return String(m_xmlHttpResponseText); RefPtr<SharedBuffer> buffer; String textEncodingName; if (m_requestURL == m_loader->requestURL()) { buffer = m_loader->mainResourceData(); textEncodingName = m_frame->document()->inputEncoding(); } else { CachedResource* cachedResource = m_frame->document()->docLoader()->cachedResource(requestURL()); if (!cachedResource) return String(); 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 String(); } buffer = cachedResource->data(); textEncodingName = cachedResource->encoding(); } if (!buffer) return String(); TextEncoding encoding(textEncodingName); if (!encoding.isValid()) encoding = WindowsLatin1Encoding(); return encoding.decode(buffer->data(), buffer->size()); }
CachedResource* MemoryCache::resourceForRequestImpl(const ResourceRequest& request, CachedResourceMap& resources) { ASSERT(WTF::isMainThread()); URL url = removeFragmentIdentifierIfNeeded(request.url()); #if ENABLE(CACHE_PARTITIONING) CachedResourceItem* item = resources.get(url); CachedResource* resource = 0; if (item) resource = item->get(request.cachePartition()); #else CachedResource* resource = resources.get(url); #endif bool wasPurgeable = MemoryCache::shouldMakeResourcePurgeableOnEviction() && resource && resource->isPurgeable(); if (resource && !resource->makePurgeable(false)) { ASSERT(!resource->hasClients()); evict(resource); return 0; } // Add the size back since we had subtracted it when we marked the memory as purgeable. if (wasPurgeable) adjustSize(resource->hasClients(), resource->size()); return resource; }
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; } } }