| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 struct SerializedResource; | 61 struct SerializedResource; |
| 62 | 62 |
| 63 // This class is used to serialize frame's contents back to text (typically HTML
). | 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. | 64 // It serializes frame's document and resources such as images and CSS styleshee
ts. |
| 65 // TODO(lukasza): Rename this class to FrameSerializer. | 65 // TODO(lukasza): Rename this class to FrameSerializer. |
| 66 class CORE_EXPORT PageSerializer final { | 66 class CORE_EXPORT PageSerializer final { |
| 67 STACK_ALLOCATED(); | 67 STACK_ALLOCATED(); |
| 68 public: | 68 public: |
| 69 class Delegate { | 69 class Delegate { |
| 70 public: | 70 public: |
| 71 virtual bool shouldIgnoreAttribute(const Attribute&) = 0; | 71 // Controls whether HTML serialization should skip the given attribute. |
| 72 virtual bool shouldIgnoreAttribute(const Attribute&) |
| 73 { |
| 74 return false; |
| 75 } |
| 72 | 76 |
| 73 // Method allowing the Delegate control which URLs are written into the | 77 // Method allowing the Delegate control which URLs are written into the |
| 74 // generated html document. | 78 // generated html document. |
| 75 // | 79 // |
| 76 // When URL of the element needs to be rewritten, this method should | 80 // When URL of the element needs to be rewritten, this method should |
| 77 // return true and populate |rewrittenLink| with a desired value of the | 81 // return true and populate |rewrittenLink| with a desired value of the |
| 78 // html attribute value to be used in place of the original link. | 82 // html attribute value to be used in place of the original link. |
| 79 // (i.e. in place of img.src or iframe.src or object.data). | 83 // (i.e. in place of img.src or iframe.src or object.data). |
| 80 // | 84 // |
| 81 // If no link rewriting is desired, this method should return false. | 85 // If no link rewriting is desired, this method should return false. |
| 82 virtual bool rewriteLink(const Element&, String& rewrittenLink) = 0; | 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 } |
| 83 }; | 97 }; |
| 84 | 98 |
| 85 // Constructs a serializer that will write output to the given vector of | 99 // Constructs a serializer that will write output to the given vector of |
| 86 // SerializedResources and use the optional Delegate for controlling some | 100 // SerializedResources and uses the Delegate for controlling some |
| 87 // serialization aspects. Callers need to ensure that the Delegate stays | 101 // serialization aspects. Callers need to ensure that both arguments stay |
| 88 // alive until the PageSerializer gets destroyed. | 102 // alive until the PageSerializer gets destroyed. |
| 89 PageSerializer(Vector<SerializedResource>&, Delegate*); | 103 PageSerializer(Vector<SerializedResource>&, Delegate&); |
| 90 | 104 |
| 91 // Initiates the serialization of the frame. All serialized content and | 105 // Initiates the serialization of the frame. All serialized content and |
| 92 // retrieved resources are added to the Vector passed to the constructor. | 106 // retrieved resources are added to the Vector passed to the constructor. |
| 93 // The first resource in that vector is the frame's serialized content. | 107 // The first resource in that vector is the frame's serialized content. |
| 94 // Subsequent resources are images, css, etc. | 108 // Subsequent resources are images, css, etc. |
| 95 void serializeFrame(const LocalFrame&); | 109 void serializeFrame(const LocalFrame&); |
| 96 | 110 |
| 97 Delegate* delegate(); | |
| 98 | |
| 99 static String markOfTheWebDeclaration(const KURL&); | 111 static String markOfTheWebDeclaration(const KURL&); |
| 100 | 112 |
| 101 private: | 113 private: |
| 102 // Serializes the stylesheet back to text and adds it to the resources if UR
L is not-empty. | 114 // Serializes the stylesheet back to text and adds it to the resources if UR
L is not-empty. |
| 103 // It also adds any resources included in that stylesheet (including any imp
orted stylesheets and their own resources). | 115 // It also adds any resources included in that stylesheet (including any imp
orted stylesheets and their own resources). |
| 104 void serializeCSSStyleSheet(CSSStyleSheet&, const KURL&); | 116 void serializeCSSStyleSheet(CSSStyleSheet&, const KURL&); |
| 105 | 117 |
| 106 // Serializes the css rule (including any imported stylesheets), adding refe
renced resources. | 118 // Serializes the css rule (including any imported stylesheets), adding refe
renced resources. |
| 107 void serializeCSSRule(CSSRule*); | 119 void serializeCSSRule(CSSRule*); |
| 108 | 120 |
| 109 bool shouldAddURL(const KURL&); | 121 bool shouldAddURL(const KURL&); |
| 110 | 122 |
| 111 void addToResources(Resource *, PassRefPtr<SharedBuffer>, const KURL&); | 123 void addToResources(Resource *, PassRefPtr<SharedBuffer>, const KURL&); |
| 112 void addImageToResources(ImageResource*, const KURL&); | 124 void addImageToResources(ImageResource*, const KURL&); |
| 113 void addFontToResources(FontResource*); | 125 void addFontToResources(FontResource*); |
| 114 | 126 |
| 115 void retrieveResourcesForProperties(const StylePropertySet*, Document&); | 127 void retrieveResourcesForProperties(const StylePropertySet*, Document&); |
| 116 void retrieveResourcesForCSSValue(CSSValue*, Document&); | 128 void retrieveResourcesForCSSValue(CSSValue*, Document&); |
| 117 | 129 |
| 118 Vector<SerializedResource>* m_resources; | 130 Vector<SerializedResource>* m_resources; |
| 119 ListHashSet<KURL> m_resourceURLs; | 131 ListHashSet<KURL> m_resourceURLs; |
| 120 | 132 |
| 121 Delegate* m_delegate; | 133 Delegate& m_delegate; |
| 122 }; | 134 }; |
| 123 | 135 |
| 124 } // namespace blink | 136 } // namespace blink |
| 125 | 137 |
| 126 #endif // PageSerializer_h | 138 #endif // PageSerializer_h |
| OLD | NEW |