Make PluginData cache its web visible plugins
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Apr 2018 17:45:24 +0000 (17:45 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Apr 2018 17:45:24 +0000 (17:45 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184421

Reviewed by Chris Dumez.

Source/WebCore:

Buffer visible plugins until the page URL changes.
For that purpose, we now cache the visible plugins and the URL it was computed from in PluginData.

Update plugin info provider API to pass the URL used to check for plugin visibility.

No observable change of behavior.

* loader/EmptyClients.cpp:
* plugins/PluginData.cpp:
(WebCore::PluginData::webVisiblePlugins const):
(WebCore::PluginData::publiclyVisiblePlugins const):
(WebCore::PluginData::supportsMimeType const):
* plugins/PluginData.h:
* plugins/PluginInfoProvider.h:

Source/WebKit:

Rename methods.
Pass an URL instead of relying on Page URL as the page URL
might not always be the URL we want to check against plugins.
In particular when navigation is on-going, we want to check the
plugins against the being navigated URL.

* WebProcess/Plugins/WebPluginInfoProvider.cpp:
(WebKit::WebPluginInfoProvider::pluginInfo):
(WebKit::WebPluginInfoProvider::webVisiblePluginInfo):
* WebProcess/Plugins/WebPluginInfoProvider.h:

Source/WebKitLegacy/mac:

* WebCoreSupport/WebPluginInfoProvider.h:
* WebCoreSupport/WebPluginInfoProvider.mm:
(WebPluginInfoProvider::pluginInfo):
(WebPluginInfoProvider::webVisiblePluginInfo):

Source/WebKitLegacy/win:

* WebCoreSupport/WebPluginInfoProvider.cpp:
(WebPluginInfoProvider::pluginInfo):
(WebPluginInfoProvider::webVisiblePluginInfo):
* WebCoreSupport/WebPluginInfoProvider.h:

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

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/EmptyClients.cpp
Source/WebCore/plugins/PluginData.cpp
Source/WebCore/plugins/PluginData.h
Source/WebCore/plugins/PluginInfoProvider.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/Plugins/WebPluginInfoProvider.cpp
Source/WebKit/WebProcess/Plugins/WebPluginInfoProvider.h
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebPluginInfoProvider.h
Source/WebKitLegacy/mac/WebCoreSupport/WebPluginInfoProvider.mm
Source/WebKitLegacy/win/ChangeLog
Source/WebKitLegacy/win/WebCoreSupport/WebPluginInfoProvider.cpp
Source/WebKitLegacy/win/WebCoreSupport/WebPluginInfoProvider.h

index 3c913ba..8d65b76 100644 (file)
@@ -1,3 +1,25 @@
+2018-04-20  Youenn Fablet  <youenn@apple.com>
+
+        Make PluginData cache its web visible plugins
+        https://bugs.webkit.org/show_bug.cgi?id=184421
+
+        Reviewed by Chris Dumez.
+
+        Buffer visible plugins until the page URL changes.
+        For that purpose, we now cache the visible plugins and the URL it was computed from in PluginData.
+
+        Update plugin info provider API to pass the URL used to check for plugin visibility.
+
+        No observable change of behavior.
+
+        * loader/EmptyClients.cpp:
+        * plugins/PluginData.cpp:
+        (WebCore::PluginData::webVisiblePlugins const):
+        (WebCore::PluginData::publiclyVisiblePlugins const):
+        (WebCore::PluginData::supportsMimeType const):
+        * plugins/PluginData.h:
+        * plugins/PluginInfoProvider.h:
+
 2018-04-20  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed build fix after r230840.
index b61b26f..c6e5eee 100644 (file)
@@ -325,8 +325,8 @@ class EmptyPaymentCoordinatorClient final : public PaymentCoordinatorClient {
 
 class EmptyPluginInfoProvider final : public PluginInfoProvider {
     void refreshPlugins() final { };
-    void getPluginInfo(Page&, Vector<PluginInfo>&, std::optional<Vector<SupportedPluginName>>&) final { }
-    void getWebVisiblePluginInfo(Page&, Vector<PluginInfo>&) final { }
+    Vector<PluginInfo> pluginInfo(Page&, std::optional<Vector<SupportedPluginName>>&) final { return { }; }
+    Vector<PluginInfo> webVisiblePluginInfo(Page&, const URL&) final { return { }; }
 };
 
 class EmptyPopupMenu : public PopupMenu {
index d3bc06a..eeec241 100644 (file)
@@ -24,6 +24,7 @@
 #include "config.h"
 #include "PluginData.h"
 
+#include "Document.h"
 #include "LocalizedStrings.h"
 #include "Page.h"
 #include "PluginInfoProvider.h"
@@ -36,11 +37,18 @@ PluginData::PluginData(Page& page)
     initPlugins();
 }
 
-Vector<PluginInfo> PluginData::webVisiblePlugins() const
+const Vector<PluginInfo>& PluginData::webVisiblePlugins() const
 {
-    Vector<PluginInfo> plugins;
-    m_page.pluginInfoProvider().getWebVisiblePluginInfo(m_page, plugins);
-    return plugins;
+    auto documentURL = m_page.mainFrame().document() ? m_page.mainFrame().document()->url() : URL { };
+    if (!documentURL.isNull() && !protocolHostAndPortAreEqual(m_cachedVisiblePlugins.pageURL, documentURL)) {
+        m_cachedVisiblePlugins.pageURL = WTFMove(documentURL);
+        m_cachedVisiblePlugins.pluginList = std::nullopt;
+    }
+
+    if (!m_cachedVisiblePlugins.pluginList)
+        m_cachedVisiblePlugins.pluginList = m_page.pluginInfoProvider().webVisiblePluginInfo(m_page, m_cachedVisiblePlugins.pageURL);
+
+    return *m_cachedVisiblePlugins.pluginList;
 }
 
 #if PLATFORM(COCOA)
@@ -73,17 +81,14 @@ static bool shouldBePubliclyVisible(const PluginInfo& plugin)
 
 Vector<PluginInfo> PluginData::publiclyVisiblePlugins() const
 {
+    auto plugins = webVisiblePlugins();
+
     if (m_page.showAllPlugins())
-        return webVisiblePlugins();
+        return plugins;
     
-    Vector<PluginInfo> allPlugins;
-    m_page.pluginInfoProvider().getWebVisiblePluginInfo(m_page, allPlugins);
-
-    Vector<PluginInfo> plugins;
-    for (auto&& plugin : allPlugins) {
-        if (shouldBePubliclyVisible(plugin))
-            plugins.append(WTFMove(plugin));
-    }
+    plugins.removeAllMatching([](auto& plugin) {
+        return !shouldBePubliclyVisible(plugin);
+    });
 
     std::sort(plugins.begin(), plugins.end(), [](const PluginInfo& a, const PluginInfo& b) {
         return codePointCompareLessThan(a.name, b.name);
@@ -174,7 +179,7 @@ void PluginData::initPlugins()
 {
     ASSERT(m_plugins.isEmpty());
 
-    m_page.pluginInfoProvider().getPluginInfo(m_page, m_plugins, m_supportedPluginNames);
+    m_plugins = m_page.pluginInfoProvider().pluginInfo(m_page, m_supportedPluginNames);
 }
 
 } // namespace WebCore
index a9a9fff..5004606 100644 (file)
@@ -102,7 +102,7 @@ public:
     static Ref<PluginData> create(Page& page) { return adoptRef(*new PluginData(page)); }
 
     const Vector<PluginInfo>& plugins() const { return m_plugins; }
-    Vector<PluginInfo> webVisiblePlugins() const;
+    const Vector<PluginInfo>& webVisiblePlugins() const;
     Vector<PluginInfo> publiclyVisiblePlugins() const;
     WEBCORE_EXPORT void getWebVisibleMimesAndPluginIndices(Vector<MimeClassInfo>&, Vector<size_t>&) const;
 
@@ -127,6 +127,12 @@ protected:
     Page& m_page;
     Vector<PluginInfo> m_plugins;
     std::optional<Vector<SupportedPluginName>> m_supportedPluginNames;
+
+    struct CachedVisiblePlugins {
+        URL pageURL;
+        std::optional<Vector<PluginInfo>> pluginList;
+    };
+    mutable CachedVisiblePlugins m_cachedVisiblePlugins;
 };
 
 inline bool isSupportedPlugin(const Vector<SupportedPluginName>& pluginNames, const URL& pageURL, const String& pluginName)
index b03cd2e..072f083 100644 (file)
@@ -39,8 +39,8 @@ public:
     void addPage(Page&);
     void removePage(Page&);
 
-    virtual void getPluginInfo(Page&, Vector<PluginInfo>&, std::optional<Vector<SupportedPluginName>>&) = 0;
-    virtual void getWebVisiblePluginInfo(Page&, Vector<PluginInfo>&) = 0;
+    virtual Vector<PluginInfo> pluginInfo(Page&, std::optional<Vector<SupportedPluginName>>&) = 0;
+    virtual Vector<PluginInfo> webVisiblePluginInfo(Page&, const URL&) = 0;
 
 private:
     virtual void refreshPlugins() = 0;
index c84367d..d6dfcb9 100644 (file)
@@ -1,3 +1,21 @@
+2018-04-20  Youenn Fablet  <youenn@apple.com>
+
+        Make PluginData cache its web visible plugins
+        https://bugs.webkit.org/show_bug.cgi?id=184421
+
+        Reviewed by Chris Dumez.
+
+        Rename methods.
+        Pass an URL instead of relying on Page URL as the page URL
+        might not always be the URL we want to check against plugins.
+        In particular when navigation is on-going, we want to check the
+        plugins against the being navigated URL.
+
+        * WebProcess/Plugins/WebPluginInfoProvider.cpp:
+        (WebKit::WebPluginInfoProvider::pluginInfo):
+        (WebKit::WebPluginInfoProvider::webVisiblePluginInfo):
+        * WebProcess/Plugins/WebPluginInfoProvider.h:
+
 2018-04-19  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix GTK+ build after r230830.
index 18f0312..347f588 100644 (file)
@@ -35,6 +35,7 @@
 #include <WebCore/Frame.h>
 #include <WebCore/FrameLoader.h>
 #include <WebCore/Page.h>
+#include <WebCore/SchemeRegistry.h>
 #include <WebCore/SubframeLoader.h>
 #include <wtf/text/StringHash.h>
 
@@ -96,7 +97,7 @@ void WebPluginInfoProvider::refreshPlugins()
 #endif
 }
 
-void WebPluginInfoProvider::getPluginInfo(Page& page, Vector<PluginInfo>& plugins, std::optional<Vector<SupportedPluginName>>& supportedPluginNames)
+Vector<PluginInfo> WebPluginInfoProvider::pluginInfo(Page& page, std::optional<Vector<SupportedPluginName>>& supportedPluginNames)
 {
 #if ENABLE(NETSCAPE_PLUGIN_API)
     populatePluginCache(page);
@@ -104,37 +105,26 @@ void WebPluginInfoProvider::getPluginInfo(Page& page, Vector<PluginInfo>& plugin
     if (m_cachedSupportedPluginNames)
         supportedPluginNames = *m_cachedSupportedPluginNames;
 
-    if (page.mainFrame().loader().subframeLoader().allowPlugins()) {
-        plugins = m_cachedPlugins;
-        return;
-    }
-
-    plugins = m_cachedApplicationPlugins;
+    return page.mainFrame().loader().subframeLoader().allowPlugins() ? m_cachedPlugins : m_cachedApplicationPlugins;
 #else
     UNUSED_PARAM(page);
-    UNUSED_PARAM(plugins);
+    UNUSED_PARAM(supportedPluginNames);
+    return { };
 #endif // ENABLE(NETSCAPE_PLUGIN_API)
 }
 
-void WebPluginInfoProvider::getWebVisiblePluginInfo(WebCore::Page& page, Vector<WebCore::PluginInfo>& plugins)
+Vector<WebCore::PluginInfo> WebPluginInfoProvider::webVisiblePluginInfo(Page& page, const WebCore::URL& url)
 {
-    ASSERT_ARG(plugins, plugins.isEmpty());
-
     std::optional<Vector<WebCore::SupportedPluginName>> supportedPluginNames;
-    getPluginInfo(page, plugins, supportedPluginNames);
+    auto plugins = pluginInfo(page, supportedPluginNames);
 
-    auto* document = page.mainFrame().document();
-
-    if (document && supportedPluginNames) {
-        plugins.removeAllMatching([&] (auto& plugin) {
-            return !isSupportedPlugin(*supportedPluginNames, document->url(), plugin.name);
-        });
-    }
+    plugins.removeAllMatching([&] (auto& plugin) {
+        return supportedPluginNames && !isSupportedPlugin(*supportedPluginNames, url, plugin.name);
+    });
 
 #if PLATFORM(MAC)
-    auto* origin = document ? &document->securityOrigin(): nullptr;
-    if (origin && origin->isLocal())
-        return;
+    if (SchemeRegistry::shouldTreatURLSchemeAsLocal(url.protocol().toString()))
+        return plugins;
 
     for (int32_t i = plugins.size() - 1; i >= 0; --i) {
         auto& info = plugins.at(i);
@@ -147,6 +137,7 @@ void WebPluginInfoProvider::getWebVisiblePluginInfo(WebCore::Page& page, Vector<
             plugins.remove(i);
     }
 #endif
+    return plugins;
 }
 
 #if ENABLE(NETSCAPE_PLUGIN_API)
index 3f640f1..2a1bdd0 100644 (file)
@@ -45,8 +45,8 @@ public:
 private:
     WebPluginInfoProvider();
 
-    void getPluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&, std::optional<Vector<WebCore::SupportedPluginName>>&) final;
-    void getWebVisiblePluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&) final;
+    Vector<WebCore::PluginInfo> pluginInfo(WebCore::Page&, std::optional<Vector<WebCore::SupportedPluginName>>&) final;
+    Vector<WebCore::PluginInfo> webVisiblePluginInfo(WebCore::Page&, const WebCore::URL&) final;
     void refreshPlugins() override;
 
 #if ENABLE(NETSCAPE_PLUGIN_API)
index b4e483c..48bbcd2 100644 (file)
@@ -1,3 +1,15 @@
+2018-04-20  Youenn Fablet  <youenn@apple.com>
+
+        Make PluginData cache its web visible plugins
+        https://bugs.webkit.org/show_bug.cgi?id=184421
+
+        Reviewed by Chris Dumez.
+
+        * WebCoreSupport/WebPluginInfoProvider.h:
+        * WebCoreSupport/WebPluginInfoProvider.mm:
+        (WebPluginInfoProvider::pluginInfo):
+        (WebPluginInfoProvider::webVisiblePluginInfo):
+
 2018-04-19  Chris Dumez  <cdumez@apple.com>
 
         Rename JSDOMWindowProxy to JSWindowProxy
index 3e695ee..8132472 100644 (file)
@@ -34,8 +34,8 @@ public:
 
 private:
     void refreshPlugins() override;
-    void getPluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&, std::optional<Vector<WebCore::SupportedPluginName>>&) final;
-    void getWebVisiblePluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&) final;
+    Vector<WebCore::PluginInfo> pluginInfo(WebCore::Page&, std::optional<Vector<WebCore::SupportedPluginName>>&) final;
+    Vector<WebCore::PluginInfo> webVisiblePluginInfo(WebCore::Page&, const WebCore::URL&) final;
 
     WebPluginInfoProvider();
 };
index 9d2a7db..2ede19a 100644 (file)
@@ -55,22 +55,27 @@ void WebPluginInfoProvider::refreshPlugins()
     [[WebPluginDatabase sharedDatabaseIfExists] refresh];
 }
 
-void WebPluginInfoProvider::getPluginInfo(WebCore::Page& page, Vector<WebCore::PluginInfo>& plugins, std::optional<Vector<SupportedPluginName>>&)
+Vector<WebCore::PluginInfo> WebPluginInfoProvider::pluginInfo(WebCore::Page& page, std::optional<Vector<SupportedPluginName>>&)
 {
+    Vector<WebCore::PluginInfo> plugins;
+
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
+
     // WebKit1 has no application plug-ins, so we don't need to add them here.
     if (!page.mainFrame().loader().subframeLoader().allowPlugins())
-        return;
+        return plugins;
 
     for (WebPluginPackage *plugin in [WebPluginDatabase sharedDatabase].plugins)
         plugins.append(plugin.pluginInfo);
 
     END_BLOCK_OBJC_EXCEPTIONS;
+
+    return plugins;
 }
 
-void WebPluginInfoProvider::getWebVisiblePluginInfo(WebCore::Page& page, Vector<WebCore::PluginInfo>& plugins)
+Vector<WebCore::PluginInfo> WebPluginInfoProvider::webVisiblePluginInfo(WebCore::Page& page, const WebCore::URL&)
 {
     std::optional<Vector<SupportedPluginName>> supportedPluginNames;
-    getPluginInfo(page, plugins, supportedPluginNames);
+    return pluginInfo(page, supportedPluginNames);
 }
index ec020ba..628c369 100644 (file)
@@ -1,3 +1,15 @@
+2018-04-20  Youenn Fablet  <youenn@apple.com>
+
+        Make PluginData cache its web visible plugins
+        https://bugs.webkit.org/show_bug.cgi?id=184421
+
+        Reviewed by Chris Dumez.
+
+        * WebCoreSupport/WebPluginInfoProvider.cpp:
+        (WebPluginInfoProvider::pluginInfo):
+        (WebPluginInfoProvider::webVisiblePluginInfo):
+        * WebCoreSupport/WebPluginInfoProvider.h:
+
 2018-04-19  Chris Dumez  <cdumez@apple.com>
 
         Rename JSDOMWindowProxy to JSWindowProxy
index dc8fab6..15942a8 100644 (file)
@@ -49,8 +49,9 @@ void WebPluginInfoProvider::refreshPlugins()
     PluginDatabase::installedPlugins()->refresh();
 }
 
-void WebPluginInfoProvider::getPluginInfo(WebCore::Page& page, Vector<WebCore::PluginInfo>& outPlugins, std::optional<Vector<WebCore::SupportedPluginName>>&)
+Vector<WebCore::PluginInfo> WebPluginInfoProvider::pluginInfo(WebCore::Page& page, std::optional<Vector<WebCore::SupportedPluginName>>&)
 {
+    Vector<WebCore::PluginInfo> outPlugins;
     const Vector<PluginPackage*>& plugins = PluginDatabase::installedPlugins()->plugins();
 
     outPlugins.resize(plugins.size());
@@ -80,10 +81,11 @@ void WebPluginInfoProvider::getPluginInfo(WebCore::Page& page, Vector<WebCore::P
 
         outPlugins[i] = info;
     }
+    return outPlugins;
 }
 
-void WebPluginInfoProvider::getWebVisiblePluginInfo(WebCore::Page& page, Vector<WebCore::PluginInfo>& plugins)
+Vector<WebCore::PluginInfo> WebPluginInfoProvider::webVisiblePluginInfo(WebCore::Page& page, const WebCore::URL&)
 {
     std::optional<Vector<WebCore::SupportedPluginName>> supportedPluginNames;
-    getPluginInfo(page, plugins, supportedPluginNames);
+    return pluginInfo(page, supportedPluginNames);
 }
index e7325ca..119615a 100644 (file)
@@ -36,8 +36,8 @@ public:
 
 private:
     void refreshPlugins() final;
-    void getPluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&, std::optional<Vector<WebCore::SupportedPluginName>>&) final;
-    void getWebVisiblePluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&) final;
+    Vector<WebCore::PluginInfo> pluginInfo(WebCore::Page&, std::optional<Vector<WebCore::SupportedPluginName>>&) final;
+    Vector<WebCore::PluginInfo> webVisiblePluginInfo(WebCore::Page&i, const WebCore::URL&) final;
 #if PLATFORM(MAC)
     void setPluginLoadClientPolicy(WebCore::PluginLoadClientPolicy, const String& host, const String& bundleIdentifier, const String& versionString) final;
     void clearPluginClientPolicies() final;