Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Unified Diff: third_party/WebKit/Source/core/html/parser/CSSPreloadScanner.cpp

Issue 1976463003: Preload scan external CSS for @import (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: actually include crasher fix Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 939aa3836a892d4162a09e8d86ce1e8046e7d0b7..b8142f0a950c92f6b800ef1036b0b3490a74af12 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"
namespace blink {
@@ -233,4 +239,71 @@ void CSSPreloadScanner::emitRule(const SegmentedString& source)
m_ruleValue.clear();
}
+CSSPreloaderResourceClient::CSSPreloaderResourceClient(Resource* resource, HTMLResourcePreloader* preloader)
+ : m_resource(resource)
+ , m_preloader(preloader)
+{
+}
+
+CSSPreloaderResourceClient::~CSSPreloaderResourceClient()
hiroshige 2016/06/17 12:15:17 We don't need this destructor if we make CSSPreloa
Charlie Harrison 2016/07/13 18:18:14 Done.
+{
+ clearResource();
+}
+
+void CSSPreloaderResourceClient::notifyFinished(Resource* resource)
+{
+ 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::clearResource()
hiroshige 2016/06/17 12:15:17 We can remove this if we make CSSPreloaderResource
Charlie Harrison 2016/07/13 18:18:14 Done.
+{
+ if (m_resource) {
+ m_resource->removeClient(this);
+ m_resource.clear();
+ }
+}
+
+void CSSPreloaderResourceClient::scanCSS(const CSSStyleSheetResource* resource)
+{
+ DCHECK(m_preloader);
+ Settings* settings = m_preloader->document()->settings();
+ if (!settings)
+ return;
+ if (!settings->cssExternalScannerNoPreload() && !settings->cssExternalScannerPreload()) {
+ return;
+ }
+
+ 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());
+ }
+
+ if (preloads.size()) {
+ m_preloader->document()->loader()->didObserveLoadingBehavior(WebLoadingBehaviorFlag::WebLoadingBehaviorCSSPreloadFound);
+ }
+
+ 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);
+ }
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698