Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Unified Diff: third_party/WebKit/Source/core/css/CSSImageSetValue.cpp

Issue 1368613002: Replace RawPtr with RefPtr on StylePendingImage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix image set caching logic Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/CSSImageSetValue.cpp
diff --git a/third_party/WebKit/Source/core/css/CSSImageSetValue.cpp b/third_party/WebKit/Source/core/css/CSSImageSetValue.cpp
index b9f8a5fb5724842e77d356e73f8bc3002cf34c61..4c500c3195767803831c41360ba8ecf4b3dd16ca 100644
--- a/third_party/WebKit/Source/core/css/CSSImageSetValue.cpp
+++ b/third_party/WebKit/Source/core/css/CSSImageSetValue.cpp
@@ -35,7 +35,6 @@
#include "core/fetch/ResourceFetcher.h"
#include "core/fetch/ResourceLoaderOptions.h"
#include "core/style/StyleFetchedImageSet.h"
-#include "core/style/StylePendingImage.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/SecurityPolicy.h"
#include "wtf/text/StringBuilder.h"
@@ -44,16 +43,16 @@ namespace blink {
CSSImageSetValue::CSSImageSetValue()
: CSSValueList(ImageSetClass, CommaSeparator)
- , m_accessedBestFitImage(false)
- , m_scaleFactor(1)
+ , m_isCachePending(true)
+ , m_cachedScaleFactor(1)
{
}
CSSImageSetValue::~CSSImageSetValue()
{
#if !ENABLE(OILPAN)
- if (m_imageSet && m_imageSet->isImageResourceSet())
- toStyleFetchedImageSet(m_imageSet)->clearImageSetValue();
+ if (m_cachedImageSet && m_cachedImageSet->isImageResourceSet())
+ toStyleFetchedImageSet(m_cachedImageSet)->clearImageSetValue();
#endif
}
@@ -82,32 +81,41 @@ void CSSImageSetValue::fillImageSet()
std::sort(m_imagesInSet.begin(), m_imagesInSet.end(), CSSImageSetValue::compareByScaleFactor);
}
-CSSImageSetValue::ImageWithScale CSSImageSetValue::bestImageForScaleFactor()
+CSSImageSetValue::ImageWithScale CSSImageSetValue::bestImageForScaleFactor(float scaleFactor)
{
ImageWithScale image;
size_t numberOfImages = m_imagesInSet.size();
for (size_t i = 0; i < numberOfImages; ++i) {
image = m_imagesInSet.at(i);
- if (image.scaleFactor >= m_scaleFactor)
+ if (image.scaleFactor >= scaleFactor)
return image;
}
return image;
}
-StyleFetchedImageSet* CSSImageSetValue::cachedImageSet(Document* document, float deviceScaleFactor, const ResourceLoaderOptions& options)
+bool CSSImageSetValue::isCachePending(float deviceScaleFactor) const
{
- ASSERT(document);
+ return m_isCachePending || deviceScaleFactor != m_cachedScaleFactor;
+}
- m_scaleFactor = deviceScaleFactor;
+StyleImage* CSSImageSetValue::cachedImageSet(float deviceScaleFactor)
+{
+ ASSERT(!isCachePending(deviceScaleFactor));
+ return m_cachedImageSet.get();
+}
+
+StyleFetchedImageSet* CSSImageSetValue::cacheImageSet(Document* document, float deviceScaleFactor, const ResourceLoaderOptions& options)
+{
+ ASSERT(document);
if (!m_imagesInSet.size())
fillImageSet();
- if (!m_accessedBestFitImage) {
+ if (m_isCachePending || deviceScaleFactor != m_cachedScaleFactor) {
// FIXME: In the future, we want to take much more than deviceScaleFactor into acount here.
// All forms of scale should be included: Page::pageScaleFactor(), LocalFrame::pageZoomFactor(),
// and any CSS transforms. https://bugs.webkit.org/show_bug.cgi?id=81698
- ImageWithScale image = bestImageForScaleFactor();
+ ImageWithScale image = bestImageForScaleFactor(deviceScaleFactor);
FetchRequest request(ResourceRequest(document->completeURL(image.imageURL)), FetchInitiatorTypeNames::css, options);
request.mutableResourceRequest().setHTTPReferrer(image.referrer);
@@ -115,32 +123,18 @@ StyleFetchedImageSet* CSSImageSetValue::cachedImageSet(Document* document, float
request.setCrossOriginAccessControl(document->securityOrigin(), options.allowCredentials, options.credentialsRequested);
if (ResourcePtr<ImageResource> cachedImage = ImageResource::fetch(request, document->fetcher())) {
- m_imageSet = StyleFetchedImageSet::create(cachedImage.get(), image.scaleFactor, this);
- m_accessedBestFitImage = true;
+ m_cachedImageSet = StyleFetchedImageSet::create(cachedImage.get(), image.scaleFactor, this);
+ m_cachedScaleFactor = deviceScaleFactor;
+ m_isCachePending = false;
}
}
- return (m_imageSet && m_imageSet->isImageResourceSet()) ? toStyleFetchedImageSet(m_imageSet) : nullptr;
+ return (m_cachedImageSet && m_cachedImageSet->isImageResourceSet()) ? toStyleFetchedImageSet(m_cachedImageSet) : nullptr;
}
-StyleFetchedImageSet* CSSImageSetValue::cachedImageSet(Document* document, float deviceScaleFactor)
+StyleFetchedImageSet* CSSImageSetValue::cacheImageSet(Document* document, float deviceScaleFactor)
{
- return cachedImageSet(document, deviceScaleFactor, ResourceFetcher::defaultResourceOptions());
-}
-
-StyleImage* CSSImageSetValue::cachedOrPendingImageSet(float deviceScaleFactor)
-{
- if (!m_imageSet) {
- m_imageSet = StylePendingImage::create(this);
- } else if (!m_imageSet->isPendingImage()) {
- // If the deviceScaleFactor has changed, we may not have the best image loaded, so we have to re-assess.
- if (deviceScaleFactor != m_scaleFactor) {
- m_accessedBestFitImage = false;
- m_imageSet = StylePendingImage::create(this);
- }
- }
-
- return m_imageSet.get();
+ return cacheImageSet(document, deviceScaleFactor, ResourceFetcher::defaultResourceOptions());
}
String CSSImageSetValue::customCSSText() const
@@ -175,16 +169,16 @@ String CSSImageSetValue::customCSSText() const
bool CSSImageSetValue::hasFailedOrCanceledSubresources() const
{
- if (!m_imageSet || !m_imageSet->isImageResourceSet())
+ if (!m_cachedImageSet || !m_cachedImageSet->isImageResourceSet())
return false;
- if (Resource* cachedResource = toStyleFetchedImageSet(m_imageSet)->cachedImage())
+ if (Resource* cachedResource = toStyleFetchedImageSet(m_cachedImageSet)->cachedImage())
return cachedResource->loadFailedOrCanceled();
return true;
}
DEFINE_TRACE_AFTER_DISPATCH(CSSImageSetValue)
{
- visitor->trace(m_imageSet);
+ visitor->trace(m_cachedImageSet);
CSSValueList::traceAfterDispatch(visitor);
}
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSImageSetValue.h ('k') | third_party/WebKit/Source/core/css/CSSImageValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698