HTMLPreloadScanner.h [plain text]
#ifndef HTMLPreloadScanner_h
#define HTMLPreloadScanner_h
#include "CSSPreloadScanner.h"
#include "HTMLTokenizer.h"
#include "SegmentedString.h"
namespace WebCore {
class TokenPreloadScanner {
WTF_MAKE_NONCOPYABLE(TokenPreloadScanner);
public:
explicit TokenPreloadScanner(const URL& documentURL, float deviceScaleFactor = 1.0);
void scan(const HTMLToken&, PreloadRequestStream&, Document&);
void setPredictedBaseElementURL(const URL& url) { m_predictedBaseElementURL = url; }
bool inPicture() { return !m_pictureSourceState.isEmpty(); }
private:
enum class TagId {
Img,
Input,
Link,
Script,
Meta,
Source,
Unknown,
Style,
Base,
Template,
Picture
};
class StartTagScanner;
static TagId tagIdFor(const HTMLToken::DataVector&);
static String initiatorFor(TagId);
void updatePredictedBaseURL(const HTMLToken&);
CSSPreloadScanner m_cssScanner;
const URL m_documentURL;
const float m_deviceScaleFactor { 1 };
URL m_predictedBaseElementURL;
bool m_inStyle { false };
Vector<bool> m_pictureSourceState;
#if ENABLE(TEMPLATE_ELEMENT)
unsigned m_templateCount { 0 };
#endif
};
class HTMLPreloadScanner {
WTF_MAKE_FAST_ALLOCATED;
public:
HTMLPreloadScanner(const HTMLParserOptions&, const URL& documentURL, float deviceScaleFactor = 1.0);
void appendToEnd(const SegmentedString&);
void scan(HTMLResourcePreloader&, Document&);
private:
TokenPreloadScanner m_scanner;
SegmentedString m_source;
HTMLTokenizer m_tokenizer;
};
WEBCORE_EXPORT bool testPreloadScannerViewportSupport(Document*);
}
#endif