| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
| 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) | 3 Copyright (C) 2001 Dirk Mueller (mueller@kde.org) |
| 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) | 4 Copyright (C) 2002 Waldo Bastian (bastian@kde.org) |
| 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) |
| 6 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. | 6 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. |
| 7 | 7 |
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
| 11 version 2 of the License, or (at your option) any later version. | 11 version 2 of the License, or (at your option) any later version. |
| 12 | 12 |
| 13 This library is distributed in the hope that it will be useful, | 13 This library is distributed in the hope that it will be useful, |
| 14 but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 Library General Public License for more details. | 16 Library General Public License for more details. |
| 17 | 17 |
| 18 You should have received a copy of the GNU Library General Public License | 18 You should have received a copy of the GNU Library General Public License |
| 19 along with this library; see the file COPYING.LIB. If not, write to | 19 along with this library; see the file COPYING.LIB. If not, write to |
| 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 Boston, MA 02110-1301, USA. | 21 Boston, MA 02110-1301, USA. |
| 22 | 22 |
| 23 This class provides all functionality needed for loading images, style sheet
s and html | 23 This class provides all functionality needed for loading images, style sheet
s and html |
| 24 pages from the web. It has a memory cache for these objects. | 24 pages from the web. It has a memory cache for these objects. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #include "core/fetch/CSSStyleSheetResource.h" | 27 #include "core/fetch/CSSStyleSheetResource.h" |
| 28 | 28 |
| 29 #include "core/css/StyleSheetContents.h" | 29 #include "core/css/StyleSheetContents.h" |
| 30 #include "core/css/serializer/CSSDeserializeStream.h" |
| 31 #include "core/css/serializer/CSSSerializeStream.h" |
| 32 #include "core/fetch/CachedMetadata.h" |
| 30 #include "core/fetch/FetchRequest.h" | 33 #include "core/fetch/FetchRequest.h" |
| 31 #include "core/fetch/ResourceClientWalker.h" | 34 #include "core/fetch/ResourceClientWalker.h" |
| 32 #include "core/fetch/ResourceFetcher.h" | 35 #include "core/fetch/ResourceFetcher.h" |
| 33 #include "core/fetch/StyleSheetResourceClient.h" | 36 #include "core/fetch/StyleSheetResourceClient.h" |
| 34 #include "platform/SharedBuffer.h" | 37 #include "platform/SharedBuffer.h" |
| 38 #include "platform/TraceEvent.h" |
| 35 #include "platform/network/HTTPParsers.h" | 39 #include "platform/network/HTTPParsers.h" |
| 36 #include "wtf/CurrentTime.h" | 40 #include "wtf/CurrentTime.h" |
| 37 | 41 |
| 38 namespace blink { | 42 namespace blink { |
| 39 | 43 |
| 40 ResourcePtr<CSSStyleSheetResource> CSSStyleSheetResource::fetch(FetchRequest& re
quest, ResourceFetcher* fetcher) | 44 ResourcePtr<CSSStyleSheetResource> CSSStyleSheetResource::fetch(FetchRequest& re
quest, ResourceFetcher* fetcher) |
| 41 { | 45 { |
| 42 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone
); | 46 ASSERT(request.resourceRequest().frameType() == WebURLRequest::FrameTypeNone
); |
| 43 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textStyle); | 47 request.mutableResourceRequest().setRequestContext(WebURLRequest::RequestCon
textStyle); |
| 44 return toCSSStyleSheetResource(fetcher->requestResource(request, CSSStyleShe
etResourceFactory())); | 48 return toCSSStyleSheetResource(fetcher->requestResource(request, CSSStyleShe
etResourceFactory())); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // sniffing. Firefox does this by setting a "type hint" on the channel. | 147 // sniffing. Firefox does this by setting a "type hint" on the channel. |
| 144 // This implementation should be observationally equivalent. | 148 // This implementation should be observationally equivalent. |
| 145 // | 149 // |
| 146 // This code defaults to allowing the stylesheet for non-HTTP protocols so | 150 // This code defaults to allowing the stylesheet for non-HTTP protocols so |
| 147 // folks can use standards mode for local HTML documents. | 151 // folks can use standards mode for local HTML documents. |
| 148 if (mimeTypeCheck == MIMETypeCheck::Lax) | 152 if (mimeTypeCheck == MIMETypeCheck::Lax) |
| 149 return true; | 153 return true; |
| 150 return mimeType().isEmpty() || equalIgnoringCase(mimeType(), "text/css") ||
equalIgnoringCase(mimeType(), "application/x-unknown-content-type"); | 154 return mimeType().isEmpty() || equalIgnoringCase(mimeType(), "text/css") ||
equalIgnoringCase(mimeType(), "application/x-unknown-content-type"); |
| 151 } | 155 } |
| 152 | 156 |
| 157 PassRefPtrWillBeRawPtr<StyleSheetContents> CSSStyleSheetResource::deserializeSty
leSheet(const CSSParserContext& context) |
| 158 { |
| 159 TRACE_EVENT0("blink", "CSSStyleSheetResource::deserializeStyleSheet"); |
| 160 auto handler = cacheHandler(); |
| 161 if (!handler) |
| 162 return nullptr; |
| 163 |
| 164 unsigned cacheTag = 1; // wtf? |
| 165 CachedMetadata* cachedMetadata = handler->cachedMetadata(cacheTag); |
| 166 if (!cachedMetadata) |
| 167 return nullptr; |
| 168 |
| 169 CSDEBUG("found cachedMetadata: %zu\n", cachedMetadata->size()); |
| 170 |
| 171 RefPtrWillBeRawPtr<StyleSheetContents> sheet; |
| 172 // for (unsigned i = 0; i < 10000; ++ i) |
| 173 { |
| 174 sheet = StyleSheetContents::create(m_response.url(), context); |
| 175 CSSDeserializeStream stream(cachedMetadata->data(), cachedMetadata->size
()); |
| 176 sheet->deserialize(&stream); |
| 177 } |
| 178 |
| 179 return sheet.release(); |
| 180 } |
| 181 |
| 153 PassRefPtrWillBeRawPtr<StyleSheetContents> CSSStyleSheetResource::restoreParsedS
tyleSheet(const CSSParserContext& context) | 182 PassRefPtrWillBeRawPtr<StyleSheetContents> CSSStyleSheetResource::restoreParsedS
tyleSheet(const CSSParserContext& context) |
| 154 { | 183 { |
| 155 if (!m_parsedStyleSheetCache) | 184 if (!m_parsedStyleSheetCache) |
| 156 return nullptr; | 185 return deserializeStyleSheet(context); |
| 157 if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) { | 186 if (m_parsedStyleSheetCache->hasFailedOrCanceledSubresources()) { |
| 158 m_parsedStyleSheetCache->removedFromMemoryCache(); | 187 m_parsedStyleSheetCache->removedFromMemoryCache(); |
| 159 m_parsedStyleSheetCache.clear(); | 188 m_parsedStyleSheetCache.clear(); |
| 160 return nullptr; | 189 return nullptr; |
| 161 } | 190 } |
| 162 | 191 |
| 163 ASSERT(m_parsedStyleSheetCache->isCacheable()); | 192 ASSERT(m_parsedStyleSheetCache->isCacheable()); |
| 164 ASSERT(m_parsedStyleSheetCache->isInMemoryCache()); | 193 ASSERT(m_parsedStyleSheetCache->isInMemoryCache()); |
| 165 | 194 |
| 166 // Contexts must be identical so we know we would get the same exact result
if we parsed again. | 195 // Contexts must be identical so we know we would get the same exact result
if we parsed again. |
| 167 if (m_parsedStyleSheetCache->parserContext() != context) | 196 if (m_parsedStyleSheetCache->parserContext() != context) |
| 168 return nullptr; | 197 return nullptr; |
| 169 | 198 |
| 170 didAccessDecodedData(); | 199 didAccessDecodedData(); |
| 171 | 200 |
| 172 return m_parsedStyleSheetCache; | 201 return m_parsedStyleSheetCache; |
| 173 } | 202 } |
| 174 | 203 |
| 175 void CSSStyleSheetResource::saveParsedStyleSheet(PassRefPtrWillBeRawPtr<StyleShe
etContents> sheet) | 204 void CSSStyleSheetResource::saveParsedStyleSheet(PassRefPtrWillBeRawPtr<StyleShe
etContents> sheet) |
| 176 { | 205 { |
| 177 ASSERT(sheet && sheet->isCacheable()); | 206 ASSERT(sheet && sheet->isCacheable()); |
| 178 | 207 |
| 208 #if 0 |
| 179 if (m_parsedStyleSheetCache) | 209 if (m_parsedStyleSheetCache) |
| 180 m_parsedStyleSheetCache->removedFromMemoryCache(); | 210 m_parsedStyleSheetCache->removedFromMemoryCache(); |
| 181 m_parsedStyleSheetCache = sheet; | 211 m_parsedStyleSheetCache = sheet; |
| 182 m_parsedStyleSheetCache->addedToMemoryCache(); | 212 m_parsedStyleSheetCache->addedToMemoryCache(); |
| 183 | 213 |
| 184 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); | 214 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); |
| 215 #else |
| 216 RefPtr<StyleSheetContents> parsedStyleSheet = sheet; |
| 217 |
| 218 if (auto handler = cacheHandler()) { |
| 219 TRACE_EVENT0("blink", "CSSStyleSheetResource::serializeStyleSheet"); |
| 220 CSSSerializeStream stream; |
| 221 parsedStyleSheet->serialize(&stream); |
| 222 CSDEBUG("serialized size: %zu\n", stream.data().size()); |
| 223 |
| 224 handler->clearCachedMetadata(CachedMetadataHandler::SendToPlatform); |
| 225 unsigned cacheTag = 1; // wtf? |
| 226 handler->setCachedMetadata(cacheTag, stream.data().data(), stream.data()
.size(), CachedMetadataHandler::SendToPlatform); |
| 227 |
| 228 /* |
| 229 FILE* fp = fopen("/usr/local/google/home/kouhei/cssserdestest/cssblob",
"w"); |
| 230 fwrite(stream.data().data(), stream.data().size(), 1, fp); |
| 231 fclose(fp); |
| 232 */ |
| 233 } else { |
| 234 CSDEBUG("no cacheHandler!\n"); |
| 235 } |
| 236 #endif |
| 185 } | 237 } |
| 186 | 238 |
| 187 } | 239 } |
| OLD | NEW |