OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 10 matching lines...) Expand all Loading... |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef WebPageSerializerImpl_h | 31 #ifndef WebFrameSerializerImpl_h |
32 #define WebPageSerializerImpl_h | 32 #define WebFrameSerializerImpl_h |
33 | 33 |
| 34 #include "public/platform/WebString.h" |
| 35 #include "public/platform/WebURL.h" |
| 36 #include "public/web/WebFrameSerializer.h" |
| 37 #include "public/web/WebFrameSerializerClient.h" |
| 38 #include "web/WebEntities.h" |
34 #include "wtf/Forward.h" | 39 #include "wtf/Forward.h" |
35 #include "wtf/HashMap.h" | 40 #include "wtf/HashMap.h" |
36 #include "wtf/Vector.h" | 41 #include "wtf/Vector.h" |
37 #include "wtf/text/StringBuilder.h" | 42 #include "wtf/text/StringBuilder.h" |
38 #include "wtf/text/StringHash.h" | 43 #include "wtf/text/StringHash.h" |
39 #include "wtf/text/WTFString.h" | 44 #include "wtf/text/WTFString.h" |
40 | 45 |
41 #include "public/platform/WebString.h" | |
42 #include "public/platform/WebURL.h" | |
43 #include "public/web/WebPageSerializer.h" | |
44 #include "public/web/WebPageSerializerClient.h" | |
45 #include "web/WebEntities.h" | |
46 | |
47 namespace WTF { | 46 namespace WTF { |
48 class TextEncoding; | 47 class TextEncoding; |
49 } | 48 } |
50 | 49 |
51 namespace blink { | 50 namespace blink { |
52 | 51 |
53 class Document; | 52 class Document; |
54 class Element; | 53 class Element; |
55 class Node; | 54 class Node; |
56 class WebLocalFrame; | 55 class WebLocalFrame; |
57 class WebLocalFrameImpl; | 56 class WebLocalFrameImpl; |
58 | 57 |
59 // Responsible for serializing the specified frame into html | 58 // Responsible for serializing the specified frame into html |
60 // (replacing links with paths to local files). | 59 // (replacing links with paths to local files). |
61 class WebPageSerializerImpl { | 60 class WebFrameSerializerImpl { |
62 STACK_ALLOCATED(); | 61 STACK_ALLOCATED(); |
63 public: | 62 public: |
64 // Do serialization action. | 63 // Do serialization action. |
65 // | 64 // |
66 // Returns false to indicate that no data has been serialized (i.e. because | 65 // Returns false to indicate that no data has been serialized (i.e. because |
67 // the target frame didn't have a valid url). | 66 // the target frame didn't have a valid url). |
68 // | 67 // |
69 // Synchronously calls WebPageSerializerClient methods to report | 68 // Synchronously calls WebFrameSerializerClient methods to report |
70 // serialization results. See WebPageSerializerClient comments for more | 69 // serialization results. See WebFrameSerializerClient comments for more |
71 // details. | 70 // details. |
72 bool serialize(); | 71 bool serialize(); |
73 | 72 |
74 // The parameter specifies which frame need to be serialized. | 73 // The parameter specifies which frame need to be serialized. |
75 // The parameter delegate specifies the pointer of interface | 74 // The parameter delegate specifies the pointer of interface |
76 // DomSerializerDelegate provide sink interface which can receive the | 75 // DomSerializerDelegate provide sink interface which can receive the |
77 // individual chunks of data to be saved. | 76 // individual chunks of data to be saved. |
78 // The parameter urlsToLocalPaths contains a mapping between original URLs | 77 // The parameter urlsToLocalPaths contains a mapping between original URLs |
79 // of saved resources and corresponding local file paths. | 78 // of saved resources and corresponding local file paths. |
80 WebPageSerializerImpl( | 79 WebFrameSerializerImpl( |
81 WebLocalFrame*, | 80 WebLocalFrame*, |
82 WebPageSerializerClient*, | 81 WebFrameSerializerClient*, |
83 const WebVector<std::pair<WebURL, WebString>>& urlsToLocalPaths); | 82 const WebVector<std::pair<WebURL, WebString>>& urlsToLocalPaths); |
84 | 83 |
85 private: | 84 private: |
86 // Specified frame which need to be serialized; | 85 // Specified frame which need to be serialized; |
87 RawPtrWillBeMember<WebLocalFrameImpl> m_specifiedWebLocalFrameImpl; | 86 RawPtrWillBeMember<WebLocalFrameImpl> m_specifiedWebLocalFrameImpl; |
88 // Pointer of WebPageSerializerClient | 87 // Pointer of WebFrameSerializerClient |
89 WebPageSerializerClient* m_client; | 88 WebFrameSerializerClient* m_client; |
90 // This hash map is used to map resource URL of original link to its local | 89 // This hash map is used to map resource URL of original link to its local |
91 // file path. | 90 // file path. |
92 typedef HashMap<WTF::String, WTF::String> LinkLocalPathMap; | 91 typedef HashMap<WTF::String, WTF::String> LinkLocalPathMap; |
93 // local_links_ include all pair of local resource path and corresponding | 92 // local_links_ include all pair of local resource path and corresponding |
94 // original link. | 93 // original link. |
95 LinkLocalPathMap m_localLinks; | 94 LinkLocalPathMap m_localLinks; |
96 // Data buffer for saving result of serialized DOM data. | 95 // Data buffer for saving result of serialized DOM data. |
97 StringBuilder m_dataBuffer; | 96 StringBuilder m_dataBuffer; |
98 | 97 |
99 // Web entities conversion maps. | 98 // Web entities conversion maps. |
(...skipping 19 matching lines...) Expand all Loading... |
119 // Flag indicates whether we have added additional contents before end t
ag. | 118 // Flag indicates whether we have added additional contents before end t
ag. |
120 // This flag will be re-assigned in each call of function | 119 // This flag will be re-assigned in each call of function |
121 // PostActionAfterSerializeOpenTag and it could be changed in function | 120 // PostActionAfterSerializeOpenTag and it could be changed in function |
122 // PreActionBeforeSerializeEndTag if the function adds new contents into | 121 // PreActionBeforeSerializeEndTag if the function adds new contents into |
123 // serialization stream. | 122 // serialization stream. |
124 bool haveAddedContentsBeforeEnd; | 123 bool haveAddedContentsBeforeEnd; |
125 }; | 124 }; |
126 | 125 |
127 // Before we begin serializing open tag of a element, we give the target | 126 // Before we begin serializing open tag of a element, we give the target |
128 // element a chance to do some work prior to add some additional data. | 127 // element a chance to do some work prior to add some additional data. |
129 WTF::String preActionBeforeSerializeOpenTag(const Element*, | 128 WTF::String preActionBeforeSerializeOpenTag( |
130 SerializeDomParam* param, | 129 const Element*, |
131 bool* needSkip); | 130 SerializeDomParam*, |
| 131 bool* needSkip); |
| 132 |
132 // After we finish serializing open tag of a element, we give the target | 133 // After we finish serializing open tag of a element, we give the target |
133 // element a chance to do some post work to add some additional data. | 134 // element a chance to do some post work to add some additional data. |
134 WTF::String postActionAfterSerializeOpenTag(const Element*, | 135 WTF::String postActionAfterSerializeOpenTag( |
135 SerializeDomParam* param); | 136 const Element*, |
| 137 SerializeDomParam*); |
| 138 |
136 // Before we begin serializing end tag of a element, we give the target | 139 // Before we begin serializing end tag of a element, we give the target |
137 // element a chance to do some work prior to add some additional data. | 140 // element a chance to do some work prior to add some additional data. |
138 WTF::String preActionBeforeSerializeEndTag(const Element*, | 141 WTF::String preActionBeforeSerializeEndTag( |
139 SerializeDomParam* param, | 142 const Element*, |
140 bool* needSkip); | 143 SerializeDomParam*, |
| 144 bool* needSkip); |
| 145 |
141 // After we finish serializing end tag of a element, we give the target | 146 // After we finish serializing end tag of a element, we give the target |
142 // element a chance to do some post work to add some additional data. | 147 // element a chance to do some post work to add some additional data. |
143 WTF::String postActionAfterSerializeEndTag(const Element*, | 148 WTF::String postActionAfterSerializeEndTag( |
144 SerializeDomParam* param); | 149 const Element*, |
| 150 SerializeDomParam*); |
| 151 |
145 // Save generated html content to data buffer. | 152 // Save generated html content to data buffer. |
146 void saveHTMLContentToBuffer(const WTF::String& content, | 153 void saveHTMLContentToBuffer( |
147 SerializeDomParam* param); | 154 const WTF::String& content, |
| 155 SerializeDomParam*); |
148 | 156 |
149 enum FlushOption { | 157 enum FlushOption { |
150 ForceFlush, | 158 ForceFlush, |
151 DoNotForceFlush, | 159 DoNotForceFlush, |
152 }; | 160 }; |
153 | 161 |
154 // Flushes the content buffer by encoding and sending the content to the | 162 // Flushes the content buffer by encoding and sending the content to the |
155 // WebPageSerializerClient. Content is not flushed if the buffer is not full | 163 // WebFrameSerializerClient. Content is not flushed if the buffer is not ful
l |
156 // unless force is 1. | 164 // unless force is 1. |
157 void encodeAndFlushBuffer(WebPageSerializerClient::PageSerializationStatus s
tatus, | 165 void encodeAndFlushBuffer( |
158 SerializeDomParam* param, | 166 WebFrameSerializerClient::FrameSerializationStatus, |
159 FlushOption); | 167 SerializeDomParam*, |
| 168 FlushOption); |
| 169 |
160 // Serialize open tag of an specified element. | 170 // Serialize open tag of an specified element. |
161 void openTagToString(Element*, | 171 void openTagToString( |
162 SerializeDomParam* param); | 172 Element*, |
| 173 SerializeDomParam*); |
| 174 |
163 // Serialize end tag of an specified element. | 175 // Serialize end tag of an specified element. |
164 void endTagToString(Element*, | 176 void endTagToString( |
165 SerializeDomParam* param); | 177 Element*, |
| 178 SerializeDomParam*); |
| 179 |
166 // Build content for a specified node | 180 // Build content for a specified node |
167 void buildContentForNode(Node*, | 181 void buildContentForNode( |
168 SerializeDomParam* param); | 182 Node*, |
| 183 SerializeDomParam*); |
169 }; | 184 }; |
170 | 185 |
171 } // namespace blink | 186 } // namespace blink |
172 | 187 |
173 #endif | 188 #endif |
OLD | NEW |