HTMLPreloadScanner.h [plain text]
#ifndef HTMLPreloadScanner_h
#define HTMLPreloadScanner_h
#include "CSSPreloadScanner.h"
#include "HTMLToken.h"
#include "SegmentedString.h"
#include <wtf/Vector.h>
namespace WebCore {
typedef size_t TokenPreloadScannerCheckpoint;
class HTMLParserOptions;
class HTMLTokenizer;
class SegmentedString;
class Frame;
class TokenPreloadScanner {
WTF_MAKE_NONCOPYABLE(TokenPreloadScanner); WTF_MAKE_FAST_ALLOCATED;
public:
explicit TokenPreloadScanner(const URL& documentURL, float deviceScaleFactor = 1.0);
~TokenPreloadScanner();
void scan(const HTMLToken&, PreloadRequestStream& requests
#if ENABLE_PICTURE_SIZES
, RenderView*, Frame*
#endif
);
void setPredictedBaseElementURL(const URL& url) { m_predictedBaseElementURL = url; }
TokenPreloadScannerCheckpoint createCheckpoint();
void rewindTo(TokenPreloadScannerCheckpoint);
bool isSafeToSendToAnotherThread()
{
return m_documentURL.isSafeToSendToAnotherThread()
&& m_predictedBaseElementURL.isSafeToSendToAnotherThread();
}
private:
enum class TagId {
Img,
Input,
Link,
Script,
Unknown,
Style,
Base,
Template,
};
class StartTagScanner;
static TagId tagIdFor(const HTMLToken::DataVector&);
static String initiatorFor(TagId);
template<typename Token>
void updatePredictedBaseURL(const Token&);
struct Checkpoint {
Checkpoint(const URL& predictedBaseElementURL, bool inStyle
#if ENABLE(TEMPLATE_ELEMENT)
, size_t templateCount
#endif
)
: predictedBaseElementURL(predictedBaseElementURL)
, inStyle(inStyle)
#if ENABLE(TEMPLATE_ELEMENT)
, templateCount(templateCount)
#endif
{
}
URL predictedBaseElementURL;
bool inStyle;
#if ENABLE(TEMPLATE_ELEMENT)
size_t templateCount;
#endif
};
CSSPreloadScanner m_cssScanner;
const URL m_documentURL;
URL m_predictedBaseElementURL;
bool m_inStyle;
float m_deviceScaleFactor;
#if ENABLE(TEMPLATE_ELEMENT)
size_t m_templateCount;
#endif
Vector<Checkpoint> m_checkpoints;
};
class HTMLPreloadScanner {
WTF_MAKE_NONCOPYABLE(HTMLPreloadScanner); WTF_MAKE_FAST_ALLOCATED;
public:
HTMLPreloadScanner(const HTMLParserOptions&, const URL& documentURL, float deviceScaleFactor = 1.0);
~HTMLPreloadScanner();
void appendToEnd(const SegmentedString&);
void scan(HTMLResourcePreloader*, const URL& documentBaseElementURL
#if ENABLE_PICTURE_SIZES
, RenderView*, Frame*
#endif
);
private:
TokenPreloadScanner m_scanner;
SegmentedString m_source;
HTMLToken m_token;
std::unique_ptr<HTMLTokenizer> m_tokenizer;
};
}
#endif