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 30 matching lines...) Expand all Loading... |
41 | 41 |
42 namespace blink { | 42 namespace blink { |
43 | 43 |
44 class Attribute; | 44 class Attribute; |
45 class CSSRule; | 45 class CSSRule; |
46 class CSSStyleSheet; | 46 class CSSStyleSheet; |
47 class CSSValue; | 47 class CSSValue; |
48 class Document; | 48 class Document; |
49 class Element; | 49 class Element; |
50 class FontResource; | 50 class FontResource; |
51 class ImageResource; | 51 class ImageResourceContent; |
52 class LocalFrame; | 52 class LocalFrame; |
53 class Resource; | |
54 class SharedBuffer; | 53 class SharedBuffer; |
55 class StylePropertySet; | 54 class StylePropertySet; |
56 | 55 |
57 struct SerializedResource; | 56 struct SerializedResource; |
58 | 57 |
59 // This class is used to serialize frame's contents back to text (typically | 58 // This class is used to serialize frame's contents back to text (typically |
60 // HTML). It serializes frame's document and resources such as images and CSS | 59 // HTML). It serializes frame's document and resources such as images and CSS |
61 // stylesheets. | 60 // stylesheets. |
62 class CORE_EXPORT FrameSerializer final { | 61 class CORE_EXPORT FrameSerializer final { |
63 STACK_ALLOCATED(); | 62 STACK_ALLOCATED(); |
64 | 63 |
65 public: | 64 public: |
| 65 enum ResourceHasCacheControlNoStoreHeader { |
| 66 NoCacheControlNoStoreHeader, |
| 67 HasCacheControlNoStoreHeader |
| 68 }; |
| 69 |
66 class Delegate { | 70 class Delegate { |
67 public: | 71 public: |
68 // Controls whether HTML serialization should skip the given attribute. | 72 // Controls whether HTML serialization should skip the given attribute. |
69 virtual bool shouldIgnoreAttribute(const Element&, const Attribute&) { | 73 virtual bool shouldIgnoreAttribute(const Element&, const Attribute&) { |
70 return false; | 74 return false; |
71 } | 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) { | 86 virtual bool rewriteLink(const Element&, String& rewrittenLink) { |
83 return false; | 87 return false; |
84 } | 88 } |
85 | 89 |
86 // Tells whether to skip serialization of a subresource or CSSStyleSheet | 90 // Tells whether to skip serialization of a subresource or CSSStyleSheet |
87 // with a given URI. Used to deduplicate resources across multiple frames. | 91 // with a given URI. Used to deduplicate resources across multiple frames. |
88 virtual bool shouldSkipResourceWithURL(const KURL&) { return false; } | 92 virtual bool shouldSkipResourceWithURL(const KURL&) { return false; } |
89 | 93 |
90 // Tells whether to skip serialization of a subresource. | 94 // Tells whether to skip serialization of a subresource. |
91 virtual bool shouldSkipResource(const Resource&) { return false; } | 95 virtual bool shouldSkipResource(ResourceHasCacheControlNoStoreHeader) { |
| 96 return false; |
| 97 } |
92 }; | 98 }; |
93 | 99 |
94 // Constructs a serializer that will write output to the given vector of | 100 // Constructs a serializer that will write output to the given vector of |
95 // SerializedResources and uses the Delegate for controlling some | 101 // SerializedResources and uses the Delegate for controlling some |
96 // serialization aspects. Callers need to ensure that both arguments stay | 102 // serialization aspects. Callers need to ensure that both arguments stay |
97 // alive until the FrameSerializer gets destroyed. | 103 // alive until the FrameSerializer gets destroyed. |
98 FrameSerializer(Vector<SerializedResource>&, Delegate&); | 104 FrameSerializer(Vector<SerializedResource>&, Delegate&); |
99 | 105 |
100 // Initiates the serialization of the frame. All serialized content and | 106 // Initiates the serialization of the frame. All serialized content and |
101 // retrieved resources are added to the Vector passed to the constructor. | 107 // retrieved resources are added to the Vector passed to the constructor. |
102 // The first resource in that vector is the frame's serialized content. | 108 // The first resource in that vector is the frame's serialized content. |
103 // Subsequent resources are images, css, etc. | 109 // Subsequent resources are images, css, etc. |
104 void serializeFrame(const LocalFrame&); | 110 void serializeFrame(const LocalFrame&); |
105 | 111 |
106 static String markOfTheWebDeclaration(const KURL&); | 112 static String markOfTheWebDeclaration(const KURL&); |
107 | 113 |
108 private: | 114 private: |
109 // Serializes the stylesheet back to text and adds it to the resources if URL | 115 // Serializes the stylesheet back to text and adds it to the resources if URL |
110 // is not-empty. It also adds any resources included in that stylesheet | 116 // is not-empty. It also adds any resources included in that stylesheet |
111 // (including any imported stylesheets and their own resources). | 117 // (including any imported stylesheets and their own resources). |
112 void serializeCSSStyleSheet(CSSStyleSheet&, const KURL&); | 118 void serializeCSSStyleSheet(CSSStyleSheet&, const KURL&); |
113 | 119 |
114 // Serializes the css rule (including any imported stylesheets), adding | 120 // Serializes the css rule (including any imported stylesheets), adding |
115 // referenced resources. | 121 // referenced resources. |
116 void serializeCSSRule(CSSRule*); | 122 void serializeCSSRule(CSSRule*); |
117 | 123 |
118 bool shouldAddURL(const KURL&); | 124 bool shouldAddURL(const KURL&); |
119 | 125 |
120 void addToResources(const Resource&, | 126 void addToResources(const String& mimeType, |
| 127 ResourceHasCacheControlNoStoreHeader, |
121 PassRefPtr<const SharedBuffer>, | 128 PassRefPtr<const SharedBuffer>, |
122 const KURL&); | 129 const KURL&); |
123 void addImageToResources(ImageResource*, const KURL&); | 130 void addImageToResources(ImageResourceContent*, const KURL&); |
124 void addFontToResources(FontResource*); | 131 void addFontToResources(FontResource*); |
125 | 132 |
126 void retrieveResourcesForProperties(const StylePropertySet*, Document&); | 133 void retrieveResourcesForProperties(const StylePropertySet*, Document&); |
127 void retrieveResourcesForCSSValue(const CSSValue&, Document&); | 134 void retrieveResourcesForCSSValue(const CSSValue&, Document&); |
128 | 135 |
129 Vector<SerializedResource>* m_resources; | 136 Vector<SerializedResource>* m_resources; |
130 HashSet<KURL> m_resourceURLs; | 137 HashSet<KURL> m_resourceURLs; |
131 | 138 |
132 bool m_isSerializingCss; | 139 bool m_isSerializingCss; |
133 | 140 |
134 Delegate& m_delegate; | 141 Delegate& m_delegate; |
135 }; | 142 }; |
136 | 143 |
137 } // namespace blink | 144 } // namespace blink |
138 | 145 |
139 #endif // FrameSerializer_h | 146 #endif // FrameSerializer_h |
OLD | NEW |