WebKit Bugzilla
Attachment 359895 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]
WIP Patch v4
bug-167941-20190123193400.patch (text/plain), 64.04 KB, created by
Adrian Perez
on 2019-01-23 09:34:02 PST
(
hide
)
Description:
WIP Patch v4
Filename:
MIME Type:
Creator:
Adrian Perez
Created:
2019-01-23 09:34:02 PST
Size:
64.04 KB
patch
obsolete
>Subversion Revision: 240341 >diff --git a/Source/WebKit/PlatformGTK.cmake b/Source/WebKit/PlatformGTK.cmake >index 2281274cf0c252ace4ace2f9167e729585be6a99..f911545242704d5fe74d60570bed2db40bb5dec6 100644 >--- a/Source/WebKit/PlatformGTK.cmake >+++ b/Source/WebKit/PlatformGTK.cmake >@@ -63,6 +63,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 3c511ed0ba099fd53266a767c419538eef115092..f45875b7fc1212855ecb2d2fee38c39c3e8d97d7 100644 >--- a/Source/WebKit/PlatformWPE.cmake >+++ b/Source/WebKit/PlatformWPE.cmake >@@ -98,6 +98,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 aa43a049691562d166faea6a04efe3cddba97b75..4e8a921bd3630ff7c52c97e769653f65479dbb82 100644 >--- a/Source/WebKit/SourcesGTK.txt >+++ b/Source/WebKit/SourcesGTK.txt >@@ -131,6 +131,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 78f432301f6503c239c67a44b0eef5843b9f6b53..e9ac9524e775f6ba9cabeb03d455ffbd43208623 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..fb037beff9af647341afcdab690b78f9dc1ab398 >--- /dev/null >+++ b/Source/WebKit/UIProcess/API/glib/WebKitContentFilterManager.cpp >@@ -0,0 +1,298 @@ >+/* >+ * 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: >+ * @manager: a #WebKitContentFilterManager >+ * @identifier: a string using to identify the filter >+ * @json_source: the rule set in JSON format >+ * @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, const gchar* jsonSource, 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, nullptr, callback, userData)); >+ manager->priv->store->compileContentRuleList(String::fromUTF8(identifier), String::fromUTF8(jsonSource), [task = WTFMove(task)](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) { >+ if (error) >+ g_task_return_error(task.get(), toGError(WEBKIT_CONTENT_FILTER_ERROR_INVALID_JSON, error)); >+ else >+ g_task_return_pointer(task.get(), webkitUserContentFilterFromRuleList(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 >+ * @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, 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, nullptr, callback, userData)); >+ manager->priv->store->removeContentRuleList(String::fromUTF8(identifier), [task = WTFMove(task)](std::error_code error) { >+ 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 >+ * @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, 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, nullptr, callback, userData)); >+ manager->priv->store->lookupContentRuleList(String::fromUTF8(identifier), [task = WTFMove(task)](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) { >+ 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(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 >+ * @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, 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, nullptr, callback, userData)); >+ manager->priv->store->getAvailableContentRuleListIdentifiers([task = WTFMove(task)](WTF::Vector<WTF::String> identifiers) { >+ 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..ac747cfd1aefc7b9359c8f3f0ba9a89c4a7a1fa8 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(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..2e955fdf017b1b9171899c6432eb4ca4f467ac8f 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..a3fed415271b4ba9d9cca8e908d60e5e3ac1e261 100644 >--- a/Source/WebKit/UIProcess/API/gtk/WebKitAutocleanups.h >+++ b/Source/WebKit/UIProcess/API/gtk/WebKitAutocleanups.h >@@ -83,6 +83,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..418b970b851db7bcf364795c3f47d6231a648301 >--- /dev/null >+++ b/Source/WebKit/UIProcess/API/gtk/WebKitContentFilterManager.h >@@ -0,0 +1,119 @@ >+/* >+ * 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, >+ const gchar *json_source, >+ 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_remove (WebKitContentFilterManager *manager, >+ const gchar *identifier, >+ 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, >+ 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, >+ 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..2cd62b5a689a73ae99fc9e31809393b17809a4ee 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,39 @@ 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. >+ */ >+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 756aaa4de72da5bb73c70ffa0ce846afee4933ef..1ca189e92df5bd8c173d973a682fc9b590817451 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 >@@ -95,6 +95,7 @@ WebKitUserScript > WebKitUserContentInjectedFrames > WebKitUserStyleLevel > WebKitUserScriptInjectionTime >+WebKitUserContentFilter > webkit_user_style_sheet_ref > webkit_user_style_sheet_unref > webkit_user_style_sheet_new >@@ -103,14 +104,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> >@@ -126,6 +132,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 >@@ -141,6 +150,34 @@ 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_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> >@@ -939,6 +976,7 @@ WEBKIT_DOWNLOAD_ERROR > WEBKIT_PRINT_ERROR > WEBKIT_JAVASCRIPT_ERROR > WEBKIT_SNAPSHOT_ERROR >+WEBKIT_CONTENT_FILTER_ERROR > WebKitNetworkError > WebKitPluginError > WebKitPolicyError >@@ -946,6 +984,7 @@ WebKitDownloadError > WebKitPrintError > WebKitJavascriptError > WebKitSnapshotError >+WebKitContentFilterError > webkit_network_error_quark > webkit_plugin_error_quark > webkit_policy_error_quark >@@ -953,6 +992,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 b9c000970a04dcf3a7ff3014ea39e502af84f1c3..e963bb71d5eb4cdcfd96529aff5a712e55943645 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..1931abf6e086ec6e0d9768960eee2bf80fcbdb21 >--- /dev/null >+++ b/Source/WebKit/UIProcess/API/wpe/WebKitContentFilterManager.h >@@ -0,0 +1,119 @@ >+/* >+ * 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, >+ const gchar *json_source, >+ 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_remove (WebKitContentFilterManager *manager, >+ const gchar *identifier, >+ 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, >+ 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, >+ 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..4edefcd61c21659979a0ac778f388ed8012913b5 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,36 @@ 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. >+ */ >+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 628db4252a4d2bf48f490da54087ac4c2c95bc91..ac0fa216e74b6ea39000577c4f0befa66036a41d 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 >@@ -72,6 +72,7 @@ WebKitUserScript > WebKitUserContentInjectedFrames > WebKitUserStyleLevel > WebKitUserScriptInjectionTime >+WebKitUserContentFilter > webkit_user_style_sheet_ref > webkit_user_style_sheet_unref > webkit_user_style_sheet_new >@@ -80,14 +81,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> >@@ -103,6 +109,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 >@@ -118,6 +127,34 @@ 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_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> >@@ -884,18 +921,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 0f27191f669d83b85a98b5f2f113e9279f4ff969..603b2034f98eb460968b0d1516ff8509005581fd 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/Source/cmake/OptionsGTK.cmake b/Source/cmake/OptionsGTK.cmake >index b85b414427de963cc8964845cfc01ec2bdebd4ee..3e9ceb8ffb31fe37dc6f4d546074ead5a38cdf37 100644 >--- a/Source/cmake/OptionsGTK.cmake >+++ b/Source/cmake/OptionsGTK.cmake >@@ -149,6 +149,7 @@ WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_WEBDRIVER PUBLIC ON) > # Private options shared with other WebKit ports. Add options here when > # we need a value different from the default defined in WebKitFeatures.cmake. > # Changing these options is completely unsupported. >+WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CONTENT_EXTENSIONS PRIVATE ON) > WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_DOWNLOAD_ATTRIBUTE PRIVATE ON) > WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CONTENT_EXTENSIONS PRIVATE ON) > WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_ENCRYPTED_MEDIA PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES}) >diff --git a/Tools/MiniBrowser/gtk/main.c b/Tools/MiniBrowser/gtk/main.c >index afbe555ea5283bbb7c8743f4a3767f6e5cd1ee41..fd95186d52df46d2327d99614f097a209f4dd67e 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,40 @@ 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(filterManager, "GTKMiniBrowserFilter", contentFilterJSON, (GAsyncReadyCallback) filterCompiledCallback, &compilationData); >+ >+ 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 ed77528b2ceb2fd0c411bf6de26ef3e29a013558..63bd1bf1b23fd824dd5956160bc4e52861dd94d0 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 } > }; >@@ -108,6 +110,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 >@@ -173,6 +192,42 @@ 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(filterManager, "WPEMiniBrowserFilter", contentFilterJSON, (GAsyncReadyCallback) filterCompiledCallback, &compilationData); >+ >+ 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, >@@ -184,6 +239,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); >diff --git a/Tools/WebKitTestRunner/TestController.cpp b/Tools/WebKitTestRunner/TestController.cpp >index 82df68e414a1a706f08bb1bdd48f1e58ad3c681e..aaf5aa629e3aa5cc03ea8e7b08fa3fae91fab38e 100644 >--- a/Tools/WebKitTestRunner/TestController.cpp >+++ b/Tools/WebKitTestRunner/TestController.cpp >@@ -908,6 +908,9 @@ bool TestController::resetStateToConsistentValues(const TestOptions& options, Re > > WKPageClearUserMediaState(m_mainWebView->page()); > >+ // Reset content extensions. >+ resetContentExtensions(); >+ > // Reset notification permissions > m_webNotificationProvider.reset(); >
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