| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 } | 64 } |
| 65 | 65 |
| 66 MHTMLArchive::MHTMLArchive() | 66 MHTMLArchive::MHTMLArchive() |
| 67 { | 67 { |
| 68 } | 68 } |
| 69 | 69 |
| 70 MHTMLArchive::~MHTMLArchive() | 70 MHTMLArchive::~MHTMLArchive() |
| 71 { | 71 { |
| 72 } | 72 } |
| 73 | 73 |
| 74 RawPtr<MHTMLArchive> MHTMLArchive::create(const KURL& url, SharedBuffer* data) | 74 MHTMLArchive* MHTMLArchive::create(const KURL& url, SharedBuffer* data) |
| 75 { | 75 { |
| 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 HeapVector<Member<ArchiveResource>> resources = parser.parseArchive(); | 81 HeapVector<Member<ArchiveResource>> resources = parser.parseArchive(); |
| 82 if (resources.isEmpty()) | 82 if (resources.isEmpty()) |
| 83 return nullptr; // Invalid MHTML file. | 83 return nullptr; // Invalid MHTML file. |
| 84 | 84 |
| 85 RawPtr<MHTMLArchive> archive = new MHTMLArchive; | 85 MHTMLArchive* archive = new MHTMLArchive; |
| 86 // The first document suitable resource is the main resource of the top fram
e. | 86 // The first document suitable resource is the main resource of the top fram
e. |
| 87 for (size_t i = 0; i < resources.size(); ++i) { | 87 for (size_t i = 0; i < resources.size(); ++i) { |
| 88 const AtomicString& mimeType = resources[i]->mimeType(); | 88 const AtomicString& mimeType = resources[i]->mimeType(); |
| 89 if (archive->mainResource() || !MIMETypeRegistry::isSupportedNonImageMIM
EType(mimeType) || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) ||
mimeType == "text/css") | 89 if (archive->mainResource() || !MIMETypeRegistry::isSupportedNonImageMIM
EType(mimeType) || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) ||
mimeType == "text/css") |
| 90 archive->addSubresource(resources[i].get()); | 90 archive->addSubresource(resources[i].get()); |
| 91 else | 91 else |
| 92 archive->setMainResource(resources[i].get()); | 92 archive->setMainResource(resources[i].get()); |
| 93 } | 93 } |
| 94 return archive.release(); | 94 return archive; |
| 95 } | 95 } |
| 96 | 96 |
| 97 void MHTMLArchive::generateMHTMLHeader( | 97 void MHTMLArchive::generateMHTMLHeader( |
| 98 const String& boundary, const String& title, const String& mimeType, | 98 const String& boundary, const String& title, const String& mimeType, |
| 99 SharedBuffer& outputBuffer) | 99 SharedBuffer& outputBuffer) |
| 100 { | 100 { |
| 101 ASSERT(!boundary.isEmpty()); | 101 ASSERT(!boundary.isEmpty()); |
| 102 ASSERT(!mimeType.isEmpty()); | 102 ASSERT(!mimeType.isEmpty()); |
| 103 | 103 |
| 104 DateComponents now; | 104 DateComponents now; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 213 |
| 214 void MHTMLArchive::generateMHTMLFooter( | 214 void MHTMLArchive::generateMHTMLFooter( |
| 215 const String& boundary, | 215 const String& boundary, |
| 216 SharedBuffer& outputBuffer) | 216 SharedBuffer& outputBuffer) |
| 217 { | 217 { |
| 218 ASSERT(!boundary.isEmpty()); | 218 ASSERT(!boundary.isEmpty()); |
| 219 CString asciiString = String("--" + boundary + "--\r\n").utf8(); | 219 CString asciiString = String("--" + boundary + "--\r\n").utf8(); |
| 220 outputBuffer.append(asciiString.data(), asciiString.length()); | 220 outputBuffer.append(asciiString.data(), asciiString.length()); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void MHTMLArchive::setMainResource(RawPtr<ArchiveResource> mainResource) | 223 void MHTMLArchive::setMainResource(ArchiveResource* mainResource) |
| 224 { | 224 { |
| 225 m_mainResource = mainResource; | 225 m_mainResource = mainResource; |
| 226 } | 226 } |
| 227 | 227 |
| 228 void MHTMLArchive::addSubresource(ArchiveResource* resource) | 228 void MHTMLArchive::addSubresource(ArchiveResource* resource) |
| 229 { | 229 { |
| 230 const KURL& url = resource->url(); | 230 const KURL& url = resource->url(); |
| 231 m_subresources.set(url, resource); | 231 m_subresources.set(url, resource); |
| 232 KURL cidURI = MHTMLParser::convertContentIDToURI(resource->contentID()); | 232 KURL cidURI = MHTMLParser::convertContentIDToURI(resource->contentID()); |
| 233 if (cidURI.isValid()) | 233 if (cidURI.isValid()) |
| 234 m_subresources.set(cidURI, resource); | 234 m_subresources.set(cidURI, resource); |
| 235 } | 235 } |
| 236 | 236 |
| 237 ArchiveResource* MHTMLArchive::subresourceForURL(const KURL& url) const | 237 ArchiveResource* MHTMLArchive::subresourceForURL(const KURL& url) const |
| 238 { | 238 { |
| 239 return m_subresources.get(url.getString()); | 239 return m_subresources.get(url.getString()); |
| 240 } | 240 } |
| 241 | 241 |
| 242 DEFINE_TRACE(MHTMLArchive) | 242 DEFINE_TRACE(MHTMLArchive) |
| 243 { | 243 { |
| 244 visitor->trace(m_mainResource); | 244 visitor->trace(m_mainResource); |
| 245 #if ENABLE(OILPAN) | |
| 246 visitor->trace(m_subresources); | 245 visitor->trace(m_subresources); |
| 247 #endif | |
| 248 } | 246 } |
| 249 | 247 |
| 250 } // namespace blink | 248 } // namespace blink |
| OLD | NEW |