Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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; |
| 87 WebFrameSerializerCacheControlPolicy m_cacheControlPolicy = WebFrameSerializ erCacheControlPolicy::None; | |
| 85 }; | 88 }; |
| 86 | 89 |
| 87 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( | 90 MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate( |
| 88 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate) | 91 WebFrameSerializer::MHTMLPartsGenerationDelegate& webDelegate) |
| 89 : m_webDelegate(webDelegate) | 92 : m_webDelegate(webDelegate) |
| 90 { | 93 { |
| 91 } | 94 } |
| 92 | 95 |
| 93 bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute(const Attribute& attrib ute) | 96 bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute(const Attribute& attrib ute) |
| 94 { | 97 { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 || doc->isXHTMLDocument() || doc->isImageDocument(); | 131 || doc->isXHTMLDocument() || doc->isImageDocument(); |
| 129 if (isHandledBySerializer) { | 132 if (isHandledBySerializer) { |
| 130 rewrittenLink = cidURI.getString(); | 133 rewrittenLink = cidURI.getString(); |
| 131 return true; | 134 return true; |
| 132 } | 135 } |
| 133 } | 136 } |
| 134 | 137 |
| 135 return false; | 138 return false; |
| 136 } | 139 } |
| 137 | 140 |
| 138 bool MHTMLFrameSerializerDelegate::shouldSkipResource(const KURL& url) | 141 bool MHTMLFrameSerializerDelegate::shouldSkipResourceWithURL(const KURL& url) |
| 139 { | 142 { |
| 140 return m_webDelegate.shouldSkipResource(url); | 143 return m_webDelegate.shouldSkipResource(url); |
| 141 } | 144 } |
| 142 | 145 |
| 146 bool MHTMLFrameSerializerDelegate::shouldSkipResource(Resource* resource) | |
| 147 { | |
| 148 DCHECK(resource); | |
| 149 return m_cacheControlPolicy == WebFrameSerializerCacheControlPolicy::SkipAny FrameOrResourceMarkedNoStore && resource->hasCacheControlNoStoreHeader(); | |
| 150 } | |
| 151 | |
| 152 bool cacheControlNoStoreHeaderPresent(WebLocalFrameImpl* webLocalFrameImpl) | |
|
Dmitry Titov
2016/05/18 00:18:47
It's probably better to just inline this function
dewittj
2016/05/19 04:13:17
To me it was confusing when written inline. This
| |
| 153 { | |
| 154 const ResourceResponse& response = webLocalFrameImpl->dataSource()->response ().toResourceResponse(); | |
| 155 if (response.cacheControlContainsNoStore()) | |
| 156 return true; | |
| 157 | |
| 158 const ResourceRequest& request = webLocalFrameImpl->dataSource()->request(). toResourceRequest(); | |
| 159 return request.cacheControlContainsNoStore(); | |
| 160 } | |
| 161 | |
| 143 } // namespace | 162 } // namespace |
| 144 | 163 |
| 145 bool WebFrameSerializer::generateMHTMLHeader( | 164 bool WebFrameSerializer::frameShouldBeSerializedAsMHTML( |
| 146 const WebString& boundary, WebFrameSerializerCacheControlPolicy cacheControl Policy, | 165 WebLocalFrame* frame, MHTMLPartsGenerationDelegate* delegate) |
| 147 WebLocalFrame* frame, WebData* data) | |
| 148 { | 166 { |
| 167 DCHECK(delegate); | |
| 168 DCHECK(frame); | |
| 169 | |
| 149 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame); | 170 WebLocalFrameImpl* webLocalFrameImpl = toWebLocalFrameImpl(frame); |
| 150 DCHECK(webLocalFrameImpl); | 171 DCHECK(webLocalFrameImpl); |
| 151 | 172 |
| 152 if (cacheControlPolicy == WebFrameSerializerCacheControlPolicy::FailForNoSto reMainFrame) { | 173 WebFrameSerializerCacheControlPolicy cacheControlPolicy = delegate->cacheCon trolPolicy(); |
| 153 const ResourceResponse& response = webLocalFrameImpl->dataSource()->resp onse().toResourceResponse(); | 174 if (cacheControlPolicy == WebFrameSerializerCacheControlPolicy::None) |
| 154 if (response.cacheControlContainsNoStore()) | 175 return true; |
| 155 return false; | 176 |
| 156 } | 177 bool needToCheckNoStore = cacheControlPolicy == WebFrameSerializerCacheContr olPolicy::SkipAnyFrameOrResourceMarkedNoStore |
| 178 || (!frame->parent() && cacheControlPolicy == WebFrameSerializerCacheCon trolPolicy::FailForNoStoreMainFrame); | |
| 179 | |
| 180 if (!needToCheckNoStore) | |
| 181 return true; | |
| 182 | |
| 183 return !cacheControlNoStoreHeaderPresent(webLocalFrameImpl); | |
| 184 } | |
| 185 | |
| 186 WebData WebFrameSerializer::generateMHTMLHeader( | |
| 187 const WebString& boundary, WebLocalFrame* frame, MHTMLPartsGenerationDelegat e* delegate) | |
| 188 { | |
| 189 DCHECK(frameShouldBeSerializedAsMHTML(frame, delegate)); | |
| 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); |
| 208 DCHECK(frameShouldBeSerializedAsMHTML(webFrame, webDelegate)); | |
|
Dmitry Titov
2016/05/18 00:18:47
These DCHECKS look complex and might not add any s
dewittj
2016/05/19 04:13:17
Done.
| |
| 174 | 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 Loading... | |
| 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 |
| OLD | NEW |