Chromium Code Reviews| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 // For security reasons we only load MHTML pages from local URLs. | 76 // For security reasons we only load MHTML pages from local URLs. |
| 77 if (!SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol())) | 77 if (!SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol())) |
| 78 return nullptr; | 78 return nullptr; |
| 79 | 79 |
| 80 MHTMLParser parser(data); | 80 MHTMLParser parser(data); |
| 81 WillBeHeapVector<RefPtrWillBeMember<ArchiveResource>> resources = parser.par seArchive(); | 81 WillBeHeapVector<RefPtrWillBeMember<ArchiveResource>> resources = parser.par seArchive(); |
| 82 if (resources.isEmpty()) | 82 if (resources.isEmpty()) |
| 83 return nullptr; // Invalid MHTML file. | 83 return nullptr; // Invalid MHTML file. |
| 84 | 84 |
| 85 RefPtrWillBeRawPtr<MHTMLArchive> archive = adoptRefWillBeNoop(new MHTMLArchi ve); | 85 RefPtrWillBeRawPtr<MHTMLArchive> archive = adoptRefWillBeNoop(new MHTMLArchi ve); |
| 86 // Special case for single resource archives, in that case we will make an i mage | |
| 87 // the main resource. | |
| 88 if (resources.size() == 1) { | |
| 89 if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType) | |
|
Dmitry Titov
2016/02/18 01:31:15
I am not sure why you are checking for both non-im
| |
| 90 || MIMETypeRegistry::isSupportedImageResourceMIMEType(mimeType)) { | |
| 91 archive->setMainResource(resources[0].get()); | |
| 92 } else { | |
| 93 archive->addSubresource(resources[0].get()); | |
|
Dmitry Titov
2016/02/18 01:30:05
Is there a need to add non-recognized mime type as
| |
| 94 } | |
| 95 return archive.release(); | |
| 96 } | |
| 97 | |
| 86 // The first document suitable resource is the main resource of the top fram e. | 98 // The first document suitable resource is the main resource of the top fram e. |
| 87 for (size_t i = 0; i < resources.size(); ++i) { | 99 for (size_t i = 0; i < resources.size(); ++i) { |
| 88 const AtomicString& mimeType = resources[i]->mimeType(); | 100 const AtomicString& mimeType = resources[i]->mimeType(); |
| 89 if (archive->mainResource() || !MIMETypeRegistry::isSupportedNonImageMIM EType(mimeType) || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || mimeType == "text/css") | 101 if (archive->mainResource() || !MIMETypeRegistry::isSupportedNonImageMIM EType(mimeType) || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || mimeType == "text/css") |
| 90 archive->addSubresource(resources[i].get()); | 102 archive->addSubresource(resources[i].get()); |
| 91 else | 103 else |
| 92 archive->setMainResource(resources[i].get()); | 104 archive->setMainResource(resources[i].get()); |
| 93 } | 105 } |
| 94 return archive.release(); | 106 return archive.release(); |
| 95 } | 107 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 | 253 |
| 242 DEFINE_TRACE(MHTMLArchive) | 254 DEFINE_TRACE(MHTMLArchive) |
| 243 { | 255 { |
| 244 visitor->trace(m_mainResource); | 256 visitor->trace(m_mainResource); |
| 245 #if ENABLE(OILPAN) | 257 #if ENABLE(OILPAN) |
| 246 visitor->trace(m_subresources); | 258 visitor->trace(m_subresources); |
| 247 #endif | 259 #endif |
| 248 } | 260 } |
| 249 | 261 |
| 250 } // namespace blink | 262 } // namespace blink |
| OLD | NEW |