Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp |
| diff --git a/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp b/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp |
| index 15a5aaf1d36714052c7ccaf8db2548737a75454c..639d87a4919e7964b358a673d6d3fb2ec4374691 100644 |
| --- a/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp |
| +++ b/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp |
| @@ -27,8 +27,11 @@ |
| #include "core/html/parser/CSSPreloadScanner.h" |
| +#include "core/fetch/CSSStyleSheetResource.h" |
| #include "core/fetch/FetchInitiatorTypeNames.h" |
| #include "core/html/parser/HTMLParserIdioms.h" |
| +#include "core/html/parser/HTMLResourcePreloader.h" |
| +#include "platform/Histogram.h" |
| #include "platform/text/SegmentedString.h" |
| namespace blink { |
| @@ -233,4 +236,33 @@ void CSSPreloadScanner::emitRule(const SegmentedString& source) |
| m_ruleValue.clear(); |
| } |
| +CSSPreloaderResourceClient::CSSPreloaderResourceClient(Resource* resource, HTMLResourcePreloader* preloader) |
| + : m_resource(resource) |
| + , m_preloader(preloader) |
| +{ |
| +} |
| + |
| +void CSSPreloaderResourceClient::notifyFinished(Resource* resource) |
| +{ |
| + resource->removeClient(this); |
| +} |
| + |
| +// Only attach for one appendData call, as that's where most imports will likely |
| +// be (according to spec). |
| +void CSSPreloaderResourceClient::didAppendData(const CSSStyleSheetResource* resource) |
| +{ |
| + const String& chunk = resource->decodedText(); |
|
kouhei (in TOK)
2016/04/21 06:35:03
Sorry, I was surprised to know that decodedText()
kouhei (in TOK)
2016/04/24 22:26:22
Hmm, thinking this over again, TextResource::decod
Charlie Harrison
2016/04/25 15:14:34
Ack. Thanks for looking into this.
|
| + if (!chunk.isNull() && m_preloader) { |
| + CSSPreloadScanner cssPreloadScanner; |
| + PreloadRequestStream preloads; |
| + // TODO(csharrison): Should SegmentedString be populated? |
| + cssPreloadScanner.scan(chunk, SegmentedString(), preloads, resource->response().url()); |
| + int currentPreloadCount = m_preloader->countPreloads(); |
| + m_preloader->takeAndPreload(preloads); |
| + DEFINE_STATIC_LOCAL(CustomCountHistogram, cssImportHistogram, ("CSSPreloaderResourceClient.PreloadCount", 1, 100, 50)); |
| + cssImportHistogram.count(m_preloader->countPreloads() - currentPreloadCount); |
| + } |
| + m_resource->removeClient(this); |
| +} |
| + |
| } // namespace blink |