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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 class TextEncoding; | 48 class TextEncoding; |
49 } | 49 } |
50 | 50 |
51 namespace blink { | 51 namespace blink { |
52 | 52 |
53 class Document; | 53 class Document; |
54 class Element; | 54 class Element; |
55 class Node; | 55 class Node; |
56 class WebLocalFrameImpl; | 56 class WebLocalFrameImpl; |
57 | 57 |
58 // Get html data by serializing all frames of current page with lists | 58 // Responsible for serializing the specified frame into html |
59 // which contain all resource links that have local copy. | 59 // (replacing links with paths to local files). |
60 // contain all saved auxiliary files included all sub frames and resources. | |
61 // This function will find out all frames and serialize them to HTML data. | |
62 // We have a data buffer to temporary saving generated html data. We will | |
63 // sequentially call WebViewDelegate::SendSerializedHtmlData once the data | |
64 // buffer is full. See comments of WebViewDelegate::SendSerializedHtmlData | |
65 // for getting more information. | |
66 class WebPageSerializerImpl { | 60 class WebPageSerializerImpl { |
67 STACK_ALLOCATED(); | 61 STACK_ALLOCATED(); |
68 public: | 62 public: |
69 // Do serialization action. Return false means no available frame has been | 63 // Do serialization action. |
70 // serialized, otherwise return true. | 64 // |
| 65 // Returns false to indicate that no data has been serialized (i.e. because |
| 66 // the target frame didn't have a valid url). |
| 67 // |
| 68 // Synchronously calls WebPageSerializerClient methods to report |
| 69 // serialization results. See WebPageSerializerClient comments for more |
| 70 // details. |
71 bool serialize(); | 71 bool serialize(); |
72 | 72 |
73 // The parameter specifies which frame need to be serialized. | 73 // The parameter specifies which frame need to be serialized. |
74 // The parameter recursive_serialization specifies whether we need to | |
75 // serialize all sub frames of the specified frame or not. | |
76 // The parameter delegate specifies the pointer of interface | 74 // The parameter delegate specifies the pointer of interface |
77 // DomSerializerDelegate provide sink interface which can receive the | 75 // DomSerializerDelegate provide sink interface which can receive the |
78 // individual chunks of data to be saved. | 76 // individual chunks of data to be saved. |
79 // The parameter links contain original URLs of all saved links. | 77 // The parameter links contain original URLs of all saved links. |
80 // The parameter local_paths contain corresponding local file paths of all | 78 // The parameter local_paths contain corresponding local file paths of all |
81 // saved links, which matched with vector:links one by one. | 79 // saved links, which matched with vector:links one by one. |
82 // The parameter local_directory_name is relative path of directory which | 80 // The parameter local_directory_name is relative path of directory which |
83 // contain all saved auxiliary files included all sub frames and resources. | 81 // contain all saved auxiliary files included all sub frames and resources. |
84 WebPageSerializerImpl(WebFrame* frame, | 82 WebPageSerializerImpl(WebFrame* frame, |
85 bool recursive, | |
86 WebPageSerializerClient* client, | 83 WebPageSerializerClient* client, |
87 const WebVector<WebURL>& links, | 84 const WebVector<WebURL>& links, |
88 const WebVector<WebString>& localPaths, | 85 const WebVector<WebString>& localPaths, |
89 const WebString& localDirectoryName); | 86 const WebString& localDirectoryName); |
90 | 87 |
91 private: | 88 private: |
92 // Specified frame which need to be serialized; | 89 // Specified frame which need to be serialized; |
93 RawPtrWillBeMember<WebLocalFrameImpl> m_specifiedWebLocalFrameImpl; | 90 RawPtrWillBeMember<WebLocalFrameImpl> m_specifiedWebLocalFrameImpl; |
94 // Pointer of WebPageSerializerClient | 91 // Pointer of WebPageSerializerClient |
95 WebPageSerializerClient* m_client; | 92 WebPageSerializerClient* m_client; |
96 // This hash map is used to map resource URL of original link to its local | 93 // This hash map is used to map resource URL of original link to its local |
97 // file path. | 94 // file path. |
98 typedef HashMap<WTF::String, WTF::String> LinkLocalPathMap; | 95 typedef HashMap<WTF::String, WTF::String> LinkLocalPathMap; |
99 // local_links_ include all pair of local resource path and corresponding | 96 // local_links_ include all pair of local resource path and corresponding |
100 // original link. | 97 // original link. |
101 LinkLocalPathMap m_localLinks; | 98 LinkLocalPathMap m_localLinks; |
102 // Data buffer for saving result of serialized DOM data. | 99 // Data buffer for saving result of serialized DOM data. |
103 StringBuilder m_dataBuffer; | 100 StringBuilder m_dataBuffer; |
104 // Passing true to recursive_serialization_ indicates we will serialize not | |
105 // only the specified frame but also all sub-frames in the specific frame. | |
106 // Otherwise we only serialize the specified frame excluded all sub-frames. | |
107 bool m_recursiveSerialization; | |
108 // Flag indicates whether we have collected all frames which need to be | |
109 // serialized or not; | |
110 bool m_framesCollected; | |
111 // Local directory name of all local resource files. | 101 // Local directory name of all local resource files. |
112 WTF::String m_localDirectoryName; | 102 WTF::String m_localDirectoryName; |
113 // Vector for saving all frames which need to be serialized. | |
114 WillBeHeapVector<RawPtrWillBeMember<WebLocalFrameImpl>> m_frames; | |
115 | 103 |
116 // Web entities conversion maps. | 104 // Web entities conversion maps. |
117 WebEntities m_htmlEntities; | 105 WebEntities m_htmlEntities; |
118 WebEntities m_xmlEntities; | 106 WebEntities m_xmlEntities; |
119 | 107 |
120 class SerializeDomParam { | 108 class SerializeDomParam { |
121 STACK_ALLOCATED(); | 109 STACK_ALLOCATED(); |
122 public: | 110 public: |
123 SerializeDomParam(const KURL&, const WTF::TextEncoding&, Document*, cons
t WTF::String& directoryName); | 111 SerializeDomParam(const KURL&, const WTF::TextEncoding&, Document*, cons
t WTF::String& directoryName); |
124 | 112 |
(...skipping 10 matching lines...) Expand all Loading... |
135 bool isInScriptOrStyleTag; | 123 bool isInScriptOrStyleTag; |
136 bool haveAddedXMLProcessingDirective; | 124 bool haveAddedXMLProcessingDirective; |
137 // Flag indicates whether we have added additional contents before end t
ag. | 125 // Flag indicates whether we have added additional contents before end t
ag. |
138 // This flag will be re-assigned in each call of function | 126 // This flag will be re-assigned in each call of function |
139 // PostActionAfterSerializeOpenTag and it could be changed in function | 127 // PostActionAfterSerializeOpenTag and it could be changed in function |
140 // PreActionBeforeSerializeEndTag if the function adds new contents into | 128 // PreActionBeforeSerializeEndTag if the function adds new contents into |
141 // serialization stream. | 129 // serialization stream. |
142 bool haveAddedContentsBeforeEnd; | 130 bool haveAddedContentsBeforeEnd; |
143 }; | 131 }; |
144 | 132 |
145 // Collect all target frames which need to be serialized. | |
146 void collectTargetFrames(); | |
147 // Before we begin serializing open tag of a element, we give the target | 133 // Before we begin serializing open tag of a element, we give the target |
148 // element a chance to do some work prior to add some additional data. | 134 // element a chance to do some work prior to add some additional data. |
149 WTF::String preActionBeforeSerializeOpenTag(const Element*, | 135 WTF::String preActionBeforeSerializeOpenTag(const Element*, |
150 SerializeDomParam* param, | 136 SerializeDomParam* param, |
151 bool* needSkip); | 137 bool* needSkip); |
152 // After we finish serializing open tag of a element, we give the target | 138 // After we finish serializing open tag of a element, we give the target |
153 // element a chance to do some post work to add some additional data. | 139 // element a chance to do some post work to add some additional data. |
154 WTF::String postActionAfterSerializeOpenTag(const Element*, | 140 WTF::String postActionAfterSerializeOpenTag(const Element*, |
155 SerializeDomParam* param); | 141 SerializeDomParam* param); |
156 // Before we begin serializing end tag of a element, we give the target | 142 // Before we begin serializing end tag of a element, we give the target |
(...skipping 27 matching lines...) Expand all Loading... |
184 void endTagToString(Element*, | 170 void endTagToString(Element*, |
185 SerializeDomParam* param); | 171 SerializeDomParam* param); |
186 // Build content for a specified node | 172 // Build content for a specified node |
187 void buildContentForNode(Node*, | 173 void buildContentForNode(Node*, |
188 SerializeDomParam* param); | 174 SerializeDomParam* param); |
189 }; | 175 }; |
190 | 176 |
191 } // namespace blink | 177 } // namespace blink |
192 | 178 |
193 #endif | 179 #endif |
OLD | NEW |