diff options
Diffstat (limited to 'chromium/third_party/blink/renderer/core/editing/serializers/styled_markup_serializer.cc')
-rw-r--r-- | chromium/third_party/blink/renderer/core/editing/serializers/styled_markup_serializer.cc | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/chromium/third_party/blink/renderer/core/editing/serializers/styled_markup_serializer.cc b/chromium/third_party/blink/renderer/core/editing/serializers/styled_markup_serializer.cc index f7106a6a7c8..e61dc42e5d9 100644 --- a/chromium/third_party/blink/renderer/core/editing/serializers/styled_markup_serializer.cc +++ b/chromium/third_party/blink/renderer/core/editing/serializers/styled_markup_serializer.cc @@ -96,12 +96,14 @@ class StyledMarkupTraverser { private: bool ShouldAnnotate() const; bool ShouldConvertBlocksToInlines() const; + bool IsForMarkupSanitization() const; void AppendStartMarkup(Node&); void AppendEndMarkup(Node&); EditingStyle* CreateInlineStyle(Element&); bool NeedsInlineStyle(const Element&); bool ShouldApplyWrappingStyle(const Node&) const; bool ContainsOnlyBRElement(const Element&) const; + bool ShouldSerializeUnrenderedElement(const Node&) const; StyledMarkupAccumulator* accumulator_; Member<Node> last_closed_; @@ -115,6 +117,11 @@ bool StyledMarkupTraverser<Strategy>::ShouldAnnotate() const { } template <typename Strategy> +bool StyledMarkupTraverser<Strategy>::IsForMarkupSanitization() const { + return accumulator_ && accumulator_->IsForMarkupSanitization(); +} + +template <typename Strategy> bool StyledMarkupTraverser<Strategy>::ShouldConvertBlocksToInlines() const { return accumulator_->ShouldConvertBlocksToInlines(); } @@ -362,10 +369,7 @@ Node* StyledMarkupTraverser<Strategy>::Traverse(Node* start_node, } auto* element = DynamicTo<Element>(n); - if (n->GetLayoutObject() || - (element && element->HasDisplayContentsStyle()) || - EnclosingElementWithTag(FirstPositionInOrBeforeNode(*n), - kSelectTag)) { + if (n->GetLayoutObject() || ShouldSerializeUnrenderedElement(*n)) { // Add the node to the markup if we're not skipping the descendants AppendStartMarkup(*n); @@ -511,6 +515,11 @@ void StyledMarkupTraverser<Strategy>::AppendStartMarkup(Node& node) { // FIXME: Should this be included in forceInline? inline_style->Style()->SetProperty(CSSPropertyID::kFloat, CSSValueID::kNone); + + if (IsForMarkupSanitization()) { + EditingStyleUtilities::StripUAStyleRulesForMarkupSanitization( + inline_style); + } } accumulator_->AppendTextWithInlineStyle(text, inline_style); break; @@ -569,6 +578,9 @@ EditingStyle* StyledMarkupTraverser<Strategy>::CreateInlineStyle( inline_style->MergeStyleFromRulesForSerialization(html_element); } + if (IsForMarkupSanitization()) + EditingStyleUtilities::StripUAStyleRulesForMarkupSanitization(inline_style); + return inline_style; } @@ -581,6 +593,25 @@ bool StyledMarkupTraverser<Strategy>::ContainsOnlyBRElement( return IsHTMLBRElement(first_child) && first_child == element.lastChild(); } +template <typename Strategy> +bool StyledMarkupTraverser<Strategy>::ShouldSerializeUnrenderedElement( + const Node& node) const { + DCHECK(!node.GetLayoutObject()); + if (node.IsElementNode() && To<Element>(node).HasDisplayContentsStyle()) + return true; + if (EnclosingElementWithTag(FirstPositionInOrBeforeNode(node), + html_names::kSelectTag)) { + return true; + } + if (IsForMarkupSanitization()) { + // During sanitization, iframes in the staging document haven't loaded and + // are hence not rendered. They should still be serialized. + if (IsA<HTMLIFrameElement>(node)) + return true; + } + return false; +} + template class StyledMarkupSerializer<EditingStrategy>; template class StyledMarkupSerializer<EditingInFlatTreeStrategy>; |