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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // correctly loading local saved resource files. Also I think we need to inherit | 68 // correctly loading local saved resource files. Also I think we need to inherit |
69 // the base target value from document object when appending new base tag. | 69 // the base target value from document object when appending new base tag. |
70 // If there are multiple base tags in original document, we will comment all old | 70 // If there are multiple base tags in original document, we will comment all old |
71 // base tags and append new base tag after each old base tag because we do not | 71 // base tags and append new base tag after each old base tag because we do not |
72 // know those old base tags are original content or added by JavaScript. If | 72 // know those old base tags are original content or added by JavaScript. If |
73 // they are added by JavaScript, it means when loading saved page, the script(s) | 73 // they are added by JavaScript, it means when loading saved page, the script(s) |
74 // will still insert base tag(s) to DOM, so the new added base tag(s) can | 74 // will still insert base tag(s) to DOM, so the new added base tag(s) can |
75 // override the incorrect base URL and make sure we alway load correct local | 75 // override the incorrect base URL and make sure we alway load correct local |
76 // saved resource files. | 76 // saved resource files. |
77 | 77 |
78 #include "web/WebPageSerializerImpl.h" | 78 #include "web/WebFrameSerializerImpl.h" |
79 | 79 |
80 #include "core/HTMLNames.h" | 80 #include "core/HTMLNames.h" |
81 #include "core/dom/Document.h" | 81 #include "core/dom/Document.h" |
82 #include "core/dom/DocumentType.h" | 82 #include "core/dom/DocumentType.h" |
83 #include "core/dom/Element.h" | 83 #include "core/dom/Element.h" |
84 #include "core/editing/serializers/Serialization.h" | 84 #include "core/editing/serializers/Serialization.h" |
| 85 #include "core/frame/FrameSerializer.h" |
85 #include "core/html/HTMLAllCollection.h" | 86 #include "core/html/HTMLAllCollection.h" |
86 #include "core/html/HTMLElement.h" | 87 #include "core/html/HTMLElement.h" |
87 #include "core/html/HTMLFormElement.h" | 88 #include "core/html/HTMLFormElement.h" |
88 #include "core/html/HTMLHtmlElement.h" | 89 #include "core/html/HTMLHtmlElement.h" |
89 #include "core/html/HTMLMetaElement.h" | 90 #include "core/html/HTMLMetaElement.h" |
90 #include "core/loader/DocumentLoader.h" | 91 #include "core/loader/DocumentLoader.h" |
91 #include "core/loader/FrameLoader.h" | 92 #include "core/loader/FrameLoader.h" |
92 #include "core/page/PageSerializer.h" | |
93 #include "public/platform/WebVector.h" | 93 #include "public/platform/WebVector.h" |
94 #include "web/WebLocalFrameImpl.h" | 94 #include "web/WebLocalFrameImpl.h" |
95 #include "wtf/text/TextEncoding.h" | 95 #include "wtf/text/TextEncoding.h" |
96 | 96 |
97 namespace blink { | 97 namespace blink { |
98 | 98 |
99 // Maximum length of data buffer which is used to temporary save generated | 99 // Maximum length of data buffer which is used to temporary save generated |
100 // html content data. This is a soft limit which might be passed if a very large | 100 // html content data. This is a soft limit which might be passed if a very large |
101 // contegious string is found in the page. | 101 // contegious string is found in the html document. |
102 static const unsigned dataBufferCapacity = 65536; | 102 static const unsigned dataBufferCapacity = 65536; |
103 | 103 |
104 WebPageSerializerImpl::SerializeDomParam::SerializeDomParam(const KURL& url, | 104 WebFrameSerializerImpl::SerializeDomParam::SerializeDomParam( |
105 const WTF::TextEncod
ing& textEncoding, | 105 const KURL& url, |
106 Document* document) | 106 const WTF::TextEncoding& textEncoding, |
| 107 Document* document) |
107 : url(url) | 108 : url(url) |
108 , textEncoding(textEncoding) | 109 , textEncoding(textEncoding) |
109 , document(document) | 110 , document(document) |
110 , isHTMLDocument(document->isHTMLDocument()) | 111 , isHTMLDocument(document->isHTMLDocument()) |
111 , haveSeenDocType(false) | 112 , haveSeenDocType(false) |
112 , haveAddedCharsetDeclaration(false) | 113 , haveAddedCharsetDeclaration(false) |
113 , skipMetaElement(nullptr) | 114 , skipMetaElement(nullptr) |
114 , isInScriptOrStyleTag(false) | 115 , isInScriptOrStyleTag(false) |
115 , haveAddedXMLProcessingDirective(false) | 116 , haveAddedXMLProcessingDirective(false) |
116 , haveAddedContentsBeforeEnd(false) | 117 , haveAddedContentsBeforeEnd(false) |
117 { | 118 { |
118 } | 119 } |
119 | 120 |
120 String WebPageSerializerImpl::preActionBeforeSerializeOpenTag( | 121 String WebFrameSerializerImpl::preActionBeforeSerializeOpenTag( |
121 const Element* element, SerializeDomParam* param, bool* needSkip) | 122 const Element* element, SerializeDomParam* param, bool* needSkip) |
122 { | 123 { |
123 StringBuilder result; | 124 StringBuilder result; |
124 | 125 |
125 *needSkip = false; | 126 *needSkip = false; |
126 if (param->isHTMLDocument) { | 127 if (param->isHTMLDocument) { |
127 // Skip the open tag of original META tag which declare charset since we | 128 // Skip the open tag of original META tag which declare charset since we |
128 // have overrided the META which have correct charset declaration after | 129 // have overrided the META which have correct charset declaration after |
129 // serializing open tag of HEAD element. | 130 // serializing open tag of HEAD element. |
130 ASSERT(element); | 131 ASSERT(element); |
131 if (isHTMLMetaElement(element) && toHTMLMetaElement(element)->computeEnc
oding().isValid()) { | 132 if (isHTMLMetaElement(element) && toHTMLMetaElement(element)->computeEnc
oding().isValid()) { |
132 // Found META tag declared charset, we need to skip it when | 133 // Found META tag declared charset, we need to skip it when |
133 // serializing DOM. | 134 // serializing DOM. |
134 param->skipMetaElement = element; | 135 param->skipMetaElement = element; |
135 *needSkip = true; | 136 *needSkip = true; |
136 } else if (isHTMLHtmlElement(*element)) { | 137 } else if (isHTMLHtmlElement(*element)) { |
137 // Check something before processing the open tag of HEAD element. | 138 // Check something before processing the open tag of HEAD element. |
138 // First we add doc type declaration if original document has it. | 139 // First we add doc type declaration if original document has it. |
139 if (!param->haveSeenDocType) { | 140 if (!param->haveSeenDocType) { |
140 param->haveSeenDocType = true; | 141 param->haveSeenDocType = true; |
141 result.append(createMarkup(param->document->doctype())); | 142 result.append(createMarkup(param->document->doctype())); |
142 } | 143 } |
143 | 144 |
144 // Add MOTW declaration before html tag. | 145 // Add MOTW declaration before html tag. |
145 // See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx
. | 146 // See http://msdn2.microsoft.com/en-us/library/ms537628(VS.85).aspx
. |
146 result.append(WebPageSerializer::generateMarkOfTheWebDeclaration(par
am->url)); | 147 result.append(WebFrameSerializer::generateMarkOfTheWebDeclaration(pa
ram->url)); |
147 } else if (isHTMLBaseElement(*element)) { | 148 } else if (isHTMLBaseElement(*element)) { |
148 // Comment the BASE tag when serializing dom. | 149 // Comment the BASE tag when serializing dom. |
149 result.appendLiteral("<!--"); | 150 result.appendLiteral("<!--"); |
150 } | 151 } |
151 } else { | 152 } else { |
152 // Write XML declaration. | 153 // Write XML declaration. |
153 if (!param->haveAddedXMLProcessingDirective) { | 154 if (!param->haveAddedXMLProcessingDirective) { |
154 param->haveAddedXMLProcessingDirective = true; | 155 param->haveAddedXMLProcessingDirective = true; |
155 // Get encoding info. | 156 // Get encoding info. |
156 String xmlEncoding = param->document->xmlEncoding(); | 157 String xmlEncoding = param->document->xmlEncoding(); |
(...skipping 11 matching lines...) Expand all Loading... |
168 } | 169 } |
169 // Add doc type declaration if original document has it. | 170 // Add doc type declaration if original document has it. |
170 if (!param->haveSeenDocType) { | 171 if (!param->haveSeenDocType) { |
171 param->haveSeenDocType = true; | 172 param->haveSeenDocType = true; |
172 result.append(createMarkup(param->document->doctype())); | 173 result.append(createMarkup(param->document->doctype())); |
173 } | 174 } |
174 } | 175 } |
175 return result.toString(); | 176 return result.toString(); |
176 } | 177 } |
177 | 178 |
178 String WebPageSerializerImpl::postActionAfterSerializeOpenTag( | 179 String WebFrameSerializerImpl::postActionAfterSerializeOpenTag( |
179 const Element* element, SerializeDomParam* param) | 180 const Element* element, SerializeDomParam* param) |
180 { | 181 { |
181 StringBuilder result; | 182 StringBuilder result; |
182 | 183 |
183 param->haveAddedContentsBeforeEnd = false; | 184 param->haveAddedContentsBeforeEnd = false; |
184 if (!param->isHTMLDocument) | 185 if (!param->isHTMLDocument) |
185 return result.toString(); | 186 return result.toString(); |
186 // Check after processing the open tag of HEAD element | 187 // Check after processing the open tag of HEAD element |
187 if (!param->haveAddedCharsetDeclaration | 188 if (!param->haveAddedCharsetDeclaration |
188 && isHTMLHeadElement(*element)) { | 189 && isHTMLHeadElement(*element)) { |
189 param->haveAddedCharsetDeclaration = true; | 190 param->haveAddedCharsetDeclaration = true; |
190 // Check meta element. WebKit only pre-parse the first 512 bytes | 191 // Check meta element. WebKit only pre-parse the first 512 bytes of the |
191 // of the document. If the whole <HEAD> is larger and meta is the | 192 // document. If the whole <HEAD> is larger and meta is the end of head |
192 // end of head part, then this kind of pages aren't decoded correctly | 193 // part, then this kind of html documents aren't decoded correctly |
193 // because of this issue. So when we serialize the DOM, we need to | 194 // because of this issue. So when we serialize the DOM, we need to make |
194 // make sure the meta will in first child of head tag. | 195 // sure the meta will in first child of head tag. |
195 // See http://bugs.webkit.org/show_bug.cgi?id=16621. | 196 // See http://bugs.webkit.org/show_bug.cgi?id=16621. |
196 // First we generate new content for writing correct META element. | 197 // First we generate new content for writing correct META element. |
197 result.append(WebPageSerializer::generateMetaCharsetDeclaration( | 198 result.append(WebFrameSerializer::generateMetaCharsetDeclaration( |
198 String(param->textEncoding.name()))); | 199 String(param->textEncoding.name()))); |
199 | 200 |
200 param->haveAddedContentsBeforeEnd = true; | 201 param->haveAddedContentsBeforeEnd = true; |
201 // Will search each META which has charset declaration, and skip them al
l | 202 // Will search each META which has charset declaration, and skip them al
l |
202 // in PreActionBeforeSerializeOpenTag. | 203 // in PreActionBeforeSerializeOpenTag. |
203 } else if (isHTMLScriptElement(*element) || isHTMLScriptElement(*element)) { | 204 } else if (isHTMLScriptElement(*element) || isHTMLScriptElement(*element)) { |
204 param->isInScriptOrStyleTag = true; | 205 param->isInScriptOrStyleTag = true; |
205 } | 206 } |
206 | 207 |
207 return result.toString(); | 208 return result.toString(); |
208 } | 209 } |
209 | 210 |
210 String WebPageSerializerImpl::preActionBeforeSerializeEndTag( | 211 String WebFrameSerializerImpl::preActionBeforeSerializeEndTag( |
211 const Element* element, SerializeDomParam* param, bool* needSkip) | 212 const Element* element, SerializeDomParam* param, bool* needSkip) |
212 { | 213 { |
213 String result; | 214 String result; |
214 | 215 |
215 *needSkip = false; | 216 *needSkip = false; |
216 if (!param->isHTMLDocument) | 217 if (!param->isHTMLDocument) |
217 return result; | 218 return result; |
218 // Skip the end tag of original META tag which declare charset. | 219 // Skip the end tag of original META tag which declare charset. |
219 // Need not to check whether it's META tag since we guarantee | 220 // Need not to check whether it's META tag since we guarantee |
220 // skipMetaElement is definitely META tag if it's not 0. | 221 // skipMetaElement is definitely META tag if it's not 0. |
221 if (param->skipMetaElement == element) { | 222 if (param->skipMetaElement == element) { |
222 *needSkip = true; | 223 *needSkip = true; |
223 } else if (isHTMLScriptElement(*element) || isHTMLScriptElement(*element)) { | 224 } else if (isHTMLScriptElement(*element) || isHTMLScriptElement(*element)) { |
224 ASSERT(param->isInScriptOrStyleTag); | 225 ASSERT(param->isInScriptOrStyleTag); |
225 param->isInScriptOrStyleTag = false; | 226 param->isInScriptOrStyleTag = false; |
226 } | 227 } |
227 | 228 |
228 return result; | 229 return result; |
229 } | 230 } |
230 | 231 |
231 // After we finish serializing end tag of a element, we give the target | 232 // After we finish serializing end tag of a element, we give the target |
232 // element a chance to do some post work to add some additional data. | 233 // element a chance to do some post work to add some additional data. |
233 String WebPageSerializerImpl::postActionAfterSerializeEndTag( | 234 String WebFrameSerializerImpl::postActionAfterSerializeEndTag( |
234 const Element* element, SerializeDomParam* param) | 235 const Element* element, SerializeDomParam* param) |
235 { | 236 { |
236 StringBuilder result; | 237 StringBuilder result; |
237 | 238 |
238 if (!param->isHTMLDocument) | 239 if (!param->isHTMLDocument) |
239 return result.toString(); | 240 return result.toString(); |
240 // Comment the BASE tag when serializing DOM. | 241 // Comment the BASE tag when serializing DOM. |
241 if (isHTMLBaseElement(*element)) { | 242 if (isHTMLBaseElement(*element)) { |
242 result.appendLiteral("-->"); | 243 result.appendLiteral("-->"); |
243 // Append a new base tag declaration. | 244 // Append a new base tag declaration. |
244 result.append(WebPageSerializer::generateBaseTagDeclaration( | 245 result.append(WebFrameSerializer::generateBaseTagDeclaration( |
245 param->document->baseTarget())); | 246 param->document->baseTarget())); |
246 } | 247 } |
247 | 248 |
248 return result.toString(); | 249 return result.toString(); |
249 } | 250 } |
250 | 251 |
251 void WebPageSerializerImpl::saveHTMLContentToBuffer( | 252 void WebFrameSerializerImpl::saveHTMLContentToBuffer( |
252 const String& result, SerializeDomParam* param) | 253 const String& result, SerializeDomParam* param) |
253 { | 254 { |
254 m_dataBuffer.append(result); | 255 m_dataBuffer.append(result); |
255 encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsNotFinished, | 256 encodeAndFlushBuffer( |
256 param, | 257 WebFrameSerializerClient::CurrentFrameIsNotFinished, |
257 DoNotForceFlush); | 258 param, |
| 259 DoNotForceFlush); |
258 } | 260 } |
259 | 261 |
260 void WebPageSerializerImpl::encodeAndFlushBuffer( | 262 void WebFrameSerializerImpl::encodeAndFlushBuffer( |
261 WebPageSerializerClient::PageSerializationStatus status, | 263 WebFrameSerializerClient::FrameSerializationStatus status, |
262 SerializeDomParam* param, | 264 SerializeDomParam* param, |
263 FlushOption flushOption) | 265 FlushOption flushOption) |
264 { | 266 { |
265 // Data buffer is not full nor do we want to force flush. | 267 // Data buffer is not full nor do we want to force flush. |
266 if (flushOption != ForceFlush && m_dataBuffer.length() <= dataBufferCapacity
) | 268 if (flushOption != ForceFlush && m_dataBuffer.length() <= dataBufferCapacity
) |
267 return; | 269 return; |
268 | 270 |
269 String content = m_dataBuffer.toString(); | 271 String content = m_dataBuffer.toString(); |
270 m_dataBuffer.clear(); | 272 m_dataBuffer.clear(); |
271 | 273 |
272 CString encodedContent = param->textEncoding.encode(content, WTF::EntitiesFo
rUnencodables); | 274 CString encodedContent = param->textEncoding.encode(content, WTF::EntitiesFo
rUnencodables); |
273 | 275 |
274 // Send result to the client. | 276 // Send result to the client. |
275 m_client->didSerializeDataForFrame(WebCString(encodedContent), status); | 277 m_client->didSerializeDataForFrame(WebCString(encodedContent), status); |
276 } | 278 } |
277 | 279 |
278 // TODO(yosin): We should utilize |MarkupFormatter| here to share code, | 280 // TODO(yosin): We should utilize |MarkupFormatter| here to share code, |
279 // especially escaping attribute values, done by |WebEntities| |m_htmlEntities| | 281 // especially escaping attribute values, done by |WebEntities| |m_htmlEntities| |
280 // and |m_xmlEntities|. | 282 // and |m_xmlEntities|. |
281 void WebPageSerializerImpl::openTagToString(Element* element, | 283 void WebFrameSerializerImpl::openTagToString( |
282 SerializeDomParam* param) | 284 Element* element, |
| 285 SerializeDomParam* param) |
283 { | 286 { |
284 bool needSkip; | 287 bool needSkip; |
285 StringBuilder result; | 288 StringBuilder result; |
286 // Do pre action for open tag. | 289 // Do pre action for open tag. |
287 result.append(preActionBeforeSerializeOpenTag(element, param, &needSkip)); | 290 result.append(preActionBeforeSerializeOpenTag(element, param, &needSkip)); |
288 if (needSkip) | 291 if (needSkip) |
289 return; | 292 return; |
290 // Add open tag | 293 // Add open tag |
291 result.append('<'); | 294 result.append('<'); |
292 result.append(element->nodeName().lower()); | 295 result.append(element->nodeName().lower()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 // Complete the open tag for element when it has child/children. | 336 // Complete the open tag for element when it has child/children. |
334 if (element->hasChildren() || param->haveAddedContentsBeforeEnd) | 337 if (element->hasChildren() || param->haveAddedContentsBeforeEnd) |
335 result.append('>'); | 338 result.append('>'); |
336 // Append the added contents generate in post action of open tag. | 339 // Append the added contents generate in post action of open tag. |
337 result.append(addedContents); | 340 result.append(addedContents); |
338 // Save the result to data buffer. | 341 // Save the result to data buffer. |
339 saveHTMLContentToBuffer(result.toString(), param); | 342 saveHTMLContentToBuffer(result.toString(), param); |
340 } | 343 } |
341 | 344 |
342 // Serialize end tag of an specified element. | 345 // Serialize end tag of an specified element. |
343 void WebPageSerializerImpl::endTagToString(Element* element, | 346 void WebFrameSerializerImpl::endTagToString( |
344 SerializeDomParam* param) | 347 Element* element, |
| 348 SerializeDomParam* param) |
345 { | 349 { |
346 bool needSkip; | 350 bool needSkip; |
347 StringBuilder result; | 351 StringBuilder result; |
348 // Do pre action for end tag. | 352 // Do pre action for end tag. |
349 result.append(preActionBeforeSerializeEndTag(element, param, &needSkip)); | 353 result.append(preActionBeforeSerializeEndTag(element, param, &needSkip)); |
350 if (needSkip) | 354 if (needSkip) |
351 return; | 355 return; |
352 // Write end tag when element has child/children. | 356 // Write end tag when element has child/children. |
353 if (element->hasChildren() || param->haveAddedContentsBeforeEnd) { | 357 if (element->hasChildren() || param->haveAddedContentsBeforeEnd) { |
354 result.appendLiteral("</"); | 358 result.appendLiteral("</"); |
355 result.append(element->nodeName().lower()); | 359 result.append(element->nodeName().lower()); |
356 result.append('>'); | 360 result.append('>'); |
357 } else { | 361 } else { |
358 // Check whether we have to write end tag for empty element. | 362 // Check whether we have to write end tag for empty element. |
359 if (param->isHTMLDocument) { | 363 if (param->isHTMLDocument) { |
360 result.append('>'); | 364 result.append('>'); |
361 // FIXME: This code is horribly wrong. WebPageSerializerImpl must d
ie. | 365 // FIXME: This code is horribly wrong. WebFrameSerializerImpl must
die. |
362 if (!element->isHTMLElement() || !toHTMLElement(element)->ieForbidsI
nsertHTML()) { | 366 if (!element->isHTMLElement() || !toHTMLElement(element)->ieForbidsI
nsertHTML()) { |
363 // We need to write end tag when it is required. | 367 // We need to write end tag when it is required. |
364 result.appendLiteral("</"); | 368 result.appendLiteral("</"); |
365 result.append(element->nodeName().lower()); | 369 result.append(element->nodeName().lower()); |
366 result.append('>'); | 370 result.append('>'); |
367 } | 371 } |
368 } else { | 372 } else { |
369 // For xml base document. | 373 // For xml base document. |
370 result.appendLiteral(" />"); | 374 result.appendLiteral(" />"); |
371 } | 375 } |
372 } | 376 } |
373 // Do post action for end tag. | 377 // Do post action for end tag. |
374 result.append(postActionAfterSerializeEndTag(element, param)); | 378 result.append(postActionAfterSerializeEndTag(element, param)); |
375 // Save the result to data buffer. | 379 // Save the result to data buffer. |
376 saveHTMLContentToBuffer(result.toString(), param); | 380 saveHTMLContentToBuffer(result.toString(), param); |
377 } | 381 } |
378 | 382 |
379 void WebPageSerializerImpl::buildContentForNode(Node* node, | 383 void WebFrameSerializerImpl::buildContentForNode( |
380 SerializeDomParam* param) | 384 Node* node, |
| 385 SerializeDomParam* param) |
381 { | 386 { |
382 switch (node->nodeType()) { | 387 switch (node->nodeType()) { |
383 case Node::ELEMENT_NODE: | 388 case Node::ELEMENT_NODE: |
384 // Process open tag of element. | 389 // Process open tag of element. |
385 openTagToString(toElement(node), param); | 390 openTagToString(toElement(node), param); |
386 // Walk through the children nodes and process it. | 391 // Walk through the children nodes and process it. |
387 for (Node *child = node->firstChild(); child; child = child->nextSibling
()) | 392 for (Node *child = node->firstChild(); child; child = child->nextSibling
()) |
388 buildContentForNode(child, param); | 393 buildContentForNode(child, param); |
389 // Process end tag of element. | 394 // Process end tag of element. |
390 endTagToString(toElement(node), param); | 395 endTagToString(toElement(node), param); |
(...skipping 10 matching lines...) Expand all Loading... |
401 // Document type node can be in DOM? | 406 // Document type node can be in DOM? |
402 case Node::DOCUMENT_TYPE_NODE: | 407 case Node::DOCUMENT_TYPE_NODE: |
403 param->haveSeenDocType = true; | 408 param->haveSeenDocType = true; |
404 default: | 409 default: |
405 // For other type node, call default action. | 410 // For other type node, call default action. |
406 saveHTMLContentToBuffer(createMarkup(node), param); | 411 saveHTMLContentToBuffer(createMarkup(node), param); |
407 break; | 412 break; |
408 } | 413 } |
409 } | 414 } |
410 | 415 |
411 WebPageSerializerImpl::WebPageSerializerImpl( | 416 WebFrameSerializerImpl::WebFrameSerializerImpl( |
412 WebLocalFrame* frame, | 417 WebLocalFrame* frame, |
413 WebPageSerializerClient* client, | 418 WebFrameSerializerClient* client, |
414 const WebVector<std::pair<WebURL, WebString>>& urlsToLocalPaths) | 419 const WebVector<std::pair<WebURL, WebString>>& urlsToLocalPaths) |
415 : m_client(client) | 420 : m_client(client) |
416 , m_htmlEntities(false) | 421 , m_htmlEntities(false) |
417 , m_xmlEntities(true) | 422 , m_xmlEntities(true) |
418 { | 423 { |
419 // Must specify available webframe. | 424 // Must specify available webframe. |
420 ASSERT(frame); | 425 ASSERT(frame); |
421 m_specifiedWebLocalFrameImpl = toWebLocalFrameImpl(frame); | 426 m_specifiedWebLocalFrameImpl = toWebLocalFrameImpl(frame); |
422 // Make sure we have non 0 client. | 427 // Make sure we have non 0 client. |
423 ASSERT(client); | 428 ASSERT(client); |
424 // Build local resources map. | 429 // Build local resources map. |
425 for (const auto& it : urlsToLocalPaths) { | 430 for (const auto& it : urlsToLocalPaths) { |
426 KURL url = it.first; | 431 KURL url = it.first; |
427 ASSERT(!m_localLinks.contains(url.string())); | 432 ASSERT(!m_localLinks.contains(url.string())); |
428 m_localLinks.set(url.string(), it.second); | 433 m_localLinks.set(url.string(), it.second); |
429 } | 434 } |
430 | 435 |
431 ASSERT(m_dataBuffer.isEmpty()); | 436 ASSERT(m_dataBuffer.isEmpty()); |
432 } | 437 } |
433 | 438 |
434 bool WebPageSerializerImpl::serialize() | 439 bool WebFrameSerializerImpl::serialize() |
435 { | 440 { |
436 bool didSerialization = false; | 441 bool didSerialization = false; |
437 | 442 |
438 Document* document = m_specifiedWebLocalFrameImpl->frame()->document(); | 443 Document* document = m_specifiedWebLocalFrameImpl->frame()->document(); |
439 const KURL& url = document->url(); | 444 const KURL& url = document->url(); |
440 | 445 |
441 if (url.isValid()) { | 446 if (url.isValid()) { |
442 didSerialization = true; | 447 didSerialization = true; |
443 | 448 |
444 const WTF::TextEncoding& textEncoding = document->encoding().isValid() ?
document->encoding() : UTF8Encoding(); | 449 const WTF::TextEncoding& textEncoding = document->encoding().isValid() ?
document->encoding() : UTF8Encoding(); |
445 if (textEncoding.isNonByteBasedEncoding()) { | 450 if (textEncoding.isNonByteBasedEncoding()) { |
446 const UChar byteOrderMark = 0xFEFF; | 451 const UChar byteOrderMark = 0xFEFF; |
447 m_dataBuffer.append(byteOrderMark); | 452 m_dataBuffer.append(byteOrderMark); |
448 } | 453 } |
449 | 454 |
450 SerializeDomParam param(url, textEncoding, document); | 455 SerializeDomParam param(url, textEncoding, document); |
451 | 456 |
452 Element* documentElement = document->documentElement(); | 457 Element* documentElement = document->documentElement(); |
453 if (documentElement) | 458 if (documentElement) |
454 buildContentForNode(documentElement, ¶m); | 459 buildContentForNode(documentElement, ¶m); |
455 | 460 |
456 encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, &p
aram, ForceFlush); | 461 encodeAndFlushBuffer(WebFrameSerializerClient::CurrentFrameIsFinished, &
param, ForceFlush); |
457 } else { | 462 } else { |
458 // Report empty contents for invalid URLs. | 463 // Report empty contents for invalid URLs. |
459 m_client->didSerializeDataForFrame( | 464 m_client->didSerializeDataForFrame( |
460 WebCString(), WebPageSerializerClient::CurrentFrameIsFinished); | 465 WebCString(), WebFrameSerializerClient::CurrentFrameIsFinished); |
461 } | 466 } |
462 | 467 |
463 ASSERT(m_dataBuffer.isEmpty()); | 468 ASSERT(m_dataBuffer.isEmpty()); |
464 return didSerialization; | 469 return didSerialization; |
465 } | 470 } |
466 | 471 |
467 } // namespace blink | 472 } // namespace blink |
OLD | NEW |