Changeset 230117 in webkit


Ignore:
Timestamp:
Mar 30, 2018 2:01:35 PM (6 years ago)
Author:
dbates@webkit.org
Message:
ASSERTION FAILED: ASSERT(!containsImage
MIMETypeRegistry::isSupportedImageResourceMIMEType([resource MIMEType])) in -[NSPasteboard(WebExtras) _web_writePromisedRTFDFromArchive:containsImage:]

https://bugs.webkit.org/show_bug.cgi?id=184161

Reviewed by Per Arne Vollan.

.:

  • ManualTests/DragInlinePDFImageDocument.html: Added.
  • ManualTests/resources/simple.pdf: Added.

Source/WebCore:

Fixes an assertion failure when quiting an app that uses a Legacy WebKit web view
after dragging-and-dropping a PDF embedded using an HTML image element into the
same web view.

When performing a drag-and-drop of a PDF document image (WebCore::PDFDocumentImage) we create a WebArchive
from the main frame's WebHTMLView and promise AppKit that will provide a Rich Text Format (RTF) document
from this archive if needed. For some reason, on app termination AppKit requests that the WebHTMLView
fullfill its RTF document promise for the WebArchive created at the start of the drag operation. WebKit
expects that the created WebArchive is either for an inline image (e.g. <img>) or an image document that
has a supported image resource MIME type (by querying MIMETypeRegistry::isSupportedImageResourceMIMEType())
and checks for these cases in this order. PDF/PostScript are not listed in the set of supported image
resource MIME types. So, the first check fails and WebKit assumes that the WebArchive was created from
an image document of a supported image resource MIME type. However, the WebArchive was created from a
WebHTMLView and has MIME type text/html. Therefore the assertion fails. We need to add PDF and PostScript
to the set of supported image resource MIME types so that WebKit does not fall back to the WebHTMLView
code path. Historically, PDF and PostScript were in the set supported image resource MIME types. Over time
the set of MIME types for image resouces (images loaded as a document) became identical to the set of MIME
types for images loaded inline (e.g. <img>) and this set omitted the MIME types for PDF and PostScript.

Additionally it is sufficient to implement MIMETypeRegistry::isSupportedImageResourceMIMEType() in terms
of MIMETypeRegistry::isSupportedImageMIMEType() and MIMETypeRegistry::isPDFOrPostScriptMIMEType() instead
of allocating a dedicated HashSet for the supported image resource MIME types (as we currently do).

  • dom/DOMImplementation.cpp:

(WebCore::DOMImplementation::createDocument): Assert that PDF is a supported image MIME type before
instantiating an ImageDocument.

  • platform/MIMETypeRegistry.cpp:

(WebCore::initializeSupportedImageMIMETypes): Remove unnecessary allocation of a HashSet for the support
image resource MIME types.
(WebCore::MIMETypeRegistry::isSupportedImageResourceMIMEType): Write in terms of MIMETypeRegistry::isSupportedImageMIMEType()
and MIMETypeRegistry::isPDFOrPostScriptMIMEType().
(WebCore::MIMETypeRegistry::getSupportedImageResourceMIMETypes): Deleted.

  • platform/MIMETypeRegistry.h:
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r230048 r230117  
     12018-03-30  Daniel Bates  <dabates@apple.com>
     2
     3        ASSERTION FAILED: ASSERT(!containsImage || MIMETypeRegistry::isSupportedImageResourceMIMEType([resource MIMEType])) in -[NSPasteboard(WebExtras) _web_writePromisedRTFDFromArchive:containsImage:]
     4        https://bugs.webkit.org/show_bug.cgi?id=184161
     5
     6        Reviewed by Per Arne Vollan.
     7
     8        * ManualTests/DragInlinePDFImageDocument.html: Added.
     9        * ManualTests/resources/simple.pdf: Added.
     10
    1112018-03-28  Tim Horton  <timothy_horton@apple.com>
    212
  • trunk/Source/WebCore/ChangeLog

    r230112 r230117  
     12018-03-30  Daniel Bates  <dabates@apple.com>
     2
     3        ASSERTION FAILED: ASSERT(!containsImage || MIMETypeRegistry::isSupportedImageResourceMIMEType([resource MIMEType])) in -[NSPasteboard(WebExtras) _web_writePromisedRTFDFromArchive:containsImage:]
     4        https://bugs.webkit.org/show_bug.cgi?id=184161
     5
     6        Reviewed by Per Arne Vollan.
     7
     8        Fixes an assertion failure when quiting an app that uses a Legacy WebKit web view
     9        after dragging-and-dropping a PDF embedded using an HTML image element into the
     10        same web view.
     11
     12        When performing a drag-and-drop of a PDF document image (WebCore::PDFDocumentImage) we create a WebArchive
     13        from the main frame's WebHTMLView and promise AppKit that will provide a Rich Text Format (RTF) document
     14        from this archive if needed. For some reason, on app termination AppKit requests that the WebHTMLView
     15        fullfill its RTF document promise for the WebArchive created at the start of the drag operation. WebKit
     16        expects that the created WebArchive is either for an inline image (e.g. <img>) or an image document that
     17        has a supported image resource MIME type (by querying MIMETypeRegistry::isSupportedImageResourceMIMEType())
     18        and checks for these cases in this order. PDF/PostScript are not listed in the set of supported image
     19        resource MIME types. So, the first check fails and WebKit assumes that the WebArchive was created from
     20        an image document of a supported image resource MIME type. However, the WebArchive was created from a
     21        WebHTMLView and has MIME type text/html. Therefore the assertion fails. We need to add PDF and PostScript
     22        to the set of supported image resource MIME types so that WebKit does not fall back to the WebHTMLView
     23        code path. Historically, PDF and PostScript were in the set supported image resource MIME types. Over time
     24        the set of MIME types for image resouces (images loaded as a document) became identical to the set of MIME
     25        types for images loaded inline (e.g. <img>) and this set omitted the MIME types for PDF and PostScript.
     26
     27        Additionally it is sufficient to implement MIMETypeRegistry::isSupportedImageResourceMIMEType() in terms
     28        of MIMETypeRegistry::isSupportedImageMIMEType() and MIMETypeRegistry::isPDFOrPostScriptMIMEType() instead
     29        of allocating a dedicated HashSet for the supported image resource MIME types (as we currently do).
     30
     31        * dom/DOMImplementation.cpp:
     32        (WebCore::DOMImplementation::createDocument): Assert that PDF is a supported image MIME type before
     33        instantiating an ImageDocument.
     34        * platform/MIMETypeRegistry.cpp:
     35        (WebCore::initializeSupportedImageMIMETypes): Remove unnecessary allocation of a HashSet for the support
     36        image resource MIME types.
     37        (WebCore::MIMETypeRegistry::isSupportedImageResourceMIMEType): Write in terms of MIMETypeRegistry::isSupportedImageMIMEType()
     38        and MIMETypeRegistry::isPDFOrPostScriptMIMEType().
     39        (WebCore::MIMETypeRegistry::getSupportedImageResourceMIMETypes): Deleted.
     40        * platform/MIMETypeRegistry.h:
     41
    1422018-03-29  Antoine Quint  <graouts@apple.com>
    243
  • trunk/Source/WebCore/dom/DOMImplementation.cpp

    r227439 r230117  
    151151
    152152    // If we want to useImageDocumentForSubframePDF, we'll let that override plugin support.
    153     if (frame && !frame->isMainFrame() && MIMETypeRegistry::isPDFMIMEType(type) && frame->settings().useImageDocumentForSubframePDF())
     153    if (frame && !frame->isMainFrame() && MIMETypeRegistry::isPDFMIMEType(type) && frame->settings().useImageDocumentForSubframePDF()) {
     154        ASSERT(Image::supportsType(type));
    154155        return ImageDocument::create(*frame, url);
     156    }
    155157
    156158    PluginData* pluginData = nullptr;
  • trunk/Source/WebCore/platform/MIMETypeRegistry.cpp

    r230107 r230117  
    5656namespace WebCore {
    5757
    58 static HashSet<String, ASCIICaseInsensitiveHash>* supportedImageResourceMIMETypes;
    5958static HashSet<String, ASCIICaseInsensitiveHash>* supportedImageMIMETypes;
    6059static HashSet<String, ASCIICaseInsensitiveHash>* supportedImageMIMETypesForEncoding;
     
    6766static void initializeSupportedImageMIMETypes()
    6867{
    69     supportedImageResourceMIMETypes = new HashSet<String, ASCIICaseInsensitiveHash>;
    7068    supportedImageMIMETypes = new HashSet<String, ASCIICaseInsensitiveHash>;
    7169
     
    7371    // This represents the subset of allowed image UTIs for which CoreServices has a corresponding MIME type. Keep this in sync with allowedImageUTIs().
    7472    static const char* const allowedImageMIMETypes[] = { "image/tiff", "image/gif", "image/jpeg", "image/vnd.microsoft.icon", "image/jp2", "image/png", "image/bmp" };
    75     for (auto& mimeType : allowedImageMIMETypes) {
     73    for (auto& mimeType : allowedImageMIMETypes)
    7674        supportedImageMIMETypes->add(ASCIILiteral { mimeType });
    77         supportedImageResourceMIMETypes->add(ASCIILiteral { mimeType });
    78     }
    7975
    8076#ifndef NDEBUG
    8177    for (auto& uti : allowedImageUTIs()) {
    8278        auto mimeType = MIMETypeForImageSourceType(uti);
    83         if (!mimeType.isEmpty()) {
     79        if (!mimeType.isEmpty())
    8480            ASSERT(supportedImageMIMETypes->contains(mimeType));
    85             ASSERT(supportedImageResourceMIMETypes->contains(mimeType));
    86         }
    8781    }
    8882
     
    9589    // Favicons don't have a MIME type in the registry either.
    9690    supportedImageMIMETypes->add("image/x-icon");
    97     supportedImageResourceMIMETypes->add("image/x-icon");
    9891
    9992    //  We only get one MIME type per UTI, hence our need to add these manually
    10093    supportedImageMIMETypes->add("image/pjpeg");
    101     supportedImageResourceMIMETypes->add("image/pjpeg");
    10294
    10395#if PLATFORM(IOS)
     
    123115        "application/bmp", "application/x-bmp", "application/x-win-bitmap",
    124116    };
    125     for (auto& type : malformedMIMETypes) {
     117    for (auto& type : malformedMIMETypes)
    126118        supportedImageMIMETypes->add(type);
    127         supportedImageResourceMIMETypes->add(type);
    128     }
    129119#endif
    130120
     
    141131        "image/x-xbitmap"  // xbm
    142132    };
    143     for (auto& type : types) {
     133    for (auto& type : types)
    144134        supportedImageMIMETypes->add(type);
    145         supportedImageResourceMIMETypes->add(type);
    146     }
    147135
    148136#if USE(WEBP)
    149137    supportedImageMIMETypes->add("image/webp");
    150     supportedImageResourceMIMETypes->add("image/webp");
    151138#endif
    152139
     
    464451bool MIMETypeRegistry::isSupportedImageResourceMIMEType(const String& mimeType)
    465452{
    466     if (mimeType.isEmpty())
    467         return false;
    468     if (!supportedImageResourceMIMETypes)
    469         initializeSupportedImageMIMETypes();
    470     return supportedImageResourceMIMETypes->contains(getNormalizedMIMEType(mimeType));
     453    return isSupportedImageMIMEType(mimeType) || isPDFOrPostScriptMIMEType(mimeType);
    471454}
    472455
     
    657640        initializeSupportedImageMIMETypes();
    658641    return *supportedImageMIMETypes;
    659 }
    660 
    661 const HashSet<String, ASCIICaseInsensitiveHash>& MIMETypeRegistry::getSupportedImageResourceMIMETypes()
    662 {
    663     if (!supportedImageResourceMIMETypes)
    664         initializeSupportedImageMIMETypes();
    665     return *supportedImageResourceMIMETypes;
    666642}
    667643
  • trunk/Source/WebCore/platform/MIMETypeRegistry.h

    r230107 r230117  
    110110
    111111    WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& getSupportedImageMIMETypes();
    112     const static HashSet<String, ASCIICaseInsensitiveHash>& getSupportedImageResourceMIMETypes();
    113112    WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& getSupportedMediaMIMETypes();
    114113    WEBCORE_EXPORT const static HashSet<String, ASCIICaseInsensitiveHash>& getPDFMIMETypes();
Note: See TracChangeset for help on using the changeset viewer.