Cleanup: MIMETypeRegistry functions
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Oct 2018 18:42:22 +0000 (18:42 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Oct 2018 18:42:22 +0000 (18:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190838

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2018-10-24
Reviewed by Simon Fraser.

Source/WebCore:

Modernize the initialization of the lists in MIMETypeRegistry. Make the
functions that return these list be self-contained. Use NeverDestroy<> to
allocate the local static variable. Use std::initializer_list() and
makeNeverDestroyed() to initialize NeverDestroy<> variables only once.

supportedImageResourceMIMETypes will be deleted and all the calls to it
will be replaced by supportedImageMIMETypes because they are identical.

* loader/archive/ArchiveFactory.cpp:
(WebCore::ArchiveFactory::registerKnownArchiveMIMETypes): This function
is called while initializing the supportedNonImageMIMETypes(). So it
should not have a direct call to it. Instead, supportedNonImageMIMETypes
is passed to it.
* loader/archive/ArchiveFactory.h:
* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::supportedImageMIMETypes):
(WebCore::supportedImageMIMETypesForEncoding):
(WebCore::supportedJavaScriptMIMETypes):
(WebCore::MIMETypeRegistry::supportedNonImageMIMETypes):
(WebCore::MIMETypeRegistry::supportedMediaMIMETypes):
(WebCore::pdfMIMETypes):
(WebCore::MIMETypeRegistry::unsupportedTextMIMETypes):
(WebCore::MIMETypeRegistry::isSupportedImageMIMEType):
(WebCore::MIMETypeRegistry::isSupportedImageMIMETypeForEncoding):
(WebCore::MIMETypeRegistry::isSupportedJavaScriptMIMEType):
(WebCore::MIMETypeRegistry::isSupportedNonImageMIMEType):
(WebCore::MIMETypeRegistry::isSupportedMediaMIMEType):
(WebCore::MIMETypeRegistry::isUnsupportedTextMIMEType):
(WebCore::MIMETypeRegistry::isPDFMIMEType):
(WebCore::MIMETypeRegistry::systemPreviewMIMETypes):
(WebCore::MIMETypeRegistry::isSystemPreviewMIMEType):
(WebCore::initializeSupportedImageMIMETypes): Deleted.
(WebCore::initializeSupportedImageMIMETypesForEncoding): Deleted.
(WebCore::initializeSupportedJavaScriptMIMETypes): Deleted.
(WebCore::initializePDFMIMETypes): Deleted.
(WebCore::initializeSupportedNonImageMimeTypes): Deleted.
(WebCore::initializeSupportedMediaMIMETypes): Deleted.
(WebCore::initializeUnsupportedTextMIMETypes): Deleted.
(WebCore::MIMETypeRegistry::isSupportedImageResourceMIMEType): Deleted.
(WebCore::MIMETypeRegistry::getSupportedImageMIMETypes): Deleted.
(WebCore::MIMETypeRegistry::getSupportedImageResourceMIMETypes): Deleted.
(WebCore::MIMETypeRegistry::getSupportedNonImageMIMETypes): Deleted.
(WebCore::MIMETypeRegistry::getSupportedMediaMIMETypes): Deleted.
(WebCore::MIMETypeRegistry::getPDFMIMETypes): Deleted.
(WebCore::MIMETypeRegistry::getUnsupportedTextMIMETypes): Deleted.
(WebCore::MIMETypeRegistry::getSystemPreviewMIMETypes): Deleted.
* platform/MIMETypeRegistry.h:
* platform/graphics/Image.cpp:
(WebCore::Image::supportsType):
* platform/graphics/cg/ImageDecoderCG.cpp:
(WebCore::ImageDecoderCG::encodedDataStatus const):
* platform/graphics/cg/UTIRegistry.cpp:
(WebCore::supportedDefaultImageSourceTypes):
(WebCore::isSupportImageSourceType):
(WebCore::allowedImageUTIs): Deleted.
(WebCore::isAllowedImageUTI): Deleted.
* platform/graphics/cg/UTIRegistry.h:
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::write):

Source/WebKit:

* UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm:
(-[WKWebViewContentProviderRegistry initWithConfiguration:]):

Source/WebKitLegacy/mac:

* Misc/WebNSPasteboardExtras.mm:
(-[NSPasteboard _web_writePromisedRTFDFromArchive:containsImage:]):
Replace isSupportedImageResourceMIMEType() by isSupportedImageMIMEType()
because they were identical.

* WebView/WebHTMLRepresentation.mm:
(+[WebHTMLRepresentation supportedMediaMIMETypes]):
(+[WebHTMLRepresentation supportedNonImageMIMETypes]):
(+[WebHTMLRepresentation supportedImageMIMETypes]):
(+[WebHTMLRepresentation unsupportedTextMIMETypes]):
* WebView/WebView.mm:
(+[WebView _unregisterViewClassAndRepresentationClassForMIMEType:]):
(+[WebView _registerViewClass:representationClass:forURLScheme:]):
(+[WebView registerViewClass:representationClass:forMIMEType:]):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@237393 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/archive/ArchiveFactory.cpp
Source/WebCore/loader/archive/ArchiveFactory.h
Source/WebCore/platform/MIMETypeRegistry.cpp
Source/WebCore/platform/MIMETypeRegistry.h
Source/WebCore/platform/graphics/Image.cpp
Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp
Source/WebCore/platform/graphics/cg/UTIRegistry.cpp
Source/WebCore/platform/graphics/cg/UTIRegistry.h
Source/WebCore/platform/mac/PasteboardMac.mm
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/Misc/WebNSPasteboardExtras.mm
Source/WebKitLegacy/mac/WebView/WebHTMLRepresentation.mm
Source/WebKitLegacy/mac/WebView/WebView.mm

index de69358..38e6da2 100644 (file)
@@ -1,3 +1,70 @@
+2018-10-24  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Cleanup: MIMETypeRegistry functions
+        https://bugs.webkit.org/show_bug.cgi?id=190838
+
+        Reviewed by Simon Fraser.
+
+        Modernize the initialization of the lists in MIMETypeRegistry. Make the
+        functions that return these list be self-contained. Use NeverDestroy<> to
+        allocate the local static variable. Use std::initializer_list() and
+        makeNeverDestroyed() to initialize NeverDestroy<> variables only once.
+
+        supportedImageResourceMIMETypes will be deleted and all the calls to it 
+        will be replaced by supportedImageMIMETypes because they are identical.
+
+        * loader/archive/ArchiveFactory.cpp:
+        (WebCore::ArchiveFactory::registerKnownArchiveMIMETypes): This function
+        is called while initializing the supportedNonImageMIMETypes(). So it
+        should not have a direct call to it. Instead, supportedNonImageMIMETypes
+        is passed to it.
+        * loader/archive/ArchiveFactory.h:
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::MIMETypeRegistry::supportedImageMIMETypes):
+        (WebCore::supportedImageMIMETypesForEncoding):
+        (WebCore::supportedJavaScriptMIMETypes):
+        (WebCore::MIMETypeRegistry::supportedNonImageMIMETypes):
+        (WebCore::MIMETypeRegistry::supportedMediaMIMETypes):
+        (WebCore::pdfMIMETypes):
+        (WebCore::MIMETypeRegistry::unsupportedTextMIMETypes):
+        (WebCore::MIMETypeRegistry::isSupportedImageMIMEType):
+        (WebCore::MIMETypeRegistry::isSupportedImageMIMETypeForEncoding):
+        (WebCore::MIMETypeRegistry::isSupportedJavaScriptMIMEType):
+        (WebCore::MIMETypeRegistry::isSupportedNonImageMIMEType):
+        (WebCore::MIMETypeRegistry::isSupportedMediaMIMEType):
+        (WebCore::MIMETypeRegistry::isUnsupportedTextMIMEType):
+        (WebCore::MIMETypeRegistry::isPDFMIMEType):
+        (WebCore::MIMETypeRegistry::systemPreviewMIMETypes):
+        (WebCore::MIMETypeRegistry::isSystemPreviewMIMEType):
+        (WebCore::initializeSupportedImageMIMETypes): Deleted.
+        (WebCore::initializeSupportedImageMIMETypesForEncoding): Deleted.
+        (WebCore::initializeSupportedJavaScriptMIMETypes): Deleted.
+        (WebCore::initializePDFMIMETypes): Deleted.
+        (WebCore::initializeSupportedNonImageMimeTypes): Deleted.
+        (WebCore::initializeSupportedMediaMIMETypes): Deleted.
+        (WebCore::initializeUnsupportedTextMIMETypes): Deleted.
+        (WebCore::MIMETypeRegistry::isSupportedImageResourceMIMEType): Deleted.
+        (WebCore::MIMETypeRegistry::getSupportedImageMIMETypes): Deleted.
+        (WebCore::MIMETypeRegistry::getSupportedImageResourceMIMETypes): Deleted.
+        (WebCore::MIMETypeRegistry::getSupportedNonImageMIMETypes): Deleted.
+        (WebCore::MIMETypeRegistry::getSupportedMediaMIMETypes): Deleted.
+        (WebCore::MIMETypeRegistry::getPDFMIMETypes): Deleted.
+        (WebCore::MIMETypeRegistry::getUnsupportedTextMIMETypes): Deleted.
+        (WebCore::MIMETypeRegistry::getSystemPreviewMIMETypes): Deleted.
+        * platform/MIMETypeRegistry.h:
+        * platform/graphics/Image.cpp:
+        (WebCore::Image::supportsType):
+        * platform/graphics/cg/ImageDecoderCG.cpp:
+        (WebCore::ImageDecoderCG::encodedDataStatus const):
+        * platform/graphics/cg/UTIRegistry.cpp:
+        (WebCore::supportedDefaultImageSourceTypes):
+        (WebCore::isSupportImageSourceType):
+        (WebCore::allowedImageUTIs): Deleted.
+        (WebCore::isAllowedImageUTI): Deleted.
+        * platform/graphics/cg/UTIRegistry.h:
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::Pasteboard::write):
+
 2018-10-24  Chris Dumez  <cdumez@apple.com>
 
         [PSON] When navigating back and forth, 'about:blank' shows up in the back/forward list
index 48c388e..6de80c1 100644 (file)
@@ -95,9 +95,8 @@ RefPtr<Archive> ArchiveFactory::create(const URL& url, SharedBuffer* data, const
     return function(url, *data);
 }
 
-void ArchiveFactory::registerKnownArchiveMIMETypes()
+void ArchiveFactory::registerKnownArchiveMIMETypes(HashSet<String, ASCIICaseInsensitiveHash>& mimeTypes)
 {
-    auto& mimeTypes = MIMETypeRegistry::getSupportedNonImageMIMETypes();
     for (auto& mimeType : archiveMIMETypes().keys())
         mimeTypes.add(mimeType);
 }
index 510e519..21d2365 100644 (file)
@@ -40,7 +40,7 @@ class ArchiveFactory {
 public:
     static bool isArchiveMIMEType(const String&);
     static RefPtr<Archive> create(const URL&, SharedBuffer* data, const String& mimeType);
-    static void registerKnownArchiveMIMETypes();
+    static void registerKnownArchiveMIMETypes(HashSet<String, ASCIICaseInsensitiveHash>&);
 };
 
 } // namespace WebCore
index 5b33162..3e98d83 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2018 Apple Inc. All rights reserved.
  * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
  *
  * Redistribution and use in source and binary forms, with or without
 
 namespace WebCore {
 
-static HashSet<String, ASCIICaseInsensitiveHash>* supportedImageResourceMIMETypes;
-static HashSet<String, ASCIICaseInsensitiveHash>* supportedImageMIMETypes;
-static HashSet<String, ASCIICaseInsensitiveHash>* supportedImageMIMETypesForEncoding;
-static HashSet<String, ASCIICaseInsensitiveHash>* supportedJavaScriptMIMETypes;
-static HashSet<String, ASCIICaseInsensitiveHash>* supportedNonImageMIMETypes;
-static HashSet<String, ASCIICaseInsensitiveHash>* supportedMediaMIMETypes;
-static HashSet<String, ASCIICaseInsensitiveHash>* pdfMIMETypes;
-static HashSet<String, ASCIICaseInsensitiveHash>* unsupportedTextMIMETypes;
-
-static void initializeSupportedImageMIMETypes()
+const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::supportedImageMIMETypes()
 {
-    supportedImageResourceMIMETypes = new HashSet<String, ASCIICaseInsensitiveHash>;
-    supportedImageMIMETypes = new HashSet<String, ASCIICaseInsensitiveHash>;
-
+    static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> supportedImageMIMETypes = std::initializer_list<String> {
 #if USE(CG)
-    // This represents the subset of allowed image UTIs for which CoreServices has a corresponding MIME type. Keep this in sync with allowedImageUTIs().
-    static const ASCIILiteral allowedImageMIMETypes[] = { "image/tiff"_s, "image/gif"_s, "image/jpeg"_s, "image/vnd.microsoft.icon"_s, "image/jp2"_s, "image/png"_s, "image/bmp"_s };
-    for (auto& mimeType : allowedImageMIMETypes) {
-        supportedImageMIMETypes->add(mimeType);
-        supportedImageResourceMIMETypes->add(mimeType);
-    }
-
-#ifndef NDEBUG
-    for (auto& uti : allowedImageUTIs()) {
-        auto mimeType = MIMETypeForImageSourceType(uti);
-        if (!mimeType.isEmpty()) {
-            ASSERT(supportedImageMIMETypes->contains(mimeType));
-            ASSERT(supportedImageResourceMIMETypes->contains(mimeType));
-        }
-    }
-
-#if PLATFORM(COCOA)
-    for (auto& mime : *supportedImageMIMETypes)
-        ASSERT_UNUSED(mime, allowedImageUTIs().contains(UTIFromMIMEType(mime)));
-#endif
-#endif
-
-    // Favicons don't have a MIME type in the registry either.
-    supportedImageMIMETypes->add("image/x-icon");
-    supportedImageResourceMIMETypes->add("image/x-icon");
-
-    //  We only get one MIME type per UTI, hence our need to add these manually
-    supportedImageMIMETypes->add("image/pjpeg");
-    supportedImageResourceMIMETypes->add("image/pjpeg");
+        // This represents the subset of allowed image UTIs for which CoreServices has a corresponding MIME type.
+        "image/tiff"_s,
+        "image/gif"_s,
+        "image/jpeg"_s,
+        "image/vnd.microsoft.icon"_s,
+        "image/jp2"_s,
+        "image/png"_s,
+        "image/bmp"_s,
+
+        "image/x-icon"_s, // Favicons don't have a MIME type in the registry either.
+        "image/pjpeg"_s, //  We only get one MIME type per UTI, hence our need to add these manually
 
 #if PLATFORM(IOS_FAMILY)
-    // Add malformed image mimetype for compatibility with Mail and to handle malformed mimetypes from the net
-    // These were removed for <rdar://problem/6564538> Re-enable UTI code in WebCore now that MobileCoreServices exists
-    // But Mail relies on at least image/tif reported as being supported (should be image/tiff).
-    // This can be removed when Mail addresses:
-    // <rdar://problem/7879510> Mail should use standard image mimetypes
-    // and we fix sniffing so that it corrects items such as image/jpg -> image/jpeg.
-    static const char* const malformedMIMETypes[] = {
+        // Add malformed image mimetype for compatibility with Mail and to handle malformed mimetypes from the net
+        // These were removed for <rdar://problem/6564538> Re-enable UTI code in WebCore now that MobileCoreServices exists
+        // But Mail relies on at least image/tif reported as being supported (should be image/tiff).
+        // This can be removed when Mail addresses:
+        // <rdar://problem/7879510> Mail should use standard image mimetypes
+        // and we fix sniffing so that it corrects items such as image/jpg -> image/jpeg.
+
         // JPEG (image/jpeg)
-        "image/jpg", "image/jp_", "image/jpe_", "application/jpg", "application/x-jpg", "image/pipeg",
-        "image/vnd.switfview-jpeg", "image/x-xbitmap",
+        "image/jpg"_s,
+        "image/jp_"_s,
+        "image/jpe_"_s,
+        "application/jpg"_s,
+        "application/x-jpg"_s,
+        "image/pipeg"_s,
+        "image/vnd.switfview-jpeg"_s,
+        "image/x-xbitmap"_s,
+
         // GIF (image/gif)
-        "image/gi_",
+        "image/gi_"_s,
+
         // PNG (image/png)
-        "application/png", "application/x-png",
+        "application/png"_s,
+        "application/x-png"_s,
+
         // TIFF (image/tiff)
-        "image/x-tif", "image/tif", "image/x-tiff", "application/tif", "application/x-tif", "application/tiff",
-        "application/x-tiff",
+        "image/x-tif"_s,
+        "image/tif"_s,
+        "image/x-tiff"_s,
+        "application/tif"_s,
+        "application/x-tif"_s,
+        "application/tiff"_s,
+        "application/x-tiff"_s,
+
         // BMP (image/bmp, image/x-bitmap)
-        "image/x-bmp", "image/x-win-bitmap", "image/x-windows-bmp", "image/ms-bmp", "image/x-ms-bmp",
-        "application/bmp", "application/x-bmp", "application/x-win-bitmap",
-    };
-    for (auto& type : malformedMIMETypes) {
-        supportedImageMIMETypes->add(type);
-        supportedImageResourceMIMETypes->add(type);
-    }
+        "image/x-bmp"_s,
+        "image/x-win-bitmap"_s,
+        "image/x-windows-bmp"_s,
+        "image/ms-bmp"_s,
+        "image/x-ms-bmp"_s,
+        "application/bmp"_s,
+        "application/x-bmp"_s,
+        "application/x-win-bitmap"_s,
 #endif
-
 #else
-    // assume that all implementations at least support the following standard
-    // image types:
-    static const char* const types[] = {
-        "image/jpeg",
-        "image/png",
-        "image/gif",
-        "image/bmp",
-        "image/vnd.microsoft.icon",    // ico
-        "image/x-icon",    // ico
-        "image/x-xbitmap"  // xbm
-    };
-    for (auto& type : types) {
-        supportedImageMIMETypes->add(type);
-        supportedImageResourceMIMETypes->add(type);
-    }
-
+        // assume that all implementations at least support the following standard
+        // image types:
+        "image/jpeg"_s,
+        "image/png"_s,
+        "image/gif"_s,
+        "image/bmp"_s,
+        "image/vnd.microsoft.icon"_s, // ico
+        "image/x-icon"_s, // ico
+        "image/x-xbitmap"_s, // xbm
 #if USE(WEBP)
-    supportedImageMIMETypes->add("image/webp");
-    supportedImageResourceMIMETypes->add("image/webp");
+        "image/webp"_s,
+#endif
 #endif
+    };
 
-#endif // USE(CG)
+#if USE(CG)
+#ifndef NDEBUG
+    // Esnure supportedImageMIMETypes() is in sync with supportedDefaultImageSourceTypes().
+    static std::once_flag onceFlag;
+    std::call_once(onceFlag, [] {
+        for (auto& imageSourceType : supportedDefaultImageSourceTypes()) {
+            auto mimeType = MIMETypeForImageSourceType(imageSourceType);
+            ASSERT_IMPLIES(!mimeType.isEmpty(), supportedImageMIMETypes.get().contains(mimeType));
+        }
+    });
+#endif
+#endif
+    return supportedImageMIMETypes;
 }
 
-static void initializeSupportedImageMIMETypesForEncoding()
+static const HashSet<String, ASCIICaseInsensitiveHash>& supportedImageMIMETypesForEncoding()
 {
-    supportedImageMIMETypesForEncoding = new HashSet<String, ASCIICaseInsensitiveHash>;
-
-#if USE(CG)
 #if PLATFORM(COCOA)
-    RetainPtr<CFArrayRef> supportedTypes = adoptCF(CGImageDestinationCopyTypeIdentifiers());
-    CFIndex count = CFArrayGetCount(supportedTypes.get());
-    for (CFIndex i = 0; i < count; i++) {
-        CFStringRef supportedType = reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(supportedTypes.get(), i));
-        String mimeType = MIMETypeForImageSourceType(supportedType);
-        if (!mimeType.isEmpty())
-            supportedImageMIMETypesForEncoding->add(mimeType);
-    }
+    static const auto supportedImageMIMETypesForEncoding = makeNeverDestroyed([] {
+        RetainPtr<CFArrayRef> supportedTypes = adoptCF(CGImageDestinationCopyTypeIdentifiers());
+        HashSet<String, ASCIICaseInsensitiveHash> supportedImageMIMETypesForEncoding;
+        CFIndex count = CFArrayGetCount(supportedTypes.get());
+        for (CFIndex i = 0; i < count; i++) {
+            CFStringRef supportedType = reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(supportedTypes.get(), i));
+            String mimeType = MIMETypeForImageSourceType(supportedType);
+            if (!mimeType.isEmpty())
+                supportedImageMIMETypesForEncoding.add(mimeType);
+        }
+        return supportedImageMIMETypesForEncoding;
+    }());
 #else
-    // FIXME: Add Windows support for all the supported UTI's when a way to convert from MIMEType to UTI reliably is found.
-    // For now, only support PNG, JPEG and GIF.  See <rdar://problem/6095286>.
-    supportedImageMIMETypesForEncoding->add("image/png");
-    supportedImageMIMETypesForEncoding->add("image/jpeg");
-    supportedImageMIMETypesForEncoding->add("image/gif");
-#endif
+    static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> supportedImageMIMETypesForEncoding =std::initializer_list<String> {
+#if USE(CG)
+        // FIXME: Add Windows support for all the supported UTI's when a way to convert from MIMEType to UTI reliably is found.
+        // For now, only support PNG, JPEG and GIF. See <rdar://problem/6095286>.
+        "image/png"_s,
+        "image/jpeg"_s,
+        "image/gif"_s,
 #elif PLATFORM(GTK)
-    supportedImageMIMETypesForEncoding->add("image/png");
-    supportedImageMIMETypesForEncoding->add("image/jpeg");
-    supportedImageMIMETypesForEncoding->add("image/tiff");
-    supportedImageMIMETypesForEncoding->add("image/bmp");
-    supportedImageMIMETypesForEncoding->add("image/ico");
+        "image/png"_s,
+        "image/jpeg"_s,
+        "image/tiff"_s,
+        "image/bmp"_s,
+        "image/ico"_s,
 #elif USE(CAIRO)
-    supportedImageMIMETypesForEncoding->add("image/png");
+        "image/png"_s,
 #endif
-}
-
-static void initializeSupportedJavaScriptMIMETypes()
-{
-    // https://html.spec.whatwg.org/multipage/scripting.html#javascript-mime-type
-    static const char* const types[] = {
-        "text/javascript",
-        "text/ecmascript",
-        "application/javascript",
-        "application/ecmascript",
-        "application/x-javascript",
-        "application/x-ecmascript",
-        "text/javascript1.0",
-        "text/javascript1.1",
-        "text/javascript1.2",
-        "text/javascript1.3",
-        "text/javascript1.4",
-        "text/javascript1.5",
-        "text/jscript",
-        "text/livescript",
-        "text/x-javascript",
-        "text/x-ecmascript"
     };
-
-    supportedJavaScriptMIMETypes = new HashSet<String, ASCIICaseInsensitiveHash>;
-    for (auto* type : types)
-        supportedJavaScriptMIMETypes->add(type);
-}
-
-static void initializePDFMIMETypes()
-{
-    const char* const types[] = {
-        "application/pdf",
-        "text/pdf"
+#endif
+    return supportedImageMIMETypesForEncoding;
+}
+
+static const HashSet<String, ASCIICaseInsensitiveHash>& supportedJavaScriptMIMETypes()
+{
+    static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> supportedJavaScriptMIMETypes = std::initializer_list<String> {
+        // https://html.spec.whatwg.org/multipage/scripting.html#javascript-mime-type
+        "text/javascript"_s,
+        "text/ecmascript"_s,
+        "application/javascript"_s,
+        "application/ecmascript"_s,
+        "application/x-javascript"_s,
+        "application/x-ecmascript"_s,
+        "text/javascript1.0"_s,
+        "text/javascript1.1"_s,
+        "text/javascript1.2"_s,
+        "text/javascript1.3"_s,
+        "text/javascript1.4"_s,
+        "text/javascript1.5"_s,
+        "text/jscript"_s,
+        "text/livescript"_s,
+        "text/x-javascript"_s,
+        "text/x-ecmascript"_s,
     };
-
-    pdfMIMETypes = new HashSet<String, ASCIICaseInsensitiveHash>;
-    for (auto& type : types)
-        pdfMIMETypes->add(type);
+    return supportedJavaScriptMIMETypes;
 }
 
-static void initializeSupportedNonImageMimeTypes()
+HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::supportedNonImageMIMETypes()
 {
-    static const char* const types[] = {
-        "text/html",
-        "text/xml",
-        "text/xsl",
-        "text/plain",
-        "text/",
-        "application/xml",
-        "application/xhtml+xml",
+    static auto supportedNonImageMIMETypes = makeNeverDestroyed([] {
+        HashSet<String, ASCIICaseInsensitiveHash> supportedNonImageMIMETypes = std::initializer_list<String> {
+            "text/html"_s,
+            "text/xml"_s,
+            "text/xsl"_s,
+            "text/plain"_s,
+            "text/"_s,
+            "application/xml"_s,
+            "application/xhtml+xml"_s,
 #if !PLATFORM(IOS_FAMILY)
-        "application/vnd.wap.xhtml+xml",
-        "application/rss+xml",
-        "application/atom+xml",
+            "application/vnd.wap.xhtml+xml"_s,
+            "application/rss+xml"_s,
+            "application/atom+xml"_s,
 #endif
-        "application/json",
-        "image/svg+xml",
+            "application/json"_s,
+            "image/svg+xml"_s,
 #if ENABLE(FTPDIR)
-        "application/x-ftp-directory",
+            "application/x-ftp-directory"_s,
 #endif
-        "multipart/x-mixed-replace"
+            "multipart/x-mixed-replace"_s,
         // Note: Adding a new type here will probably render it as HTML.
         // This can result in cross-site scripting vulnerabilities.
-    };
+        };
+        supportedNonImageMIMETypes.add(supportedJavaScriptMIMETypes().begin(), supportedJavaScriptMIMETypes().end());
+#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
+        ArchiveFactory::registerKnownArchiveMIMETypes(supportedNonImageMIMETypes);
+#endif
+        return supportedNonImageMIMETypes;
+    }());
+    return supportedNonImageMIMETypes;
+}
 
-    if (!supportedJavaScriptMIMETypes)
-        initializeSupportedJavaScriptMIMETypes();
+const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::supportedMediaMIMETypes()
+{
+    static const auto supportedMediaMIMETypes = makeNeverDestroyed([] {
+        HashSet<String, ASCIICaseInsensitiveHash> supportedMediaMIMETypes;
+#if ENABLE(VIDEO)
+        MediaPlayer::getSupportedTypes(supportedMediaMIMETypes);
+#endif
+        return supportedMediaMIMETypes;
+    }());
+    return supportedMediaMIMETypes;
+}
 
-    supportedNonImageMIMETypes = new HashSet<String, ASCIICaseInsensitiveHash> { *supportedJavaScriptMIMETypes };
-    for (auto& type : types)
-        supportedNonImageMIMETypes->add(type);
+const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::pdfMIMETypes()
+{
+    static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> pdfMIMETypes = std::initializer_list<String> {
+        "application/pdf"_s,
+        "text/pdf"_s,
+    };
+    return pdfMIMETypes;
+}
 
-#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
-    ArchiveFactory::registerKnownArchiveMIMETypes();
+const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::unsupportedTextMIMETypes()
+{
+    static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> unsupportedTextMIMETypes = std::initializer_list<String> {
+        "text/calendar"_s,
+        "text/x-calendar"_s,
+        "text/x-vcalendar"_s,
+        "text/vcalendar"_s,
+        "text/vcard"_s,
+        "text/x-vcard"_s,
+        "text/directory"_s,
+        "text/ldif"_s,
+        "text/qif"_s,
+        "text/x-qif"_s,
+        "text/x-csv"_s,
+        "text/x-vcf"_s,
+#if !PLATFORM(IOS_FAMILY)
+        "text/rtf"_s,
+#else
+        "text/vnd.sun.j2me.app-descriptor"_s,
 #endif
+    };
+    return unsupportedTextMIMETypes;
 }
 
 static const Vector<String>* typesForCommonExtension(const String& extension)
@@ -392,41 +417,6 @@ Vector<String> MIMETypeRegistry::getMediaMIMETypesForExtension(const String& ext
     return { };
 }
 
-static void initializeSupportedMediaMIMETypes()
-{
-    supportedMediaMIMETypes = new HashSet<String, ASCIICaseInsensitiveHash>;
-#if ENABLE(VIDEO)
-    MediaPlayer::getSupportedTypes(*supportedMediaMIMETypes);
-#endif
-}
-
-static void initializeUnsupportedTextMIMETypes()
-{
-    static const char* const types[] = {
-        "text/calendar"_s,
-        "text/x-calendar"_s,
-        "text/x-vcalendar"_s,
-        "text/vcalendar"_s,
-        "text/vcard"_s,
-        "text/x-vcard"_s,
-        "text/directory"_s,
-        "text/ldif"_s,
-        "text/qif"_s,
-        "text/x-qif"_s,
-        "text/x-csv"_s,
-        "text/x-vcf"_s,
-#if !PLATFORM(IOS_FAMILY)
-        "text/rtf"_s,
-#else
-        "text/vnd.sun.j2me.app-descriptor"_s,
-#endif
-    };
-
-    unsupportedTextMIMETypes = new HashSet<String, ASCIICaseInsensitiveHash>;
-    for (auto& type : types)
-        unsupportedTextMIMETypes->add(type);
-}
-
 String MIMETypeRegistry::getMIMETypeForPath(const String& path)
 {
     size_t pos = path.reverseFind('.');
@@ -443,9 +433,7 @@ bool MIMETypeRegistry::isSupportedImageMIMEType(const String& mimeType)
 {
     if (mimeType.isEmpty())
         return false;
-    if (!supportedImageMIMETypes)
-        initializeSupportedImageMIMETypes();
-    return supportedImageMIMETypes->contains(getNormalizedMIMEType(mimeType));
+    return supportedImageMIMETypes().contains(getNormalizedMIMEType(mimeType));
 }
 
 bool MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(const String& mimeType)
@@ -461,24 +449,13 @@ bool MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(const String& mimeType
     return false;
 }
 
-bool MIMETypeRegistry::isSupportedImageResourceMIMEType(const String& mimeType)
-{
-    if (mimeType.isEmpty())
-        return false;
-    if (!supportedImageResourceMIMETypes)
-        initializeSupportedImageMIMETypes();
-    return supportedImageResourceMIMETypes->contains(getNormalizedMIMEType(mimeType));
-}
-
 bool MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(const String& mimeType)
 {
     ASSERT(isMainThread());
 
     if (mimeType.isEmpty())
         return false;
-    if (!supportedImageMIMETypesForEncoding)
-        initializeSupportedImageMIMETypesForEncoding();
-    return supportedImageMIMETypesForEncoding->contains(mimeType);
+    return supportedImageMIMETypesForEncoding().contains(mimeType);
 }
 
 bool MIMETypeRegistry::isSupportedJavaScriptMIMEType(const String& mimeType)
@@ -494,9 +471,7 @@ bool MIMETypeRegistry::isSupportedJavaScriptMIMEType(const String& mimeType)
         return isSupported;
     }
 
-    if (!supportedJavaScriptMIMETypes)
-        initializeSupportedNonImageMimeTypes();
-    return supportedJavaScriptMIMETypes->contains(mimeType);
+    return supportedJavaScriptMIMETypes().contains(mimeType);
 }
 
 bool MIMETypeRegistry::isSupportedStyleSheetMIMEType(const String& mimeType)
@@ -539,18 +514,14 @@ bool MIMETypeRegistry::isSupportedNonImageMIMEType(const String& mimeType)
 {
     if (mimeType.isEmpty())
         return false;
-    if (!supportedNonImageMIMETypes)
-        initializeSupportedNonImageMimeTypes();
-    return supportedNonImageMIMETypes->contains(mimeType);
+    return supportedNonImageMIMETypes().contains(mimeType);
 }
 
 bool MIMETypeRegistry::isSupportedMediaMIMEType(const String& mimeType)
 {
     if (mimeType.isEmpty())
         return false;
-    if (!supportedMediaMIMETypes)
-        initializeSupportedMediaMIMETypes();
-    return supportedMediaMIMETypes->contains(mimeType);
+    return supportedMediaMIMETypes().contains(mimeType);
 }
 
 bool MIMETypeRegistry::isSupportedTextTrackMIMEType(const String& mimeType)
@@ -562,9 +533,7 @@ bool MIMETypeRegistry::isUnsupportedTextMIMEType(const String& mimeType)
 {
     if (mimeType.isEmpty())
         return false;
-    if (!unsupportedTextMIMETypes)
-        initializeUnsupportedTextMIMETypes();
-    return unsupportedTextMIMETypes->contains(mimeType);
+    return unsupportedTextMIMETypes().contains(mimeType);
 }
 
 bool MIMETypeRegistry::isTextMIMEType(const String& mimeType)
@@ -622,9 +591,7 @@ bool MIMETypeRegistry::isPDFMIMEType(const String& mimeType)
 {
     if (mimeType.isEmpty())
         return false;
-    if (!pdfMIMETypes)
-        initializePDFMIMETypes();
-    return pdfMIMETypes->contains(mimeType);
+    return pdfMIMETypes().contains(mimeType);
 }
 
 bool MIMETypeRegistry::isPostScriptMIMEType(const String& mimeType)
@@ -651,49 +618,6 @@ bool MIMETypeRegistry::canShowMIMEType(const String& mimeType)
     return false;
 }
 
-const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::getSupportedImageMIMETypes()
-{
-    if (!supportedImageMIMETypes)
-        initializeSupportedImageMIMETypes();
-    return *supportedImageMIMETypes;
-}
-
-const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::getSupportedImageResourceMIMETypes()
-{
-    if (!supportedImageResourceMIMETypes)
-        initializeSupportedImageMIMETypes();
-    return *supportedImageResourceMIMETypes;
-}
-
-HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::getSupportedNonImageMIMETypes()
-{
-    if (!supportedNonImageMIMETypes)
-        initializeSupportedNonImageMimeTypes();
-    return *supportedNonImageMIMETypes;
-}
-
-const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::getSupportedMediaMIMETypes()
-{
-    if (!supportedMediaMIMETypes)
-        initializeSupportedMediaMIMETypes();
-    return *supportedMediaMIMETypes;
-}
-
-
-const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::getPDFMIMETypes()
-{
-    if (!pdfMIMETypes)
-        initializePDFMIMETypes();
-    return *pdfMIMETypes;
-}
-
-const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::getUnsupportedTextMIMETypes()
-{
-    if (!unsupportedTextMIMETypes)
-        initializeUnsupportedTextMIMETypes();
-    return *unsupportedTextMIMETypes;
-}
-
 const String& defaultMIMEType()
 {
     static NeverDestroyed<const String> defaultMIMEType(MAKE_STATIC_STRING_IMPL("application/octet-stream"));
@@ -701,7 +625,7 @@ const String& defaultMIMEType()
 }
 
 #if USE(SYSTEM_PREVIEW)
-const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::getSystemPreviewMIMETypes()
+const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::systemPreviewMIMETypes()
 {
     static NeverDestroyed<HashSet<String, ASCIICaseInsensitiveHash>> systemPreviewMIMETypes = std::initializer_list<String> {
         // The official type: https://www.iana.org/assignments/media-types/model/vnd.usdz+zip
@@ -717,7 +641,7 @@ bool MIMETypeRegistry::isSystemPreviewMIMEType(const String& mimeType)
 {
     if (mimeType.isEmpty())
         return false;
-    return getSystemPreviewMIMETypes().contains(mimeType);
+    return systemPreviewMIMETypes().contains(mimeType);
 }
 #endif
 
index 8d5a0dd..7185df4 100644 (file)
@@ -50,10 +50,6 @@ public:
     // Check to see if a MIME type is suitable for being loaded as an image, including SVG and Video (where supported).
     WEBCORE_EXPORT static bool isSupportedImageVideoOrSVGMIMEType(const String& mimeType);
 
-    // Check to see if a MIME type is suitable for being loaded as an image
-    // document in a frame.
-    WEBCORE_EXPORT static bool isSupportedImageResourceMIMEType(const String& mimeType);
-
     // Check to see if a MIME type is suitable for being encoded.
     static bool isSupportedImageMIMETypeForEncoding(const String& mimeType);
 
@@ -108,18 +104,15 @@ public:
     // makes this test is after many other tests are done on the MIME type.
     WEBCORE_EXPORT static bool isTextMIMEType(const String& mimeType);
 
-    // FIXME: WebKit coding style says we should not have the word "get" in the names of these functions.
     // FIXME: Would be nice to find a way to avoid exposing these sets, even worse exposing non-const references.
-    WEBCORE_EXPORT static HashSet<String, ASCIICaseInsensitiveHash>& getSupportedNonImageMIMETypes();
-
-    WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& getSupportedImageMIMETypes();
-    const static HashSet<String, ASCIICaseInsensitiveHash>& getSupportedImageResourceMIMETypes();
-    WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& getSupportedMediaMIMETypes();
-    WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& getPDFMIMETypes();
-    WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& getUnsupportedTextMIMETypes();
+    WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& supportedImageMIMETypes();
+    WEBCORE_EXPORT static HashSet<String, ASCIICaseInsensitiveHash>& supportedNonImageMIMETypes();
+    WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& supportedMediaMIMETypes();
+    WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& pdfMIMETypes();
+    WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& unsupportedTextMIMETypes();
 
 #if USE(SYSTEM_PREVIEW)
-    WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& getSystemPreviewMIMETypes();
+    WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& systemPreviewMIMETypes();
 #endif
 
     // FIXME: WebKit coding style says we should not have the word "get" in the name of this function.
index c42ec95..5bce618 100644 (file)
@@ -82,7 +82,7 @@ RefPtr<Image> Image::create(ImageObserver& observer)
 
 bool Image::supportsType(const String& type)
 {
-    return MIMETypeRegistry::isSupportedImageResourceMIMEType(type);
+    return MIMETypeRegistry::isSupportedImageMIMEType(type);
 } 
 
 bool Image::isPDFResource(const String& mimeType, const URL& url)
index 29401e8..852dd06 100644 (file)
@@ -199,7 +199,7 @@ EncodedDataStatus ImageDecoderCG::encodedDataStatus() const
         return EncodedDataStatus::Error;
 
     case kCGImageStatusIncomplete: {
-        if (!isAllowedImageUTI(uti))
+        if (!isSupportImageSourceType(uti))
             return EncodedDataStatus::Error;
 
         RetainPtr<CFDictionaryRef> image0Properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), 0, imageSourceOptions().get()));
@@ -213,7 +213,7 @@ EncodedDataStatus ImageDecoderCG::encodedDataStatus() const
     }
 
     case kCGImageStatusComplete:
-        if (!isAllowedImageUTI(uti))
+        if (!isSupportImageSourceType(uti))
             return EncodedDataStatus::Error;
 
         return EncodedDataStatus::Complete;
index d342243..ec9c879 100644 (file)
 
 namespace WebCore {
 
-HashSet<String>& allowedImageUTIs()
+const HashSet<String>& supportedDefaultImageSourceTypes()
 {
     // CG at least supports the following standard image types:
-    static NeverDestroyed<HashSet<String>> s_allowedImageUTIs = std::initializer_list<String> {
+    static NeverDestroyed<HashSet<String>> supportedDefaultImageSourceTypes = std::initializer_list<String> {
         "com.compuserve.gif",
         "com.microsoft.bmp",
         "com.microsoft.cur",
@@ -54,25 +54,24 @@ HashSet<String>& allowedImageUTIs()
     };
 
 #ifndef NDEBUG
-    // But make sure that all of them are really supported.
-    static bool checked = false;
-    if (!checked) {
-        RetainPtr<CFArrayRef> systemImageUTIs = adoptCF(CGImageSourceCopyTypeIdentifiers());
-        CFIndex count = CFArrayGetCount(systemImageUTIs.get());
-        for (auto& imageUTI : s_allowedImageUTIs.get()) {
-            RetainPtr<CFStringRef> string = imageUTI.createCFString();
-            ASSERT(CFArrayContainsValue(systemImageUTIs.get(), CFRangeMake(0, count), string.get()));
+    // Make sure that CG supports them.
+    static std::once_flag onceFlag;
+    std::call_once(onceFlag, [] {
+        RetainPtr<CFArrayRef> systemImageSourceTypes = adoptCF(CGImageSourceCopyTypeIdentifiers());
+        CFIndex count = CFArrayGetCount(systemImageSourceTypes.get());
+        for (auto& imageSourceType : supportedDefaultImageSourceTypes.get()) {
+            RetainPtr<CFStringRef> string = imageSourceType.createCFString();
+            ASSERT(CFArrayContainsValue(systemImageSourceTypes.get(), CFRangeMake(0, count), string.get()));
         }
-        checked = true;
-    }
+    });
 #endif
 
-    return s_allowedImageUTIs.get();
+    return supportedDefaultImageSourceTypes;
 }
 
-bool isAllowedImageUTI(const String& imageUTI)
+bool isSupportImageSourceType(const String& imageSourceType)
 {
-    return !imageUTI.isEmpty() && allowedImageUTIs().contains(imageUTI);
+    return !imageSourceType.isEmpty() && supportedDefaultImageSourceTypes().contains(imageSourceType);
 }
 
 }
index 22f26ad..56f3f47 100644 (file)
@@ -30,7 +30,7 @@
 
 namespace WebCore {
 
-HashSet<String>& allowedImageUTIs();
-bool isAllowedImageUTI(const String&);
+const HashSet<String>& supportedDefaultImageSourceTypes();
+bool isSupportImageSourceType(const String&);
 
 }
index 3c367da..43d7dfd 100644 (file)
@@ -255,7 +255,7 @@ void Pasteboard::write(const PasteboardImage& pasteboardImage)
         return;
 
     // FIXME: Why can we assert this? It doesn't seem like it's guaranteed.
-    ASSERT(MIMETypeRegistry::isSupportedImageResourceMIMEType(pasteboardImage.resourceMIMEType));
+    ASSERT(MIMETypeRegistry::isSupportedImageMIMEType(pasteboardImage.resourceMIMEType));
 
     auto types = writableTypesForImage();
     if (pasteboardImage.dataInWebArchiveFormat)
index ce99cf3..f47bf1c 100644 (file)
@@ -1,3 +1,13 @@
+2018-10-24  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Cleanup: MIMETypeRegistry functions
+        https://bugs.webkit.org/show_bug.cgi?id=190838
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/Cocoa/WKWebViewContentProviderRegistry.mm:
+        (-[WKWebViewContentProviderRegistry initWithConfiguration:]):
+
 2018-10-24  Chris Dumez  <cdumez@apple.com>
 
         REGRESSION (r237257): [iOS] Crashes in com.apple.WebKit: WebKit::RemoteScrollingCoordinator::scheduleTreeStateCommit
index fe8efe4..26521bd 100644 (file)
@@ -5682,7 +5682,7 @@ static inline WebKit::FindOptions toFindOptions(_WKFindOptions wkFindOptions)
 
 - (BOOL)_isDisplayingPDF
 {
-    for (auto& mimeType : WebCore::MIMETypeRegistry::getPDFMIMETypes()) {
+    for (auto& mimeType : WebCore::MIMETypeRegistry::pdfMIMETypes()) {
         Class providerClass = [[_configuration _contentProviderRegistry] providerForMIMEType:mimeType];
         if ([_customContentView isKindOfClass:providerClass])
             return YES;
index 13b30bd..6d7f917 100644 (file)
         return nil;
 
 #if ENABLE(WKPDFVIEW)
-    for (auto& mimeType : WebCore::MIMETypeRegistry::getPDFMIMETypes())
+    for (auto& mimeType : WebCore::MIMETypeRegistry::pdfMIMETypes())
         [self registerProvider:[WKPDFView class] forMIMEType:mimeType];
 #elif ENABLE(WKLEGACYPDFVIEW)
-    for (auto& mimeType : WebCore::MIMETypeRegistry::getPDFMIMETypes())
+    for (auto& mimeType : WebCore::MIMETypeRegistry::pdfMIMETypes())
         [self registerProvider:[WKLegacyPDFView class] forMIMEType:mimeType];
 #endif
 
 #if USE(SYSTEM_PREVIEW)
     if (configuration._systemPreviewEnabled) {
-        for (auto& mimeType : WebCore::MIMETypeRegistry::getSystemPreviewMIMETypes())
+        for (auto& mimeType : WebCore::MIMETypeRegistry::systemPreviewMIMETypes())
             [self registerProvider:[WKSystemPreviewView class] forMIMEType:mimeType];
     }
 #endif
index 071a9bb..9f64a18 100644 (file)
@@ -1,3 +1,25 @@
+2018-10-24  Said Abou-Hallawa  <sabouhallawa@apple.com>
+
+        Cleanup: MIMETypeRegistry functions
+        https://bugs.webkit.org/show_bug.cgi?id=190838
+
+        Reviewed by Simon Fraser.
+
+        * Misc/WebNSPasteboardExtras.mm:
+        (-[NSPasteboard _web_writePromisedRTFDFromArchive:containsImage:]):
+        Replace isSupportedImageResourceMIMEType() by isSupportedImageMIMEType()
+        because they were identical.
+
+        * WebView/WebHTMLRepresentation.mm:
+        (+[WebHTMLRepresentation supportedMediaMIMETypes]):
+        (+[WebHTMLRepresentation supportedNonImageMIMETypes]):
+        (+[WebHTMLRepresentation supportedImageMIMETypes]):
+        (+[WebHTMLRepresentation unsupportedTextMIMETypes]):
+        * WebView/WebView.mm:
+        (+[WebView _unregisterViewClassAndRepresentationClassForMIMEType:]):
+        (+[WebView _registerViewClass:representationClass:forURLScheme:]):
+        (+[WebView registerViewClass:representationClass:forMIMEType:]):
+
 2018-10-23  David Kilzer  <ddkilzer@apple.com>
 
         Fix false positive leaks when using custom -init methods that don't start with -init
index f209a14..fd969a4 100644 (file)
@@ -214,13 +214,13 @@ static NSArray *_writableTypesForImageWithArchive (void)
     if (containsImage && [subresources count] > 0) {
         WebResource *subresource = [subresources objectAtIndex:0];
         NSString *subresourceMIMEType = [subresource MIMEType];
-        if (MIMETypeRegistry::isSupportedImageResourceMIMEType(subresourceMIMEType) || MIMETypeRegistry::isPDFOrPostScriptMIMEType(subresourceMIMEType))
+        if (MIMETypeRegistry::isSupportedImageMIMEType(subresourceMIMEType) || MIMETypeRegistry::isPDFOrPostScriptMIMEType(subresourceMIMEType))
             resource = subresource;
     }
     ASSERT(resource != nil);
     
-    ASSERT(!containsImage || MIMETypeRegistry::isSupportedImageResourceMIMEType([resource MIMEType]) || MIMETypeRegistry::isPDFOrPostScriptMIMEType([resource MIMEType]));
-    if (!containsImage || MIMETypeRegistry::isSupportedImageResourceMIMEType([resource MIMEType]) || MIMETypeRegistry::isPDFOrPostScriptMIMEType([resource MIMEType]))
+    ASSERT(!containsImage || MIMETypeRegistry::isSupportedImageMIMEType([resource MIMEType]) || MIMETypeRegistry::isPDFOrPostScriptMIMEType([resource MIMEType]));
+    if (!containsImage || MIMETypeRegistry::isSupportedImageMIMEType([resource MIMEType]) || MIMETypeRegistry::isPDFOrPostScriptMIMEType([resource MIMEType]))
         [self _web_writeFileWrapperAsRTFDAttachment:[resource _fileWrapperRepresentation]];
     
 }
index a45c775..cc4aa6c 100644 (file)
@@ -104,25 +104,25 @@ static RetainPtr<NSArray> newArrayWithStrings(const HashSet<String, ASCIICaseIns
 
 + (NSArray *)supportedMediaMIMETypes
 {
-    static NSArray *staticSupportedMediaMIMETypes = newArrayWithStrings(MIMETypeRegistry::getSupportedMediaMIMETypes()).leakRef();
+    static NSArray *staticSupportedMediaMIMETypes = newArrayWithStrings(MIMETypeRegistry::supportedMediaMIMETypes()).leakRef();
     return staticSupportedMediaMIMETypes;
 }
 
 + (NSArray *)supportedNonImageMIMETypes
 {
-    static NSArray *staticSupportedNonImageMIMETypes = newArrayWithStrings(MIMETypeRegistry::getSupportedNonImageMIMETypes()).leakRef();
+    static NSArray *staticSupportedNonImageMIMETypes = newArrayWithStrings(MIMETypeRegistry::supportedNonImageMIMETypes()).leakRef();
     return staticSupportedNonImageMIMETypes;
 }
 
 + (NSArray *)supportedImageMIMETypes
 {
-    static NSArray *staticSupportedImageMIMETypes = newArrayWithStrings(MIMETypeRegistry::getSupportedImageMIMETypes()).leakRef();
+    static NSArray *staticSupportedImageMIMETypes = newArrayWithStrings(MIMETypeRegistry::supportedImageMIMETypes()).leakRef();
     return staticSupportedImageMIMETypes;
 }
 
 + (NSArray *)unsupportedTextMIMETypes
 {
-    static NSArray *staticUnsupportedTextMIMETypes = newArrayWithStrings(MIMETypeRegistry::getUnsupportedTextMIMETypes()).leakRef();
+    static NSArray *staticUnsupportedTextMIMETypes = newArrayWithStrings(MIMETypeRegistry::unsupportedTextMIMETypes()).leakRef();
     return staticUnsupportedTextMIMETypes;
 }
 
index af8f093..4c59c7b 100644 (file)
@@ -3420,7 +3420,7 @@ IGNORE_WARNINGS_END
     // FIXME: We also need to maintain MIMEType registrations (which can be dynamically changed)
     // in the WebCore MIMEType registry.  For now we're doing this in a safe, limited manner
     // to fix <rdar://problem/5372989> - a future revamping of the entire system is neccesary for future robustness
-    MIMETypeRegistry::getSupportedNonImageMIMETypes().remove(MIMEType);
+    MIMETypeRegistry::supportedNonImageMIMETypes().remove(MIMEType);
 }
 
 + (void)_registerViewClass:(Class)viewClass representationClass:(Class)representationClass forURLScheme:(NSString *)URLScheme
@@ -3432,7 +3432,7 @@ IGNORE_WARNINGS_END
     // in the WebCore MIMEType registry.  For now we're doing this in a safe, limited manner
     // to fix <rdar://problem/5372989> - a future revamping of the entire system is neccesary for future robustness
     if ([viewClass class] == [WebHTMLView class])
-        MIMETypeRegistry::getSupportedNonImageMIMETypes().add(MIMEType);
+        MIMETypeRegistry::supportedNonImageMIMETypes().add(MIMEType);
     
     // This is used to make _representationExistsForURLScheme faster.
     // Without this set, we'd have to create the MIME type each time.
@@ -6997,7 +6997,7 @@ static WebFrame *incrementFrame(WebFrame *frame, WebFindOptions options = 0)
     // in the WebCore MIMEType registry.  For now we're doing this in a safe, limited manner
     // to fix <rdar://problem/5372989> - a future revamping of the entire system is neccesary for future robustness
     if ([viewClass class] == [WebHTMLView class])
-        MIMETypeRegistry::getSupportedNonImageMIMETypes().add(MIMEType);
+        MIMETypeRegistry::supportedNonImageMIMETypes().add(MIMEType);
 }
 
 - (void)setGroupName:(NSString *)groupName