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..532e5a6182ccfec551f3607032fa143d45bf2422 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::didAppendFirstData(const CSSStyleSheetResource* resource) |
| +{ |
| + const String& chunk = resource->decodedText(); |
| + if (!chunk.isNull() && m_preloader) { |
| + CSSPreloadScanner cssPreloadScanner; |
| + PreloadRequestStream preloads; |
| + // TODO(csharrison): Should SegmentedString be populated? |
|
kouhei (in TOK)
2016/04/25 22:10:05
The only caveat of using empty SegmentedString her
Charlie Harrison
2016/04/25 22:29:12
Yeah I know :/ I think leaving it out is okay, bec
|
| + 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 |