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

Side by Side Diff: third_party/WebKit/Source/web/WebFrameSerializer.cpp

Issue 1977303003: Adds a feature to MHTML serialization that omits subframes and subresources marked no-store. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@no-store
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/ResourceRequest.h"
50 #include "platform/network/ResourceResponse.h" 51 #include "platform/network/ResourceResponse.h"
51 #include "platform/weborigin/KURL.h" 52 #include "platform/weborigin/KURL.h"
52 #include "public/platform/WebString.h" 53 #include "public/platform/WebString.h"
53 #include "public/platform/WebURL.h" 54 #include "public/platform/WebURL.h"
54 #include "public/platform/WebURLResponse.h" 55 #include "public/platform/WebURLResponse.h"
55 #include "public/platform/WebVector.h" 56 #include "public/platform/WebVector.h"
56 #include "public/web/WebDataSource.h" 57 #include "public/web/WebDataSource.h"
57 #include "public/web/WebDocument.h" 58 #include "public/web/WebDocument.h"
58 #include "public/web/WebFrame.h" 59 #include "public/web/WebFrame.h"
59 #include "public/web/WebFrameSerializerCacheControlPolicy.h" 60 #include "public/web/WebFrameSerializerCacheControlPolicy.h"
(...skipping 11 matching lines...) Expand all
71 namespace blink { 72 namespace blink {
72 73
73 namespace { 74 namespace {
74 75
75 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate { 76 class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate {
76 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate); 77 WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate);
77 public: 78 public:
78 explicit MHTMLFrameSerializerDelegate(WebFrameSerializer::MHTMLPartsGenerati onDelegate&); 79 explicit MHTMLFrameSerializerDelegate(WebFrameSerializer::MHTMLPartsGenerati onDelegate&);
79 bool shouldIgnoreAttribute(const Attribute&) override; 80 bool shouldIgnoreAttribute(const Attribute&) override;
80 bool rewriteLink(const Element&, String& rewrittenLink) override; 81 bool rewriteLink(const Element&, String& rewrittenLink) override;
81 bool shouldSkipResource(const KURL&) override; 82 bool shouldSkipResourceWithURL(const KURL&) override;
83 bool shouldSkipResource(Resource*) override;
82 84
83 private: 85 private:
84 WebFrameSerializer::MHTMLPartsGenerationDelegate& m_webDelegate; 86 WebFrameSerializer::MHTMLPartsGenerationDelegate& m_webDelegate;
85 }; 87 };
86 88
87 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( 89 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate(
88 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate) 90 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate)
89 : m_webDelegate(webDelegate) 91 : m_webDelegate(webDelegate)
90 { 92 {
91 } 93 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 || doc->isXHTMLDocument() || doc->isImageDocument(); 130 || doc->isXHTMLDocument() || doc->isImageDocument();
129 if (isHandledBySerializer) { 131 if (isHandledBySerializer) {
130 rewrittenLink = cidURI.getString(); 132 rewrittenLink = cidURI.getString();
131 return true; 133 return true;
132 } 134 }
133 } 135 }
134 136
135 return false; 137 return false;
136 } 138 }
137 139
138 bool MHTMLFrameSerializerDelegate::shouldSkipResource(const KURL& url) 140 bool MHTMLFrameSerializerDelegate::shouldSkipResourceWithURL(const KURL& url)
139 { 141 {
140 return m_webDelegate.shouldSkipResource(url); 142 return m_webDelegate.shouldSkipResource(url);
141 } 143 }
142 144
143 } // namespace 145 bool MHTMLFrameSerializerDelegate::shouldSkipResource(Resource* resource)
146 {
147 DCHECK(resource);
148 return m_webDelegate.cacheControlPolicy() == WebFrameSerializerCacheControlP olicy::SkipAnyFrameOrResourceMarkedNoStore && resource->hasCacheControlNoStoreHe ader();
149 }
144 150
145 bool WebFrameSerializer::generateMHTMLHeader( 151 bool cacheControlNoStoreHeaderPresent(WebLocalFrameImpl* webLocalFrameImpl)
Łukasz Anforowicz 2016/05/19 18:50:18 nit: const-ref?
dewittj 2016/05/19 19:44:55 Done.
146 const WebString& boundary, WebFrameSerializerCacheControlPolicy cacheControl Policy, 152 {
147 WebLocalFrame* frame, WebData* data) 153 const ResourceResponse& response = webLocalFrameImpl->dataSource()->response ().toResourceResponse();
154 if (response.cacheControlContainsNoStore())
155 return true;
156
157 const ResourceRequest& request = webLocalFrameImpl->dataSource()->request(). toResourceRequest();
158 return request.cacheControlContainsNoStore();
159 }
160
161 bool frameShouldBeSerializedAsMHTML(WebLocalFrame* frame, WebFrameSerializerCach eControlPolicy cacheControlPolicy)
Łukasz Anforowicz 2016/05/19 18:50:18 nit: const-ref?
dewittj 2016/05/19 19:44:55 I don't think that's a great thing to do here, sin
Łukasz Anforowicz 2016/05/19 19:51:24 Blink's DEFINE_TYPE_CASTS macro makes sure that al
148 { 162 {
149 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame); 163 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame);
150 DCHECK(webLocalFrameImpl); 164 DCHECK(webLocalFrameImpl);
151 165
152 if (cacheControlPolicy == WebFrameSerializerCacheControlPolicy::FailForNoSto reMainFrame) { 166 if (cacheControlPolicy == WebFrameSerializerCacheControlPolicy::None)
153 const ResourceResponse& response = webLocalFrameImpl->dataSource()->resp onse().toResourceResponse(); 167 return true;
154 if (response.cacheControlContainsNoStore()) 168
155 return false; 169 bool needToCheckNoStore = cacheControlPolicy == WebFrameSerializerCacheContr olPolicy::SkipAnyFrameOrResourceMarkedNoStore
156 } 170 || (!frame->parent() && cacheControlPolicy == WebFrameSerializerCacheCon trolPolicy::FailForNoStoreMainFrame);
171
172 if (!needToCheckNoStore)
173 return true;
174
175 return !cacheControlNoStoreHeaderPresent(webLocalFrameImpl);
176 }
177
178 } // namespace
179
180 WebData WebFrameSerializer::generateMHTMLHeader(
181 const WebString& boundary, WebLocalFrame* frame, MHTMLPartsGenerationDelegat e* delegate)
182 {
183 DCHECK(frame);
184 DCHECK(delegate);
185
186 if (!frameShouldBeSerializedAsMHTML(frame, delegate->cacheControlPolicy()))
187 return WebData();
188
189 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame);
190 DCHECK(webLocalFrameImpl);
157 191
158 Document* document = webLocalFrameImpl->frame()->document(); 192 Document* document = webLocalFrameImpl->frame()->document();
159 193
160 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); 194 RefPtr<SharedBuffer> buffer = SharedBuffer::create();
161 MHTMLArchive::generateMHTMLHeader( 195 MHTMLArchive::generateMHTMLHeader(
162 boundary, document->title(), document->suggestedMIMEType(), 196 boundary, document->title(), document->suggestedMIMEType(),
163 *buffer); 197 *buffer);
164 *data = buffer.release(); 198 return buffer.release();
165 return true;
166 } 199 }
167 200
168 WebData WebFrameSerializer::generateMHTMLParts( 201 WebData WebFrameSerializer::generateMHTMLParts(
169 const WebString& boundary, WebLocalFrame* webFrame, bool useBinaryEncoding, 202 const WebString& boundary, WebLocalFrame* webFrame, MHTMLPartsGenerationDele gate* webDelegate)
170 MHTMLPartsGenerationDelegate* webDelegate)
171 { 203 {
172 DCHECK(webFrame); 204 DCHECK(webFrame);
173 DCHECK(webDelegate); 205 DCHECK(webDelegate);
174 206
207 if (!frameShouldBeSerializedAsMHTML(webFrame, webDelegate->cacheControlPolic y()))
208 return WebData();
209
175 // Translate arguments from public to internal blink APIs. 210 // Translate arguments from public to internal blink APIs.
176 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); 211 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame();
177 MHTMLArchive::EncodingPolicy encodingPolicy = useBinaryEncoding 212 MHTMLArchive::EncodingPolicy encodingPolicy = webDelegate->useBinaryEncoding ()
178 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding 213 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding
179 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; 214 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding;
180 215
181 // Serialize. 216 // Serialize.
182 Vector<SerializedResource> resources; 217 Vector<SerializedResource> resources;
183 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate); 218 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate);
184 FrameSerializer serializer(resources, coreDelegate); 219 FrameSerializer serializer(resources, coreDelegate);
185 serializer.serializeFrame(*frame); 220 serializer.serializeFrame(*frame);
186 221
187 // Get Content-ID for the frame being serialized. 222 // Get Content-ID for the frame being serialized.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 WebString WebFrameSerializer::generateBaseTagDeclaration(const WebString& baseTa rget) 273 WebString WebFrameSerializer::generateBaseTagDeclaration(const WebString& baseTa rget)
239 { 274 {
240 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. 275 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|.
241 if (baseTarget.isEmpty()) 276 if (baseTarget.isEmpty())
242 return String("<base href=\".\">"); 277 return String("<base href=\".\">");
243 String baseString = "<base href=\".\" target=\"" + static_cast<const String& >(baseTarget) + "\">"; 278 String baseString = "<base href=\".\" target=\"" + static_cast<const String& >(baseTarget) + "\">";
244 return baseString; 279 return baseString;
245 } 280 }
246 281
247 } // namespace blink 282 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698