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

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

Issue 1373573002: ABANDONED: OOPIFs: Moving stitching of local paths from renderer to browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@page-serialization-recursive-begone
Patch Set: Removed no longer needed WebKit dependency. Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/web/WebPageSerializerImpl.cpp
diff --git a/third_party/WebKit/Source/web/WebPageSerializerImpl.cpp b/third_party/WebKit/Source/web/WebPageSerializerImpl.cpp
index 34bc016e83ca2780aa3ff3e6153ee8224a56a56b..2fd5e753a85e9b5623b719f657ee458d38d83eb1 100644
--- a/third_party/WebKit/Source/web/WebPageSerializerImpl.cpp
+++ b/third_party/WebKit/Source/web/WebPageSerializerImpl.cpp
@@ -86,6 +86,7 @@
#include "core/html/HTMLAllCollection.h"
#include "core/html/HTMLElement.h"
#include "core/html/HTMLFormElement.h"
+#include "core/html/HTMLFrameElementBase.h"
#include "core/html/HTMLHtmlElement.h"
#include "core/html/HTMLMetaElement.h"
#include "core/loader/DocumentLoader.h"
@@ -103,12 +104,10 @@ static const unsigned dataBufferCapacity = 65536;
WebPageSerializerImpl::SerializeDomParam::SerializeDomParam(const KURL& url,
const WTF::TextEncoding& textEncoding,
- Document* document,
- const String& directoryName)
+ Document* document)
: url(url)
, textEncoding(textEncoding)
, document(document)
- , directoryName(directoryName)
, isHTMLDocument(document->isHTMLDocument())
, haveSeenDocType(false)
, haveAddedCharsetDeclaration(false)
@@ -262,13 +261,10 @@ void WebPageSerializerImpl::saveHTMLContentToBuffer(
const String& result, SerializeDomParam* param)
{
m_dataBuffer.append(result);
- encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsNotFinished,
- param,
- DoNotForceFlush);
+ encodeAndFlushBuffer(param, DoNotForceFlush);
}
void WebPageSerializerImpl::encodeAndFlushBuffer(
- WebPageSerializerClient::PageSerializationStatus status,
SerializeDomParam* param,
FlushOption flushOption)
{
@@ -282,13 +278,11 @@ void WebPageSerializerImpl::encodeAndFlushBuffer(
CString encodedContent = param->textEncoding.normalizeAndEncode(content, WTF::EntitiesForUnencodables);
// Send result to the client.
- m_client->didSerializeDataForFrame(param->url,
- WebCString(encodedContent.data(), encodedContent.length()),
- status);
+ m_client->writeHtmlFragment(WebCString(encodedContent.data(), encodedContent.length()));
}
-void WebPageSerializerImpl::openTagToString(Element* element,
- SerializeDomParam* param)
+void WebPageSerializerImpl::handleOpenTag(
+ Element* element, SerializeDomParam* param)
{
bool needSkip;
StringBuilder result;
@@ -318,21 +312,11 @@ void WebPageSerializerImpl::openTagToString(Element* element,
if (attrValue.startsWith("javascript:", TextCaseInsensitive)) {
result.append(attrValue);
} else {
- // Get the absolute link
- WebLocalFrameImpl* subFrame = WebLocalFrameImpl::fromFrameOwnerElement(element);
- String completeURL = subFrame ? subFrame->frame()->document()->url() :
- param->document->completeURL(attrValue);
- // Check whether we have local files for those link.
- if (m_localLinks.contains(completeURL)) {
- if (!param->directoryName.isEmpty()) {
- result.appendLiteral("./");
- result.append(param->directoryName);
- result.append('/');
- }
- result.append(m_localLinks.get(completeURL));
- } else {
- result.append(completeURL);
- }
+ saveHTMLContentToBuffer(result.toString(), param);
+ encodeAndFlushBuffer(param, ForceFlush);
+ result.clear();
+
+ handleLinkAttr(element, param, attrValue);
}
} else {
if (param->isHTMLDocument)
@@ -355,9 +339,22 @@ void WebPageSerializerImpl::openTagToString(Element* element,
saveHTMLContentToBuffer(result.toString(), param);
}
+void WebPageSerializerImpl::handleLinkAttr(
+ Element* element, SerializeDomParam* param, const String& attrValue)
+{
+ if (isHTMLFrameElementBase(element)) {
+ WebFrame* subFrame = WebFrame::fromFrame(
+ toHTMLFrameElementBase(element)->contentFrame());
+ m_client->writeLocalPathForSubFrame(*subFrame);
+ } else {
+ KURL completeURL = param->document->completeURL(attrValue);
+ m_client->writeLocalPathForSavableResource(completeURL);
+ }
+}
+
// Serialize end tag of an specified element.
-void WebPageSerializerImpl::endTagToString(Element* element,
- SerializeDomParam* param)
+void WebPageSerializerImpl::handleEndTag(
+ Element* element, SerializeDomParam* param)
{
bool needSkip;
StringBuilder result;
@@ -398,12 +395,12 @@ void WebPageSerializerImpl::buildContentForNode(Node* node,
switch (node->nodeType()) {
case Node::ELEMENT_NODE:
// Process open tag of element.
- openTagToString(toElement(node), param);
+ handleOpenTag(toElement(node), param);
// Walk through the children nodes and process it.
for (Node *child = node->firstChild(); child; child = child->nextSibling())
buildContentForNode(child, param);
// Process end tag of element.
- endTagToString(toElement(node), param);
+ handleEndTag(toElement(node), param);
break;
case Node::TEXT_NODE:
saveHTMLContentToBuffer(createMarkup(node), param);
@@ -424,13 +421,10 @@ void WebPageSerializerImpl::buildContentForNode(Node* node,
}
}
-WebPageSerializerImpl::WebPageSerializerImpl(WebFrame* frame,
- WebPageSerializerClient* client,
- const WebVector<WebURL>& links,
- const WebVector<WebString>& localPaths,
- const WebString& localDirectoryName)
+WebPageSerializerImpl::WebPageSerializerImpl(
+ WebFrame* frame,
+ WebPageSerializerClient* client)
: m_client(client)
- , m_localDirectoryName(localDirectoryName)
, m_htmlEntities(false)
, m_xmlEntities(true)
{
@@ -439,13 +433,6 @@ WebPageSerializerImpl::WebPageSerializerImpl(WebFrame* frame,
m_specifiedWebLocalFrameImpl = toWebLocalFrameImpl(frame);
// Make sure we have non 0 client.
ASSERT(client);
- // Build local resources map.
- ASSERT(links.size() == localPaths.size());
- for (size_t i = 0; i < links.size(); i++) {
- KURL url = links[i];
- ASSERT(!m_localLinks.contains(url.string()));
- m_localLinks.set(url.string(), localPaths[i]);
- }
ASSERT(m_dataBuffer.isEmpty());
}
@@ -459,23 +446,22 @@ bool WebPageSerializerImpl::serialize()
Document* document = webFrame->frame()->document();
const KURL& url = document->url();
- if (url.isValid() && m_localLinks.contains(url.string())) {
+ if (url.isValid()) {
didSerialization = true;
const WTF::TextEncoding& textEncoding = document->encoding().isValid() ? document->encoding() : UTF8Encoding();
- String directoryName = url == mainURL ? m_localDirectoryName : "";
- SerializeDomParam param(url, textEncoding, document, directoryName);
+ SerializeDomParam param(url, textEncoding, document);
Element* documentElement = document->documentElement();
if (documentElement)
buildContentForNode(documentElement, &param);
- encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, &param, ForceFlush);
+ encodeAndFlushBuffer(&param, ForceFlush);
}
ASSERT(m_dataBuffer.isEmpty());
- m_client->didSerializeDataForFrame(KURL(), WebCString("", 0), WebPageSerializerClient::AllFramesAreFinished);
+ m_client->endOfFrame();
return didSerialization;
}

Powered by Google App Engine
This is Rietveld 408576698