Chromium Code Reviews| Index: Source/core/html/HTMLLinkElement.cpp |
| diff --git a/Source/core/html/HTMLLinkElement.cpp b/Source/core/html/HTMLLinkElement.cpp |
| index 6b6d8b195ff4c55adb09468cb5ede4836628fbea..bb0d0b153108e3c1c7ca1fd253f014f8eaafcd4d 100644 |
| --- a/Source/core/html/HTMLLinkElement.cpp |
| +++ b/Source/core/html/HTMLLinkElement.cpp |
| @@ -46,6 +46,7 @@ |
| #include "core/frame/csp/ContentSecurityPolicy.h" |
| #include "core/html/LinkManifest.h" |
| #include "core/html/imports/LinkImport.h" |
| +#include "core/html/parser/CompactHTMLToken.h" |
| #include "core/loader/FrameLoader.h" |
| #include "core/loader/FrameLoaderClient.h" |
| #include "core/rendering/style/StyleInheritedData.h" |
| @@ -480,12 +481,19 @@ PassOwnPtrWillBeRawPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) |
| LinkStyle::LinkStyle(HTMLLinkElement* owner) |
| : LinkResource(owner) |
| + , m_token(adoptPtr(new HTMLToken)) |
| + , m_tokenizer(HTMLTokenizer::create(m_options)) |
| + , m_preloadScanner(adoptPtr(new CSSPreloadScanner)) |
| + , m_preloadLength(0) |
| , m_disabledState(Unset) |
| , m_pendingSheetType(None) |
| , m_loading(false) |
| , m_firedLoad(false) |
| , m_loadedSheet(false) |
| { |
| + // The tokenizer uses RAWTEXTState to identify the origin of a request. |
| + // This state is also used while handling CSS prefetch in the html parser. |
| + m_tokenizer->setState(HTMLTokenizer::RAWTEXTState); |
| } |
| LinkStyle::~LinkStyle() |
| @@ -554,6 +562,47 @@ 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) |
|
Yoav Weiss
2015/01/05 13:18:44
Maybe a comment saying that the absence of m_prelo
jonnyr
2015/01/06 00:13:06
Done.
|
| + return; |
| + |
| + PreloadRequestStream pendingPreloads; |
| + String sheetText = cachedStyleSheet->sheetText(); |
| + if (sheetText.length() == m_preloadLength) |
| + return; |
| + |
| + m_input.append(sheetText.substring(m_preloadLength)); |
| + |
| + while (true) { |
| + |
|
Yoav Weiss
2015/01/05 13:18:44
Why not merge the if condition into the while loop
jonnyr
2015/01/06 00:13:06
Done.
|
| + if (!m_tokenizer->nextToken(m_input.current(), *m_token)) |
| + break; // We've reached the end of our current input. |
| + |
| + { |
| + CompactHTMLToken token(m_token.get(), TextPosition(m_input.current().currentLine(), m_input.current().currentColumn())); |
| + m_preloadScanner->scan(token.data(), m_input.current(), pendingPreloads); |
| + } |
| + m_token->clear(); |
| + } |
| + |
| + m_preloadLength = sheetText.length(); |
| + |
| + 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_tokenizer.clear(); |
| + m_token.clear(); |
| + } |
| +} |
| + |
| bool LinkStyle::sheetLoaded() |
| { |
| if (!styleSheetIsLoading()) { |