summaryrefslogtreecommitdiff
path: root/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
commit32761a6cee1d0dee366b885b7b9c777e67885688 (patch)
treed6bec92bebfb216f4126356e55518842c2f476a1 /Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp
parenta4e969f4965059196ca948db781e52f7cfebf19e (diff)
downloadWebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp')
-rw-r--r--Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp62
1 files changed, 36 insertions, 26 deletions
diff --git a/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp b/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp
index d45f36e8e..69bce8f40 100644
--- a/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp
+++ b/Source/WebCore/loader/cache/CachedCSSStyleSheet.cpp
@@ -3,7 +3,7 @@
Copyright (C) 2001 Dirk Mueller (mueller@kde.org)
Copyright (C) 2002 Waldo Bastian (bastian@kde.org)
Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
- Copyright (C) 2004, 2005, 2006 Apple Inc.
+ Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
@@ -30,10 +30,9 @@
#include "CSSStyleSheet.h"
#include "CachedResourceClientWalker.h"
#include "CachedStyleSheetClient.h"
-#include "HTTPHeaderNames.h"
#include "HTTPParsers.h"
#include "MemoryCache.h"
-#include "SharedBuffer.h"
+#include "ResourceBuffer.h"
#include "StyleSheetContents.h"
#include "TextResourceDecoder.h"
#include <wtf/CurrentTime.h>
@@ -41,8 +40,8 @@
namespace WebCore {
-CachedCSSStyleSheet::CachedCSSStyleSheet(const ResourceRequest& resourceRequest, const String& charset, SessionID sessionID)
- : CachedResource(resourceRequest, CSSStyleSheet, sessionID)
+CachedCSSStyleSheet::CachedCSSStyleSheet(const ResourceRequest& resourceRequest, const String& charset)
+ : CachedResource(resourceRequest, CSSStyleSheet)
, m_decoder(TextResourceDecoder::create("text/css", charset))
{
// Prefer text/css but accept any type (dell.com serves a stylesheet
@@ -78,25 +77,31 @@ String CachedCSSStyleSheet::encoding() const
return m_decoder->encoding().name();
}
-const String CachedCSSStyleSheet::sheetText(MIMETypeCheck mimeTypeCheck, bool* hasValidMIMEType) const
+const String CachedCSSStyleSheet::sheetText(bool enforceMIMEType, bool* hasValidMIMEType) const
{
- if (!m_data || m_data->isEmpty() || !canUseSheet(mimeTypeCheck, hasValidMIMEType))
+ ASSERT(!isPurgeable());
+
+ if (!m_data || m_data->isEmpty() || !canUseSheet(enforceMIMEType, hasValidMIMEType))
return String();
if (!m_decodedSheetText.isNull())
return m_decodedSheetText;
// Don't cache the decoded text, regenerating is cheap and it can use quite a bit of memory
- return m_decoder->decodeAndFlush(m_data->data(), m_data->size());
+ String sheetText = m_decoder->decode(m_data->data(), m_data->size());
+ sheetText.append(m_decoder->flush());
+ return sheetText;
}
-void CachedCSSStyleSheet::finishLoading(SharedBuffer* data)
+void CachedCSSStyleSheet::finishLoading(ResourceBuffer* data)
{
m_data = data;
- setEncodedSize(data ? data->size() : 0);
+ setEncodedSize(m_data.get() ? m_data->size() : 0);
// Decode the data to find out the encoding and keep the sheet text around during checkNotify()
- if (data)
- m_decodedSheetText = m_decoder->decodeAndFlush(data->data(), data->size());
+ if (m_data) {
+ m_decodedSheetText = m_decoder->decode(m_data->data(), m_data->size());
+ m_decodedSheetText.append(m_decoder->flush());
+ }
setLoading(false);
checkNotify();
// Clear the decoded text as it is unlikely to be needed immediately again and is cheap to regenerate.
@@ -113,12 +118,12 @@ void CachedCSSStyleSheet::checkNotify()
c->setCSSStyleSheet(m_resourceRequest.url(), m_response.url(), m_decoder->encoding().name(), this);
}
-bool CachedCSSStyleSheet::canUseSheet(MIMETypeCheck mimeTypeCheck, bool* hasValidMIMEType) const
+bool CachedCSSStyleSheet::canUseSheet(bool enforceMIMEType, bool* hasValidMIMEType) const
{
if (errorOccurred())
return false;
-
- if (mimeTypeCheck == MIMETypeCheck::Lax)
+
+ if (!enforceMIMEType && !hasValidMIMEType)
return true;
// This check exactly matches Firefox. Note that we grab the Content-Type
@@ -128,10 +133,12 @@ bool CachedCSSStyleSheet::canUseSheet(MIMETypeCheck mimeTypeCheck, bool* hasVali
//
// This code defaults to allowing the stylesheet for non-HTTP protocols so
// folks can use standards mode for local HTML documents.
- String mimeType = extractMIMETypeFromMediaType(response().httpHeaderField(HTTPHeaderName::ContentType));
- bool typeOK = mimeType.isEmpty() || equalLettersIgnoringASCIICase(mimeType, "text/css") || equalLettersIgnoringASCIICase(mimeType, "application/x-unknown-content-type");
+ String mimeType = extractMIMETypeFromMediaType(response().httpHeaderField("Content-Type"));
+ bool typeOK = mimeType.isEmpty() || equalIgnoringCase(mimeType, "text/css") || equalIgnoringCase(mimeType, "application/x-unknown-content-type");
if (hasValidMIMEType)
*hasValidMIMEType = typeOK;
+ if (!enforceMIMEType)
+ return true;
return typeOK;
}
@@ -141,19 +148,22 @@ void CachedCSSStyleSheet::destroyDecodedData()
return;
m_parsedStyleSheetCache->removedFromMemoryCache();
- m_parsedStyleSheetCache = nullptr;
+ m_parsedStyleSheetCache.clear();
setDecodedSize(0);
+
+ if (!MemoryCache::shouldMakeResourcePurgeableOnEviction() && isSafeToMakePurgeable())
+ makePurgeable(true);
}
-PassRefPtr<StyleSheetContents> CachedCSSStyleSheet::restoreParsedStyleSheet(const CSSParserContext& context, CachePolicy cachePolicy)
+PassRefPtr<StyleSheetContents> CachedCSSStyleSheet::restoreParsedStyleSheet(const CSSParserContext& context)
{
if (!m_parsedStyleSheetCache)
- return nullptr;
- if (!m_parsedStyleSheetCache->subresourcesAllowReuse(cachePolicy)) {
+ return 0;
+ if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) {
m_parsedStyleSheetCache->removedFromMemoryCache();
- m_parsedStyleSheetCache = nullptr;
- return nullptr;
+ m_parsedStyleSheetCache.clear();
+ return 0;
}
ASSERT(m_parsedStyleSheetCache->isCacheable());
@@ -161,20 +171,20 @@ PassRefPtr<StyleSheetContents> CachedCSSStyleSheet::restoreParsedStyleSheet(cons
// Contexts must be identical so we know we would get the same exact result if we parsed again.
if (m_parsedStyleSheetCache->parserContext() != context)
- return nullptr;
+ return 0;
didAccessDecodedData(monotonicallyIncreasingTime());
return m_parsedStyleSheetCache;
}
-void CachedCSSStyleSheet::saveParsedStyleSheet(Ref<StyleSheetContents>&& sheet)
+void CachedCSSStyleSheet::saveParsedStyleSheet(PassRef<StyleSheetContents> sheet)
{
ASSERT(sheet.get().isCacheable());
if (m_parsedStyleSheetCache)
m_parsedStyleSheetCache->removedFromMemoryCache();
- m_parsedStyleSheetCache = WTFMove(sheet);
+ m_parsedStyleSheetCache = std::move(sheet);
m_parsedStyleSheetCache->addedToMemoryCache();
setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes());