| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promo te products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #ifndef PageSerializer_h | |
| 32 #define PageSerializer_h | |
| 33 | |
| 34 #include "core/CoreExport.h" | |
| 35 #include "platform/heap/Handle.h" | |
| 36 #include "platform/weborigin/KURL.h" | |
| 37 #include "platform/weborigin/KURLHash.h" | |
| 38 #include "wtf/ListHashSet.h" | |
| 39 #include "wtf/PassOwnPtr.h" | |
| 40 #include "wtf/Vector.h" | |
| 41 #include "wtf/text/WTFString.h" | |
| 42 | |
| 43 namespace blink { | |
| 44 | |
| 45 class Attribute; | |
| 46 class CSSRule; | |
| 47 class CSSStyleSheet; | |
| 48 class CSSValue; | |
| 49 class Document; | |
| 50 class Element; | |
| 51 class FontResource; | |
| 52 class ImageResource; | |
| 53 class LocalFrame; | |
| 54 class Node; | |
| 55 class Page; | |
| 56 class LayoutObject; | |
| 57 class Resource; | |
| 58 class SharedBuffer; | |
| 59 class StylePropertySet; | |
| 60 | |
| 61 struct SerializedResource; | |
| 62 | |
| 63 // This class is used to serialize frame's contents back to text (typically HTML
). | |
| 64 // It serializes frame's document and resources such as images and CSS styleshee
ts. | |
| 65 // TODO(lukasza): Rename this class to FrameSerializer. | |
| 66 class CORE_EXPORT PageSerializer final { | |
| 67 STACK_ALLOCATED(); | |
| 68 public: | |
| 69 class Delegate { | |
| 70 public: | |
| 71 // Controls whether HTML serialization should skip the given attribute. | |
| 72 virtual bool shouldIgnoreAttribute(const Attribute&) | |
| 73 { | |
| 74 return false; | |
| 75 } | |
| 76 | |
| 77 // Method allowing the Delegate control which URLs are written into the | |
| 78 // generated html document. | |
| 79 // | |
| 80 // When URL of the element needs to be rewritten, this method should | |
| 81 // return true and populate |rewrittenLink| with a desired value of the | |
| 82 // html attribute value to be used in place of the original link. | |
| 83 // (i.e. in place of img.src or iframe.src or object.data). | |
| 84 // | |
| 85 // If no link rewriting is desired, this method should return false. | |
| 86 virtual bool rewriteLink(const Element&, String& rewrittenLink) | |
| 87 { | |
| 88 return false; | |
| 89 } | |
| 90 | |
| 91 // Tells whether to skip serialization of a subresource with a given URI
. | |
| 92 // Used to deduplicate resources across multiple frames. | |
| 93 virtual bool shouldSkipResource(const KURL&) | |
| 94 { | |
| 95 return false; | |
| 96 } | |
| 97 }; | |
| 98 | |
| 99 // Constructs a serializer that will write output to the given vector of | |
| 100 // SerializedResources and uses the Delegate for controlling some | |
| 101 // serialization aspects. Callers need to ensure that both arguments stay | |
| 102 // alive until the PageSerializer gets destroyed. | |
| 103 PageSerializer(Vector<SerializedResource>&, Delegate&); | |
| 104 | |
| 105 // Initiates the serialization of the frame. All serialized content and | |
| 106 // retrieved resources are added to the Vector passed to the constructor. | |
| 107 // The first resource in that vector is the frame's serialized content. | |
| 108 // Subsequent resources are images, css, etc. | |
| 109 void serializeFrame(const LocalFrame&); | |
| 110 | |
| 111 static String markOfTheWebDeclaration(const KURL&); | |
| 112 | |
| 113 private: | |
| 114 // Serializes the stylesheet back to text and adds it to the resources if UR
L is not-empty. | |
| 115 // It also adds any resources included in that stylesheet (including any imp
orted stylesheets and their own resources). | |
| 116 void serializeCSSStyleSheet(CSSStyleSheet&, const KURL&); | |
| 117 | |
| 118 // Serializes the css rule (including any imported stylesheets), adding refe
renced resources. | |
| 119 void serializeCSSRule(CSSRule*); | |
| 120 | |
| 121 bool shouldAddURL(const KURL&); | |
| 122 | |
| 123 void addToResources(Resource *, PassRefPtr<SharedBuffer>, const KURL&); | |
| 124 void addImageToResources(ImageResource*, const KURL&); | |
| 125 void addFontToResources(FontResource*); | |
| 126 | |
| 127 void retrieveResourcesForProperties(const StylePropertySet*, Document&); | |
| 128 void retrieveResourcesForCSSValue(CSSValue*, Document&); | |
| 129 | |
| 130 Vector<SerializedResource>* m_resources; | |
| 131 ListHashSet<KURL> m_resourceURLs; | |
| 132 | |
| 133 Delegate& m_delegate; | |
| 134 }; | |
| 135 | |
| 136 } // namespace blink | |
| 137 | |
| 138 #endif // PageSerializer_h | |
| OLD | NEW |