Match unsupported plugins based on domains and not origin
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Mar 2018 02:06:39 +0000 (02:06 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Mar 2018 02:06:39 +0000 (02:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=183384

Reviewed by Chris Dumez.

Source/WebCore:

Move from an origin-keyed map to a vector of plugins.
We iterate through the vector and a match happens if the page host name ends with the provided matching domain.
This allows supporting rules for *.mydomain.com by passing 'mydomain.com'.
Covered by existing tests.
We are not testing subdomains like www.localhost since there is no support in our CI but this is tested through Unit tests.

* loader/EmptyClients.cpp:
* platform/URL.cpp:
(WebCore::URL::isMatchingDomain const):
* platform/URL.h:
* plugins/PluginData.h:
(WebCore::isSupportedPlugin):
(WebCore::SupportedPluginName::decode):
(WebCore::SupportedPluginName::encode const):
* plugins/PluginInfoProvider.h:

Source/WebKit:

Moved from a HashMap of plugins to a Vector of plugins since we cannot match exactly based on the origin.

* Scripts/webkit/messages.py:
* UIProcess/API/C/WKContext.cpp:
(WKContextAddSupportedPlugin):
* UIProcess/API/Cocoa/WKProcessPool.mm:
(-[WKProcessPool _addSupportedPlugin:named:withMimeTypes:withExtensions:]):
* UIProcess/Plugins/PluginInfoStore.cpp:
(WebKit::PluginInfoStore::isSupportedPlugin):
(WebKit::PluginInfoStore::supportedPluginNames):
(WebKit::PluginInfoStore::addSupportedPlugin):
* UIProcess/Plugins/PluginInfoStore.h:
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::addSupportedPlugin):
* UIProcess/WebProcessPool.h:
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::getPlugins):
* UIProcess/WebProcessProxy.h:
* UIProcess/WebProcessProxy.messages.in:
* WebProcess/Plugins/WebPluginInfoProvider.cpp:
(WebKit::WebPluginInfoProvider::getPluginInfo):
(WebKit::WebPluginInfoProvider::getWebVisiblePluginInfo):
* WebProcess/Plugins/WebPluginInfoProvider.h:

Source/WebKitLegacy/mac:

* WebCoreSupport/WebPluginInfoProvider.h:
* WebCoreSupport/WebPluginInfoProvider.mm:
(WebPluginInfoProvider::getPluginInfo):
(WebPluginInfoProvider::getWebVisiblePluginInfo):

Tools:

* TestWebKitAPI/Tests/WebCore/URL.cpp:
(TestWebKitAPI::TEST_F):
* WebKitTestRunner/TestController.cpp:
(WTR::TestController::setPluginSupportedMode): Update to whitelist
localhost and not http://localhost:8080

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

29 files changed:
Source/WebCore/ChangeLog
Source/WebCore/loader/EmptyClients.cpp
Source/WebCore/platform/URL.cpp
Source/WebCore/platform/URL.h
Source/WebCore/plugins/PluginData.h
Source/WebCore/plugins/PluginInfoProvider.h
Source/WebKit/ChangeLog
Source/WebKit/Scripts/webkit/messages.py
Source/WebKit/UIProcess/API/C/WKContext.cpp
Source/WebKit/UIProcess/API/C/WKContextPrivate.h
Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm
Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h
Source/WebKit/UIProcess/Plugins/PluginInfoStore.cpp
Source/WebKit/UIProcess/Plugins/PluginInfoStore.h
Source/WebKit/UIProcess/WebProcessPool.cpp
Source/WebKit/UIProcess/WebProcessPool.h
Source/WebKit/UIProcess/WebProcessProxy.cpp
Source/WebKit/UIProcess/WebProcessProxy.h
Source/WebKit/UIProcess/WebProcessProxy.messages.in
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/WebCoreSupport/WebPluginInfoProvider.cpp
Source/WebKitLegacy/win/WebCoreSupport/WebPluginInfoProvider.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebCore/URL.cpp
Tools/WebKitTestRunner/TestController.cpp

index e7379bb..727aa25 100644 (file)
@@ -1,3 +1,26 @@
+2018-03-07  Youenn Fablet  <youenn@apple.com>
+
+        Match unsupported plugins based on domains and not origin
+        https://bugs.webkit.org/show_bug.cgi?id=183384
+
+        Reviewed by Chris Dumez.
+
+        Move from an origin-keyed map to a vector of plugins.
+        We iterate through the vector and a match happens if the page host name ends with the provided matching domain.
+        This allows supporting rules for *.mydomain.com by passing 'mydomain.com'.
+        Covered by existing tests.
+        We are not testing subdomains like www.localhost since there is no support in our CI but this is tested through Unit tests.
+
+        * loader/EmptyClients.cpp:
+        * platform/URL.cpp:
+        (WebCore::URL::isMatchingDomain const):
+        * platform/URL.h:
+        * plugins/PluginData.h:
+        (WebCore::isSupportedPlugin):
+        (WebCore::SupportedPluginName::decode):
+        (WebCore::SupportedPluginName::encode const):
+        * plugins/PluginInfoProvider.h:
+
 2017-12-18  Youenn Fablet  <youenn@apple.com>
 
         Update to libwebrtc revision 4e70a72571dd26b85c2385e9c618e343428df5d3
index 3386802..d8850ff 100644 (file)
@@ -325,7 +325,7 @@ class EmptyPaymentCoordinatorClient final : public PaymentCoordinatorClient {
 
 class EmptyPluginInfoProvider final : public PluginInfoProvider {
     void refreshPlugins() final { };
-    void getPluginInfo(Page&, Vector<PluginInfo>&, std::optional<SupportedPluginNames>&) final { }
+    void getPluginInfo(Page&, Vector<PluginInfo>&, std::optional<Vector<SupportedPluginName>>&) final { }
     void getWebVisiblePluginInfo(Page&, Vector<PluginInfo>&) final { }
 };
 
index 597a56c..97d91f3 100644 (file)
@@ -776,6 +776,22 @@ bool hostsAreEqual(const URL& a, const URL& b)
     return true;
 }
 
+bool URL::isMatchingDomain(const String& domain) const
+{
+    // We restrict it to HTTP for simplicity since we do not want to match data, blob or file based URLs.
+    if (isNull() || !protocolIsInHTTPFamily())
+        return false;
+
+    if (domain.isEmpty())
+        return true;
+
+    auto host = this->host();
+    if (!host.endsWith(domain))
+        return false;
+
+    return host.length() == domain.length() || host.characterAt(host.length() - domain.length() - 1) == '.';
+}
+
 String encodeWithURLEscapeSequences(const String& input)
 {
     return percentEncodeCharacters(input, URLParser::isInUserInfoEncodeSet);
index b8ed778..45a7b31 100644 (file)
@@ -141,6 +141,8 @@ public:
     WEBCORE_EXPORT bool isBlankURL() const;
     bool cannotBeABaseURL() const { return m_cannotBeABaseURL; }
 
+    WEBCORE_EXPORT bool isMatchingDomain(const String&) const;
+
     WEBCORE_EXPORT bool setProtocol(const String&);
     void setHost(const String&);
 
index 690ba72..a9a9fff 100644 (file)
@@ -20,7 +20,7 @@
 
 #pragma once
 
-#include "SecurityOriginData.h"
+#include "URL.h"
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 #include <wtf/RefCounted.h>
@@ -88,12 +88,12 @@ inline bool operator==(PluginInfo& a, PluginInfo& b)
     return result;
 }
 
-struct SupportedPluginNames {
-    HashSet<String> allOriginPlugins;
-    HashMap<SecurityOriginData, HashSet<String>> originSpecificPlugins;
+struct SupportedPluginName {
+    String matchingDomain;
+    String pluginName;
 
     template<class Encoder> void encode(Encoder&) const;
-    template<class Decoder> static std::optional<SupportedPluginNames> decode(Decoder&);
+    template<class Decoder> static std::optional<SupportedPluginName> decode(Decoder&);
 };
 
 // FIXME: merge with PluginDatabase in the future
@@ -126,39 +126,35 @@ private:
 protected:
     Page& m_page;
     Vector<PluginInfo> m_plugins;
-    std::optional<SupportedPluginNames> m_supportedPluginNames;
+    std::optional<Vector<SupportedPluginName>> m_supportedPluginNames;
 };
 
-inline bool isSupportedPlugin(SupportedPluginNames& pluginNames, SecurityOriginData& origin, const String& pluginName)
+inline bool isSupportedPlugin(const Vector<SupportedPluginName>& pluginNames, const URL& pageURL, const String& pluginName)
 {
-    auto iterator = pluginNames.originSpecificPlugins.find(origin);
-    if (iterator != pluginNames.originSpecificPlugins.end()) {
-        if (iterator->value.contains(pluginName))
-            return true;
-    }
-
-    return pluginNames.allOriginPlugins.contains(pluginName);
+    return pluginNames.findMatching([&] (auto&& plugin) {
+        return pageURL.isMatchingDomain(plugin.matchingDomain) && plugin.pluginName == pluginName;
+    }) != notFound;
 }
 
-template<class Decoder> inline std::optional<SupportedPluginNames> SupportedPluginNames::decode(Decoder& decoder)
+template<class Decoder> inline std::optional<SupportedPluginName> SupportedPluginName::decode(Decoder& decoder)
 {
-    std::optional<HashSet<String>> allOriginPlugins;
-    decoder >> allOriginPlugins;
-    if (!allOriginPlugins)
+    std::optional<String> matchingDomain;
+    decoder >> matchingDomain;
+    if (!matchingDomain)
         return std::nullopt;
 
-    std::optional<HashMap<SecurityOriginData, HashSet<String>>> originSpecificPlugins;
-    decoder >> originSpecificPlugins;
-    if (!originSpecificPlugins)
+    std::optional<String> pluginName;
+    decoder >> pluginName;
+    if (!pluginName)
         return std::nullopt;
 
-    return SupportedPluginNames { WTFMove(allOriginPlugins.value()), WTFMove(originSpecificPlugins.value()) };
+    return SupportedPluginName { WTFMove(matchingDomain.value()), WTFMove(pluginName.value()) };
 }
 
-template<class Encoder> inline void SupportedPluginNames::encode(Encoder& encoder) const
+template<class Encoder> inline void SupportedPluginName::encode(Encoder& encoder) const
 {
-    encoder << allOriginPlugins;
-    encoder << originSpecificPlugins;
+    encoder << matchingDomain;
+    encoder << pluginName;
 }
 
 } // namespace WebCore
index 6e05efb..b03cd2e 100644 (file)
@@ -39,7 +39,7 @@ public:
     void addPage(Page&);
     void removePage(Page&);
 
-    virtual void getPluginInfo(Page&, Vector<PluginInfo>&, std::optional<SupportedPluginNames>&) = 0;
+    virtual void getPluginInfo(Page&, Vector<PluginInfo>&, std::optional<Vector<SupportedPluginName>>&) = 0;
     virtual void getWebVisiblePluginInfo(Page&, Vector<PluginInfo>&) = 0;
 
 private:
index 7ac5b43..32089ab 100644 (file)
@@ -1,3 +1,34 @@
+2018-03-07  Youenn Fablet  <youenn@apple.com>
+
+        Match unsupported plugins based on domains and not origin
+        https://bugs.webkit.org/show_bug.cgi?id=183384
+
+        Reviewed by Chris Dumez.
+
+        Moved from a HashMap of plugins to a Vector of plugins since we cannot match exactly based on the origin.
+
+        * Scripts/webkit/messages.py:
+        * UIProcess/API/C/WKContext.cpp:
+        (WKContextAddSupportedPlugin):
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        (-[WKProcessPool _addSupportedPlugin:named:withMimeTypes:withExtensions:]):
+        * UIProcess/Plugins/PluginInfoStore.cpp:
+        (WebKit::PluginInfoStore::isSupportedPlugin):
+        (WebKit::PluginInfoStore::supportedPluginNames):
+        (WebKit::PluginInfoStore::addSupportedPlugin):
+        * UIProcess/Plugins/PluginInfoStore.h:
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::addSupportedPlugin):
+        * UIProcess/WebProcessPool.h:
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::getPlugins):
+        * UIProcess/WebProcessProxy.h:
+        * UIProcess/WebProcessProxy.messages.in:
+        * WebProcess/Plugins/WebPluginInfoProvider.cpp:
+        (WebKit::WebPluginInfoProvider::getPluginInfo):
+        (WebKit::WebPluginInfoProvider::getWebVisiblePluginInfo):
+        * WebProcess/Plugins/WebPluginInfoProvider.h:
+
 2018-03-07  Brent Fulgham  <bfulgham@apple.com>
 
         REGRESSION (r229093): Media playback on Facebook and Hulu require mDNSResponder access
index 4ba3adb..717c120 100644 (file)
@@ -398,7 +398,7 @@ def headers_for_type(type):
         'WebCore::ShippingMethodUpdate': ['<WebCore/ApplePaySessionPaymentRequest.h>'],
         'WebCore::ShouldNotifyWhenResolved': ['<WebCore/ServiceWorkerTypes.h>'],
         'WebCore::ShouldSample': ['<WebCore/DiagnosticLoggingClient.h>'],
-        'WebCore::SupportedPluginNames': ['<WebCore/PluginData.h>'],
+        'WebCore::SupportedPluginName': ['<WebCore/PluginData.h>'],
         'WebCore::TextCheckingRequestData': ['<WebCore/TextChecking.h>'],
         'WebCore::TextCheckingResult': ['<WebCore/TextCheckerClient.h>'],
         'WebCore::TextIndicatorData': ['<WebCore/TextIndicator.h>'],
index dee0a09..9f2bf64 100644 (file)
@@ -621,7 +621,7 @@ ProcessID WKContextGetDatabaseProcessIdentifier(WKContextRef contextRef)
     return toImpl(contextRef)->storageProcessIdentifier();
 }
 
-void WKContextAddSupportedPlugin(WKContextRef contextRef, WKStringRef originRef, WKStringRef nameRef, WKArrayRef mimeTypesRef, WKArrayRef extensionsRef)
+void WKContextAddSupportedPlugin(WKContextRef contextRef, WKStringRef domainRef, WKStringRef nameRef, WKArrayRef mimeTypesRef, WKArrayRef extensionsRef)
 {
 #if ENABLE(NETSCAPE_PLUGIN_API)
     HashSet<String> mimeTypes;
@@ -634,10 +634,7 @@ void WKContextAddSupportedPlugin(WKContextRef contextRef, WKStringRef originRef,
     for (size_t i = 0; i < count; ++i)
         extensions.add(toWTFString(static_cast<WKStringRef>(WKArrayGetItemAtIndex(extensionsRef, i))));
 
-    RefPtr<SecurityOrigin> origin;
-    if (!WKStringIsEmpty(originRef))
-        origin = SecurityOrigin::createFromString(toWTFString(originRef));
-    toImpl(contextRef)->addSupportedPlugin(origin.get(), toWTFString(nameRef), WTFMove(mimeTypes), WTFMove(extensions));
+    toImpl(contextRef)->addSupportedPlugin(toWTFString(domainRef), toWTFString(nameRef), WTFMove(mimeTypes), WTFMove(extensions));
 #endif
 }
 
index 06480e1..eca52d3 100644 (file)
@@ -112,7 +112,7 @@ WK_EXPORT void WKContextPreconnectToServer(WKContextRef context, WKURLRef server
 WK_EXPORT WKProcessID WKContextGetNetworkProcessIdentifier(WKContextRef context);
 WK_EXPORT WKProcessID WKContextGetDatabaseProcessIdentifier(WKContextRef context);
 
-WK_EXPORT void WKContextAddSupportedPlugin(WKContextRef context, WKStringRef origin, WKStringRef name, WKArrayRef mimeTypes, WKArrayRef extensions);
+WK_EXPORT void WKContextAddSupportedPlugin(WKContextRef context, WKStringRef domain, WKStringRef name, WKArrayRef mimeTypes, WKArrayRef extensions);
 WK_EXPORT void WKContextClearSupportedPlugins(WKContextRef context);
 
 #ifdef __cplusplus
index 5f0c326..1d6bbb1 100644 (file)
@@ -397,7 +397,7 @@ static NSDictionary *policiesHashMapToDictionary(const HashMap<String, HashMap<S
     _processPool->setAutomationSession(automationSession ? automationSession->_session.get() : nullptr);
 }
 
-- (void)_addSupportedPlugin:(NSString *) origin named:(NSString *) name withMimeTypes: (NSSet<NSString *> *) nsMimeTypes withExtensions: (NSSet<NSString *> *) nsExtensions
+- (void)_addSupportedPlugin:(NSString *) domain named:(NSString *) name withMimeTypes: (NSSet<NSString *> *) nsMimeTypes withExtensions: (NSSet<NSString *> *) nsExtensions
 {
     HashSet<String> mimeTypes;
     for (NSString *mimeType in nsMimeTypes)
@@ -406,7 +406,7 @@ static NSDictionary *policiesHashMapToDictionary(const HashMap<String, HashMap<S
     for (NSString *extension in nsExtensions)
         extensions.add(extension);
 
-    _processPool->addSupportedPlugin([origin length] ? WebCore::SecurityOrigin::createFromString(origin).ptr() : nullptr, name, WTFMove(mimeTypes), WTFMove(extensions));
+    _processPool->addSupportedPlugin(domain, name, WTFMove(mimeTypes), WTFMove(extensions));
 }
 
 - (void)_clearSupportedPlugins
index 8d152b5..7b00eea 100644 (file)
@@ -72,7 +72,7 @@
 - (void)_automationCapabilitiesDidChange WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 - (void)_setAutomationSession:(_WKAutomationSession *)automationSession WK_API_AVAILABLE(macosx(10.12), ios(10.0));
 
-- (void)_addSupportedPlugin:(NSString *) origin named:(NSString *) name withMimeTypes: (NSSet<NSString *> *) mimeTypes withExtensions: (NSSet<NSString *> *) extensions WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+- (void)_addSupportedPlugin:(NSString *) domain named:(NSString *) name withMimeTypes: (NSSet<NSString *> *) mimeTypes withExtensions: (NSSet<NSString *> *) extensions WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (void)_clearSupportedPlugins WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 // Test only. Should be called only while no web content processes are running.
index 61c00ee..23db334 100644 (file)
@@ -29,8 +29,9 @@
 #if ENABLE(NETSCAPE_PLUGIN_API)
 
 #include "PluginModuleInfo.h"
-#include <WebCore/URL.h>
 #include <WebCore/MIMETypeRegistry.h>
+#include <WebCore/SecurityOrigin.h>
+#include <WebCore/URL.h>
 #include <algorithm>
 #include <wtf/ListHashSet.h>
 #include <wtf/StdLibExtras.h>
@@ -214,53 +215,31 @@ bool PluginInfoStore::isSupportedPlugin(const PluginInfoStore::SupportedPlugin&
 
 bool PluginInfoStore::isSupportedPlugin(const String& mimeType, const URL& pluginURL, const String&, const URL& pageURL)
 {
-    // We check only pageURLString for consistency with WebProcess visible plugins.
+    // We check only pageURL for consistency with WebProcess visible plugins.
     if (!m_supportedPlugins)
         return true;
 
-    for (auto& plugin : m_supportedPlugins->originSpecificPlugins.get(SecurityOriginData { pageURL.protocol().toString(), pageURL.host(), pageURL.port() })) {
-        if (isSupportedPlugin(plugin, mimeType, pluginURL))
-            return true;
-    }
-    for (auto& plugin : m_supportedPlugins->allOriginPlugins) {
-        if (isSupportedPlugin(plugin, mimeType, pluginURL))
-            return true;
-    }
-    return false;
+    return m_supportedPlugins->findMatching([&] (auto&& plugin) {
+        return pageURL.isMatchingDomain(plugin.matchingDomain) && isSupportedPlugin(plugin, mimeType, pluginURL);
+    }) != notFound;
 }
 
-std::optional<SupportedPluginNames> PluginInfoStore::supportedPluginNames()
+std::optional<Vector<SupportedPluginName>> PluginInfoStore::supportedPluginNames()
 {
     if (!m_supportedPlugins)
         return std::nullopt;
 
-    HashSet<String> allOriginPlugins;
-    for (auto& plugin : m_supportedPlugins->allOriginPlugins)
-        allOriginPlugins.add(plugin.name);
-
-    HashMap<SecurityOriginData, HashSet<String>> originSpecificPlugins;
-    for (auto& keyValue : m_supportedPlugins->originSpecificPlugins) {
-        HashSet<String> names;
-        for (auto& plugin : keyValue.value)
-            names.add(plugin.name);
-        originSpecificPlugins.add(keyValue.key, WTFMove(names));
-    }
-    return SupportedPluginNames { WTFMove(allOriginPlugins), WTFMove(originSpecificPlugins) };
+    return WTF::map(*m_supportedPlugins, [] (auto&& item) {
+        return SupportedPluginName { item.matchingDomain, item.name };
+    });
 }
 
-void PluginInfoStore::addSupportedPlugin(const SecurityOrigin* origin, String&& name, HashSet<String>&& mimeTypes, HashSet<String> extensions)
+void PluginInfoStore::addSupportedPlugin(String&& domainName, String&& name, HashSet<String>&& mimeTypes, HashSet<String> extensions)
 {
     if (!m_supportedPlugins)
-        m_supportedPlugins = SupportedPlugins { };
+        m_supportedPlugins = Vector<SupportedPlugin> { };
 
-    SupportedPlugin plugin { WTFMove(name), WTFMove(mimeTypes), WTFMove(extensions) };
-    if (!origin) {
-        m_supportedPlugins->allOriginPlugins.append(WTFMove(plugin));
-        return;
-    }
-    m_supportedPlugins->originSpecificPlugins.ensure(SecurityOriginData::fromSecurityOrigin(*origin), [] {
-        return Vector<SupportedPlugin> { };
-    }).iterator->value.append(WTFMove(plugin));
+    m_supportedPlugins->append(SupportedPlugin { WTFMove(domainName), WTFMove(name), WTFMove(mimeTypes), WTFMove(extensions) });
 }
 
 PluginModuleInfo PluginInfoStore::infoForPluginWithPath(const String& pluginPath) const
index d3a109f..2da1549 100644 (file)
@@ -64,8 +64,8 @@ public:
     static PluginModuleLoadPolicy defaultLoadPolicyForPlugin(const PluginModuleInfo&);
 
     bool isSupportedPlugin(const String& mimeType, const WebCore::URL& pluginURL, const String& frameURLString, const WebCore::URL& pageURL);
-    std::optional<WebCore::SupportedPluginNames> supportedPluginNames();
-    void addSupportedPlugin(const WebCore::SecurityOrigin*, String&& name, HashSet<String>&& mimeTypes, HashSet<String> extensions);
+    std::optional<Vector<WebCore::SupportedPluginName>> supportedPluginNames();
+    void addSupportedPlugin(String&& matchingDomain, String&& name, HashSet<String>&& mimeTypes, HashSet<String> extensions);
     void clearSupportedPlugins() { m_supportedPlugins = std::nullopt; }
 
 private:
@@ -97,17 +97,14 @@ private:
     bool m_pluginListIsUpToDate;
 
     struct SupportedPlugin {
+        String matchingDomain;
         String name;
         HashSet<String> mimeTypes;
         HashSet<String> extensions;
     };
-    struct SupportedPlugins {
-        Vector<SupportedPlugin> allOriginPlugins;
-        HashMap<WebCore::SecurityOriginData, Vector<SupportedPlugin>> originSpecificPlugins;
-    };
     static bool isSupportedPlugin(const SupportedPlugin&, const String& mimeType, const WebCore::URL& pluginURL);
 
-    std::optional<SupportedPlugins> m_supportedPlugins;
+    std::optional<Vector<SupportedPlugin>> m_supportedPlugins;
 };
     
 } // namespace WebKit
index 3fcaf5a..53f99fb 100644 (file)
@@ -1793,12 +1793,12 @@ void WebProcessPool::clearPluginClientPolicies()
 }
 #endif
 
-void WebProcessPool::addSupportedPlugin(SecurityOrigin* origin, String&& name, HashSet<String>&& mimeTypes, HashSet<String> extensions)
+void WebProcessPool::addSupportedPlugin(String&& matchingDomain, String&& name, HashSet<String>&& mimeTypes, HashSet<String> extensions)
 {
 #if ENABLE(NETSCAPE_PLUGIN_API)
-    m_pluginInfoStore.addSupportedPlugin(origin, WTFMove(name), WTFMove(mimeTypes), WTFMove(extensions));
+    m_pluginInfoStore.addSupportedPlugin(WTFMove(matchingDomain), WTFMove(name), WTFMove(mimeTypes), WTFMove(extensions));
 #else
-    UNUSED_PARAM(origin);
+    UNUSED_PARAM(matchingDomain);
     UNUSED_PARAM(name);
     UNUSED_PARAM(mimeTypes);
     UNUSED_PARAM(extensions);
index 907ef7b..b8926ed 100644 (file)
@@ -202,7 +202,7 @@ public:
     const HashMap<String, HashMap<String, HashMap<String, uint8_t>>>& pluginLoadClientPolicies() const { return m_pluginLoadClientPolicies; }
 #endif
 
-    void addSupportedPlugin(WebCore::SecurityOrigin*, String&& name, HashSet<String>&& mimeTypes, HashSet<String> extensions);
+    void addSupportedPlugin(String&& matchingDomain, String&& name, HashSet<String>&& mimeTypes, HashSet<String> extensions);
     void clearSupportedPlugins();
 
     ProcessID networkProcessIdentifier();
index a1198b3..ae8b8fd 100644 (file)
@@ -570,7 +570,7 @@ void WebProcessProxy::addBackForwardItem(uint64_t itemID, uint64_t pageID, const
 }
 
 #if ENABLE(NETSCAPE_PLUGIN_API)
-void WebProcessProxy::getPlugins(bool refresh, Vector<PluginInfo>& plugins, Vector<PluginInfo>& applicationPlugins, std::optional<WebCore::SupportedPluginNames>& supportedPluginNames)
+void WebProcessProxy::getPlugins(bool refresh, Vector<PluginInfo>& plugins, Vector<PluginInfo>& applicationPlugins, std::optional<Vector<WebCore::SupportedPluginName>>& supportedPluginNames)
 {
     if (refresh)
         m_processPool->pluginInfoStore().refresh();
index 1b66540..697eb90 100644 (file)
@@ -238,7 +238,7 @@ private:
 
     // Plugins
 #if ENABLE(NETSCAPE_PLUGIN_API)
-    void getPlugins(bool refresh, Vector<WebCore::PluginInfo>& plugins, Vector<WebCore::PluginInfo>& applicationPlugins, std::optional<WebCore::SupportedPluginNames>&);
+    void getPlugins(bool refresh, Vector<WebCore::PluginInfo>& plugins, Vector<WebCore::PluginInfo>& applicationPlugins, std::optional<Vector<WebCore::SupportedPluginName>>&);
 #endif // ENABLE(NETSCAPE_PLUGIN_API)
 #if ENABLE(NETSCAPE_PLUGIN_API)
     void getPluginProcessConnection(uint64_t pluginProcessToken, Ref<Messages::WebProcessProxy::GetPluginProcessConnection::DelayedReply>&&);
index 7f809f8..98c712a 100644 (file)
@@ -33,7 +33,7 @@ messages -> WebProcessProxy LegacyReceiver {
 
     # Plugin messages.
 #if ENABLE(NETSCAPE_PLUGIN_API)
-    GetPlugins(bool refresh) -> (Vector<WebCore::PluginInfo> plugins, Vector<WebCore::PluginInfo> applicationPlugins, struct std::optional<WebCore::SupportedPluginNames> supportedPluginNames)
+    GetPlugins(bool refresh) -> (Vector<WebCore::PluginInfo> plugins, Vector<WebCore::PluginInfo> applicationPlugins, struct std::optional<Vector<WebCore::SupportedPluginName>> supportedPluginNames)
     GetPluginProcessConnection(uint64_t pluginProcessToken) -> (IPC::Attachment connectionHandle, bool supportsAsynchronousInitialization) Delayed
 #endif
     GetNetworkProcessConnection() -> (IPC::Attachment connectionHandle) Delayed
index d97c020..44889a0 100644 (file)
@@ -35,7 +35,6 @@
 #include <WebCore/FrameLoader.h>
 #include <WebCore/MainFrame.h>
 #include <WebCore/Page.h>
-#include <WebCore/SecurityOriginData.h>
 #include <WebCore/SubframeLoader.h>
 #include <wtf/text/StringHash.h>
 
@@ -97,7 +96,7 @@ void WebPluginInfoProvider::refreshPlugins()
 #endif
 }
 
-void WebPluginInfoProvider::getPluginInfo(Page& page, Vector<PluginInfo>& plugins, std::optional<SupportedPluginNames>& supportedPluginNames)
+void WebPluginInfoProvider::getPluginInfo(Page& page, Vector<PluginInfo>& plugins, std::optional<Vector<SupportedPluginName>>& supportedPluginNames)
 {
 #if ENABLE(NETSCAPE_PLUGIN_API)
     populatePluginCache(page);
@@ -121,20 +120,19 @@ void WebPluginInfoProvider::getWebVisiblePluginInfo(WebCore::Page& page, Vector<
 {
     ASSERT_ARG(plugins, plugins.isEmpty());
 
-    std::optional<WebCore::SupportedPluginNames> supportedPluginNames;
+    std::optional<Vector<WebCore::SupportedPluginName>> supportedPluginNames;
     getPluginInfo(page, plugins, supportedPluginNames);
 
     auto* document = page.mainFrame().document();
-    auto* origin = document ? &document->securityOrigin(): nullptr;
 
-    if (origin && supportedPluginNames) {
-        auto originData = SecurityOriginData::fromSecurityOrigin(*origin);
+    if (document && supportedPluginNames) {
         plugins.removeAllMatching([&] (auto& plugin) {
-            return !isSupportedPlugin(*supportedPluginNames, originData, plugin.name);
+            return !isSupportedPlugin(*supportedPluginNames, document->url(), plugin.name);
         });
     }
 
 #if PLATFORM(MAC)
+    auto* origin = document ? &document->securityOrigin(): nullptr;
     if (origin && origin->isLocal())
         return;
 
index c5cb1d8..3f640f1 100644 (file)
@@ -45,7 +45,7 @@ public:
 private:
     WebPluginInfoProvider();
 
-    void getPluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&, std::optional<WebCore::SupportedPluginNames>&) final;
+    void getPluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&, std::optional<Vector<WebCore::SupportedPluginName>>&) final;
     void getWebVisiblePluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&) final;
     void refreshPlugins() override;
 
@@ -68,7 +68,7 @@ private:
     bool m_shouldRefreshPlugins { false };
     Vector<WebCore::PluginInfo> m_cachedPlugins;
     Vector<WebCore::PluginInfo> m_cachedApplicationPlugins;
-    std::optional<WebCore::SupportedPluginNames> m_cachedSupportedPluginNames;
+    std::optional<Vector<WebCore::SupportedPluginName>> m_cachedSupportedPluginNames;
 #endif
 };
 
index 4d1398d..9365955 100644 (file)
@@ -1,3 +1,15 @@
+2018-03-07  Youenn Fablet  <youenn@apple.com>
+
+        Match unsupported plugins based on domains and not origin
+        https://bugs.webkit.org/show_bug.cgi?id=183384
+
+        Reviewed by Chris Dumez.
+
+        * WebCoreSupport/WebPluginInfoProvider.h:
+        * WebCoreSupport/WebPluginInfoProvider.mm:
+        (WebPluginInfoProvider::getPluginInfo):
+        (WebPluginInfoProvider::getWebVisiblePluginInfo):
+
 2018-03-05  Andy Estes  <aestes@apple.com>
 
         [Mac] Teach WebCore::Pasteboard about file promise drags
index 4a91bab..3e695ee 100644 (file)
@@ -34,7 +34,7 @@ public:
 
 private:
     void refreshPlugins() override;
-    void getPluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&, std::optional<WebCore::SupportedPluginNames>&) final;
+    void getPluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&, std::optional<Vector<WebCore::SupportedPluginName>>&) final;
     void getWebVisiblePluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&) final;
 
     WebPluginInfoProvider();
index 982db72..cd58f82 100644 (file)
@@ -55,7 +55,7 @@ void WebPluginInfoProvider::refreshPlugins()
     [[WebPluginDatabase sharedDatabaseIfExists] refresh];
 }
 
-void WebPluginInfoProvider::getPluginInfo(WebCore::Page& page, Vector<WebCore::PluginInfo>& plugins, std::optional<SupportedPluginNames>&)
+void WebPluginInfoProvider::getPluginInfo(WebCore::Page& page, Vector<WebCore::PluginInfo>& plugins, std::optional<Vector<SupportedPluginName>>&)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
@@ -71,6 +71,6 @@ void WebPluginInfoProvider::getPluginInfo(WebCore::Page& page, Vector<WebCore::P
 
 void WebPluginInfoProvider::getWebVisiblePluginInfo(WebCore::Page& page, Vector<WebCore::PluginInfo>& plugins)
 {
-    std::optional<SupportedPluginNames> supportedPluginNames;
+    std::optional<Vector<SupportedPluginName>> supportedPluginNames;
     getPluginInfo(page, plugins, supportedPluginNames);
 }
index 8db9d09..dc8fab6 100644 (file)
@@ -49,7 +49,7 @@ void WebPluginInfoProvider::refreshPlugins()
     PluginDatabase::installedPlugins()->refresh();
 }
 
-void WebPluginInfoProvider::getPluginInfo(WebCore::Page& page, Vector<WebCore::PluginInfo>& outPlugins, std::optional<WebCore::SupportedPluginNames>&)
+void WebPluginInfoProvider::getPluginInfo(WebCore::Page& page, Vector<WebCore::PluginInfo>& outPlugins, std::optional<Vector<WebCore::SupportedPluginName>>&)
 {
     const Vector<PluginPackage*>& plugins = PluginDatabase::installedPlugins()->plugins();
 
@@ -84,6 +84,6 @@ void WebPluginInfoProvider::getPluginInfo(WebCore::Page& page, Vector<WebCore::P
 
 void WebPluginInfoProvider::getWebVisiblePluginInfo(WebCore::Page& page, Vector<WebCore::PluginInfo>& plugins)
 {
-    std::optional<WebCore::SupportedPluginNames> supportedPluginNames;
+    std::optional<Vector<WebCore::SupportedPluginName>> supportedPluginNames;
     getPluginInfo(page, plugins, supportedPluginNames);
 }
index bbc9bdc..e7325ca 100644 (file)
@@ -36,7 +36,7 @@ public:
 
 private:
     void refreshPlugins() final;
-    void getPluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&, std::optional<WebCore::SupportedPluginNames>&) final;
+    void getPluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&, std::optional<Vector<WebCore::SupportedPluginName>>&) final;
     void getWebVisiblePluginInfo(WebCore::Page&, Vector<WebCore::PluginInfo>&) final;
 #if PLATFORM(MAC)
     void setPluginLoadClientPolicy(WebCore::PluginLoadClientPolicy, const String& host, const String& bundleIdentifier, const String& versionString) final;
index 0dd130c..8b00bdb 100644 (file)
@@ -1,3 +1,16 @@
+2018-03-07  Youenn Fablet  <youenn@apple.com>
+
+        Match unsupported plugins based on domains and not origin
+        https://bugs.webkit.org/show_bug.cgi?id=183384
+
+        Reviewed by Chris Dumez.
+
+        * TestWebKitAPI/Tests/WebCore/URL.cpp:
+        (TestWebKitAPI::TEST_F):
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::TestController::setPluginSupportedMode): Update to whitelist
+        localhost and not http://localhost:8080
+
 2018-03-07  Jonathan Bedard  <jbedard@apple.com>
 
         webkitpy: Allow apple_additions() to define additional ports
index 7c788a7..e07b475 100644 (file)
@@ -264,4 +264,32 @@ TEST_F(URLTest, HostIsIPAddress)
     EXPECT_TRUE(URL::hostIsIPAddress("::123.45.67.89"));
 }
 
+TEST_F(URLTest, HostIsMatchingDomain)
+{
+    URL url = createURL("http://www.webkit.org");
+
+    EXPECT_TRUE(url.isMatchingDomain(String { }));
+    EXPECT_TRUE(url.isMatchingDomain(emptyString()));
+    EXPECT_TRUE(url.isMatchingDomain(ASCIILiteral("org")));
+    EXPECT_TRUE(url.isMatchingDomain(ASCIILiteral("webkit.org")));
+    EXPECT_TRUE(url.isMatchingDomain(ASCIILiteral("www.webkit.org")));
+
+    EXPECT_FALSE(url.isMatchingDomain(ASCIILiteral("rg")));
+    EXPECT_FALSE(url.isMatchingDomain(ASCIILiteral(".org")));
+    EXPECT_FALSE(url.isMatchingDomain(ASCIILiteral("ww.webkit.org")));
+    EXPECT_FALSE(url.isMatchingDomain(ASCIILiteral("http://www.webkit.org")));
+
+    url = createURL("file:///www.webkit.org");
+
+    EXPECT_FALSE(url.isMatchingDomain(String { }));
+    EXPECT_FALSE(url.isMatchingDomain(emptyString()));
+    EXPECT_FALSE(url.isMatchingDomain(ASCIILiteral("org")));
+    EXPECT_FALSE(url.isMatchingDomain(ASCIILiteral("webkit.org")));
+    EXPECT_FALSE(url.isMatchingDomain(ASCIILiteral("www.webkit.org")));
+
+    URL emptyURL;
+    EXPECT_FALSE(emptyURL.isMatchingDomain(String { }));
+    EXPECT_FALSE(emptyURL.isMatchingDomain(emptyString()));
+}
+
 } // namespace TestWebKitAPI
index cf50801..3fae217 100644 (file)
@@ -1703,7 +1703,7 @@ void TestController::setPluginSupportedMode(const String& mode)
 
     WKRetainPtr<WKMutableArrayRef> emptyArray = adoptWK(WKMutableArrayCreate());
     WKRetainPtr<WKStringRef> allOrigins = adoptWK(WKStringCreateWithUTF8CString(""));
-    WKRetainPtr<WKStringRef> specificOrigin = adoptWK(WKStringCreateWithUTF8CString("http://localhost:8080"));
+    WKRetainPtr<WKStringRef> specificOrigin = adoptWK(WKStringCreateWithUTF8CString("localhost"));
 
     WKRetainPtr<WKStringRef> pdfName = adoptWK(WKStringCreateWithUTF8CString("My personal PDF"));
     WKContextAddSupportedPlugin(m_context.get(), allOrigins.get(), pdfName.get(), emptyArray.get(), emptyArray.get());