Replace WTF::move with WTFMove
[WebKit-https.git] / Source / WebCore / css / CSSImageValue.cpp
index 957a221..d0b6274 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2004, 2005, 2006, 2008, 2013 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
 #include "CachedResourceLoader.h"
 #include "CachedResourceRequest.h"
 #include "CachedResourceRequestInitiators.h"
+#include "CrossOriginAccessControl.h"
 #include "Document.h"
 #include "Element.h"
 #include "MemoryCache.h"
 #include "StyleCachedImage.h"
 #include "StylePendingImage.h"
-#include "WebCoreMemoryInstrumentation.h"
 
 namespace WebCore {
 
-CSSImageValue::CSSImageValue(ClassType classType, const String& url)
-    : CSSValue(classType)
-    , m_url(url)
-    , m_accessedImage(false)
-{
-}
-
 CSSImageValue::CSSImageValue(const String& url)
     : CSSValue(ImageClass)
     , m_url(url)
@@ -59,8 +52,15 @@ CSSImageValue::CSSImageValue(const String& url, StyleImage* image)
 {
 }
 
+inline void CSSImageValue::detachPendingImage()
+{
+    if (is<StylePendingImage>(m_image.get()))
+        downcast<StylePendingImage>(*m_image).detachFromCSSValue();
+}
+
 CSSImageValue::~CSSImageValue()
 {
+    detachPendingImage();
 }
 
 StyleImage* CSSImageValue::cachedOrPendingImage()
@@ -71,73 +71,59 @@ StyleImage* CSSImageValue::cachedOrPendingImage()
     return m_image.get();
 }
 
-StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader, Element* initiatorElement)
+StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader& loader, const ResourceLoaderOptions& options)
 {
-    if (isCursorImageValue())
-        return static_cast<CSSCursorImageValue*>(this)->cachedImage(loader);
-    return cachedImage(loader, m_url, initiatorElement);
-}
-
-StyleCachedImage* CSSImageValue::cachedImage(CachedResourceLoader* loader, const String& url, Element* initiatorElement)
-{
-    ASSERT(loader);
-
     if (!m_accessedImage) {
         m_accessedImage = true;
 
-        CachedResourceRequest request(ResourceRequest(loader->document()->completeURL(url)));
-        if (initiatorElement)
-            request.setInitiator(initiatorElement);
+        CachedResourceRequest request(ResourceRequest(loader.document()->completeURL(m_url)), options);
+        if (m_initiatorName.isEmpty())
+            request.setInitiator(cachedResourceRequestInitiators().css);
         else
-            request.setInitiator(cachedResourceRequestInitiators().css, loader->document());
-        if (CachedResourceHandle<CachedImage> cachedImage = loader->requestImage(request))
+            request.setInitiator(m_initiatorName);
+
+        if (options.requestOriginPolicy() == PotentiallyCrossOriginEnabled)
+            updateRequestForAccessControl(request.mutableResourceRequest(), loader.document()->securityOrigin(), options.allowCredentials());
+
+        if (CachedResourceHandle<CachedImage> cachedImage = loader.requestImage(request)) {
+            detachPendingImage();
             m_image = StyleCachedImage::create(cachedImage.get());
+        }
     }
 
-    return (m_image && m_image->isCachedImage()) ? static_cast<StyleCachedImage*>(m_image.get()) : 0;
+    return is<StyleCachedImage>(m_image.get()) ? downcast<StyleCachedImage>(m_image.get()) : nullptr;
 }
 
-String CSSImageValue::cachedImageURL()
+bool CSSImageValue::traverseSubresources(const std::function<bool (const CachedResource&)>& handler) const
 {
-    if (!m_image || !m_image->isCachedImage())
-        return String();
-    return static_cast<StyleCachedImage*>(m_image.get())->cachedImage()->url();
-}
-
-void CSSImageValue::clearCachedImage()
-{
-    m_image = 0;
-    m_accessedImage = false;
+    if (!is<StyleCachedImage>(m_image.get()))
+        return false;
+    CachedResource* cachedResource = downcast<StyleCachedImage>(*m_image).cachedImage();
+    ASSERT(cachedResource);
+    return handler(*cachedResource);
 }
 
-bool CSSImageValue::hasFailedOrCanceledSubresources() const
+bool CSSImageValue::equals(const CSSImageValue& other) const
 {
-    if (!m_image || !m_image->isCachedImage())
-        return false;
-    CachedResource* cachedResource = static_cast<StyleCachedImage*>(m_image.get())->cachedImage();
-    if (!cachedResource)
-        return true;
-    return cachedResource->loadFailedOrCanceled();
+    return m_url == other.m_url;
 }
 
-String CSSImageValue::customCssText() const
+String CSSImageValue::customCSSText() const
 {
-    return "url(" + quoteCSSURLIfNeeded(m_url) + ")";
+    return "url(" + quoteCSSURLIfNeeded(m_url) + ')';
 }
 
-PassRefPtr<CSSValue> CSSImageValue::cloneForCSSOM() const
+Ref<CSSValue> CSSImageValue::cloneForCSSOM() const
 {
     // NOTE: We expose CSSImageValues as URI primitive values in CSSOM to maintain old behavior.
-    RefPtr<CSSPrimitiveValue> uriValue = CSSPrimitiveValue::create(m_url, CSSPrimitiveValue::CSS_URI);
+    Ref<CSSPrimitiveValue> uriValue = CSSPrimitiveValue::create(m_url, CSSPrimitiveValue::CSS_URI);
     uriValue->setCSSOMSafe();
-    return uriValue.release();
+    return WTFMove(uriValue);
 }
 
-void CSSImageValue::reportDescendantMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const
+bool CSSImageValue::knownToBeOpaque(const RenderElement* renderer) const
 {
-    MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::CSS);
-    info.addMember(m_url);
-    // No need to report m_image as it is counted as part of RenderArena.
+    return m_image ? m_image->knownToBeOpaque(renderer) : false;
 }
 
 } // namespace WebCore