Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: Source/core/page/PageSerializer.cpp

Issue 1167413004: Merge page serializers [4/12] (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix nits Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Source/web/tests/PageSerializerTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "core/editing/MarkupAccumulator.h" 49 #include "core/editing/MarkupAccumulator.h"
50 #include "core/fetch/FontResource.h" 50 #include "core/fetch/FontResource.h"
51 #include "core/fetch/ImageResource.h" 51 #include "core/fetch/ImageResource.h"
52 #include "core/frame/LocalFrame.h" 52 #include "core/frame/LocalFrame.h"
53 #include "core/html/HTMLFrameOwnerElement.h" 53 #include "core/html/HTMLFrameOwnerElement.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/parser/HTMLParserIdioms.h" 60 #include "core/html/parser/HTMLParserIdioms.h"
61 #include "core/page/Page.h"
60 #include "core/style/StyleFetchedImage.h" 62 #include "core/style/StyleFetchedImage.h"
61 #include "core/style/StyleImage.h" 63 #include "core/style/StyleImage.h"
62 #include "core/page/Page.h"
63 #include "platform/SerializedResource.h" 64 #include "platform/SerializedResource.h"
64 #include "platform/graphics/Image.h" 65 #include "platform/graphics/Image.h"
65 #include "wtf/OwnPtr.h" 66 #include "wtf/OwnPtr.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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 url = urlForBlankFrame(frame); 220 url = urlForBlankFrame(frame);
220 } 221 }
221 222
222 if (m_resourceURLs.contains(url)) { 223 if (m_resourceURLs.contains(url)) {
223 // FIXME: We could have 2 frame with the same URL but which were dynamic ally changed and have now 224 // FIXME: We could have 2 frame with the same URL but which were dynamic ally changed and have now
224 // different content. So we should serialize both and somehow rename the frame src in the containing 225 // different content. So we should serialize both and somehow rename the frame src in the containing
225 // frame. Arg! 226 // frame. Arg!
226 return; 227 return;
227 } 228 }
228 229
229 WTF::TextEncoding textEncoding(document.charset()); 230 // If frame is an image document, add the image and don't continue
230 if (!textEncoding.isValid()) { 231 if (document.isImageDocument()) {
231 // FIXME: iframes used as images trigger this. We should deal with them correctly. 232 ImageDocument& imageDocument = toImageDocument(document);
233 addImageToResources(imageDocument.cachedImage(), imageDocument.imageElem ent()->layoutObject(), url);
232 return; 234 return;
233 } 235 }
234 236
235 WillBeHeapVector<RawPtrWillBeMember<Node>> serializedNodes; 237 WillBeHeapVector<RawPtrWillBeMember<Node>> serializedNodes;
236 SerializerMarkupAccumulator accumulator(this, document, serializedNodes); 238 SerializerMarkupAccumulator accumulator(this, document, serializedNodes);
237 String text = serializeNodes<EditingStrategy>(accumulator, document, Include Node); 239 String text = serializeNodes<EditingStrategy>(accumulator, document, Include Node);
238 CString frameHTML = textEncoding.normalizeAndEncode(text, WTF::EntitiesForUn encodables); 240 CString frameHTML = document.encoding().normalizeAndEncode(text, WTF::Entiti esForUnencodables);
239 m_resources->append(SerializedResource(url, document.suggestedMIMEType(), Sh aredBuffer::create(frameHTML.data(), frameHTML.length()))); 241 m_resources->append(SerializedResource(url, document.suggestedMIMEType(), Sh aredBuffer::create(frameHTML.data(), frameHTML.length())));
240 m_resourceURLs.add(url); 242 m_resourceURLs.add(url);
241 243
242 for (Node* node: serializedNodes) { 244 for (Node* node: serializedNodes) {
243 ASSERT(node); 245 ASSERT(node);
244 if (!node->isElementNode()) 246 if (!node->isElementNode())
245 continue; 247 continue;
246 248
247 Element& element = toElement(*node); 249 Element& element = toElement(*node);
248 // We have to process in-line style as it might contain some resources ( typically background images). 250 // We have to process in-line style as it might contain some resources ( typically background images).
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 String mimeType = resource->response().mimeType(); 338 String mimeType = resource->response().mimeType();
337 m_resources->append(SerializedResource(url, mimeType, data)); 339 m_resources->append(SerializedResource(url, mimeType, data));
338 m_resourceURLs.add(url); 340 m_resourceURLs.add(url);
339 } 341 }
340 342
341 void PageSerializer::addImageToResources(ImageResource* image, LayoutObject* ima geLayoutObject, const KURL& url) 343 void PageSerializer::addImageToResources(ImageResource* image, LayoutObject* ima geLayoutObject, const KURL& url)
342 { 344 {
343 if (!shouldAddURL(url)) 345 if (!shouldAddURL(url))
344 return; 346 return;
345 347
346 if (!image || image->image() == Image::nullImage() || image->errorOccurred() ) 348 if (!image || !image->hasImage() || image->errorOccurred())
347 return; 349 return;
348 350
349 RefPtr<SharedBuffer> data = imageLayoutObject ? image->imageForLayoutObject( imageLayoutObject)->data() : nullptr; 351 RefPtr<SharedBuffer> data = imageLayoutObject ? image->imageForLayoutObject( imageLayoutObject)->data() : nullptr;
350 if (!data) 352 if (!data)
351 data = image->image()->data(); 353 data = image->image()->data();
352 354
353 addToResources(image, data, url); 355 addToResources(image, data, url);
354 } 356 }
355 357
356 void PageSerializer::addFontToResources(FontResource* font) 358 void PageSerializer::addFontToResources(FontResource* font)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 415
414 return fakeURL; 416 return fakeURL;
415 } 417 }
416 418
417 PageSerializer::Delegate* PageSerializer::delegate() 419 PageSerializer::Delegate* PageSerializer::delegate()
418 { 420 {
419 return m_delegate.get(); 421 return m_delegate.get();
420 } 422 }
421 423
422 } // namespace blink 424 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/web/tests/PageSerializerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698