提交 08164a0e 编写于 作者: A Adam Barth

Delete ScriptableDocumentParser

There's only one parser: the HTMLDocumentParser. No need for the complex class
hierarchy.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/680583003
上级 001d6302
......@@ -47,7 +47,6 @@
#include "bindings/core/v8/WindowProxy.h"
#include "core/dom/Document.h"
#include "core/dom/Node.h"
#include "core/dom/ScriptableDocumentParser.h"
#include "core/events/Event.h"
#include "core/events/EventListener.h"
#include "core/frame/LocalDOMWindow.h"
......@@ -57,6 +56,7 @@
#include "core/html/HTMLLinkElement.h"
#include "core/html/imports/HTMLImportChild.h"
#include "core/html/imports/HTMLImportLoader.h"
#include "core/html/parser/HTMLDocumentParser.h"
#include "core/inspector/InspectorTraceEvents.h"
#include "core/inspector/ScriptCallStack.h"
#include "core/loader/FrameLoaderClient.h"
......@@ -190,7 +190,7 @@ WindowProxy* ScriptController::windowProxy(DOMWrapperWorld& world)
TextPosition ScriptController::eventHandlerPosition() const
{
ScriptableDocumentParser* parser = m_frame->document()->scriptableDocumentParser();
HTMLDocumentParser* parser = m_frame->document()->scriptableDocumentParser();
if (parser)
return parser->textPosition();
return TextPosition::minimumPosition();
......
......@@ -445,8 +445,6 @@ sky_core_files = [
"dom/RenderTreeBuilder.cpp",
"dom/RenderTreeBuilder.h",
"dom/RequestAnimationFrameCallback.h",
"dom/ScriptableDocumentParser.cpp",
"dom/ScriptableDocumentParser.h",
"dom/ScriptedAnimationController.cpp",
"dom/ScriptedAnimationController.h",
"dom/SelectorQuery.cpp",
......
......@@ -1449,9 +1449,9 @@ PassRefPtrWillBeRawPtr<DocumentParser> Document::createParser()
return HTMLDocumentParser::create(toHTMLDocument(*this), false);
}
ScriptableDocumentParser* Document::scriptableDocumentParser() const
HTMLDocumentParser* Document::scriptableDocumentParser() const
{
return parser() ? parser()->asScriptableDocumentParser() : 0;
return parser() ? parser()->asHTMLDocumentParser() : 0;
}
void Document::detachParser()
......@@ -1743,7 +1743,7 @@ void Document::executeScriptsWaitingForResourcesTimerFired(Timer<Document>*)
{
if (!isRenderingReady())
return;
if (ScriptableDocumentParser* parser = scriptableDocumentParser())
if (HTMLDocumentParser* parser = scriptableDocumentParser())
parser->executeScriptsWaitingForResources();
}
......@@ -2767,7 +2767,7 @@ void Document::addMessage(PassRefPtrWillBeRawPtr<ConsoleMessage> consoleMessage)
if (!consoleMessage->scriptState() && consoleMessage->url().isNull() && !consoleMessage->lineNumber()) {
consoleMessage->setURL(url().string());
if (parsing() && scriptableDocumentParser()) {
ScriptableDocumentParser* parser = scriptableDocumentParser();
HTMLDocumentParser* parser = scriptableDocumentParser();
if (!parser->isWaitingForScripts() && !parser->isExecutingScript())
consoleMessage->setLineNumber(parser->lineNumber().oneBasedInt());
}
......
......@@ -90,6 +90,7 @@ class Frame;
class FrameHost;
class FrameView;
class HTMLCanvasElement;
class HTMLDocumentParser;
class HTMLElement;
class HTMLImport;
class HTMLImportLoader;
......@@ -112,7 +113,6 @@ class RenderView;
class RequestAnimationFrameCallback;
class ResourceFetcher;
class ScriptRunner;
class ScriptableDocumentParser;
class ScriptedAnimationController;
class SegmentedString;
class SelectorQueryCache;
......@@ -367,7 +367,7 @@ public:
virtual PassRefPtrWillBeRawPtr<DocumentParser> createParser();
DocumentParser* parser() const { return m_parser.get(); }
ScriptableDocumentParser* scriptableDocumentParser() const;
HTMLDocumentParser* scriptableDocumentParser() const;
enum ReadyState {
Loading,
......
......@@ -68,9 +68,9 @@ PassRefPtrWillBeRawPtr<Node> DocumentFragment::cloneNode(bool deep)
return clone.release();
}
void DocumentFragment::parseHTML(const String& source, Element* contextElement, ParserContentPolicy parserContentPolicy)
void DocumentFragment::parseHTML(const String& source, Element* contextElement)
{
HTMLDocumentParser::parseDocumentFragment(source, this, contextElement, parserContentPolicy);
HTMLDocumentParser::parseDocumentFragment(source, this, contextElement);
}
} // namespace blink
......@@ -25,7 +25,6 @@
#define DocumentFragment_h
#include "core/dom/ContainerNode.h"
#include "core/dom/ParserContentPolicy.h"
namespace blink {
......@@ -34,7 +33,7 @@ class DocumentFragment : public ContainerNode {
public:
static PassRefPtrWillBeRawPtr<DocumentFragment> create(Document&);
void parseHTML(const String&, Element* contextElement, ParserContentPolicy = AllowScriptingContent);
void parseHTML(const String&, Element* contextElement);
virtual bool canContainRangeEndPoint() const OVERRIDE FINAL { return true; }
virtual bool isTemplateContent() const { return false; }
......
......@@ -32,7 +32,7 @@ namespace blink {
class Document;
class SegmentedString;
class ScriptableDocumentParser;
class HTMLDocumentParser;
class TextResourceDecoder;
class DocumentParser : public RefCountedWillBeGarbageCollectedFinalized<DocumentParser> {
......@@ -40,7 +40,7 @@ public:
virtual ~DocumentParser();
virtual void trace(Visitor*);
virtual ScriptableDocumentParser* asScriptableDocumentParser() { return 0; }
virtual HTMLDocumentParser* asHTMLDocumentParser() { return 0; }
// http://www.whatwg.org/specs/web-apps/current-work/#insertion-point
virtual bool hasInsertionPoint() { return true; }
......
......@@ -52,7 +52,6 @@
#include "core/dom/NamedNodeMap.h"
#include "core/dom/NodeRenderStyle.h"
#include "core/dom/RenderTreeBuilder.h"
#include "core/dom/ScriptableDocumentParser.h"
#include "core/dom/SelectorQuery.h"
#include "core/dom/StyleEngine.h"
#include "core/dom/Text.h"
......@@ -75,6 +74,7 @@
#include "core/html/HTMLDocument.h"
#include "core/html/HTMLElement.h"
#include "core/html/HTMLTemplateElement.h"
#include "core/html/parser/HTMLDocumentParser.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/page/Chrome.h"
#include "core/page/ChromeClient.h"
......@@ -1553,7 +1553,7 @@ String Element::outerHTML() const
void Element::setInnerHTML(const String& html, ExceptionState& exceptionState)
{
if (RefPtrWillBeRawPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, this, AllowScriptingContent, "innerHTML", exceptionState)) {
if (RefPtrWillBeRawPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, this, "innerHTML", exceptionState)) {
ContainerNode* container = this;
if (isHTMLTemplateElement(*this))
container = toHTMLTemplateElement(this)->content();
......@@ -1577,7 +1577,7 @@ void Element::setOuterHTML(const String& html, ExceptionState& exceptionState)
RefPtrWillBeRawPtr<Node> prev = previousSibling();
RefPtrWillBeRawPtr<Node> next = nextSibling();
RefPtrWillBeRawPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, parent.get(), AllowScriptingContent, "outerHTML", exceptionState);
RefPtrWillBeRawPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(html, parent.get(), "outerHTML", exceptionState);
if (exceptionState.hadException())
return;
......
/*
* Copyright (C) 2010 Google, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ParserContentPolicy_h
#define ParserContentPolicy_h
namespace blink {
enum ParserContentPolicy {
DisallowScriptingContent,
AllowScriptingContent,
AllowScriptingContentAndDoNotMarkAlreadyStarted,
};
static inline bool scriptingContentIsAllowed(ParserContentPolicy parserContentPolicy)
{
return parserContentPolicy == AllowScriptingContent || parserContentPolicy == AllowScriptingContentAndDoNotMarkAlreadyStarted;
}
static inline ParserContentPolicy disallowScriptingContent(ParserContentPolicy parserContentPolicy)
{
if (!scriptingContentIsAllowed(parserContentPolicy))
return parserContentPolicy;
return DisallowScriptingContent;
}
} // namespace blink
#endif // ParserContentPolicy_h
/*
* Copyright (C) 2010 Google, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "core/dom/ScriptableDocumentParser.h"
#include "core/dom/Document.h"
#include "core/frame/Settings.h"
namespace blink {
ScriptableDocumentParser::ScriptableDocumentParser(Document& document, ParserContentPolicy parserContentPolicy)
: DecodedDataDocumentParser(document)
, m_parserContentPolicy(parserContentPolicy)
{
}
};
/*
* Copyright (C) 2010 Google, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ScriptableDocumentParser_h
#define ScriptableDocumentParser_h
#include "core/dom/DecodedDataDocumentParser.h"
#include "core/dom/ParserContentPolicy.h"
#include "wtf/text/TextPosition.h"
namespace blink {
class ScriptableDocumentParser : public DecodedDataDocumentParser {
public:
// Only used by Document::open for deciding if its safe to act on a
// JavaScript document.open() call right now, or it should be ignored.
virtual bool isExecutingScript() const { return false; }
// FIXME: Only the HTMLDocumentParser ever blocks script execution on
// stylesheet load, which is likely a bug in the XMLDocumentParser.
virtual void executeScriptsWaitingForResources() { }
virtual bool isWaitingForScripts() const = 0;
// These are used to expose the current line/column to the scripting system.
virtual OrdinalNumber lineNumber() const = 0;
virtual TextPosition textPosition() const = 0;
ParserContentPolicy parserContentPolicy() { return m_parserContentPolicy; }
protected:
explicit ScriptableDocumentParser(Document&, ParserContentPolicy = AllowScriptingContent);
private:
virtual ScriptableDocumentParser* asScriptableDocumentParser() OVERRIDE FINAL { return this; }
ParserContentPolicy m_parserContentPolicy;
};
}
#endif // ScriptableDocumentParser_h
......@@ -27,10 +27,10 @@
#include "core/css/StyleSheetContents.h"
#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/dom/ScriptableDocumentParser.h"
#include "core/dom/StyleEngine.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLStyleElement.h"
#include "core/html/parser/HTMLDocumentParser.h"
#include "platform/TraceEvent.h"
#include "wtf/text/StringBuilder.h"
......
......@@ -115,7 +115,7 @@ void ShadowRoot::setInnerHTML(const String& markup, ExceptionState& exceptionSta
return;
}
if (RefPtrWillBeRawPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, host(), AllowScriptingContent, "innerHTML", exceptionState))
if (RefPtrWillBeRawPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, host(), "innerHTML", exceptionState))
replaceChildrenWithFragment(this, fragment.release(), exceptionState);
}
......
......@@ -35,7 +35,6 @@
#include "core/dom/DocumentFragment.h"
#include "core/dom/DocumentMarkerController.h"
#include "core/dom/NodeTraversal.h"
#include "core/dom/ParserContentPolicy.h"
#include "core/dom/Text.h"
#include "core/editing/DeleteSelectionCommand.h"
#include "core/editing/InputMethodController.h"
......
......@@ -529,10 +529,10 @@ String createMarkup(const Range* range, WillBeHeapVector<RawPtrWillBeMember<Node
return createMarkupInternal(document, range, updatedRange, nodes, shouldAnnotate, convertBlocksToInlines, shouldResolveURLs, constrainingAncestor);
}
PassRefPtrWillBeRawPtr<DocumentFragment> createFragmentFromMarkup(Document& document, const String& markup, ParserContentPolicy parserContentPolicy)
PassRefPtrWillBeRawPtr<DocumentFragment> createFragmentFromMarkup(Document& document, const String& markup)
{
RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(document);
fragment->parseHTML(markup, nullptr, parserContentPolicy);
fragment->parseHTML(markup, nullptr);
return fragment.release();
}
......@@ -545,12 +545,12 @@ String createMarkup(const Node* node, EChildrenOnly childrenOnly, WillBeHeapVect
return accumulator.serializeNodes(const_cast<Node&>(*node), childrenOnly, tagNamesToSkip);
}
PassRefPtrWillBeRawPtr<DocumentFragment> createFragmentForInnerOuterHTML(const String& markup, Element* contextElement, ParserContentPolicy parserContentPolicy, const char* method, ExceptionState& exceptionState)
PassRefPtrWillBeRawPtr<DocumentFragment> createFragmentForInnerOuterHTML(const String& markup, Element* contextElement, const char* method, ExceptionState& exceptionState)
{
ASSERT(contextElement);
Document& document = isHTMLTemplateElement(*contextElement) ? contextElement->document().ensureTemplateDocument() : contextElement->document();
RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(document);
fragment->parseHTML(markup, contextElement, parserContentPolicy);
fragment->parseHTML(markup, contextElement);
return fragment;
}
......
......@@ -26,7 +26,6 @@
#ifndef markup_h
#define markup_h
#include "core/dom/ParserContentPolicy.h"
#include "core/editing/HTMLInterchange.h"
#include "platform/heap/Handle.h"
#include "wtf/Forward.h"
......@@ -47,8 +46,8 @@ class Range;
enum EChildrenOnly { IncludeNode, ChildrenOnly };
enum EAbsoluteURLs { DoNotResolveURLs, ResolveAllURLs, ResolveNonLocalURLs };
PassRefPtrWillBeRawPtr<DocumentFragment> createFragmentFromMarkup(Document&, const String& markup, ParserContentPolicy = AllowScriptingContent);
PassRefPtrWillBeRawPtr<DocumentFragment> createFragmentForInnerOuterHTML(const String&, Element*, ParserContentPolicy, const char* method, ExceptionState&);
PassRefPtrWillBeRawPtr<DocumentFragment> createFragmentFromMarkup(Document&, const String& markup);
PassRefPtrWillBeRawPtr<DocumentFragment> createFragmentForInnerOuterHTML(const String&, Element*, const char* method, ExceptionState&);
// These methods are used by HTMLElement & ShadowRoot to replace the
// children with respected fragment/text.
......
......@@ -46,10 +46,9 @@ namespace blink {
static const unsigned maximumHTMLParserDOMTreeDepth = 512;
static inline void setAttributes(Element* element, AtomicHTMLToken* token, ParserContentPolicy parserContentPolicy)
static inline void setAttributes(Element* element, AtomicHTMLToken* token)
{
if (!scriptingContentIsAllowed(parserContentPolicy))
element->stripScriptingAttributes(token->attributes());
element->stripScriptingAttributes(token->attributes());
element->parserSetAttributes(token->attributes());
}
......@@ -211,8 +210,6 @@ void HTMLConstructionSite::queueTask(const HTMLConstructionSiteTask& task)
void HTMLConstructionSite::attachLater(ContainerNode* parent, PassRefPtrWillBeRawPtr<Node> prpChild, bool selfClosing)
{
ASSERT(scriptingContentIsAllowed(m_parserContentPolicy) || !prpChild.get()->isElementNode());
HTMLConstructionSiteTask task(HTMLConstructionSiteTask::Insert);
task.parent = parent;
task.child = prpChild;
......@@ -245,17 +242,15 @@ void HTMLConstructionSite::executeQueuedTasks()
// We might be detached now.
}
HTMLConstructionSite::HTMLConstructionSite(Document* document, ParserContentPolicy parserContentPolicy)
HTMLConstructionSite::HTMLConstructionSite(Document* document)
: m_document(document)
, m_attachmentRoot(document)
, m_parserContentPolicy(parserContentPolicy)
{
}
HTMLConstructionSite::HTMLConstructionSite(DocumentFragment* fragment, ParserContentPolicy parserContentPolicy)
HTMLConstructionSite::HTMLConstructionSite(DocumentFragment* fragment)
: m_document(&fragment->document())
, m_attachmentRoot(fragment)
, m_parserContentPolicy(parserContentPolicy)
{
}
......@@ -322,9 +317,8 @@ void HTMLConstructionSite::insertSelfClosingHTMLElement(AtomicHTMLToken* token)
void HTMLConstructionSite::insertScriptElement(AtomicHTMLToken* token)
{
RefPtrWillBeRawPtr<HTMLScriptElement> element = HTMLScriptElement::create(ownerDocumentForCurrentNode());
setAttributes(element.get(), token, m_parserContentPolicy);
if (scriptingContentIsAllowed(m_parserContentPolicy))
attachLater(currentNode(), element);
setAttributes(element.get(), token);
attachLater(currentNode(), element);
m_openElements.push(element.release());
}
......@@ -349,7 +343,7 @@ PassRefPtrWillBeRawPtr<Element> HTMLConstructionSite::createElement(AtomicHTMLTo
{
QualifiedName tagName(token->name());
RefPtrWillBeRawPtr<Element> element = ownerDocumentForCurrentNode().createElement(tagName, true);
setAttributes(element.get(), token, m_parserContentPolicy);
setAttributes(element.get(), token);
return element.release();
}
......@@ -364,7 +358,7 @@ PassRefPtrWillBeRawPtr<HTMLElement> HTMLConstructionSite::createHTMLElement(Atom
{
Document& document = ownerDocumentForCurrentNode();
RefPtrWillBeRawPtr<HTMLElement> element = HTMLElementFactory::createHTMLElement(token->name(), document, true);
setAttributes(element.get(), token, m_parserContentPolicy);
setAttributes(element.get(), token);
return element.release();
}
......
......@@ -28,7 +28,6 @@
#define HTMLConstructionSite_h
#include "core/dom/Document.h"
#include "core/dom/ParserContentPolicy.h"
#include "core/html/parser/HTMLElementStack.h"
#include "wtf/Noncopyable.h"
#include "wtf/PassRefPtr.h"
......@@ -88,8 +87,8 @@ class HTMLConstructionSite FINAL {
WTF_MAKE_NONCOPYABLE(HTMLConstructionSite);
DISALLOW_ALLOCATION();
public:
HTMLConstructionSite(Document*, ParserContentPolicy);
HTMLConstructionSite(DocumentFragment*, ParserContentPolicy);
explicit HTMLConstructionSite(Document*);
explicit HTMLConstructionSite(DocumentFragment*);
~HTMLConstructionSite();
void trace(Visitor*);
......@@ -131,8 +130,6 @@ public:
Document& ownerDocumentForCurrentNode();
HTMLElementStack* openElements() const { return &m_openElements; }
ParserContentPolicy parserContentPolicy() { return m_parserContentPolicy; }
private:
// In the common case, this queue will have only one task because most
// tokens produce only one DOM mutation.
......@@ -206,8 +203,6 @@ private:
};
PendingText m_pendingText;
ParserContentPolicy m_parserContentPolicy;
};
} // namespace blink
......
......@@ -63,11 +63,11 @@ static HTMLTokenizer::State tokenizerStateForContextElement(Element* contextElem
}
HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors)
: ScriptableDocumentParser(document)
: DecodedDataDocumentParser(document)
, m_options(&document)
, m_token(m_options.useThreading ? nullptr : adoptPtr(new HTMLToken))
, m_tokenizer(m_options.useThreading ? nullptr : HTMLTokenizer::create(m_options))
, m_treeBuilder(HTMLTreeBuilder::create(this, &document, parserContentPolicy(), reportErrors, m_options))
, m_treeBuilder(HTMLTreeBuilder::create(this, &document, reportErrors, m_options))
, m_parserScheduler(HTMLParserScheduler::create(this))
, m_weakFactory(this)
, m_isFragment(false)
......@@ -80,12 +80,12 @@ HTMLDocumentParser::HTMLDocumentParser(HTMLDocument& document, bool reportErrors
// FIXME: Member variables should be grouped into self-initializing structs to
// minimize code duplication between these constructors.
HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* contextElement, ParserContentPolicy parserContentPolicy)
: ScriptableDocumentParser(fragment->document(), parserContentPolicy)
HTMLDocumentParser::HTMLDocumentParser(DocumentFragment* fragment, Element* contextElement)
: DecodedDataDocumentParser(fragment->document())
, m_options(&fragment->document())
, m_token(adoptPtr(new HTMLToken))
, m_tokenizer(HTMLTokenizer::create(m_options))
, m_treeBuilder(HTMLTreeBuilder::create(this, fragment, contextElement, this->parserContentPolicy(), m_options))
, m_treeBuilder(HTMLTreeBuilder::create(this, fragment, contextElement, m_options))
, m_weakFactory(this)
, m_isFragment(true)
, m_endWasDelayed(false)
......@@ -117,7 +117,7 @@ HTMLDocumentParser::~HTMLDocumentParser()
void HTMLDocumentParser::trace(Visitor* visitor)
{
visitor->trace(m_treeBuilder);
ScriptableDocumentParser::trace(visitor);
DecodedDataDocumentParser::trace(visitor);
}
void HTMLDocumentParser::detach()
......@@ -228,7 +228,6 @@ void HTMLDocumentParser::resumeParsingAfterYield()
void HTMLDocumentParser::runScriptsForPausedTreeBuilder()
{
ASSERT(scriptingContentIsAllowed(parserContentPolicy()));
if (m_isFragment)
return;
TextPosition scriptStartPosition = TextPosition::belowRangePosition();
......@@ -703,9 +702,9 @@ void HTMLDocumentParser::executeScriptsWaitingForResources()
resumeParsingAfterScriptExecution();
}
void HTMLDocumentParser::parseDocumentFragment(const String& source, DocumentFragment* fragment, Element* contextElement, ParserContentPolicy parserContentPolicy)
void HTMLDocumentParser::parseDocumentFragment(const String& source, DocumentFragment* fragment, Element* contextElement)
{
RefPtrWillBeRawPtr<HTMLDocumentParser> parser = HTMLDocumentParser::create(fragment, contextElement, parserContentPolicy);
RefPtrWillBeRawPtr<HTMLDocumentParser> parser = HTMLDocumentParser::create(fragment, contextElement);
parser->insert(source); // Use insert() so that the parser will not yield.
parser->finish();
ASSERT(!parser->processingData()); // Make sure we're done. <rdar://problem/3963151>
......
......@@ -27,8 +27,7 @@
#define HTMLDocumentParser_h
#include "base/memory/weak_ptr.h"
#include "core/dom/ParserContentPolicy.h"
#include "core/dom/ScriptableDocumentParser.h"
#include "core/dom/DecodedDataDocumentParser.h"
#include "core/fetch/ResourceClient.h"
#include "core/frame/UseCounter.h"
#include "core/html/parser/CompactHTMLToken.h"
......@@ -59,7 +58,7 @@ class ScriptSourceCode;
class PumpSession;
class HTMLDocumentParser : public ScriptableDocumentParser {
class HTMLDocumentParser : public DecodedDataDocumentParser {
WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLDocumentParser);
public:
......@@ -73,12 +72,12 @@ public:
// Exposed for HTMLParserScheduler
void resumeParsingAfterYield();
static void parseDocumentFragment(const String&, DocumentFragment*, Element* contextElement, ParserContentPolicy = AllowScriptingContent);
static void parseDocumentFragment(const String&, DocumentFragment*, Element* contextElement);
HTMLTokenizer* tokenizer() const { return m_tokenizer.get(); }
virtual TextPosition textPosition() const OVERRIDE FINAL;
virtual OrdinalNumber lineNumber() const OVERRIDE FINAL;
TextPosition textPosition() const;
OrdinalNumber lineNumber() const;
struct ParsedChunk {
OwnPtr<CompactHTMLTokenStream> tokens;
......@@ -88,6 +87,10 @@ public:
virtual void appendBytes(const char* bytes, size_t length) OVERRIDE;
virtual void flush() OVERRIDE FINAL;
bool isWaitingForScripts() const;
bool isExecutingScript() const;
void executeScriptsWaitingForResources();
UseCounter* useCounter() { return UseCounter::getFrom(contextForParsingSession()); }
protected:
......@@ -96,25 +99,24 @@ protected:
virtual void finish() OVERRIDE FINAL;
HTMLDocumentParser(HTMLDocument&, bool reportErrors);
HTMLDocumentParser(DocumentFragment*, Element* contextElement, ParserContentPolicy);
HTMLDocumentParser(DocumentFragment*, Element* contextElement);
HTMLTreeBuilder* treeBuilder() const { return m_treeBuilder.get(); }
private:
static PassRefPtrWillBeRawPtr<HTMLDocumentParser> create(DocumentFragment* fragment, Element* contextElement, ParserContentPolicy parserContentPolicy)
static PassRefPtrWillBeRawPtr<HTMLDocumentParser> create(DocumentFragment* fragment, Element* contextElement)
{
return adoptRefWillBeNoop(new HTMLDocumentParser(fragment, contextElement, parserContentPolicy));
return adoptRefWillBeNoop(new HTMLDocumentParser(fragment, contextElement));
}
virtual HTMLDocumentParser* asHTMLDocumentParser() OVERRIDE FINAL { return this; }
// DocumentParser
virtual void detach() OVERRIDE FINAL;
virtual bool hasInsertionPoint() OVERRIDE FINAL;
virtual bool processingData() const OVERRIDE FINAL;
virtual void prepareToStopParsing() OVERRIDE FINAL;
virtual void stopParsing() OVERRIDE FINAL;
virtual bool isWaitingForScripts() const OVERRIDE FINAL;
virtual bool isExecutingScript() const OVERRIDE FINAL;
virtual void executeScriptsWaitingForResources() OVERRIDE FINAL;
void startBackgroundParser();
void stopBackgroundParser();
......
......@@ -45,12 +45,12 @@ static TextPosition uninitializedPositionValue1()
return TextPosition(OrdinalNumber::fromOneBasedInt(-1), OrdinalNumber::first());
}
HTMLTreeBuilder::HTMLTreeBuilder(HTMLDocumentParser* parser, HTMLDocument* document, ParserContentPolicy parserContentPolicy, bool, const HTMLParserOptions& options)
HTMLTreeBuilder::HTMLTreeBuilder(HTMLDocumentParser* parser, HTMLDocument* document, bool, const HTMLParserOptions& options)
:
#if ENABLE(ASSERT)
m_isAttached(true),
#endif
m_tree(document, parserContentPolicy)
m_tree(document)
, m_insertionMode(HTMLMode)
, m_originalInsertionMode(HTMLMode)
, m_parser(parser)
......@@ -62,13 +62,13 @@ HTMLTreeBuilder::HTMLTreeBuilder(HTMLDocumentParser* parser, HTMLDocument* docum
// FIXME: Member variables should be grouped into self-initializing structs to
// minimize code duplication between these constructors.
HTMLTreeBuilder::HTMLTreeBuilder(HTMLDocumentParser* parser, DocumentFragment* fragment, Element* contextElement, ParserContentPolicy parserContentPolicy, const HTMLParserOptions& options)
HTMLTreeBuilder::HTMLTreeBuilder(HTMLDocumentParser* parser, DocumentFragment* fragment, Element* contextElement, const HTMLParserOptions& options)
:
#if ENABLE(ASSERT)
m_isAttached(true),
#endif
m_fragmentContext(fragment, contextElement)
, m_tree(fragment, parserContentPolicy)
, m_tree(fragment)
, m_insertionMode(HTMLMode)
, m_originalInsertionMode(HTMLMode)
, m_parser(parser)
......@@ -209,8 +209,7 @@ void HTMLTreeBuilder::processEndTag(AtomicHTMLToken* token)
if (token->name() == HTMLNames::scriptTag) {
// Pause ourselves so that parsing stops until the script can be processed by the caller.
ASSERT(m_tree.currentElement()->hasLocalName(HTMLNames::scriptTag.localName()));
if (scriptingContentIsAllowed(m_tree.parserContentPolicy()))
m_scriptToProcess = m_tree.currentElement();
m_scriptToProcess = m_tree.currentElement();
m_tree.openElements()->pop();
setInsertionMode(m_originalInsertionMode);
......
......@@ -54,13 +54,13 @@ class HTMLDocumentParser;
class HTMLTreeBuilder FINAL : public NoBaseWillBeGarbageCollectedFinalized<HTMLTreeBuilder> {
WTF_MAKE_NONCOPYABLE(HTMLTreeBuilder); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
public:
static PassOwnPtrWillBeRawPtr<HTMLTreeBuilder> create(HTMLDocumentParser* parser, HTMLDocument* document, ParserContentPolicy parserContentPolicy, bool reportErrors, const HTMLParserOptions& options)
static PassOwnPtrWillBeRawPtr<HTMLTreeBuilder> create(HTMLDocumentParser* parser, HTMLDocument* document, bool reportErrors, const HTMLParserOptions& options)
{
return adoptPtrWillBeNoop(new HTMLTreeBuilder(parser, document, parserContentPolicy, reportErrors, options));
return adoptPtrWillBeNoop(new HTMLTreeBuilder(parser, document, reportErrors, options));
}
static PassOwnPtrWillBeRawPtr<HTMLTreeBuilder> create(HTMLDocumentParser* parser, DocumentFragment* fragment, Element* contextElement, ParserContentPolicy parserContentPolicy, const HTMLParserOptions& options)
static PassOwnPtrWillBeRawPtr<HTMLTreeBuilder> create(HTMLDocumentParser* parser, DocumentFragment* fragment, Element* contextElement, const HTMLParserOptions& options)
{
return adoptPtrWillBeNoop(new HTMLTreeBuilder(parser, fragment, contextElement, parserContentPolicy, options));
return adoptPtrWillBeNoop(new HTMLTreeBuilder(parser, fragment, contextElement, options));
}
~HTMLTreeBuilder();
void trace(Visitor*);
......@@ -92,8 +92,8 @@ private:
TextMode,
};
HTMLTreeBuilder(HTMLDocumentParser*, HTMLDocument*, ParserContentPolicy, bool reportErrors, const HTMLParserOptions&);
HTMLTreeBuilder(HTMLDocumentParser*, DocumentFragment*, Element* contextElement, ParserContentPolicy, const HTMLParserOptions&);
HTMLTreeBuilder(HTMLDocumentParser*, HTMLDocument*, bool reportErrors, const HTMLParserOptions&);
HTMLTreeBuilder(HTMLDocumentParser*, DocumentFragment*, Element* contextElement, const HTMLParserOptions&);
void processStartTag(AtomicHTMLToken*);
void processEndTag(AtomicHTMLToken*);
......
......@@ -30,7 +30,7 @@
#include "core/loader/DocumentWriter.h"
#include "core/dom/Document.h"
#include "core/dom/ScriptableDocumentParser.h"
#include "core/dom/DocumentParser.h"
#include "core/frame/LocalFrame.h"
namespace blink {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册