| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 #include "core/dom/Element.h" | 46 #include "core/dom/Element.h" |
| 47 #include "core/dom/Text.h" | 47 #include "core/dom/Text.h" |
| 48 #include "core/editing/MarkupAccumulator.h" | 48 #include "core/editing/MarkupAccumulator.h" |
| 49 #include "core/fetch/FontResource.h" | 49 #include "core/fetch/FontResource.h" |
| 50 #include "core/fetch/ImageResource.h" | 50 #include "core/fetch/ImageResource.h" |
| 51 #include "core/frame/LocalFrame.h" | 51 #include "core/frame/LocalFrame.h" |
| 52 #include "core/html/HTMLFrameOwnerElement.h" | 52 #include "core/html/HTMLFrameOwnerElement.h" |
| 53 #include "core/html/HTMLImageElement.h" | 53 #include "core/html/HTMLImageElement.h" |
| 54 #include "core/html/HTMLInputElement.h" | 54 #include "core/html/HTMLInputElement.h" |
| 55 #include "core/html/HTMLLinkElement.h" | 55 #include "core/html/HTMLLinkElement.h" |
| 56 #include "core/html/HTMLMetaElement.h" |
| 56 #include "core/html/HTMLStyleElement.h" | 57 #include "core/html/HTMLStyleElement.h" |
| 57 #include "core/html/parser/HTMLParserIdioms.h" | 58 #include "core/html/parser/HTMLParserIdioms.h" |
| 58 #include "core/page/Page.h" | 59 #include "core/page/Page.h" |
| 59 #include "core/rendering/RenderImage.h" | 60 #include "core/rendering/RenderImage.h" |
| 60 #include "core/rendering/style/StyleFetchedImage.h" | 61 #include "core/rendering/style/StyleFetchedImage.h" |
| 61 #include "core/rendering/style/StyleImage.h" | 62 #include "core/rendering/style/StyleImage.h" |
| 62 #include "platform/SerializedResource.h" | 63 #include "platform/SerializedResource.h" |
| 63 #include "platform/graphics/Image.h" | 64 #include "platform/graphics/Image.h" |
| 64 #include "wtf/text/CString.h" | 65 #include "wtf/text/CString.h" |
| 65 #include "wtf/text/StringBuilder.h" | 66 #include "wtf/text/StringBuilder.h" |
| 66 #include "wtf/text/TextEncoding.h" | 67 #include "wtf/text/TextEncoding.h" |
| 67 #include "wtf/text/WTFString.h" | 68 #include "wtf/text/WTFString.h" |
| 68 | 69 |
| 69 namespace WebCore { | 70 namespace WebCore { |
| 70 | 71 |
| 71 static bool isCharsetSpecifyingNode(const Node& node) | 72 static bool isCharsetSpecifyingNode(const Node& node) |
| 72 { | 73 { |
| 73 if (!node.isHTMLElement()) | 74 if (!isHTMLMetaElement(node)) |
| 74 return false; | 75 return false; |
| 75 | 76 |
| 76 const HTMLElement& element = toHTMLElement(node); | 77 const HTMLMetaElement& element = toHTMLMetaElement(node); |
| 77 if (!element.hasTagName(HTMLNames::metaTag)) | |
| 78 return false; | |
| 79 HTMLAttributeList attributes; | 78 HTMLAttributeList attributes; |
| 80 if (element.hasAttributes()) { | 79 if (element.hasAttributes()) { |
| 81 unsigned attributeCount = element.attributeCount(); | 80 unsigned attributeCount = element.attributeCount(); |
| 82 for (unsigned i = 0; i < attributeCount; ++i) { | 81 for (unsigned i = 0; i < attributeCount; ++i) { |
| 83 const Attribute& attribute = element.attributeItem(i); | 82 const Attribute& attribute = element.attributeItem(i); |
| 84 // FIXME: We should deal appropriately with the attribute if they ha
ve a namespace. | 83 // FIXME: We should deal appropriately with the attribute if they ha
ve a namespace. |
| 85 attributes.append(std::make_pair(attribute.name().localName(), attri
bute.value().string())); | 84 attributes.append(std::make_pair(attribute.name().localName(), attri
bute.value().string())); |
| 86 } | 85 } |
| 87 } | 86 } |
| 88 WTF::TextEncoding textEncoding = encodingFromMetaAttributes(attributes); | 87 WTF::TextEncoding textEncoding = encodingFromMetaAttributes(attributes); |
| 89 return textEncoding.isValid(); | 88 return textEncoding.isValid(); |
| 90 } | 89 } |
| 91 | 90 |
| 92 static bool shouldIgnoreElement(const Element& element) | 91 static bool shouldIgnoreElement(const Element& element) |
| 93 { | 92 { |
| 94 return element.hasTagName(HTMLNames::scriptTag) || element.hasTagName(HTMLNa
mes::noscriptTag) || isCharsetSpecifyingNode(element); | 93 return isHTMLScriptElement(element) || isHTMLNoScriptElement(element) || isC
harsetSpecifyingNode(element); |
| 95 } | 94 } |
| 96 | 95 |
| 97 static const QualifiedName& frameOwnerURLAttributeName(const HTMLFrameOwnerEleme
nt& frameOwner) | 96 static const QualifiedName& frameOwnerURLAttributeName(const HTMLFrameOwnerEleme
nt& frameOwner) |
| 98 { | 97 { |
| 99 // FIXME: We should support all frame owners including applets. | 98 // FIXME: We should support all frame owners including applets. |
| 100 return frameOwner.hasTagName(HTMLNames::objectTag) ? HTMLNames::dataAttr : H
TMLNames::srcAttr; | 99 return isHTMLObjectElement(frameOwner) ? HTMLNames::dataAttr : HTMLNames::sr
cAttr; |
| 101 } | 100 } |
| 102 | 101 |
| 103 class SerializerMarkupAccumulator FINAL : public MarkupAccumulator { | 102 class SerializerMarkupAccumulator FINAL : public MarkupAccumulator { |
| 104 public: | 103 public: |
| 105 SerializerMarkupAccumulator(PageSerializer*, const Document&, Vector<Node*>*
); | 104 SerializerMarkupAccumulator(PageSerializer*, const Document&, Vector<Node*>*
); |
| 106 virtual ~SerializerMarkupAccumulator(); | 105 virtual ~SerializerMarkupAccumulator(); |
| 107 | 106 |
| 108 protected: | 107 protected: |
| 109 virtual void appendText(StringBuilder& out, Text&) OVERRIDE; | 108 virtual void appendText(StringBuilder& out, Text&) OVERRIDE; |
| 110 virtual void appendElement(StringBuilder& out, Element&, Namespaces*) OVERRI
DE; | 109 virtual void appendElement(StringBuilder& out, Element&, Namespaces*) OVERRI
DE; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 132 Element* parent = text.parentElement(); | 131 Element* parent = text.parentElement(); |
| 133 if (parent && !shouldIgnoreElement(*parent)) | 132 if (parent && !shouldIgnoreElement(*parent)) |
| 134 MarkupAccumulator::appendText(out, text); | 133 MarkupAccumulator::appendText(out, text); |
| 135 } | 134 } |
| 136 | 135 |
| 137 void SerializerMarkupAccumulator::appendElement(StringBuilder& out, Element& ele
ment, Namespaces* namespaces) | 136 void SerializerMarkupAccumulator::appendElement(StringBuilder& out, Element& ele
ment, Namespaces* namespaces) |
| 138 { | 137 { |
| 139 if (!shouldIgnoreElement(element)) | 138 if (!shouldIgnoreElement(element)) |
| 140 MarkupAccumulator::appendElement(out, element, namespaces); | 139 MarkupAccumulator::appendElement(out, element, namespaces); |
| 141 | 140 |
| 142 if (element.hasTagName(HTMLNames::headTag)) { | 141 if (isHTMLHeadElement(element)) { |
| 143 out.append("<meta charset=\""); | 142 out.append("<meta charset=\""); |
| 144 out.append(m_document.charset()); | 143 out.append(m_document.charset()); |
| 145 out.append("\">"); | 144 out.append("\">"); |
| 146 } | 145 } |
| 147 | 146 |
| 148 // FIXME: For object (plugins) tags and video tag we could replace them by a
n image of their current contents. | 147 // FIXME: For object (plugins) tags and video tag we could replace them by a
n image of their current contents. |
| 149 } | 148 } |
| 150 | 149 |
| 151 void SerializerMarkupAccumulator::appendCustomAttributes(StringBuilder& out, con
st Element& element, Namespaces* namespaces) | 150 void SerializerMarkupAccumulator::appendCustomAttributes(StringBuilder& out, con
st Element& element, Namespaces* namespaces) |
| 152 { | 151 { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 ASSERT(*iter); | 217 ASSERT(*iter); |
| 219 Node& node = **iter; | 218 Node& node = **iter; |
| 220 if (!node.isElementNode()) | 219 if (!node.isElementNode()) |
| 221 continue; | 220 continue; |
| 222 | 221 |
| 223 Element& element = toElement(node); | 222 Element& element = toElement(node); |
| 224 // 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). |
| 225 if (element.isStyledElement()) | 224 if (element.isStyledElement()) |
| 226 retrieveResourcesForProperties(element.inlineStyle(), document); | 225 retrieveResourcesForProperties(element.inlineStyle(), document); |
| 227 | 226 |
| 228 if (element.hasTagName(HTMLNames::imgTag)) { | 227 if (isHTMLImageElement(element)) { |
| 229 HTMLImageElement& imageElement = toHTMLImageElement(element); | 228 HTMLImageElement& imageElement = toHTMLImageElement(element); |
| 230 KURL url = document.completeURL(imageElement.getAttribute(HTMLNames:
:srcAttr)); | 229 KURL url = document.completeURL(imageElement.getAttribute(HTMLNames:
:srcAttr)); |
| 231 ImageResource* cachedImage = imageElement.cachedImage(); | 230 ImageResource* cachedImage = imageElement.cachedImage(); |
| 232 addImageToResources(cachedImage, imageElement.renderer(), url); | 231 addImageToResources(cachedImage, imageElement.renderer(), url); |
| 233 } else if (element.hasTagName(HTMLNames::inputTag)) { | 232 } else if (isHTMLInputElement(element)) { |
| 234 HTMLInputElement& inputElement = toHTMLInputElement(element); | 233 HTMLInputElement& inputElement = toHTMLInputElement(element); |
| 235 if (inputElement.isImageButton() && inputElement.hasImageLoader()) { | 234 if (inputElement.isImageButton() && inputElement.hasImageLoader()) { |
| 236 KURL url = inputElement.src(); | 235 KURL url = inputElement.src(); |
| 237 ImageResource* cachedImage = inputElement.imageLoader()->image()
; | 236 ImageResource* cachedImage = inputElement.imageLoader()->image()
; |
| 238 addImageToResources(cachedImage, inputElement.renderer(), url); | 237 addImageToResources(cachedImage, inputElement.renderer(), url); |
| 239 } | 238 } |
| 240 } else if (element.hasTagName(HTMLNames::linkTag)) { | 239 } else if (isHTMLLinkElement(element)) { |
| 241 HTMLLinkElement& linkElement = toHTMLLinkElement(element); | 240 HTMLLinkElement& linkElement = toHTMLLinkElement(element); |
| 242 if (CSSStyleSheet* sheet = linkElement.sheet()) { | 241 if (CSSStyleSheet* sheet = linkElement.sheet()) { |
| 243 KURL url = document.completeURL(linkElement.getAttribute(HTMLNam
es::hrefAttr)); | 242 KURL url = document.completeURL(linkElement.getAttribute(HTMLNam
es::hrefAttr)); |
| 244 serializeCSSStyleSheet(sheet, url); | 243 serializeCSSStyleSheet(sheet, url); |
| 245 ASSERT(m_resourceURLs.contains(url)); | 244 ASSERT(m_resourceURLs.contains(url)); |
| 246 } | 245 } |
| 247 } else if (element.hasTagName(HTMLNames::styleTag)) { | 246 } else if (isHTMLStyleElement(element)) { |
| 248 HTMLStyleElement& styleElement = toHTMLStyleElement(element); | 247 HTMLStyleElement& styleElement = toHTMLStyleElement(element); |
| 249 if (CSSStyleSheet* sheet = styleElement.sheet()) | 248 if (CSSStyleSheet* sheet = styleElement.sheet()) |
| 250 serializeCSSStyleSheet(sheet, KURL()); | 249 serializeCSSStyleSheet(sheet, KURL()); |
| 251 } | 250 } |
| 252 } | 251 } |
| 253 | 252 |
| 254 for (LocalFrame* childFrame = frame->tree().firstChild(); childFrame; childF
rame = childFrame->tree().nextSibling()) | 253 for (LocalFrame* childFrame = frame->tree().firstChild(); childFrame; childF
rame = childFrame->tree().nextSibling()) |
| 255 serializeFrame(childFrame); | 254 serializeFrame(childFrame); |
| 256 } | 255 } |
| 257 | 256 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 if (iter != m_blankFrameURLs.end()) | 379 if (iter != m_blankFrameURLs.end()) |
| 381 return iter->value; | 380 return iter->value; |
| 382 String url = "wyciwyg://frame/" + String::number(m_blankFrameCounter++); | 381 String url = "wyciwyg://frame/" + String::number(m_blankFrameCounter++); |
| 383 KURL fakeURL(ParsedURLString, url); | 382 KURL fakeURL(ParsedURLString, url); |
| 384 m_blankFrameURLs.add(frame, fakeURL); | 383 m_blankFrameURLs.add(frame, fakeURL); |
| 385 | 384 |
| 386 return fakeURL; | 385 return fakeURL; |
| 387 } | 386 } |
| 388 | 387 |
| 389 } | 388 } |
| OLD | NEW |