| 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 26 matching lines...) Expand all Loading... |
| 37 #include "wtf/text/StringBuilder.h" | 37 #include "wtf/text/StringBuilder.h" |
| 38 #include "wtf/text/StringHash.h" | 38 #include "wtf/text/StringHash.h" |
| 39 #include "wtf/text/WTFString.h" | 39 #include "wtf/text/WTFString.h" |
| 40 | 40 |
| 41 #include "public/platform/WebString.h" | 41 #include "public/platform/WebString.h" |
| 42 #include "public/platform/WebURL.h" | 42 #include "public/platform/WebURL.h" |
| 43 #include "public/web/WebPageSerializer.h" | 43 #include "public/web/WebPageSerializer.h" |
| 44 #include "public/web/WebPageSerializerClient.h" | 44 #include "public/web/WebPageSerializerClient.h" |
| 45 #include "web/WebEntities.h" | 45 #include "web/WebEntities.h" |
| 46 | 46 |
| 47 namespace WTF{ | 47 namespace WTF { |
| 48 class TextEncoding; | 48 class TextEncoding; |
| 49 } | 49 } |
| 50 | 50 |
| 51 namespace blink { | 51 namespace blink { |
| 52 |
| 52 class Document; | 53 class Document; |
| 53 class Element; | 54 class Element; |
| 54 class Node; | 55 class Node; |
| 55 } | |
| 56 | |
| 57 namespace blink { | |
| 58 class WebLocalFrameImpl; | 56 class WebLocalFrameImpl; |
| 59 | 57 |
| 60 // Get html data by serializing all frames of current page with lists | 58 // Get html data by serializing all frames of current page with lists |
| 61 // which contain all resource links that have local copy. | 59 // which contain all resource links that have local copy. |
| 62 // contain all saved auxiliary files included all sub frames and resources. | 60 // contain all saved auxiliary files included all sub frames and resources. |
| 63 // This function will find out all frames and serialize them to HTML data. | 61 // This function will find out all frames and serialize them to HTML data. |
| 64 // We have a data buffer to temporary saving generated html data. We will | 62 // We have a data buffer to temporary saving generated html data. We will |
| 65 // sequentially call WebViewDelegate::SendSerializedHtmlData once the data | 63 // sequentially call WebViewDelegate::SendSerializedHtmlData once the data |
| 66 // buffer is full. See comments of WebViewDelegate::SendSerializedHtmlData | 64 // buffer is full. See comments of WebViewDelegate::SendSerializedHtmlData |
| 67 // for getting more information. | 65 // for getting more information. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // Local directory name of all local resource files. | 110 // Local directory name of all local resource files. |
| 113 WTF::String m_localDirectoryName; | 111 WTF::String m_localDirectoryName; |
| 114 // Vector for saving all frames which need to be serialized. | 112 // Vector for saving all frames which need to be serialized. |
| 115 Vector<WebLocalFrameImpl*> m_frames; | 113 Vector<WebLocalFrameImpl*> m_frames; |
| 116 | 114 |
| 117 // Web entities conversion maps. | 115 // Web entities conversion maps. |
| 118 WebEntities m_htmlEntities; | 116 WebEntities m_htmlEntities; |
| 119 WebEntities m_xmlEntities; | 117 WebEntities m_xmlEntities; |
| 120 | 118 |
| 121 struct SerializeDomParam { | 119 struct SerializeDomParam { |
| 122 const blink::KURL& url; | 120 const KURL& url; |
| 123 const WTF::TextEncoding& textEncoding; | 121 const WTF::TextEncoding& textEncoding; |
| 124 blink::Document* document; | 122 Document* document; |
| 125 const WTF::String& directoryName; | 123 const WTF::String& directoryName; |
| 126 bool isHTMLDocument; // document.isHTMLDocument() | 124 bool isHTMLDocument; // document.isHTMLDocument() |
| 127 bool haveSeenDocType; | 125 bool haveSeenDocType; |
| 128 bool haveAddedCharsetDeclaration; | 126 bool haveAddedCharsetDeclaration; |
| 129 // This meta element need to be skipped when serializing DOM. | 127 // This meta element need to be skipped when serializing DOM. |
| 130 const blink::Element* skipMetaElement; | 128 const Element* skipMetaElement; |
| 131 // Flag indicates we are in script or style tag. | 129 // Flag indicates we are in script or style tag. |
| 132 bool isInScriptOrStyleTag; | 130 bool isInScriptOrStyleTag; |
| 133 bool haveAddedXMLProcessingDirective; | 131 bool haveAddedXMLProcessingDirective; |
| 134 // Flag indicates whether we have added additional contents before end t
ag. | 132 // Flag indicates whether we have added additional contents before end t
ag. |
| 135 // This flag will be re-assigned in each call of function | 133 // This flag will be re-assigned in each call of function |
| 136 // PostActionAfterSerializeOpenTag and it could be changed in function | 134 // PostActionAfterSerializeOpenTag and it could be changed in function |
| 137 // PreActionBeforeSerializeEndTag if the function adds new contents into | 135 // PreActionBeforeSerializeEndTag if the function adds new contents into |
| 138 // serialization stream. | 136 // serialization stream. |
| 139 bool haveAddedContentsBeforeEnd; | 137 bool haveAddedContentsBeforeEnd; |
| 140 | 138 |
| 141 SerializeDomParam(const blink::KURL&, const WTF::TextEncoding&, blink::D
ocument*, const WTF::String& directoryName); | 139 SerializeDomParam(const KURL&, const WTF::TextEncoding&, Document*, cons
t WTF::String& directoryName); |
| 142 }; | 140 }; |
| 143 | 141 |
| 144 // Collect all target frames which need to be serialized. | 142 // Collect all target frames which need to be serialized. |
| 145 void collectTargetFrames(); | 143 void collectTargetFrames(); |
| 146 // Before we begin serializing open tag of a element, we give the target | 144 // Before we begin serializing open tag of a element, we give the target |
| 147 // element a chance to do some work prior to add some additional data. | 145 // element a chance to do some work prior to add some additional data. |
| 148 WTF::String preActionBeforeSerializeOpenTag(const blink::Element* element, | 146 WTF::String preActionBeforeSerializeOpenTag(const Element*, |
| 149 SerializeDomParam* param, | 147 SerializeDomParam* param, |
| 150 bool* needSkip); | 148 bool* needSkip); |
| 151 // After we finish serializing open tag of a element, we give the target | 149 // After we finish serializing open tag of a element, we give the target |
| 152 // element a chance to do some post work to add some additional data. | 150 // element a chance to do some post work to add some additional data. |
| 153 WTF::String postActionAfterSerializeOpenTag(const blink::Element* element, | 151 WTF::String postActionAfterSerializeOpenTag(const Element*, |
| 154 SerializeDomParam* param); | 152 SerializeDomParam* param); |
| 155 // Before we begin serializing end tag of a element, we give the target | 153 // Before we begin serializing end tag of a element, we give the target |
| 156 // element a chance to do some work prior to add some additional data. | 154 // element a chance to do some work prior to add some additional data. |
| 157 WTF::String preActionBeforeSerializeEndTag(const blink::Element* element, | 155 WTF::String preActionBeforeSerializeEndTag(const Element*, |
| 158 SerializeDomParam* param, | 156 SerializeDomParam* param, |
| 159 bool* needSkip); | 157 bool* needSkip); |
| 160 // After we finish serializing end tag of a element, we give the target | 158 // After we finish serializing end tag of a element, we give the target |
| 161 // element a chance to do some post work to add some additional data. | 159 // element a chance to do some post work to add some additional data. |
| 162 WTF::String postActionAfterSerializeEndTag(const blink::Element* element, | 160 WTF::String postActionAfterSerializeEndTag(const Element*, |
| 163 SerializeDomParam* param); | 161 SerializeDomParam* param); |
| 164 // Save generated html content to data buffer. | 162 // Save generated html content to data buffer. |
| 165 void saveHTMLContentToBuffer(const WTF::String& content, | 163 void saveHTMLContentToBuffer(const WTF::String& content, |
| 166 SerializeDomParam* param); | 164 SerializeDomParam* param); |
| 167 | 165 |
| 168 enum FlushOption { | 166 enum FlushOption { |
| 169 ForceFlush, | 167 ForceFlush, |
| 170 DoNotForceFlush, | 168 DoNotForceFlush, |
| 171 }; | 169 }; |
| 172 | 170 |
| 173 // Flushes the content buffer by encoding and sending the content to the | 171 // Flushes the content buffer by encoding and sending the content to the |
| 174 // WebPageSerializerClient. Content is not flushed if the buffer is not full | 172 // WebPageSerializerClient. Content is not flushed if the buffer is not full |
| 175 // unless force is 1. | 173 // unless force is 1. |
| 176 void encodeAndFlushBuffer(WebPageSerializerClient::PageSerializationStatus s
tatus, | 174 void encodeAndFlushBuffer(WebPageSerializerClient::PageSerializationStatus s
tatus, |
| 177 SerializeDomParam* param, | 175 SerializeDomParam* param, |
| 178 FlushOption); | 176 FlushOption); |
| 179 // Serialize open tag of an specified element. | 177 // Serialize open tag of an specified element. |
| 180 void openTagToString(blink::Element*, | 178 void openTagToString(Element*, |
| 181 SerializeDomParam* param); | 179 SerializeDomParam* param); |
| 182 // Serialize end tag of an specified element. | 180 // Serialize end tag of an specified element. |
| 183 void endTagToString(blink::Element*, | 181 void endTagToString(Element*, |
| 184 SerializeDomParam* param); | 182 SerializeDomParam* param); |
| 185 // Build content for a specified node | 183 // Build content for a specified node |
| 186 void buildContentForNode(blink::Node*, | 184 void buildContentForNode(Node*, |
| 187 SerializeDomParam* param); | 185 SerializeDomParam* param); |
| 188 }; | 186 }; |
| 189 | 187 |
| 190 } // namespace blink | 188 } // namespace blink |
| 191 | 189 |
| 192 #endif | 190 #endif |
| OLD | NEW |