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

Unified Diff: Source/core/html/HTMLLinkElement.cpp

Issue 166633002: Prefetch @import files from CSS files. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed according to comments. Created 6 years, 5 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
« no previous file with comments | « Source/core/html/HTMLLinkElement.h ('k') | Source/core/html/parser/CSSPreloadScanner.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLLinkElement.cpp
diff --git a/Source/core/html/HTMLLinkElement.cpp b/Source/core/html/HTMLLinkElement.cpp
index 5b1e253e9ae9ad5a0940b25817d3fca1bca46862..0f693fb47db4f5a224248607c0d769229cf0ef88 100644
--- a/Source/core/html/HTMLLinkElement.cpp
+++ b/Source/core/html/HTMLLinkElement.cpp
@@ -476,6 +476,8 @@ PassOwnPtrWillBeRawPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner)
LinkStyle::LinkStyle(HTMLLinkElement* owner)
: LinkResource(owner)
+ , m_preloadScanner(adoptPtr(new CSSPreloadScanner))
+ , m_preloadInput(adoptPtr(new SegmentedString))
, m_disabledState(Unset)
, m_pendingSheetType(None)
, m_loading(false)
@@ -542,6 +544,29 @@ void LinkStyle::setCSSStyleSheet(const String& href, const KURL& baseURL, const
const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleSheet(styleSheet);
}
+void LinkStyle::dataReceived(const CSSStyleSheetResource* cachedStyleSheet, const char* data, int length)
+{
+ if (!m_preloadScanner)
+ return;
+
+ PreloadRequestStream pendingPreloads;
+ m_preloadInput->append(SegmentedString(String(data, length)));
abarth-chromium 2014/07/29 16:43:52 How can you take a const char* and make a String o
+ m_preloadScanner->scan(data, *m_preloadInput, pendingPreloads);
+
+ OwnPtr<HTMLResourcePreloader> preloader = HTMLResourcePreloader::create(document());
+ preloader->takeAndPreload(pendingPreloads);
+ if (m_preloadScanner->isDoneParsingImports()) {
+ // Note: Although dataRecieved will be called for each packet of data
+ // returned from the network, @import statements are always at the top
+ // of the CSS file. As soon as we reach a part of the CSS file which
+ // is not an @import we can delete our preloader and ignore the rest of
+ // file. If we ever make CSS preloading more complicated (to look for
+ // URLs other than @imports) we will need to re-think this logic.
+ m_preloadScanner.clear();
+ m_preloadInput.clear();
+ }
+}
+
bool LinkStyle::sheetLoaded()
{
if (!styleSheetIsLoading()) {
« no previous file with comments | « Source/core/html/HTMLLinkElement.h ('k') | Source/core/html/parser/CSSPreloadScanner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698