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 0b8fb30bd64ccb2e3673a74f60f4b014c2742a74..1cdeb2137816a9d2d3bf6d7a49233fee3bd689bb 100644 |
--- a/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp |
+++ b/third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp |
@@ -27,8 +27,14 @@ |
#include "core/html/parser/CSSPreloadScanner.h" |
+#include "core/dom/Document.h" |
+#include "core/fetch/CSSStyleSheetResource.h" |
#include "core/fetch/FetchInitiatorTypeNames.h" |
+#include "core/frame/Settings.h" |
#include "core/html/parser/HTMLParserIdioms.h" |
+#include "core/html/parser/HTMLResourcePreloader.h" |
+#include "core/loader/DocumentLoader.h" |
+#include "platform/Histogram.h" |
#include "platform/text/SegmentedString.h" |
#include <memory> |
@@ -234,4 +240,68 @@ void CSSPreloadScanner::emitRule(const SegmentedString& source) |
m_ruleValue.clear(); |
} |
+CSSPreloaderResourceClient::CSSPreloaderResourceClient(Resource* resource, HTMLResourcePreloader* preloader) |
+ : m_preloader(preloader) |
+{ |
+ DCHECK(resource->getType() == Resource::Type::CSSStyleSheet); |
+ setResource(static_cast<CSSStyleSheetResource*>(resource), Resource::DontMarkAsReferenced); |
hiroshige
2016/07/26 09:57:10
We can use toCSSStyleSheetResource() instead of st
Charlie Harrison
2016/07/26 16:31:52
Done.
|
+} |
+ |
+CSSPreloaderResourceClient::~CSSPreloaderResourceClient() |
+{ |
+} |
+ |
+void CSSPreloaderResourceClient::setCSSStyleSheet(const String& href, const KURL& baseURL, const String& charset, const CSSStyleSheetResource*) |
+{ |
+ clearResource(); |
+} |
+ |
+// Only attach for one appendData call, as that's where most imports will likely |
+// be (according to spec). |
+void CSSPreloaderResourceClient::didAppendFirstData(const CSSStyleSheetResource* resource) |
+{ |
+ if (m_preloader) |
+ scanCSS(resource); |
+ clearResource(); |
+} |
+ |
+void CSSPreloaderResourceClient::scanCSS(const CSSStyleSheetResource* resource) |
+{ |
+ DCHECK(m_preloader); |
+ CSSPreloadScanner cssPreloadScanner; |
+ PreloadRequestStream preloads; |
+ // Passing an empty SegmentedString here results in PreloadRequest with no |
+ // file/line information. |
+ // TODO(csharrison): If this becomes an issue the CSSPreloadScanner may be |
+ // augmented to take care of this case without performing an additional |
+ // copy. |
+ const String& chunk = resource->decodedText(); |
+ if (!chunk.isNull()) { |
+ cssPreloadScanner.scan(chunk, SegmentedString(), preloads, resource->response().url()); |
+ } |
+ fetchPreloads(preloads); |
+} |
+ |
+void CSSPreloaderResourceClient::fetchPreloads(PreloadRequestStream& preloads) |
+{ |
+ if (preloads.size()) { |
+ m_preloader->document()->loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoadingBehaviorCSSPreloadFound); |
+ } |
+ |
+ Settings* settings = m_preloader->document()->settings(); |
+ DCHECK(settings); |
+ if (settings->cssExternalScannerPreload()) { |
+ int currentPreloadCount = m_preloader->countPreloads(); |
+ m_preloader->takeAndPreload(preloads); |
+ DEFINE_STATIC_LOCAL(CustomCountHistogram, cssImportHistogram, ("PreloadScanner.ExternalCSS.PreloadCount", 1, 100, 50)); |
+ cssImportHistogram.count(m_preloader->countPreloads() - currentPreloadCount); |
+ } |
+} |
+ |
+DEFINE_TRACE(CSSPreloaderResourceClient) |
+{ |
+ visitor->trace(m_preloader); |
+ ResourceOwner<CSSStyleSheetResource>::trace(visitor); |
+} |
+ |
} // namespace blink |