Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "config.h" | 29 #include "config.h" |
| 30 #include "ArchiveFactory.h" | 30 #include "ArchiveFactory.h" |
| 31 | 31 |
| 32 #include "MIMETypeRegistry.h" | |
| 33 | |
| 34 #if USE(CF) && ENABLE(WEB_ARCHIVE) | |
|
eae
2013/04/05 22:28:53
Where did this come from?
Nate Chapin
2013/04/05 22:31:03
I removed these ifdefs a few hours ago, must be a
| |
| 35 #include "LegacyWebArchive.h" | |
| 36 #endif | |
| 37 #if ENABLE(MHTML) | |
| 32 #include "MHTMLArchive.h" | 38 #include "MHTMLArchive.h" |
| 33 #include "MIMETypeRegistry.h" | 39 #endif |
| 34 | 40 |
| 35 #include <wtf/HashMap.h> | 41 #include <wtf/HashMap.h> |
| 36 #include <wtf/HashSet.h> | 42 #include <wtf/HashSet.h> |
| 37 #include <wtf/StdLibExtras.h> | 43 #include <wtf/StdLibExtras.h> |
| 38 #include <wtf/text/WTFString.h> | 44 #include <wtf/text/WTFString.h> |
| 39 | 45 |
| 40 namespace WebCore { | 46 namespace WebCore { |
| 41 | 47 |
| 42 typedef PassRefPtr<Archive> RawDataCreationFunction(const KURL&, SharedBuffer*); | 48 typedef PassRefPtr<Archive> RawDataCreationFunction(const KURL&, SharedBuffer*); |
| 43 typedef HashMap<String, RawDataCreationFunction*, CaseFoldingHash> ArchiveMIMETy pesMap; | 49 typedef HashMap<String, RawDataCreationFunction*, CaseFoldingHash> ArchiveMIMETy pesMap; |
| 44 | 50 |
| 45 // The create functions in the archive classes return PassRefPtr to concrete sub classes | 51 // The create functions in the archive classes return PassRefPtr to concrete sub classes |
| 46 // of Archive. This adaptor makes the functions have a uniform return type. | 52 // of Archive. This adaptor makes the functions have a uniform return type. |
| 47 template <typename ArchiveClass> static PassRefPtr<Archive> archiveFactoryCreate (const KURL& url, SharedBuffer* buffer) | 53 template <typename ArchiveClass> static PassRefPtr<Archive> archiveFactoryCreate (const KURL& url, SharedBuffer* buffer) |
| 48 { | 54 { |
| 49 return ArchiveClass::create(url, buffer); | 55 return ArchiveClass::create(url, buffer); |
| 50 } | 56 } |
| 51 | 57 |
| 52 static ArchiveMIMETypesMap& archiveMIMETypes() | 58 static ArchiveMIMETypesMap& archiveMIMETypes() |
| 53 { | 59 { |
| 54 DEFINE_STATIC_LOCAL(ArchiveMIMETypesMap, mimeTypes, ()); | 60 DEFINE_STATIC_LOCAL(ArchiveMIMETypesMap, mimeTypes, ()); |
| 55 static bool initialized = false; | 61 static bool initialized = false; |
| 56 | 62 |
| 57 if (initialized) | 63 if (initialized) |
| 58 return mimeTypes; | 64 return mimeTypes; |
| 59 | 65 |
| 66 #if ENABLE(WEB_ARCHIVE) && USE(CF) | |
| 67 mimeTypes.set("application/x-webarchive", archiveFactoryCreate<LegacyWebArch ive>); | |
| 68 #endif | |
| 69 #if ENABLE(MHTML) | |
| 60 mimeTypes.set("multipart/related", archiveFactoryCreate<MHTMLArchive>); | 70 mimeTypes.set("multipart/related", archiveFactoryCreate<MHTMLArchive>); |
| 71 #endif | |
| 61 | 72 |
| 62 initialized = true; | 73 initialized = true; |
| 63 return mimeTypes; | 74 return mimeTypes; |
| 64 } | 75 } |
| 65 | 76 |
| 66 bool ArchiveFactory::isArchiveMimeType(const String& mimeType) | 77 bool ArchiveFactory::isArchiveMimeType(const String& mimeType) |
| 67 { | 78 { |
| 68 return !mimeType.isEmpty() && archiveMIMETypes().contains(mimeType); | 79 return !mimeType.isEmpty() && archiveMIMETypes().contains(mimeType); |
| 69 } | 80 } |
| 70 | 81 |
| 71 PassRefPtr<Archive> ArchiveFactory::create(const KURL& url, SharedBuffer* data, const String& mimeType) | 82 PassRefPtr<Archive> ArchiveFactory::create(const KURL& url, SharedBuffer* data, const String& mimeType) |
| 72 { | 83 { |
| 73 RawDataCreationFunction* function = mimeType.isEmpty() ? 0 : archiveMIMEType s().get(mimeType); | 84 RawDataCreationFunction* function = mimeType.isEmpty() ? 0 : archiveMIMEType s().get(mimeType); |
| 74 return function ? function(url, data) : PassRefPtr<Archive>(0); | 85 return function ? function(url, data) : PassRefPtr<Archive>(0); |
| 75 } | 86 } |
| 76 | 87 |
| 77 void ArchiveFactory::registerKnownArchiveMIMETypes() | 88 void ArchiveFactory::registerKnownArchiveMIMETypes() |
| 78 { | 89 { |
| 79 HashSet<String>& mimeTypes = MIMETypeRegistry::getSupportedNonImageMIMETypes (); | 90 HashSet<String>& mimeTypes = MIMETypeRegistry::getSupportedNonImageMIMETypes (); |
| 80 ArchiveMIMETypesMap::iterator i = archiveMIMETypes().begin(); | 91 ArchiveMIMETypesMap::iterator i = archiveMIMETypes().begin(); |
| 81 ArchiveMIMETypesMap::iterator end = archiveMIMETypes().end(); | 92 ArchiveMIMETypesMap::iterator end = archiveMIMETypes().end(); |
| 82 | 93 |
| 83 for (; i != end; ++i) | 94 for (; i != end; ++i) |
| 84 mimeTypes.add(i->key); | 95 mimeTypes.add(i->key); |
| 85 } | 96 } |
| 86 | 97 |
| 87 } | 98 } |
| OLD | NEW |