Add API to remove a single content filter.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Feb 2015 18:33:39 +0000 (18:33 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 27 Feb 2015 18:33:39 +0000 (18:33 +0000)
<rdar://problem/19977764> and https://bugs.webkit.org/show_bug.cgi?id=142088

Reviewed by Sam Weinig.

Source/WebCore:

* page/UserContentController.cpp:
(WebCore::UserContentController::removeUserContentFilter):
* page/UserContentController.h:

Source/WebKit2:

* Shared/WebPageGroupData.h:

* UIProcess/API/C/WKPageGroup.cpp:
(WKPageGroupRemoveUserContentFilter):

* UIProcess/API/C/WKPageGroup.h:
* UIProcess/API/Cocoa/WKUserContentController.mm:
(-[WKUserContentController _removeUserContentFilter:]):

* UIProcess/API/Cocoa/WKUserContentControllerPrivate.h:
* UIProcess/UserContent/WebUserContentControllerProxy.cpp:
(WebKit::WebUserContentControllerProxy::WebUserContentControllerProxy):
(WebKit::WebUserContentControllerProxy::addProcess):
(WebKit::WebUserContentControllerProxy::addUserContentFilter):
(WebKit::WebUserContentControllerProxy::removeUserContentFilter):
(WebKit::WebUserContentControllerProxy::removeAllUserContentFilters):
* UIProcess/UserContent/WebUserContentControllerProxy.h:

* UIProcess/WebPageGroup.cpp:
(WebKit::WebPageGroup::addUserContentFilter):
(WebKit::WebPageGroup::removeUserContentFilter):
* UIProcess/WebPageGroup.h:

* WebProcess/UserContent/WebUserContentController.cpp:
(WebKit::WebUserContentController::removeUserContentFilter):
* WebProcess/UserContent/WebUserContentController.h:
* WebProcess/UserContent/WebUserContentController.messages.in:

* WebProcess/WebPage/WebPageGroupProxy.cpp:
(WebKit::WebPageGroupProxy::WebPageGroupProxy):
(WebKit::WebPageGroupProxy::removeUserContentFilter):
* WebProcess/WebPage/WebPageGroupProxy.h:
* WebProcess/WebPage/WebPageGroupProxy.messages.in:

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

19 files changed:
Source/WebCore/ChangeLog
Source/WebCore/page/UserContentController.cpp
Source/WebCore/page/UserContentController.h
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPageGroupData.h
Source/WebKit2/UIProcess/API/C/WKPageGroup.cpp
Source/WebKit2/UIProcess/API/C/WKPageGroup.h
Source/WebKit2/UIProcess/API/Cocoa/WKUserContentController.mm
Source/WebKit2/UIProcess/API/Cocoa/WKUserContentControllerPrivate.h
Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.cpp
Source/WebKit2/UIProcess/UserContent/WebUserContentControllerProxy.h
Source/WebKit2/UIProcess/WebPageGroup.cpp
Source/WebKit2/UIProcess/WebPageGroup.h
Source/WebKit2/WebProcess/UserContent/WebUserContentController.cpp
Source/WebKit2/WebProcess/UserContent/WebUserContentController.h
Source/WebKit2/WebProcess/UserContent/WebUserContentController.messages.in
Source/WebKit2/WebProcess/WebPage/WebPageGroupProxy.cpp
Source/WebKit2/WebProcess/WebPage/WebPageGroupProxy.h
Source/WebKit2/WebProcess/WebPage/WebPageGroupProxy.messages.in

index 85a98f9..27dcc39 100644 (file)
@@ -1,3 +1,14 @@
+2015-02-27  Brady Eidson  <beidson@apple.com>
+
+        Add API to remove a single content filter.
+        <rdar://problem/19977764> and https://bugs.webkit.org/show_bug.cgi?id=142088
+
+        Reviewed by Sam Weinig.
+
+        * page/UserContentController.cpp:
+        (WebCore::UserContentController::removeUserContentFilter):
+        * page/UserContentController.h:
+
 2015-02-26  Brent Fulgham  <bfulgham@apple.com>
 
         [Win] Remove remaining SafariTheme cruft
index 788b849..f1b5a55 100644 (file)
@@ -187,6 +187,14 @@ void UserContentController::addUserContentFilter(const String& name, const Strin
     m_contentExtensionBackend->setRuleList(name, ContentExtensions::ExtensionsManager::createRuleList(ruleList));
 }
 
+void UserContentController::removeUserContentFilter(const String& name)
+{
+    if (!m_contentExtensionBackend)
+        return;
+
+    m_contentExtensionBackend->removeRuleList(name);
+}
+
 void UserContentController::removeAllUserContentFilters()
 {
     if (!m_contentExtensionBackend)
index c1d88dc..3dca718 100644 (file)
@@ -81,6 +81,7 @@ public:
 #if ENABLE(CONTENT_EXTENSIONS)
     // FIXME: This should really take a pointer to a compiled UserContentFilter.
     WEBCORE_EXPORT void addUserContentFilter(const String& name, const String& ruleList);
+    WEBCORE_EXPORT void removeUserContentFilter(const String& name);
     WEBCORE_EXPORT void removeAllUserContentFilters();
     
     // FIXME: Consider putting this (and other future content filter predicates) in its own class.
index feffbc1..f480296 100644 (file)
@@ -1,3 +1,44 @@
+2015-02-27  Brady Eidson  <beidson@apple.com>
+
+        Add API to remove a single content filter.
+        <rdar://problem/19977764> and https://bugs.webkit.org/show_bug.cgi?id=142088
+
+        Reviewed by Sam Weinig.
+
+        * Shared/WebPageGroupData.h:
+
+        * UIProcess/API/C/WKPageGroup.cpp:
+        (WKPageGroupRemoveUserContentFilter):
+
+        * UIProcess/API/C/WKPageGroup.h:
+        * UIProcess/API/Cocoa/WKUserContentController.mm:
+        (-[WKUserContentController _removeUserContentFilter:]):
+
+        * UIProcess/API/Cocoa/WKUserContentControllerPrivate.h:
+        * UIProcess/UserContent/WebUserContentControllerProxy.cpp:
+        (WebKit::WebUserContentControllerProxy::WebUserContentControllerProxy):
+        (WebKit::WebUserContentControllerProxy::addProcess):
+        (WebKit::WebUserContentControllerProxy::addUserContentFilter):
+        (WebKit::WebUserContentControllerProxy::removeUserContentFilter):
+        (WebKit::WebUserContentControllerProxy::removeAllUserContentFilters):
+        * UIProcess/UserContent/WebUserContentControllerProxy.h:
+
+        * UIProcess/WebPageGroup.cpp:
+        (WebKit::WebPageGroup::addUserContentFilter):
+        (WebKit::WebPageGroup::removeUserContentFilter):
+        * UIProcess/WebPageGroup.h:
+
+        * WebProcess/UserContent/WebUserContentController.cpp:
+        (WebKit::WebUserContentController::removeUserContentFilter):
+        * WebProcess/UserContent/WebUserContentController.h:
+        * WebProcess/UserContent/WebUserContentController.messages.in:
+
+        * WebProcess/WebPage/WebPageGroupProxy.cpp:
+        (WebKit::WebPageGroupProxy::WebPageGroupProxy):
+        (WebKit::WebPageGroupProxy::removeUserContentFilter):
+        * WebProcess/WebPage/WebPageGroupProxy.h:
+        * WebProcess/WebPage/WebPageGroupProxy.messages.in:
+
 2015-02-26  Anders Carlsson  <andersca@apple.com>
 
         Add API to remove all website data for the given data records
index fda3d50..a2e8f5d 100644 (file)
@@ -28,7 +28,8 @@
 
 #include <WebCore/UserScript.h>
 #include <WebCore/UserStyleSheet.h>
-#include <wtf/Vector.h>
+#include <wtf/HashMap.h>
+#include <wtf/text/StringHash.h>
 #include <wtf/text/WTFString.h>
 
 namespace IPC {
@@ -51,7 +52,7 @@ struct WebPageGroupData {
     Vector<WebCore::UserScript> userScripts;
 
 #if ENABLE(CONTENT_EXTENSIONS)
-    Vector<std::pair<String, String>> userContentFilters;
+    HashMap<String, String> userContentFilters;
 #endif
 };
 
index 350d5d7..52453c8 100644 (file)
@@ -89,6 +89,17 @@ void WKPageGroupAddUserContentFilter(WKPageGroupRef pageGroupRef, WKUserContentF
 #endif
 }
 
+void WKPageGroupRemoveUserContentFilter(WKPageGroupRef pageGroupRef, WKStringRef userContentFilterNameRef)
+{
+#if ENABLE(CONTENT_EXTENSIONS)
+    toImpl(pageGroupRef)->removeUserContentFilter(toWTFString(userContentFilterNameRef));
+#else
+    UNUSED_PARAM(pageGroupRef);
+    UNUSED_PARAM(userContentFilterNameRef);
+#endif
+}
+
+
 void WKPageGroupRemoveAllUserContentFilters(WKPageGroupRef pageGroupRef)
 {
 #if ENABLE(CONTENT_EXTENSIONS)
index 0cd87ea..b21455c 100644 (file)
@@ -50,6 +50,7 @@ WK_EXPORT void WKPageGroupAddUserScript(WKPageGroupRef pageGroup, WKStringRef so
 WK_EXPORT void WKPageGroupRemoveAllUserScripts(WKPageGroupRef pageGroup);
 
 WK_EXPORT void WKPageGroupAddUserContentFilter(WKPageGroupRef pageGroup, WKUserContentFilterRef userContentFilter);
+WK_EXPORT void WKPageGroupRemoveUserContentFilter(WKPageGroupRef pageGroup, WKStringRef userContentFilterName);
 WK_EXPORT void WKPageGroupRemoveAllUserContentFilters(WKPageGroupRef pageGroup);
 
 #ifdef __cplusplus
index 80abdd4..980bd02 100644 (file)
@@ -134,6 +134,13 @@ private:
 #endif
 }
 
+- (void)_removeUserContentFilter:(NSString *)userContentFilterName
+{
+#if ENABLE(CONTENT_EXTENSIONS)
+    _userContentControllerProxy->removeUserContentFilter(userContentFilterName);
+#endif
+}
+
 - (void)_removeAllUserContentFilters
 {
 #if ENABLE(CONTENT_EXTENSIONS)
index 732ad4a..627cc44 100644 (file)
@@ -32,6 +32,7 @@
 @interface WKUserContentController (WKPrivate)
 
 - (void)_addUserContentFilter:(_WKUserContentFilter *)userContentFilter WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+- (void)_removeUserContentFilter:(NSString *)userContentFilterName WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 - (void)_removeAllUserContentFilters WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
 
 @end
index 84bc41a..d5aac13 100644 (file)
@@ -51,9 +51,6 @@ static uint64_t generateIdentifier()
 WebUserContentControllerProxy::WebUserContentControllerProxy()
     : m_identifier(generateIdentifier())
     , m_userScripts(*API::Array::create())
-#if ENABLE(CONTENT_EXTENSIONS)
-    , m_userContentFilters(*API::Array::create())
-#endif
 {
 }
 
@@ -86,7 +83,7 @@ void WebUserContentControllerProxy::addProcess(WebProcessProxy& webProcessProxy)
 
 #if ENABLE(CONTENT_EXTENSIONS)
     Vector<std::pair<String, String>> userContentFilters;
-    for (const auto& userContentFilter : m_userContentFilters->elementsOfType<API::UserContentFilter>())
+    for (const auto& userContentFilter : m_userContentFilters.values())
         userContentFilters.append(std::make_pair(userContentFilter->name(), userContentFilter->serializedRules()));
     webProcessProxy.connection()->send(Messages::WebUserContentController::AddUserContentFilters(userContentFilters), m_identifier);
 #endif
@@ -187,7 +184,7 @@ void WebUserContentControllerProxy::didPostMessage(IPC::Connection& connection,
 #if ENABLE(CONTENT_EXTENSIONS)
 void WebUserContentControllerProxy::addUserContentFilter(API::UserContentFilter& userContentFilter)
 {
-    m_userContentFilters->elements().append(&userContentFilter);
+    m_userContentFilters.set(userContentFilter.name(), &userContentFilter);
 
     auto pair = std::make_pair(userContentFilter.name(), userContentFilter.serializedRules());
 
@@ -195,9 +192,17 @@ void WebUserContentControllerProxy::addUserContentFilter(API::UserContentFilter&
         process->connection()->send(Messages::WebUserContentController::AddUserContentFilters({ pair }), m_identifier);
 }
 
+void WebUserContentControllerProxy::removeUserContentFilter(const String& name)
+{
+    m_userContentFilters.remove(name);
+
+    for (WebProcessProxy* process : m_processes)
+        process->connection()->send(Messages::WebUserContentController::RemoveUserContentFilter(name), m_identifier);
+}
+
 void WebUserContentControllerProxy::removeAllUserContentFilters()
 {
-    m_userContentFilters->elements().clear();
+    m_userContentFilters.clear();
 
     for (WebProcessProxy* process : m_processes)
         process->connection()->send(Messages::WebUserContentController::RemoveAllUserContentFilters(), m_identifier);
index 825d696..6526ece 100644 (file)
@@ -35,6 +35,7 @@
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
+#include <wtf/text/StringHash.h>
 
 namespace API {
 class Array;
@@ -83,6 +84,7 @@ public:
 
 #if ENABLE(CONTENT_EXTENSIONS)
     void addUserContentFilter(API::UserContentFilter&);
+    void removeUserContentFilter(const String&);
     void removeAllUserContentFilters();
 #endif
 
@@ -99,7 +101,7 @@ private:
     HashMap<uint64_t, RefPtr<WebScriptMessageHandler>> m_scriptMessageHandlers;
 
 #if ENABLE(CONTENT_EXTENSIONS)
-    Ref<API::Array> m_userContentFilters;
+    HashMap<String, RefPtr<API::UserContentFilter>> m_userContentFilters;
 #endif
 };
 
index 5f5af0b..d7db0d8 100644 (file)
@@ -175,10 +175,16 @@ void WebPageGroup::removeAllUserContent()
 #if ENABLE(CONTENT_EXTENSIONS)
 void WebPageGroup::addUserContentFilter(const API::UserContentFilter& userContentFilter)
 {
-    m_data.userContentFilters.append(std::make_pair(userContentFilter.name(), userContentFilter.serializedRules()));
+    m_data.userContentFilters.set(userContentFilter.name(), userContentFilter.serializedRules());
     sendToAllProcessesInGroup(Messages::WebPageGroupProxy::AddUserContentFilter(userContentFilter.name(), userContentFilter.serializedRules()), m_data.pageGroupID);
 }
 
+void WebPageGroup::removeUserContentFilter(const String& contentFilterName)
+{
+    m_data.userContentFilters.remove(contentFilterName);
+    sendToAllProcessesInGroup(Messages::WebPageGroupProxy::RemoveUserContentFilter(contentFilterName), m_data.pageGroupID);
+}
+
 void WebPageGroup::removeAllUserContentFilters()
 {
     m_data.userContentFilters.clear();
index 8743a4f..748e117 100644 (file)
@@ -32,6 +32,7 @@
 #include "WebProcessProxy.h"
 #include <wtf/Forward.h>
 #include <wtf/HashSet.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebKit {
 
@@ -67,6 +68,7 @@ public:
 
 #if ENABLE(CONTENT_EXTENSIONS)
     void addUserContentFilter(const API::UserContentFilter&);
+    void removeUserContentFilter(const String&);
     void removeAllUserContentFilters();
 #endif
 
index 2360333..aa5e2dc 100644 (file)
@@ -187,6 +187,11 @@ void WebUserContentController::addUserContentFilters(const Vector<std::pair<Stri
         m_userContentController->addUserContentFilter(userContentFilter.first, userContentFilter.second);
 }
 
+void WebUserContentController::removeUserContentFilter(const String& name)
+{
+    m_userContentController->removeUserContentFilter(name);
+}
+
 void WebUserContentController::removeAllUserContentFilters()
 {
     m_userContentController->removeAllUserContentFilters();
index 4c20122..daa108d 100644 (file)
@@ -62,6 +62,7 @@ private:
 
 #if ENABLE(CONTENT_EXTENSIONS)
     void addUserContentFilters(const Vector<std::pair<String, String>>&);
+    void removeUserContentFilter(const String& name);
     void removeAllUserContentFilters();
 #endif
 
index d797f42..2c04af3 100644 (file)
@@ -35,6 +35,7 @@ messages -> WebUserContentController {
 
 #if ENABLE(CONTENT_EXTENSIONS)
     AddUserContentFilters(Vector<std::pair<String, String>> userContentFilters);
+    RemoveUserContentFilter(String name);
     RemoveAllUserContentFilters();
 #endif
 }
index ee2235a..3220007 100644 (file)
@@ -54,8 +54,8 @@ WebPageGroupProxy::WebPageGroupProxy(const WebPageGroupData& data)
         addUserScript(userScript);
 
 #if ENABLE(CONTENT_EXTENSIONS)
-    for (const auto& pair : data.userContentFilters)
-        addUserContentFilter(pair.first, pair.second);
+    for (const auto& slot : data.userContentFilters)
+        addUserContentFilter(slot.key, slot.value);
 #endif
 }
 
@@ -102,6 +102,11 @@ void WebPageGroupProxy::addUserContentFilter(const String& name, const String& s
     userContentController().addUserContentFilter(name, serializedRules);
 }
 
+void WebPageGroupProxy::removeUserContentFilter(const String& name)
+{
+    userContentController().removeUserContentFilter(name);
+}
+
 void WebPageGroupProxy::removeAllUserContentFilters()
 {
     userContentController().removeAllUserContentFilters();    
index 19aa04f..a627ed1 100644 (file)
@@ -65,6 +65,7 @@ public:
 
 #if ENABLE(CONTENT_EXTENSIONS)
     void addUserContentFilter(const String& name, const String& serializedRules);
+    void removeUserContentFilter(const String& name);
     void removeAllUserContentFilters();
 #endif
 
index 97292a4..4c6f3ea 100644 (file)
@@ -29,6 +29,7 @@ messages -> WebPageGroupProxy {
 
 #if ENABLE(CONTENT_EXTENSIONS)
     AddUserContentFilter(String name, String serializedRules);
+    RemoveUserContentFilter(String name);
     RemoveAllUserContentFilters();
 #endif
 }