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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 29 matching lines...) Expand all
40 #include "core/html/HTMLAllCollection.h" 40 #include "core/html/HTMLAllCollection.h"
41 #include "core/html/HTMLFrameElementBase.h" 41 #include "core/html/HTMLFrameElementBase.h"
42 #include "core/html/HTMLFrameOwnerElement.h" 42 #include "core/html/HTMLFrameOwnerElement.h"
43 #include "core/html/HTMLInputElement.h" 43 #include "core/html/HTMLInputElement.h"
44 #include "core/html/HTMLTableElement.h" 44 #include "core/html/HTMLTableElement.h"
45 #include "core/loader/DocumentLoader.h" 45 #include "core/loader/DocumentLoader.h"
46 #include "platform/SerializedResource.h" 46 #include "platform/SerializedResource.h"
47 #include "platform/SharedBuffer.h" 47 #include "platform/SharedBuffer.h"
48 #include "platform/mhtml/MHTMLArchive.h" 48 #include "platform/mhtml/MHTMLArchive.h"
49 #include "platform/mhtml/MHTMLParser.h" 49 #include "platform/mhtml/MHTMLParser.h"
50 #include "platform/network/ResourceResponse.h"
50 #include "platform/weborigin/KURL.h" 51 #include "platform/weborigin/KURL.h"
51 #include "public/platform/WebString.h" 52 #include "public/platform/WebString.h"
52 #include "public/platform/WebURL.h" 53 #include "public/platform/WebURL.h"
54 #include "public/platform/WebURLResponse.h"
53 #include "public/platform/WebVector.h" 55 #include "public/platform/WebVector.h"
56 #include "public/web/WebDataSource.h"
54 #include "public/web/WebDocument.h" 57 #include "public/web/WebDocument.h"
55 #include "public/web/WebFrame.h" 58 #include "public/web/WebFrame.h"
59 #include "public/web/WebFrameSerializerCacheControlPolicy.h"
56 #include "public/web/WebFrameSerializerClient.h" 60 #include "public/web/WebFrameSerializerClient.h"
57 #include "web/WebFrameSerializerImpl.h" 61 #include "web/WebFrameSerializerImpl.h"
58 #include "web/WebLocalFrameImpl.h" 62 #include "web/WebLocalFrameImpl.h"
59 #include "web/WebRemoteFrameImpl.h" 63 #include "web/WebRemoteFrameImpl.h"
60 #include "wtf/Assertions.h" 64 #include "wtf/Assertions.h"
61 #include "wtf/HashMap.h" 65 #include "wtf/HashMap.h"
62 #include "wtf/HashSet.h" 66 #include "wtf/HashSet.h"
63 #include "wtf/Noncopyable.h" 67 #include "wtf/Noncopyable.h"
64 #include "wtf/Vector.h" 68 #include "wtf/Vector.h"
65 #include "wtf/text/StringConcatenate.h" 69 #include "wtf/text/StringConcatenate.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 } 133 }
130 134
131 return false; 135 return false;
132 } 136 }
133 137
134 bool MHTMLFrameSerializerDelegate::shouldSkipResource(const KURL& url) 138 bool MHTMLFrameSerializerDelegate::shouldSkipResource(const KURL& url)
135 { 139 {
136 return m_webDelegate.shouldSkipResource(url); 140 return m_webDelegate.shouldSkipResource(url);
137 } 141 }
138 142
143 bool resourceResponseContainsNoStore(const ResourceResponse& response)
144 {
145 DEFINE_STATIC_LOCAL(const AtomicString, cacheControlHeader, ("cache-control" ));
146 DEFINE_STATIC_LOCAL(const AtomicString, pragmaHeader, ("pragma"));
147
148 return parseCacheControlDirectives(
149 response.httpHeaderField(cacheControlHeader),
150 response.httpHeaderField(pragmaHeader)).containsNoStore;
151 }
152
139 } // namespace 153 } // namespace
140 154
141 WebData WebFrameSerializer::generateMHTMLHeader( 155 bool WebFrameSerializer::generateMHTMLHeader(
142 const WebString& boundary, WebLocalFrame* frame) 156 const WebString& boundary, WebFrameSerializerCacheControlPolicy cacheControl Policy,
157 WebLocalFrame* frame, WebData* data)
143 { 158 {
144 Document* document = toWebLocalFrameImpl(frame)->frame()->document(); 159 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame);
160 DCHECK(webLocalFrameImpl);
161
162 if (cacheControlPolicy == WebFrameSerializerCacheControlPolicy::FailForNoSto reMainFrame) {
163 const ResourceResponse& response = webLocalFrameImpl->dataSource()->resp onse().toResourceResponse();
164 if (resourceResponseContainsNoStore(response))
165 return false;
166 }
167
168 Document* document = webLocalFrameImpl->frame()->document();
145 169
146 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); 170 RefPtr<SharedBuffer> buffer = SharedBuffer::create();
147 MHTMLArchive::generateMHTMLHeader( 171 MHTMLArchive::generateMHTMLHeader(
148 boundary, document->title(), document->suggestedMIMEType(), 172 boundary, document->title(), document->suggestedMIMEType(),
149 *buffer); 173 *buffer);
150 return buffer.release(); 174 *data = buffer.release();
175 return true;
151 } 176 }
152 177
153 WebData WebFrameSerializer::generateMHTMLParts( 178 WebData WebFrameSerializer::generateMHTMLParts(
154 const WebString& boundary, WebLocalFrame* webFrame, bool useBinaryEncoding, 179 const WebString& boundary, WebLocalFrame* webFrame, bool useBinaryEncoding,
155 MHTMLPartsGenerationDelegate* webDelegate) 180 MHTMLPartsGenerationDelegate* webDelegate)
156 { 181 {
157 DCHECK(webFrame); 182 DCHECK(webFrame);
158 DCHECK(webDelegate); 183 DCHECK(webDelegate);
159 184
160 // Translate arguments from public to internal blink APIs. 185 // Translate arguments from public to internal blink APIs.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 WebString WebFrameSerializer::generateBaseTagDeclaration(const WebString& baseTa rget) 248 WebString WebFrameSerializer::generateBaseTagDeclaration(const WebString& baseTa rget)
224 { 249 {
225 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. 250 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|.
226 if (baseTarget.isEmpty()) 251 if (baseTarget.isEmpty())
227 return String("<base href=\".\">"); 252 return String("<base href=\".\">");
228 String baseString = "<base href=\".\" target=\"" + static_cast<const String& >(baseTarget) + "\">"; 253 String baseString = "<base href=\".\" target=\"" + static_cast<const String& >(baseTarget) + "\">";
229 return baseString; 254 return baseString;
230 } 255 }
231 256
232 } // namespace blink 257 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698