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

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

Issue 1502563004: Save-Page-As-Complete-Html: Each frame links to a distinct local file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no-url-deduping-for-frame-and-adding-save-item-id
Patch Set: Rebasing... Created 4 years, 11 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/WebFrameSerializerImpl.cpp
diff --git a/third_party/WebKit/Source/web/WebFrameSerializerImpl.cpp b/third_party/WebKit/Source/web/WebFrameSerializerImpl.cpp
index 49240cb6dd4b3b324852571255d14b00590f0c31..b1ce352001a769cd1f3060912ab3052e67b35a73 100644
--- a/third_party/WebKit/Source/web/WebFrameSerializerImpl.cpp
+++ b/third_party/WebKit/Source/web/WebFrameSerializerImpl.cpp
@@ -86,6 +86,7 @@
#include "core/html/HTMLAllCollection.h"
#include "core/html/HTMLElement.h"
#include "core/html/HTMLFormElement.h"
+#include "core/html/HTMLFrameOwnerElement.h"
#include "core/html/HTMLHtmlElement.h"
#include "core/html/HTMLMetaElement.h"
#include "core/loader/DocumentLoader.h"
@@ -274,6 +275,21 @@ void WebFrameSerializerImpl::encodeAndFlushBuffer(
// TODO(yosin): We should utilize |MarkupFormatter| here to share code,
// especially escaping attribute values, done by |WebEntities| |m_htmlEntities|
// and |m_xmlEntities|.
+void WebFrameSerializerImpl::appendAttribute(
+ StringBuilder& result,
+ bool isHTMLDocument,
+ const String& attrName,
+ const String& attrValue) {
+ result.append(' ');
+ result.append(attrName);
+ result.appendLiteral("=\"");
+ if (isHTMLDocument)
+ result.append(m_htmlEntities.convertEntitiesInString(attrValue));
+ else
+ result.append(m_xmlEntities.convertEntitiesInString(attrValue));
+ result.append('\"');
+}
+
void WebFrameSerializerImpl::openTagToString(
Element* element,
SerializeDomParam* param)
@@ -287,42 +303,39 @@ void WebFrameSerializerImpl::openTagToString(
// Add open tag
result.append('<');
result.append(element->nodeName().lower());
+
+ // Find out if this element owns a frame.
+ WebFrame* frame = nullptr;
+ if (element->isFrameOwnerElement()) {
+ frame = WebFrame::fromFrame(
+ toHTMLFrameOwnerElement(element)->contentFrame());
+ }
+
// Go through all attributes and serialize them.
- AttributeCollection attributes = element->attributes();
- AttributeCollection::iterator end = attributes.end();
- for (AttributeCollection::iterator it = attributes.begin(); it != end; ++it) {
- result.append(' ');
- // Add attribute pair
- result.append(it->name().toString());
- result.appendLiteral("=\"");
- if (!it->value().isEmpty()) {
- const String& attrValue = it->value();
-
- // Check whether we need to replace some resource links
- // with local resource paths.
- const QualifiedName& attrName = it->name();
- if (element->hasLegalLinkAttribute(attrName)) {
- // For links start with "javascript:", we do not change it.
- if (attrValue.startsWith("javascript:", TextCaseInsensitive)) {
- result.append(m_htmlEntities.convertEntitiesInString(attrValue));
+ for (const auto& it : element->attributes()) {
+ const QualifiedName& attrName = it.name();
+ String attrValue = it.value();
+
+ // Rewrite the attribute value if requested.
+ if (element->hasLegalLinkAttribute(attrName)) {
+ // For links start with "javascript:", we do not change it.
+ if (!attrValue.startsWith("javascript:", TextCaseInsensitive)) {
+ // Get the absolute link.
+ KURL completeURL = param->document->completeURL(attrValue);
+
+ // Check whether we have a local file to link to.
+ WebString rewrittenLink;
+ if (frame && m_delegate->rewriteFrameSource(frame, &rewrittenLink)) {
+ attrValue = rewrittenLink;
+ } else if (m_delegate->rewriteLink(completeURL, &rewrittenLink)) {
+ attrValue = rewrittenLink;
} else {
- // Get the absolute link
- String completeURL = param->document->completeURL(attrValue);
- // Check whether we have local files for those link.
- if (m_localLinks.contains(completeURL)) {
- result.append(m_htmlEntities.convertEntitiesInString(m_localLinks.get(completeURL)));
- } else {
- result.append(m_htmlEntities.convertEntitiesInString(completeURL));
- }
+ attrValue = completeURL;
}
- } else {
- if (param->isHTMLDocument)
- result.append(m_htmlEntities.convertEntitiesInString(attrValue));
- else
- result.append(m_xmlEntities.convertEntitiesInString(attrValue));
}
}
- result.append('\"');
+
+ appendAttribute(result, param->isHTMLDocument, attrName.toString(), attrValue);
}
// Do post action for open tag.
@@ -410,22 +423,18 @@ void WebFrameSerializerImpl::buildContentForNode(
WebFrameSerializerImpl::WebFrameSerializerImpl(
WebLocalFrame* frame,
WebFrameSerializerClient* client,
- const WebVector<std::pair<WebURL, WebString>>& urlsToLocalPaths)
+ WebFrameSerializer::LinkRewritingDelegate* delegate)
: m_client(client)
+ , m_delegate(delegate)
, m_htmlEntities(false)
, m_xmlEntities(true)
{
// Must specify available webframe.
ASSERT(frame);
m_specifiedWebLocalFrameImpl = toWebLocalFrameImpl(frame);
- // Make sure we have non 0 client.
+ // Make sure we have non null client and delegate.
ASSERT(client);
- // Build local resources map.
- for (const auto& it : urlsToLocalPaths) {
- KURL url = it.first;
- ASSERT(!m_localLinks.contains(url.string()));
- m_localLinks.set(url.string(), it.second);
- }
+ ASSERT(delegate);
ASSERT(m_dataBuffer.isEmpty());
}
« no previous file with comments | « third_party/WebKit/Source/web/WebFrameSerializerImpl.h ('k') | third_party/WebKit/Source/web/tests/WebFrameSerializerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698