Chromium Code Reviews| 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 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 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 "config.h" | 27 #include "config.h" |
| 28 #include "core/fetch/CSSStyleSheetResource.h" | 28 #include "core/fetch/CSSStyleSheetResource.h" |
| 29 | 29 |
| 30 #include "core/css/StyleSheetContents.h" | 30 #include "core/css/StyleSheetContents.h" |
| 31 #include "core/fetch/ResourceClientWalker.h" | 31 #include "core/fetch/ResourceClientWalker.h" |
| 32 #include "core/fetch/StyleSheetResourceClient.h" | 32 #include "core/fetch/StyleSheetResourceClient.h" |
| 33 #include "core/html/parser/CompactHTMLToken.h" | |
| 33 #include "core/html/parser/TextResourceDecoder.h" | 34 #include "core/html/parser/TextResourceDecoder.h" |
| 34 #include "platform/SharedBuffer.h" | 35 #include "platform/SharedBuffer.h" |
| 35 #include "platform/network/HTTPParsers.h" | 36 #include "platform/network/HTTPParsers.h" |
| 36 #include "wtf/CurrentTime.h" | 37 #include "wtf/CurrentTime.h" |
| 37 #include "wtf/Vector.h" | 38 #include "wtf/Vector.h" |
| 38 | 39 |
| 39 namespace WebCore { | 40 namespace WebCore { |
| 40 | 41 |
| 41 CSSStyleSheetResource::CSSStyleSheetResource(const ResourceRequest& resourceRequ est, const String& charset) | 42 CSSStyleSheetResource::CSSStyleSheetResource(const ResourceRequest& resourceRequ est, const String& charset, Document* document) |
| 42 : StyleSheetResource(resourceRequest, CSSStyleSheet) | 43 : StyleSheetResource(resourceRequest, CSSStyleSheet) |
| 43 , m_decoder(TextResourceDecoder::create("text/css", charset)) | 44 , m_decoder(TextResourceDecoder::create("text/css", charset)) |
| 45 , m_tokenizer(HTMLTokenizer::create(m_options)) | |
| 46 , m_preloadScanner(adoptPtr(new CSSPreloadScanner)) | |
| 47 , m_input(adoptPtr(new BackgroundHTMLInputStream)) | |
| 48 , m_token(adoptPtr(new HTMLToken)) | |
| 49 , m_preloader(adoptPtr(new HTMLResourcePreloader(document))) | |
| 50 , m_prescan(true) | |
| 44 { | 51 { |
| 45 DEFINE_STATIC_LOCAL(const AtomicString, acceptCSS, ("text/css,*/*;q=0.1", At omicString::ConstructFromLiteral)); | 52 DEFINE_STATIC_LOCAL(const AtomicString, acceptCSS, ("text/css,*/*;q=0.1", At omicString::ConstructFromLiteral)); |
| 46 | 53 |
| 47 // Prefer text/css but accept any type (dell.com serves a stylesheet | 54 // Prefer text/css but accept any type (dell.com serves a stylesheet |
| 48 // as text/html; see <http://bugs.webkit.org/show_bug.cgi?id=11451>). | 55 // as text/html; see <http://bugs.webkit.org/show_bug.cgi?id=11451>). |
| 49 setAccept(acceptCSS); | 56 setAccept(acceptCSS); |
| 57 m_tokenizer->setState(HTMLTokenizer::RAWTEXTState); | |
| 50 } | 58 } |
| 51 | 59 |
| 52 CSSStyleSheetResource::~CSSStyleSheetResource() | 60 CSSStyleSheetResource::~CSSStyleSheetResource() |
| 53 { | 61 { |
| 54 if (m_parsedStyleSheetCache) | 62 if (m_parsedStyleSheetCache) |
| 55 m_parsedStyleSheetCache->removedFromMemoryCache(); | 63 m_parsedStyleSheetCache->removedFromMemoryCache(); |
| 56 } | 64 } |
| 57 | 65 |
| 58 void CSSStyleSheetResource::didAddClient(ResourceClient* c) | 66 void CSSStyleSheetResource::didAddClient(ResourceClient* c) |
| 59 { | 67 { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 m_decodedSheetText = m_decodedSheetText + m_decoder->flush(); | 109 m_decodedSheetText = m_decodedSheetText + m_decoder->flush(); |
| 102 } | 110 } |
| 103 | 111 |
| 104 ResourceClientWalker<StyleSheetResourceClient> w(m_clients); | 112 ResourceClientWalker<StyleSheetResourceClient> w(m_clients); |
| 105 while (StyleSheetResourceClient* c = w.next()) | 113 while (StyleSheetResourceClient* c = w.next()) |
| 106 c->setCSSStyleSheet(m_resourceRequest.url(), m_response.url(), m_decoder ->encoding().name(), this); | 114 c->setCSSStyleSheet(m_resourceRequest.url(), m_response.url(), m_decoder ->encoding().name(), this); |
| 107 // Clear the decoded text as it is unlikely to be needed immediately again a nd is cheap to regenerate. | 115 // Clear the decoded text as it is unlikely to be needed immediately again a nd is cheap to regenerate. |
| 108 m_decodedSheetText = String(); | 116 m_decodedSheetText = String(); |
| 109 } | 117 } |
| 110 | 118 |
| 119 void CSSStyleSheetResource::appendData(const char* data, int length) | |
| 120 { | |
| 121 Resource::appendData(data, length); | |
| 122 if (m_prescan) { | |
| 123 // FIXME: Allow scanning entire CSS file for background images and prefe tch according to applied rules. | |
| 124 m_prescan = false; | |
| 125 prescan(data); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 void CSSStyleSheetResource::prescan(const char* data) | |
| 130 { | |
| 131 PreloadRequestStream pendingPreloads; | |
| 132 m_input->append(data); | |
| 133 | |
| 134 while (true) { | |
| 135 if (!m_tokenizer->nextToken(m_input->current(), *m_token)) | |
| 136 break; // We've reached the end of our current input. | |
| 137 | |
| 138 CompactHTMLToken token(m_token.get(), TextPosition(m_input->current().cu rrentLine(), m_input->current().currentColumn())); | |
| 139 m_preloadScanner->scan(token.data(), m_input->current(), pendingPreloads ); | |
|
shatch
2014/02/14 16:20:17
What's the advantage to running this through the t
| |
| 140 m_token->clear(); | |
| 141 } | |
| 142 m_preloader->takeAndPreload(pendingPreloads); | |
| 143 } | |
| 144 | |
| 111 bool CSSStyleSheetResource::canUseSheet(bool enforceMIMEType, bool* hasValidMIME Type) const | 145 bool CSSStyleSheetResource::canUseSheet(bool enforceMIMEType, bool* hasValidMIME Type) const |
| 112 { | 146 { |
| 113 if (errorOccurred()) | 147 if (errorOccurred()) |
| 114 return false; | 148 return false; |
| 115 | 149 |
| 116 if (!enforceMIMEType && !hasValidMIMEType) | 150 if (!enforceMIMEType && !hasValidMIMEType) |
| 117 return true; | 151 return true; |
| 118 | 152 |
| 119 // This check exactly matches Firefox. Note that we grab the Content-Type | 153 // This check exactly matches Firefox. Note that we grab the Content-Type |
| 120 // header directly because we want to see what the value is BEFORE content | 154 // header directly because we want to see what the value is BEFORE content |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 | 208 |
| 175 if (m_parsedStyleSheetCache) | 209 if (m_parsedStyleSheetCache) |
| 176 m_parsedStyleSheetCache->removedFromMemoryCache(); | 210 m_parsedStyleSheetCache->removedFromMemoryCache(); |
| 177 m_parsedStyleSheetCache = sheet; | 211 m_parsedStyleSheetCache = sheet; |
| 178 m_parsedStyleSheetCache->addedToMemoryCache(); | 212 m_parsedStyleSheetCache->addedToMemoryCache(); |
| 179 | 213 |
| 180 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); | 214 setDecodedSize(m_parsedStyleSheetCache->estimatedSizeInBytes()); |
| 181 } | 215 } |
| 182 | 216 |
| 183 } | 217 } |
| OLD | NEW |