diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/html/parser/HTMLDocumentParser.h | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/html/parser/HTMLDocumentParser.h')
-rw-r--r-- | Source/WebCore/html/parser/HTMLDocumentParser.h | 140 |
1 files changed, 67 insertions, 73 deletions
diff --git a/Source/WebCore/html/parser/HTMLDocumentParser.h b/Source/WebCore/html/parser/HTMLDocumentParser.h index 89d44960d..9a79d44c4 100644 --- a/Source/WebCore/html/parser/HTMLDocumentParser.h +++ b/Source/WebCore/html/parser/HTMLDocumentParser.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 Google, Inc. All Rights Reserved. + * Copyright (C) 2015 Apple Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,111 +24,89 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef HTMLDocumentParser_h -#define HTMLDocumentParser_h +#pragma once -#include "CachedResourceClient.h" -#include "FragmentScriptingPermission.h" #include "HTMLInputStream.h" -#include "HTMLParserOptions.h" -#include "HTMLPreloadScanner.h" #include "HTMLScriptRunnerHost.h" #include "HTMLSourceTracker.h" -#include "HTMLToken.h" #include "HTMLTokenizer.h" +#include "PendingScriptClient.h" #include "ScriptableDocumentParser.h" -#include "SegmentedString.h" #include "XSSAuditor.h" #include "XSSAuditorDelegate.h" -#include <wtf/Deque.h> -#include <wtf/WeakPtr.h> -#include <wtf/text/TextPosition.h> namespace WebCore { -class BackgroundHTMLParser; -class CompactHTMLToken; -class Document; class DocumentFragment; +class Element; class HTMLDocument; class HTMLParserScheduler; +class HTMLPreloadScanner; class HTMLScriptRunner; class HTMLTreeBuilder; class HTMLResourcePreloader; -class ScriptController; -class ScriptSourceCode; - class PumpSession; -class HTMLDocumentParser : public ScriptableDocumentParser, HTMLScriptRunnerHost, CachedResourceClient { +class HTMLDocumentParser : public ScriptableDocumentParser, private HTMLScriptRunnerHost, private PendingScriptClient { WTF_MAKE_FAST_ALLOCATED; public: - static PassRefPtr<HTMLDocumentParser> create(HTMLDocument& document) - { - return adoptRef(new HTMLDocumentParser(document)); - } + static Ref<HTMLDocumentParser> create(HTMLDocument&); virtual ~HTMLDocumentParser(); - // Exposed for HTMLParserScheduler - void resumeParsingAfterYield(); - - static void parseDocumentFragment(const String&, DocumentFragment&, Element* contextElement, ParserContentPolicy = AllowScriptingContent); - - HTMLTokenizer* tokenizer() const { return m_tokenizer.get(); } + static void parseDocumentFragment(const String&, DocumentFragment&, Element& contextElement, ParserContentPolicy = AllowScriptingContent); - virtual TextPosition textPosition() const override; + // For HTMLParserScheduler. + void resumeParsingAfterYield(); - virtual void suspendScheduledTasks() override; - virtual void resumeScheduledTasks() override; + // For HTMLTreeBuilder. + HTMLTokenizer& tokenizer(); + TextPosition textPosition() const final; protected: - virtual void insert(const SegmentedString&) override; - virtual void append(PassRefPtr<StringImpl>) override; - virtual void finish() override; - explicit HTMLDocumentParser(HTMLDocument&); - HTMLDocumentParser(DocumentFragment&, Element* contextElement, ParserContentPolicy); - HTMLTreeBuilder* treeBuilder() const { return m_treeBuilder.get(); } + void insert(SegmentedString&&) final; + void append(RefPtr<StringImpl>&&) override; + void finish() override; - void forcePlaintextForTextDocument(); + HTMLTreeBuilder& treeBuilder(); private: - static PassRefPtr<HTMLDocumentParser> create(DocumentFragment& fragment, Element* contextElement, ParserContentPolicy parserContentPolicy) - { - return adoptRef(new HTMLDocumentParser(fragment, contextElement, parserContentPolicy)); - } + HTMLDocumentParser(DocumentFragment&, Element& contextElement, ParserContentPolicy); + static Ref<HTMLDocumentParser> create(DocumentFragment&, Element& contextElement, ParserContentPolicy); // DocumentParser - virtual void detach() override; - virtual bool hasInsertionPoint() override; - virtual bool processingData() const override; - virtual void prepareToStopParsing() override; - virtual void stopParsing() override; - virtual bool isWaitingForScripts() const override; - virtual bool isExecutingScript() const override; - virtual void executeScriptsWaitingForStylesheets() override; + void detach() final; + bool hasInsertionPoint() final; + bool processingData() const final; + void prepareToStopParsing() final; + void stopParsing() final; + bool isWaitingForScripts() const override; + bool isExecutingScript() const final; + bool hasScriptsWaitingForStylesheets() const final; + void executeScriptsWaitingForStylesheets() final; + void suspendScheduledTasks() final; + void resumeScheduledTasks() final; + + bool shouldAssociateConsoleMessagesWithTextPosition() const final; // HTMLScriptRunnerHost - virtual void watchForLoad(CachedResource*) override; - virtual void stopWatchingForLoad(CachedResource*) override; - virtual HTMLInputStream& inputStream() override { return m_input; } - virtual bool hasPreloadScanner() const override { return m_preloadScanner.get(); } - virtual void appendCurrentInputStreamToPreloadScannerAndScan() override; + void watchForLoad(PendingScript&) final; + void stopWatchingForLoad(PendingScript&) final; + HTMLInputStream& inputStream() final; + bool hasPreloadScanner() const final; + void appendCurrentInputStreamToPreloadScannerAndScan() final; - // CachedResourceClient - virtual void notifyFinished(CachedResource*) override; + // PendingScriptClient + void notifyFinished(PendingScript&) final; Document* contextForParsingSession(); - enum SynchronousMode { - AllowYield, - ForceSynchronous, - }; - bool canTakeNextToken(SynchronousMode, PumpSession&); + enum SynchronousMode { AllowYield, ForceSynchronous }; void pumpTokenizer(SynchronousMode); + bool pumpTokenizerLoop(SynchronousMode, bool parsingFragment, PumpSession&); void pumpTokenizerIfPossible(SynchronousMode); - void constructTreeFromHTMLToken(HTMLToken&); + void constructTreeFromHTMLToken(HTMLTokenizer::TokenPtr&); void runScriptsForPausedTreeBuilder(); void resumeParsingAfterScriptExecution(); @@ -139,16 +118,13 @@ private: bool isParsingFragment() const; bool isScheduledForResume() const; - bool inPumpSession() const { return m_pumpSessionNestingLevel > 0; } - bool shouldDelayEnd() const { return inPumpSession() || isWaitingForScripts() || isScheduledForResume() || isExecutingScript(); } - - HTMLToken& token() { return *m_token.get(); } + bool inPumpSession() const; + bool shouldDelayEnd() const; HTMLParserOptions m_options; HTMLInputStream m_input; - std::unique_ptr<HTMLToken> m_token; - std::unique_ptr<HTMLTokenizer> m_tokenizer; + HTMLTokenizer m_tokenizer; std::unique_ptr<HTMLScriptRunner> m_scriptRunner; std::unique_ptr<HTMLTreeBuilder> m_treeBuilder; std::unique_ptr<HTMLPreloadScanner> m_preloadScanner; @@ -161,11 +137,29 @@ private: std::unique_ptr<HTMLResourcePreloader> m_preloader; - bool m_endWasDelayed; - bool m_haveBackgroundParser; - unsigned m_pumpSessionNestingLevel; + bool m_endWasDelayed { false }; + unsigned m_pumpSessionNestingLevel { 0 }; }; +inline HTMLTokenizer& HTMLDocumentParser::tokenizer() +{ + return m_tokenizer; +} + +inline HTMLInputStream& HTMLDocumentParser::inputStream() +{ + return m_input; +} + +inline bool HTMLDocumentParser::hasPreloadScanner() const +{ + return m_preloadScanner.get(); +} + +inline HTMLTreeBuilder& HTMLDocumentParser::treeBuilder() +{ + ASSERT(m_treeBuilder); + return *m_treeBuilder; } -#endif +} // namespace WebCore |