diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/loader/archive/ArchiveFactory.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/loader/archive/ArchiveFactory.cpp')
-rw-r--r-- | Source/WebCore/loader/archive/ArchiveFactory.cpp | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/Source/WebCore/loader/archive/ArchiveFactory.cpp b/Source/WebCore/loader/archive/ArchiveFactory.cpp index adbd5da44..417ac47a7 100644 --- a/Source/WebCore/loader/archive/ArchiveFactory.cpp +++ b/Source/WebCore/loader/archive/ArchiveFactory.cpp @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -40,41 +40,42 @@ #include <wtf/HashMap.h> #include <wtf/HashSet.h> +#include <wtf/NeverDestroyed.h> #include <wtf/StdLibExtras.h> #include <wtf/text/WTFString.h> namespace WebCore { -typedef PassRefPtr<Archive> RawDataCreationFunction(const URL&, SharedBuffer*); -typedef HashMap<String, RawDataCreationFunction*, CaseFoldingHash> ArchiveMIMETypesMap; +typedef RefPtr<Archive> RawDataCreationFunction(const URL&, SharedBuffer&); +typedef HashMap<String, RawDataCreationFunction*, ASCIICaseInsensitiveHash> ArchiveMIMETypesMap; -// The create functions in the archive classes return PassRefPtr to concrete subclasses +// The create functions in the archive classes return RefPtr to concrete subclasses // of Archive. This adaptor makes the functions have a uniform return type. -template <typename ArchiveClass> static PassRefPtr<Archive> archiveFactoryCreate(const URL& url, SharedBuffer* buffer) +template<typename ArchiveClass> static RefPtr<Archive> archiveFactoryCreate(const URL& url, SharedBuffer& buffer) { return ArchiveClass::create(url, buffer); } -static ArchiveMIMETypesMap& archiveMIMETypes() +static ArchiveMIMETypesMap createArchiveMIMETypesMap() { - DEFINE_STATIC_LOCAL(ArchiveMIMETypesMap, mimeTypes, ()); - static bool initialized = false; - - if (initialized) - return mimeTypes; + ArchiveMIMETypesMap map; - // FIXME: Remove unnecessary 'static_cast<RawDataCreationFunction*>' from the following 'mimeTypes.set' operations - // once we switch to a non-broken Visual Studio compiler. https://bugs.webkit.org/show_bug.cgi?id=121235 #if ENABLE(WEB_ARCHIVE) && USE(CF) - mimeTypes.set("application/x-webarchive", static_cast<RawDataCreationFunction*>(&archiveFactoryCreate<LegacyWebArchive>)); + map.add(ASCIILiteral { "application/x-webarchive" }, archiveFactoryCreate<LegacyWebArchive>); #endif + #if ENABLE(MHTML) - mimeTypes.set("multipart/related", static_cast<RawDataCreationFunction*>(&archiveFactoryCreate<MHTMLArchive>)); - mimeTypes.set("application/x-mimearchive", static_cast<RawDataCreationFunction*>(&archiveFactoryCreate<MHTMLArchive>)); + map.add(ASCIILiteral { "multipart/related" }, archiveFactoryCreate<MHTMLArchive>); + map.add(ASCIILiteral { "application/x-mimearchive" }, archiveFactoryCreate<MHTMLArchive>); #endif - initialized = true; - return mimeTypes; + return map; +} + +static ArchiveMIMETypesMap& archiveMIMETypes() +{ + static NeverDestroyed<ArchiveMIMETypesMap> map = createArchiveMIMETypesMap(); + return map; } bool ArchiveFactory::isArchiveMimeType(const String& mimeType) @@ -82,17 +83,22 @@ bool ArchiveFactory::isArchiveMimeType(const String& mimeType) return !mimeType.isEmpty() && archiveMIMETypes().contains(mimeType); } -PassRefPtr<Archive> ArchiveFactory::create(const URL& url, SharedBuffer* data, const String& mimeType) +RefPtr<Archive> ArchiveFactory::create(const URL& url, SharedBuffer* data, const String& mimeType) { - RawDataCreationFunction* function = mimeType.isEmpty() ? 0 : archiveMIMETypes().get(mimeType); - return function ? function(url, data) : PassRefPtr<Archive>(0); + if (!data) + return nullptr; + if (mimeType.isEmpty()) + return nullptr; + auto* function = archiveMIMETypes().get(mimeType); + if (!function) + return nullptr; + return function(url, *data); } void ArchiveFactory::registerKnownArchiveMIMETypes() { - HashSet<String>& mimeTypes = MIMETypeRegistry::getSupportedNonImageMIMETypes(); - - for (const auto& mimeType : archiveMIMETypes().keys()) + auto& mimeTypes = MIMETypeRegistry::getSupportedNonImageMIMETypes(); + for (auto& mimeType : archiveMIMETypes().keys()) mimeTypes.add(mimeType); } |