OLD | NEW |
1 /* | 1 /* |
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) | 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. | 3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "platform/CrossOriginAttributeValue.h" | 32 #include "platform/CrossOriginAttributeValue.h" |
33 #include "platform/weborigin/KURL.h" | 33 #include "platform/weborigin/KURL.h" |
34 #include "platform/weborigin/SecurityPolicy.h" | 34 #include "platform/weborigin/SecurityPolicy.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 CSSImageValue::CSSImageValue(const AtomicString& rawValue, const KURL& url, Styl
eImage* image) | 38 CSSImageValue::CSSImageValue(const AtomicString& rawValue, const KURL& url, Styl
eImage* image) |
39 : CSSValue(ImageClass) | 39 : CSSValue(ImageClass) |
40 , m_relativeURL(rawValue) | 40 , m_relativeURL(rawValue) |
41 , m_absoluteURL(url.getString()) | 41 , m_absoluteURL(url.getString()) |
42 , m_isCachePending(!image) | |
43 , m_cachedImage(image) | 42 , m_cachedImage(image) |
44 { | 43 { |
45 } | 44 } |
46 | 45 |
47 CSSImageValue::CSSImageValue(const AtomicString& absoluteURL) | 46 CSSImageValue::CSSImageValue(const AtomicString& absoluteURL) |
48 : CSSValue(ImageClass) | 47 : CSSValue(ImageClass) |
49 , m_relativeURL(absoluteURL) | 48 , m_relativeURL(absoluteURL) |
50 , m_absoluteURL(absoluteURL) | 49 , m_absoluteURL(absoluteURL) |
51 , m_isCachePending(true) | |
52 { | 50 { |
53 } | 51 } |
54 | 52 |
55 CSSImageValue::~CSSImageValue() | 53 CSSImageValue::~CSSImageValue() |
56 { | 54 { |
57 } | 55 } |
58 | 56 |
59 StyleImage* CSSImageValue::cacheImage(Document* document, CrossOriginAttributeVa
lue crossOrigin) | 57 StyleImage* CSSImageValue::cacheImage(Document* document, CrossOriginAttributeVa
lue crossOrigin) |
60 { | 58 { |
61 ASSERT(document); | 59 ASSERT(document); |
62 | 60 |
63 if (m_isCachePending) { | 61 if (!m_cachedImage) { |
64 m_isCachePending = false; | |
65 | |
66 FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isE
mpty() ? FetchInitiatorTypeNames::css : m_initiatorName); | 62 FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isE
mpty() ? FetchInitiatorTypeNames::css : m_initiatorName); |
67 request.mutableResourceRequest().setHTTPReferrer(SecurityPolicy::generat
eReferrer(m_referrer.referrerPolicy, request.url(), m_referrer.referrer)); | 63 request.mutableResourceRequest().setHTTPReferrer(SecurityPolicy::generat
eReferrer(m_referrer.referrerPolicy, request.url(), m_referrer.referrer)); |
68 | 64 |
69 if (crossOrigin != CrossOriginAttributeNotSet) | 65 if (crossOrigin != CrossOriginAttributeNotSet) |
70 request.setCrossOriginAccessControl(document->getSecurityOrigin(), c
rossOrigin); | 66 request.setCrossOriginAccessControl(document->getSecurityOrigin(), c
rossOrigin); |
71 | 67 |
72 if (ImageResource* cachedImage = ImageResource::fetch(request, document-
>fetcher())) | 68 if (ImageResource* cachedImage = ImageResource::fetch(request, document-
>fetcher())) |
73 m_cachedImage = StyleFetchedImage::create(cachedImage, document, req
uest.url()); | 69 m_cachedImage = StyleFetchedImage::create(cachedImage, document, req
uest.url()); |
74 else | 70 else |
75 m_cachedImage = StyleInvalidImage::create(url()); | 71 m_cachedImage = StyleInvalidImage::create(url()); |
76 } | 72 } |
77 | 73 |
78 return m_cachedImage.get(); | 74 return m_cachedImage.get(); |
79 } | 75 } |
80 | 76 |
81 void CSSImageValue::restoreCachedResourceIfNeeded(Document& document) const | 77 void CSSImageValue::restoreCachedResourceIfNeeded(Document& document) const |
82 { | 78 { |
83 if (m_isCachePending || !m_cachedImage || !document.fetcher() || m_absoluteU
RL.isNull()) | 79 if (!m_cachedImage || !document.fetcher() || m_absoluteURL.isNull()) |
84 return; | 80 return; |
85 if (document.fetcher()->cachedResource(KURL(ParsedURLString, m_absoluteURL))
) | 81 if (document.fetcher()->cachedResource(KURL(ParsedURLString, m_absoluteURL))
) |
86 return; | 82 return; |
87 | 83 |
88 ImageResource* resource = m_cachedImage->cachedImage(); | 84 ImageResource* resource = m_cachedImage->cachedImage(); |
89 if (!resource) | 85 if (!resource) |
90 return; | 86 return; |
91 | 87 |
92 FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isEmpty
() ? FetchInitiatorTypeNames::css : m_initiatorName, resource->options()); | 88 FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isEmpty
() ? FetchInitiatorTypeNames::css : m_initiatorName, resource->options()); |
93 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textImage); | 89 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textImage); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 CSSValue::traceAfterDispatch(visitor); | 122 CSSValue::traceAfterDispatch(visitor); |
127 } | 123 } |
128 | 124 |
129 void CSSImageValue::reResolveURL(const Document& document) const | 125 void CSSImageValue::reResolveURL(const Document& document) const |
130 { | 126 { |
131 KURL url = document.completeURL(m_relativeURL); | 127 KURL url = document.completeURL(m_relativeURL); |
132 AtomicString urlString(url.getString()); | 128 AtomicString urlString(url.getString()); |
133 if (urlString == m_absoluteURL) | 129 if (urlString == m_absoluteURL) |
134 return; | 130 return; |
135 m_absoluteURL = urlString; | 131 m_absoluteURL = urlString; |
136 m_isCachePending = true; | |
137 m_cachedImage.clear(); | 132 m_cachedImage.clear(); |
138 } | 133 } |
139 | 134 |
140 } // namespace blink | 135 } // namespace blink |
OLD | NEW |