This source file includes following definitions.
- m_accessedImage
- cachedOrPendingImage
- cachedImage
- hasFailedOrCanceledSubresources
- equals
- customCSSText
- cloneForCSSOM
- knownToBeOpaque
- traceAfterDispatch
- reResolveURL
#include "config.h"
#include "core/css/CSSImageValue.h"
#include "FetchInitiatorTypeNames.h"
#include "core/css/CSSMarkup.h"
#include "core/dom/Document.h"
#include "core/fetch/CrossOriginAccessControl.h"
#include "core/fetch/FetchRequest.h"
#include "core/fetch/ImageResource.h"
#include "core/rendering/style/StyleFetchedImage.h"
#include "core/rendering/style/StylePendingImage.h"
#include "platform/weborigin/KURL.h"
namespace WebCore {
CSSImageValue::CSSImageValue(const String& rawValue, const KURL& url, StyleImage* image)
: CSSValue(ImageClass)
, m_relativeURL(rawValue)
, m_absoluteURL(url.string())
, m_image(image)
, m_accessedImage(image)
{
}
CSSImageValue::~CSSImageValue()
{
}
StyleImage* CSSImageValue::cachedOrPendingImage()
{
if (!m_image)
m_image = StylePendingImage::create(this);
return m_image.get();
}
StyleFetchedImage* CSSImageValue::cachedImage(ResourceFetcher* fetcher, const ResourceLoaderOptions& options)
{
ASSERT(fetcher);
if (!m_accessedImage) {
m_accessedImage = true;
FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isEmpty() ? FetchInitiatorTypeNames::css : m_initiatorName, options);
if (options.corsEnabled == IsCORSEnabled)
request.setCrossOriginAccessControl(fetcher->document()->securityOrigin(), options.allowCredentials, options.credentialsRequested);
if (ResourcePtr<ImageResource> cachedImage = fetcher->fetchImage(request))
m_image = StyleFetchedImage::create(cachedImage.get());
}
return (m_image && m_image->isImageResource()) ? toStyleFetchedImage(m_image) : 0;
}
bool CSSImageValue::hasFailedOrCanceledSubresources() const
{
if (!m_image || !m_image->isImageResource())
return false;
if (Resource* cachedResource = toStyleFetchedImage(m_image)->cachedImage())
return cachedResource->loadFailedOrCanceled();
return true;
}
bool CSSImageValue::equals(const CSSImageValue& other) const
{
return m_absoluteURL == other.m_absoluteURL;
}
String CSSImageValue::customCSSText() const
{
return "url(" + quoteCSSURLIfNeeded(m_absoluteURL) + ")";
}
PassRefPtrWillBeRawPtr<CSSValue> CSSImageValue::cloneForCSSOM() const
{
RefPtrWillBeRawPtr<CSSPrimitiveValue> uriValue = CSSPrimitiveValue::create(m_absoluteURL, CSSPrimitiveValue::CSS_URI);
uriValue->setCSSOMSafe();
return uriValue.release();
}
bool CSSImageValue::knownToBeOpaque(const RenderObject* renderer) const
{
return m_image ? m_image->knownToBeOpaque(renderer) : false;
}
void CSSImageValue::traceAfterDispatch(Visitor* visitor)
{
CSSValue::traceAfterDispatch(visitor);
}
void CSSImageValue::reResolveURL(const Document& document)
{
KURL url = document.completeURL(m_relativeURL);
if (url == m_absoluteURL)
return;
m_absoluteURL = url.string();
m_accessedImage = false;
m_image.clear();
}
}