From 08164a0e819b347de9b6676296406fa65918df9c Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 24 Oct 2014 11:04:40 -0700 Subject: [PATCH] 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 --- engine/bindings/core/v8/ScriptController.cpp | 4 +- engine/core/core.gni | 2 - engine/core/dom/Document.cpp | 8 +-- engine/core/dom/Document.h | 4 +- engine/core/dom/DocumentFragment.cpp | 4 +- engine/core/dom/DocumentFragment.h | 3 +- engine/core/dom/DocumentParser.h | 4 +- engine/core/dom/Element.cpp | 6 +- engine/core/dom/ParserContentPolicy.h | 51 --------------- engine/core/dom/ScriptableDocumentParser.cpp | 40 ------------ engine/core/dom/ScriptableDocumentParser.h | 64 ------------------- engine/core/dom/StyleElement.cpp | 2 +- engine/core/dom/shadow/ShadowRoot.cpp | 2 +- engine/core/editing/Editor.cpp | 1 - engine/core/editing/markup.cpp | 8 +-- engine/core/editing/markup.h | 5 +- .../core/html/parser/HTMLConstructionSite.cpp | 22 +++---- .../core/html/parser/HTMLConstructionSite.h | 9 +-- .../core/html/parser/HTMLDocumentParser.cpp | 17 +++-- engine/core/html/parser/HTMLDocumentParser.h | 26 ++++---- engine/core/html/parser/HTMLTreeBuilder.cpp | 11 ++-- engine/core/html/parser/HTMLTreeBuilder.h | 12 ++-- engine/core/loader/DocumentWriter.cpp | 2 +- 23 files changed, 68 insertions(+), 239 deletions(-) delete mode 100644 engine/core/dom/ParserContentPolicy.h delete mode 100644 engine/core/dom/ScriptableDocumentParser.cpp delete mode 100644 engine/core/dom/ScriptableDocumentParser.h diff --git a/engine/bindings/core/v8/ScriptController.cpp b/engine/bindings/core/v8/ScriptController.cpp index 09710a9c9..38f1942d6 100644 --- a/engine/bindings/core/v8/ScriptController.cpp +++ b/engine/bindings/core/v8/ScriptController.cpp @@ -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(); diff --git a/engine/core/core.gni b/engine/core/core.gni index 40eba65c1..c23b3f9a7 100644 --- a/engine/core/core.gni +++ b/engine/core/core.gni @@ -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", diff --git a/engine/core/dom/Document.cpp b/engine/core/dom/Document.cpp index 859a8506d..52b868405 100644 --- a/engine/core/dom/Document.cpp +++ b/engine/core/dom/Document.cpp @@ -1449,9 +1449,9 @@ PassRefPtrWillBeRawPtr 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*) { if (!isRenderingReady()) return; - if (ScriptableDocumentParser* parser = scriptableDocumentParser()) + if (HTMLDocumentParser* parser = scriptableDocumentParser()) parser->executeScriptsWaitingForResources(); } @@ -2767,7 +2767,7 @@ void Document::addMessage(PassRefPtrWillBeRawPtr 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()); } diff --git a/engine/core/dom/Document.h b/engine/core/dom/Document.h index 4f5ce5129..11b0a3fcd 100644 --- a/engine/core/dom/Document.h +++ b/engine/core/dom/Document.h @@ -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 createParser(); DocumentParser* parser() const { return m_parser.get(); } - ScriptableDocumentParser* scriptableDocumentParser() const; + HTMLDocumentParser* scriptableDocumentParser() const; enum ReadyState { Loading, diff --git a/engine/core/dom/DocumentFragment.cpp b/engine/core/dom/DocumentFragment.cpp index 3a747faa4..8eb48f85a 100644 --- a/engine/core/dom/DocumentFragment.cpp +++ b/engine/core/dom/DocumentFragment.cpp @@ -68,9 +68,9 @@ PassRefPtrWillBeRawPtr 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 diff --git a/engine/core/dom/DocumentFragment.h b/engine/core/dom/DocumentFragment.h index a256f17a9..83319cec1 100644 --- a/engine/core/dom/DocumentFragment.h +++ b/engine/core/dom/DocumentFragment.h @@ -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 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; } diff --git a/engine/core/dom/DocumentParser.h b/engine/core/dom/DocumentParser.h index f7f4d9dc9..9b0b7658e 100644 --- a/engine/core/dom/DocumentParser.h +++ b/engine/core/dom/DocumentParser.h @@ -32,7 +32,7 @@ namespace blink { class Document; class SegmentedString; -class ScriptableDocumentParser; +class HTMLDocumentParser; class TextResourceDecoder; class DocumentParser : public RefCountedWillBeGarbageCollectedFinalized { @@ -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; } diff --git a/engine/core/dom/Element.cpp b/engine/core/dom/Element.cpp index 7fde14dd4..1123628b2 100644 --- a/engine/core/dom/Element.cpp +++ b/engine/core/dom/Element.cpp @@ -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 fragment = createFragmentForInnerOuterHTML(html, this, AllowScriptingContent, "innerHTML", exceptionState)) { + if (RefPtrWillBeRawPtr 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 prev = previousSibling(); RefPtrWillBeRawPtr next = nextSibling(); - RefPtrWillBeRawPtr fragment = createFragmentForInnerOuterHTML(html, parent.get(), AllowScriptingContent, "outerHTML", exceptionState); + RefPtrWillBeRawPtr fragment = createFragmentForInnerOuterHTML(html, parent.get(), "outerHTML", exceptionState); if (exceptionState.hadException()) return; diff --git a/engine/core/dom/ParserContentPolicy.h b/engine/core/dom/ParserContentPolicy.h deleted file mode 100644 index 2b21a8d8b..000000000 --- a/engine/core/dom/ParserContentPolicy.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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 diff --git a/engine/core/dom/ScriptableDocumentParser.cpp b/engine/core/dom/ScriptableDocumentParser.cpp deleted file mode 100644 index e6fc30296..000000000 --- a/engine/core/dom/ScriptableDocumentParser.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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) -{ -} - -}; diff --git a/engine/core/dom/ScriptableDocumentParser.h b/engine/core/dom/ScriptableDocumentParser.h deleted file mode 100644 index 0d748f1c2..000000000 --- a/engine/core/dom/ScriptableDocumentParser.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 diff --git a/engine/core/dom/StyleElement.cpp b/engine/core/dom/StyleElement.cpp index 739f34fd8..97f9d02d4 100644 --- a/engine/core/dom/StyleElement.cpp +++ b/engine/core/dom/StyleElement.cpp @@ -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" diff --git a/engine/core/dom/shadow/ShadowRoot.cpp b/engine/core/dom/shadow/ShadowRoot.cpp index f1e521687..b6fb2f784 100644 --- a/engine/core/dom/shadow/ShadowRoot.cpp +++ b/engine/core/dom/shadow/ShadowRoot.cpp @@ -115,7 +115,7 @@ void ShadowRoot::setInnerHTML(const String& markup, ExceptionState& exceptionSta return; } - if (RefPtrWillBeRawPtr fragment = createFragmentForInnerOuterHTML(markup, host(), AllowScriptingContent, "innerHTML", exceptionState)) + if (RefPtrWillBeRawPtr fragment = createFragmentForInnerOuterHTML(markup, host(), "innerHTML", exceptionState)) replaceChildrenWithFragment(this, fragment.release(), exceptionState); } diff --git a/engine/core/editing/Editor.cpp b/engine/core/editing/Editor.cpp index 845438aaf..3401c706b 100644 --- a/engine/core/editing/Editor.cpp +++ b/engine/core/editing/Editor.cpp @@ -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" diff --git a/engine/core/editing/markup.cpp b/engine/core/editing/markup.cpp index a04a843a2..44aecb727 100644 --- a/engine/core/editing/markup.cpp +++ b/engine/core/editing/markup.cpp @@ -529,10 +529,10 @@ String createMarkup(const Range* range, WillBeHeapVector createFragmentFromMarkup(Document& document, const String& markup, ParserContentPolicy parserContentPolicy) +PassRefPtrWillBeRawPtr createFragmentFromMarkup(Document& document, const String& markup) { RefPtrWillBeRawPtr 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), childrenOnly, tagNamesToSkip); } -PassRefPtrWillBeRawPtr createFragmentForInnerOuterHTML(const String& markup, Element* contextElement, ParserContentPolicy parserContentPolicy, const char* method, ExceptionState& exceptionState) +PassRefPtrWillBeRawPtr createFragmentForInnerOuterHTML(const String& markup, Element* contextElement, const char* method, ExceptionState& exceptionState) { ASSERT(contextElement); Document& document = isHTMLTemplateElement(*contextElement) ? contextElement->document().ensureTemplateDocument() : contextElement->document(); RefPtrWillBeRawPtr fragment = DocumentFragment::create(document); - fragment->parseHTML(markup, contextElement, parserContentPolicy); + fragment->parseHTML(markup, contextElement); return fragment; } diff --git a/engine/core/editing/markup.h b/engine/core/editing/markup.h index 999f2f24d..a6efe1057 100644 --- a/engine/core/editing/markup.h +++ b/engine/core/editing/markup.h @@ -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 createFragmentFromMarkup(Document&, const String& markup, ParserContentPolicy = AllowScriptingContent); -PassRefPtrWillBeRawPtr createFragmentForInnerOuterHTML(const String&, Element*, ParserContentPolicy, const char* method, ExceptionState&); +PassRefPtrWillBeRawPtr createFragmentFromMarkup(Document&, const String& markup); +PassRefPtrWillBeRawPtr createFragmentForInnerOuterHTML(const String&, Element*, const char* method, ExceptionState&); // These methods are used by HTMLElement & ShadowRoot to replace the // children with respected fragment/text. diff --git a/engine/core/html/parser/HTMLConstructionSite.cpp b/engine/core/html/parser/HTMLConstructionSite.cpp index 882ebcee9..ecf078558 100644 --- a/engine/core/html/parser/HTMLConstructionSite.cpp +++ b/engine/core/html/parser/HTMLConstructionSite.cpp @@ -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 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 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 HTMLConstructionSite::createElement(AtomicHTMLTo { QualifiedName tagName(token->name()); RefPtrWillBeRawPtr element = ownerDocumentForCurrentNode().createElement(tagName, true); - setAttributes(element.get(), token, m_parserContentPolicy); + setAttributes(element.get(), token); return element.release(); } @@ -364,7 +358,7 @@ PassRefPtrWillBeRawPtr HTMLConstructionSite::createHTMLElement(Atom { Document& document = ownerDocumentForCurrentNode(); RefPtrWillBeRawPtr element = HTMLElementFactory::createHTMLElement(token->name(), document, true); - setAttributes(element.get(), token, m_parserContentPolicy); + setAttributes(element.get(), token); return element.release(); } diff --git a/engine/core/html/parser/HTMLConstructionSite.h b/engine/core/html/parser/HTMLConstructionSite.h index c2ae7ec44..fdd81525d 100644 --- a/engine/core/html/parser/HTMLConstructionSite.h +++ b/engine/core/html/parser/HTMLConstructionSite.h @@ -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 diff --git a/engine/core/html/parser/HTMLDocumentParser.cpp b/engine/core/html/parser/HTMLDocumentParser.cpp index ba515826c..c0d782815 100644 --- a/engine/core/html/parser/HTMLDocumentParser.cpp +++ b/engine/core/html/parser/HTMLDocumentParser.cpp @@ -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 parser = HTMLDocumentParser::create(fragment, contextElement, parserContentPolicy); + RefPtrWillBeRawPtr 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. diff --git a/engine/core/html/parser/HTMLDocumentParser.h b/engine/core/html/parser/HTMLDocumentParser.h index 2d996c7df..e6c37742a 100644 --- a/engine/core/html/parser/HTMLDocumentParser.h +++ b/engine/core/html/parser/HTMLDocumentParser.h @@ -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 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 create(DocumentFragment* fragment, Element* contextElement, ParserContentPolicy parserContentPolicy) + static PassRefPtrWillBeRawPtr 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(); diff --git a/engine/core/html/parser/HTMLTreeBuilder.cpp b/engine/core/html/parser/HTMLTreeBuilder.cpp index b654d24b1..a5e7ff64c 100644 --- a/engine/core/html/parser/HTMLTreeBuilder.cpp +++ b/engine/core/html/parser/HTMLTreeBuilder.cpp @@ -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); diff --git a/engine/core/html/parser/HTMLTreeBuilder.h b/engine/core/html/parser/HTMLTreeBuilder.h index 82fa09315..c0d3c1707 100644 --- a/engine/core/html/parser/HTMLTreeBuilder.h +++ b/engine/core/html/parser/HTMLTreeBuilder.h @@ -54,13 +54,13 @@ class HTMLDocumentParser; class HTMLTreeBuilder FINAL : public NoBaseWillBeGarbageCollectedFinalized { WTF_MAKE_NONCOPYABLE(HTMLTreeBuilder); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED; public: - static PassOwnPtrWillBeRawPtr create(HTMLDocumentParser* parser, HTMLDocument* document, ParserContentPolicy parserContentPolicy, bool reportErrors, const HTMLParserOptions& options) + static PassOwnPtrWillBeRawPtr 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 create(HTMLDocumentParser* parser, DocumentFragment* fragment, Element* contextElement, ParserContentPolicy parserContentPolicy, const HTMLParserOptions& options) + static PassOwnPtrWillBeRawPtr 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*); diff --git a/engine/core/loader/DocumentWriter.cpp b/engine/core/loader/DocumentWriter.cpp index fb970709d..eca812c64 100644 --- a/engine/core/loader/DocumentWriter.cpp +++ b/engine/core/loader/DocumentWriter.cpp @@ -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 { -- GitLab