Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Commit c5b15e9

Browse files
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. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@268162 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 629d0f5 commit c5b15e9

File tree

6 files changed

+82
-24
lines changed

6 files changed

+82
-24
lines changed

LayoutTests/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2020-10-07 Tim Horton <[email protected]>
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+
113
2020-10-07 Chris Dumez <[email protected]>
214

315
Constructing a AudioWorkletNode should construct an AudioWorkletProcessor on the Worklet thread

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

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<script>testRunner.setPluginsEnabled(false);</script>
2+
<embed src="resources/image.pdf"></embed>

LayoutTests/platform/win/TestExpectations

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4278,6 +4278,7 @@ storage/indexeddb/request-leak-private.html [ Skip ]
42784278
storage/indexeddb/request-leak.html [ Skip ]
42794279

42804280
webkit.org/b/194711 fast/replaced/encrypted-pdf-as-object-and-embed.html [ Failure ]
4281+
webkit.org/b/194711 fast/replaced/pdf-as-embed-with-no-mime-type-is-not-blank.html [ Failure ]
42814282

42824283
webkit.org/b/195461 http/tests/referrer-policy-iframe/no-referrer/cross-origin-http-http.html [ Failure ]
42834284
webkit.org/b/195461 http/tests/referrer-policy-iframe/no-referrer/same-origin.html [ Failure ]

Source/WebCore/ChangeLog

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
2020-10-07 Tim Horton <[email protected]>
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+
140
2020-10-07 Chris Dumez <[email protected]>
241

342
Constructing a AudioWorkletNode should construct an AudioWorkletProcessor on the Worklet thread

Source/WebCore/loader/SubframeLoader.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,31 +148,14 @@ bool FrameLoader::SubframeLoader::pluginIsLoadable(const URL& url, const String&
148148
return true;
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)
151+
static String findPluginMIMETypeFromURL(Page& page, const URL& url)
152152
{
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('.');
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()) {
178161
for (auto& extension : type.extensions) {
@@ -184,7 +167,28 @@ static String findPluginMIMETypeFromURL(Page& page, const StringView& url)
184167
return { };
185168
}
186169

187-
static void logPluginRequest(Page* page, const String& mimeType, const String& url, bool success)
170+
bool 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+
191+
static void logPluginRequest(Page* page, const String& mimeType, const URL& url, bool success)
188192
{
189193
if (!page)
190194
return;
@@ -230,7 +234,7 @@ bool FrameLoader::SubframeLoader::requestObject(HTMLPlugInImageElement& ownerEle
230234
bool useFallback;
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
}
236240

@@ -276,7 +280,7 @@ RefPtr<Widget> FrameLoader::SubframeLoader::createJavaAppletWidget(const IntSize
276280
if (m_frame.settings().arePluginsEnabled())
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) {
282286
RenderEmbeddedObject* renderer = element.renderEmbeddedObject();

0 commit comments

Comments
 (0)