2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #include "core/css/CSSImageValue.h"
24 #include "FetchInitiatorTypeNames.h"
25 #include "core/css/CSSMarkup.h"
26 #include "core/dom/Document.h"
27 #include "core/fetch/CrossOriginAccessControl.h"
28 #include "core/fetch/FetchRequest.h"
29 #include "core/fetch/ImageResource.h"
30 #include "core/rendering/style/StyleFetchedImage.h"
31 #include "core/rendering/style/StylePendingImage.h"
32 #include "platform/weborigin/KURL.h"
36 CSSImageValue::CSSImageValue(const KURL& url)
37 : CSSValue(ImageClass)
39 , m_accessedImage(false)
43 CSSImageValue::CSSImageValue(const KURL& url, StyleImage* image)
44 : CSSValue(ImageClass)
47 , m_accessedImage(true)
51 CSSImageValue::~CSSImageValue()
55 StyleImage* CSSImageValue::cachedOrPendingImage()
58 m_image = StylePendingImage::create(this);
63 StyleFetchedImage* CSSImageValue::cachedImage(ResourceFetcher* fetcher, const ResourceLoaderOptions& options)
67 if (!m_accessedImage) {
68 m_accessedImage = true;
70 FetchRequest request(ResourceRequest(m_url), m_initiatorName.isEmpty() ? FetchInitiatorTypeNames::css : m_initiatorName, options);
72 if (options.corsEnabled == IsCORSEnabled)
73 request.setCrossOriginAccessControl(fetcher->document()->securityOrigin(), options.allowCredentials);
75 if (ResourcePtr<ImageResource> cachedImage = fetcher->fetchImage(request))
76 m_image = StyleFetchedImage::create(cachedImage.get());
79 return (m_image && m_image->isImageResource()) ? toStyleFetchedImage(m_image) : 0;
82 bool CSSImageValue::hasFailedOrCanceledSubresources() const
84 if (!m_image || !m_image->isImageResource())
86 if (Resource* cachedResource = toStyleFetchedImage(m_image)->cachedImage())
87 return cachedResource->loadFailedOrCanceled();
91 bool CSSImageValue::equals(const CSSImageValue& other) const
93 return m_url == other.m_url;
96 String CSSImageValue::customCSSText() const
98 return "url(" + quoteCSSURLIfNeeded(m_url) + ")";
101 PassRefPtr<CSSValue> CSSImageValue::cloneForCSSOM() const
103 // NOTE: We expose CSSImageValues as URI primitive values in CSSOM to maintain old behavior.
104 RefPtrWillBeRawPtr<CSSPrimitiveValue> uriValue = CSSPrimitiveValue::create(m_url, CSSPrimitiveValue::CSS_URI);
105 uriValue->setCSSOMSafe();
106 return uriValue.release();
109 bool CSSImageValue::knownToBeOpaque(const RenderObject* renderer) const
111 return m_image ? m_image->knownToBeOpaque(renderer) : false;
114 void CSSImageValue::traceAfterDispatch(Visitor* visitor)
116 CSSValue::traceAfterDispatch(visitor);
119 } // namespace WebCore