diff options
Diffstat (limited to 'Source/WebCore/page/PageSerializer.cpp')
| -rw-r--r-- | Source/WebCore/page/PageSerializer.cpp | 96 |
1 files changed, 48 insertions, 48 deletions
diff --git a/Source/WebCore/page/PageSerializer.cpp b/Source/WebCore/page/PageSerializer.cpp index 9766b2655..55eeaa942 100644 --- a/Source/WebCore/page/PageSerializer.cpp +++ b/Source/WebCore/page/PageSerializer.cpp @@ -31,7 +31,6 @@ #include "config.h" #include "PageSerializer.h" -#include "CSSFontFaceRule.h" #include "CSSImageValue.h" #include "CSSImportRule.h" #include "CSSStyleRule.h" @@ -67,10 +66,10 @@ namespace WebCore { static bool isCharsetSpecifyingNode(const Node& node) { - if (!is<HTMLElement>(node)) + if (!node.isHTMLElement()) return false; - const HTMLElement& element = downcast<HTMLElement>(node); + const HTMLElement& element = toHTMLElement(node); if (!element.hasTagName(HTMLNames::metaTag)) return false; HTMLMetaCharsetParser::AttributeList attributes; @@ -92,7 +91,7 @@ static bool shouldIgnoreElement(const Element& element) static const QualifiedName& frameOwnerURLAttributeName(const HTMLFrameOwnerElement& frameOwner) { // FIXME: We should support all frame owners including applets. - return is<HTMLObjectElement>(frameOwner) ? HTMLNames::dataAttr : HTMLNames::srcAttr; + return isHTMLObjectElement(frameOwner) ? HTMLNames::dataAttr : HTMLNames::srcAttr; } class SerializerMarkupAccumulator final : public WebCore::MarkupAccumulator { @@ -107,7 +106,7 @@ private: virtual void appendText(StringBuilder&, const Text&) override; virtual void appendElement(StringBuilder&, const Element&, Namespaces*) override; virtual void appendCustomAttributes(StringBuilder&, const Element&, Namespaces*) override; - virtual void appendEndTag(const Element&) override; + virtual void appendEndTag(const Node&) override; }; SerializerMarkupAccumulator::SerializerMarkupAccumulator(PageSerializer& serializer, Document& document, Vector<Node*>* nodes) @@ -116,7 +115,7 @@ SerializerMarkupAccumulator::SerializerMarkupAccumulator(PageSerializer& seriali , m_document(document) { // MarkupAccumulator does not serialize the <?xml ... line, so we add it explicitely to ensure the right encoding is specified. - if (m_document.isXMLDocument() || m_document.xmlStandalone()) + if (m_document.isXHTMLDocument() || m_document.xmlStandalone() || m_document.isSVGDocument()) appendString("<?xml version=\"" + m_document.xmlVersion() + "\" encoding=\"" + m_document.charset() + "\"?>"); } @@ -137,9 +136,9 @@ void SerializerMarkupAccumulator::appendElement(StringBuilder& out, const Elemen MarkupAccumulator::appendElement(out, element, namespaces); if (element.hasTagName(HTMLNames::headTag)) { - out.appendLiteral("<meta charset=\""); + out.append("<meta charset=\""); out.append(m_document.charset()); - out.appendLiteral("\">"); + out.append("\">"); } // FIXME: For object (plugins) tags and video tag we could replace them by an image of their current contents. @@ -147,10 +146,10 @@ void SerializerMarkupAccumulator::appendElement(StringBuilder& out, const Elemen void SerializerMarkupAccumulator::appendCustomAttributes(StringBuilder& out, const Element& element, Namespaces* namespaces) { - if (!is<HTMLFrameOwnerElement>(element)) + if (!element.isFrameOwnerElement()) return; - const HTMLFrameOwnerElement& frameOwner = downcast<HTMLFrameOwnerElement>(element); + const HTMLFrameOwnerElement& frameOwner = toHTMLFrameOwnerElement(element); Frame* frame = frameOwner.contentFrame(); if (!frame) return; @@ -164,10 +163,10 @@ void SerializerMarkupAccumulator::appendCustomAttributes(StringBuilder& out, con appendAttribute(out, element, Attribute(frameOwnerURLAttributeName(frameOwner), url.string()), namespaces); } -void SerializerMarkupAccumulator::appendEndTag(const Element& element) +void SerializerMarkupAccumulator::appendEndTag(const Node& node) { - if (!shouldIgnoreElement(element)) - MarkupAccumulator::appendEndTag(element); + if (node.isElementNode() && !shouldIgnoreElement(toElement(node))) + MarkupAccumulator::appendEndTag(node); } PageSerializer::Resource::Resource() @@ -216,34 +215,35 @@ 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); - CString frameHTML = textEncoding.encode(text, EntitiesForUnencodables); + String text = accumulator.serializeNodes(*document->documentElement(), 0, IncludeNode); + CString frameHTML = textEncoding.encode(text.deprecatedCharacters(), text.length(), EntitiesForUnencodables); m_resources->append(Resource(url, document->suggestedMIMEType(), SharedBuffer::create(frameHTML.data(), frameHTML.length()))); m_resourceURLs.add(url); - for (auto& node : nodes) { - if (!is<Element>(*node)) + for (Vector<Node*>::iterator iter = nodes.begin(); iter != nodes.end(); ++iter) { + Node* node = *iter; + if (!node->isElementNode()) continue; - Element& element = downcast<Element>(*node); + Element* element = toElement(node); // We have to process in-line style as it might contain some resources (typically background images). - if (is<StyledElement>(element)) - retrieveResourcesForProperties(downcast<StyledElement>(element).inlineStyle(), document); - - if (is<HTMLImageElement>(element)) { - HTMLImageElement& imageElement = downcast<HTMLImageElement>(element); - URL url = document->completeURL(imageElement.fastGetAttribute(HTMLNames::srcAttr)); - CachedImage* cachedImage = imageElement.cachedImage(); - addImageToResources(cachedImage, imageElement.renderer(), url); - } else if (is<HTMLLinkElement>(element)) { - HTMLLinkElement& linkElement = downcast<HTMLLinkElement>(element); - if (CSSStyleSheet* sheet = linkElement.sheet()) { - URL url = document->completeURL(linkElement.getAttribute(HTMLNames::hrefAttr)); + if (element->isStyledElement()) + retrieveResourcesForProperties(toStyledElement(element)->inlineStyle(), document); + + if (isHTMLImageElement(element)) { + HTMLImageElement* imageElement = toHTMLImageElement(element); + URL url = document->completeURL(imageElement->getAttribute(HTMLNames::srcAttr)); + CachedImage* cachedImage = imageElement->cachedImage(); + addImageToResources(cachedImage, imageElement->renderer(), url); + } else if (element->hasTagName(HTMLNames::linkTag)) { + HTMLLinkElement* linkElement = toHTMLLinkElement(element); + if (CSSStyleSheet* sheet = linkElement->sheet()) { + URL url = document->completeURL(linkElement->getAttribute(HTMLNames::hrefAttr)); serializeCSSStyleSheet(sheet, url); ASSERT(m_resourceURLs.contains(url)); } - } else if (is<HTMLStyleElement>(element)) { - if (CSSStyleSheet* sheet = downcast<HTMLStyleElement>(element).sheet()) + } else if (isHTMLStyleElement(element)) { + if (CSSStyleSheet* sheet = toHTMLStyleElement(element)->sheet()) serializeCSSStyleSheet(sheet, URL()); } } @@ -261,21 +261,21 @@ void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const URL if (!itemText.isEmpty()) { cssText.append(itemText); if (i < styleSheet->length() - 1) - cssText.appendLiteral("\n\n"); + cssText.append("\n\n"); } Document* document = styleSheet->ownerDocument(); // Some rules have resources associated with them that we need to retrieve. - if (is<CSSImportRule>(*rule)) { - CSSImportRule& importRule = downcast<CSSImportRule>(*rule); - URL importURL = document->completeURL(importRule.href()); + if (rule->type() == CSSRule::IMPORT_RULE) { + CSSImportRule* importRule = static_cast<CSSImportRule*>(rule); + URL importURL = document->completeURL(importRule->href()); if (m_resourceURLs.contains(importURL)) continue; - serializeCSSStyleSheet(importRule.styleSheet(), importURL); - } else if (is<CSSFontFaceRule>(*rule)) { + serializeCSSStyleSheet(importRule->styleSheet(), importURL); + } else if (rule->type() == CSSRule::FONT_FACE_RULE) { // FIXME: Add support for font face rule. It is not clear to me at this point if the actual otf/eot file can // be retrieved from the CSSFontFaceRule object. - } else if (is<CSSStyleRule>(*rule)) - retrieveResourcesForRule(downcast<CSSStyleRule>(*rule).styleRule(), document); + } else if (rule->type() == CSSRule::STYLE_RULE) + retrieveResourcesForRule(static_cast<CSSStyleRule*>(rule)->styleRule(), document); } if (url.isValid() && !m_resourceURLs.contains(url)) { @@ -283,7 +283,7 @@ void PageSerializer::serializeCSSStyleSheet(CSSStyleSheet* styleSheet, const URL TextEncoding textEncoding(styleSheet->contents().charset()); ASSERT(textEncoding.isValid()); String textString = cssText.toString(); - CString text = textEncoding.encode(textString, EntitiesForUnencodables); + CString text = textEncoding.encode(textString.deprecatedCharacters(), textString.length(), EntitiesForUnencodables); m_resources->append(Resource(url, String("text/css"), SharedBuffer::create(text.data(), text.length()))); m_resourceURLs.add(url); } @@ -311,9 +311,9 @@ void PageSerializer::addImageToResources(CachedImage* image, RenderElement* imag m_resourceURLs.add(url); } -void PageSerializer::retrieveResourcesForRule(StyleRule& rule, Document* document) +void PageSerializer::retrieveResourcesForRule(StyleRule* rule, Document* document) { - retrieveResourcesForProperties(&rule.properties(), document); + retrieveResourcesForProperties(&rule->properties(), document); } void PageSerializer::retrieveResourcesForProperties(const StyleProperties* styleDeclaration, Document* document) @@ -327,18 +327,18 @@ void PageSerializer::retrieveResourcesForProperties(const StyleProperties* style unsigned propertyCount = styleDeclaration->propertyCount(); for (unsigned i = 0; i < propertyCount; ++i) { RefPtr<CSSValue> cssValue = styleDeclaration->propertyAt(i).value(); - if (!is<CSSImageValue>(*cssValue)) + if (!cssValue->isImageValue()) continue; - StyleImage* styleImage = downcast<CSSImageValue>(*cssValue).cachedOrPendingImage(); + StyleImage* styleImage = toCSSImageValue(cssValue.get())->cachedOrPendingImage(); // Non cached-images are just place-holders and do not contain data. - if (!is<StyleCachedImage>(styleImage)) + if (!styleImage || !styleImage->isCachedImage()) continue; - CachedImage* image = downcast<StyleCachedImage>(*styleImage).cachedImage(); + CachedImage* image = static_cast<StyleCachedImage*>(styleImage)->cachedImage(); URL url = document->completeURL(image->url()); - addImageToResources(image, nullptr, url); + addImageToResources(image, 0, url); } } |
