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

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

Issue 1947263004: Introduces a new MHTML generation parameter specifying different behvaior for cache-control headers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Łukasz comments. Created 4 years, 7 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/WebFrameSerializer.cpp
diff --git a/third_party/WebKit/Source/web/WebFrameSerializer.cpp b/third_party/WebKit/Source/web/WebFrameSerializer.cpp
index 09fab010910923bea9bed94a704d40d0052a75d2..5e452f16cebaf073e87a2f397b6281d8fd7a5dfb 100644
--- a/third_party/WebKit/Source/web/WebFrameSerializer.cpp
+++ b/third_party/WebKit/Source/web/WebFrameSerializer.cpp
@@ -47,12 +47,16 @@
#include "platform/SharedBuffer.h"
#include "platform/mhtml/MHTMLArchive.h"
#include "platform/mhtml/MHTMLParser.h"
+#include "platform/network/ResourceResponse.h"
#include "platform/weborigin/KURL.h"
#include "public/platform/WebString.h"
#include "public/platform/WebURL.h"
+#include "public/platform/WebURLResponse.h"
#include "public/platform/WebVector.h"
+#include "public/web/WebDataSource.h"
#include "public/web/WebDocument.h"
#include "public/web/WebFrame.h"
+#include "public/web/WebFrameSerializerCacheControlPolicy.h"
#include "public/web/WebFrameSerializerClient.h"
#include "web/WebFrameSerializerImpl.h"
#include "web/WebLocalFrameImpl.h"
@@ -136,18 +140,39 @@ bool MHTMLFrameSerializerDelegate::shouldSkipResource(const KURL& url)
return m_webDelegate.shouldSkipResource(url);
}
+bool resourceResponseContainsNoStore(const ResourceResponse& response)
+{
+ DEFINE_STATIC_LOCAL(const AtomicString, cacheControlHeader, ("cache-control"));
+ DEFINE_STATIC_LOCAL(const AtomicString, pragmaHeader, ("pragma"));
+
+ return parseCacheControlDirectives(
+ response.httpHeaderField(cacheControlHeader),
+ response.httpHeaderField(pragmaHeader)).containsNoStore;
+}
+
} // namespace
-WebData WebFrameSerializer::generateMHTMLHeader(
- const WebString& boundary, WebLocalFrame* frame)
+bool WebFrameSerializer::generateMHTMLHeader(
+ const WebString& boundary, WebFrameSerializerCacheControlPolicy cacheControlPolicy,
+ WebLocalFrame* frame, WebData* data)
{
- Document* document = toWebLocalFrameImpl(frame)->frame()->document();
+ WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame);
+ DCHECK(webLocalFrameImpl);
+
+ if (cacheControlPolicy == WebFrameSerializerCacheControlPolicy::FailForNoStoreMainFrame) {
+ const ResourceResponse& response = webLocalFrameImpl->dataSource()->response().toResourceResponse();
+ if (resourceResponseContainsNoStore(response))
+ return false;
+ }
+
+ Document* document = webLocalFrameImpl->frame()->document();
RefPtr<SharedBuffer> buffer = SharedBuffer::create();
MHTMLArchive::generateMHTMLHeader(
boundary, document->title(), document->suggestedMIMEType(),
*buffer);
- return buffer.release();
+ *data = buffer.release();
+ return true;
}
WebData WebFrameSerializer::generateMHTMLParts(

Powered by Google App Engine
This is Rietveld 408576698