| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 namespace blink { | 71 namespace blink { |
| 72 | 72 |
| 73 static bool isCharsetSpecifyingNode(const Node& node) | 73 static bool isCharsetSpecifyingNode(const Node& node) |
| 74 { | 74 { |
| 75 if (!isHTMLMetaElement(node)) | 75 if (!isHTMLMetaElement(node)) |
| 76 return false; | 76 return false; |
| 77 | 77 |
| 78 const HTMLMetaElement& element = toHTMLMetaElement(node); | 78 const HTMLMetaElement& element = toHTMLMetaElement(node); |
| 79 HTMLAttributeList attributeList; | 79 HTMLAttributeList attributeList; |
| 80 AttributeCollection attributes = element.attributes(); | 80 AttributeCollection attributes = element.attributes(); |
| 81 for (const Attribute& attr : attributes) { | 81 for (const Attribute& attr: attributes) { |
| 82 // FIXME: We should deal appropriately with the attribute if they have a
namespace. | 82 // FIXME: We should deal appropriately with the attribute if they have a
namespace. |
| 83 attributeList.append(std::make_pair(attr.name().localName(), attr.value(
).string())); | 83 attributeList.append(std::make_pair(attr.name().localName(), attr.value(
).string())); |
| 84 } | 84 } |
| 85 WTF::TextEncoding textEncoding = encodingFromMetaAttributes(attributeList); | 85 WTF::TextEncoding textEncoding = encodingFromMetaAttributes(attributeList); |
| 86 return textEncoding.isValid(); | 86 return textEncoding.isValid(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 static bool shouldIgnoreElement(const Element& element) | 89 static bool shouldIgnoreElement(const Element& element) |
| 90 { | 90 { |
| 91 return isHTMLScriptElement(element) || isHTMLNoScriptElement(element) || isC
harsetSpecifyingNode(element); | 91 return isHTMLScriptElement(element) || isHTMLNoScriptElement(element) || isC
harsetSpecifyingNode(element); |
| 92 } | 92 } |
| 93 | 93 |
| 94 static const QualifiedName& frameOwnerURLAttributeName(const HTMLFrameOwnerEleme
nt& frameOwner) | 94 static const QualifiedName& frameOwnerURLAttributeName(const HTMLFrameOwnerEleme
nt& frameOwner) |
| 95 { | 95 { |
| 96 // FIXME: We should support all frame owners including applets. | 96 // FIXME: We should support all frame owners including applets. |
| 97 return isHTMLObjectElement(frameOwner) ? HTMLNames::dataAttr : HTMLNames::sr
cAttr; | 97 return isHTMLObjectElement(frameOwner) ? HTMLNames::dataAttr : HTMLNames::sr
cAttr; |
| 98 } | 98 } |
| 99 | 99 |
| 100 class SerializerMarkupAccumulator final : public MarkupAccumulator { | 100 class SerializerMarkupAccumulator final : public MarkupAccumulator { |
| 101 STACK_ALLOCATED(); |
| 101 public: | 102 public: |
| 102 SerializerMarkupAccumulator(PageSerializer*, const Document&, WillBeHeapVect
or<RawPtrWillBeMember<Node>>*); | 103 SerializerMarkupAccumulator(PageSerializer*, const Document&, WillBeHeapVect
or<RawPtrWillBeMember<Node>>*); |
| 103 virtual ~SerializerMarkupAccumulator(); | 104 virtual ~SerializerMarkupAccumulator(); |
| 104 | 105 |
| 105 protected: | 106 protected: |
| 106 virtual void appendText(StringBuilder& out, Text&) override; | 107 virtual void appendText(StringBuilder& out, Text&) override; |
| 107 virtual void appendElement(StringBuilder& out, Element&, Namespaces*) overri
de; | 108 virtual void appendElement(StringBuilder& out, Element&, Namespaces*) overri
de; |
| 108 virtual void appendCustomAttributes(StringBuilder& out, const Element&, Name
spaces*) override; | 109 virtual void appendCustomAttributes(StringBuilder& out, const Element&, Name
spaces*) override; |
| 109 virtual void appendEndTag(const Element&) override; | 110 virtual void appendEndTag(const Element&) override; |
| 110 | 111 |
| 111 private: | 112 private: |
| 112 PageSerializer* m_serializer; | 113 RawPtrWillBeMember<PageSerializer> m_serializer; |
| 113 const Document& m_document; | 114 RawPtrWillBeMember<const Document> m_document; |
| 114 }; | 115 }; |
| 115 | 116 |
| 116 SerializerMarkupAccumulator::SerializerMarkupAccumulator(PageSerializer* seriali
zer, const Document& document, WillBeHeapVector<RawPtrWillBeMember<Node>>* nodes
) | 117 SerializerMarkupAccumulator::SerializerMarkupAccumulator(PageSerializer* seriali
zer, const Document& document, WillBeHeapVector<RawPtrWillBeMember<Node>>* nodes
) |
| 117 : MarkupAccumulator(nodes, ResolveAllURLs, nullptr) | 118 : MarkupAccumulator(nodes, ResolveAllURLs, nullptr) |
| 118 , m_serializer(serializer) | 119 , m_serializer(serializer) |
| 119 , m_document(document) | 120 , m_document(&document) |
| 120 { | 121 { |
| 121 } | 122 } |
| 122 | 123 |
| 123 SerializerMarkupAccumulator::~SerializerMarkupAccumulator() | 124 SerializerMarkupAccumulator::~SerializerMarkupAccumulator() |
| 124 { | 125 { |
| 125 } | 126 } |
| 126 | 127 |
| 127 void SerializerMarkupAccumulator::appendText(StringBuilder& out, Text& text) | 128 void SerializerMarkupAccumulator::appendText(StringBuilder& out, Text& text) |
| 128 { | 129 { |
| 129 Element* parent = text.parentElement(); | 130 Element* parent = text.parentElement(); |
| 130 if (parent && !shouldIgnoreElement(*parent)) | 131 if (parent && !shouldIgnoreElement(*parent)) |
| 131 MarkupAccumulator::appendText(out, text); | 132 MarkupAccumulator::appendText(out, text); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void SerializerMarkupAccumulator::appendElement(StringBuilder& out, Element& ele
ment, Namespaces* namespaces) | 135 void SerializerMarkupAccumulator::appendElement(StringBuilder& out, Element& ele
ment, Namespaces* namespaces) |
| 135 { | 136 { |
| 136 if (!shouldIgnoreElement(element)) | 137 if (!shouldIgnoreElement(element)) |
| 137 MarkupAccumulator::appendElement(out, element, namespaces); | 138 MarkupAccumulator::appendElement(out, element, namespaces); |
| 138 | 139 |
| 139 if (isHTMLHeadElement(element)) { | 140 if (isHTMLHeadElement(element)) { |
| 140 out.appendLiteral("<meta charset=\""); | 141 out.appendLiteral("<meta charset=\""); |
| 141 out.append(m_document.charset()); | 142 out.append(m_document->charset()); |
| 142 out.appendLiteral("\">"); | 143 out.appendLiteral("\">"); |
| 143 } | 144 } |
| 144 | 145 |
| 145 // FIXME: For object (plugins) tags and video tag we could replace them by a
n image of their current contents. | 146 // FIXME: For object (plugins) tags and video tag we could replace them by a
n image of their current contents. |
| 146 } | 147 } |
| 147 | 148 |
| 148 void SerializerMarkupAccumulator::appendCustomAttributes(StringBuilder& out, con
st Element& element, Namespaces* namespaces) | 149 void SerializerMarkupAccumulator::appendCustomAttributes(StringBuilder& out, con
st Element& element, Namespaces* namespaces) |
| 149 { | 150 { |
| 150 if (!element.isFrameOwnerElement()) | 151 if (!element.isFrameOwnerElement()) |
| 151 return; | 152 return; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 return; | 207 return; |
| 207 } | 208 } |
| 208 | 209 |
| 209 WillBeHeapVector<RawPtrWillBeMember<Node>> serializedNodes; | 210 WillBeHeapVector<RawPtrWillBeMember<Node>> serializedNodes; |
| 210 SerializerMarkupAccumulator accumulator(this, document, &serializedNodes); | 211 SerializerMarkupAccumulator accumulator(this, document, &serializedNodes); |
| 211 String text = accumulator.serializeNodes(document, IncludeNode); | 212 String text = accumulator.serializeNodes(document, IncludeNode); |
| 212 CString frameHTML = textEncoding.normalizeAndEncode(text, WTF::EntitiesForUn
encodables); | 213 CString frameHTML = textEncoding.normalizeAndEncode(text, WTF::EntitiesForUn
encodables); |
| 213 m_resources->append(SerializedResource(url, document.suggestedMIMEType(), Sh
aredBuffer::create(frameHTML.data(), frameHTML.length()))); | 214 m_resources->append(SerializedResource(url, document.suggestedMIMEType(), Sh
aredBuffer::create(frameHTML.data(), frameHTML.length()))); |
| 214 m_resourceURLs.add(url); | 215 m_resourceURLs.add(url); |
| 215 | 216 |
| 216 for (Node* node : serializedNodes) { | 217 for (Node* node: serializedNodes) { |
| 217 ASSERT(node); | 218 ASSERT(node); |
| 218 if (!node->isElementNode()) | 219 if (!node->isElementNode()) |
| 219 continue; | 220 continue; |
| 220 | 221 |
| 221 Element& element = toElement(*node); | 222 Element& element = toElement(*node); |
| 222 // We have to process in-line style as it might contain some resources (
typically background images). | 223 // We have to process in-line style as it might contain some resources (
typically background images). |
| 223 if (element.isStyledElement()) | 224 if (element.isStyledElement()) |
| 224 retrieveResourcesForProperties(element.inlineStyle(), document); | 225 retrieveResourcesForProperties(element.inlineStyle(), document); |
| 225 | 226 |
| 226 if (isHTMLImageElement(element)) { | 227 if (isHTMLImageElement(element)) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 322 |
| 322 RefPtr<SharedBuffer> data = imageRenderer ? image->imageForRenderer(imageRen
derer)->data() : nullptr; | 323 RefPtr<SharedBuffer> data = imageRenderer ? image->imageForRenderer(imageRen
derer)->data() : nullptr; |
| 323 if (!data) | 324 if (!data) |
| 324 data = image->image()->data(); | 325 data = image->image()->data(); |
| 325 | 326 |
| 326 addToResources(image, data, url); | 327 addToResources(image, data, url); |
| 327 } | 328 } |
| 328 | 329 |
| 329 void PageSerializer::addFontToResources(FontResource* font) | 330 void PageSerializer::addFontToResources(FontResource* font) |
| 330 { | 331 { |
| 331 if (!font || !shouldAddURL(font->url()) || !font->isLoaded() || !font->resou
rceBuffer()) { | 332 if (!font || !shouldAddURL(font->url()) || !font->isLoaded() || !font->resou
rceBuffer()) |
| 332 return; | 333 return; |
| 333 } | 334 |
| 334 RefPtr<SharedBuffer> data(font->resourceBuffer()); | 335 RefPtr<SharedBuffer> data(font->resourceBuffer()); |
| 335 | 336 |
| 336 addToResources(font, data, font->url()); | 337 addToResources(font, data, font->url()); |
| 337 } | 338 } |
| 338 | 339 |
| 339 void PageSerializer::retrieveResourcesForProperties(const StylePropertySet* styl
eDeclaration, Document& document) | 340 void PageSerializer::retrieveResourcesForProperties(const StylePropertySet* styl
eDeclaration, Document& document) |
| 340 { | 341 { |
| 341 if (!styleDeclaration) | 342 if (!styleDeclaration) |
| 342 return; | 343 return; |
| 343 | 344 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 370 addFontToResources(fontFaceSrcValue->fetch(&document)); | 371 addFontToResources(fontFaceSrcValue->fetch(&document)); |
| 371 } else if (cssValue->isValueList()) { | 372 } else if (cssValue->isValueList()) { |
| 372 CSSValueList* cssValueList = toCSSValueList(cssValue); | 373 CSSValueList* cssValueList = toCSSValueList(cssValue); |
| 373 for (unsigned i = 0; i < cssValueList->length(); i++) | 374 for (unsigned i = 0; i < cssValueList->length(); i++) |
| 374 retrieveResourcesForCSSValue(cssValueList->item(i), document); | 375 retrieveResourcesForCSSValue(cssValueList->item(i), document); |
| 375 } | 376 } |
| 376 } | 377 } |
| 377 | 378 |
| 378 KURL PageSerializer::urlForBlankFrame(LocalFrame* frame) | 379 KURL PageSerializer::urlForBlankFrame(LocalFrame* frame) |
| 379 { | 380 { |
| 380 HashMap<LocalFrame*, KURL>::iterator iter = m_blankFrameURLs.find(frame); | 381 BlankFrameURLMap::iterator iter = m_blankFrameURLs.find(frame); |
| 381 if (iter != m_blankFrameURLs.end()) | 382 if (iter != m_blankFrameURLs.end()) |
| 382 return iter->value; | 383 return iter->value; |
| 383 String url = "wyciwyg://frame/" + String::number(m_blankFrameCounter++); | 384 String url = "wyciwyg://frame/" + String::number(m_blankFrameCounter++); |
| 384 KURL fakeURL(ParsedURLString, url); | 385 KURL fakeURL(ParsedURLString, url); |
| 385 m_blankFrameURLs.add(frame, fakeURL); | 386 m_blankFrameURLs.add(frame, fakeURL); |
| 386 | 387 |
| 387 return fakeURL; | 388 return fakeURL; |
| 388 } | 389 } |
| 389 | 390 |
| 390 } | 391 } // namespace blink |
| OLD | NEW |