This source file includes following definitions.
- shouldUpdateHeaderAfterRevalidation
- m_proxyResource
- failBeforeStarting
- load
- checkNotify
- appendData
- setResourceBuffer
- setDataBufferingPolicy
- error
- finishOnePart
- finish
- passesAccessControlCheck
- passesAccessControlCheck
- currentAge
- freshnessLifetime
- canUseResponse
- lastResourceRequest
- willSendRequest
- unlock
- responseReceived
- setSerializedCachedMetadata
- setCachedMetadata
- cachedMetadata
- setCacheLiveResourcePriority
- clearLoader
- addClient
- didAddClient
- shouldSendCachedDataSynchronouslyForType
- addClientToSet
- removeClient
- allClientsRemoved
- cancelTimerFired
- deleteIfPossible
- setDecodedSize
- setEncodedSize
- didAccessDecodedData
- finishPendingClients
- prune
- setResourceToRevalidate
- clearResourceToRevalidate
- switchClientsToRevalidatedResource
- updateResponseAfterRevalidation
- revalidationSucceeded
- revalidationFailed
- hasOneHandle
- registerHandle
- unregisterHandle
- canReuseRedirectChain
- mustRevalidateDueToCacheHeaders
- canUseCacheValidator
- isPurgeable
- wasPurged
- lock
- overheadSize
- didChangePriority
- callbackHandler
- schedule
- cancel
- isScheduled
- timerFired
- initatorTypeNameToString
- resourceTypeToString
- ResourceTypeName
#include "config.h"
#include "core/fetch/Resource.h"
#include "FetchInitiatorTypeNames.h"
#include "core/fetch/CachedMetadata.h"
#include "core/fetch/CrossOriginAccessControl.h"
#include "core/fetch/MemoryCache.h"
#include "core/fetch/ResourceClient.h"
#include "core/fetch/ResourceClientWalker.h"
#include "core/fetch/ResourceFetcher.h"
#include "core/fetch/ResourceLoader.h"
#include "core/fetch/ResourcePtr.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "platform/Logging.h"
#include "platform/SharedBuffer.h"
#include "platform/weborigin/KURL.h"
#include "public/platform/Platform.h"
#include "wtf/CurrentTime.h"
#include "wtf/MathExtras.h"
#include "wtf/RefCountedLeakCounter.h"
#include "wtf/StdLibExtras.h"
#include "wtf/Vector.h"
#include "wtf/text/CString.h"
using namespace WTF;
namespace WebCore {
const char* const headersToIgnoreAfterRevalidation[] = {
"allow",
"connection",
"etag",
"expires",
"keep-alive",
"last-modified"
"proxy-authenticate",
"proxy-connection",
"trailer",
"transfer-encoding",
"upgrade",
"www-authenticate",
"x-frame-options",
"x-xss-protection",
};
const char* const headerPrefixesToIgnoreAfterRevalidation[] = {
"content-",
"x-content-",
"x-webkit-"
};
static inline bool shouldUpdateHeaderAfterRevalidation(const AtomicString& header)
{
for (size_t i = 0; i < WTF_ARRAY_LENGTH(headersToIgnoreAfterRevalidation); i++) {
if (equalIgnoringCase(header, headersToIgnoreAfterRevalidation[i]))
return false;
}
for (size_t i = 0; i < WTF_ARRAY_LENGTH(headerPrefixesToIgnoreAfterRevalidation); i++) {
if (header.startsWith(headerPrefixesToIgnoreAfterRevalidation[i], false))
return false;
}
return true;
}
DEFINE_DEBUG_ONLY_GLOBAL(RefCountedLeakCounter, cachedResourceLeakCounter, ("Resource"));
Resource::Resource(const ResourceRequest& request, Type type)
: m_resourceRequest(request)
, m_responseTimestamp(currentTime())
, m_cancelTimer(this, &Resource::cancelTimerFired)
, m_lastDecodedAccessTime(0)
, m_loadFinishTime(0)
, m_identifier(0)
, m_encodedSize(0)
, m_decodedSize(0)
, m_handleCount(0)
, m_preloadCount(0)
, m_protectorCount(0)
, m_preloadResult(PreloadNotReferenced)
, m_cacheLiveResourcePriority(CacheLiveResourcePriorityLow)
, m_requestedFromNetworkingLayer(false)
, m_loading(false)
, m_switchingClientsToRevalidatedResource(false)
, m_type(type)
, m_status(Pending)
, m_wasPurged(false)
, m_needsSynchronousCacheHit(false)
#ifdef ENABLE_RESOURCE_IS_DELETED_CHECK
, m_deleted(false)
#endif
, m_resourceToRevalidate(0)
, m_proxyResource(0)
{
ASSERT(m_type == unsigned(type));
#ifndef NDEBUG
cachedResourceLeakCounter.increment();
#endif
if (!m_resourceRequest.url().hasFragmentIdentifier())
return;
KURL urlForCache = MemoryCache::removeFragmentIdentifierIfNeeded(m_resourceRequest.url());
if (urlForCache.hasFragmentIdentifier())
return;
m_fragmentIdentifierForRequest = m_resourceRequest.url().fragmentIdentifier();
m_resourceRequest.setURL(urlForCache);
}
Resource::~Resource()
{
ASSERT(!m_resourceToRevalidate);
ASSERT(canDelete());
RELEASE_ASSERT(!memoryCache()->contains(this));
RELEASE_ASSERT(!ResourceCallback::callbackHandler()->isScheduled(this));
ASSERT(url().isNull() || memoryCache()->resourceForURL(KURL(ParsedURLString, url())) != this);
assertAlive();
#ifdef ENABLE_RESOURCE_IS_DELETED_CHECK
m_deleted = true;
#endif
#ifndef NDEBUG
cachedResourceLeakCounter.decrement();
#endif
}
void Resource::failBeforeStarting()
{
WTF_LOG(ResourceLoading, "Cannot start loading '%s'", url().string().latin1().data());
error(Resource::LoadError);
}
void Resource::load(ResourceFetcher* fetcher, const ResourceLoaderOptions& options)
{
if (!fetcher->frame()) {
failBeforeStarting();
return;
}
m_options = options;
m_loading = true;
if (!accept().isEmpty())
m_resourceRequest.setHTTPAccept(accept());
ResourceRequest request(m_resourceRequest);
if (!m_fragmentIdentifierForRequest.isNull()) {
KURL url = request.url();
url.setFragmentIdentifier(m_fragmentIdentifierForRequest);
request.setURL(url);
m_fragmentIdentifierForRequest = String();
}
m_status = Pending;
if (m_loader) {
RELEASE_ASSERT(m_options.synchronousPolicy == RequestSynchronously);
m_loader->changeToSynchronous();
return;
}
m_loader = ResourceLoader::create(fetcher, this, request, options);
m_loader->start();
}
void Resource::checkNotify()
{
if (isLoading())
return;
ResourceClientWalker<ResourceClient> w(m_clients);
while (ResourceClient* c = w.next())
c->notifyFinished(this);
}
void Resource::appendData(const char* data, int length)
{
TRACE_EVENT0("webkit", "Resource::appendData");
ASSERT(!m_resourceToRevalidate);
ASSERT(!errorOccurred());
if (m_options.dataBufferingPolicy == DoNotBufferData)
return;
if (m_data)
m_data->append(data, length);
else
m_data = SharedBuffer::createPurgeable(data, length);
setEncodedSize(m_data->size());
}
void Resource::setResourceBuffer(PassRefPtr<SharedBuffer> resourceBuffer)
{
ASSERT(!m_resourceToRevalidate);
ASSERT(!errorOccurred());
ASSERT(m_options.dataBufferingPolicy == BufferData);
m_data = resourceBuffer;
setEncodedSize(m_data->size());
}
void Resource::setDataBufferingPolicy(DataBufferingPolicy dataBufferingPolicy)
{
m_options.dataBufferingPolicy = dataBufferingPolicy;
m_data.clear();
setEncodedSize(0);
}
void Resource::error(Resource::Status status)
{
if (m_resourceToRevalidate)
revalidationFailed();
if (!m_error.isNull() && (m_error.isCancellation() || !isPreloaded()))
memoryCache()->remove(this);
setStatus(status);
ASSERT(errorOccurred());
m_data.clear();
setLoading(false);
checkNotify();
}
void Resource::finishOnePart()
{
setLoading(false);
checkNotify();
}
void Resource::finish(double finishTime)
{
ASSERT(!m_resourceToRevalidate);
ASSERT(!errorOccurred());
m_loadFinishTime = finishTime;
finishOnePart();
if (!errorOccurred())
m_status = Cached;
}
bool Resource::passesAccessControlCheck(SecurityOrigin* securityOrigin)
{
String ignoredErrorDescription;
return passesAccessControlCheck(securityOrigin, ignoredErrorDescription);
}
bool Resource::passesAccessControlCheck(SecurityOrigin* securityOrigin, String& errorDescription)
{
return WebCore::passesAccessControlCheck(m_response, resourceRequest().allowStoredCredentials() ? AllowStoredCredentials : DoNotAllowStoredCredentials, securityOrigin, errorDescription);
}
static double currentAge(const ResourceResponse& response, double responseTimestamp)
{
double dateValue = response.date();
double apparentAge = std::isfinite(dateValue) ? std::max(0., responseTimestamp - dateValue) : 0;
double ageValue = response.age();
double correctedReceivedAge = std::isfinite(ageValue) ? std::max(apparentAge, ageValue) : apparentAge;
double residentTime = currentTime() - responseTimestamp;
return correctedReceivedAge + residentTime;
}
static double freshnessLifetime(const ResourceResponse& response, double responseTimestamp)
{
#if !OS(ANDROID)
if (response.url().isLocalFile())
return 0;
#endif
if (!response.url().protocolIsInHTTPFamily()
&& !response.url().protocolIs("filesystem"))
return std::numeric_limits<double>::max();
double maxAgeValue = response.cacheControlMaxAge();
if (std::isfinite(maxAgeValue))
return maxAgeValue;
double expiresValue = response.expires();
double dateValue = response.date();
double creationTime = std::isfinite(dateValue) ? dateValue : responseTimestamp;
if (std::isfinite(expiresValue))
return expiresValue - creationTime;
double lastModifiedValue = response.lastModified();
if (std::isfinite(lastModifiedValue))
return (creationTime - lastModifiedValue) * 0.1;
return 0;
}
static bool canUseResponse(const ResourceResponse& response, double responseTimestamp)
{
if (response.isNull())
return false;
if (response.cacheControlContainsNoCache() || response.cacheControlContainsNoStore())
return false;
if (response.httpStatusCode() == 303) {
return false;
}
if (response.httpStatusCode() == 302 || response.httpStatusCode() == 307) {
return false;
}
return currentAge(response, responseTimestamp) <= freshnessLifetime(response, responseTimestamp);
}
const ResourceRequest& Resource::lastResourceRequest()
{
if (!m_redirectChain.size())
return m_resourceRequest;
return m_redirectChain.last().m_request;
}
void Resource::willSendRequest(ResourceRequest& request, const ResourceResponse& response)
{
m_redirectChain.append(RedirectPair(request, response));
m_requestedFromNetworkingLayer = true;
}
bool Resource::unlock()
{
if (!m_data)
return false;
if (!m_data->isLocked())
return true;
if (!memoryCache()->contains(this) || hasClients() || m_handleCount > 1 || m_proxyResource || m_resourceToRevalidate || !m_loadFinishTime || !isSafeToUnlock())
return false;
m_data->unlock();
return true;
}
void Resource::responseReceived(const ResourceResponse& response)
{
setResponse(response);
m_responseTimestamp = currentTime();
String encoding = response.textEncodingName();
if (!encoding.isNull())
setEncoding(encoding);
if (!m_resourceToRevalidate)
return;
if (response.httpStatusCode() == 304)
revalidationSucceeded(response);
else
revalidationFailed();
}
void Resource::setSerializedCachedMetadata(const char* data, size_t size)
{
ASSERT(!m_cachedMetadata);
ASSERT(!m_resourceToRevalidate);
m_cachedMetadata = CachedMetadata::deserialize(data, size);
}
void Resource::setCachedMetadata(unsigned dataTypeID, const char* data, size_t size)
{
ASSERT(!m_cachedMetadata);
m_cachedMetadata = CachedMetadata::create(dataTypeID, data, size);
const Vector<char>& serializedData = m_cachedMetadata->serialize();
blink::Platform::current()->cacheMetadata(m_response.url(), m_response.responseTime(), serializedData.data(), serializedData.size());
}
CachedMetadata* Resource::cachedMetadata(unsigned dataTypeID) const
{
if (!m_cachedMetadata || m_cachedMetadata->dataTypeID() != dataTypeID)
return 0;
return m_cachedMetadata.get();
}
void Resource::setCacheLiveResourcePriority(CacheLiveResourcePriority priority)
{
if (memoryCache()->contains(this) && memoryCache()->isInLiveDecodedResourcesList(this) && cacheLiveResourcePriority() != static_cast<unsigned>(priority)) {
memoryCache()->removeFromLiveDecodedResourcesList(this);
m_cacheLiveResourcePriority = priority;
memoryCache()->insertInLiveDecodedResourcesList(this);
memoryCache()->prune();
}
}
void Resource::clearLoader()
{
m_loader = nullptr;
}
void Resource::addClient(ResourceClient* client)
{
if (addClientToSet(client))
didAddClient(client);
}
void Resource::didAddClient(ResourceClient* c)
{
if (!isLoading() && !stillNeedsLoad())
c->notifyFinished(this);
}
static bool shouldSendCachedDataSynchronouslyForType(Resource::Type type)
{
if (type == Resource::Image)
return true;
if (type == Resource::CSSStyleSheet)
return true;
if (type == Resource::Script)
return true;
if (type == Resource::Font)
return true;
return false;
}
bool Resource::addClientToSet(ResourceClient* client)
{
ASSERT(!isPurgeable());
if (m_preloadResult == PreloadNotReferenced) {
if (isLoaded())
m_preloadResult = PreloadReferencedWhileComplete;
else if (m_requestedFromNetworkingLayer)
m_preloadResult = PreloadReferencedWhileLoading;
else
m_preloadResult = PreloadReferenced;
}
if (!hasClients() && memoryCache()->contains(this))
memoryCache()->addToLiveResourcesSize(this);
if (!m_response.isNull() && !m_proxyResource && !shouldSendCachedDataSynchronouslyForType(type()) && !m_needsSynchronousCacheHit) {
m_clientsAwaitingCallback.add(client);
ResourceCallback::callbackHandler()->schedule(this);
return false;
}
m_clients.add(client);
return true;
}
void Resource::removeClient(ResourceClient* client)
{
if (m_clientsAwaitingCallback.contains(client)) {
ASSERT(!m_clients.contains(client));
m_clientsAwaitingCallback.remove(client);
if (m_clientsAwaitingCallback.isEmpty())
ResourceCallback::callbackHandler()->cancel(this);
} else {
ASSERT(m_clients.contains(client));
m_clients.remove(client);
didRemoveClient(client);
}
bool deleted = deleteIfPossible();
if (!deleted && !hasClients()) {
if (memoryCache()->contains(this)) {
memoryCache()->removeFromLiveResourcesSize(this);
memoryCache()->removeFromLiveDecodedResourcesList(this);
}
if (!m_switchingClientsToRevalidatedResource)
allClientsRemoved();
if (response().cacheControlContainsNoStore() && url().protocolIs("https")) {
memoryCache()->remove(this);
memoryCache()->prune();
} else {
memoryCache()->prune(this);
}
}
}
void Resource::allClientsRemoved()
{
if (!m_loader)
return;
if (m_type == MainResource || m_type == Raw)
cancelTimerFired(&m_cancelTimer);
else if (!m_cancelTimer.isActive())
m_cancelTimer.startOneShot(0, FROM_HERE);
unlock();
}
void Resource::cancelTimerFired(Timer<Resource>* timer)
{
ASSERT_UNUSED(timer, timer == &m_cancelTimer);
if (hasClients() || !m_loader)
return;
ResourcePtr<Resource> protect(this);
m_loader->cancelIfNotFinishing();
if (m_status != Cached)
memoryCache()->remove(this);
}
bool Resource::deleteIfPossible()
{
if (canDelete() && !memoryCache()->contains(this)) {
InspectorInstrumentation::willDestroyResource(this);
delete this;
return true;
}
return false;
}
void Resource::setDecodedSize(size_t decodedSize)
{
if (decodedSize == m_decodedSize)
return;
size_t oldSize = size();
m_decodedSize = decodedSize;
if (memoryCache()->contains(this)) {
if (m_decodedSize && !memoryCache()->isInLiveDecodedResourcesList(this) && hasClients())
memoryCache()->insertInLiveDecodedResourcesList(this);
else if (!m_decodedSize && memoryCache()->isInLiveDecodedResourcesList(this))
memoryCache()->removeFromLiveDecodedResourcesList(this);
memoryCache()->update(this, oldSize, size());
}
}
void Resource::setEncodedSize(size_t encodedSize)
{
if (encodedSize == m_encodedSize)
return;
size_t oldSize = size();
m_encodedSize = encodedSize;
if (memoryCache()->contains(this))
memoryCache()->update(this, oldSize, size());
}
void Resource::didAccessDecodedData(double timeStamp)
{
m_lastDecodedAccessTime = timeStamp;
if (memoryCache()->contains(this)) {
if (memoryCache()->isInLiveDecodedResourcesList(this)) {
memoryCache()->removeFromLiveDecodedResourcesList(this);
memoryCache()->insertInLiveDecodedResourcesList(this);
}
memoryCache()->prune();
}
}
void Resource::finishPendingClients()
{
while (!m_clientsAwaitingCallback.isEmpty()) {
ResourceClient* client = m_clientsAwaitingCallback.begin()->key;
m_clientsAwaitingCallback.remove(client);
m_clients.add(client);
didAddClient(client);
}
}
void Resource::prune()
{
destroyDecodedDataIfPossible();
unlock();
}
void Resource::setResourceToRevalidate(Resource* resource)
{
ASSERT(resource);
ASSERT(!m_resourceToRevalidate);
ASSERT(resource != this);
ASSERT(m_handlesToRevalidate.isEmpty());
ASSERT(resource->type() == type());
WTF_LOG(ResourceLoading, "Resource %p setResourceToRevalidate %p", this, resource);
ASSERT(!resource->m_proxyResource);
resource->m_proxyResource = this;
m_resourceToRevalidate = resource;
}
void Resource::clearResourceToRevalidate()
{
ASSERT(m_resourceToRevalidate);
if (m_switchingClientsToRevalidatedResource)
return;
if (m_resourceToRevalidate->m_proxyResource == this) {
m_resourceToRevalidate->m_proxyResource = 0;
m_resourceToRevalidate->deleteIfPossible();
}
m_handlesToRevalidate.clear();
m_resourceToRevalidate = 0;
deleteIfPossible();
}
void Resource::switchClientsToRevalidatedResource()
{
ASSERT(m_resourceToRevalidate);
ASSERT(memoryCache()->contains(m_resourceToRevalidate));
ASSERT(!memoryCache()->contains(this));
WTF_LOG(ResourceLoading, "Resource %p switchClientsToRevalidatedResource %p", this, m_resourceToRevalidate);
m_resourceToRevalidate->m_identifier = m_identifier;
m_switchingClientsToRevalidatedResource = true;
HashSet<ResourcePtrBase*>::iterator end = m_handlesToRevalidate.end();
for (HashSet<ResourcePtrBase*>::iterator it = m_handlesToRevalidate.begin(); it != end; ++it) {
ResourcePtrBase* handle = *it;
handle->m_resource = m_resourceToRevalidate;
m_resourceToRevalidate->registerHandle(handle);
--m_handleCount;
}
ASSERT(!m_handleCount);
m_handlesToRevalidate.clear();
Vector<ResourceClient*> clientsToMove;
HashCountedSet<ResourceClient*>::iterator end2 = m_clients.end();
for (HashCountedSet<ResourceClient*>::iterator it = m_clients.begin(); it != end2; ++it) {
ResourceClient* client = it->key;
unsigned count = it->value;
while (count) {
clientsToMove.append(client);
--count;
}
}
unsigned moveCount = clientsToMove.size();
for (unsigned n = 0; n < moveCount; ++n)
removeClient(clientsToMove[n]);
ASSERT(m_clients.isEmpty());
for (unsigned n = 0; n < moveCount; ++n)
m_resourceToRevalidate->addClientToSet(clientsToMove[n]);
for (unsigned n = 0; n < moveCount; ++n) {
ASSERT(m_resourceToRevalidate);
if (m_resourceToRevalidate->m_clients.contains(clientsToMove[n]))
m_resourceToRevalidate->didAddClient(clientsToMove[n]);
}
m_switchingClientsToRevalidatedResource = false;
}
void Resource::updateResponseAfterRevalidation(const ResourceResponse& validatingResponse)
{
m_responseTimestamp = currentTime();
const HTTPHeaderMap& newHeaders = validatingResponse.httpHeaderFields();
HTTPHeaderMap::const_iterator end = newHeaders.end();
for (HTTPHeaderMap::const_iterator it = newHeaders.begin(); it != end; ++it) {
if (!shouldUpdateHeaderAfterRevalidation(it->key))
continue;
m_response.setHTTPHeaderField(it->key, it->value);
}
}
void Resource::revalidationSucceeded(const ResourceResponse& response)
{
ASSERT(m_resourceToRevalidate);
ASSERT(!memoryCache()->contains(m_resourceToRevalidate));
ASSERT(m_resourceToRevalidate->isLoaded());
ASSERT(memoryCache()->contains(this));
ASSERT(!canDelete());
m_resourceToRevalidate->updateResponseAfterRevalidation(response);
memoryCache()->replace(m_resourceToRevalidate, this);
switchClientsToRevalidatedResource();
assertAlive();
clearResourceToRevalidate();
}
void Resource::revalidationFailed()
{
ASSERT(WTF::isMainThread());
WTF_LOG(ResourceLoading, "Revalidation failed for %p", this);
ASSERT(resourceToRevalidate());
clearResourceToRevalidate();
}
bool Resource::hasOneHandle() const
{
return m_handleCount == 1 || (memoryCache()->contains(this) && m_handleCount == 2);
}
void Resource::registerHandle(ResourcePtrBase* h)
{
assertAlive();
++m_handleCount;
if (m_resourceToRevalidate)
m_handlesToRevalidate.add(h);
}
void Resource::unregisterHandle(ResourcePtrBase* h)
{
assertAlive();
ASSERT(m_handleCount > 0);
--m_handleCount;
if (m_resourceToRevalidate)
m_handlesToRevalidate.remove(h);
if (!m_handleCount) {
if (deleteIfPossible())
return;
unlock();
} else if (m_handleCount == 1 && memoryCache()->contains(this)) {
unlock();
}
}
bool Resource::canReuseRedirectChain() const
{
for (size_t i = 0; i < m_redirectChain.size(); ++i) {
if (!canUseResponse(m_redirectChain[i].m_redirectResponse, m_responseTimestamp))
return false;
}
return true;
}
bool Resource::mustRevalidateDueToCacheHeaders() const
{
return !canUseResponse(m_response, m_responseTimestamp);
}
bool Resource::canUseCacheValidator() const
{
if (m_loading || errorOccurred())
return false;
if (m_response.cacheControlContainsNoStore())
return false;
return m_response.hasCacheValidatorFields();
}
bool Resource::isPurgeable() const
{
return m_data && !m_data->isLocked();
}
bool Resource::wasPurged() const
{
return m_wasPurged;
}
bool Resource::lock()
{
if (!m_data)
return true;
if (m_data->isLocked())
return true;
ASSERT(!hasClients());
if (!m_data->lock()) {
m_wasPurged = true;
return false;
}
return true;
}
size_t Resource::overheadSize() const
{
static const int kAverageClientsHashMapSize = 384;
return sizeof(Resource) + m_response.memoryUsage() + kAverageClientsHashMapSize + m_resourceRequest.url().string().length() * 2;
}
void Resource::didChangePriority(ResourceLoadPriority loadPriority, int intraPriorityValue)
{
if (m_loader)
m_loader->didChangePriority(loadPriority, intraPriorityValue);
}
Resource::ResourceCallback* Resource::ResourceCallback::callbackHandler()
{
DEFINE_STATIC_LOCAL(ResourceCallback, callbackHandler, ());
return &callbackHandler;
}
Resource::ResourceCallback::ResourceCallback()
: m_callbackTimer(this, &ResourceCallback::timerFired)
{
}
void Resource::ResourceCallback::schedule(Resource* resource)
{
if (!m_callbackTimer.isActive())
m_callbackTimer.startOneShot(0, FROM_HERE);
resource->assertAlive();
m_resourcesWithPendingClients.add(resource);
}
void Resource::ResourceCallback::cancel(Resource* resource)
{
resource->assertAlive();
m_resourcesWithPendingClients.remove(resource);
if (m_callbackTimer.isActive() && m_resourcesWithPendingClients.isEmpty())
m_callbackTimer.stop();
}
bool Resource::ResourceCallback::isScheduled(Resource* resource) const
{
return m_resourcesWithPendingClients.contains(resource);
}
void Resource::ResourceCallback::timerFired(Timer<ResourceCallback>*)
{
HashSet<Resource*>::iterator end = m_resourcesWithPendingClients.end();
Vector<ResourcePtr<Resource> > resources;
for (HashSet<Resource*>::iterator it = m_resourcesWithPendingClients.begin(); it != end; ++it)
resources.append(*it);
m_resourcesWithPendingClients.clear();
for (size_t i = 0; i < resources.size(); i++) {
resources[i]->assertAlive();
resources[i]->finishPendingClients();
resources[i]->assertAlive();
}
for (size_t i = 0; i < resources.size(); i++)
resources[i]->assertAlive();
}
static const char* initatorTypeNameToString(const AtomicString& initiatorTypeName)
{
if (initiatorTypeName == FetchInitiatorTypeNames::css)
return "CSS resource";
if (initiatorTypeName == FetchInitiatorTypeNames::document)
return "Document";
if (initiatorTypeName == FetchInitiatorTypeNames::icon)
return "Icon";
if (initiatorTypeName == FetchInitiatorTypeNames::internal)
return "Internal resource";
if (initiatorTypeName == FetchInitiatorTypeNames::link)
return "Link element resource";
if (initiatorTypeName == FetchInitiatorTypeNames::processinginstruction)
return "Processing instruction";
if (initiatorTypeName == FetchInitiatorTypeNames::texttrack)
return "Text track";
if (initiatorTypeName == FetchInitiatorTypeNames::xml)
return "XML resource";
if (initiatorTypeName == FetchInitiatorTypeNames::xmlhttprequest)
return "XMLHttpRequest";
return "Resource";
}
const char* Resource::resourceTypeToString(Type type, const FetchInitiatorInfo& initiatorInfo)
{
switch (type) {
case Resource::MainResource:
return "Main resource";
case Resource::Image:
return "Image";
case Resource::CSSStyleSheet:
return "CSS stylesheet";
case Resource::Script:
return "Script";
case Resource::Font:
return "Font";
case Resource::Raw:
return initatorTypeNameToString(initiatorInfo.name);
case Resource::SVGDocument:
return "SVG document";
case Resource::XSLStyleSheet:
return "XSL stylesheet";
case Resource::LinkPrefetch:
return "Link prefetch resource";
case Resource::LinkSubresource:
return "Link subresource";
case Resource::TextTrack:
return "Text track";
case Resource::Shader:
return "Shader";
case Resource::ImportResource:
return "Imported resource";
}
ASSERT_NOT_REACHED();
return initatorTypeNameToString(initiatorInfo.name);
}
#if !LOG_DISABLED
const char* ResourceTypeName(Resource::Type type)
{
switch (type) {
case Resource::MainResource:
return "MainResource";
case Resource::Image:
return "Image";
case Resource::CSSStyleSheet:
return "CSSStyleSheet";
case Resource::Script:
return "Script";
case Resource::Font:
return "Font";
case Resource::Raw:
return "Raw";
case Resource::SVGDocument:
return "SVGDocument";
case Resource::XSLStyleSheet:
return "XSLStyleSheet";
case Resource::LinkPrefetch:
return "LinkPrefetch";
case Resource::LinkSubresource:
return "LinkSubresource";
case Resource::TextTrack:
return "TextTrack";
case Resource::Shader:
return "Shader";
case Resource::ImportResource:
return "ImportResource";
}
ASSERT_NOT_REACHED();
return "Unknown";
}
#endif
}