[GTK][WPE] Add content extensions support in WKTR and unskip layout tests
authoraperez@igalia.com <aperez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Feb 2019 00:07:21 +0000 (00:07 +0000)
committeraperez@igalia.com <aperez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Feb 2019 00:07:21 +0000 (00:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193622

Reviewed by Michael Catanzaro.

.:

* Source/cmake/OptionsGTK.cmake: Enable CONTENT_EXTENSIONS by default.
* Source/cmake/OptionsWPE.cmake: Ditto.
* Source/cmake/WebKitFeatures.cmake: Add a private CONTENT_EXTENSIONS option.

Source/WebCore:

No new tests needed.

* SourcesCocoa.txt: Remove loader/ResourceLoadInfo.cpp, it's not Cocoa-specific anymore.
* Sources.txt: Add loader/ResourceLoadInfo.cpp, all ports use it now.

Source/WebKit:

* NetworkProcess/cache/NetworkCacheData.h: Define an adoptAndMapFile() implementation
for GFileIOStream objects.
* NetworkProcess/cache/NetworkCacheDataSoup.cpp:
(WebKit::NetworkCache::adoptAndMapFile): Added implementation, which extracts the file
descriptor from a GFileIOStream, as it inherits from GFileDescriptorBased, and then
reuses the version of adoptAndMapFile() which takes a file descritor for the actual work.
* NetworkProcess/NetworkLoadChecker.cpp:
(Webkit::NetworkLoadChecker::checkRequest): Use "this" when referring to
processContentExtensionRulesForLoad() in order to avoid ambiguity.
* Sources.txt: Add WKUserContentExtensionStoreRef.cpp, all ports use it now.
* SourcesCocoa.txt: Remove WKUserContentExtensionStoreRef.cpp, because it is not
Cocoa-specific anymore.
* SourcesGTK.txt: Add APIContentRuleListStoreGLib.cpp.
* SourcesWPE.txt: Ditto.
* UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:
(WKUserContentExtensionStoreCreate): Added.
(toResult): Added.
(WKUserContentExtensionStoreCompile): Added.
(WKUserContentExtensionStoreLookup): Added.
(WKUserContentExtensionStoreRemove): Added.
* UIProcess/API/C/WKUserContentExtensionStoreRef.h: Add declarations for the new C API
functions and for the WKUserContentExtensionStoreResult status enum.
* UIProcess/API/glib/APIContentRuleListStoreGLib.cpp: Added.
(API::ContentRuleListStore::defaultStorePath): Add a dummy implementation. The public API
for the GLib based ports (GTK+ and WPE) will not allow using the default store and will
always indicating a path.

Tools:

This adds support for loading content extension rule sets from the JSON files which
accompany the corresponding layout test, using the C API. The Cocoa specific parts
of WKTR for this could be removed, but that is left for a follow-up patch with
cleanups.

* Scripts/webkitperl/FeatureList.pm: Add an option to toggle CONTENT_EXTENSIONS.
* WebKitTestRunner/TestController.cpp:
(WTR::testPath): Subtract one from the length when constructing the result std::string to
avoid having the null-terminator copied into the result.
(WTR::TestController::configureViewForTest): Call configureContentExtensionForTest() as
part of the preparations to run a test.
(WTR::ContentExtensionStoreCallbackContext::ContentExtensionStoreCallbackContext): Added.
(WTR::contentExtensionStoreCallback): Added.
(WTR::contentExtensionJSONPath): Used to calculate the path to the JSON rule set to be
used for content extensions test.
(WTR::TestController::configureContentExtensionForTest): Added, handles enabling content
extensions and compiling the JSON rule set for tests involving content extensions.
(WTR::TestController::resetContentExtensions): Removes the content extension built for
testing and disables content extensions.
(WTR::TestController::resetPreferencesToConsistentValues): Add a call to
resetContentExtensions().
(WTR::TestController::userContentController): Added implementation for ports other than Cocoa.
* WebKitTestRunner/TestController.h: Add declarations for resetContentExtensions(),
configureContentExtensionForTest(), and userContentController().

LayoutTests:

* platform/gtk/TestExpectations: Un-skip tests for content extensions and add expectations.

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

27 files changed:
ChangeLog
LayoutTests/ChangeLog
LayoutTests/platform/gtk/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Sources.txt
Source/WebCore/SourcesCocoa.txt
Source/WebKit/ChangeLog
Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp
Source/WebKit/NetworkProcess/cache/NetworkCacheData.h
Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp
Source/WebKit/Sources.txt
Source/WebKit/SourcesCocoa.txt
Source/WebKit/SourcesGTK.txt
Source/WebKit/SourcesWPE.txt
Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp
Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.h
Source/WebKit/UIProcess/API/glib/APIContentRuleListStoreGLib.cpp [new file with mode: 0644]
Source/cmake/OptionsGTK.cmake
Source/cmake/OptionsWPE.cmake
Source/cmake/WebKitFeatures.cmake
Tools/ChangeLog
Tools/Scripts/webkitperl/FeatureList.pm
Tools/WebKitTestRunner/TestController.cpp
Tools/WebKitTestRunner/TestController.h
Tools/WebKitTestRunner/cocoa/TestControllerCocoa.mm
Tools/WebKitTestRunner/ios/TestControllerIOS.mm
Tools/WebKitTestRunner/mac/TestControllerMac.mm

index 32f46f7..031b5e2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2019-02-11  Adrian Perez de Castro  <aperez@igalia.com>
+
+        [GTK][WPE] Add content extensions support in WKTR and unskip layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=193622
+
+        Reviewed by Michael Catanzaro.
+
+        * Source/cmake/OptionsGTK.cmake: Enable CONTENT_EXTENSIONS by default.
+        * Source/cmake/OptionsWPE.cmake: Ditto.
+        * Source/cmake/WebKitFeatures.cmake: Add a private CONTENT_EXTENSIONS option.
+
 2019-02-07  Miguel Gomez  <magomez@igalia.com>
 
         [WPE] Implement GStreamer based holepunch
index cd465a5..db77a4e 100644 (file)
@@ -1,3 +1,12 @@
+2019-02-11  Adrian Perez de Castro  <aperez@igalia.com>
+
+        [GTK][WPE] Add content extensions support in WKTR and unskip layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=193622
+
+        Reviewed by Michael Catanzaro.
+
+        * platform/gtk/TestExpectations: Un-skip tests for content extensions and add expectations.
+
 2019-02-11  Daniel Bates  <dabates@apple.com>
 
         [iOS] Mouse/Touch/Pointer events are missing modifier keys
index c518b56..c851c75 100644 (file)
@@ -123,6 +123,34 @@ fast/images/object-image.html [ WontFix Pass ]
 # The 64 bits release bot has been made to use 8 bpp depth, so this won't pass there.
 webkit.org/b/121951 fast/dom/Window/window-screen-properties.html [ Failure Pass ]
 
+# Content extensions, the failures need up-to-date expectations.
+http/tests/contentextensions/basic-filter.html [ Failure ]
+http/tests/contentextensions/block-cookies-in-csp-report.php [ Failure ]
+http/tests/contentextensions/block-cookies-in-image-load-in-onunload.html [ Failure Timeout ]
+http/tests/contentextensions/block-cookies-in-ping.html [ Failure ]
+http/tests/contentextensions/block-cookies-send.html [ Failure ]
+http/tests/contentextensions/block-csp-report.php [ Failure ]
+http/tests/contentextensions/block-everything-unless-domain-redirect.php [ Failure ]
+http/tests/contentextensions/block-image-load-in-onunload.html [ Failure Timeout ]
+http/tests/contentextensions/block-ping.html [ Failure ]
+http/tests/contentextensions/character-set-basic-support.html [ Failure ]
+http/tests/contentextensions/css-display-none.html [ Failure ]
+http/tests/contentextensions/domain-rules.html [ Failure ]
+http/tests/contentextensions/fetch-redirect-blocked.html [ Failure ]
+http/tests/contentextensions/filters-with-quantifiers-combined.html [ Failure ]
+http/tests/contentextensions/hide-on-csp-report.php [ Failure ]
+http/tests/contentextensions/hide-on-ping-with-ping-that-redirects.html [ Failure ]
+http/tests/contentextensions/hide-on-ping.html [ Failure ]
+http/tests/contentextensions/injected-script-callback.html [ Failure ]
+http/tests/contentextensions/main-resource-redirect-blocked.php [ Failure ]
+http/tests/contentextensions/main-resource-redirect-error.html [ Failure ]
+http/tests/contentextensions/media-filtered.html [ Failure ]
+http/tests/contentextensions/reload-without-contentextensions.html [ Failure ]
+http/tests/contentextensions/subresource-redirect-blocked.html [ Failure ]
+http/tests/contentextensions/text-track-blocked.html [ Failure ]
+http/tests/contentextensions/top-url.html [ Failure ]
+http/tests/contentextensions/whitelist.html [ Failure ]
+
 # This test requires Mac ObjC bindings, although it currently passes
 Bug(GTK) http/tests/security/dataTransfer-set-data-file-url.html [ WontFix Pass ]
 
@@ -3816,6 +3844,8 @@ fast/text/emoji-gender-fe0f-7.html [ Pass ]
 fast/text/emoji-gender-fe0f-8.html [ Pass ]
 fast/text/emoji-gender-fe0f-9.html [ Pass ]
 
+http/tests/contentextensions [ Pass ]
+
 imported/w3c/web-platform-tests/css/css-scoping/stylesheet-title-001.html [ Pass ]
 imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-capitalize-026.html [ Pass ]
 
index acbd4c7..6b5b3e0 100644 (file)
@@ -1,3 +1,15 @@
+2019-02-11  Adrian Perez de Castro  <aperez@igalia.com>
+
+        [GTK][WPE] Add content extensions support in WKTR and unskip layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=193622
+
+        Reviewed by Michael Catanzaro.
+
+        No new tests needed.
+
+        * SourcesCocoa.txt: Remove loader/ResourceLoadInfo.cpp, it's not Cocoa-specific anymore.
+        * Sources.txt: Add loader/ResourceLoadInfo.cpp, all ports use it now.
+
 2019-02-11  Daniel Bates  <dabates@apple.com>
 
         [iOS] Mouse/Touch/Pointer events are missing modifier keys
index 7aeccf7..81cbc04 100644 (file)
@@ -1393,6 +1393,7 @@ loader/PingLoader.cpp
 loader/PolicyChecker.cpp
 loader/ProgressTracker.cpp
 loader/ResourceCryptographicDigest.cpp
+loader/ResourceLoadInfo.cpp
 loader/ResourceLoadNotifier.cpp
 loader/ResourceLoadObserver.cpp
 loader/ResourceLoadStatistics.cpp
index 9a312d3..de38abf 100644 (file)
@@ -109,8 +109,6 @@ html/shadow/mac/ImageControlsRootElementMac.cpp
 
 history/mac/HistoryItemMac.mm
 
-loader/ResourceLoadInfo.cpp
-
 loader/archive/cf/LegacyWebArchive.cpp
 loader/archive/cf/LegacyWebArchiveMac.mm
 
index c4bd1e8..b31f1b4 100644 (file)
@@ -1,3 +1,37 @@
+2019-02-11  Adrian Perez de Castro  <aperez@igalia.com>
+
+        [GTK][WPE] Add content extensions support in WKTR and unskip layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=193622
+
+        Reviewed by Michael Catanzaro.
+
+        * NetworkProcess/cache/NetworkCacheData.h: Define an adoptAndMapFile() implementation
+        for GFileIOStream objects.
+        * NetworkProcess/cache/NetworkCacheDataSoup.cpp:
+        (WebKit::NetworkCache::adoptAndMapFile): Added implementation, which extracts the file
+        descriptor from a GFileIOStream, as it inherits from GFileDescriptorBased, and then
+        reuses the version of adoptAndMapFile() which takes a file descritor for the actual work.
+        * NetworkProcess/NetworkLoadChecker.cpp:
+        (Webkit::NetworkLoadChecker::checkRequest): Use "this" when referring to
+        processContentExtensionRulesForLoad() in order to avoid ambiguity.
+        * Sources.txt: Add WKUserContentExtensionStoreRef.cpp, all ports use it now.
+        * SourcesCocoa.txt: Remove WKUserContentExtensionStoreRef.cpp, because it is not
+        Cocoa-specific anymore.
+        * SourcesGTK.txt: Add APIContentRuleListStoreGLib.cpp.
+        * SourcesWPE.txt: Ditto.
+        * UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:
+        (WKUserContentExtensionStoreCreate): Added.
+        (toResult): Added.
+        (WKUserContentExtensionStoreCompile): Added.
+        (WKUserContentExtensionStoreLookup): Added.
+        (WKUserContentExtensionStoreRemove): Added.
+        * UIProcess/API/C/WKUserContentExtensionStoreRef.h: Add declarations for the new C API
+        functions and for the WKUserContentExtensionStoreResult status enum.
+        * UIProcess/API/glib/APIContentRuleListStoreGLib.cpp: Added.
+        (API::ContentRuleListStore::defaultStorePath): Add a dummy implementation. The public API
+        for the GLib based ports (GTK+ and WPE) will not allow using the default store and will
+        always indicating a path.
+
 2019-02-11  Daniel Bates  <dabates@apple.com>
 
         [iOS] Mouse/Touch/Pointer events are missing modifier keys
index 0ec8ff1..7878fad 100644 (file)
@@ -238,7 +238,7 @@ void NetworkLoadChecker::checkRequest(ResourceRequest&& request, ContentSecurity
         }
 
 #if ENABLE(CONTENT_EXTENSIONS)
-        processContentExtensionRulesForLoad(WTFMove(request), [this, handler = WTFMove(handler), originalRequest = WTFMove(originalRequest)](auto result) mutable {
+        this->processContentExtensionRulesForLoad(WTFMove(request), [this, handler = WTFMove(handler), originalRequest = WTFMove(originalRequest)](auto result) mutable {
             if (!result.has_value()) {
                 ASSERT(result.error().isCancellation());
                 handler(WTFMove(result.error()));
@@ -249,7 +249,7 @@ void NetworkLoadChecker::checkRequest(ResourceRequest&& request, ContentSecurity
                 return;
             }
 
-            continueCheckingRequestOrDoSyntheticRedirect(WTFMove(originalRequest), WTFMove(result.value().request), WTFMove(handler));
+            this->continueCheckingRequestOrDoSyntheticRedirect(WTFMove(originalRequest), WTFMove(result.value().request), WTFMove(handler));
         });
 #else
         this->continueCheckingRequestOrDoSyntheticRedirect(WTFMove(originalRequest), WTFMove(request), WTFMove(handler));
index 5bedc0d..5559c35 100644 (file)
@@ -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 USE(GLIB) && !PLATFORM(WIN)
+Data adoptAndMapFile(GFileIOStream*, size_t offset, size_t);
+#endif
 Data mapFile(const char* path);
 
 using Salt = std::array<uint8_t, 8>;
index 3ae8a6f..515c09e 100644 (file)
 #include <sys/types.h>
 #include <unistd.h>
 
+#if USE(GLIB) && !PLATFORM(WIN)
+#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 USE(GLIB) && !PLATFORM(WIN)
+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())
index b39d264..3b6066e 100644 (file)
@@ -348,6 +348,7 @@ UIProcess/API/C/WKResourceCacheManager.cpp
 UIProcess/API/C/WKSessionStateRef.cpp
 UIProcess/API/C/WKTextChecker.cpp
 UIProcess/API/C/WKUserContentControllerRef.cpp
+UIProcess/API/C/WKUserContentExtensionStoreRef.cpp
 UIProcess/API/C/WKUserMediaPermissionCheck.cpp
 UIProcess/API/C/WKUserMediaPermissionRequest.cpp
 UIProcess/API/C/WKWebsiteDataStoreRef.cpp
index 2c7983e..9fee2c6 100644 (file)
@@ -221,7 +221,6 @@ UIProcess/API/APIWebsiteDataRecord.cpp
 UIProcess/API/C/WKContextMenuListener.cpp
 UIProcess/API/C/WKMediaSessionFocusManager.cpp
 UIProcess/API/C/WKTestingSupport.cpp
-UIProcess/API/C/WKUserContentExtensionStoreRef.cpp
 UIProcess/API/C/WKUserScriptRef.cpp
 
 UIProcess/API/C/cg/WKIconDatabaseCG.cpp
index 15ae6b5..4829a9f 100644 (file)
@@ -126,6 +126,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
index 4dc0f3c..5ce9583 100644 (file)
@@ -109,6 +109,7 @@ 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
index 265c8df..41c6974 100644 (file)
 #include "config.h"
 #include "WKUserContentExtensionStoreRef.h"
 
+#include "APIContentRuleList.h"
 #include "APIContentRuleListStore.h"
 #include "WKAPICast.h"
+#include <wtf/CompletionHandler.h>
 
 using namespace WebKit;
 
@@ -39,3 +41,66 @@ WKTypeID WKUserContentExtensionStoreGetTypeID()
     return 0;
 #endif
 }
+
+WKUserContentExtensionStoreRef WKUserContentExtensionStoreCreate(WKStringRef path)
+{
+#if ENABLE(CONTENT_EXTENSIONS)
+    return toAPI(&API::ContentRuleListStore::storeWithPath(toWTFString(path), false).leakRef());
+#else
+    UNUSED_PARAM(path);
+    return nullptr;
+#endif
+}
+
+#if ENABLE(CONTENT_EXTENSIONS)
+static inline WKUserContentExtensionStoreResult toResult(const std::error_code& error)
+{
+    if (!error)
+        return kWKUserContentExtensionStoreSuccess;
+
+    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;
+    }
+}
+#endif
+
+void WKUserContentExtensionStoreCompile(WKUserContentExtensionStoreRef store, WKStringRef identifier, WKStringRef jsonSource, void* context, WKUserContentExtensionStoreFunction callback)
+{
+#if ENABLE(CONTENT_EXTENSIONS)
+    toImpl(store)->compileContentRuleList(toWTFString(identifier), toWTFString(jsonSource), [context, callback](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) {
+        callback(error ? nullptr : toAPI(contentRuleList.leakRef()), toResult(error), context);
+    });
+#else
+    UNUSED_PARAM(jsonSource);
+    callback(nullptr, kWKUserContentExtensionStoreCompileFailed, context);
+#endif
+}
+
+void WKUserContentExtensionStoreLookup(WKUserContentExtensionStoreRef store, WKStringRef identifier, void* context, WKUserContentExtensionStoreFunction callback)
+{
+#if ENABLE(CONTENT_EXTENSIONS)
+    toImpl(store)->lookupContentRuleList(toWTFString(identifier), [context, callback](RefPtr<API::ContentRuleList> contentRuleList, std::error_code error) {
+        callback(error ? nullptr : toAPI(contentRuleList.leakRef()), toResult(error), context);
+    });
+#else
+    callback(nullptr, kWKUserContentExtensionStoreLookupFailed, context);
+#endif
+}
+
+void WKUserContentExtensionStoreRemove(WKUserContentExtensionStoreRef store, WKStringRef identifier, void* context, WKUserContentExtensionStoreFunction callback)
+{
+#if ENABLE(CONTENT_EXTENSIONS)
+    toImpl(store)->removeContentRuleList(toWTFString(identifier), [context, callback](std::error_code error) {
+        callback(nullptr, toResult(error), context);
+    });
+#else
+    callback(nullptr, kWKUserContentExtensionStoreRemoveFailed, context);
+#endif
+}
index 53598ec..a2ca35c 100644 (file)
@@ -34,6 +34,22 @@ extern "C" {
 
 WK_EXPORT WKTypeID WKUserContentExtensionStoreGetTypeID();
 
+WK_EXPORT WKUserContentExtensionStoreRef WKUserContentExtensionStoreCreate(WKStringRef path);
+
+typedef uint32_t WKUserContentExtensionStoreResult;
+enum {
+    kWKUserContentExtensionStoreSuccess = 0,
+    kWKUserContentExtensionStoreLookupFailed,
+    kWKUserContentExtensionStoreVersionMismatch,
+    kWKUserContentExtensionStoreCompileFailed,
+    kWKUserContentExtensionStoreRemoveFailed,
+};
+
+typedef void (*WKUserContentExtensionStoreFunction)(WKUserContentFilterRef, WKUserContentExtensionStoreResult, void*);
+WK_EXPORT void WKUserContentExtensionStoreCompile(WKUserContentExtensionStoreRef, WKStringRef identifier, WKStringRef jsonSource, void* context, WKUserContentExtensionStoreFunction callback);
+WK_EXPORT void WKUserContentExtensionStoreLookup(WKUserContentExtensionStoreRef, WKStringRef identifier, void* context, WKUserContentExtensionStoreFunction callback);
+WK_EXPORT void WKUserContentExtensionStoreRemove(WKUserContentExtensionStoreRef, WKStringRef identifier, void* context, WKUserContentExtensionStoreFunction 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 (file)
index 0000000..4dde992
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 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 "APIContentRuleListStore.h"
+
+namespace API {
+
+#if ENABLE(CONTENT_EXTENSIONS)
+String ContentRuleListStore::defaultStorePath(bool)
+{
+    ASSERT_NOT_REACHED();
+    return String();
+}
+#endif
+
+}; // namespace API
index 9f3d1a3..718ca0a 100644 (file)
@@ -150,12 +150,13 @@ 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)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_INPUT_TYPE_COLOR PRIVATE ON)
-WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MHTML PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MEDIA_STREAM PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
+WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_MHTML PRIVATE ON)
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_SERVICE_WORKER PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
 WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_WEB_RTC PRIVATE ${ENABLE_EXPERIMENTAL_FEATURES})
 
index fe4a68b..5829ee2 100644 (file)
@@ -47,6 +47,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)
index f70b817..a031de4 100644 (file)
@@ -102,6 +102,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)
index 48d71eb..f2930ce 100644 (file)
@@ -1,3 +1,35 @@
+2019-02-11  Adrian Perez de Castro  <aperez@igalia.com>
+
+        [GTK][WPE] Add content extensions support in WKTR and unskip layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=193622
+
+        Reviewed by Michael Catanzaro.
+
+        This adds support for loading content extension rule sets from the JSON files which
+        accompany the corresponding layout test, using the C API. The Cocoa specific parts
+        of WKTR for this could be removed, but that is left for a follow-up patch with
+        cleanups.
+
+        * Scripts/webkitperl/FeatureList.pm: Add an option to toggle CONTENT_EXTENSIONS.
+        * WebKitTestRunner/TestController.cpp:
+        (WTR::testPath): Subtract one from the length when constructing the result std::string to
+        avoid having the null-terminator copied into the result.
+        (WTR::TestController::configureViewForTest): Call configureContentExtensionForTest() as
+        part of the preparations to run a test.
+        (WTR::ContentExtensionStoreCallbackContext::ContentExtensionStoreCallbackContext): Added.
+        (WTR::contentExtensionStoreCallback): Added.
+        (WTR::contentExtensionJSONPath): Used to calculate the path to the JSON rule set to be
+        used for content extensions test.
+        (WTR::TestController::configureContentExtensionForTest): Added, handles enabling content
+        extensions and compiling the JSON rule set for tests involving content extensions.
+        (WTR::TestController::resetContentExtensions): Removes the content extension built for
+        testing and disables content extensions.
+        (WTR::TestController::resetPreferencesToConsistentValues): Add a call to
+        resetContentExtensions().
+        (WTR::TestController::userContentController): Added implementation for ports other than Cocoa.
+        * WebKitTestRunner/TestController.h: Add declarations for resetContentExtensions(),
+        configureContentExtensionForTest(), and userContentController().
+
 2019-02-11  Daniel Bates  <dabates@apple.com>
 
         [iOS] Mouse/Touch/Pointer events are missing modifier keys
index c335033..809718f 100644 (file)
@@ -62,6 +62,7 @@ my (
     $cachePartitioningSupport,
     $channelMessagingSupport,
     $cloopSupport,
+    $contentExtensionsSupport,
     $contentFilteringSupport,
     $contextMenusSupport,
     $css3TextSupport,
@@ -227,6 +228,9 @@ my @features = (
     { option => "channel-messaging", desc => "Toggle Channel Messaging support",
       define => "ENABLE_CHANNEL_MESSAGING", value => \$channelMessagingSupport },
 
+    { option => "content-extensions", desc => "Toggle Content Extensions support",
+      define => "ENABLE_CONTENT_EXTENSIONS", value => \$contentExtensionsSupport },
+
     { option => "content-filtering", desc => "Toggle content filtering support",
       define => "ENABLE_CONTENT_FILTERING", value => \$contentFilteringSupport },
 
index 8055efc..7747f8d 100644 (file)
@@ -60,6 +60,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>
@@ -537,7 +539,9 @@ WKRetainPtr<WKPageConfigurationRef> TestController::generatePageConfiguration(WK
     auto pageConfiguration = adoptWK(WKPageConfigurationCreate());
     WKPageConfigurationSetContext(pageConfiguration.get(), m_context.get());
     WKPageConfigurationSetPageGroup(pageConfiguration.get(), m_pageGroup.get());
-    WKPageConfigurationSetUserContentController(pageConfiguration.get(), adoptWK(WKUserContentControllerCreate()).get());
+
+    m_userContentController = adoptWK(WKUserContentControllerCreate());
+    WKPageConfigurationSetUserContentController(pageConfiguration.get(), userContentController());
     return pageConfiguration;
 }
 
@@ -932,6 +936,9 @@ bool TestController::resetStateToConsistentValues(const TestOptions& options, Re
     // Reset Custom Policy Delegate.
     setCustomPolicyDelegate(false, false);
 
+    // Reset Content Extensions.
+    resetContentExtensions();
+
     m_shouldDownloadUndisplayableMIMETypes = false;
 
     m_workQueueManager.clearWorkQueue();
@@ -1102,12 +1109,13 @@ static std::string testPath(WKURLRef url)
         auto path = adoptWK(WKURLCopyPath(url));
         auto buffer = std::vector<char>(WKStringGetMaximumUTF8CStringSize(path.get()));
         auto length = WKStringGetUTF8CString(path.get(), buffer.data(), buffer.size());
+        RELEASE_ASSERT(length > 0);
 #if OS(WINDOWS)
         // Remove the first '/' if it starts with something like "/C:/".
         if (length >= 4 && buffer[0] == '/' && buffer[2] == ':' && buffer[3] == '/')
             return std::string(buffer.data() + 1, length - 1);
 #endif
-        return std::string(buffer.data(), length);
+        return std::string(buffer.data(), length - 1);
     }
     return std::string();
 }
@@ -1327,10 +1335,119 @@ void TestController::configureViewForTest(const TestInvocation& test)
     ensureViewSupportsOptionsForTest(test);
     updateWebViewSizeForTest(test);
     updateWindowScaleForTest(mainWebView(), test);
-
+    configureContentExtensionForTest(test);
     platformConfigureViewForTest(test);
 }
 
+#if ENABLE(CONTENT_EXTENSIONS) && !PLATFORM(COCOA)
+struct ContentExtensionStoreCallbackContext {
+    explicit ContentExtensionStoreCallbackContext(TestController& controller)
+        : testController(controller)
+    {
+    }
+
+    TestController& testController;
+    uint32_t status { kWKUserContentExtensionStoreSuccess };
+    WKRetainPtr<WKUserContentFilterRef> filter;
+    bool done { false };
+};
+
+static void contentExtensionStoreCallback(WKUserContentFilterRef filter, uint32_t status, void* userData)
+{
+    auto* context = static_cast<ContentExtensionStoreCallbackContext*>(userData);
+    context->status = status;
+    context->filter = filter ? adoptWK(filter) : nullptr;
+    context->done = true;
+    context->testController.notifyDone();
+}
+
+static std::string contentExtensionJSONPath(WKURLRef url)
+{
+    auto path = testPath(url);
+    if (path.length())
+        return path + ".json";
+
+    auto p = adoptWK(WKURLCopyPath(url));
+    auto buffer = std::vector<char>(WKStringGetMaximumUTF8CStringSize(p.get()));
+    const auto length = WKStringGetUTF8CString(p.get(), buffer.data(), buffer.size());
+    return std::string("LayoutTests/http/tests") + std::string(buffer.data(), length - 1) + ".json";
+}
+#endif
+
+#if !PLATFORM(COCOA)
+#if ENABLE(CONTENT_EXTENSIONS)
+void TestController::configureContentExtensionForTest(const TestInvocation& test)
+{
+    const char* contentExtensionsPath = libraryPathForTesting();
+    if (!contentExtensionsPath)
+        contentExtensionsPath = "/tmp/wktr-contentextensions";
+
+    if (!test.urlContains("contentextensions/")) {
+        WKPageSetUserContentExtensionsEnabled(m_mainWebView->page(), false);
+        return;
+    }
+
+    std::string jsonFilePath(contentExtensionJSONPath(test.url()));
+    std::ifstream jsonFile(jsonFilePath);
+    if (!jsonFile.good()) {
+        WTFLogAlways("Could not open file '%s'", jsonFilePath.c_str());
+        return;
+    }
+
+    std::string jsonFileContents {std::istreambuf_iterator<char>(jsonFile), std::istreambuf_iterator<char>()};
+    auto jsonSource = adoptWK(WKStringCreateWithUTF8CString(jsonFileContents.c_str()));
+
+    auto storePath = adoptWK(WKStringCreateWithUTF8CString(contentExtensionsPath));
+    auto extensionStore = adoptWK(WKUserContentExtensionStoreCreate(storePath.get()));
+    ASSERT(extensionStore);
+
+    auto filterIdentifier = adoptWK(WKStringCreateWithUTF8CString("TestContentExtension"));
+
+    ContentExtensionStoreCallbackContext context(*this);
+    WKUserContentExtensionStoreCompile(extensionStore.get(), filterIdentifier.get(), jsonSource.get(), &context, contentExtensionStoreCallback);
+    runUntil(context.done, noTimeout);
+    ASSERT(context.status == kWKUserContentExtensionStoreSuccess);
+    ASSERT(context.filter);
+
+    WKPageSetUserContentExtensionsEnabled(mainWebView()->page(), true);
+    WKUserContentControllerAddUserContentFilter(userContentController(), context.filter.get());
+}
+
+void TestController::resetContentExtensions()
+{
+    if (!mainWebView())
+        return;
+
+    WKPageSetUserContentExtensionsEnabled(mainWebView()->page(), false);
+
+    const char* contentExtensionsPath = libraryPathForTesting();
+    if (!contentExtensionsPath)
+        return;
+
+    WKUserContentControllerRemoveAllUserContentFilters(userContentController());
+
+    auto storePath = adoptWK(WKStringCreateWithUTF8CString(contentExtensionsPath));
+    auto extensionStore = adoptWK(WKUserContentExtensionStoreCreate(storePath.get()));
+    ASSERT(extensionStore);
+
+    auto filterIdentifier = adoptWK(WKStringCreateWithUTF8CString("TestContentExtension"));
+
+    ContentExtensionStoreCallbackContext context(*this);
+    WKUserContentExtensionStoreRemove(extensionStore.get(), filterIdentifier.get(), &context, contentExtensionStoreCallback);
+    runUntil(context.done, noTimeout);
+    ASSERT(!context.filter);
+}
+#else // ENABLE(CONTENT_EXTENSIONS)
+void TestController::configureContentExtensionForTest(const TestInvocation&)
+{
+}
+
+void TestController::resetContentExtensions()
+{
+}
+#endif // ENABLE(CONTENT_EXTENSIONS)
+#endif // !PLATFORM(COCOA)
+
 class CommandTokenizer {
 public:
     explicit CommandTokenizer(const std::string& input)
index 705c175..2b9577b 100644 (file)
@@ -107,6 +107,7 @@ public:
 
     PlatformWebView* mainWebView() { return m_mainWebView.get(); }
     WKContextRef context() { return m_context.get(); }
+    WKUserContentControllerRef userContentController() { return m_userContentController.get(); }
 
     EventSenderProxy* eventSenderProxy() { return m_eventSenderProxy.get(); }
 
@@ -148,6 +149,10 @@ public:
     unsigned userMediaPermissionRequestCountForOrigin(WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString);
     void resetUserMediaPermissionRequestCountForOrigin(WKStringRef userMediaDocumentOriginString, WKStringRef topLevelDocumentOriginString);
 
+    // Content Extensions.
+    void configureContentExtensionForTest(const TestInvocation&);
+    void resetContentExtensions();
+
     // Policy delegate.
     void setCustomPolicyDelegate(bool enabled, bool permissive);
 
@@ -459,6 +464,7 @@ private:
     std::unique_ptr<PlatformWebView> m_mainWebView;
     WKRetainPtr<WKContextRef> m_context;
     WKRetainPtr<WKPageGroupRef> m_pageGroup;
+    WKRetainPtr<WKUserContentControllerRef> m_userContentController;
 
 #if PLATFORM(IOS_FAMILY)
     Vector<std::unique_ptr<InstanceMethodSwizzler>> m_inputModeSwizzlers;
index 5e9f935..fe3bd6e 100644 (file)
@@ -238,8 +238,8 @@ void TestController::setDefaultCalendarType(NSString *identifier)
     if (!m_calendarSwizzler)
         m_calendarSwizzler = std::make_unique<ClassMethodSwizzler>([NSCalendar class], @selector(currentCalendar), reinterpret_cast<IMP>(swizzledCalendar));
 }
-    
-void TestController::cocoaResetStateToConsistentValues(const TestOptions& options)
+
+void TestController::resetContentExtensions()
 {
 #if WK_API_ENABLED
     __block bool doneRemoving = false;
@@ -249,13 +249,21 @@ void TestController::cocoaResetStateToConsistentValues(const TestOptions& option
     platformRunUntil(doneRemoving, noTimeout);
     [[_WKUserContentExtensionStore defaultStore] _removeAllContentExtensions];
 
+    if (auto* webView = mainWebView()) {
+        TestRunnerWKWebView *platformView = webView->platformView();
+        [platformView.configuration.userContentController _removeAllUserContentFilters];
+    }
+#endif
+}
 
+void TestController::cocoaResetStateToConsistentValues(const TestOptions& options)
+{
+#if WK_API_ENABLED
     m_calendarSwizzler = nullptr;
     m_overriddenCalendarIdentifier = nil;
     
     if (auto* webView = mainWebView()) {
         TestRunnerWKWebView *platformView = webView->platformView();
-        [platformView.configuration.userContentController _removeAllUserContentFilters];
         platformView._viewScale = 1;
         platformView._minimumEffectiveDeviceWidth = 0;
 
index 04011a6..21bd497 100644 (file)
@@ -105,6 +105,10 @@ void TestController::initializeTestPluginDirectory()
     m_testPluginDirectory.adopt(WKStringCreateWithCFString((CFStringRef)[[NSBundle mainBundle] bundlePath]));
 }
 
+void TestController::configureContentExtensionForTest(const TestInvocation&)
+{
+}
+
 void TestController::platformResetPreferencesToConsistentValues()
 {
     WKPreferencesRef preferences = platformPreferences();
index 583eed4..31eda93 100644 (file)
@@ -118,7 +118,7 @@ void TestController::updatePlatformSpecificTestOptionsForTest(TestOptions& optio
     options.shouldShowWebView = shouldShowWebView();
 }
 
-void TestController::platformConfigureViewForTest(const TestInvocation& test)
+void TestController::configureContentExtensionForTest(const TestInvocation& test)
 {
 #if WK_API_ENABLED
     if (!test.urlContains("contentextensions/"))
@@ -153,6 +153,10 @@ void TestController::platformConfigureViewForTest(const TestInvocation& test)
 #endif
 }
 
+void TestController::platformConfigureViewForTest(const TestInvocation& test)
+{
+}
+
 static NSSet *allowedFontFamilySet()
 {
     static NSSet *fontFamilySet = [[NSSet setWithObjects: