Changeset 268162 in webkit


Ignore:
Timestamp:
Oct 7, 2020 5:01:27 PM (4 years ago)
Author:
timothy_horton@apple.com
Message:

REGRESSION: Safari unable to load PDF in <embed> (docs.legalconnect.com)
https://bugs.webkit.org/show_bug.cgi?id=217451
<rdar://problem/69767043>

Reviewed by Alex Christensen.

Source/WebCore:

Test: fast/replaced/pdf-as-embed-with-no-mime-type-is-not-blank.html

If plugins are enabled, we'll always let the request go through, and WebKit will
guess that files with PDFPlugin-handled extensions should instantiate PDFPlugin,
even if no other plugins are available.

However, if plugins are disabled, requestPlugin() will early return if the explicitly
specified MIME type is not handled by an application plugin (even though the downstream
WebKit code would have happily instantiated an application plugin for us).

Application plugins shouldn't depend on the plugin enablement setting.
To fix this, have SubframeLoader guess the MIME type if not explicitly specified
(matching WebKit's behavior), and allow the request if it matches an application plugin.

  • loader/SubframeLoader.cpp:

(WebCore::findPluginMIMETypeFromURL):
Improve this previously logging-only function to use the lastPathComponent
of the URL instead of randomly looking at the end of the URL, to ignore
query strings and fragments when looking for the file extension.

(WebCore::FrameLoader::SubframeLoader::requestPlugin):
Make use of findPluginMIMETypeFromURL to guess the MIME type if it's not
explicitly specified. If the guessed MIME type is one that is handled
by application plugins, allow the request to go out to WebKit (which
may then instantiate a PDFPlugin, for example).

(WebCore::logPluginRequest):
(WebCore::FrameLoader::SubframeLoader::requestObject):
(WebCore::FrameLoader::SubframeLoader::createJavaAppletWidget):
Pass the URL instead of stringifying it, so we can lastPathComponent as above.

LayoutTests:

  • fast/replaced/pdf-as-embed-with-no-mime-type-is-not-blank-expected-mismatch.html: Added.
  • fast/replaced/pdf-as-embed-with-no-mime-type-is-not-blank.html: Added.

Add a test ensuring that <embed> with no specified MIME type still renders the PDF.

Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r268161 r268162  
     12020-10-07  Tim Horton  <timothy_horton@apple.com>
     2
     3        REGRESSION: Safari unable to load PDF in <embed> (docs.legalconnect.com)
     4        https://bugs.webkit.org/show_bug.cgi?id=217451
     5        <rdar://problem/69767043>
     6
     7        Reviewed by Alex Christensen.
     8
     9        * fast/replaced/pdf-as-embed-with-no-mime-type-is-not-blank-expected-mismatch.html: Added.
     10        * fast/replaced/pdf-as-embed-with-no-mime-type-is-not-blank.html: Added.
     11        Add a test ensuring that <embed> with no specified MIME type still renders the PDF.
     12
    1132020-10-07  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/platform/win/TestExpectations

    r267884 r268162  
    42794279
    42804280webkit.org/b/194711 fast/replaced/encrypted-pdf-as-object-and-embed.html [ Failure ]
     4281webkit.org/b/194711 fast/replaced/pdf-as-embed-with-no-mime-type-is-not-blank.html [ Failure ]
    42814282
    42824283webkit.org/b/195461 http/tests/referrer-policy-iframe/no-referrer/cross-origin-http-http.html [ Failure ]
  • trunk/Source/WebCore/ChangeLog

    r268161 r268162  
     12020-10-07  Tim Horton  <timothy_horton@apple.com>
     2
     3        REGRESSION: Safari unable to load PDF in <embed> (docs.legalconnect.com)
     4        https://bugs.webkit.org/show_bug.cgi?id=217451
     5        <rdar://problem/69767043>
     6
     7        Reviewed by Alex Christensen.
     8
     9        Test: fast/replaced/pdf-as-embed-with-no-mime-type-is-not-blank.html
     10
     11        If plugins are enabled, we'll always let the request go through, and WebKit will
     12        guess that files with PDFPlugin-handled extensions should instantiate PDFPlugin,
     13        even if no other plugins are available.
     14
     15        However, if plugins are disabled, requestPlugin() will early return if the explicitly
     16        specified MIME type is not handled by an application plugin (even though the downstream
     17        WebKit code would have happily instantiated an application plugin for us).
     18
     19        Application plugins shouldn't depend on the plugin enablement setting.
     20        To fix this, have SubframeLoader guess the MIME type if not explicitly specified
     21        (matching WebKit's behavior), and allow the request if it matches an application plugin.
     22
     23        * loader/SubframeLoader.cpp:
     24        (WebCore::findPluginMIMETypeFromURL):
     25        Improve this previously logging-only function to use the lastPathComponent
     26        of the URL instead of randomly looking at the end of the URL, to ignore
     27        query strings and fragments when looking for the file extension.
     28
     29        (WebCore::FrameLoader::SubframeLoader::requestPlugin):
     30        Make use of findPluginMIMETypeFromURL to guess the MIME type if it's not
     31        explicitly specified. If the guessed MIME type is one that is handled
     32        by application plugins, allow the request to go out to WebKit (which
     33        may then instantiate a PDFPlugin, for example).
     34
     35        (WebCore::logPluginRequest):
     36        (WebCore::FrameLoader::SubframeLoader::requestObject):
     37        (WebCore::FrameLoader::SubframeLoader::createJavaAppletWidget):
     38        Pass the URL instead of stringifying it, so we can lastPathComponent as above.
     39
    1402020-10-07  Chris Dumez  <cdumez@apple.com>
    241
  • trunk/Source/WebCore/loader/SubframeLoader.cpp

    r264878 r268162  
    149149}
    150150
    151 bool FrameLoader::SubframeLoader::requestPlugin(HTMLPlugInImageElement& ownerElement, const URL& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback)
    152 {
    153     // Application plug-ins are plug-ins implemented by the user agent, for example Qt plug-ins,
    154     // as opposed to third-party code such as Flash. The user agent decides whether or not they are
    155     // permitted, rather than WebKit.
    156     if (!(m_frame.settings().arePluginsEnabled() || MIMETypeRegistry::isApplicationPluginMIMEType(mimeType)))
    157         return false;
    158 
    159     if (!pluginIsLoadable(url, mimeType))
    160         return false;
    161 
    162     ASSERT(ownerElement.hasTagName(objectTag) || ownerElement.hasTagName(embedTag));
    163     return loadPlugin(ownerElement, url, mimeType, paramNames, paramValues, useFallback);
    164 }
    165 
    166 static String findPluginMIMETypeFromURL(Page& page, const StringView& url)
    167 {
    168     if (!url)
    169         return { };
    170 
    171     size_t dotIndex = url.reverseFind('.');
     151static String findPluginMIMETypeFromURL(Page& page, const URL& url)
     152{
     153    auto lastPathComponent = url.lastPathComponent();
     154    size_t dotIndex = lastPathComponent.reverseFind('.');
    172155    if (dotIndex == notFound)
    173156        return { };
    174157
    175     auto extensionFromURL = url.substring(dotIndex + 1);
     158    auto extensionFromURL = lastPathComponent.substring(dotIndex + 1);
    176159
    177160    for (auto& type : page.pluginData().webVisibleMimeTypes()) {
     
    185168}
    186169
    187 static void logPluginRequest(Page* page, const String& mimeType, const String& url, bool success)
     170bool FrameLoader::SubframeLoader::requestPlugin(HTMLPlugInImageElement& ownerElement, const URL& url, const String& explicitMIMEType, const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback)
     171{
     172    String mimeType = explicitMIMEType;
     173    if (mimeType.isEmpty()) {
     174        if (auto page = ownerElement.document().page())
     175            mimeType = findPluginMIMETypeFromURL(*page, url);
     176    }
     177
     178    // Application plug-ins are plug-ins implemented by the user agent, for example Qt plug-ins,
     179    // as opposed to third-party code such as Flash. The user agent decides whether or not they are
     180    // permitted, rather than WebKit.
     181    if (!(m_frame.settings().arePluginsEnabled() || MIMETypeRegistry::isApplicationPluginMIMEType(mimeType)))
     182        return false;
     183
     184    if (!pluginIsLoadable(url, explicitMIMEType))
     185        return false;
     186
     187    ASSERT(ownerElement.hasTagName(objectTag) || ownerElement.hasTagName(embedTag));
     188    return loadPlugin(ownerElement, url, explicitMIMEType, paramNames, paramValues, useFallback);
     189}
     190
     191static void logPluginRequest(Page* page, const String& mimeType, const URL& url, bool success)
    188192{
    189193    if (!page)
     
    231235    if (shouldUsePlugin(completedURL, mimeType, hasFallbackContent, useFallback)) {
    232236        bool success = requestPlugin(ownerElement, completedURL, mimeType, paramNames, paramValues, useFallback);
    233         logPluginRequest(document.page(), mimeType, completedURL.string(), success);
     237        logPluginRequest(document.page(), mimeType, completedURL, success);
    234238        return success;
    235239    }
     
    277281        widget = m_frame.loader().client().createJavaAppletWidget(size, element, baseURL, paramNames, paramValues);
    278282
    279     logPluginRequest(m_frame.page(), element.serviceType(), String(), widget);
     283    logPluginRequest(m_frame.page(), element.serviceType(), { }, widget);
    280284
    281285    if (!widget) {
Note: See TracChangeset for help on using the changeset viewer.