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

Unified Diff: third_party/WebKit/Source/web/WebPageSerializer.cpp

Issue 1386873003: OOPIFs: Transitioning MHTML generation from view-oriented to frame-oriented. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mhtml-generation-mgr-cleanup
Patch Set: Rebasing... Created 5 years 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/web/WebPageSerializer.cpp
diff --git a/third_party/WebKit/Source/web/WebPageSerializer.cpp b/third_party/WebKit/Source/web/WebPageSerializer.cpp
index 501cb39b75a8879c5e99d2228c0265b63df5b420..5e0e3fec455dbc5cec720af033f99c25a4b4ca0e 100644
--- a/third_party/WebKit/Source/web/WebPageSerializer.cpp
+++ b/third_party/WebKit/Source/web/WebPageSerializer.cpp
@@ -34,16 +34,18 @@
#include "core/HTMLNames.h"
#include "core/dom/Document.h"
#include "core/dom/Element.h"
+#include "core/frame/Frame.h"
#include "core/frame/LocalFrame.h"
+#include "core/frame/RemoteFrame.h"
#include "core/html/HTMLAllCollection.h"
#include "core/html/HTMLFrameElementBase.h"
#include "core/html/HTMLFrameOwnerElement.h"
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLTableElement.h"
#include "core/loader/DocumentLoader.h"
-#include "core/page/Page.h"
#include "core/page/PageSerializer.h"
#include "platform/SerializedResource.h"
+#include "platform/SharedBuffer.h"
#include "platform/mhtml/MHTMLArchive.h"
#include "platform/mhtml/MHTMLParser.h"
#include "platform/weborigin/KURL.h"
@@ -51,14 +53,15 @@
#include "public/platform/WebString.h"
#include "public/platform/WebURL.h"
#include "public/platform/WebVector.h"
+#include "public/web/WebDocument.h"
#include "public/web/WebFrame.h"
#include "public/web/WebPageSerializerClient.h"
-#include "public/web/WebView.h"
#include "web/WebLocalFrameImpl.h"
#include "web/WebPageSerializerImpl.h"
-#include "web/WebViewImpl.h"
+#include "web/WebRemoteFrameImpl.h"
#include "wtf/Assertions.h"
#include "wtf/HashMap.h"
+#include "wtf/HashSet.h"
#include "wtf/Noncopyable.h"
#include "wtf/Vector.h"
#include "wtf/text/StringConcatenate.h"
@@ -133,77 +136,82 @@ bool MHTMLPageSerializerDelegate::rewriteLink(
return false;
}
-ContentIDMap generateFrameContentIDs(Page* page)
+ContentIDMap createFrameToContentIDMap(
+ const WebVector<std::pair<WebFrame*, WebString>>& webFrameToContentID)
{
- ContentIDMap frameToContentID;
- int frameID = 0;
- for (Frame* frame = page->mainFrame(); frame; frame = frame->tree().traverseNext()) {
- // TODO(lukasza): Move cid generation to the browser + use base/guid.h
- // (see the draft at crrev.com/1386873003).
- StringBuilder contentIDBuilder;
- contentIDBuilder.appendLiteral("<frame");
- contentIDBuilder.appendNumber(frameID++);
- contentIDBuilder.appendLiteral("@mhtml.blink>");
-
- frameToContentID.add(frame, contentIDBuilder.toString());
+ ContentIDMap result;
+ for (const auto& it : webFrameToContentID) {
+ WebFrame* webFrame = it.first;
+ const WebString& webContentID = it.second;
+
+ Frame* frame = webFrame->isWebLocalFrame()
+ ? static_cast<Frame*>(toWebLocalFrameImpl(webFrame)->frame())
+ : static_cast<Frame*>(toWebRemoteFrameImpl(webFrame)->frame());
+ String contentID(webContentID);
+
+ result.add(frame, contentID);
}
- return frameToContentID;
+ return result;
}
-PassRefPtr<SharedBuffer> serializePageToMHTML(Page* page, MHTMLArchive::EncodingPolicy encodingPolicy)
+} // namespace
+
+WebString WebPageSerializer::generateMHTMLBoundary()
{
- Vector<SerializedResource> resources;
- ContentIDMap frameToContentID = generateFrameContentIDs(page);
- MHTMLPageSerializerDelegate delegate(frameToContentID);
- PageSerializer serializer(resources, &delegate);
+ return MHTMLArchive::generateMHTMLBoundary();
+}
- RefPtr<SharedBuffer> output = SharedBuffer::create();
- String boundary = MHTMLArchive::generateMHTMLBoundary();
+WebData WebPageSerializer::generateMHTMLHeader(
+ const WebString& boundary, WebLocalFrame* topLevelFrame)
+{
+ Document* document = toWebLocalFrameImpl(topLevelFrame)->frame()->document();
- Document* document = page->deprecatedLocalMainFrame()->document();
+ RefPtr<SharedBuffer> buffer = SharedBuffer::create();
MHTMLArchive::generateMHTMLHeader(
- boundary, document->title(), document->suggestedMIMEType(), *output);
-
- for (Frame* frame = page->deprecatedLocalMainFrame(); frame; frame = frame->tree().traverseNext()) {
- // TODO(lukasza): This causes incomplete MHTML for OOPIFs.
- // (crbug.com/538766)
- if (!frame->isLocalFrame())
- continue;
+ boundary, document->title(), document->suggestedMIMEType(),
+ *buffer);
+ return PassRefPtr<SharedBuffer>(buffer);
+}
- resources.clear();
- serializer.serializeFrame(*toLocalFrame(frame));
+WebData WebPageSerializer::generateMHTMLParts(
+ const WebString& boundary, WebLocalFrame* webFrame, bool useBinaryEncoding,
+ const WebVector<std::pair<WebFrame*, WebString>>& webFrameToContentID)
+{
+ // Translate arguments from public to internal blink APIs.
+ LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame();
+ MHTMLArchive::EncodingPolicy encodingPolicy = useBinaryEncoding
+ ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding
+ : MHTMLArchive::EncodingPolicy::UseDefaultEncoding;
+ ContentIDMap frameToContentID =
+ createFrameToContentIDMap(webFrameToContentID);
+
+ // Serialize.
+ Vector<SerializedResource> resources;
+ MHTMLPageSerializerDelegate delegate(frameToContentID);
+ PageSerializer serializer(resources, &delegate);
+ serializer.serializeFrame(*frame);
- bool isFirstResource = true;
- for (const SerializedResource& resource : resources) {
- // Frame is the 1st resource (see PageSerializer::serializeFrame doc
- // comment). Frames need a Content-ID header.
- String contentID = isFirstResource ? frameToContentID.get(frame) : String();
+ // Encode serializer's output as MHTML.
+ RefPtr<SharedBuffer> output = SharedBuffer::create();
+ bool isFirstResource = true;
+ for (const SerializedResource& resource : resources) {
+ // Frame is the 1st resource (see PageSerializer::serializeFrame doc
+ // comment). Frames need a Content-ID header.
+ String contentID = isFirstResource ? frameToContentID.get(frame) : String();
- MHTMLArchive::generateMHTMLPart(
- boundary, contentID, encodingPolicy, resource, *output);
+ MHTMLArchive::generateMHTMLPart(
+ boundary, contentID, encodingPolicy, resource, *output);
- isFirstResource = false;
- }
+ isFirstResource = false;
}
-
- MHTMLArchive::generateMHTMLFooter(boundary, *output);
return output.release();
}
-} // namespace
-
-WebCString WebPageSerializer::serializeToMHTML(WebView* view)
-{
- RefPtr<SharedBuffer> mhtml = serializePageToMHTML(toWebViewImpl(view)->page(), MHTMLArchive::UseDefaultEncoding);
- // FIXME: we are copying all the data here. Idealy we would have a WebSharedData().
- return WebCString(mhtml->data(), mhtml->size());
-}
-
-WebCString WebPageSerializer::serializeToMHTMLUsingBinaryEncoding(WebView* view)
+WebData WebPageSerializer::generateMHTMLFooter(const WebString& boundary)
{
- RefPtr<SharedBuffer> mhtml = serializePageToMHTML(toWebViewImpl(view)->page(), MHTMLArchive::UseBinaryEncoding);
- // FIXME: we are copying all the data here. Idealy we would have a WebSharedData().
- return WebCString(mhtml->data(), mhtml->size());
+ RefPtr<SharedBuffer> buffer = SharedBuffer::create();
+ MHTMLArchive::generateMHTMLFooter(boundary, *buffer);
+ return PassRefPtr<SharedBuffer>(buffer);
}
bool WebPageSerializer::serialize(WebLocalFrame* frame,

Powered by Google App Engine
This is Rietveld 408576698