| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 #include "core/html/HTMLFrameElementBase.h" | 53 #include "core/html/HTMLFrameElementBase.h" |
| 54 #include "core/html/HTMLImageElement.h" | 54 #include "core/html/HTMLImageElement.h" |
| 55 #include "core/html/HTMLInputElement.h" | 55 #include "core/html/HTMLInputElement.h" |
| 56 #include "core/html/HTMLLinkElement.h" | 56 #include "core/html/HTMLLinkElement.h" |
| 57 #include "core/html/HTMLMetaElement.h" | 57 #include "core/html/HTMLMetaElement.h" |
| 58 #include "core/html/HTMLStyleElement.h" | 58 #include "core/html/HTMLStyleElement.h" |
| 59 #include "core/html/ImageDocument.h" | 59 #include "core/html/ImageDocument.h" |
| 60 #include "core/style/StyleFetchedImage.h" | 60 #include "core/style/StyleFetchedImage.h" |
| 61 #include "core/style/StyleImage.h" | 61 #include "core/style/StyleImage.h" |
| 62 #include "platform/SerializedResource.h" | 62 #include "platform/SerializedResource.h" |
| 63 #include "platform/TraceEvent.h" |
| 63 #include "platform/graphics/Image.h" | 64 #include "platform/graphics/Image.h" |
| 64 #include "platform/heap/Handle.h" | 65 #include "platform/heap/Handle.h" |
| 65 #include "wtf/HashSet.h" | 66 #include "wtf/HashSet.h" |
| 66 #include "wtf/text/CString.h" | 67 #include "wtf/text/CString.h" |
| 67 #include "wtf/text/StringBuilder.h" | 68 #include "wtf/text/StringBuilder.h" |
| 68 #include "wtf/text/TextEncoding.h" | 69 #include "wtf/text/TextEncoding.h" |
| 69 #include "wtf/text/WTFString.h" | 70 #include "wtf/text/WTFString.h" |
| 70 | 71 |
| 71 namespace blink { | 72 namespace blink { |
| 72 | 73 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 FrameSerializer::FrameSerializer( | 242 FrameSerializer::FrameSerializer( |
| 242 Vector<SerializedResource>& resources, | 243 Vector<SerializedResource>& resources, |
| 243 Delegate& delegate) | 244 Delegate& delegate) |
| 244 : m_resources(&resources) | 245 : m_resources(&resources) |
| 245 , m_delegate(delegate) | 246 , m_delegate(delegate) |
| 246 { | 247 { |
| 247 } | 248 } |
| 248 | 249 |
| 249 void FrameSerializer::serializeFrame(const LocalFrame& frame) | 250 void FrameSerializer::serializeFrame(const LocalFrame& frame) |
| 250 { | 251 { |
| 252 TRACE_EVENT0("page-serialization", "FrameSerializer::serializeFrame"); |
| 251 ASSERT(frame.document()); | 253 ASSERT(frame.document()); |
| 252 Document& document = *frame.document(); | 254 Document& document = *frame.document(); |
| 253 KURL url = document.url(); | 255 KURL url = document.url(); |
| 254 | 256 |
| 255 // If frame is an image document, add the image and don't continue | 257 // If frame is an image document, add the image and don't continue |
| 256 if (document.isImageDocument()) { | 258 if (document.isImageDocument()) { |
| 257 ImageDocument& imageDocument = toImageDocument(document); | 259 ImageDocument& imageDocument = toImageDocument(document); |
| 258 addImageToResources(imageDocument.cachedImage(), url); | 260 addImageToResources(imageDocument.cachedImage(), url); |
| 259 return; | 261 return; |
| 260 } | 262 } |
| 261 | 263 |
| 264 TRACE_EVENT_BEGIN0("page-serialization", "FrameSerializer::serializeFrame HT
ML"); |
| 262 HeapVector<Member<Node>> serializedNodes; | 265 HeapVector<Member<Node>> serializedNodes; |
| 263 SerializerMarkupAccumulator accumulator(m_delegate, document, serializedNode
s); | 266 SerializerMarkupAccumulator accumulator(m_delegate, document, serializedNode
s); |
| 264 String text = serializeNodes<EditingStrategy>(accumulator, document, Include
Node); | 267 String text = serializeNodes<EditingStrategy>(accumulator, document, Include
Node); |
| 265 | 268 |
| 266 CString frameHTML = document.encoding().encode(text, WTF::EntitiesForUnencod
ables); | 269 CString frameHTML = document.encoding().encode(text, WTF::EntitiesForUnencod
ables); |
| 267 m_resources->append(SerializedResource(url, document.suggestedMIMEType(), Sh
aredBuffer::create(frameHTML.data(), frameHTML.length()))); | 270 m_resources->append(SerializedResource(url, document.suggestedMIMEType(), Sh
aredBuffer::create(frameHTML.data(), frameHTML.length()))); |
| 271 TRACE_EVENT_END0("page-serialization", "FrameSerializer::serializeFrame HTML
"); |
| 268 | 272 |
| 269 for (Node* node: serializedNodes) { | 273 for (Node* node: serializedNodes) { |
| 270 ASSERT(node); | 274 ASSERT(node); |
| 271 if (!node->isElementNode()) | 275 if (!node->isElementNode()) |
| 272 continue; | 276 continue; |
| 273 | 277 |
| 274 Element& element = toElement(*node); | 278 Element& element = toElement(*node); |
| 275 // We have to process in-line style as it might contain some resources (
typically background images). | 279 // We have to process in-line style as it might contain some resources (
typically background images). |
| 276 if (element.isStyledElement()) { | 280 if (element.isStyledElement()) { |
| 277 retrieveResourcesForProperties(element.inlineStyle(), document); | 281 retrieveResourcesForProperties(element.inlineStyle(), document); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 299 } else if (isHTMLStyleElement(element)) { | 303 } else if (isHTMLStyleElement(element)) { |
| 300 HTMLStyleElement& styleElement = toHTMLStyleElement(element); | 304 HTMLStyleElement& styleElement = toHTMLStyleElement(element); |
| 301 if (CSSStyleSheet* sheet = styleElement.sheet()) | 305 if (CSSStyleSheet* sheet = styleElement.sheet()) |
| 302 serializeCSSStyleSheet(*sheet, KURL()); | 306 serializeCSSStyleSheet(*sheet, KURL()); |
| 303 } | 307 } |
| 304 } | 308 } |
| 305 } | 309 } |
| 306 | 310 |
| 307 void FrameSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, const KU
RL& url) | 311 void FrameSerializer::serializeCSSStyleSheet(CSSStyleSheet& styleSheet, const KU
RL& url) |
| 308 { | 312 { |
| 313 TRACE_EVENT2("page-serialization", "FrameSerializer::serializeCSSStyleSheet"
, |
| 314 "type", "CSS", "url", url.elidedString().utf8().data()); |
| 309 StringBuilder cssText; | 315 StringBuilder cssText; |
| 310 cssText.append("@charset \""); | 316 cssText.append("@charset \""); |
| 311 cssText.append(styleSheet.contents()->charset().lower()); | 317 cssText.append(styleSheet.contents()->charset().lower()); |
| 312 cssText.append("\";\n\n"); | 318 cssText.append("\";\n\n"); |
| 313 | 319 |
| 314 for (unsigned i = 0; i < styleSheet.length(); ++i) { | 320 for (unsigned i = 0; i < styleSheet.length(); ++i) { |
| 315 CSSRule* rule = styleSheet.item(i); | 321 CSSRule* rule = styleSheet.item(i); |
| 316 String itemText = rule->cssText(); | 322 String itemText = rule->cssText(); |
| 317 if (!itemText.isEmpty()) { | 323 if (!itemText.isEmpty()) { |
| 318 cssText.append(itemText); | 324 cssText.append(itemText); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 String mimeType = resource.response().mimeType(); | 405 String mimeType = resource.response().mimeType(); |
| 400 m_resources->append(SerializedResource(url, mimeType, std::move(data))); | 406 m_resources->append(SerializedResource(url, mimeType, std::move(data))); |
| 401 m_resourceURLs.add(url); | 407 m_resourceURLs.add(url); |
| 402 } | 408 } |
| 403 | 409 |
| 404 void FrameSerializer::addImageToResources(ImageResource* image, const KURL& url) | 410 void FrameSerializer::addImageToResources(ImageResource* image, const KURL& url) |
| 405 { | 411 { |
| 406 if (!image || !image->hasImage() || image->errorOccurred() || !shouldAddURL(
url)) | 412 if (!image || !image->hasImage() || image->errorOccurred() || !shouldAddURL(
url)) |
| 407 return; | 413 return; |
| 408 | 414 |
| 415 TRACE_EVENT2("page-serialization", "FrameSerializer::addImageToResources", |
| 416 "type", "image", "url", url.elidedString().utf8().data()); |
| 409 RefPtr<const SharedBuffer> data = image->getImage()->data(); | 417 RefPtr<const SharedBuffer> data = image->getImage()->data(); |
| 410 addToResources(*image, data, url); | 418 addToResources(*image, data, url); |
| 411 } | 419 } |
| 412 | 420 |
| 413 void FrameSerializer::addFontToResources(FontResource* font) | 421 void FrameSerializer::addFontToResources(FontResource* font) |
| 414 { | 422 { |
| 415 if (!font || !font->isLoaded() || !font->resourceBuffer() || !shouldAddURL(f
ont->url())) | 423 if (!font || !font->isLoaded() || !font->resourceBuffer() || !shouldAddURL(f
ont->url())) |
| 416 return; | 424 return; |
| 417 | 425 |
| 418 RefPtr<const SharedBuffer> data(font->resourceBuffer()); | 426 RefPtr<const SharedBuffer> data(font->resourceBuffer()); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 continue; | 484 continue; |
| 477 } | 485 } |
| 478 emitsMinus = ch == '-'; | 486 emitsMinus = ch == '-'; |
| 479 builder.append(ch); | 487 builder.append(ch); |
| 480 } | 488 } |
| 481 CString escapedUrl = builder.toString().ascii(); | 489 CString escapedUrl = builder.toString().ascii(); |
| 482 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl
.length()), escapedUrl.data()); | 490 return String::format("saved from url=(%04d)%s", static_cast<int>(escapedUrl
.length()), escapedUrl.data()); |
| 483 } | 491 } |
| 484 | 492 |
| 485 } // namespace blink | 493 } // namespace blink |
| OLD | NEW |