| 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 const AtomicString& mimeType = resources[0]->mimeType(); |
| 90 if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType) |
| 91 || MIMETypeRegistry::isSupportedImageResourceMIMEType(mimeType)) { |
| 92 archive->setMainResource(resources[0].get()); |
| 93 } else { |
| 94 archive->addSubresource(resources[0].get()); |
| 95 } |
| 96 return archive.release(); |
| 97 } |
| 98 |
| 86 // The first document suitable resource is the main resource of the top fram
e. | 99 // The first document suitable resource is the main resource of the top fram
e. |
| 87 for (size_t i = 0; i < resources.size(); ++i) { | 100 for (size_t i = 0; i < resources.size(); ++i) { |
| 88 const AtomicString& mimeType = resources[i]->mimeType(); | 101 const AtomicString& mimeType = resources[i]->mimeType(); |
| 89 if (archive->mainResource() || !MIMETypeRegistry::isSupportedNonImageMIM
EType(mimeType) || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) ||
mimeType == "text/css") | 102 if (archive->mainResource() || !MIMETypeRegistry::isSupportedNonImageMIM
EType(mimeType) || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) ||
mimeType == "text/css") |
| 90 archive->addSubresource(resources[i].get()); | 103 archive->addSubresource(resources[i].get()); |
| 91 else | 104 else |
| 92 archive->setMainResource(resources[i].get()); | 105 archive->setMainResource(resources[i].get()); |
| 93 } | 106 } |
| 94 return archive.release(); | 107 return archive.release(); |
| 95 } | 108 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 254 |
| 242 DEFINE_TRACE(MHTMLArchive) | 255 DEFINE_TRACE(MHTMLArchive) |
| 243 { | 256 { |
| 244 visitor->trace(m_mainResource); | 257 visitor->trace(m_mainResource); |
| 245 #if ENABLE(OILPAN) | 258 #if ENABLE(OILPAN) |
| 246 visitor->trace(m_subresources); | 259 visitor->trace(m_subresources); |
| 247 #endif | 260 #endif |
| 248 } | 261 } |
| 249 | 262 |
| 250 } // namespace blink | 263 } // namespace blink |
| OLD | NEW |