WebKit Bugzilla
Attachment 361851 Details for
Bug 167941
: [WPE][GTK] Enable support for CONTENT_EXTENSIONS
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch v7
bug-167941-20190213012516.patch (text/plain), 74.63 KB, created by
Adrian Perez
on 2019-02-12 15:25:18 PST
(
hide
)
Description:
Patch v7
Filename:
MIME Type:
Creator:
Adrian Perez
Created:
2019-02-12 15:25:18 PST
Size:
74.63 KB
patch
obsolete
>Subversion Revision: 241299 >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 9282f081d742ed2e3a58cb3350b22f335bf24efd..92ee41840f91db44122ecd4f3c1e7912583668f5 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,70 @@ >+2019-02-12 Adrian Perez de Castro <aperez@igalia.com> >+ >+ [WPE][GTK] Enable support for CONTENT_EXTENSIONS >+ https://bugs.webkit.org/show_bug.cgi?id=167941 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Adds new API to manage a collection of content extensions on disk (including compilation >+ of new ones) using WebKitContentFilterManager; the associated WebKitUserContentFilter >+ type (which represents a compiled content extension); and the functions needed to enable >+ and disable them for a given WebKitUserContentManager. >+ >+ * PlatformGTK.cmake: Add WebKitContentFilterManager.h to the list of public API headers. >+ * PlatformWPE.cmake: Ditto. >+ * SourcesGTK.txt: Add WebKitContentFilterManager.cpp >+ * SourcesWPE.txt: Ditto. >+ * UIProcess/API/glib/WebKitContentFilterManager.cpp: Added. >+ (toGError): Utility function to convert content extension errors to GError. >+ (webkit_content_filter_manager_class_init): Added. >+ (webkit_content_filter_manager_new): Added. >+ (webkit_content_filter_manager_compile_string): Added. Utility function implemented in >+ terms of webkit_content_filter_manager_compile(). >+ (webkit_content_filter_manager_compile_string_finish): Added. Utility function implemented >+ in terms of webkit_content_filter_manager_compile_finish(). >+ (webkit_content_filter_manager_compile): Added. >+ (webkit_content_filter_manager_compile_finish): Added. >+ (webkit_content_filter_manager_remove): Added. >+ (webkit_content_filter_manager_remove_finish): Added. >+ (webkit_content_filter_manager_lookup): Added. >+ (webkit_content_filter_manager_lookup_finish): Added. >+ (webkit_content_filter_manager_fetch_identifiers): Added. >+ (webkit_content_filter_manager_fetch_identifiers_finish): Added. >+ * UIProcess/API/glib/WebKitError.cpp: Add definition of webkit_content_filter_error_quark(). >+ * UIProcess/API/glib/WebKitUserContent.cpp: Add WebKitUserContentFilter. >+ (_WebKitUserContentFilter::_WebKitUserContentFilter): Added. >+ (webkit_user_content_filter_ref): Added. >+ (webkit_user_content_filter_unref): Added. >+ (webkit_user_content_filter_get_identifier): Added. >+ (webkitUserContentFilterFromRuleList): Added. >+ (webkitUserContentFilterGetContentRuleList): Added. >+ * UIProcess/API/glib/WebKitUserContentManager.cpp: Add new API functions to add and >+ remove content filters. >+ (webkit_user_content_manager_add_filter): Added. >+ (webkit_user_content_manager_remove_filter): Added. >+ (webkit_user_content_manager_remove_all_filters): Added. >+ * UIProcess/API/glib/WebKitUserContentPrivate.h: Added declarations for >+ webkitUserContentFilterGetContentRuleList() and webkitUserContentFilterFromRuleList() >+ * UIProcess/API/gtk/WebKitAutocleanups.h: Added autocleanups for WebKitContentFilterManager >+ and WebKitUserContentFilter. >+ * UIProcess/API/gtk/WebKitContentFilterManager.h: Added. >+ * UIProcess/API/gtk/WebKitError.h: Added declarations for WEBKIT_CONTENT_FILTER_ERROR, >+ and the associated WebKitContentFilterError enum. >+ * UIProcess/API/gtk/WebKitUserContent.h: Added declarations for WebKitUserContentFilter, >+ its associated ref/unref functions, and webkit_user_content_filter_get_identifier(). >+ * UIProcess/API/gtk/WebKitUserContentManager.h: Added declarations for new API functions >+ which add and remove user content filters. >+ * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Added new API functions and types >+ to be included in the documentation. >+ * UIProcess/API/gtk/webkit2.h: Added inclusion of WebKitContentFilterManager.h >+ * UIProcess/API/wpe/WebKitContentFilterManager.h: Added. >+ * UIProcess/API/wpe/WebKitError.h: Same as for the GTK port header. >+ * UIProcess/API/wpe/WebKitUserContent.h: Same as for the GTK port header. >+ * UIProcess/API/wpe/WebKitUserContentManager.h: Same as for the GTK port header. >+ * UIProcess/API/wpe/docs/wpe-0.1-sections.txt: Added new API functions and types to >+ be included in the documentation. >+ * UIProcess/API/wpe/webkit.h: Added inclusion of WebKitContentFilterManager.h >+ > 2019-01-21 Adrian Perez de Castro <aperez@igalia.com> > > [GTK][WPE] Add content extensions support in WKTR and unskip layout tests >diff --git a/Source/WebKit/PlatformGTK.cmake b/Source/WebKit/PlatformGTK.cmake >index 634b0003d951e14879de2309977c763a8c4bda85..377c66033ce210ef46433c3951654f9e120c9611 100644 >--- a/Source/WebKit/PlatformGTK.cmake >+++ b/Source/WebKit/PlatformGTK.cmake >@@ -67,6 +67,7 @@ set(WebKit2GTK_INSTALLED_HEADERS > ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitBackForwardListItem.h > ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitColorChooserRequest.h > ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitCredential.h >+ ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitContentFilterManager.h > ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitContextMenu.h > ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitContextMenuActions.h > ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitContextMenuItem.h >diff --git a/Source/WebKit/PlatformWPE.cmake b/Source/WebKit/PlatformWPE.cmake >index 0fbe5e2542543c90f9c720614f5985e1b0e7f30a..53a90aaf00eefe12d9dfe405417afd6fda09a928 100644 >--- a/Source/WebKit/PlatformWPE.cmake >+++ b/Source/WebKit/PlatformWPE.cmake >@@ -96,6 +96,7 @@ set(WPE_API_INSTALLED_HEADERS > ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitBackForwardList.h > ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitBackForwardListItem.h > ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitCredential.h >+ ${WEBKIT_DIR}/UIProcess/API/gtk/WebKitContentFilterManager.h > ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitContextMenu.h > ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitContextMenuActions.h > ${WEBKIT_DIR}/UIProcess/API/wpe/WebKitContextMenuItem.h >diff --git a/Source/WebKit/SourcesGTK.txt b/Source/WebKit/SourcesGTK.txt >index 4829a9ff27237c4a49431cc344e9530d1a244f31..3c0edbc5ef539984ad9a9f6a14825bc051626b9c 100644 >--- a/Source/WebKit/SourcesGTK.txt >+++ b/Source/WebKit/SourcesGTK.txt >@@ -134,6 +134,7 @@ UIProcess/API/glib/WebKitAuthenticationRequest.cpp @no-unify > UIProcess/API/glib/WebKitAutomationSession.cpp @no-unify > UIProcess/API/glib/WebKitBackForwardList.cpp @no-unify > UIProcess/API/glib/WebKitBackForwardListItem.cpp @no-unify >+UIProcess/API/glib/WebKitContentFilterManager.cpp @no-unify > UIProcess/API/glib/WebKitContextMenuClient.cpp @no-unify > UIProcess/API/glib/WebKitCookieManager.cpp @no-unify > UIProcess/API/glib/WebKitCredential.cpp @no-unify >diff --git a/Source/WebKit/SourcesWPE.txt b/Source/WebKit/SourcesWPE.txt >index 5ce95833b6041261105d85481b41d099e2dbf26d..3ae05644452a222f7cb27a5b8653102f6b55b56d 100644 >--- a/Source/WebKit/SourcesWPE.txt >+++ b/Source/WebKit/SourcesWPE.txt >@@ -117,6 +117,7 @@ UIProcess/API/glib/WebKitAuthenticationRequest.cpp @no-unify > UIProcess/API/glib/WebKitAutomationSession.cpp @no-unify > UIProcess/API/glib/WebKitBackForwardList.cpp @no-unify > UIProcess/API/glib/WebKitBackForwardListItem.cpp @no-unify >+UIProcess/API/glib/WebKitContentFilterManager.cpp @no-unify > UIProcess/API/glib/WebKitContextMenuClient.cpp @no-unify > UIProcess/API/glib/WebKitCookieManager.cpp @no-unify > UIProcess/API/glib/WebKitCredential.cpp @no-unify >diff --git a/Source/WebKit/UIProcess/API/glib/WebKitContentFilterManager.cpp b/Source/WebKit/UIProcess/API/glib/WebKitContentFilterManager.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..c9b32c1c071bad8cadd3fb34ac6666233a08c2d6 >--- /dev/null >+++ b/Source/WebKit/UIProcess/API/glib/WebKitContentFilterManager.cpp >@@ -0,0 +1,365 @@ >+/* >+ * Copyright (C) 2018-2019 Igalia S.L. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "WebKitContentFilterManager.h" >+ >+#include "APIContentRuleList.h" >+#include "APIContentRuleListStore.h" >+#include "ContentExtensionError.h" >+#include "WebKitError.h" >+#include "WebKitUserContent.h" >+#include "WebKitUserContentPrivate.h" >+#include <wtf/CompletionHandler.h> >+#include <wtf/RefPtr.h> >+#include <wtf/glib/GRefPtr.h> >+#include <wtf/glib/WTFGType.h> >+ >+/** >+ * SECTION: WebKitContentFilterManager >+ * @Short_description: Handles compilation of content filters and their storage. >+ * @Title: WebKitContentFilterManager >+ * >+ * The WebKitContentFilterManager provides the means to compile >+ * [JSON rule sets](https://webkit.org/blog/3476/content-blockers-first-look/) into >+ * binary #WebKitUserContentFilter objects with webkit_content_filter_manager_compile(). >+ * >+ * Compiled filters are stored on disk, and functionality is provided to manage compiled >+ * filters: webkit_content_filter_manager_fetch_identifiers() can be used to retrieve the >+ * list of filters which have been previously compiled (and stored), >+ * webkit_content_filter_manager_lookup() can be used to retrieve a filter which has been >+ * previously compiled, and removed with webkit_content_filter_manager_remove(). >+ */ >+ >+static inline GError* >+toGError(WebKitContentFilterError code, const std::error_code error) >+{ >+ ASSERT(error); >+ ASSERT(error.category() == WebCore::ContentExtensions::contentExtensionErrorCategory()); >+ return g_error_new_literal(WEBKIT_CONTENT_FILTER_ERROR, code, error.message().c_str()); >+} >+ >+ >+struct _WebKitContentFilterManagerPrivate { >+ RefPtr<API::ContentRuleListStore> store; >+}; >+ >+ >+WEBKIT_DEFINE_TYPE(WebKitContentFilterManager, webkit_content_filter_manager, G_TYPE_OBJECT) >+ >+static void webkit_content_filter_manager_class_init(WebKitContentFilterManagerClass* klass) >+{ >+} >+ >+/** >+ * webkit_content_filter_manager_new: >+ * @storage_path: path where data for compiled filters will be stored on disk >+ * >+ * Create a new #WebKitContentFilterManager to manipulate and compile filters stored at @storage_path. >+ * >+ * Returns: (transfer full): a newly created #WebKitContentFilterManager >+ * >+ * Since: 2.24 >+ */ >+WebKitContentFilterManager* webkit_content_filter_manager_new(const gchar* path) >+{ >+ WebKitContentFilterManager* manager = WEBKIT_CONTENT_FILTER_MANAGER(g_object_new(WEBKIT_TYPE_CONTENT_FILTER_MANAGER, nullptr)); >+ manager->priv->store = path ? adoptRef(new API::ContentRuleListStore(String::fromUTF8(path), false)) : &API::ContentRuleListStore::defaultStore(false); >+ return manager; >+} >+ >+/** >+ * webkit_content_filter_manager_compile_string: >+ * @manager: a #WebKitContentFilterManager >+ * @identifier: a string used to identify the filter >+ * @json_source: a string containing the rule seet in JSON format >+ * @cancellable: (allow-none): a #GCancellable or %NULL to ignore >+ * @callback: (scope async): a #GAsyncReadyCallback to call when the compilation is completed >+ * @user_data: (closure): the data to pass to the callback function >+ * >+ * This is a convenience function which works in the same way as >+ * webkit_content_filter_manager_compile() and allows to easily compile the >+ * source JSON from a string. >+ * >+ * When the operation is finished, @callback will be invoked, which then can use >+ * webkit_content_filter_manager_compile_string_finish() to obtain the result of >+ * the compilation. >+ * >+ * Since: 2.24 >+ */ >+void webkit_content_filter_manager_compile_string(WebKitContentFilterManager* manager, const gchar* identifier, const gchar* jsonSource, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) >+{ >+ g_return_if_fail(WEBKIT_IS_CONTENT_FILTER_MANAGER(manager)); >+ g_return_if_fail(identifier); >+ g_return_if_fail(jsonSource); >+ g_return_if_fail(callback); >+ >+ GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new_static(jsonSource, strlen(jsonSource))); >+ webkit_content_filter_manager_compile(manager, identifier, bytes.get(), cancellable, callback, userData); >+} >+ >+/** >+ * webkit_content_filter_manager_compile_string_finish: >+ * @manager: a #WebKitContentFilterManager >+ * @result: a #GAsyncResult >+ * @error: return location for error or %NULL to ignore >+ * >+ * Finishes an asynchronous filter compilation previously started with >+ * webkit_content_filter_manager_compile_string(). >+ * >+ * Returns: (transfer full): a #WebKitUserContentFilter, or %NULL if compilation failed >+ * >+ * Since: 2.24 >+ */ >+WebKitUserContentFilter* webkit_content_filter_manager_compile_string_finish(WebKitContentFilterManager* manager, GAsyncResult* result, GError** error) >+{ >+ g_return_val_if_fail(WEBKIT_IS_CONTENT_FILTER_MANAGER(manager), nullptr); >+ g_return_val_if_fail(result, nullptr); >+ return webkit_content_filter_manager_compile_finish(manager, result, error); >+} >+ >+/** >+ * webkit_content_filter_manager_compile: >+ * @manager: a #WebKitContentFilterManager >+ * @identifier: a string used to identify the filter >+ * @json_source: #GBytes containing the rule set in JSON format >+ * @cancellable: (allow-none): a #GCancellable or %NULL to ignore >+ * @callback: (scope async): a #GAsyncReadyCallback to call when the compilation is completed >+ * @user_data: (closure): the data to pass to the callback function >+ * >+ * Asynchronously compile a content filter from a source rule set in the >+ * [WebKit content extesions JSON format](https://webkit.org/blog/3476/content-blockers-first-look/). >+ * >+ * The @identifier can be used afterwards to refer to the filter when using >+ * webkit_content_filter_manager_remove() and webkit_content_filter_manager_lookup(). >+ * When the @identifier has been used in the past, the newly compiled filter will replace >+ * the one compiled beforehand. >+ * >+ * When the operation is finished, @callback will be invoked, which then can use >+ * webkit_content_filter_manager_compile_finish() to obtain the result of the compilation. >+ * >+ * Since: 2.24 >+ */ >+void webkit_content_filter_manager_compile(WebKitContentFilterManager* manager, const gchar* identifier, GBytes* jsonSource, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) >+{ >+ g_return_if_fail(WEBKIT_IS_CONTENT_FILTER_MANAGER(manager)); >+ g_return_if_fail(identifier); >+ g_return_if_fail(jsonSource); >+ g_return_if_fail(callback); >+ >+ GRefPtr<GTask> task = adoptGRef(g_task_new(manager, cancellable, callback, userData)); >+ auto jsonString = String::fromUTF8(static_cast<const char*>(g_bytes_get_data(jsonSource, nullptr)) ? : "", g_bytes_get_size(jsonSource)); >+ manager->priv->store->compileContentRuleList(String::fromUTF8(identifier), WTFMove(jsonString), [task = WTFMove(task)](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) { >+ if (g_task_return_error_if_cancelled(task.get())) >+ return; >+ >+ if (error) >+ g_task_return_error(task.get(), toGError(WEBKIT_CONTENT_FILTER_ERROR_INVALID_JSON, error)); >+ else >+ g_task_return_pointer(task.get(), webkitUserContentFilterFromRuleList(WTFMove(contentRuleList)), reinterpret_cast<GDestroyNotify>(webkit_user_content_filter_unref)); >+ }); >+} >+ >+/** >+ * webkit_content_filter_manager_compile_finish: >+ * @manager: a #WebKitContentFilterManager >+ * @result: a #GAsyncResult >+ * @error: return location for error or %NULL to ignore >+ * >+ * Finishes an asynchronous filter compilation previously started with >+ * webkit_content_filter_manager_compile(). >+ * >+ * Returns: (transfer full): a #WebKitUserContentFilter, or %NULL if compilation failed >+ * >+ * Since: 2.24 >+ */ >+WebKitUserContentFilter* webkit_content_filter_manager_compile_finish(WebKitContentFilterManager* manager, GAsyncResult* result, GError** error) >+{ >+ g_return_val_if_fail(WEBKIT_IS_CONTENT_FILTER_MANAGER(manager), nullptr); >+ g_return_val_if_fail(result, nullptr); >+ return static_cast<WebKitUserContentFilter*>(g_task_propagate_pointer(G_TASK(result), error)); >+} >+ >+/** >+ * webkit_content_filter_manager_remove: >+ * @manager: a #WebKitContentFilterManager >+ * @identifier: a filter identifier >+ * @cancellable: (allow-none): a #GCancellable or %NULL to ignore >+ * @callback: (scope async): a #GAsyncReadyCallback to call when the removal is completed >+ * @user_data: (closure): the data to pass to the callback function >+ * >+ * Asynchronously remove a content filter given its @identifier. >+ * >+ * When the operation is finished, @callback will be invoked, which then can use >+ * webkit_content_filter_manager_remove_finish() to check whether the removal was >+ * successful. >+ * >+ * Since: 2.24 >+ */ >+void webkit_content_filter_manager_remove(WebKitContentFilterManager* manager, const gchar* identifier, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) >+{ >+ g_return_if_fail(WEBKIT_IS_CONTENT_FILTER_MANAGER(manager)); >+ g_return_if_fail(identifier); >+ g_return_if_fail(callback); >+ >+ GRefPtr<GTask> task = adoptGRef(g_task_new(manager, cancellable, callback, userData)); >+ manager->priv->store->removeContentRuleList(String::fromUTF8(identifier), [task = WTFMove(task)](std::error_code error) { >+ if (g_task_return_error_if_cancelled(task.get())) >+ return; >+ >+ if (error) { >+ ASSERT(static_cast<API::ContentRuleListStore::Error>(error.value()) == API::ContentRuleListStore::Error::RemoveFailed); >+ g_task_return_error(task.get(), toGError(WEBKIT_CONTENT_FILTER_ERROR_NOT_FOUND, error)); >+ } else >+ g_task_return_boolean(task.get(), TRUE); >+ }); >+} >+ >+/** >+ * webkit_content_filter_manager_remove_finish: >+ * @manager: a #WebKitContentFilterManager >+ * @result: a #GAsyncResult >+ * @error: return location for error or %NULL to ignore >+ * >+ * Finishes an asynchronous filter removal previously started with >+ * webkit_content_filter_manager_remove(). >+ * >+ * Returns: whether the removal was successful >+ * >+ * Since: 2.24 >+ */ >+gboolean webkit_content_filter_manager_remove_finish(WebKitContentFilterManager* manager, GAsyncResult* result, GError** error) >+{ >+ g_return_val_if_fail(WEBKIT_IS_CONTENT_FILTER_MANAGER(manager), FALSE); >+ g_return_val_if_fail(result, FALSE); >+ return g_task_propagate_boolean(G_TASK(result), error); >+} >+ >+/** >+ * webkit_content_filter_manager_lookup: >+ * @manager: a #WebKitContentFilterManager >+ * @identifier: a filter identifier >+ * @cancellable: (allow-none): a #GCancellable or %NULL to ignore >+ * @callback: (scope async): a #GAsyncReadyCallback to call when the removal is completed >+ * @user_data: (closure): the data to pass to the callback function >+ * >+ * Asynchronously lookup a content filter given its @identifier. >+ * >+ * When the operation is finished, @callback will be invoked, which then can use >+ * webkit_content_filter_manager_lookup_finish() to obtain the resulting filter. >+ * >+ * Since: 2.24 >+ */ >+void webkit_content_filter_manager_lookup(WebKitContentFilterManager* manager, const gchar* identifier, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) >+{ >+ g_return_if_fail(WEBKIT_IS_CONTENT_FILTER_MANAGER(manager)); >+ g_return_if_fail(identifier); >+ g_return_if_fail(callback); >+ >+ GRefPtr<GTask> task = adoptGRef(g_task_new(manager, cancellable, callback, userData)); >+ manager->priv->store->lookupContentRuleList(String::fromUTF8(identifier), [task = WTFMove(task)](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) { >+ if (g_task_return_error_if_cancelled(task.get())) >+ return; >+ >+ if (error) { >+ ASSERT(static_cast<API::ContentRuleListStore::Error>(error.value()) == API::ContentRuleListStore::Error::LookupFailed >+ || static_cast<API::ContentRuleListStore::Error>(error.value()) == API::ContentRuleListStore::Error::VersionMismatch); >+ g_task_return_error(task.get(), toGError(WEBKIT_CONTENT_FILTER_ERROR_NOT_FOUND, error)); >+ } else >+ g_task_return_pointer(task.get(), webkitUserContentFilterFromRuleList(WTFMove(contentRuleList)), reinterpret_cast<GDestroyNotify>(webkit_user_content_filter_unref)); >+ }); >+} >+ >+/** >+ * webkit_content_filter_manager_lookup_finish: >+ * @manager: a #WebKitContentFilterManager >+ * @result: a #GAsyncResult >+ * @error: return location for error or %NULL to ignore >+ * >+ * Finishes an asynchronous filter lookup previously started with >+ * webkit_content_filter_manager_lookup(). >+ * >+ * Returns: (transfer full): a #WebKitUserContentFilter, or %NULL if the lookup failed >+ * >+ * Since: 2.24 >+ */ >+WebKitUserContentFilter* webkit_content_filter_manager_lookup_finish(WebKitContentFilterManager* manager, GAsyncResult* result, GError** error) >+{ >+ g_return_val_if_fail(WEBKIT_IS_CONTENT_FILTER_MANAGER(manager), nullptr); >+ g_return_val_if_fail(result, nullptr); >+ return static_cast<WebKitUserContentFilter*>(g_task_propagate_pointer(G_TASK(result), error)); >+} >+ >+/** >+ * webkit_content_filter_manager_fetch_identifiers: >+ * @manager: a #WebKitContentFilterManager >+ * @cancellable: (allow-none): a #GCancellable or %NULL to ignore >+ * @callback: (scope async): a #GAsyncReadyCallback to call when the removal is completed >+ * @user_data: (closure): the data to pass to the callback function >+ * >+ * Asynchronously retrieve a list of the identifiers for all the stored filters. >+ * >+ * When the operation is finished, @callback will be invoked, which then can use >+ * webkit_content_filter_manager_fetch_identifiers_finish() to obtain the list of >+ * filter identifiers. >+ * >+ * Since: 2.24 >+ */ >+void webkit_content_filter_manager_fetch_identifiers(WebKitContentFilterManager* manager, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) >+{ >+ g_return_if_fail(WEBKIT_IS_CONTENT_FILTER_MANAGER(manager)); >+ g_return_if_fail(callback); >+ >+ GRefPtr<GTask> task = adoptGRef(g_task_new(manager, cancellable, callback, userData)); >+ manager->priv->store->getAvailableContentRuleListIdentifiers([task = WTFMove(task)](WTF::Vector<WTF::String> identifiers) { >+ if (g_task_return_error_if_cancelled(task.get())) >+ return; >+ >+ GStrv result = static_cast<GStrv>(g_new0(gchar*, identifiers.size() + 1)); >+ for (size_t i = 0; i < identifiers.size(); ++i) >+ result[i] = g_strdup(identifiers[i].utf8().data()); >+ result[identifiers.size()] = nullptr; >+ g_task_return_pointer(task.get(), result, reinterpret_cast<GDestroyNotify>(g_strfreev)); >+ }); >+} >+ >+/** >+ * webkit_content_filter_manager_fetch_identifiers_finish: >+ * @manager: a #WebKitContentFilterManager >+ * @result: a #GAsyncResult >+ * >+ * Finishes an asynchronous fetch of the list of identifiers for the stored filters previously >+ * started with webkit_content_filter_manager_fetch_identifiers(). >+ * >+ * Returns: (transfer full) (array zero-terminated=1) (element-type utf8): a %NULL-terminated list of filter identifiers. >+ * >+ * Since: 2.24 >+ */ >+gchar** webkit_content_filter_manager_fetch_identifiers_finish(WebKitContentFilterManager* manager, GAsyncResult* result) >+{ >+ g_return_val_if_fail(WEBKIT_IS_CONTENT_FILTER_MANAGER(manager), nullptr); >+ g_return_val_if_fail(result, nullptr); >+ return static_cast<gchar**>(g_task_propagate_pointer(G_TASK(result), nullptr)); >+} >diff --git a/Source/WebKit/UIProcess/API/glib/WebKitError.cpp b/Source/WebKit/UIProcess/API/glib/WebKitError.cpp >index ae9f74fc06018ef28b94f276805d5603d5ac7765..1398e7f16a8e1d082efe42e304a7dadb46be28a3 100644 >--- a/Source/WebKit/UIProcess/API/glib/WebKitError.cpp >+++ b/Source/WebKit/UIProcess/API/glib/WebKitError.cpp >@@ -71,3 +71,5 @@ GQuark webkit_snapshot_error_quark() > { > return g_quark_from_static_string("WebKitSnapshotError"); > } >+ >+G_DEFINE_QUARK(WebContentFilterError, webkit_content_filter_error) >diff --git a/Source/WebKit/UIProcess/API/glib/WebKitUserContent.cpp b/Source/WebKit/UIProcess/API/glib/WebKitUserContent.cpp >index acce07fa8c916faff0666213205af4023049d68c..c00a7953f9366ce403da0167d4c77f3b648b148c 100644 >--- a/Source/WebKit/UIProcess/API/glib/WebKitUserContent.cpp >+++ b/Source/WebKit/UIProcess/API/glib/WebKitUserContent.cpp >@@ -1,5 +1,5 @@ > /* >- * Copyright (C) 2014 Igalia S.L. >+ * Copyright (C) 2014, 2018-2019 Igalia S.L. > * > * This library is free software; you can redistribute it and/or > * modify it under the terms of the GNU Library General Public >@@ -317,3 +317,84 @@ API::UserScript& webkitUserScriptGetUserScript(WebKitUserScript* userScript) > { > return *userScript->userScript; > } >+ >+ >+struct _WebKitUserContentFilter { >+ _WebKitUserContentFilter(RefPtr<API::ContentRuleList>&& contentRuleList) >+ : contentRuleList(contentRuleList), referenceCount(1) >+ { >+ } >+ >+ RefPtr<API::ContentRuleList> contentRuleList; >+ int referenceCount; >+}; >+ >+G_DEFINE_BOXED_TYPE(WebKitUserContentFilter, webkit_user_content_filter, webkit_user_content_filter_ref, webkit_user_content_filter_unref) >+ >+/** >+ * webkit_user_content_filter_ref: >+ * @user_content_filter: A #WebKitUserContentFilter >+ * >+ * Atomically increments the reference count of @user_content_filter by one. >+ * This function is MT-safe and may be called from any thread. >+ * >+ * Since: 2.24 >+ */ >+WebKitUserContentFilter* webkit_user_content_filter_ref(WebKitUserContentFilter* userContentFilter) >+{ >+ g_return_val_if_fail(userContentFilter, nullptr); >+ g_atomic_int_inc(&userContentFilter->referenceCount); >+ return userContentFilter; >+} >+ >+/** >+ * webkit_user_content_filter_unref: >+ * @user_content_filter: A #WebKitUserContentFilter >+ * >+ * Atomically decrements the reference count of @user_content_filter by one. >+ * If the reference count drops to 0, all the memory allocated by the >+ * #WebKitUserContentFilter is released. This function is MT-safe and may >+ * be called from any thread. >+ * >+ * Since: 2.24 >+ */ >+void webkit_user_content_filter_unref(WebKitUserContentFilter* userContentFilter) >+{ >+ g_return_if_fail(userContentFilter); >+ if (g_atomic_int_dec_and_test(&userContentFilter->referenceCount)) { >+ userContentFilter->~WebKitUserContentFilter(); >+ fastFree(userContentFilter); >+ } >+} >+ >+/** >+ * webkit_user_content_filter_get_identifier: >+ * @user_content_filter: A #WebKitUserContentFilter >+ * >+ * Obtain the identifier passed to webkit_content_filter_manager_compile() >+ * when the @user_content_filter was compiled. >+ * @user_content_filter. >+ * >+ * Returns: (transfer none): the identifier for the filter >+ * >+ * Since: 2.24 >+ */ >+const char* >+webkit_user_content_filter_get_identifier(WebKitUserContentFilter* userContentFilter) >+{ >+ g_return_val_if_fail(userContentFilter, nullptr); >+ return userContentFilter->contentRuleList->name().utf8().data(); >+} >+ >+WebKitUserContentFilter* webkitUserContentFilterFromRuleList(RefPtr<API::ContentRuleList>&& contentRuleList) >+{ >+ WebKitUserContentFilter* userContentFilter = static_cast<WebKitUserContentFilter*>(fastMalloc(sizeof(WebKitUserContentFilter))); >+ new (userContentFilter) WebKitUserContentFilter(WTFMove(contentRuleList)); >+ return userContentFilter; >+} >+ >+API::ContentRuleList& webkitUserContentFilterGetContentRuleList(WebKitUserContentFilter* userContentFilter) >+{ >+ ASSERT(userContentFilter); >+ return *userContentFilter->contentRuleList; >+} >diff --git a/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp b/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp >index 7b0769470981c90cf29a305c3216525937af537b..5c8ad7ff7d0d376acb24c95842b48ad7e496efae 100644 >--- a/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp >+++ b/Source/WebKit/UIProcess/API/glib/WebKitUserContentManager.cpp >@@ -318,6 +318,48 @@ void webkit_user_content_manager_unregister_script_message_handler_in_world(WebK > manager->priv->userContentController->removeUserMessageHandlerForName(String::fromUTF8(name), webkitUserContentWorld(worldName)); > } > >+/** >+ * webkit_user_content_manager_add_filter: >+ * @manager: A #WebKitUserContentManager >+ * @filter: A #WebKitUserContentFilter >+ * >+ * Adds a #WebKitUserContentFilter to the given #WebKitUserContentManager. >+ * The same #WebKitUserContentFilter can be reused with multiple >+ * #WebKitUserContentManager instances. >+ * >+ * Filters need to be compiled from source or loaded from disk using a >+ * #WebKitContentFilterManager. >+ * >+ * Since: 2.24 >+ */ >+void webkit_user_content_manager_add_filter(WebKitUserContentManager* manager, WebKitUserContentFilter* filter) >+{ >+ g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); >+ g_return_if_fail(filter); >+ manager->priv->userContentController->addContentRuleList(webkitUserContentFilterGetContentRuleList(filter)); >+} >+ >+void webkit_user_content_manager_remove_filter(WebKitUserContentManager* manager, WebKitUserContentFilter* filter) >+{ >+ g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); >+ g_return_if_fail(filter); >+ manager->priv->userContentController->removeContentRuleList(webkitUserContentFilterGetContentRuleList(filter).name()); >+} >+ >+/** >+ * webkit_user_content_manager_remove_all_filters: >+ * @manager: A #WebKitUserContentManager >+ * >+ * Removes all content filters from the given #WebKitUserContentManager. >+ * >+ * Since: 2.24 >+ */ >+void webkit_user_content_manager_remove_all_filters(WebKitUserContentManager* manager) >+{ >+ g_return_if_fail(WEBKIT_IS_USER_CONTENT_MANAGER(manager)); >+ manager->priv->userContentController->removeAllContentRuleLists(); >+} >+ > WebUserContentControllerProxy* webkitUserContentManagerGetUserContentControllerProxy(WebKitUserContentManager* manager) > { > return manager->priv->userContentController.get(); >diff --git a/Source/WebKit/UIProcess/API/glib/WebKitUserContentPrivate.h b/Source/WebKit/UIProcess/API/glib/WebKitUserContentPrivate.h >index f181a294553cb28ff8dca95b4fc16aca88ce31b7..8c40d87036c3b3673504e8c974238228d4b4ecca 100644 >--- a/Source/WebKit/UIProcess/API/glib/WebKitUserContentPrivate.h >+++ b/Source/WebKit/UIProcess/API/glib/WebKitUserContentPrivate.h >@@ -1,5 +1,5 @@ > /* >- * Copyright (C) 2014 Igalia S.L. >+ * Copyright (C) 2014, 2018 Igalia S.L. > * > * This library is free software; you can redistribute it and/or > * modify it under the terms of the GNU Library General Public >@@ -20,6 +20,7 @@ > #ifndef WebKitUserContentPrivate_h > #define WebKitUserContentPrivate_h > >+#include "APIContentRuleList.h" > #include "APIUserContentWorld.h" > #include "APIUserScript.h" > #include "APIUserStyleSheet.h" >@@ -30,5 +31,7 @@ > API::UserScript& webkitUserScriptGetUserScript(WebKitUserScript*); > API::UserStyleSheet& webkitUserStyleSheetGetUserStyleSheet(WebKitUserStyleSheet*); > API::UserContentWorld& webkitUserContentWorld(const char*); >+API::ContentRuleList& webkitUserContentFilterGetContentRuleList(WebKitUserContentFilter*); >+WebKitUserContentFilter* webkitUserContentFilterFromRuleList(RefPtr<API::ContentRuleList>&&); > > #endif // WebKitUserContentPrivate_h >diff --git a/Source/WebKit/UIProcess/API/gtk/WebKitAutocleanups.h b/Source/WebKit/UIProcess/API/gtk/WebKitAutocleanups.h >index 8cc9f0f77622130342f70eab5f4bf2cf1ab7720f..ef769935c5f20cc8a80ae8158bb7be5af13bf49d 100644 >--- a/Source/WebKit/UIProcess/API/gtk/WebKitAutocleanups.h >+++ b/Source/WebKit/UIProcess/API/gtk/WebKitAutocleanups.h >@@ -38,6 +38,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitAutomationSession, g_object_unref) > G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitBackForwardList, g_object_unref) > G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitBackForwardListItem, g_object_unref) > G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitColorChooserRequest, g_object_unref) >+G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitContentFilterManager, g_object_unref) > G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitContextMenu, g_object_unref) > G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitContextMenuItem, g_object_unref) > G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitCookieManager, g_object_unref) >@@ -83,6 +84,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitNetworkProxySettings, webkit_network_proxy_ > G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitSecurityOrigin, webkit_security_origin_unref) > G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitUserScript, webkit_user_script_unref) > G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitUserStyleSheet, webkit_user_style_sheet_unref) >+G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitUserContentFilter, webkit_user_content_filter_unref) > G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitWebsiteData, webkit_website_data_unref) > G_DEFINE_AUTOPTR_CLEANUP_FUNC (WebKitWebViewSessionState, webkit_web_view_session_state_unref) > >diff --git a/Source/WebKit/UIProcess/API/gtk/WebKitContentFilterManager.h b/Source/WebKit/UIProcess/API/gtk/WebKitContentFilterManager.h >new file mode 100644 >index 0000000000000000000000000000000000000000..c2a123932b164a018942996379c252c78153b434 >--- /dev/null >+++ b/Source/WebKit/UIProcess/API/gtk/WebKitContentFilterManager.h >@@ -0,0 +1,137 @@ >+/* >+ * Copyright (C) 2018 Igalia S.L. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) >+#error "Only <webkit2/webkit2.h> can be included directly." >+#endif >+ >+#ifndef WebKitContentFilterManager_h >+#define WebKitContentFilterManager_h >+ >+#include <gio/gio.h> >+#include <webkit2/WebKitDefines.h> >+ >+G_BEGIN_DECLS >+ >+#define WEBKIT_TYPE_CONTENT_FILTER_MANAGER (webkit_content_filter_manager_get_type()) >+#define WEBKIT_CONTENT_FILTER_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_CONTENT_FILTER_MANAGER, WebKitContentFilterManager)) >+#define WEBKIT_IS_CONTENT_FILTER_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_CONTENT_FILTER_MANAGER)) >+#define WEBKIT_CONTENT_FILTER_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_CONTENT_FILTER_MANAGER, WebKitContentFilterManagerClass)) >+#define WEBKIT_IS_CONTENT_FILTER_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_CONTENT_FILTER_MANAGER)) >+#define WEBKIT_CONTENT_FILTER_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_CONTENT_FILTER_MANAGER, WebKitContentFilterManagerClass)) >+ >+typedef struct _WebKitContentFilterManager WebKitContentFilterManager; >+typedef struct _WebKitContentFilterManagerClass WebKitContentFilterManagerClass; >+typedef struct _WebKitContentFilterManagerPrivate WebKitContentFilterManagerPrivate; >+ >+typedef struct _WebKitUserContentFilter WebKitUserContentFilter; >+ >+struct _WebKitContentFilterManager { >+ GObject parent; >+ >+ /*< private >*/ >+ WebKitContentFilterManagerPrivate *priv; >+}; >+ >+struct _WebKitContentFilterManagerClass { >+ GObjectClass parent_class; >+ >+ void (*_webkit_reserved0) (void); >+ void (*_webkit_reserved1) (void); >+ void (*_webkit_reserved2) (void); >+ void (*_webkit_reserved3) (void); >+}; >+ >+ >+WEBKIT_API GType >+webkit_content_filter_manager_get_type (void); >+ >+WEBKIT_API WebKitContentFilterManager * >+webkit_content_filter_manager_new (const gchar *storage_path); >+ >+WEBKIT_API void >+webkit_content_filter_manager_compile (WebKitContentFilterManager *manager, >+ const gchar *identifier, >+ GBytes *json_source, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+ >+WEBKIT_API WebKitUserContentFilter * >+webkit_content_filter_manager_compile_finish (WebKitContentFilterManager *manager, >+ GAsyncResult *result, >+ GError **error); >+ >+WEBKIT_API void >+webkit_content_filter_manager_compile_string (WebKitContentFilterManager *manager, >+ const gchar *identifier, >+ const gchar *json_source, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+ >+WEBKIT_API WebKitUserContentFilter * >+webkit_content_filter_manager_compile_string_finish (WebKitContentFilterManager *manager, >+ GAsyncResult *result, >+ GError **error); >+ >+ >+WEBKIT_API void >+webkit_content_filter_manager_remove (WebKitContentFilterManager *manager, >+ const gchar *identifier, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+ >+WEBKIT_API gboolean >+webkit_content_filter_manager_remove_finish (WebKitContentFilterManager *manager, >+ GAsyncResult *result, >+ GError **error); >+ >+WEBKIT_API void >+webkit_content_filter_manager_lookup (WebKitContentFilterManager *manager, >+ const gchar *identifier, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+ >+WEBKIT_API WebKitUserContentFilter * >+webkit_content_filter_manager_lookup_finish (WebKitContentFilterManager *manager, >+ GAsyncResult *result, >+ GError **error); >+ >+WEBKIT_API void >+webkit_content_filter_manager_fetch_identifiers (WebKitContentFilterManager *manager, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+ >+WEBKIT_API gchar** >+webkit_content_filter_manager_fetch_identifiers_finish (WebKitContentFilterManager *manager, >+ GAsyncResult *result); >+ >+G_END_DECLS >+ >+#endif /* !WebKitContentFilterManager_h */ >diff --git a/Source/WebKit/UIProcess/API/gtk/WebKitError.h b/Source/WebKit/UIProcess/API/gtk/WebKitError.h >index 78b8ddcb8a7ca4fa271524e95692cfe2a5bbb874..7d4e63e2b40119515386278b061f3af0d716089e 100644 >--- a/Source/WebKit/UIProcess/API/gtk/WebKitError.h >+++ b/Source/WebKit/UIProcess/API/gtk/WebKitError.h >@@ -29,13 +29,14 @@ > > G_BEGIN_DECLS > >-#define WEBKIT_NETWORK_ERROR webkit_network_error_quark () >-#define WEBKIT_POLICY_ERROR webkit_policy_error_quark () >-#define WEBKIT_PLUGIN_ERROR webkit_plugin_error_quark () >-#define WEBKIT_DOWNLOAD_ERROR webkit_download_error_quark () >-#define WEBKIT_PRINT_ERROR webkit_print_error_quark () >-#define WEBKIT_JAVASCRIPT_ERROR webkit_javascript_error_quark () >-#define WEBKIT_SNAPSHOT_ERROR webkit_snapshot_error_quark () >+#define WEBKIT_NETWORK_ERROR webkit_network_error_quark () >+#define WEBKIT_POLICY_ERROR webkit_policy_error_quark () >+#define WEBKIT_PLUGIN_ERROR webkit_plugin_error_quark () >+#define WEBKIT_DOWNLOAD_ERROR webkit_download_error_quark () >+#define WEBKIT_PRINT_ERROR webkit_print_error_quark () >+#define WEBKIT_JAVASCRIPT_ERROR webkit_javascript_error_quark () >+#define WEBKIT_SNAPSHOT_ERROR webkit_snapshot_error_quark () >+#define WEBKIT_CONTENT_FILTER_ERROR webkit_content_filter_error_quark () > > /** > * WebKitNetworkError: >@@ -141,26 +142,41 @@ typedef enum { > WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE = 799 > } WebKitSnapshotError; > >+/** >+ * WebKitContentFilterError: >+ * @WEBKIT_CONTENT_FILTER_ERROR_INVALID_JSON: The JSON source for a content filter is invalid. >+ * @WEBKIT_CONTENT_FILTER_ERROR_NOT_FOUND: The requested content filter could not be found. >+ * >+ * Since: 2.24 >+ */ >+typedef enum { >+ WEBKIT_CONTENT_FILTER_ERROR_INVALID_JSON, >+ WEBKIT_CONTENT_FILTER_ERROR_NOT_FOUND, >+} WebKitContentFilterError; >+ >+WEBKIT_API GQuark >+webkit_network_error_quark (void); >+ > WEBKIT_API GQuark >-webkit_network_error_quark (void); >+webkit_policy_error_quark (void); > > WEBKIT_API GQuark >-webkit_policy_error_quark (void); >+webkit_plugin_error_quark (void); > > WEBKIT_API GQuark >-webkit_plugin_error_quark (void); >+webkit_download_error_quark (void); > > WEBKIT_API GQuark >-webkit_download_error_quark (void); >+webkit_print_error_quark (void); > > WEBKIT_API GQuark >-webkit_print_error_quark (void); >+webkit_javascript_error_quark (void); > > WEBKIT_API GQuark >-webkit_javascript_error_quark (void); >+webkit_snapshot_error_quark (void); > > WEBKIT_API GQuark >-webkit_snapshot_error_quark (void); >+webkit_content_filter_error_quark (void); > > G_END_DECLS > >diff --git a/Source/WebKit/UIProcess/API/gtk/WebKitUserContent.h b/Source/WebKit/UIProcess/API/gtk/WebKitUserContent.h >index 1dd450d0cb7290f25cbb4ce67a4a7ad1f1d3d1f3..2746e763f03a0803a72bbf7fda5bdda46edc6e52 100644 >--- a/Source/WebKit/UIProcess/API/gtk/WebKitUserContent.h >+++ b/Source/WebKit/UIProcess/API/gtk/WebKitUserContent.h >@@ -136,6 +136,22 @@ webkit_user_script_new_for_world (const gchar *source, > const gchar* const *whitelist, > const gchar* const *blacklist); > >+#define WEBKIT_TYPE_USER_CONTENT_FILTER (webkit_user_content_filter_get_type()) >+ >+typedef struct _WebKitUserContentFilter WebKitUserContentFilter; >+ >+WEBKIT_API GType >+webkit_user_content_filter_get_type (void); >+ >+WEBKIT_API const char* >+webkit_user_content_filter_get_identifier (WebKitUserContentFilter *user_content_filter); >+ >+WEBKIT_API WebKitUserContentFilter * >+webkit_user_content_filter_ref (WebKitUserContentFilter *user_content_filter); >+ >+WEBKIT_API void >+webkit_user_content_filter_unref (WebKitUserContentFilter *user_content_filter); >+ > G_END_DECLS > > #endif >diff --git a/Source/WebKit/UIProcess/API/gtk/WebKitUserContentManager.h b/Source/WebKit/UIProcess/API/gtk/WebKitUserContentManager.h >index ff505689323ab8b514ed387fcadbc3952fb313e5..1f41d1191386893f68ee865b40802316db810246 100644 >--- a/Source/WebKit/UIProcess/API/gtk/WebKitUserContentManager.h >+++ b/Source/WebKit/UIProcess/API/gtk/WebKitUserContentManager.h >@@ -93,6 +93,17 @@ webkit_user_content_manager_add_script (WebKitUs > WEBKIT_API void > webkit_user_content_manager_remove_all_scripts (WebKitUserContentManager *manager); > >+WEBKIT_API void >+webkit_user_content_manager_add_filter (WebKitUserContentManager *manager, >+ WebKitUserContentFilter *filter); >+ >+WEBKIT_API void >+webkit_user_content_manager_remove_filter (WebKitUserContentManager *manager, >+ WebKitUserContentFilter *filter); >+ >+WEBKIT_API void >+webkit_user_content_manager_remove_all_filters (WebKitUserContentManager *manager); >+ > G_END_DECLS > > #endif >diff --git a/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt b/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt >index 4efb952584672511ee95d062a96e7ff4ea33fb10..3035cb6039305511d14b7ce0242c959d281e8d8a 100644 >--- a/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt >+++ b/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt >@@ -96,6 +96,7 @@ WebKitUserScript > WebKitUserContentInjectedFrames > WebKitUserStyleLevel > WebKitUserScriptInjectionTime >+WebKitUserContentFilter > webkit_user_style_sheet_ref > webkit_user_style_sheet_unref > webkit_user_style_sheet_new >@@ -104,14 +105,19 @@ webkit_user_script_ref > webkit_user_script_unref > webkit_user_script_new > webkit_user_script_new_for_world >+webkit_user_content_filter_ref >+webkit_user_content_filter_unref >+webkit_user_content_filter_get_identifier > > <SUBSECTION Standard> > WEBKIT_TYPE_USER_STYLE_SHEET > WEBKIT_TYPE_USER_SCRIPT >+WEBKIT_TYPE_USER_CONTENT_FILTER > > <SUBSECTION Private> > webkit_user_style_sheet_get_type > webkit_user_script_get_type >+webkit_user_content_filter_get_type > </SECTION> > > <SECTION> >@@ -127,6 +133,9 @@ webkit_user_content_manager_register_script_message_handler > webkit_user_content_manager_unregister_script_message_handler > webkit_user_content_manager_register_script_message_handler_in_world > webkit_user_content_manager_unregister_script_message_handler_in_world >+webkit_user_content_manager_add_filter >+webkit_user_content_manager_remove_filter >+webkit_user_content_manager_remove_all_filters > > <SUBSECTION Standard> > WEBKIT_IS_USER_CONTENT_MANAGER >@@ -142,6 +151,36 @@ WebKitUserContentManagerPrivate > webkit_user_content_manager_get_type > </SECTION> > >+<SECTION> >+<FILE>WebKitContentFilterManager</FILE> >+<TITLE>WebKitContentFilterManager</TITLE> >+WebKitContentFilterManager >+webkit_content_filter_manager_new >+webkit_content_filter_manager_compile >+webkit_content_filter_manager_compile_finish >+webkit_content_filter_manager_compile_string >+webkit_content_filter_manager_compile_string_finish >+webkit_content_filter_manager_lookup >+webkit_content_filter_manager_lookup_finish >+webkit_content_filter_manager_remove >+webkit_content_filter_manager_remove_finish >+webkit_content_filter_manager_fetch_identifiers >+webkit_content_filter_manager_fetch_identifiers_finish >+ >+<SUBSECTION Standard> >+WEBKIT_IS_CONTENT_FILTER_MANAGER >+WEBKIT_IS_CONTENT_FILTER_MANAGER_CLASS >+WEBKIT_TYPE_CONTENT_FILTER_MANAGER >+WEBKIT_CONTENT_FILTER_MANAGER >+WEBKIT_CONTENT_FILTER_MANAGER_CLASS >+WEBKIT_CONTENT_FILTER_MANAGER_GET_CLASS >+WebKitContentFilterManagerClass >+ >+<SUBSECTION Private> >+WebKitContentFilterManagerPrivate >+webkit_content_filter_manager_get_type >+</SECTION> >+ > <SECTION> > <FILE>WebKitWebView</FILE> > <TITLE>WebKitWebView</TITLE> >@@ -944,6 +983,7 @@ WEBKIT_DOWNLOAD_ERROR > WEBKIT_PRINT_ERROR > WEBKIT_JAVASCRIPT_ERROR > WEBKIT_SNAPSHOT_ERROR >+WEBKIT_CONTENT_FILTER_ERROR > WebKitNetworkError > WebKitPluginError > WebKitPolicyError >@@ -951,6 +991,7 @@ WebKitDownloadError > WebKitPrintError > WebKitJavascriptError > WebKitSnapshotError >+WebKitContentFilterError > webkit_network_error_quark > webkit_plugin_error_quark > webkit_policy_error_quark >@@ -958,6 +999,7 @@ webkit_download_error_quark > webkit_print_error_quark > webkit_javascript_error_quark > webkit_snapshot_error_quark >+webkit_content_filter_error_quark > </SECTION> > > <SECTION> >diff --git a/Source/WebKit/UIProcess/API/gtk/webkit2.h b/Source/WebKit/UIProcess/API/gtk/webkit2.h >index 5c6e4ccec5aba1a29bae15561ac06102a6f0079e..15504d4975771d03d3174db13b531adc31e10484 100644 >--- a/Source/WebKit/UIProcess/API/gtk/webkit2.h >+++ b/Source/WebKit/UIProcess/API/gtk/webkit2.h >@@ -32,6 +32,7 @@ > #include <webkit2/WebKitAutomationSession.h> > #include <webkit2/WebKitBackForwardList.h> > #include <webkit2/WebKitBackForwardListItem.h> >+#include <webkit2/WebKitContentFilterManager.h> > #include <webkit2/WebKitContextMenu.h> > #include <webkit2/WebKitContextMenuActions.h> > #include <webkit2/WebKitContextMenuItem.h> >diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitContentFilterManager.h b/Source/WebKit/UIProcess/API/wpe/WebKitContentFilterManager.h >new file mode 100644 >index 0000000000000000000000000000000000000000..3b281049b3dcca62612e42ae860b49fba4f9faa1 >--- /dev/null >+++ b/Source/WebKit/UIProcess/API/wpe/WebKitContentFilterManager.h >@@ -0,0 +1,136 @@ >+/* >+ * Copyright (C) 2018 Igalia S.L. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#if !defined(__WEBKIT_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) >+#error "Only <wpe/webkit.h> can be included directly." >+#endif >+ >+#ifndef WebKitContentFilterManager_h >+#define WebKitContentFilterManager_h >+ >+#include <gio/gio.h> >+#include <wpe/WebKitDefines.h> >+ >+G_BEGIN_DECLS >+ >+#define WEBKIT_TYPE_CONTENT_FILTER_MANAGER (webkit_content_filter_manager_get_type()) >+#define WEBKIT_CONTENT_FILTER_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_CONTENT_FILTER_MANAGER, WebKitContentFilterManager)) >+#define WEBKIT_IS_CONTENT_FILTER_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_CONTENT_FILTER_MANAGER)) >+#define WEBKIT_CONTENT_FILTER_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_CONTENT_FILTER_MANAGER, WebKitContentFilterManagerClass)) >+#define WEBKIT_IS_CONTENT_FILTER_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_CONTENT_FILTER_MANAGER)) >+#define WEBKIT_CONTENT_FILTER_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_CONTENT_FILTER_MANAGER, WebKitContentFilterManagerClass)) >+ >+typedef struct _WebKitContentFilterManager WebKitContentFilterManager; >+typedef struct _WebKitContentFilterManagerClass WebKitContentFilterManagerClass; >+typedef struct _WebKitContentFilterManagerPrivate WebKitContentFilterManagerPrivate; >+ >+typedef struct _WebKitUserContentFilter WebKitUserContentFilter; >+ >+struct _WebKitContentFilterManager { >+ GObject parent; >+ >+ /*< private >*/ >+ WebKitContentFilterManagerPrivate *priv; >+}; >+ >+struct _WebKitContentFilterManagerClass { >+ GObjectClass parent_class; >+ >+ void (*_webkit_reserved0) (void); >+ void (*_webkit_reserved1) (void); >+ void (*_webkit_reserved2) (void); >+ void (*_webkit_reserved3) (void); >+}; >+ >+ >+WEBKIT_API GType >+webkit_content_filter_manager_get_type (void); >+ >+WEBKIT_API WebKitContentFilterManager * >+webkit_content_filter_manager_new (const gchar *storage_path); >+ >+WEBKIT_API void >+webkit_content_filter_manager_compile (WebKitContentFilterManager *manager, >+ const gchar *identifier, >+ GBytes *json_source, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+ >+WEBKIT_API WebKitUserContentFilter * >+webkit_content_filter_manager_compile_finish (WebKitContentFilterManager *manager, >+ GAsyncResult *result, >+ GError **error); >+ >+WEBKIT_API void >+webkit_content_filter_manager_compile_string (WebKitContentFilterManager *manager, >+ const gchar *identifier, >+ const gchar *json_source, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+ >+WEBKIT_API WebKitUserContentFilter * >+webkit_content_filter_manager_compile_string_finish (WebKitContentFilterManager *manager, >+ GAsyncResult *result, >+ GError **error); >+ >+WEBKIT_API void >+webkit_content_filter_manager_remove (WebKitContentFilterManager *manager, >+ const gchar *identifier, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+ >+WEBKIT_API gboolean >+webkit_content_filter_manager_remove_finish (WebKitContentFilterManager *manager, >+ GAsyncResult *result, >+ GError **error); >+ >+WEBKIT_API void >+webkit_content_filter_manager_lookup (WebKitContentFilterManager *manager, >+ const gchar *identifier, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+ >+WEBKIT_API WebKitUserContentFilter * >+webkit_content_filter_manager_lookup_finish (WebKitContentFilterManager *manager, >+ GAsyncResult *result, >+ GError **error); >+ >+WEBKIT_API void >+webkit_content_filter_manager_fetch_identifiers (WebKitContentFilterManager *manager, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+ >+WEBKIT_API gchar** >+webkit_content_filter_manager_fetch_identifiers_finish (WebKitContentFilterManager *manager, >+ GAsyncResult *result); >+ >+G_END_DECLS >+ >+#endif /* !WebKitContentFilterManager_h */ >diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitError.h b/Source/WebKit/UIProcess/API/wpe/WebKitError.h >index 4dad4ef3d1f7c3a6399cd50b6f213e91213fc814..d7022500347167a81fbe21a48cfcc1074f3fe819 100644 >--- a/Source/WebKit/UIProcess/API/wpe/WebKitError.h >+++ b/Source/WebKit/UIProcess/API/wpe/WebKitError.h >@@ -29,12 +29,13 @@ > > G_BEGIN_DECLS > >-#define WEBKIT_NETWORK_ERROR webkit_network_error_quark () >-#define WEBKIT_POLICY_ERROR webkit_policy_error_quark () >-#define WEBKIT_PLUGIN_ERROR webkit_plugin_error_quark () >-#define WEBKIT_DOWNLOAD_ERROR webkit_download_error_quark () >-#define WEBKIT_JAVASCRIPT_ERROR webkit_javascript_error_quark () >-#define WEBKIT_SNAPSHOT_ERROR webkit_snapshot_error_quark () >+#define WEBKIT_NETWORK_ERROR webkit_network_error_quark () >+#define WEBKIT_POLICY_ERROR webkit_policy_error_quark () >+#define WEBKIT_PLUGIN_ERROR webkit_plugin_error_quark () >+#define WEBKIT_DOWNLOAD_ERROR webkit_download_error_quark () >+#define WEBKIT_JAVASCRIPT_ERROR webkit_javascript_error_quark () >+#define WEBKIT_SNAPSHOT_ERROR webkit_snapshot_error_quark () >+#define WEBKIT_CONTENT_FILTER_ERROR webkit_content_filter_error_quark () > > /** > * WebKitNetworkError: >@@ -126,23 +127,38 @@ typedef enum { > WEBKIT_SNAPSHOT_ERROR_FAILED_TO_CREATE = 799 > } WebKitSnapshotError; > >+/** >+ * WebKitContentFilterError: >+ * @WEBKIT_CONTENT_FILTER_ERROR_INVALID_JSON: The JSON source for a content filter is invalid. >+ * @WEBKIT_CONTENT_FILTER_ERROR_NOT_FOUND: The requested content filter could not be found. >+ * >+ * Since: 2.24 >+ */ >+typedef enum { >+ WEBKIT_CONTENT_FILTER_ERROR_INVALID_JSON, >+ WEBKIT_CONTENT_FILTER_ERROR_NOT_FOUND, >+} WebKitContentFilterError; >+ >+WEBKIT_API GQuark >+webkit_network_error_quark (void); >+ > WEBKIT_API GQuark >-webkit_network_error_quark (void); >+webkit_policy_error_quark (void); > > WEBKIT_API GQuark >-webkit_policy_error_quark (void); >+webkit_plugin_error_quark (void); > > WEBKIT_API GQuark >-webkit_plugin_error_quark (void); >+webkit_download_error_quark (void); > > WEBKIT_API GQuark >-webkit_download_error_quark (void); >+webkit_javascript_error_quark (void); > > WEBKIT_API GQuark >-webkit_javascript_error_quark (void); >+webkit_snapshot_error_quark (void); > > WEBKIT_API GQuark >-webkit_snapshot_error_quark (void); >+webkit_content_filter_error_quark (void); > > G_END_DECLS > >diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitUserContent.h b/Source/WebKit/UIProcess/API/wpe/WebKitUserContent.h >index 926f98dc5ad899c33e3a134189f59b921d8e8f10..f28b99a1d547c764646d6a3b77149cfba5a7a771 100644 >--- a/Source/WebKit/UIProcess/API/wpe/WebKitUserContent.h >+++ b/Source/WebKit/UIProcess/API/wpe/WebKitUserContent.h >@@ -136,6 +136,22 @@ webkit_user_script_new_for_world (const gchar *source, > const gchar* const *whitelist, > const gchar* const *blacklist); > >+#define WEBKIT_TYPE_USER_CONTENT_FILTER (webkit_user_content_filter_get_type()) >+ >+typedef struct _WebKitUserContentFilter WebKitUserContentFilter; >+ >+WEBKIT_API GType >+webkit_user_content_filter_get_type (void); >+ >+WEBKIT_API const char* >+webkit_user_content_filter_get_identifier (WebKitUserContentFilter *user_content_filter); >+ >+WEBKIT_API WebKitUserContentFilter * >+webkit_user_content_filter_ref (WebKitUserContentFilter *user_content_filter); >+ >+WEBKIT_API void >+webkit_user_content_filter_unref (WebKitUserContentFilter *user_content_filter); >+ > G_END_DECLS > > #endif >diff --git a/Source/WebKit/UIProcess/API/wpe/WebKitUserContentManager.h b/Source/WebKit/UIProcess/API/wpe/WebKitUserContentManager.h >index 6513fa7b4235eebac361b94d65c68947d85916a3..12d7ede6ec468ed26ddb2689541f77e56abe77aa 100644 >--- a/Source/WebKit/UIProcess/API/wpe/WebKitUserContentManager.h >+++ b/Source/WebKit/UIProcess/API/wpe/WebKitUserContentManager.h >@@ -93,6 +93,17 @@ webkit_user_content_manager_add_script (WebKitUs > WEBKIT_API void > webkit_user_content_manager_remove_all_scripts (WebKitUserContentManager *manager); > >+WEBKIT_API void >+webkit_user_content_manager_add_filter (WebKitUserContentManager *manager, >+ WebKitUserContentFilter *filter); >+ >+WEBKIT_API void >+webkit_user_content_manager_remove_filter (WebKitUserContentManager *manager, >+ WebKitUserContentFilter *filter); >+ >+WEBKIT_API void >+webkit_user_content_manager_remove_all_filters (WebKitUserContentManager *manager); >+ > G_END_DECLS > > #endif >diff --git a/Source/WebKit/UIProcess/API/wpe/docs/wpe-0.1-sections.txt b/Source/WebKit/UIProcess/API/wpe/docs/wpe-0.1-sections.txt >index a5ecfe4637f8f3917af26127face01517f378806..9c41d5cd7e43a90b7b2c1d4a27c38e08a16c2ee2 100644 >--- a/Source/WebKit/UIProcess/API/wpe/docs/wpe-0.1-sections.txt >+++ b/Source/WebKit/UIProcess/API/wpe/docs/wpe-0.1-sections.txt >@@ -73,6 +73,7 @@ WebKitUserScript > WebKitUserContentInjectedFrames > WebKitUserStyleLevel > WebKitUserScriptInjectionTime >+WebKitUserContentFilter > webkit_user_style_sheet_ref > webkit_user_style_sheet_unref > webkit_user_style_sheet_new >@@ -81,14 +82,19 @@ webkit_user_script_ref > webkit_user_script_unref > webkit_user_script_new > webkit_user_script_new_for_world >+webkit_user_content_filter_ref >+webkit_user_content_filter_unref >+webkit_user_content_filter_get_identifier > > <SUBSECTION Standard> > WEBKIT_TYPE_USER_STYLE_SHEET > WEBKIT_TYPE_USER_SCRIPT >+WEBKIT_TYPE_USER_CONTENT_FILTER > > <SUBSECTION Private> > webkit_user_style_sheet_get_type > webkit_user_script_get_type >+webkit_user_content_filter_get_type > </SECTION> > > <SECTION> >@@ -104,6 +110,9 @@ webkit_user_content_manager_register_script_message_handler > webkit_user_content_manager_unregister_script_message_handler > webkit_user_content_manager_register_script_message_handler_in_world > webkit_user_content_manager_unregister_script_message_handler_in_world >+webkit_user_content_manager_add_filter >+webkit_user_content_manager_remove_filter >+webkit_user_content_manager_remove_all_filters > > <SUBSECTION Standard> > WEBKIT_IS_USER_CONTENT_MANAGER >@@ -119,6 +128,36 @@ WebKitUserContentManagerPrivate > webkit_user_content_manager_get_type > </SECTION> > >+<SECTION> >+<FILE>WebKitContentFilterManager</FILE> >+<TITLE>WebKitContentFilterManager</TITLE> >+WebKitContentFilterManager >+webkit_content_filter_manager_new >+webkit_content_filter_manager_compile >+webkit_content_filter_manager_compile_finish >+webkit_content_filter_manager_compile_string >+webkit_content_filter_manager_compile_string_finish >+webkit_content_filter_manager_lookup >+webkit_content_filter_manager_lookup_finish >+webkit_content_filter_manager_remove >+webkit_content_filter_manager_remove_finish >+webkit_content_filter_manager_fetch_identifiers >+webkit_content_filter_manager_fetch_identifiers_finish >+ >+<SUBSECTION Standard> >+WEBKIT_IS_CONTENT_FILTER_MANAGER >+WEBKIT_IS_CONTENT_FILTER_MANAGER_CLASS >+WEBKIT_TYPE_CONTENT_FILTER_MANAGER >+WEBKIT_CONTENT_FILTER_MANAGER >+WEBKIT_CONTENT_FILTER_MANAGER_CLASS >+WEBKIT_CONTENT_FILTER_MANAGER_GET_CLASS >+WebKitContentFilterManagerClass >+ >+<SUBSECTION Private> >+WebKitContentFilterManagerPrivate >+webkit_content_filter_manager_get_type >+</SECTION> >+ > <SECTION> > <FILE>WebKitWebView</FILE> > <TITLE>WebKitWebView</TITLE> >@@ -887,18 +926,21 @@ WEBKIT_POLICY_ERROR > WEBKIT_DOWNLOAD_ERROR > WEBKIT_JAVASCRIPT_ERROR > WEBKIT_SNAPSHOT_ERROR >+WEBKIT_CONTENT_FILTER_ERROR > WebKitNetworkError > WebKitPluginError > WebKitPolicyError > WebKitDownloadError > WebKitJavascriptError > WebKitSnapshotError >+WebKitContentFilterError > webkit_network_error_quark > webkit_plugin_error_quark > webkit_policy_error_quark > webkit_download_error_quark > webkit_javascript_error_quark > webkit_snapshot_error_quark >+webkit_content_filter_error_quark > </SECTION> > > <SECTION> >diff --git a/Source/WebKit/UIProcess/API/wpe/webkit.h b/Source/WebKit/UIProcess/API/wpe/webkit.h >index 9955a40f8fe56ddaaacc07d92925720635274c98..6629168f1bcea5e97387b1a1aa31c1eb32bca84b 100644 >--- a/Source/WebKit/UIProcess/API/wpe/webkit.h >+++ b/Source/WebKit/UIProcess/API/wpe/webkit.h >@@ -32,6 +32,7 @@ > #include <wpe/WebKitAutomationSession.h> > #include <wpe/WebKitBackForwardList.h> > #include <wpe/WebKitBackForwardListItem.h> >+#include <wpe/WebKitContentFilterManager.h> > #include <wpe/WebKitContextMenu.h> > #include <wpe/WebKitContextMenuActions.h> > #include <wpe/WebKitContextMenuItem.h> >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 0a26f30c77d7fea40d5921d766e598d15f04d329..29c03136c07b17cc952d0c89e1ab260bc4bd2e77 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,19 @@ >+2019-02-12 Adrian Perez de Castro <aperez@igalia.com> >+ >+ [WPE][GTK] Enable support for CONTENT_EXTENSIONS >+ https://bugs.webkit.org/show_bug.cgi?id=167941 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add support to load a JSON rule set file for content blocking. >+ >+ * MiniBrowser/gtk/main.c: >+ (filterCompiledCallback): Added. >+ (main): >+ * MiniBrowser/wpe/main.cpp: >+ (filterCompiledCallback): Added. >+ (main): >+ > 2019-01-21 Adrian Perez de Castro <aperez@igalia.com> > > [GTK][WPE] Add content extensions support in WKTR and unskip layout tests >diff --git a/Tools/MiniBrowser/gtk/main.c b/Tools/MiniBrowser/gtk/main.c >index afbe555ea5283bbb7c8743f4a3767f6e5cd1ee41..d57fb44cfd74fa3a28139ea6fb35c2fa8354d1db 100644 >--- a/Tools/MiniBrowser/gtk/main.c >+++ b/Tools/MiniBrowser/gtk/main.c >@@ -48,6 +48,7 @@ static gboolean privateMode; > static gboolean automationMode; > static gboolean fullScreen; > static gboolean ignoreTLSErrors; >+static const char *contentFilter; > static const char *cookiesFile; > static const char *cookiesPolicy; > static const char *proxy; >@@ -112,6 +113,7 @@ static const GOptionEntry commandLineOptions[] = > { "proxy", 0, 0, G_OPTION_ARG_STRING, &proxy, "Set proxy", "PROXY" }, > { "ignore-host", 0, 0, G_OPTION_ARG_STRING_ARRAY, &ignoreHosts, "Set proxy ignore hosts", "HOSTS" }, > { "ignore-tls-errors", 0, 0, G_OPTION_ARG_NONE, &ignoreTLSErrors, "Ignore TLS errors", NULL }, >+ { "content-filter", 0, 0, G_OPTION_ARG_STRING, &contentFilter, "JSON with content filtering rules", "FILE" }, > { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &uriArguments, 0, "[URLâ¦]" }, > { 0, 0, 0, 0, 0, 0, 0 } > }; >@@ -471,6 +473,23 @@ static void automationStartedCallback(WebKitWebContext *webContext, WebKitAutoma > g_signal_connect(session, "create-web-view", G_CALLBACK(createWebViewForAutomationCallback), NULL); > } > >+typedef struct { >+ GMainLoop *mainLoop; >+ WebKitUserContentFilter *filter; >+ GError *error; >+} FilterCompilationData; >+ >+static void >+filterCompiledCallback(WebKitContentFilterManager *filterManager, GAsyncResult *result, FilterCompilationData *data) >+{ >+ g_assert_nonnull(filterManager); >+ g_assert_nonnull(result); >+ g_assert_nonnull(data); >+ >+ data->filter = webkit_content_filter_manager_compile_finish(filterManager, result, &data->error); >+ g_main_loop_quit(data->mainLoop); >+} >+ > int main(int argc, char *argv[]) > { > #if ENABLE_DEVELOPER_MODE >@@ -539,6 +558,41 @@ int main(int argc, char *argv[]) > webkit_user_content_manager_register_script_message_handler(userContentManager, "aboutData"); > g_signal_connect(userContentManager, "script-message-received::aboutData", G_CALLBACK(aboutDataScriptMessageReceivedCallback), webContext); > >+ if (contentFilter) { >+ gchar *filtersPath; >+ WebKitContentFilterManager *filterManager; >+ FilterCompilationData compilationData = { NULL, NULL, NULL }; >+ gchar *contentFilterJSON = NULL; >+ GError *error = NULL; >+ >+ if (!g_file_get_contents(contentFilter, &contentFilterJSON, NULL, &error)) { >+ g_printerr("Cannot load '%s': %s.\n", contentFilter, error->message); >+ g_error_free(error); >+ return 1; >+ } >+ >+ filtersPath = g_build_filename(g_get_user_cache_dir(), g_get_prgname(), NULL); >+ filterManager = webkit_content_filter_manager_new(filtersPath); >+ g_free(filtersPath); >+ >+ webkit_content_filter_manager_compile_string(filterManager, "GTKMiniBrowserFilter", contentFilterJSON, NULL, (GAsyncReadyCallback) filterCompiledCallback, &compilationData); >+ g_free(contentFilterJSON); >+ >+ compilationData.mainLoop = g_main_loop_new(NULL, FALSE); >+ g_main_loop_run(compilationData.mainLoop); >+ g_main_loop_unref(compilationData.mainLoop); >+ g_object_unref(filterManager); >+ >+ if (!compilationData.filter) { >+ g_printerr("Cannot compile '%s': %s\n", contentFilter, compilationData.error->message); >+ g_error_free(compilationData.error); >+ return 1; >+ } >+ >+ webkit_user_content_manager_add_filter(userContentManager, compilationData.filter); >+ webkit_user_content_filter_unref(compilationData.filter); >+ } >+ > webkit_web_context_set_automation_allowed(webContext, automationMode); > g_signal_connect(webContext, "automation-started", G_CALLBACK(automationStartedCallback), NULL); > >diff --git a/Tools/MiniBrowser/wpe/main.cpp b/Tools/MiniBrowser/wpe/main.cpp >index 131a0f387090b347752408f9ea416dba180affaa..b0b0063eb0d33ca47d8d73c2bb66e621aad85ad1 100644 >--- a/Tools/MiniBrowser/wpe/main.cpp >+++ b/Tools/MiniBrowser/wpe/main.cpp >@@ -39,6 +39,7 @@ static gboolean headlessMode; > static gboolean privateMode; > static gboolean automationMode; > static gboolean ignoreTLSErrors; >+static const char* contentFilter; > static const char* cookiesFile; > static const char* cookiesPolicy; > static const char* proxy; >@@ -53,6 +54,7 @@ static const GOptionEntry commandLineOptions[] = > { "proxy", 0, 0, G_OPTION_ARG_STRING, &proxy, "Set proxy", "PROXY" }, > { "ignore-host", 0, 0, G_OPTION_ARG_STRING_ARRAY, &ignoreHosts, "Set proxy ignore hosts", "HOSTS" }, > { "ignore-tls-errors", 0, 0, G_OPTION_ARG_NONE, &ignoreTLSErrors, "Ignore TLS errors", nullptr }, >+ { "content-filter", 0, 0, G_OPTION_ARG_STRING, &contentFilter, "JSON with content filtering rules", "FILE" }, > { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &uriArguments, nullptr, "[URL]" }, > { nullptr, 0, 0, G_OPTION_ARG_NONE, nullptr, nullptr, nullptr } > }; >@@ -125,6 +127,23 @@ static std::unique_ptr<WPEToolingBackends::ViewBackend> createViewBackend(uint32 > return std::make_unique<WPEToolingBackends::WindowViewBackend>(width, height); > } > >+typedef struct { >+ GMainLoop* mainLoop { nullptr }; >+ WebKitUserContentFilter* filter { nullptr }; >+ GError* error { nullptr }; >+} FilterCompilationData; >+ >+static void >+filterCompiledCallback(WebKitContentFilterManager *filterManager, GAsyncResult *result, FilterCompilationData *data) >+{ >+ g_assert_nonnull(filterManager); >+ g_assert_nonnull(result); >+ g_assert_nonnull(data); >+ >+ data->filter = webkit_content_filter_manager_compile_finish(filterManager, result, &data->error); >+ g_main_loop_quit(data->mainLoop); >+} >+ > int main(int argc, char *argv[]) > { > #if ENABLE_DEVELOPER_MODE >@@ -184,6 +203,43 @@ int main(int argc, char *argv[]) > webkit_web_context_set_process_model(webContext, (singleprocess && *singleprocess) ? > WEBKIT_PROCESS_MODEL_SHARED_SECONDARY_PROCESS : WEBKIT_PROCESS_MODEL_MULTIPLE_SECONDARY_PROCESSES); > >+ WebKitUserContentManager* userContentManager = nullptr; >+ if (contentFilter) { >+ gchar* filtersPath; >+ WebKitContentFilterManager* filterManager; >+ FilterCompilationData compilationData; >+ gchar* contentFilterJSON = nullptr; >+ GError* error = nullptr; >+ >+ if (!g_file_get_contents(contentFilter, &contentFilterJSON, nullptr, &error)) { >+ g_printerr("Cannot load '%s': %s.\n", contentFilter, error->message); >+ g_error_free(error); >+ return 1; >+ } >+ >+ filtersPath = g_build_filename(g_get_user_cache_dir(), g_get_prgname(), nullptr); >+ filterManager = webkit_content_filter_manager_new(filtersPath); >+ g_free(filtersPath); >+ >+ webkit_content_filter_manager_compile_string(filterManager, "WPEMiniBrowserFilter", contentFilterJSON, nullptr, (GAsyncReadyCallback) filterCompiledCallback, &compilationData); >+ g_free(contentFilterJSON); >+ >+ compilationData.mainLoop = g_main_loop_new(NULL, FALSE); >+ g_main_loop_run(compilationData.mainLoop); >+ g_main_loop_unref(compilationData.mainLoop); >+ g_object_unref(filterManager); >+ >+ if (!compilationData.filter) { >+ g_printerr("Cannot compile '%s': %s\n", contentFilter, compilationData.error->message); >+ g_error_free(compilationData.error); >+ return 1; >+ } >+ >+ userContentManager = webkit_user_content_manager_new(); >+ webkit_user_content_manager_add_filter(userContentManager, compilationData.filter); >+ webkit_user_content_filter_unref(compilationData.filter); >+ } >+ > auto* settings = webkit_settings_new_with_settings( > "enable-developer-extras", TRUE, > "enable-webgl", TRUE, >@@ -200,6 +256,7 @@ int main(int argc, char *argv[]) > "backend", viewBackend, > "web-context", webContext, > "settings", settings, >+ "user-content-manager", userContentManager, > "is-controlled-by-automation", automationMode, > nullptr)); > g_object_unref(settings);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 167941
:
300813
|
300820
|
300823
|
300824
|
300826
|
300913
|
300918
|
301041
|
301050
|
301263
|
303066
|
303124
|
303125
|
357177
|
357215
|
359725
|
359895
|
359972
|
360918
|
361851
|
361875
|
361981
|
362081
|
362184
|
362334
|
362419
|
362488