WebKit Bugzilla
Attachment 357177 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
bug-167941-20181213012550.patch (text/plain), 78.96 KB, created by
Adrian Perez
on 2018-12-12 15:25:51 PST
(
hide
)
Description:
WIP Patch
Filename:
MIME Type:
Creator:
Adrian Perez
Created:
2018-12-12 15:25:51 PST
Size:
78.96 KB
patch
obsolete
>Subversion Revision: 239103 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 78968cc908200dd880e5da90869b77c1c2283602..0c665600f647a6ef19c6232821b623a0d36b8613 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,15 @@ >+2018-12-12 Adrian Perez de Castro <aperez@igalia.com> >+ >+ [GTK] Enable CONTENT_EXTENSIONS and fix the build with it enabled >+ https://bugs.webkit.org/show_bug.cgi?id=167941 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ No new tests needed. >+ >+ * SourcesGTK.txt: Add sources needed for content extensions. >+ * SourcesWPE.txt: Add sources needed for content extensions. >+ > 2018-12-12 Carlos Garcia Campos <cgarcia@igalia.com> > > Unreviewed. Fix WPE build after r239101. >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index 3260d9aed2ab3b3897342eb0dc8ac661f7c051ce..6c6f5aae6413add08454e90b1bd3c257184dc035 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,81 @@ >+2018-12-12 Adrian Perez de Castro <aperez@igalia.com> >+ >+ [GTK] Enable CONTENT_EXTENSIONS and fix the build with it enabled >+ https://bugs.webkit.org/show_bug.cgi?id=167941 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Patch >+ >+ * NetworkProcess/cache/NetworkCacheData.h: >+ * NetworkProcess/cache/NetworkCacheDataSoup.cpp: >+ (WebKit::NetworkCache::adoptAndMapFile): Implement for file handles handles which wrap >+ GFileIOStream object, by extracting the Unix file descriptor from the GFileIOStream and >+ forwarding to the adoptAndMapFile() implementation which takes a file descriptor. >+ * PlatformGTK.cmake: List new WebKitContentFilterManager.h public API header. >+ * SourcesGTK.txt: Add sources to the list. >+ * SourcesWPE.txt: Ditto. >+ * UIProcess/API/APIContentRuleListStore.cpp: >+ (API::createExtension): Change usge of SharedMemory::create() to >+ NetworkCache::Data::tryCreateSharedMemory(), which always does the right thing. For the >+ Cocoa port it internally calls SharedMemory::create(), and for the ports using libsoup >+ it calls SharedMemory::wrapMap(). This is needed because SharedMemory::create() on >+ non-Cocoa ports creates a completely new and empty shared memory area of the given size, >+ but that is wrong because it does not match the Cocoa semantics, where it creates a >+ "submap" for the passed memory address, possibly of a different size than the original >+ mapping, pointing to the same physical memory pages (a "view" of another memory area). >+ * UIProcess/API/C/WKUserContentExtensionStoreRef.cpp: Add implementations for functions >+ that manipulate the content extensions in a store. >+ (WKUserContentExtensionStoreGetDefaultUserContentExtensionStore): >+ (WKUserContentExtensionStoreCreate): Added. >+ (toResult): Added. >+ (WKUserContentExtensionStoreCompileFilter): Added. >+ (WKUserContentExtensionStoreLookupFilter): Added. >+ (WKUserContentExtensionStoreRemoveFilter): Added. >+ * UIProcess/API/C/WKUserContentExtensionStoreRef.h: Add prototypes for the new functions >+ that manipulate the content extensions in a store. >+ * UIProcess/API/glib/APIContentRuleListStoreGLib.cpp: Added. >+ (API::ContentRuleListStore::defaultStorePath): Implement calculating the default location >+ for the compiled content extensions storage. >+ * UIProcess/API/glib/WebKitContentFilterManager.cpp: Added. >+ (toGError): >+ (webkit_content_filter_manager_class_init): >+ (webkit_content_filter_manager_new): >+ (webkit_content_filter_manager_compile): >+ (webkit_content_filter_manager_compile_finish): >+ (webkit_content_filter_manager_remove): >+ (webkit_content_filter_manager_remove_finish): >+ (webkit_content_filter_manager_lookup): >+ (webkit_content_filter_manager_lookup_finish): >+ (webkit_content_filter_manager_fetch_identifiers): >+ (webkit_content_filter_manager_fetch_identifiers_finish): >+ * UIProcess/API/glib/WebKitUserContent.cpp: Add a boxed type WebKitUserContentFilter which >+ wraps an API::ContentRuleList object. This is similar to how the WebKitUserScript and >+ WebKitUserStyleSheet types work in order to provide a similar API for the new >+ functionality. >+ (_WebKitUserContentFilter::_WebKitUserContentFilter): >+ (webkit_user_content_filter_ref): >+ (webkit_user_content_filter_unref): >+ (webkit_user_content_filter_get_name): >+ (webkitUserContentFilterFromRuleList): >+ (webkitUserContentFilterGetContentRuleList): >+ * UIProcess/API/glib/WebKitUserContentManager.cpp: Implement the new functions used to add >+ and remove WebKitUserContentFilter instances to the content manager. >+ (webkit_user_content_manager_add_filter): >+ (webkit_user_content_manager_remove_filter): >+ (webkit_user_content_manager_remove_all_filters): >+ * UIProcess/API/glib/WebKitUserContentPrivate.h: Add prototypes for functions used to wrap >+ and unwrap the API::ContentRuleList in WebKitUserContentFilter instances. >+ * UIProcess/API/gtk/WebKitContentFilterManager.h: Added. >+ * UIProcess/API/gtk/WebKitUserContent.h: Add new function prototypes. >+ * UIProcess/API/gtk/WebKitUserContentManager.h: Add new function prototypes. >+ * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: List new public API functions and types. >+ * UIProcess/API/gtk/webkit2.h: Add #include for the new WebKitContentFilterManager.h header. >+ * UIProcess/API/wpe/WebKitContentFilterManager.h: Added. >+ * UIProcess/API/wpe/WebKitUserContent.h: Add prototypes for new public API function and types. >+ * UIProcess/API/wpe/WebKitUserContentManager.h: Ditto. >+ * UIProcess/API/wpe/webkit.h: Add #include for the new WebKitContentFilterManager.h header. >+ > 2018-11-30 Carlos Garcia Campos <cgarcia@igalia.com> > > [WPE] Add API to notify about frame displayed view backend callback >diff --git a/Source/WebCore/SourcesGTK.txt b/Source/WebCore/SourcesGTK.txt >index 5e2356dbb66b2b052b69e4668a375dcfdd74b866..701b193401ac4ff40b764c822aa8462c41da7aa0 100644 >--- a/Source/WebCore/SourcesGTK.txt >+++ b/Source/WebCore/SourcesGTK.txt >@@ -41,6 +41,8 @@ accessibility/atk/WebKitAccessibleWrapperAtk.cpp > > editing/atk/FrameSelectionAtk.cpp > >+loader/ResourceLoadInfo.cpp >+ > loader/soup/ResourceLoaderSoup.cpp > > page/linux/ResourceUsageOverlayLinux.cpp >diff --git a/Source/WebCore/SourcesWPE.txt b/Source/WebCore/SourcesWPE.txt >index 381e585a17761a1f6073842e4cdc5953e28739ed..4d4ecd8f86487a95c9c4e955e3efa61c89b4b9a6 100644 >--- a/Source/WebCore/SourcesWPE.txt >+++ b/Source/WebCore/SourcesWPE.txt >@@ -26,6 +26,8 @@ accessibility/wpe/AccessibilityObjectWPE.cpp > > editing/libwpe/EditorLibWPE.cpp > >+loader/ResourceLoadInfo.cpp >+ > loader/soup/ResourceLoaderSoup.cpp > > page/linux/ResourceUsageOverlayLinux.cpp >diff --git a/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h b/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h >index 496108de63eb44de9f7ba58684efe2491da689bf..50c5264b0d597b5b5a601dbd0df17cc8f8be7a17 100644 >--- a/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h >+++ b/Source/WebKit/NetworkProcess/cache/NetworkCacheData.h >@@ -98,6 +98,9 @@ private: > Data concatenate(const Data&, const Data&); > bool bytesEqual(const Data&, const Data&); > Data adoptAndMapFile(int fd, size_t offset, size_t); >+#if PLATFORM(GTK) || PLATFORM(WPE) >+Data adoptAndMapFile(GFileIOStream*, size_t offset, size_t); >+#endif > Data mapFile(const char* path); > > using Salt = std::array<uint8_t, 8>; >diff --git a/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp b/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp >index 3ae8a6fa90c083601a614d429195928e9a3bb53f..adae356e86495cbc8b4c932408363de9ce8b7a13 100644 >--- a/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp >+++ b/Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp >@@ -33,6 +33,10 @@ > #include <sys/types.h> > #include <unistd.h> > >+#if PLATFORM(GTK) || PLATFORM(WPE) >+#include <gio/gfiledescriptorbased.h> >+#endif >+ > namespace WebKit { > namespace NetworkCache { > >@@ -126,6 +130,15 @@ Data Data::adoptMap(void* map, size_t size, int fd) > return { WTFMove(buffer), fd }; > } > >+#if PLATFORM(GTK) || PLATFORM(WPE) >+Data adoptAndMapFile(GFileIOStream* stream, size_t offset, size_t size) >+{ >+ GInputStream* inputStream = g_io_stream_get_input_stream(G_IO_STREAM(stream)); >+ int fd = g_file_descriptor_based_get_fd(G_FILE_DESCRIPTOR_BASED(inputStream)); >+ return adoptAndMapFile(fd, offset, size); >+} >+#endif >+ > RefPtr<SharedMemory> Data::tryCreateSharedMemory() const > { > if (isNull() || !isMap()) >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/SourcesGTK.txt b/Source/WebKit/SourcesGTK.txt >index 265384b641887537895d07f3ad5832944c01d291..aeca410d50fc12065466c341071754d1fa398828 100644 >--- a/Source/WebKit/SourcesGTK.txt >+++ b/Source/WebKit/SourcesGTK.txt >@@ -121,6 +121,7 @@ UIProcess/API/C/WKViewportAttributes.cpp > UIProcess/API/C/gtk/WKTextCheckerGtk.cpp > UIProcess/API/C/gtk/WKView.cpp > >+UIProcess/API/glib/APIContentRuleListStoreGLib.cpp @no-unify > UIProcess/API/glib/APIWebsiteDataStoreGLib.cpp @no-unify > UIProcess/API/glib/IconDatabase.cpp @no-unify > UIProcess/API/glib/WebKitApplicationInfo.cpp @no-unify >@@ -128,6 +129,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 8ee2fef42a6647859f35f8d34793af94a029393e..36b70310c1d2427b0d9524b6f4c2eb74bacd701d 100644 >--- a/Source/WebKit/SourcesWPE.txt >+++ b/Source/WebKit/SourcesWPE.txt >@@ -103,10 +103,12 @@ UIProcess/WebResourceLoadStatisticsTelemetry.cpp > UIProcess/WebViewportAttributes.cpp > > UIProcess/API/C/WKGrammarDetail.cpp >+UIProcess/API/C/WKUserContentExtensionStoreRef.cpp > UIProcess/API/C/WKViewportAttributes.cpp > > UIProcess/API/C/wpe/WKView.cpp > >+UIProcess/API/glib/APIContentRuleListStoreGLib.cpp @no-unify > UIProcess/API/glib/APIWebsiteDataStoreGLib.cpp @no-unify > UIProcess/API/glib/IconDatabase.cpp @no-unify > UIProcess/API/glib/WebKitApplicationInfo.cpp @no-unify >@@ -114,6 +116,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/APIContentRuleListStore.cpp b/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp >index 0778cd66bab8d8c1571c078658ab3b852316200b..8f0f598a4d2bc689bd42cd0a583ef9a2c34f8f59 100644 >--- a/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp >+++ b/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp >@@ -369,7 +369,7 @@ static std::error_code compiledToFile(WTF::String&& json, Vector<WebCore::Conten > > static Ref<API::ContentRuleList> createExtension(const WTF::String& identifier, const ContentRuleListMetaData& metaData, const WebKit::NetworkCache::Data& fileData) > { >- auto sharedMemory = WebKit::SharedMemory::create(const_cast<uint8_t*>(fileData.data()), fileData.size(), WebKit::SharedMemory::Protection::ReadOnly); >+ auto sharedMemory = fileData.tryCreateSharedMemory(); > const size_t headerAndSourceSize = ContentRuleListFileHeaderSize + metaData.sourceSize; > auto compiledContentRuleListData = WebKit::WebCompiledContentRuleListData( > WTFMove(sharedMemory), >diff --git a/Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp b/Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp >index 265c8dffdabfb01d3debb1ef2e52e374de079e12..d30f5f78a13bb980c68ca8084ee690b1a7b2c1bf 100644 >--- a/Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp >+++ b/Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp >@@ -1,4 +1,5 @@ > /* >+ * Copyright (C) 2018 Igalia S.L. All rights reserved. > * Copyright (C) 2015 Apple Inc. All rights reserved. > * > * Redistribution and use in source and binary forms, with or without >@@ -26,8 +27,11 @@ > #include "config.h" > #include "WKUserContentExtensionStoreRef.h" > >+#include "APIContentRuleList.h" > #include "APIContentRuleListStore.h" > #include "WKAPICast.h" >+#include "WKType.h" >+#include <wtf/Function.h> > > using namespace WebKit; > >@@ -39,3 +43,81 @@ WKTypeID WKUserContentExtensionStoreGetTypeID() > return 0; > #endif > } >+ >+WKUserContentExtensionStoreRef WKUserContentExtensionStoreGetDefaultUserContentExtensionStore(void) >+{ >+#if ENABLE(CONTENT_EXTENSIONS) >+ RefPtr<API::ContentRuleListStore> contentRuleListStore = adoptRef(API::ContentRuleListStore::defaultStore(false)); >+ return toAPI(contentRuleListStore.leakRef()); >+#else >+ return nullptr; >+#endif >+} >+ >+WKUserContentExtensionStoreRef WKUserContentExtensionStoreCreate(WKStringRef path) >+{ >+#if ENABLE(CONTENT_EXTENSIONS) >+ RefPtr<API::ContentRuleListStore> contentRuleListStore = adoptRef(new API::ContentRuleListStore(toWTFString(path), false)); >+ return toAPI(contentRuleListStore.leakRef()); >+#else >+ return nullptr; >+#endif >+} >+ >+#if ENABLE(CONTENT_EXTENSIONS) >+static inline WKUserContentExtensionStoreResult toResult(const std::error_code& error) >+{ >+ if (error) { >+ switch (static_cast<API::ContentRuleListStore::Error>(error.value())) { >+ case API::ContentRuleListStore::Error::LookupFailed: >+ return kWKUserContentExtensionStoreLookupFailed; >+ case API::ContentRuleListStore::Error::VersionMismatch: >+ return kWKUserContentExtensionStoreVersionMismatch; >+ case API::ContentRuleListStore::Error::CompileFailed: >+ return kWKUserContentExtensionStoreCompileFailed; >+ case API::ContentRuleListStore::Error::RemoveFailed: >+ return kWKUserContentExtensionStoreRemoveFailed; >+ } >+ } else >+ return kWKUserContentExtensionStoreSuccess; >+} >+#endif >+ >+void WKUserContentExtensionStoreCompileFilter(WKUserContentExtensionStoreRef userContentExtensionStore, WKStringRef identifier, WKStringRef jsonSource, void* context, WKUserContentExtensionStoreFilterFunction callback) >+{ >+#if ENABLE(CONTENT_EXTENSIONS) >+ WKRetain(identifier); >+ WKRetain(userContentExtensionStore); >+ toImpl(userContentExtensionStore)->compileContentRuleList(toWTFString(identifier), toWTFString(jsonSource), [=](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) { >+ callback(userContentExtensionStore, identifier, error ? nullptr : toAPI(contentRuleList.get()), toResult(error), context); >+ WKRelease(identifier); >+ WKRelease(userContentExtensionStore); >+ }); >+#endif >+} >+ >+void WKUserContentExtensionStoreLookupFilter(WKUserContentExtensionStoreRef userContentExtensionStore, WKStringRef identifier, void* context, WKUserContentExtensionStoreFilterFunction callback) >+{ >+#if ENABLE(CONTENT_EXTENSIONS) >+ WKRetain(identifier); >+ WKRetain(userContentExtensionStore); >+ toImpl(userContentExtensionStore)->lookupContentRuleList(toWTFString(identifier), [=](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) { >+ callback(userContentExtensionStore, identifier, error ? nullptr : toAPI(contentRuleList.get()), toResult(error), context); >+ WKRelease(identifier); >+ WKRelease(userContentExtensionStore); >+ }); >+#endif >+} >+ >+void WKUserContentExtensionStoreRemoveFilter(WKUserContentExtensionStoreRef userContentExtensionStore, WKStringRef identifier, void* context, WKUserContentExtensionStoreFilterFunction callback) >+{ >+#if ENABLE(CONTENT_EXTENSIONS) >+ WKRetain(identifier); >+ WKRetain(userContentExtensionStore); >+ toImpl(userContentExtensionStore)->removeContentRuleList(toWTFString(identifier), [=](std::error_code error) { >+ callback(userContentExtensionStore, identifier, nullptr, toResult(error), context); >+ WKRelease(identifier); >+ WKRelease(userContentExtensionStore); >+ }); >+#endif >+} >diff --git a/Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.h b/Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.h >index 53598ec809a72b7f63c93e82bd8ca28b4f9b5865..93b516803257c80021fbd99a14c1b0b39eafe8ed 100644 >--- a/Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.h >+++ b/Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.h >@@ -1,4 +1,5 @@ > /* >+ * Copyright (C) 2017 Igalia S.L. All rights reserved. > * Copyright (C) 2015 Apple Inc. All rights reserved. > * > * Redistribution and use in source and binary forms, with or without >@@ -34,6 +35,23 @@ extern "C" { > > WK_EXPORT WKTypeID WKUserContentExtensionStoreGetTypeID(); > >+WK_EXPORT WKUserContentExtensionStoreRef WKUserContentExtensionStoreGetDefaultUserContentExtensionStore(void); >+WK_EXPORT WKUserContentExtensionStoreRef WKUserContentExtensionStoreCreate(WKStringRef path); >+ >+enum { >+ kWKUserContentExtensionStoreSuccess = 0, >+ kWKUserContentExtensionStoreLookupFailed, >+ kWKUserContentExtensionStoreVersionMismatch, >+ kWKUserContentExtensionStoreCompileFailed, >+ kWKUserContentExtensionStoreRemoveFailed, >+}; >+typedef uint32_t WKUserContentExtensionStoreResult; >+ >+typedef void (*WKUserContentExtensionStoreFilterFunction)(WKUserContentExtensionStoreRef, WKStringRef, WKUserContentFilterRef, WKUserContentExtensionStoreResult, void*); >+WK_EXPORT void WKUserContentExtensionStoreCompileFilter(WKUserContentExtensionStoreRef userContentExtensionStore, WKStringRef identifier, WKStringRef jsonSource, void* context, WKUserContentExtensionStoreFilterFunction callback); >+WK_EXPORT void WKUserContentExtensionStoreLookupFilter(WKUserContentExtensionStoreRef userContentExtensionStore, WKStringRef identifier, void* context, WKUserContentExtensionStoreFilterFunction callback); >+WK_EXPORT void WKUserContentExtensionStoreRemoveFilter(WKUserContentExtensionStoreRef userContentExtensionStore, WKStringRef identifier, void* context, WKUserContentExtensionStoreFilterFunction callback); >+ > #ifdef __cplusplus > } > #endif >diff --git a/Source/WebKit/UIProcess/API/glib/APIContentRuleListStoreGLib.cpp b/Source/WebKit/UIProcess/API/glib/APIContentRuleListStoreGLib.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..b93a468fb737d4a6a1ae74b7152135b4d32b0d38 >--- /dev/null >+++ b/Source/WebKit/UIProcess/API/glib/APIContentRuleListStoreGLib.cpp >@@ -0,0 +1,40 @@ >+/* >+ * 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. >+ */ >+ >+#include "config.h" >+#include "APIContentRuleListStore.h" >+ >+#include <WebCore/FileSystem.h> >+#include <glib.h> >+ >+namespace API { >+ >+String ContentRuleListStore::defaultStorePath(bool) >+{ >+ const auto cacheDir = WebCore::FileSystem::pathByAppendingComponent(WebCore::FileSystem::stringFromFileSystemRepresentation(g_get_user_cache_dir()), g_get_prgname()); >+ return WebCore::FileSystem::pathByAppendingComponent(cacheDir, "ContentExtensions"); >+} >+ >+}; // namespace API >diff --git a/Source/WebKit/UIProcess/API/glib/WebKitContentFilterManager.cpp b/Source/WebKit/UIProcess/API/glib/WebKitContentFilterManager.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..b2e2c862f9421832e4af398ca0ebd97b3f278e81 >--- /dev/null >+++ b/Source/WebKit/UIProcess/API/glib/WebKitContentFilterManager.cpp >@@ -0,0 +1,236 @@ >+/* >+ * 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. >+ */ >+ >+#include "config.h" >+#include "WebKitContentFilterManager.h" >+ >+#include "ContentExtensionError.h" >+#include "APIContentRuleList.h" >+#include "APIContentRuleListStore.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> >+ >+ >+G_DEFINE_QUARK(WebContentFilterError, webkit_content_filter_error) >+ >+ >+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: >+ * >+ * Since: 2.24 >+ */ >+WebKitContentFilterManager* webkit_content_filter_manager_new(const char* 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: >+ * @json_source: >+ * @callback: >+ * @user_data: >+ * >+ * Since: 2.20 >+ */ >+void webkit_content_filter_manager_compile(WebKitContentFilterManager* manager, const char* identifier, const char* jsonSource, GAsyncReadyCallback callback, void* 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: >+ * @error: >+ * >+ * Since: 2.20 >+ */ >+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: >+ * @callback: >+ * @user_data: >+ * >+ * Since: 2.20 >+ */ >+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: >+ * @error: >+ * >+ * 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: >+ * @callback: >+ * @user_data: >+ * >+ * 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: >+ * @error: >+ * >+ * 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: >+ * @user_data: >+ * >+ * 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: >+ * >+ * Since: 2.24 >+ */ >+GStrv 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<GStrv>(g_task_propagate_pointer(G_TASK(result), nullptr)); >+} >diff --git a/Source/WebKit/UIProcess/API/glib/WebKitUserContent.cpp b/Source/WebKit/UIProcess/API/glib/WebKitUserContent.cpp >index acce07fa8c916faff0666213205af4023049d68c..56bab90935b1b0d19ab4a535810e8af24c44e90c 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, 2017, 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 >@@ -317,3 +317,79 @@ 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); >+ } >+} >+ >+/** >+ * @user_content_filter: A #WebKitUserContentFilter >+ * >+ * Obtain the name which identifies @user_content_filter. >+ * >+ * Since: 2.24 >+ */ >+const char* >+webkit_user_content_filter_get_name(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..80de8b51206b0a3e7dd9adca3050c1478b82d2c0 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 >@@ -24,11 +24,14 @@ > #include "APIUserScript.h" > #include "APIUserStyleSheet.h" > #include "WebKitUserContent.h" >+#include "APIContentRuleList.h" > #include <WebCore/UserScript.h> > #include <WebCore/UserStyleSheet.h> > > 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/WebKitContentFilterManager.h b/Source/WebKit/UIProcess/API/gtk/WebKitContentFilterManager.h >new file mode 100644 >index 0000000000000000000000000000000000000000..df4b0eb4501faf022ab531a2e3221639e5becb22 >--- /dev/null >+++ b/Source/WebKit/UIProcess/API/gtk/WebKitContentFilterManager.h >@@ -0,0 +1,132 @@ >+/* >+ * 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_CONTENT_FILTER_ERROR (webkit_content_filter_error_quark()) >+ >+/** >+ * 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; >+ >+ >+#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 GStrv >+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/WebKitUserContent.h b/Source/WebKit/UIProcess/API/gtk/WebKitUserContent.h >index 1dd450d0cb7290f25cbb4ce67a4a7ad1f1d3d1f3..d50e960b260bb6e27867d86023ddc49d244a6d9f 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_name (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..84fba00c4dab5f8b743c89f3a893b628bca7b159 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 >@@ -90,11 +90,14 @@ webkit_web_context_get_type > <SECTION> > <FILE>WebKitUserContent</FILE> > <TITLE>WebKitUserContent</TITLE> >+WebKitUserContentFilter > WebKitUserStyleSheet > WebKitUserScript > WebKitUserContentInjectedFrames > WebKitUserStyleLevel > WebKitUserScriptInjectionTime >+webkit_user_content_filter_ref >+webkit_user_content_filter_unref > webkit_user_style_sheet_ref > webkit_user_style_sheet_unref > webkit_user_style_sheet_new >@@ -105,14 +108,44 @@ webkit_user_script_new > webkit_user_script_new_for_world > > <SUBSECTION Standard> >+WEBKIT_TYPE_USER_CONTENT_FILTER > WEBKIT_TYPE_USER_STYLE_SHEET > WEBKIT_TYPE_USER_SCRIPT > > <SUBSECTION Private> >+webkit_user_content_filter_get_type > webkit_user_style_sheet_get_type > webkit_user_script_get_type > </SECTION> > >+<SECTION> >+<FILE>WebKitContentFilterManager</FILE> >+<TITLE>WebKitContentFilterManager</TITLE> >+WebKitContentFilterError >+WebKitContentFilterManager >+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_new >+webkit_content_filter_manager_remove >+webkit_content_filter_manager_remove_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>WebKitUserContentManager</FILE> > <TITLE>WebKitUserContentManager</TITLE> >@@ -939,6 +972,7 @@ WEBKIT_DOWNLOAD_ERROR > WEBKIT_PRINT_ERROR > WEBKIT_JAVASCRIPT_ERROR > WEBKIT_SNAPSHOT_ERROR >+WEBKIT_CONTENT_FILTER_ERROR > WebKitNetworkError > WebKitPluginError > WebKitPolicyError >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..86866b011aab1bc9b2507ccc2c8ce7456e157355 >--- /dev/null >+++ b/Source/WebKit/UIProcess/API/wpe/WebKitContentFilterManager.h >@@ -0,0 +1,132 @@ >+/* >+ * 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_CONTENT_FILTER_ERROR (webkit_content_filter_error_quark()) >+ >+/** >+ * 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; >+ >+ >+#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 GStrv >+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/WebKitUserContent.h b/Source/WebKit/UIProcess/API/wpe/WebKitUserContent.h >index 926f98dc5ad899c33e3a134189f59b921d8e8f10..10a4ccf9055f904782c3acbbd6cfb765ad065398 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_name (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/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 91b0936540979192c6cfdd11db04ab1ec4d4c89a..8048a775252e229884825bb4fe26bd3d9795a738 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_ENCRYPTED_MEDIA PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES}) > WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_FTPDIR PRIVATE OFF) >diff --git a/Source/cmake/OptionsWPE.cmake b/Source/cmake/OptionsWPE.cmake >index c7a259b99f54b77c9d5b0a1a6a1f63a91bb08f64..e096316276250c755cc6f03a28d67eb9186ac0a7 100644 >--- a/Source/cmake/OptionsWPE.cmake >+++ b/Source/cmake/OptionsWPE.cmake >@@ -29,6 +29,7 @@ WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_XSLT PUBLIC ON) > # we need a value different from the default defined in WebKitFeatures.cmake. > # Changing these options is completely unsupported. > WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_ASYNC_SCROLLING PRIVATE ON) >+WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CONTENT_EXTENSIONS PRIVATE ON) > WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_GEOLOCATION PRIVATE OFF) > WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MHTML PRIVATE ON) > WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_NETSCAPE_PLUGIN_API PRIVATE OFF) >diff --git a/Source/cmake/WebKitFeatures.cmake b/Source/cmake/WebKitFeatures.cmake >index 657ed0cfbf47f876614a75739a6c5f8ef02a8dcb..ae44a431145e10d7d467e2884cff811cfd7ca278 100644 >--- a/Source/cmake/WebKitFeatures.cmake >+++ b/Source/cmake/WebKitFeatures.cmake >@@ -96,6 +96,7 @@ macro(WEBKIT_OPTION_BEGIN) > WEBKIT_OPTION_DEFINE(ENABLE_BUBBLEWRAP_SANDBOX "Toggle Bubblewrap sandboxing support" PRIVATE OFF) > WEBKIT_OPTION_DEFINE(ENABLE_CACHE_PARTITIONING "Toggle cache partitioning support" PRIVATE OFF) > WEBKIT_OPTION_DEFINE(ENABLE_CHANNEL_MESSAGING "Toggle Channel Messaging support" PRIVATE ON) >+ WEBKIT_OPTION_DEFINE(ENABLE_CONTENT_EXTENSIONS "Toggle content extensions support" PRIVATE OFF) > WEBKIT_OPTION_DEFINE(ENABLE_CONTENT_FILTERING "Toggle content filtering support" PRIVATE OFF) > WEBKIT_OPTION_DEFINE(ENABLE_CONTEXT_MENUS "Toggle Context Menu support" PRIVATE ON) > WEBKIT_OPTION_DEFINE(ENABLE_CSS3_TEXT "Toggle CSS3 Text support" PRIVATE OFF) >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index e7df678569325f50af965b3480f126109a8c8da7..af94c6507c24d844429b0ba723ba90e8b1eebe04 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,29 @@ >+2018-12-12 Adrian Perez de Castro <aperez@igalia.com> >+ >+ [GTK] Enable CONTENT_EXTENSIONS and fix the build with it enabled >+ https://bugs.webkit.org/show_bug.cgi?id=167941 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * MiniBrowser/gtk/main.c: Add support for a --content-filter= command line option which >+ accepts the path to a JSON file containing a content extension rule set in source form. >+ (filterCompiledCallback): >+ (main): >+ * MiniBrowser/wpe/main.cpp: Ditto. >+ (filterCompiledCallback): >+ (main): >+ * WebKitTestRunner/TestController.cpp: WIP. Attempt at making WKTR support content >+ extensions. >+ (WTR::UserContentExtensionStoreResult::UserContentExtensionStoreResult): >+ (WTR::didUserContentExtensionStoreOperation): >+ (WTR::TestController::resetStateToConsistentValues): >+ (WTR::testURLPath): >+ (WTR::TestController::configureViewForTest): >+ (WTR::TestController::configureContentFilterForTest): >+ (WTR::TestController::resetContentFilters): >+ * WebKitTestRunner/TestController.h: >+ * WebKitTestRunner/cocoa/TestControllerCocoa.mm: >+ > 2018-11-30 Carlos Garcia Campos <cgarcia@igalia.com> > > [WPE] Add API to notify about frame displayed view backend callback >diff --git a/Tools/MiniBrowser/gtk/main.c b/Tools/MiniBrowser/gtk/main.c >index afbe555ea5283bbb7c8743f4a3767f6e5cd1ee41..c994c45c1fd95865fe56fd8ab9a7cc1aa87a21d5 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,35 @@ 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) { >+ 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; >+ } >+ >+ filterManager = webkit_content_filter_manager_new(NULL); >+ 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 e0c29b2129934371274a6f25451eae9821c4689f..38dc1025970f86ddda87ed83692af1981dee3d20 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; >+ 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 >@@ -173,6 +192,38 @@ 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) { >+ userContentManager = webkit_user_content_manager_new(); >+ >+ 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; >+ } >+ >+ filterManager = webkit_content_filter_manager_new(NULL); >+ 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; >+ } >+ >+ 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, >@@ -183,6 +234,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 0850558130bc5b76285afb8245a7fb8fe43c1f05..a65043f8ce646ac2856c7b8f031394025c3b0e81 100644 >--- a/Tools/WebKitTestRunner/TestController.cpp >+++ b/Tools/WebKitTestRunner/TestController.cpp >@@ -34,6 +34,7 @@ > #include "WebCoreTestSupport.h" > #include <JavaScriptCore/InitializeThreading.h> > #include <WebKit/WKArray.h> >+#include <WebKit/WKAPICast.h> > #include <WebKit/WKAuthenticationChallenge.h> > #include <WebKit/WKAuthenticationDecisionListener.h> > #include <WebKit/WKContextConfigurationRef.h> >@@ -60,6 +61,8 @@ > #include <WebKit/WKRetainPtr.h> > #include <WebKit/WKSecurityOriginRef.h> > #include <WebKit/WKTextChecker.h> >+#include <WebKit/WKUserContentControllerRef.h> >+#include <WebKit/WKUserContentExtensionStoreRef.h> > #include <WebKit/WKUserMediaPermissionCheck.h> > #include <WebKit/WKWebsiteDataStoreRef.h> > #include <algorithm> >@@ -709,6 +712,32 @@ void TestController::ensureViewSupportsOptionsForTest(const TestInvocation& test > TestInvocation::dumpWebProcessUnresponsiveness("<unknown> - TestController::run - Failed to reset state to consistent values\n"); > } > >+struct UserContentExtensionStoreResult { >+ UserContentExtensionStoreResult(WKRetainPtr<WKUserContentExtensionStoreRef>& store, WKRetainPtr<WKStringRef>& identifier) >+ : store(store) >+ , identifier(identifier) >+ { >+ } >+ >+ WKRetainPtr<WKUserContentExtensionStoreRef> store; >+ WKRetainPtr<WKStringRef> identifier; >+ WKUserContentExtensionStoreResult status { kWKUserContentExtensionStoreSuccess }; >+ WKRetainPtr<WKUserContentFilterRef> filter { nullptr }; >+ bool finished { false }; >+}; >+ >+static void didUserContentExtensionStoreOperation(WKUserContentExtensionStoreRef store, WKStringRef identifier, WKUserContentFilterRef filter, WKUserContentExtensionStoreResult status, void* context) >+{ >+ auto result = reinterpret_cast<UserContentExtensionStoreResult*>(context); >+ >+ ASSERT(WKStringIsEqual(identifier, result->identifier.get())); >+ ASSERT(store == result->store.get()); >+ >+ result->filter = adoptWK(filter); >+ result->status = status; >+ result->finished = true; >+} >+ > void TestController::resetPreferencesToConsistentValues(const TestOptions& options) > { > // Reset preferences >@@ -901,6 +930,9 @@ bool TestController::resetStateToConsistentValues(const TestOptions& options, Re > > WKPageClearUserMediaState(m_mainWebView->page()); > >+ // Reset content extensions. >+ resetContentFilters(); >+ > // Reset notification permissions > m_webNotificationProvider.reset(); > >@@ -1090,6 +1122,14 @@ static std::string testPath(WKURLRef url) > return std::string(); > } > >+static std::string testURLPath(WKURLRef url) >+{ >+ auto path = adoptWK(WKURLCopyPath(url)); >+ auto buffer = std::vector<char>(WKStringGetMaximumUTF8CStringSize(path.get())); >+ auto length = WKStringGetUTF8CString(path.get(), buffer.data(), buffer.size()); >+ return std::string(buffer.data(), length); >+} >+ > static WKURLRef createTestURL(const char* pathOrURL) > { > if (strstr(pathOrURL, "http://") || strstr(pathOrURL, "https://") || strstr(pathOrURL, "file://")) >@@ -1299,10 +1339,62 @@ void TestController::configureViewForTest(const TestInvocation& test) > ensureViewSupportsOptionsForTest(test); > updateWebViewSizeForTest(test); > updateWindowScaleForTest(mainWebView(), test); >- >+ configureContentFilterForTest(test); > platformConfigureViewForTest(test); > } > >+void TestController::configureContentFilterForTest(const TestInvocation& test) >+{ >+#if ENABLE(CONTENT_EXTENSIONS) >+ if (!test.urlContains("contentextensions/")) >+ return; >+ >+ std::string jsonPath("LayoutTests/http/tests" + testURLPath(test.url())); >+ std::ifstream jsonFile(jsonPath + ".json"); >+ if (!jsonFile.good()) >+ return; >+ >+ std::string jsonFileContents((std::istreambuf_iterator<char>(jsonFile)), >+ (std::istreambuf_iterator<char>())); >+ auto jsonSource = adoptWK(WKStringCreateWithUTF8CString(jsonFileContents.c_str())); >+ >+ auto extensionStore = adoptWK(WKUserContentExtensionStoreGetDefaultUserContentExtensionStore()); >+ ASSERT(extensionStore); >+ >+ auto filterIdentifier = adoptWK(WKStringCreateWithUTF8CString("TestContentExtension")); >+ UserContentExtensionStoreResult result { extensionStore, filterIdentifier }; >+ WKUserContentExtensionStoreCompileFilter(extensionStore.get(), filterIdentifier.get(), jsonSource.get(), &result, didUserContentExtensionStoreOperation); >+ platformRunUntil(result.finished, 0_s); >+ ASSERT(kWKUserContentExtensionStoreSuccess == result.status); >+ ASSERT(result.filter); >+ >+ auto pageConfiguration = adoptWK(WKPageCopyPageConfiguration(m_mainWebView->page())); >+ auto userContentController = adoptWK(WKPageConfigurationGetUserContentController(pageConfiguration.get())); >+ ASSERT(userContentController); >+ WKUserContentControllerAddUserContentFilter(userContentController.get(), result.filter.get()); >+ WKPageSetUserContentExtensionsEnabled(m_mainWebView->page(), true); >+#endif >+} >+ >+void TestController::resetContentFilters() >+{ >+#if ENABLE(CONTENT_EXTENSIONS) >+ auto pageConfiguration = adoptWK(WKPageCopyPageConfiguration(m_mainWebView->page())); >+ auto userContentController = adoptWK(WKPageConfigurationGetUserContentController(pageConfiguration.get())); >+ ASSERT(userContentController); >+ WKUserContentControllerRemoveAllUserContentFilters(userContentController.get()); >+ >+ auto extensionStore = adoptWK(WKUserContentExtensionStoreGetDefaultUserContentExtensionStore()); >+ ASSERT(extensionStore); >+ >+ auto filterIdentifier = adoptWK(WKStringCreateWithUTF8CString("TestContentExtension")); >+ UserContentExtensionStoreResult result { extensionStore, filterIdentifier }; >+ WKUserContentExtensionStoreRemoveFilter(extensionStore.get(), filterIdentifier.get(), &result, didUserContentExtensionStoreOperation); >+ platformRunUntil(result.finished, 0_s); >+ ASSERT(!result.filter); >+#endif >+} >+ > class CommandTokenizer { > public: > explicit CommandTokenizer(const std::string& input) >diff --git a/Tools/WebKitTestRunner/TestController.h b/Tools/WebKitTestRunner/TestController.h >index 13a39c6905f0d87ba87b9db57f8dad5c17ac71bc..f899a306b72fde7a52a580236b0b4f7b1de56a40 100644 >--- a/Tools/WebKitTestRunner/TestController.h >+++ b/Tools/WebKitTestRunner/TestController.h >@@ -148,6 +148,10 @@ public: > unsigned userMediaPermissionRequestCountForOrigin(WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString); > void resetUserMediaPermissionRequestCountForOrigin(WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString); > >+ // Content extensions. >+ void configureContentFilterForTest(const TestInvocation& test); >+ void resetContentFilters(); >+ > // Policy delegate. > void setCustomPolicyDelegate(bool enabled, bool permissive); > >diff --git a/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm b/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm >index 11b0e3ae34fbbe7e1ba9e1721a4d118d33026796..c6d56d6f68a748ff36d1724c45c512df0adfdcd1 100644 >--- a/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm >+++ b/Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm >@@ -38,7 +38,6 @@ > #import <WebKit/WKPreferencesRefPrivate.h> > #import <WebKit/WKProcessPoolPrivate.h> > #import <WebKit/WKStringCF.h> >-#import <WebKit/WKUserContentControllerPrivate.h> > #import <WebKit/WKWebView.h> > #import <WebKit/WKWebViewConfiguration.h> > #import <WebKit/WKWebViewConfigurationPrivate.h> >@@ -47,8 +46,7 @@ > #import <WebKit/WKWebsiteDataStorePrivate.h> > #import <WebKit/WKWebsiteDataStoreRef.h> > #import <WebKit/_WKApplicationManifest.h> >-#import <WebKit/_WKUserContentExtensionStore.h> >-#import <WebKit/_WKUserContentExtensionStorePrivate.h> >+#import <WebKit/_WKProcessPoolConfiguration.h> > #import <wtf/MainThread.h> > > namespace WTR { >diff --git a/ChangeLog b/ChangeLog >index 4b999e325e9813d97048abab45ce923b920adfc8..0f9eba376a26e125f613be346bd694e797c7e6d6 100644 >--- a/ChangeLog >+++ b/ChangeLog >@@ -1,3 +1,15 @@ >+2018-12-12 Adrian Perez de Castro <aperez@igalia.com> >+ >+ [GTK] Enable CONTENT_EXTENSIONS and fix the build with it enabled >+ https://bugs.webkit.org/show_bug.cgi?id=167941 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * Source/cmake/OptionsGTK.cmake: Set ENABLE_CONTENT_EXTENSIONS as enabled by default. >+ * Source/cmake/OptionsWPE.cmake: Set ENABLE_CONTENT_EXTENSIONS as enabled by default. >+ * Source/cmake/WebKitFeatures.cmake: Add ENABLE_CONTENT_EXTENSIONS to the list of features, >+ initially disabled. Ports implementing it need to toggle the feature. >+ > 2018-12-12 Carlos Garcia Campos <cgarcia@igalia.com> > > [FreeType] Add initial implementation of variation fonts
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