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

Side by Side Diff: third_party/WebKit/Source/core/css/CSSImageValue.cpp

Issue 1481383002: [Experimental] CSSSerializer Proof-of-concept Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: snapshot: top_25 sites ser/dser now works Created 4 years, 11 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 unified diff | Download patch
OLDNEW
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,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 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 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, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 */ 19 */
20 20
21 #include "core/css/CSSImageValue.h" 21 #include "core/css/CSSImageValue.h"
22 22
23 #include "core/css/CSSMarkup.h" 23 #include "core/css/CSSMarkup.h"
24 #include "core/css/serializer/CSSDeserializeStream.h"
25 #include "core/css/serializer/CSSSerializeStream.h"
24 #include "core/dom/Document.h" 26 #include "core/dom/Document.h"
25 #include "core/fetch/FetchInitiatorTypeNames.h" 27 #include "core/fetch/FetchInitiatorTypeNames.h"
26 #include "core/fetch/FetchRequest.h" 28 #include "core/fetch/FetchRequest.h"
27 #include "core/fetch/ImageResource.h" 29 #include "core/fetch/ImageResource.h"
28 #include "core/fetch/ResourceFetcher.h" 30 #include "core/fetch/ResourceFetcher.h"
29 #include "core/loader/MixedContentChecker.h" 31 #include "core/loader/MixedContentChecker.h"
30 #include "core/style/StyleFetchedImage.h" 32 #include "core/style/StyleFetchedImage.h"
31 #include "platform/CrossOriginAttributeValue.h" 33 #include "platform/CrossOriginAttributeValue.h"
32 #include "platform/weborigin/KURL.h" 34 #include "platform/weborigin/KURL.h"
33 #include "platform/weborigin/SecurityPolicy.h" 35 #include "platform/weborigin/SecurityPolicy.h"
34 36
35 namespace blink { 37 namespace blink {
36 38
37 CSSImageValue::CSSImageValue(const AtomicString& rawValue, const KURL& url, Styl eFetchedImage* image) 39 CSSImageValue::CSSImageValue(const AtomicString& rawValue, const KURL& url, Styl eFetchedImage* image)
38 : CSSValue(ImageClass) 40 : CSSValue(ImageClass)
39 , m_relativeURL(rawValue) 41 , m_relativeURL(rawValue)
40 , m_absoluteURL(url.string()) 42 , m_absoluteURL(url.string())
41 , m_isCachePending(!image) 43 , m_isCachePending(!image)
42 , m_cachedImage(image) 44 , m_cachedImage(image)
43 { 45 {
44 } 46 }
45 47
46 CSSImageValue::~CSSImageValue() 48 CSSImageValue::~CSSImageValue()
47 { 49 {
48 } 50 }
49 51
52 PassRefPtrWillBeRawPtr<CSSImageValue> CSSImageValue::deserializeAfterDispatch(CS SDeserializeStream* stream)
53 {
54 AtomicString relativeURL = stream->readAtomicString();
55 AtomicString absoluteURL = stream->readAtomicString();
56 Referrer referrer = stream->readReferrer();
57 AtomicString initiatorName = stream->readAtomicString();
58
59 return adoptRefWillBeNoop(new CSSImageValue(relativeURL, absoluteURL, referr er, initiatorName));
60 }
61
62 CSSImageValue::CSSImageValue(AtomicString relativeURL, AtomicString absoluteURL, const Referrer& referrer, AtomicString initiatorName)
63 : CSSValue(ImageClass)
64 , m_relativeURL(relativeURL)
65 , m_absoluteURL(absoluteURL)
66 , m_referrer(referrer)
67 , m_isCachePending(true)
68 , m_cachedImage(nullptr)
69 , m_initiatorName(initiatorName)
70 {
71 }
72
50 StyleFetchedImage* CSSImageValue::cacheImage(Document* document, CrossOriginAttr ibuteValue crossOrigin) 73 StyleFetchedImage* CSSImageValue::cacheImage(Document* document, CrossOriginAttr ibuteValue crossOrigin)
51 { 74 {
52 ASSERT(document); 75 ASSERT(document);
53 76
54 if (m_isCachePending) { 77 if (m_isCachePending) {
55 m_isCachePending = false; 78 m_isCachePending = false;
56 79
57 FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isE mpty() ? FetchInitiatorTypeNames::css : m_initiatorName); 80 FetchRequest request(ResourceRequest(m_absoluteURL), m_initiatorName.isE mpty() ? FetchInitiatorTypeNames::css : m_initiatorName);
58 request.mutableResourceRequest().setHTTPReferrer(SecurityPolicy::generat eReferrer(m_referrer.referrerPolicy, request.url(), m_referrer.referrer)); 81 request.mutableResourceRequest().setHTTPReferrer(SecurityPolicy::generat eReferrer(m_referrer.referrerPolicy, request.url(), m_referrer.referrer));
59 82
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 String CSSImageValue::customCSSText() const 124 String CSSImageValue::customCSSText() const
102 { 125 {
103 return serializeURI(m_relativeURL); 126 return serializeURI(m_relativeURL);
104 } 127 }
105 128
106 bool CSSImageValue::knownToBeOpaque(const LayoutObject* layoutObject) const 129 bool CSSImageValue::knownToBeOpaque(const LayoutObject* layoutObject) const
107 { 130 {
108 return m_cachedImage ? m_cachedImage->knownToBeOpaque(layoutObject) : false; 131 return m_cachedImage ? m_cachedImage->knownToBeOpaque(layoutObject) : false;
109 } 132 }
110 133
134 void CSSImageValue::serializeAfterDispatch(CSSSerializeStream* stream) const
135 {
136 stream->writeAtomicString(m_relativeURL);
137 stream->writeAtomicString(m_absoluteURL);
138 stream->writeReferrer(m_referrer);
139 stream->writeAtomicString(m_initiatorName);
140 }
141
111 DEFINE_TRACE_AFTER_DISPATCH(CSSImageValue) 142 DEFINE_TRACE_AFTER_DISPATCH(CSSImageValue)
112 { 143 {
113 visitor->trace(m_cachedImage); 144 visitor->trace(m_cachedImage);
114 CSSValue::traceAfterDispatch(visitor); 145 CSSValue::traceAfterDispatch(visitor);
115 } 146 }
116 147
117 void CSSImageValue::reResolveURL(const Document& document) 148 void CSSImageValue::reResolveURL(const Document& document)
118 { 149 {
119 KURL url = document.completeURL(m_relativeURL); 150 KURL url = document.completeURL(m_relativeURL);
120 AtomicString urlString(url.string()); 151 AtomicString urlString(url.string());
121 if (urlString == m_absoluteURL) 152 if (urlString == m_absoluteURL)
122 return; 153 return;
123 m_absoluteURL = urlString; 154 m_absoluteURL = urlString;
124 m_isCachePending = true; 155 m_isCachePending = true;
125 m_cachedImage.clear(); 156 m_cachedImage.clear();
126 } 157 }
127 158
128 } // namespace blink 159 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/css/CSSImageValue.h ('k') | third_party/WebKit/Source/core/css/CSSInheritedValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698