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

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: Adds a test that compares actual visible content. 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
145 bool MHTMLFrameSerializerDelegate::shouldSkipResource(Resource* resource)
146 {
147 DCHECK(resource);
148 return m_webDelegate.cacheControlPolicy() == WebFrameSerializerCacheControlP olicy::SkipAnyFrameOrResourceMarkedNoStore && resource->hasCacheControlNoStoreHe ader();
149 }
150
151 bool cacheControlNoStoreHeaderPresent(WebLocalFrameImpl* webLocalFrameImpl)
152 {
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
143 } // namespace 161 } // namespace
144 162
145 bool WebFrameSerializer::generateMHTMLHeader( 163 bool WebFrameSerializer::frameShouldBeSerializedAsMHTML(
146 const WebString& boundary, WebFrameSerializerCacheControlPolicy cacheControl Policy, 164 WebLocalFrame* frame, MHTMLPartsGenerationDelegate* delegate)
147 WebLocalFrame* frame, WebData* data)
148 { 165 {
166 DCHECK(delegate);
167 DCHECK(frame);
168
149 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame); 169 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame);
150 DCHECK(webLocalFrameImpl); 170 DCHECK(webLocalFrameImpl);
151 171
152 if (cacheControlPolicy == WebFrameSerializerCacheControlPolicy::FailForNoSto reMainFrame) { 172 WebFrameSerializerCacheControlPolicy cacheControlPolicy = delegate->cacheCon trolPolicy();
153 const ResourceResponse& response = webLocalFrameImpl->dataSource()->resp onse().toResourceResponse(); 173 if (cacheControlPolicy == WebFrameSerializerCacheControlPolicy::None)
154 if (response.cacheControlContainsNoStore()) 174 return true;
155 return false; 175
156 } 176 bool needToCheckNoStore = cacheControlPolicy == WebFrameSerializerCacheContr olPolicy::SkipAnyFrameOrResourceMarkedNoStore
177 || (!frame->parent() && cacheControlPolicy == WebFrameSerializerCacheCon trolPolicy::FailForNoStoreMainFrame);
178
179 if (!needToCheckNoStore)
180 return true;
181
182 return !cacheControlNoStoreHeaderPresent(webLocalFrameImpl);
183 }
184
185 WebData WebFrameSerializer::generateMHTMLHeader(
186 const WebString& boundary, WebLocalFrame* frame, MHTMLPartsGenerationDelegat e* delegate)
187 {
188 if (!frameShouldBeSerializedAsMHTML(frame, delegate))
189 return WebData();
190
191 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame);
192 DCHECK(webLocalFrameImpl);
157 193
158 Document* document = webLocalFrameImpl->frame()->document(); 194 Document* document = webLocalFrameImpl->frame()->document();
159 195
160 RefPtr<SharedBuffer> buffer = SharedBuffer::create(); 196 RefPtr<SharedBuffer> buffer = SharedBuffer::create();
161 MHTMLArchive::generateMHTMLHeader( 197 MHTMLArchive::generateMHTMLHeader(
162 boundary, document->title(), document->suggestedMIMEType(), 198 boundary, document->title(), document->suggestedMIMEType(),
163 *buffer); 199 *buffer);
164 *data = buffer.release(); 200 return buffer.release();
165 return true;
166 } 201 }
167 202
168 WebData WebFrameSerializer::generateMHTMLParts( 203 WebData WebFrameSerializer::generateMHTMLParts(
169 const WebString& boundary, WebLocalFrame* webFrame, bool useBinaryEncoding, 204 const WebString& boundary, WebLocalFrame* webFrame, MHTMLPartsGenerationDele gate* webDelegate)
170 MHTMLPartsGenerationDelegate* webDelegate)
171 { 205 {
172 DCHECK(webFrame); 206 DCHECK(webFrame);
173 DCHECK(webDelegate); 207 DCHECK(webDelegate);
174 208
209 if (!frameShouldBeSerializedAsMHTML(webFrame, webDelegate))
210 return WebData();
211
175 // Translate arguments from public to internal blink APIs. 212 // Translate arguments from public to internal blink APIs.
176 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame(); 213 LocalFrame* frame = toWebLocalFrameImpl(webFrame)->frame();
177 MHTMLArchive::EncodingPolicy encodingPolicy = useBinaryEncoding 214 MHTMLArchive::EncodingPolicy encodingPolicy = webDelegate->useBinaryEncoding ()
178 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding 215 ? MHTMLArchive::EncodingPolicy::UseBinaryEncoding
179 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding; 216 : MHTMLArchive::EncodingPolicy::UseDefaultEncoding;
180 217
181 // Serialize. 218 // Serialize.
182 Vector<SerializedResource> resources; 219 Vector<SerializedResource> resources;
183 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate); 220 MHTMLFrameSerializerDelegate coreDelegate(*webDelegate);
184 FrameSerializer serializer(resources, coreDelegate); 221 FrameSerializer serializer(resources, coreDelegate);
185 serializer.serializeFrame(*frame); 222 serializer.serializeFrame(*frame);
186 223
187 // Get Content-ID for the frame being serialized. 224 // 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) 275 WebString WebFrameSerializer::generateBaseTagDeclaration(const WebString& baseTa rget)
239 { 276 {
240 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|. 277 // TODO(yosin) We should call |FrameSerializer::baseTagDeclarationOf()|.
241 if (baseTarget.isEmpty()) 278 if (baseTarget.isEmpty())
242 return String("<base href=\".\">"); 279 return String("<base href=\".\">");
243 String baseString = "<base href=\".\" target=\"" + static_cast<const String& >(baseTarget) + "\">"; 280 String baseString = "<base href=\".\" target=\"" + static_cast<const String& >(baseTarget) + "\">";
244 return baseString; 281 return baseString;
245 } 282 }
246 283
247 } // namespace blink 284 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698