| 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 1f7ba05a7e78c6e6c763f579126cc082c116d11e..9b513a1996f7c08624f4f502c73c5ad63ada73c4 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,9 +278,7 @@ 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()));
|
| }
|
|
|
| // TODO(yosin): We should utilize |MarkupFormatter| here to share code,
|
| @@ -321,21 +315,11 @@ void WebPageSerializerImpl::openTagToString(Element* element,
|
| if (attrValue.startsWith("javascript:", TextCaseInsensitive)) {
|
| result.append(m_htmlEntities.convertEntitiesInString(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_htmlEntities.convertEntitiesInString(m_localLinks.get(completeURL)));
|
| - } else {
|
| - result.append(m_htmlEntities.convertEntitiesInString(completeURL));
|
| - }
|
| + saveHTMLContentToBuffer(result.toString(), param);
|
| + encodeAndFlushBuffer(param, ForceFlush);
|
| + result.clear();
|
| +
|
| + handleLinkAttr(element, param, attrValue);
|
| }
|
| } else {
|
| if (param->isHTMLDocument)
|
| @@ -358,9 +342,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;
|
| @@ -401,12 +398,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);
|
| @@ -427,13 +424,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)
|
| {
|
| @@ -442,13 +436,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());
|
| }
|
| @@ -462,23 +449,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, ¶m);
|
|
|
| - encodeAndFlushBuffer(WebPageSerializerClient::CurrentFrameIsFinished, ¶m, ForceFlush);
|
| + encodeAndFlushBuffer(¶m, ForceFlush);
|
| }
|
|
|
| ASSERT(m_dataBuffer.isEmpty());
|
| - m_client->didSerializeDataForFrame(KURL(), WebCString("", 0), WebPageSerializerClient::AllFramesAreFinished);
|
| + m_client->endOfFrame();
|
| return didSerialization;
|
| }
|
|
|
|
|