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

Side by Side Diff: third_party/WebKit/Source/platform/mhtml/MHTMLArchive.cpp

Issue 2425863002: Allow image documents in MHT if there is only one resource. (Closed)
Patch Set: Fix test expectations file Created 4 years, 1 month 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
« no previous file with comments | « third_party/WebKit/LayoutTests/platform/mac/mhtml/invalid-bad-boundary2-expected.png ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // sandboxing enforcement on MHTML pages. 71 // sandboxing enforcement on MHTML pages.
72 if (!canLoadArchive(url)) 72 if (!canLoadArchive(url))
73 return nullptr; 73 return nullptr;
74 74
75 MHTMLParser parser(std::move(data)); 75 MHTMLParser parser(std::move(data));
76 HeapVector<Member<ArchiveResource>> resources = parser.parseArchive(); 76 HeapVector<Member<ArchiveResource>> resources = parser.parseArchive();
77 if (resources.isEmpty()) 77 if (resources.isEmpty())
78 return nullptr; // Invalid MHTML file. 78 return nullptr; // Invalid MHTML file.
79 79
80 MHTMLArchive* archive = new MHTMLArchive; 80 MHTMLArchive* archive = new MHTMLArchive;
81
82 size_t resourcesCount = resources.size();
81 // The first document suitable resource is the main resource of the top frame. 83 // The first document suitable resource is the main resource of the top frame.
82 for (size_t i = 0; i < resources.size(); ++i) { 84 for (size_t i = 0; i < resourcesCount; ++i) {
85 if (archive->mainResource()) {
86 archive->addSubresource(resources[i].get());
87 continue;
88 }
89
83 const AtomicString& mimeType = resources[i]->mimeType(); 90 const AtomicString& mimeType = resources[i]->mimeType();
84 if (archive->mainResource() || 91 bool isMimeTypeSuitableForMainResource =
85 !MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType) || 92 MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType);
86 MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || 93 // Want to allow image-only MHTML archives, but retain behavior for other
87 mimeType == "text/css") 94 // documents that have already been created expecting the first HTML page to
95 // be considered the main resource.
96 if (resourcesCount == 1 &&
97 MIMETypeRegistry::isSupportedImageResourceMIMEType(mimeType)) {
98 isMimeTypeSuitableForMainResource = true;
99 }
100 // explicitly disallow JS and CSS as the main resource.
101 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) ||
102 MIMETypeRegistry::isSupportedStyleSheetMIMEType(mimeType))
103 isMimeTypeSuitableForMainResource = false;
104
105 if (isMimeTypeSuitableForMainResource)
106 archive->setMainResource(resources[i].get());
107 else
88 archive->addSubresource(resources[i].get()); 108 archive->addSubresource(resources[i].get());
89 else
90 archive->setMainResource(resources[i].get());
91 } 109 }
92 return archive; 110 return archive;
93 } 111 }
94 112
95 bool MHTMLArchive::canLoadArchive(const KURL& url) { 113 bool MHTMLArchive::canLoadArchive(const KURL& url) {
96 // MHTML pages can only be loaded from local URLs, http/https URLs, and 114 // MHTML pages can only be loaded from local URLs, http/https URLs, and
97 // content URLs(Android specific). The latter is now allowed due to full 115 // content URLs(Android specific). The latter is now allowed due to full
98 // sandboxing enforcement on MHTML pages. 116 // sandboxing enforcement on MHTML pages.
99 if (SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol())) 117 if (SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol()))
100 return true; 118 return true;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 ArchiveResource* MHTMLArchive::subresourceForURL(const KURL& url) const { 268 ArchiveResource* MHTMLArchive::subresourceForURL(const KURL& url) const {
251 return m_subresources.get(url.getString()); 269 return m_subresources.get(url.getString());
252 } 270 }
253 271
254 DEFINE_TRACE(MHTMLArchive) { 272 DEFINE_TRACE(MHTMLArchive) {
255 visitor->trace(m_mainResource); 273 visitor->trace(m_mainResource);
256 visitor->trace(m_subresources); 274 visitor->trace(m_subresources);
257 } 275 }
258 276
259 } // namespace blink 277 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/platform/mac/mhtml/invalid-bad-boundary2-expected.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698