Use enum class in createMarkup arguments
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Sep 2018 04:22:50 +0000 (04:22 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 28 Sep 2018 04:22:50 +0000 (04:22 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190028

Reviewed by Wenson Hsieh.

Source/WebCore:

Replaced enums used by createMarkup with equivalent enum classes: EChildrenOnly with SerializedNodes,
EAbsoluteURLs with ResolveURLs, and EFragmentSerialization with SerializationSyntax.

Also replaced the boolean convertBlocksToInlines with an enum class of the same name.

Finally, renamed the createMarkup variant which doesn't serialize style and used for innerHTML and XMLSerializer
to serializeFragment.

* dom/Element.cpp:
(WebCore::Element::innerHTML const):
(WebCore::Element::outerHTML const):
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::innerHTML const):
* editing/CompositeEditCommand.cpp:
(WebCore::CompositeEditCommand::moveParagraphs):
* editing/HTMLInterchange.h:
(WebCore::AnnotateForInterchange): Renamed from EAnnotateForInterchange.
* editing/MarkupAccumulator.cpp:
(WebCore::MarkupAccumulator::MarkupAccumulator):
(WebCore::MarkupAccumulator::serializeNodes):
(WebCore::MarkupAccumulator::serializeNodesWithNamespaces):
(WebCore::MarkupAccumulator::resolveURLIfNeeded const):
* editing/MarkupAccumulator.h:
(WebCore::MarkupAccumulator::inXMLFragmentSerialization const):
* editing/ReplaceRangeWithTextCommand.cpp:
(WebCore::ReplaceRangeWithTextCommand::inputEventDataTransfer const):
* editing/ReplaceSelectionCommand.cpp:
(WebCore::ReplaceSelectionCommand::willApplyCommand):
* editing/SpellingCorrectionCommand.cpp:
(WebCore::SpellingCorrectionCommand::inputEventDataTransfer const):
* editing/cocoa/EditorCocoa.mm:
(WebCore::Editor::selectionInHTMLFormat):
* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::WebContentMarkupReader::readRTFD):
(WebCore::WebContentMarkupReader::readRTF):
* editing/gtk/EditorGtk.cpp:
(WebCore::Editor::writeImageToPasteboard):
(WebCore::Editor::writeSelectionToPasteboard):
* editing/markup.cpp:
(WebCore::StyledMarkupAccumulator::StyledMarkupAccumulator):
(WebCore::StyledMarkupAccumulator::serializeNodes):
(WebCore::StyledMarkupAccumulator::traverseNodesForSerialization):
(WebCore::highestAncestorToWrapMarkup):
(WebCore::createMarkupInternal):
(WebCore::createMarkup):
(WebCore::sanitizedMarkupForFragmentInDocument):
(WebCore::serializeFragment): Renamed from createMarkup. This is used for innerHTML and XMLSerializer,
which faithfully serializes the fragment without any computed style as inline styles.
(WebCore::documentTypeString):
(WebCore::createFullMarkup): Deleted two varinats used in WebKitLegacy.
* editing/markup.h:
(WebCore::ResolveURLs): Renamed from EAbsoluteURLs.
(WebCore::ConvertBlocksToInlines): Added.
(WebCore::SerializedNodes): Renamed from EChildrenOnly.
(WebCore::SerializationSyntax): Renamed from EFragmentSerialization.
* editing/wpe/EditorWPE.cpp:
(WebCore::Editor::writeSelectionToPasteboard):
* inspector/DOMEditor.cpp:
* inspector/agents/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::getOuterHTML):
* loader/archive/cf/LegacyWebArchive.cpp:
(WebCore::LegacyWebArchive::create):
(WebCore::LegacyWebArchive::createFromSelection):
* page/PageSerializer.cpp:
(WebCore::PageSerializer::SerializerMarkupAccumulator::SerializerMarkupAccumulator):
(WebCore::PageSerializer::serializeFrame):
* page/win/DragControllerWin.cpp:
(WebCore::DragController::declareAndWriteDragImage):
* Source/WebCore/platform/win/PasteboardWin.cpp:
(WebCore::Pasteboard::writeRangeToDataObject):
(WebCore::Pasteboard::writeSelection):
* xml/XMLHttpRequest.cpp:
(WebCore::XMLHttpRequest::send):
* xml/XMLSerializer.cpp:
(WebCore::XMLSerializer::serializeToString):
* xml/XSLTProcessorLibxslt.cpp:
(WebCore::xsltStylesheetPointer):
(WebCore::xmlDocPtrFromNode):

Source/WebKit:

* WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
(WebKit::WebEditorClient::updateGlobalSelection):

Source/WebKitLegacy/mac:

* DOM/WebDOMOperations.mm:
(-[DOMNode markupString]): Moved the code from WebCore/editing/markup.cpp
(-[DOMRange markupString]): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@236583 268f45cc-cd09-0410-ab3c-d52691b4dbfc

29 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/ShadowRoot.cpp
Source/WebCore/editing/CompositeEditCommand.cpp
Source/WebCore/editing/HTMLInterchange.h
Source/WebCore/editing/MarkupAccumulator.cpp
Source/WebCore/editing/MarkupAccumulator.h
Source/WebCore/editing/ReplaceRangeWithTextCommand.cpp
Source/WebCore/editing/ReplaceSelectionCommand.cpp
Source/WebCore/editing/SpellingCorrectionCommand.cpp
Source/WebCore/editing/cocoa/EditorCocoa.mm
Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
Source/WebCore/editing/gtk/EditorGtk.cpp
Source/WebCore/editing/markup.cpp
Source/WebCore/editing/markup.h
Source/WebCore/editing/wpe/EditorWPE.cpp
Source/WebCore/inspector/DOMEditor.cpp
Source/WebCore/inspector/agents/InspectorDOMAgent.cpp
Source/WebCore/loader/archive/cf/LegacyWebArchive.cpp
Source/WebCore/page/PageSerializer.cpp
Source/WebCore/page/win/DragControllerWin.cpp
Source/WebCore/platform/win/PasteboardWin.cpp
Source/WebCore/xml/XMLHttpRequest.cpp
Source/WebCore/xml/XMLSerializer.cpp
Source/WebCore/xml/XSLTProcessorLibxslt.cpp
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/DOM/WebDOMOperations.mm

index 653b43b..1e7af03 100644 (file)
@@ -1,3 +1,89 @@
+2018-09-26  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Use enum class in createMarkup arguments
+        https://bugs.webkit.org/show_bug.cgi?id=190028
+
+        Reviewed by Wenson Hsieh.
+
+        Replaced enums used by createMarkup with equivalent enum classes: EChildrenOnly with SerializedNodes,
+        EAbsoluteURLs with ResolveURLs, and EFragmentSerialization with SerializationSyntax.
+
+        Also replaced the boolean convertBlocksToInlines with an enum class of the same name.
+
+        Finally, renamed the createMarkup variant which doesn't serialize style and used for innerHTML and XMLSerializer
+        to serializeFragment.
+
+        * dom/Element.cpp:
+        (WebCore::Element::innerHTML const):
+        (WebCore::Element::outerHTML const):
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::innerHTML const):
+        * editing/CompositeEditCommand.cpp:
+        (WebCore::CompositeEditCommand::moveParagraphs):
+        * editing/HTMLInterchange.h:
+        (WebCore::AnnotateForInterchange): Renamed from EAnnotateForInterchange.
+        * editing/MarkupAccumulator.cpp:
+        (WebCore::MarkupAccumulator::MarkupAccumulator):
+        (WebCore::MarkupAccumulator::serializeNodes):
+        (WebCore::MarkupAccumulator::serializeNodesWithNamespaces):
+        (WebCore::MarkupAccumulator::resolveURLIfNeeded const):
+        * editing/MarkupAccumulator.h:
+        (WebCore::MarkupAccumulator::inXMLFragmentSerialization const):
+        * editing/ReplaceRangeWithTextCommand.cpp:
+        (WebCore::ReplaceRangeWithTextCommand::inputEventDataTransfer const):
+        * editing/ReplaceSelectionCommand.cpp:
+        (WebCore::ReplaceSelectionCommand::willApplyCommand):
+        * editing/SpellingCorrectionCommand.cpp:
+        (WebCore::SpellingCorrectionCommand::inputEventDataTransfer const):
+        * editing/cocoa/EditorCocoa.mm:
+        (WebCore::Editor::selectionInHTMLFormat):
+        * editing/cocoa/WebContentReaderCocoa.mm:
+        (WebCore::WebContentMarkupReader::readRTFD):
+        (WebCore::WebContentMarkupReader::readRTF):
+        * editing/gtk/EditorGtk.cpp:
+        (WebCore::Editor::writeImageToPasteboard):
+        (WebCore::Editor::writeSelectionToPasteboard):
+        * editing/markup.cpp:
+        (WebCore::StyledMarkupAccumulator::StyledMarkupAccumulator):
+        (WebCore::StyledMarkupAccumulator::serializeNodes):
+        (WebCore::StyledMarkupAccumulator::traverseNodesForSerialization):
+        (WebCore::highestAncestorToWrapMarkup):
+        (WebCore::createMarkupInternal):
+        (WebCore::createMarkup):
+        (WebCore::sanitizedMarkupForFragmentInDocument):
+        (WebCore::serializeFragment): Renamed from createMarkup. This is used for innerHTML and XMLSerializer,
+        which faithfully serializes the fragment without any computed style as inline styles.
+        (WebCore::documentTypeString):
+        (WebCore::createFullMarkup): Deleted two varinats used in WebKitLegacy.
+        * editing/markup.h:
+        (WebCore::ResolveURLs): Renamed from EAbsoluteURLs.
+        (WebCore::ConvertBlocksToInlines): Added.
+        (WebCore::SerializedNodes): Renamed from EChildrenOnly.
+        (WebCore::SerializationSyntax): Renamed from EFragmentSerialization.
+        * editing/wpe/EditorWPE.cpp:
+        (WebCore::Editor::writeSelectionToPasteboard):
+        * inspector/DOMEditor.cpp:
+        * inspector/agents/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::getOuterHTML):
+        * loader/archive/cf/LegacyWebArchive.cpp:
+        (WebCore::LegacyWebArchive::create):
+        (WebCore::LegacyWebArchive::createFromSelection):
+        * page/PageSerializer.cpp:
+        (WebCore::PageSerializer::SerializerMarkupAccumulator::SerializerMarkupAccumulator):
+        (WebCore::PageSerializer::serializeFrame):
+        * page/win/DragControllerWin.cpp:
+        (WebCore::DragController::declareAndWriteDragImage):
+        * Source/WebCore/platform/win/PasteboardWin.cpp:
+        (WebCore::Pasteboard::writeRangeToDataObject):
+        (WebCore::Pasteboard::writeSelection):
+        * xml/XMLHttpRequest.cpp:
+        (WebCore::XMLHttpRequest::send):
+        * xml/XMLSerializer.cpp:
+        (WebCore::XMLSerializer::serializeToString):
+        * xml/XSLTProcessorLibxslt.cpp:
+        (WebCore::xsltStylesheetPointer):
+        (WebCore::xmlDocPtrFromNode):
+
 2018-09-27  John Wilander  <wilander@apple.com>
 
         Resource Load Statistics: Non-redirected top frame navigation should not get captured in statistics
index 9fed0cf..d91fe43 100644 (file)
@@ -2777,12 +2777,12 @@ ExceptionOr<void> Element::mergeWithNextTextNode(Text& node)
 
 String Element::innerHTML() const
 {
-    return createMarkup(*this, ChildrenOnly);
+    return serializeFragment(*this, SerializedNodes::SubtreesOfChildren);
 }
 
 String Element::outerHTML() const
 {
-    return createMarkup(*this);
+    return serializeFragment(*this, SerializedNodes::SubtreeIncludingNode);
 }
 
 ExceptionOr<void> Element::setOuterHTML(const String& html)
index b0af8fe..e44e6b2 100644 (file)
@@ -153,7 +153,7 @@ Style::Scope& ShadowRoot::styleScope()
 
 String ShadowRoot::innerHTML() const
 {
-    return createMarkup(*this, ChildrenOnly);
+    return serializeFragment(*this, SerializedNodes::SubtreesOfChildren);
 }
 
 ExceptionOr<void> ShadowRoot::setInnerHTML(const String& markup)
index e5f3392..6b14c2a 100644 (file)
@@ -1444,7 +1444,7 @@ void CompositeEditCommand::moveParagraphs(const VisiblePosition& startOfParagrap
     RefPtr<DocumentFragment> fragment;
     // This used to use a ternary for initialization, but that confused some versions of GCC, see bug 37912
     if (startOfParagraphToMove != endOfParagraphToMove)
-        fragment = createFragmentFromMarkup(document(), createMarkup(*range, 0, DoNotAnnotateForInterchange, true), emptyString());
+        fragment = createFragmentFromMarkup(document(), createMarkup(*range, nullptr, AnnotateForInterchange::No, ConvertBlocksToInlines::Yes), emptyString());
 
     // A non-empty paragraph's style is moved when we copy and move it.  We don't move 
     // anything if we're given an empty paragraph, but an empty paragraph can have style
index 05e690b..d4c505c 100644 (file)
@@ -38,7 +38,10 @@ class Text;
 #define AppleTabSpanClass         "Apple-tab-span"
 #define WebKitMSOListQuirksStyle  "WebKit-mso-list-quirks-style"
 
-enum EAnnotateForInterchange { DoNotAnnotateForInterchange, AnnotateForInterchange };
+// Controls whether a special BR which is removed upon paste in ReplaceSelectionCommand needs to be inserted
+// and making sequence of spaces not collapsible by inserting non-breaking spaces.
+// See https://trac.webkit.org/r8087 and https://trac.webkit.org/r8096.
+enum class AnnotateForInterchange : uint8_t { No, Yes };
 
 String convertHTMLTextToInterchangeFormat(const String&, const Text*);
 
index b3c95e4..09942b7 100644 (file)
@@ -116,24 +116,24 @@ void MarkupAccumulator::appendCharactersReplacingEntities(StringBuilder& result,
         appendCharactersReplacingEntitiesInternal<UChar>(result, source, offset, length, entityMask);
 }
 
-MarkupAccumulator::MarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs resolveUrlsMethod, const Range* range, EFragmentSerialization fragmentSerialization)
+MarkupAccumulator::MarkupAccumulator(Vector<Node*>* nodes, ResolveURLs resolveURLs, const Range* range, SerializationSyntax serializationSyntax)
     : m_nodes(nodes)
     , m_range(range)
-    , m_resolveURLsMethod(resolveUrlsMethod)
-    , m_fragmentSerialization(fragmentSerialization)
+    , m_resolveURLs(resolveURLs)
+    , m_serializationSyntax(serializationSyntax)
     , m_prefixLevel(0)
 {
 }
 
 MarkupAccumulator::~MarkupAccumulator() = default;
 
-String MarkupAccumulator::serializeNodes(Node& targetNode, EChildrenOnly childrenOnly, Vector<QualifiedName>* tagNamesToSkip)
+String MarkupAccumulator::serializeNodes(Node& targetNode, SerializedNodes root, Vector<QualifiedName>* tagNamesToSkip)
 {
-    serializeNodesWithNamespaces(targetNode, childrenOnly, 0, tagNamesToSkip);
+    serializeNodesWithNamespaces(targetNode, root, 0, tagNamesToSkip);
     return m_markup.toString();
 }
 
-void MarkupAccumulator::serializeNodesWithNamespaces(Node& targetNode, EChildrenOnly childrenOnly, const Namespaces* namespaces, Vector<QualifiedName>* tagNamesToSkip)
+void MarkupAccumulator::serializeNodesWithNamespaces(Node& targetNode, SerializedNodes root, const Namespaces* namespaces, Vector<QualifiedName>* tagNamesToSkip)
 {
     if (tagNamesToSkip && is<Element>(targetNode)) {
         for (auto& name : *tagNamesToSkip) {
@@ -151,7 +151,7 @@ void MarkupAccumulator::serializeNodesWithNamespaces(Node& targetNode, EChildren
         namespaceHash.set(XMLNames::xmlNamespaceURI->impl(), xmlAtom().impl());
     }
 
-    if (!childrenOnly)
+    if (root == SerializedNodes::SubtreeIncludingNode)
         appendStartTag(targetNode, &namespaceHash);
 
     if (targetNode.document().isHTMLDocument() && elementCannotHaveEndTag(targetNode))
@@ -159,24 +159,24 @@ void MarkupAccumulator::serializeNodesWithNamespaces(Node& targetNode, EChildren
 
     Node* current = targetNode.hasTagName(templateTag) ? downcast<HTMLTemplateElement>(targetNode).content().firstChild() : targetNode.firstChild();
     for ( ; current; current = current->nextSibling())
-        serializeNodesWithNamespaces(*current, IncludeNode, &namespaceHash, tagNamesToSkip);
+        serializeNodesWithNamespaces(*current, SerializedNodes::SubtreeIncludingNode, &namespaceHash, tagNamesToSkip);
 
-    if (!childrenOnly)
+    if (root == SerializedNodes::SubtreeIncludingNode)
         appendEndTag(targetNode);
 }
 
 String MarkupAccumulator::resolveURLIfNeeded(const Element& element, const String& urlString) const
 {
-    switch (m_resolveURLsMethod) {
-    case ResolveAllURLs:
+    switch (m_resolveURLs) {
+    case ResolveURLs::Yes:
         return element.document().completeURL(urlString).string();
 
-    case ResolveNonLocalURLs:
+    case ResolveURLs::YesExcludingLocalFileURLsForPrivacy:
         if (!element.document().url().isLocalFile())
             return element.document().completeURL(urlString).string();
         break;
 
-    case DoNotResolveURLs:
+    case ResolveURLs::No:
         break;
     }
     return urlString;
index 2e263eb..bee8681 100644 (file)
@@ -59,10 +59,10 @@ enum EntityMask {
 // FIXME: Noncopyable?
 class MarkupAccumulator {
 public:
-    MarkupAccumulator(Vector<Node*>*, EAbsoluteURLs, const Range* = nullptr, EFragmentSerialization = HTMLFragmentSerialization);
+    MarkupAccumulator(Vector<Node*>*, ResolveURLs, const Range* = nullptr, SerializationSyntax = SerializationSyntax::HTML);
     virtual ~MarkupAccumulator();
 
-    String serializeNodes(Node& targetNode, EChildrenOnly, Vector<QualifiedName>* tagNamesToSkip = nullptr);
+    String serializeNodes(Node& targetNode, SerializedNodes, Vector<QualifiedName>* tagNamesToSkip = nullptr);
 
     static void appendCharactersReplacingEntities(StringBuilder&, const String&, unsigned, unsigned, EntityMask);
 
@@ -114,13 +114,13 @@ protected:
 private:
     String resolveURLIfNeeded(const Element&, const String&) const;
     void appendQuotedURLAttributeValue(StringBuilder&, const Element&, const Attribute&);
-    void serializeNodesWithNamespaces(Node& targetNode, EChildrenOnly, const Namespaces*, Vector<QualifiedName>* tagNamesToSkip);
-    bool inXMLFragmentSerialization() const { return m_fragmentSerialization == XMLFragmentSerialization; }
+    void serializeNodesWithNamespaces(Node& targetNode, SerializedNodes, const Namespaces*, Vector<QualifiedName>* tagNamesToSkip);
+    bool inXMLFragmentSerialization() const { return m_serializationSyntax == SerializationSyntax::XML; }
     void generateUniquePrefix(QualifiedName&, const Namespaces&);
 
     StringBuilder m_markup;
-    const EAbsoluteURLs m_resolveURLsMethod;
-    EFragmentSerialization m_fragmentSerialization;
+    const ResolveURLs m_resolveURLs;
+    SerializationSyntax m_serializationSyntax;
     unsigned m_prefixLevel;
 };
 
index 73a8ce3..502bc04 100644 (file)
@@ -82,7 +82,7 @@ String ReplaceRangeWithTextCommand::inputEventData() const
 RefPtr<DataTransfer> ReplaceRangeWithTextCommand::inputEventDataTransfer() const
 {
     if (!isEditingTextAreaOrTextInput())
-        return DataTransfer::createForInputEvent(m_text, createMarkup(*m_textFragment));
+        return DataTransfer::createForInputEvent(m_text, serializeFragment(*m_textFragment, SerializedNodes::SubtreeIncludingNode));
 
     return CompositeEditCommand::inputEventDataTransfer();
 }
index 125eb3e..4804e90 100644 (file)
@@ -921,7 +921,7 @@ bool ReplaceSelectionCommand::willApplyCommand()
 {
     ensureReplacementFragment();
     m_documentFragmentPlainText = m_documentFragment->textContent();
-    m_documentFragmentHTMLMarkup = createMarkup(*m_documentFragment);
+    m_documentFragmentHTMLMarkup = serializeFragment(*m_documentFragment, SerializedNodes::SubtreeIncludingNode);
     return CompositeEditCommand::willApplyCommand();
 }
 
index 870d445..c109db0 100644 (file)
@@ -131,7 +131,7 @@ Vector<RefPtr<StaticRange>> SpellingCorrectionCommand::targetRanges() const
 RefPtr<DataTransfer> SpellingCorrectionCommand::inputEventDataTransfer() const
 {
     if (!isEditingTextAreaOrTextInput())
-        return DataTransfer::createForInputEvent(m_correction, createMarkup(*m_correctionFragment));
+        return DataTransfer::createForInputEvent(m_correction, serializeFragment(*m_correctionFragment, SerializedNodes::SubtreeIncludingNode));
 
     return CompositeEditCommand::inputEventDataTransfer();
 }
index 85065c8..ed0d232 100644 (file)
@@ -76,7 +76,7 @@ static RefPtr<SharedBuffer> archivedDataForAttributedString(NSAttributedString *
 String Editor::selectionInHTMLFormat()
 {
     if (auto range = selectedRange())
-        return createMarkup(*range, nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
+        return createMarkup(*range, nullptr, AnnotateForInterchange::Yes, ConvertBlocksToInlines::No, ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
     return { };
 }
 
index e885084..c5a88f3 100644 (file)
@@ -629,7 +629,7 @@ bool WebContentMarkupReader::readRTFD(SharedBuffer& buffer)
     if (!fragment)
         return false;
 
-    markup = createMarkup(*fragment);
+    markup = serializeFragment(*fragment, SerializedNodes::SubtreeIncludingNode);
     return true;
 }
 
@@ -655,7 +655,7 @@ bool WebContentMarkupReader::readRTF(SharedBuffer& buffer)
     auto fragment = createFragmentAndAddResources(frame, string.get());
     if (!fragment)
         return false;
-    markup = createMarkup(*fragment);
+    markup = serializeFragment(*fragment, SerializedNodes::SubtreeIncludingNode);
     return true;
 }
 
index 890bde6..6efd7e8 100644 (file)
@@ -137,7 +137,7 @@ void Editor::writeImageToPasteboard(Pasteboard& pasteboard, Element& imageElemen
 
     pasteboardImage.url.url = imageElement.document().completeURL(stripLeadingAndTrailingHTMLSpaces(elementURL(imageElement)));
     pasteboardImage.url.title = title;
-    pasteboardImage.url.markup = createMarkup(imageElement, IncludeNode, nullptr, ResolveAllURLs);
+    pasteboardImage.url.markup = serializeFragment(imageElement, SerializedNodes::SubtreeIncludingNode, nullptr, ResolveURLs::Yes);
     pasteboard.write(pasteboardImage);
 }
 
@@ -146,7 +146,7 @@ void Editor::writeSelectionToPasteboard(Pasteboard& pasteboard)
     PasteboardWebContent pasteboardContent;
     pasteboardContent.canSmartCopyOrDelete = canSmartCopyOrDelete();
     pasteboardContent.text = selectedTextForDataTransfer();
-    pasteboardContent.markup = createMarkup(*selectedRange(), nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
+    pasteboardContent.markup = createMarkup(*selectedRange(), nullptr, AnnotateForInterchange::Yes, ConvertBlocksToInlines::No, ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
     pasteboard.write(pasteboardContent);
 }
 
index 7f4afe3..594d785 100644 (file)
@@ -219,7 +219,7 @@ class StyledMarkupAccumulator final : public MarkupAccumulator {
 public:
     enum RangeFullySelectsNode { DoesFullySelectNode, DoesNotFullySelectNode };
 
-    StyledMarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs, EAnnotateForInterchange, MSOListMode, const Range*, bool needsPositionStyleConversion, Node* highestNodeToBeSerialized = nullptr);
+    StyledMarkupAccumulator(Vector<Node*>* nodes, ResolveURLs, AnnotateForInterchange, MSOListMode, const Range*, bool needsPositionStyleConversion, Node* highestNodeToBeSerialized = nullptr);
 
     Node* serializeNodes(Node* startNode, Node* pastEnd);
     void wrapWithNode(Node&, bool convertBlocksToInlines = false, RangeFullySelectsNode = DoesFullySelectNode);
@@ -249,14 +249,14 @@ private:
         appendElement(out, element, false, DoesFullySelectNode);
     }
 
-    enum NodeTraversalMode { EmitString, DoNotEmitString };
+    enum class NodeTraversalMode { EmitString, DoNotEmitString };
     Node* traverseNodesForSerialization(Node* startNode, Node* pastEnd, NodeTraversalMode);
 
     bool appendNodeToPreserveMSOList(Node&);
 
     bool shouldAnnotate()
     {
-        return m_shouldAnnotate == AnnotateForInterchange;
+        return m_annotate == AnnotateForInterchange::Yes;
     }
 
     bool shouldApplyWrappingStyle(const Node& node) const
@@ -265,7 +265,7 @@ private:
     }
 
     Vector<String> m_reversedPrecedingMarkup;
-    const EAnnotateForInterchange m_shouldAnnotate;
+    const AnnotateForInterchange m_annotate;
     Node* m_highestNodeToBeSerialized;
     RefPtr<EditingStyle> m_wrappingStyle;
     bool m_needRelativeStyleWrapper;
@@ -275,9 +275,9 @@ private:
     bool m_inMSOList { false };
 };
 
-inline StyledMarkupAccumulator::StyledMarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs shouldResolveURLs, EAnnotateForInterchange shouldAnnotate, MSOListMode msoListMode, const Range* range, bool needsPositionStyleConversion, Node* highestNodeToBeSerialized)
-    : MarkupAccumulator(nodes, shouldResolveURLs, range)
-    , m_shouldAnnotate(shouldAnnotate)
+inline StyledMarkupAccumulator::StyledMarkupAccumulator(Vector<Node*>* nodes, ResolveURLs urlsToResolve, AnnotateForInterchange annotate, MSOListMode msoListMode, const Range* range, bool needsPositionStyleConversion, Node* highestNodeToBeSerialized)
+    : MarkupAccumulator(nodes, urlsToResolve, range)
+    , m_annotate(annotate)
     , m_highestNodeToBeSerialized(highestNodeToBeSerialized)
     , m_needRelativeStyleWrapper(false)
     , m_needsPositionStyleConversion(needsPositionStyleConversion)
@@ -505,19 +505,19 @@ void StyledMarkupAccumulator::appendElement(StringBuilder& out, const Element& e
 Node* StyledMarkupAccumulator::serializeNodes(Node* startNode, Node* pastEnd)
 {
     if (!m_highestNodeToBeSerialized) {
-        Node* lastClosed = traverseNodesForSerialization(startNode, pastEnd, DoNotEmitString);
+        Node* lastClosed = traverseNodesForSerialization(startNode, pastEnd, NodeTraversalMode::DoNotEmitString);
         m_highestNodeToBeSerialized = lastClosed;
     }
 
     if (m_highestNodeToBeSerialized && m_highestNodeToBeSerialized->parentNode())
         m_wrappingStyle = EditingStyle::wrappingStyleForSerialization(*m_highestNodeToBeSerialized->parentNode(), shouldAnnotate());
 
-    return traverseNodesForSerialization(startNode, pastEnd, EmitString);
+    return traverseNodesForSerialization(startNode, pastEnd, NodeTraversalMode::EmitString);
 }
 
 Node* StyledMarkupAccumulator::traverseNodesForSerialization(Node* startNode, Node* pastEnd, NodeTraversalMode traversalMode)
 {
-    const bool shouldEmit = traversalMode == EmitString;
+    const bool shouldEmit = traversalMode == NodeTraversalMode::EmitString;
     Vector<Node*> ancestorsToClose;
     Node* next;
     Node* lastClosed = nullptr;
@@ -530,7 +530,7 @@ Node* StyledMarkupAccumulator::traverseNodesForSerialization(Node* startNode, No
         ASSERT(n);
         if (!n)
             break;
-        
+
         next = NodeTraversal::next(*n);
         bool openedTag = false;
 
@@ -703,12 +703,12 @@ static bool isElementPresentational(const Node* node)
         || node->hasTagName(iTag) || node->hasTagName(emTag) || node->hasTagName(bTag) || node->hasTagName(strongTag);
 }
 
-static Node* highestAncestorToWrapMarkup(const Range* range, EAnnotateForInterchange shouldAnnotate)
+static Node* highestAncestorToWrapMarkup(const Range* range, AnnotateForInterchange annotate)
 {
     auto* commonAncestor = range->commonAncestorContainer();
     ASSERT(commonAncestor);
     Node* specialCommonAncestor = nullptr;
-    if (shouldAnnotate == AnnotateForInterchange) {
+    if (annotate == AnnotateForInterchange::Yes) {
         // Include ancestors that aren't completely inside the range but are required to retain 
         // the structure and appearance of the copied markup.
         specialCommonAncestor = ancestorToRetainStructureAndAppearance(commonAncestor);
@@ -748,10 +748,10 @@ static Node* highestAncestorToWrapMarkup(const Range* range, EAnnotateForInterch
     return specialCommonAncestor;
 }
 
-// FIXME: Shouldn't we omit style info when annotate == DoNotAnnotateForInterchange? 
+// FIXME: Shouldn't we omit style info when annotate == AnnotateForInterchange::No?
 // FIXME: At least, annotation and style info should probably not be included in range.markupString()
 static String createMarkupInternal(Document& document, const Range& range, Vector<Node*>* nodes,
-    EAnnotateForInterchange shouldAnnotate, bool convertBlocksToInlines, EAbsoluteURLs shouldResolveURLs, MSOListMode msoListMode)
+    AnnotateForInterchange annotate, ConvertBlocksToInlines convertBlocksToInlines, ResolveURLs urlsToResolve, MSOListMode msoListMode)
 {
     static NeverDestroyed<const String> interchangeNewlineString(MAKE_STATIC_STRING_IMPL("<br class=\"" AppleInterchangeNewline "\">"));
 
@@ -770,17 +770,17 @@ static String createMarkupInternal(Document& document, const Range& range, Vecto
     if (body && VisiblePosition(firstPositionInNode(body)) == VisiblePosition(range.startPosition())
         && VisiblePosition(lastPositionInNode(body)) == VisiblePosition(range.endPosition()))
         fullySelectedRoot = body;
-    Node* specialCommonAncestor = highestAncestorToWrapMarkup(&range, shouldAnnotate);
+    Node* specialCommonAncestor = highestAncestorToWrapMarkup(&range, annotate);
 
     bool needsPositionStyleConversion = body && fullySelectedRoot == body
         && document.settings().shouldConvertPositionStyleOnCopy();
-    StyledMarkupAccumulator accumulator(nodes, shouldResolveURLs, shouldAnnotate, msoListMode, &range, needsPositionStyleConversion, specialCommonAncestor);
+    StyledMarkupAccumulator accumulator(nodes, urlsToResolve, annotate, msoListMode, &range, needsPositionStyleConversion, specialCommonAncestor);
     Node* pastEnd = range.pastLastNode();
 
     Node* startNode = range.firstNode();
     VisiblePosition visibleStart(range.startPosition(), VP_DEFAULT_AFFINITY);
     VisiblePosition visibleEnd(range.endPosition(), VP_DEFAULT_AFFINITY);
-    if (shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAfter(visibleStart)) {
+    if (annotate == AnnotateForInterchange::Yes && needInterchangeNewlineAfter(visibleStart)) {
         if (visibleStart == visibleEnd.previous())
             return interchangeNewlineString;
 
@@ -796,7 +796,7 @@ static String createMarkupInternal(Document& document, const Range& range, Vecto
     if (specialCommonAncestor && lastClosed) {
         // Also include all of the ancestors of lastClosed up to this special ancestor.
         for (ContainerNode* ancestor = lastClosed->parentNode(); ancestor; ancestor = ancestor->parentNode()) {
-            if (ancestor == fullySelectedRoot && !convertBlocksToInlines) {
+            if (ancestor == fullySelectedRoot && convertBlocksToInlines == ConvertBlocksToInlines::No) {
                 RefPtr<EditingStyle> fullySelectedRootStyle = styleFromMatchedRulesAndInlineDecl(*fullySelectedRoot);
 
                 // Bring the background attribute over, but not as an attribute because a background attribute on a div
@@ -818,7 +818,7 @@ static String createMarkupInternal(Document& document, const Range& range, Vecto
             } else {
                 // Since this node and all the other ancestors are not in the selection we want to set RangeFullySelectsNode to DoesNotFullySelectNode
                 // so that styles that affect the exterior of the node are not included.
-                accumulator.wrapWithNode(*ancestor, convertBlocksToInlines, StyledMarkupAccumulator::DoesNotFullySelectNode);
+                accumulator.wrapWithNode(*ancestor, convertBlocksToInlines == ConvertBlocksToInlines::Yes, StyledMarkupAccumulator::DoesNotFullySelectNode);
             }
             if (nodes)
                 nodes->append(ancestor);
@@ -837,15 +837,15 @@ static String createMarkupInternal(Document& document, const Range& range, Vecto
     }
 
     // FIXME: The interchange newline should be placed in the block that it's in, not after all of the content, unconditionally.
-    if (shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAfter(visibleEnd.previous()))
+    if (annotate == AnnotateForInterchange::Yes && needInterchangeNewlineAfter(visibleEnd.previous()))
         accumulator.appendString(interchangeNewlineString);
 
     return accumulator.takeResults();
 }
 
-String createMarkup(const Range& range, Vector<Node*>* nodes, EAnnotateForInterchange shouldAnnotate, bool convertBlocksToInlines, EAbsoluteURLs shouldResolveURLs)
+String createMarkup(const Range& range, Vector<Node*>* nodes, AnnotateForInterchange annotate, ConvertBlocksToInlines convertBlocksToInlines, ResolveURLs urlsToReslve)
 {
-    return createMarkupInternal(range.ownerDocument(), range, nodes, shouldAnnotate, convertBlocksToInlines, shouldResolveURLs, MSOListMode::DoNotPreserve);
+    return createMarkupInternal(range.ownerDocument(), range, nodes, annotate, convertBlocksToInlines, urlsToReslve, MSOListMode::DoNotPreserve);
 }
 
 static bool shouldPreserveMSOLists(const String& markup)
@@ -871,7 +871,7 @@ String sanitizedMarkupForFragmentInDocument(Ref<DocumentFragment>&& fragment, Do
 
     auto range = Range::create(document);
     range->selectNodeContents(*bodyElement);
-    auto result = createMarkupInternal(document, range.get(), nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs, msoListMode);
+    auto result = createMarkupInternal(document, range.get(), nullptr, AnnotateForInterchange::Yes, ConvertBlocksToInlines::No, ResolveURLs::YesExcludingLocalFileURLsForPrivacy, msoListMode);
 
     if (msoListMode == MSOListMode::Preserve) {
         StringBuilder builder;
@@ -947,10 +947,10 @@ Ref<DocumentFragment> createFragmentFromMarkup(Document& document, const String&
     return fragment;
 }
 
-String createMarkup(const Node& node, EChildrenOnly childrenOnly, Vector<Node*>* nodes, EAbsoluteURLs shouldResolveURLs, Vector<QualifiedName>* tagNamesToSkip, EFragmentSerialization fragmentSerialization)
+String serializeFragment(const Node& node, SerializedNodes root, Vector<Node*>* nodes, ResolveURLs urlsToResolve, Vector<QualifiedName>* tagNamesToSkip, SerializationSyntax serializationSyntax)
 {
-    MarkupAccumulator accumulator(nodes, shouldResolveURLs, 0, fragmentSerialization);
-    return accumulator.serializeNodes(const_cast<Node&>(node), childrenOnly, tagNamesToSkip);
+    MarkupAccumulator accumulator(nodes, urlsToResolve, nullptr, serializationSyntax);
+    return accumulator.serializeNodes(const_cast<Node&>(node), root, tagNamesToSkip);
 }
 
 static void fillContainerFromString(ContainerNode& paragraph, const String& string)
@@ -1094,25 +1094,7 @@ String documentTypeString(const Document& document)
     DocumentType* documentType = document.doctype();
     if (!documentType)
         return emptyString();
-    return createMarkup(*documentType);
-}
-
-String createFullMarkup(const Node& node)
-{
-    // FIXME: This is never "for interchange". Is that right?
-    String markupString = createMarkup(node, IncludeNode, 0);
-
-    Node::NodeType nodeType = node.nodeType();
-    if (nodeType != Node::DOCUMENT_NODE && nodeType != Node::DOCUMENT_TYPE_NODE)
-        markupString = documentTypeString(node.document()) + markupString;
-
-    return markupString;
-}
-
-String createFullMarkup(const Range& range)
-{
-    // FIXME: This is always "for interchange". Is that right?
-    return documentTypeString(range.startContainer().document()) + createMarkup(range, 0, AnnotateForInterchange);
+    return serializeFragment(*documentType, SerializedNodes::SubtreeIncludingNode);
 }
 
 String urlToMarkup(const URL& url, const String& title)
index c00c93a..feae1c3 100644 (file)
@@ -55,10 +55,6 @@ std::unique_ptr<Page> createPageForSanitizingWebContent();
 String sanitizeMarkup(const String&, MSOListQuirks = MSOListQuirks::Disabled, std::optional<WTF::Function<void(DocumentFragment&)>> fragmentSanitizer = std::nullopt);
 String sanitizedMarkupForFragmentInDocument(Ref<DocumentFragment>&&, Document&, MSOListQuirks, const String& originalMarkup);
 
-enum EChildrenOnly { IncludeNode, ChildrenOnly };
-enum EAbsoluteURLs { DoNotResolveURLs, ResolveAllURLs, ResolveNonLocalURLs };
-enum EFragmentSerialization { HTMLFragmentSerialization, XMLFragmentSerialization };
-
 WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromText(Range& context, const String& text);
 WEBCORE_EXPORT Ref<DocumentFragment> createFragmentFromMarkup(Document&, const String& markup, const String& baseURL, ParserContentPolicy = AllowScriptingContent);
 ExceptionOr<Ref<DocumentFragment>> createFragmentForInnerOuterHTML(Element&, const String& markup, ParserContentPolicy);
@@ -71,14 +67,17 @@ bool isPlainTextMarkup(Node*);
 // These methods are used by HTMLElement & ShadowRoot to replace the children with respected fragment/text.
 ExceptionOr<void> replaceChildrenWithFragment(ContainerNode&, Ref<DocumentFragment>&&);
 
-String createMarkup(const Range&, Vector<Node*>* = nullptr, EAnnotateForInterchange = DoNotAnnotateForInterchange, bool convertBlocksToInlines = false, EAbsoluteURLs = DoNotResolveURLs);
-String createMarkup(const Node&, EChildrenOnly = IncludeNode, Vector<Node*>* = nullptr, EAbsoluteURLs = DoNotResolveURLs, Vector<QualifiedName>* tagNamesToSkip = nullptr, EFragmentSerialization = HTMLFragmentSerialization);
+enum class ResolveURLs : uint8_t { No, Yes, YesExcludingLocalFileURLsForPrivacy };
+enum class ConvertBlocksToInlines : uint8_t { No, Yes };
+WEBCORE_EXPORT String createMarkup(const Range&, Vector<Node*>* = nullptr, AnnotateForInterchange = AnnotateForInterchange::No, ConvertBlocksToInlines = ConvertBlocksToInlines::No, ResolveURLs = ResolveURLs::No);
 
-WEBCORE_EXPORT String createFullMarkup(const Node&);
-WEBCORE_EXPORT String createFullMarkup(const Range&);
+enum class SerializedNodes : uint8_t { SubtreeIncludingNode, SubtreesOfChildren };
+enum class SerializationSyntax : uint8_t { HTML, XML };
+WEBCORE_EXPORT String serializeFragment(const Node&, SerializedNodes, Vector<Node*>* = nullptr, ResolveURLs = ResolveURLs::No, Vector<QualifiedName>* tagNamesToSkip = nullptr, SerializationSyntax = SerializationSyntax::HTML);
+WEBCORE_EXPORT String serializeFragmentWithDocType(const Node&);
 
 String urlToMarkup(const URL&, const String& title);
 
-String documentTypeString(const Document&);
+WEBCORE_EXPORT String documentTypeString(const Document&);
 
 }
index 60aada9..2a61c2a 100644 (file)
@@ -64,7 +64,7 @@ void Editor::writeSelectionToPasteboard(Pasteboard& pasteboard)
 {
     PasteboardWebContent pasteboardContent;
     pasteboardContent.text = selectedTextForDataTransfer();
-    pasteboardContent.markup = createMarkup(*selectedRange(), nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
+    pasteboardContent.markup = createMarkup(*selectedRange(), nullptr, AnnotateForInterchange::Yes, ConvertBlocksToInlines::No, ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
     pasteboard.write(pasteboardContent);
 }
 
index e0af0fd..4516680 100644 (file)
@@ -212,7 +212,7 @@ public:
 private:
     ExceptionOr<void> perform() final
     {
-        m_oldHTML = createMarkup(m_node.get());
+        m_oldHTML = serializeFragment(m_node.get(), SerializedNodes::SubtreeIncludingNode);
         auto result = DOMPatchSupport { m_domEditor, m_node->document() }.patchNode(m_node, m_html);
         if (result.hasException())
             return result.releaseException();
index af816ad..a8aae0b 100644 (file)
@@ -766,7 +766,7 @@ void InspectorDOMAgent::getOuterHTML(ErrorString& errorString, int nodeId, WTF::
     if (!node)
         return;
 
-    *outerHTML = createMarkup(*node);
+    *outerHTML = serializeFragment(*node, SerializedNodes::SubtreeIncludingNode);
 }
 
 void InspectorDOMAgent::setOuterHTML(ErrorString& errorString, int nodeId, const String& outerHTML)
index 12a30cc..8656093 100644 (file)
@@ -421,7 +421,7 @@ RefPtr<LegacyWebArchive> LegacyWebArchive::create(Node& node, WTF::Function<bool
     }
 
     Vector<Node*> nodeList;
-    String markupString = createMarkup(node, IncludeNode, &nodeList, DoNotResolveURLs, tagNamesToFilter.get());
+    String markupString = serializeFragment(node, SerializedNodes::SubtreeIncludingNode, &nodeList, ResolveURLs::No, tagNamesToFilter.get());
     auto nodeType = node.nodeType();
     if (nodeType != Node::DOCUMENT_NODE && nodeType != Node::DOCUMENT_TYPE_NODE)
         markupString = documentTypeString(node.document()) + markupString;
@@ -460,7 +460,7 @@ RefPtr<LegacyWebArchive> LegacyWebArchive::create(Range* range)
 
     // FIXME: This is always "for interchange". Is that right?
     Vector<Node*> nodeList;
-    String markupString = documentTypeString(document) + createMarkup(*range, &nodeList, AnnotateForInterchange);
+    String markupString = documentTypeString(document) + createMarkup(*range, &nodeList, AnnotateForInterchange::Yes);
     return create(markupString, *frame, nodeList, nullptr);
 }
 
@@ -555,7 +555,7 @@ RefPtr<LegacyWebArchive> LegacyWebArchive::createFromSelection(Frame* frame)
 
     Vector<Node*> nodeList;
     if (auto selectionRange = frame->selection().toNormalizedRange())
-        builder.append(createMarkup(*selectionRange, &nodeList, AnnotateForInterchange));
+        builder.append(createMarkup(*selectionRange, &nodeList, AnnotateForInterchange::Yes));
 
     auto archive = create(builder.toString(), *frame, nodeList, nullptr);
     
index 1d5f8ee..5f0fe76 100644 (file)
@@ -109,7 +109,7 @@ private:
 };
 
 PageSerializer::SerializerMarkupAccumulator::SerializerMarkupAccumulator(PageSerializer& serializer, Document& document, Vector<Node*>* nodes)
-    : MarkupAccumulator(nodes, ResolveAllURLs)
+    : MarkupAccumulator(nodes, ResolveURLs::Yes)
     , m_serializer(serializer)
     , m_document(document)
 {
@@ -198,7 +198,7 @@ void PageSerializer::serializeFrame(Frame* frame)
         // FIXME: iframes used as images trigger this. We should deal with them correctly.
         return;
     }
-    String text = accumulator.serializeNodes(*document->documentElement(), IncludeNode);
+    String text = accumulator.serializeNodes(*document->documentElement(), SerializedNodes::SubtreeIncludingNode);
     m_resources.append({ url, document->suggestedMIMEType(), SharedBuffer::create(textEncoding.encode(text, UnencodableHandling::Entities)) });
     m_resourceURLs.add(url);
 
index 42f6d6b..2d46d6b 100644 (file)
@@ -78,7 +78,7 @@ void DragController::declareAndWriteDragImage(DataTransfer& dataTransfer, Elemen
     // Order is important here for Explorer's sake
     pasteboard.writeURLToWritableDataObject(url, label);
     pasteboard.writeImageToDataObject(element, url);
-    pasteboard.writeMarkup(createMarkup(element, IncludeNode, 0, ResolveAllURLs));
+    pasteboard.writeMarkup(serializeFragment(element, SerializedNodes::SubtreeIncludingNode, nullptr, ResolveURLs::Yes));
 }
 
 }
index 66abe45..37c30d3 100644 (file)
@@ -444,7 +444,7 @@ void Pasteboard::writeRangeToDataObject(Range& selectedRange, Frame& frame)
     medium.tymed = TYMED_HGLOBAL;
 
     Vector<char> data;
-    markupToCFHTML(createMarkup(selectedRange, 0, AnnotateForInterchange),
+    markupToCFHTML(createMarkup(selectedRange, nullptr, AnnotateForInterchange::Yes),
         selectedRange.startContainer().document().url().string(), data);
     medium.hGlobal = createGlobalData(data);
     if (medium.hGlobal && FAILED(m_writableDataObject->SetData(htmlFormat(), &medium, TRUE)))
@@ -469,7 +469,7 @@ void Pasteboard::writeSelection(Range& selectedRange, bool canSmartCopyOrDelete,
     // Put CF_HTML format on the pasteboard 
     if (::OpenClipboard(m_owner)) {
         Vector<char> data;
-        markupToCFHTML(createMarkup(selectedRange, 0, AnnotateForInterchange),
+        markupToCFHTML(createMarkup(selectedRange, nullptr, AnnotateForInterchange::Yes),
             selectedRange.startContainer().document().url().string(), data);
         HGLOBAL cbData = createGlobalData(data);
         if (!::SetClipboardData(HTMLClipboardFormat, cbData))
index 631ba78..4510d21 100644 (file)
@@ -469,7 +469,7 @@ ExceptionOr<void> XMLHttpRequest::send(Document& document)
 
         // FIXME: According to XMLHttpRequest Level 2, this should use the Document.innerHTML algorithm
         // from the HTML5 specification to serialize the document.
-        m_requestEntityBody = FormData::create(UTF8Encoding().encode(createMarkup(document), UnencodableHandling::Entities));
+        m_requestEntityBody = FormData::create(UTF8Encoding().encode(serializeFragment(document, SerializedNodes::SubtreeIncludingNode), UnencodableHandling::Entities));
         if (m_upload)
             m_requestEntityBody->setAlwaysStream(true);
     }
index cb84bf9..79c38dd 100644 (file)
@@ -26,7 +26,7 @@ namespace WebCore {
 
 String XMLSerializer::serializeToString(Node& node)
 {
-    return createMarkup(node, IncludeNode, nullptr, DoNotResolveURLs, nullptr, XMLFragmentSerialization);
+    return serializeFragment(node, SerializedNodes::SubtreeIncludingNode, nullptr, ResolveURLs::No, nullptr, SerializationSyntax::XML);
 }
 
 } // namespace WebCore
index 66ad15f..75aeddf 100644 (file)
@@ -244,7 +244,7 @@ static xsltStylesheetPtr xsltStylesheetPointer(RefPtr<XSLStyleSheet>& cachedStyl
 
         // According to Mozilla documentation, the node must be a Document node, an xsl:stylesheet or xsl:transform element.
         // But we just use text content regardless of node type.
-        cachedStylesheet->parseString(createMarkup(*stylesheetRootNode));
+        cachedStylesheet->parseString(serializeFragment(*stylesheetRootNode, SerializedNodes::SubtreeIncludingNode));
     }
 
     if (!cachedStylesheet || !cachedStylesheet->document())
@@ -262,7 +262,7 @@ static inline xmlDocPtr xmlDocPtrFromNode(Node& sourceNode, bool& shouldDelete)
     if (sourceIsDocument && ownerDocument->transformSource())
         sourceDoc = ownerDocument->transformSource()->platformSource();
     if (!sourceDoc) {
-        sourceDoc = xmlDocPtrForString(ownerDocument->cachedResourceLoader(), createMarkup(sourceNode),
+        sourceDoc = xmlDocPtrForString(ownerDocument->cachedResourceLoader(), serializeFragment(sourceNode, SerializedNodes::SubtreeIncludingNode),
             sourceIsDocument ? ownerDocument->url().string() : String());
         shouldDelete = sourceDoc;
     }
index 267ad70..7c73414 100644 (file)
@@ -1,3 +1,13 @@
+2018-09-26  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Use enum class in createMarkup arguments
+        https://bugs.webkit.org/show_bug.cgi?id=190028
+
+        Reviewed by Wenson Hsieh.
+
+        * WebProcess/WebCoreSupport/gtk/WebEditorClientGtk.cpp:
+        (WebKit::WebEditorClient::updateGlobalSelection):
+
 2018-09-27  John Wilander  <wilander@apple.com>
 
         Resource Load Statistics: Non-redirected top frame navigation should not get captured in statistics
index bcaa211..9b78997 100644 (file)
@@ -126,7 +126,7 @@ void WebEditorClient::updateGlobalSelection(Frame* frame)
     PasteboardWebContent pasteboardContent;
     pasteboardContent.canSmartCopyOrDelete = false;
     pasteboardContent.text = range->text();
-    pasteboardContent.markup = createMarkup(*range, nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
+    pasteboardContent.markup = createMarkup(*range, nullptr, AnnotateForInterchange::Yes, ConvertBlocksToInlines::No, ResolveURLs::YesExcludingLocalFileURLsForPrivacy);
     Pasteboard::createForGlobalSelection()->write(pasteboardContent);
 }
 
index 78104e7..1d5bdf6 100644 (file)
@@ -1,3 +1,14 @@
+2018-09-26  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Use enum class in createMarkup arguments
+        https://bugs.webkit.org/show_bug.cgi?id=190028
+
+        Reviewed by Wenson Hsieh.
+
+        * DOM/WebDOMOperations.mm:
+        (-[DOMNode markupString]): Moved the code from WebCore/editing/markup.cpp
+        (-[DOMRange markupString]): Ditto.
+
 2018-09-27  Antoine Quint  <graouts@apple.com>
 
         [Web Animations] Turn Web Animations with CSS integration on
index add4755..9cf0d25 100644 (file)
@@ -137,7 +137,14 @@ using namespace JSC;
 
 - (NSString *)markupString
 {
-    return createFullMarkup(*core(self));
+    auto& node = *core(self);
+
+    String markupString = serializeFragment(node, SerializedNodes::SubtreeIncludingNode);
+    Node::NodeType nodeType = node.nodeType();
+    if (nodeType != Node::DOCUMENT_NODE && nodeType != Node::DOCUMENT_TYPE_NODE)
+        markupString = documentTypeString(node.document()) + markupString;
+
+    return markupString;
 }
 
 - (NSRect)_renderRect:(bool *)isReplaced
@@ -187,7 +194,8 @@ using namespace JSC;
 
 - (NSString *)markupString
 {
-    return createFullMarkup(*core(self));
+    auto& range = *core(self);
+    return String { documentTypeString(range.startContainer().document()) + createMarkup(range, nullptr, AnnotateForInterchange::Yes) };
 }
 
 @end