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

Side by Side Diff: third_party/WebKit/Source/web/WebPageSerializer.cpp

Issue 1436683002: Making PageSerializer operate on single frames only. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mhtml-removing-unused-code
Patch Set: Created 5 years, 1 month 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
OLDNEW
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 bool MHTMLPageSerializerDelegate::shouldIgnoreAttribute(const Attribute& attribu te) 77 bool MHTMLPageSerializerDelegate::shouldIgnoreAttribute(const Attribute& attribu te)
78 { 78 {
79 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display i mages, as only the value of src 79 // TODO(fgorski): Presence of srcset attribute causes MHTML to not display i mages, as only the value of src
80 // is pulled into the archive. Discarding srcset prevents the problem. Long term we should make sure to MHTML 80 // is pulled into the archive. Discarding srcset prevents the problem. Long term we should make sure to MHTML
81 // plays nicely with srcset. 81 // plays nicely with srcset.
82 return attribute.localName() == HTMLNames::srcsetAttr; 82 return attribute.localName() == HTMLNames::srcsetAttr;
83 } 83 }
84 84
85 } // namespace 85 } // namespace
86 86
87 static PassRefPtr<SharedBuffer> serializePageToMHTML(Page* page, MHTMLArchive::E ncodingPolicy encodingPolicy) 87 static PassRefPtr<SharedBuffer> serializePageToMHTML(Page* page, MHTMLArchive::E ncodingPolicy encodingPolicy)
dcheng 2015/11/12 23:47:32 Is this covered by any tests right now?
Łukasz Anforowicz 2015/11/13 00:22:10 If "this" = "serializePageToMHTML function", then
88 { 88 {
89 Vector<SerializedResource> resources; 89 Vector<SerializedResource> resources;
90 HashSet<KURL> alreadySerializedUrls;
90 PageSerializer serializer(&resources, adoptPtr(new MHTMLPageSerializerDelega te)); 91 PageSerializer serializer(&resources, adoptPtr(new MHTMLPageSerializerDelega te));
91 serializer.serialize(page); 92
93 RefPtr<SharedBuffer> output = SharedBuffer::create();
94 String boundary = MHTMLArchive::generateMHTMLBoundary();
95
92 Document* document = page->deprecatedLocalMainFrame()->document(); 96 Document* document = page->deprecatedLocalMainFrame()->document();
93 return MHTMLArchive::generateMHTMLData(resources, encodingPolicy, document-> title(), document->suggestedMIMEType()); 97 MHTMLArchive::generateMHTMLHeader(
98 boundary, document->title(), document->suggestedMIMEType(), *output);
99
100 Frame* frame = page->deprecatedLocalMainFrame();
101 for (; frame; frame = frame->tree().traverseNext()) {
102 // TODO(lukasza): This causes incomplete MHTML for OOPIFs.
103 // (crbug.com/538766)
104 if (!frame->isLocalFrame())
105 continue;
106
107 resources.clear();
108 serializer.serializeFrame(toLocalFrame(frame));
109
110 for (const auto& resource : resources) {
111 if (alreadySerializedUrls.contains(resource.url))
112 continue;
113 alreadySerializedUrls.add(resource.url);
114
115 MHTMLArchive::generateMHTMLPart(
116 boundary, encodingPolicy, resource, *output);
117 }
118 }
119
120 MHTMLArchive::generateMHTMLFooter(boundary, *output);
121 return output.release();
94 } 122 }
95 123
96 WebCString WebPageSerializer::serializeToMHTML(WebView* view) 124 WebCString WebPageSerializer::serializeToMHTML(WebView* view)
97 { 125 {
98 RefPtr<SharedBuffer> mhtml = serializePageToMHTML(toWebViewImpl(view)->page( ), MHTMLArchive::UseDefaultEncoding); 126 RefPtr<SharedBuffer> mhtml = serializePageToMHTML(toWebViewImpl(view)->page( ), MHTMLArchive::UseDefaultEncoding);
99 // FIXME: we are copying all the data here. Idealy we would have a WebShared Data(). 127 // FIXME: we are copying all the data here. Idealy we would have a WebShared Data().
100 return WebCString(mhtml->data(), mhtml->size()); 128 return WebCString(mhtml->data(), mhtml->size());
101 } 129 }
102 130
103 WebCString WebPageSerializer::serializeToMHTMLUsingBinaryEncoding(WebView* view) 131 WebCString WebPageSerializer::serializeToMHTMLUsingBinaryEncoding(WebView* view)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 WebString WebPageSerializer::generateBaseTagDeclaration(const WebString& baseTar get) 165 WebString WebPageSerializer::generateBaseTagDeclaration(const WebString& baseTar get)
138 { 166 {
139 // TODO(yosin) We should call |PageSerializer::baseTagDeclarationOf()|. 167 // TODO(yosin) We should call |PageSerializer::baseTagDeclarationOf()|.
140 if (baseTarget.isEmpty()) 168 if (baseTarget.isEmpty())
141 return String("<base href=\".\">"); 169 return String("<base href=\".\">");
142 String baseString = "<base href=\".\" target=\"" + static_cast<const String& >(baseTarget) + "\">"; 170 String baseString = "<base href=\".\" target=\"" + static_cast<const String& >(baseTarget) + "\">";
143 return baseString; 171 return baseString;
144 } 172 }
145 173
146 } // namespace blink 174 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698