| OLD | NEW |
| 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 Loading... |
| 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(); | |
| 83 // The first document suitable resource is the main resource of the top frame. | 81 // The first document suitable resource is the main resource of the top frame. |
| 84 for (size_t i = 0; i < resourcesCount; ++i) { | 82 for (size_t i = 0; i < resources.size(); ++i) { |
| 85 if (archive->mainResource()) { | 83 const AtomicString& mimeType = resources[i]->mimeType(); |
| 84 if (archive->mainResource() || |
| 85 !MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType) || |
| 86 MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || |
| 87 mimeType == "text/css") |
| 86 archive->addSubresource(resources[i].get()); | 88 archive->addSubresource(resources[i].get()); |
| 87 continue; | 89 else |
| 88 } | |
| 89 | |
| 90 const AtomicString& mimeType = resources[i]->mimeType(); | |
| 91 bool isMimeTypeSuitableForMainResource = | |
| 92 MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType); | |
| 93 // Want to allow image-only MHTML archives, but retain behavior for other | |
| 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()); | 90 archive->setMainResource(resources[i].get()); |
| 107 else | |
| 108 archive->addSubresource(resources[i].get()); | |
| 109 } | 91 } |
| 110 return archive; | 92 return archive; |
| 111 } | 93 } |
| 112 | 94 |
| 113 bool MHTMLArchive::canLoadArchive(const KURL& url) { | 95 bool MHTMLArchive::canLoadArchive(const KURL& url) { |
| 114 // MHTML pages can only be loaded from local URLs, http/https URLs, and | 96 // MHTML pages can only be loaded from local URLs, http/https URLs, and |
| 115 // content URLs(Android specific). The latter is now allowed due to full | 97 // content URLs(Android specific). The latter is now allowed due to full |
| 116 // sandboxing enforcement on MHTML pages. | 98 // sandboxing enforcement on MHTML pages. |
| 117 if (SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol())) | 99 if (SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol())) |
| 118 return true; | 100 return true; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 ArchiveResource* MHTMLArchive::subresourceForURL(const KURL& url) const { | 250 ArchiveResource* MHTMLArchive::subresourceForURL(const KURL& url) const { |
| 269 return m_subresources.get(url.getString()); | 251 return m_subresources.get(url.getString()); |
| 270 } | 252 } |
| 271 | 253 |
| 272 DEFINE_TRACE(MHTMLArchive) { | 254 DEFINE_TRACE(MHTMLArchive) { |
| 273 visitor->trace(m_mainResource); | 255 visitor->trace(m_mainResource); |
| 274 visitor->trace(m_subresources); | 256 visitor->trace(m_subresources); |
| 275 } | 257 } |
| 276 | 258 |
| 277 } // namespace blink | 259 } // namespace blink |
| OLD | NEW |