Chromium Code Reviews| Index: Source/core/html/HTMLLinkElement.cpp |
| diff --git a/Source/core/html/HTMLLinkElement.cpp b/Source/core/html/HTMLLinkElement.cpp |
| index 5b1e253e9ae9ad5a0940b25817d3fca1bca46862..b05a3d082cf0da3abdbd1c5de2647f3faa9fc43a 100644 |
| --- a/Source/core/html/HTMLLinkElement.cpp |
| +++ b/Source/core/html/HTMLLinkElement.cpp |
| @@ -476,6 +476,9 @@ PassOwnPtrWillBeRawPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) |
| LinkStyle::LinkStyle(HTMLLinkElement* owner) |
| : LinkResource(owner) |
| + , m_preloadScanner(adoptPtr(new CSSPreloadScanner)) |
| + , m_preloadInput(adoptPtr(new SegmentedString)) |
| + , m_preloadLength(0) |
| , m_disabledState(Unset) |
| , m_pendingSheetType(None) |
| , m_loading(false) |
| @@ -542,6 +545,34 @@ void LinkStyle::setCSSStyleSheet(const String& href, const KURL& baseURL, const |
| const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleSheet(styleSheet); |
| } |
| +void LinkStyle::dataReceived(const CSSStyleSheetResource* cachedStyleSheet) |
| +{ |
| + if (!m_preloadScanner) |
| + return; |
| + |
| + PreloadRequestStream pendingPreloads; |
| + String sheetText = cachedStyleSheet->sheetText(); |
| + if (sheetText.length() == m_preloadLength) |
| + return; |
| + |
| + m_preloadInput->append(SegmentedString(sheetText.substring(m_preloadLength))); |
| + m_preloadScanner->scan(sheetText.substring(m_preloadLength), *m_preloadInput, pendingPreloads); |
| + m_preloadLength = sheetText.length(); |
|
abarth-chromium
2014/07/31 14:54:23
Why do you call sheetText.substring(m_preloadLengt
jonnyr
2015/01/05 10:34:52
First of all sorry for the delay in following up o
|
| + |
| + 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()) { |