| Index: Source/core/html/HTMLLinkElement.cpp
|
| diff --git a/Source/core/html/HTMLLinkElement.cpp b/Source/core/html/HTMLLinkElement.cpp
|
| index 6b6d8b195ff4c55adb09468cb5ede4836628fbea..e039960f2479721a6dc1e9b43396b6e3b88d70a8 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,43 @@ void LinkStyle::setCSSStyleSheet(const String& href, const KURL& baseURL, const
|
| const_cast<CSSStyleSheetResource*>(cachedStyleSheet)->saveParsedStyleSheet(styleSheet);
|
| }
|
|
|
| +void LinkStyle::dataReceived(const CSSStyleSheetResource* cachedStyleSheet)
|
| +{
|
| + // An absence of preload scanner means we are done with @import statements.
|
| + if (!m_preloadScanner)
|
| + return;
|
| +
|
| + PreloadRequestStream pendingPreloads;
|
| + String sheetText = cachedStyleSheet->sheetText();
|
| + if (sheetText.length() == m_preloadLength)
|
| + return;
|
| +
|
| + m_input.append(sheetText.substring(m_preloadLength));
|
| +
|
| + while (m_tokenizer->nextToken(m_input.current(), *m_token)) {
|
| + 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()) {
|
|
|