Title: [124704] trunk/Source/WebCore
Revision
124704
Author
[email protected]
Date
2012-08-04 15:49:18 -0700 (Sat, 04 Aug 2012)

Log Message

Refactor SubframeLoader::requestPlugin/loadPlugin for clarity.
https://bugs.webkit.org/show_bug.cgi?id=93138

Patch by Mike West <[email protected]> on 2012-08-04
Reviewed by Adam Barth.

SubframeLoader::requestPlugin and SubframeLoader::loadPlugin both do a
variety of checks to determine whether or not a specific resource ought
to instantiate a plugin in a specific context. r124636[1] moved one of
those checks, but there doesn't seem to be a clear way to determine
which checks should be performed where.

This patch refactors the checks out of those two methods for clarity,
moving them all into a new method: SubframeLoader::pluginIsLoadable.
That method requires the resource URL and MIME type, as well as the
`object` or `embed` element that owns this bit of rendering. The URL
and type are used directly to determine availability, while the element
is currently used only to create a renderer on which
setPluginUnavailabilityReason can be called if the plugin is blocked by
Content Security Policy.

This patch introduces no new tests, as it shouldn't change the code's
behavior: it should be a straightforward refactoring without web-visible
side-effects.

[1]: http://trac.webkit.org/changeset/124636

* loader/SubframeLoader.cpp:
(WebCore::SubframeLoader::pluginIsLoadable):
    A new method that extracts the various 'Should we allow this plugin
    in this context?' checks from requestPlugin and loadPlugin into ine
    location, rather than spreading them across both.
(WebCore):
(WebCore::SubframeLoader::requestPlugin):
(WebCore::SubframeLoader::loadPlugin):
* loader/SubframeLoader.h:
(SubframeLoader):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (124703 => 124704)


--- trunk/Source/WebCore/ChangeLog	2012-08-04 22:08:58 UTC (rev 124703)
+++ trunk/Source/WebCore/ChangeLog	2012-08-04 22:49:18 UTC (rev 124704)
@@ -1,3 +1,42 @@
+2012-08-04  Mike West  <[email protected]>
+
+        Refactor SubframeLoader::requestPlugin/loadPlugin for clarity.
+        https://bugs.webkit.org/show_bug.cgi?id=93138
+
+        Reviewed by Adam Barth.
+
+        SubframeLoader::requestPlugin and SubframeLoader::loadPlugin both do a
+        variety of checks to determine whether or not a specific resource ought
+        to instantiate a plugin in a specific context. r124636[1] moved one of
+        those checks, but there doesn't seem to be a clear way to determine
+        which checks should be performed where.
+
+        This patch refactors the checks out of those two methods for clarity,
+        moving them all into a new method: SubframeLoader::pluginIsLoadable.
+        That method requires the resource URL and MIME type, as well as the
+        `object` or `embed` element that owns this bit of rendering. The URL
+        and type are used directly to determine availability, while the element
+        is currently used only to create a renderer on which
+        setPluginUnavailabilityReason can be called if the plugin is blocked by
+        Content Security Policy.
+
+        This patch introduces no new tests, as it shouldn't change the code's
+        behavior: it should be a straightforward refactoring without web-visible
+        side-effects.
+
+        [1]: http://trac.webkit.org/changeset/124636
+
+        * loader/SubframeLoader.cpp:
+        (WebCore::SubframeLoader::pluginIsLoadable):
+            A new method that extracts the various 'Should we allow this plugin
+            in this context?' checks from requestPlugin and loadPlugin into ine
+            location, rather than spreading them across both.
+        (WebCore):
+        (WebCore::SubframeLoader::requestPlugin):
+        (WebCore::SubframeLoader::loadPlugin):
+        * loader/SubframeLoader.h:
+        (SubframeLoader):
+
 2012-08-04  John J. Barton  <[email protected]>
 
         Web Inspector: filteredItemSelectionDialog.css has wrong selector for highlights

Modified: trunk/Source/WebCore/loader/SubframeLoader.cpp (124703 => 124704)


--- trunk/Source/WebCore/loader/SubframeLoader.cpp	2012-08-04 22:08:58 UTC (rev 124703)
+++ trunk/Source/WebCore/loader/SubframeLoader.cpp	2012-08-04 22:49:18 UTC (rev 124704)
@@ -104,30 +104,53 @@
     return shouldUsePlugin(completedURL, mimeType, shouldPreferPlugInsForImages, false, useFallback);
 }
 
-bool SubframeLoader::requestPlugin(HTMLPlugInImageElement* ownerElement, const KURL& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback)
+bool SubframeLoader::pluginIsLoadable(HTMLPlugInImageElement* pluginElement, const KURL& url, const String& mimeType)
 {
     Settings* settings = m_frame->settings();
     if (!settings)
         return false;
 
-    // Application plug-ins are plug-ins implemented by the user agent, for example Qt plug-ins,
-    // as opposed to third-party code such as Flash. The user agent decides whether or not they are
-    // permitted, rather than WebKit.
-    if ((!allowPlugins(AboutToInstantiatePlugin) && !MIMETypeRegistry::isApplicationPluginMIMEType(mimeType)))
-        return false;
-
     if (MIMETypeRegistry::isJavaAppletMIMEType(mimeType)) {
         if (!settings->isJavaEnabled())
             return false;
-        if (m_frame->document() && m_frame->document()->securityOrigin()->isLocal() && !settings->isJavaEnabledForLocalFiles())
+        if (document() && document()->securityOrigin()->isLocal() && !settings->isJavaEnabledForLocalFiles())
             return false;
     }
 
-    if (m_frame->document()) {
-        if (m_frame->document()->isSandboxed(SandboxPlugins))
+    if (document()) {
+        if (document()->isSandboxed(SandboxPlugins))
             return false;
+
+        if (!document()->securityOrigin()->canDisplay(url)) {
+            FrameLoader::reportLocalLoadFailed(m_frame, url.string());
+            return false;
+        }
+
+        if (!document()->contentSecurityPolicy()->allowObjectFromSource(url)) {
+            RenderEmbeddedObject* renderer = pluginElement->renderEmbeddedObject();
+            renderer->setPluginUnavailabilityReason(RenderEmbeddedObject::PluginBlockedByContentSecurityPolicy);
+            return false;
+        }
+
+        if (m_frame->loader() && !m_frame->loader()->checkIfRunInsecureContent(document()->securityOrigin(), url))
+            return false;
     }
 
+    return true;
+}
+
+bool SubframeLoader::requestPlugin(HTMLPlugInImageElement* ownerElement, const KURL& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback)
+{
+
+    // Application plug-ins are plug-ins implemented by the user agent, for example Qt plug-ins,
+    // as opposed to third-party code such as Flash. The user agent decides whether or not they are
+    // permitted, rather than WebKit.
+    if ((!allowPlugins(AboutToInstantiatePlugin) && !MIMETypeRegistry::isApplicationPluginMIMEType(mimeType)))
+        return false;
+
+    if (!pluginIsLoadable(ownerElement, url, mimeType))
+        return false;
+
     ASSERT(ownerElement->hasTagName(objectTag) || ownerElement->hasTagName(embedTag));
     return loadPlugin(ownerElement, url, mimeType, paramNames, paramValues, useFallback);
 }
@@ -414,23 +437,9 @@
     if (!renderer || useFallback)
         return false;
 
-    if (!document()->securityOrigin()->canDisplay(url)) {
-        FrameLoader::reportLocalLoadFailed(m_frame, url.string());
-        return false;
-    }
-
-    if (!document()->contentSecurityPolicy()->allowObjectFromSource(url)) {
-        renderer->setPluginUnavailabilityReason(RenderEmbeddedObject::PluginBlockedByContentSecurityPolicy);
-        return false;
-    }
-
-    FrameLoader* frameLoader = m_frame->loader();
-    if (!frameLoader->checkIfRunInsecureContent(document()->securityOrigin(), url))
-        return false;
-
     IntSize contentSize = roundedIntSize(LayoutSize(renderer->contentWidth(), renderer->contentHeight()));
     bool loadManually = document()->isPluginDocument() && !m_containsPlugins && toPluginDocument(document())->shouldLoadPluginManually();
-    RefPtr<Widget> widget = frameLoader->client()->createPlugin(contentSize,
+    RefPtr<Widget> widget = m_frame->loader()->client()->createPlugin(contentSize,
         pluginElement, url, paramNames, paramValues, mimeType, loadManually);
 
     if (!widget) {

Modified: trunk/Source/WebCore/loader/SubframeLoader.h (124703 => 124704)


--- trunk/Source/WebCore/loader/SubframeLoader.h	2012-08-04 22:08:58 UTC (rev 124703)
+++ trunk/Source/WebCore/loader/SubframeLoader.h	2012-08-04 22:49:18 UTC (rev 124704)
@@ -88,6 +88,7 @@
         const Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallback);
 
     bool shouldUsePlugin(const KURL&, const String& mimeType, bool shouldPreferPlugInsForImages, bool hasFallback, bool& useFallback);
+    bool pluginIsLoadable(HTMLPlugInImageElement*, const KURL&, const String& mimeType);
 
     Document* document() const;
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to