Bug 193622 - [GTK][WPE] Add content extensions support in WKTR and unskip layout tests
Summary: [GTK][WPE] Add content extensions support in WKTR and unskip layout tests
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: Other
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Adrian Perez
URL:
Keywords: InRadar
Depends on:
Blocks: 194515 167941 194908
  Show dependency treegraph
 
Reported: 2019-01-20 12:24 PST by Adrian Perez
Modified: 2019-02-21 10:39 PST (History)
11 users (show)

See Also:


Attachments
Patch (39.20 KB, patch)
2019-01-20 15:22 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v2 (43.16 KB, patch)
2019-01-21 00:20 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v3 (43.71 KB, patch)
2019-01-21 01:01 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v4 (43.71 KB, patch)
2019-01-21 05:45 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v5 (43.77 KB, patch)
2019-01-21 06:15 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v6 (43.48 KB, patch)
2019-01-21 06:42 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews104 for mac-highsierra-wk2 (524.84 KB, application/zip)
2019-01-21 07:35 PST, Build Bot
no flags Details
Archive of layout-test-results from ews123 for ios-simulator-wk2 (417.78 KB, application/zip)
2019-01-21 07:47 PST, Build Bot
no flags Details
Patch v7 (45.19 KB, patch)
2019-01-28 16:00 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews106 for mac-highsierra-wk2 (1.26 MB, application/zip)
2019-01-28 17:24 PST, Build Bot
no flags Details
Archive of layout-test-results from ews121 for ios-simulator-wk2 (446.76 KB, application/zip)
2019-01-29 00:17 PST, Build Bot
no flags Details
Patch v8 (39.83 KB, patch)
2019-02-01 07:29 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v9 (39.93 KB, patch)
2019-02-03 06:31 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v10 (39.88 KB, patch)
2019-02-04 02:37 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v11 (42.73 KB, patch)
2019-02-07 14:16 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v12 (43.38 KB, patch)
2019-02-07 14:39 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v13 (43.36 KB, patch)
2019-02-07 14:59 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v14 (43.44 KB, patch)
2019-02-09 15:19 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v15 (43.49 KB, patch)
2019-02-10 04:44 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v16 (43.42 KB, patch)
2019-02-10 14:48 PST, Adrian Perez
no flags Details | Formatted Diff | Diff
Patch v17 (38.70 KB, patch)
2019-02-11 14:23 PST, Adrian Perez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Perez 2019-01-20 12:24:27 PST
This is intended to be landed before the API for the GTK+ and WPE
ports (see bug #167941 for that), in order to make sure that the
layout tests for content extensions also can be run by these two
ports.
Comment 1 Adrian Perez 2019-01-20 15:22:59 PST
Created attachment 359655 [details]
Patch


Initial version of the patch for review, needs adding some
commentary on the ChangeLogs, and for some reason I am having
some troubles to run the tests for the WPE port (WKTR is not
cooperating well with Weston in my machine), so I will give
it another go tomorrow to mark more tests as passing for WPE.

Anyway, this is basically working well to run the tests for
the GTK+ port, with some flakyness, and soon I should have
them running for WPE as well. So I think that reviewin can
start :-)
Comment 2 Build Bot 2019-01-20 15:26:14 PST
Attachment 359655 [details] did not pass style-queue:


ERROR: Tools/WebKitTestRunner/TestController.cpp:37:  Alphabetical sorting problem.  [build/include_order] [4]
ERROR: Tools/WebKitTestRunner/TestController.cpp:1333:  Declaration has space between type name and * in auto *context  [whitespace/declaration] [3]
ERROR: Source/WebCore/ChangeLog:8:  You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible.  [changelog/nonewtests] [5]
Total errors found: 3 in 23 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Michael Catanzaro 2019-01-20 19:40:13 PST
Comment on attachment 359655 [details]
Patch

All EWS are red!
Comment 4 Adrian Perez 2019-01-20 23:36:40 PST
(In reply to Michael Catanzaro from comment #3)
> Comment on attachment 359655 [details]
> Patch
> 
> All EWS are red!

Indeed :\

I think it's a small bit related to the older compiler version that
the EWS bots are using. For the Cocoa bots, there's some files now
listed in Sources.txt which have to be removed from SourcesCocoa.txt
to avoid the error about the duplicated source file. I'll also fix
the style bot complaints before reuploading :)
Comment 5 Adrian Perez 2019-01-21 00:20:44 PST
Created attachment 359674 [details]
Patch v2

Should fix build in the EWS bots, and also make
the style checker happy. ChangeLog entries now have descriptions, too.
Comment 6 Adrian Perez 2019-01-21 01:01:52 PST
Created attachment 359676 [details]
Patch v3

Should fix the build for th GTK+ and WPE bots now.
Comment 7 Adrian Perez 2019-01-21 04:25:11 PST
(In reply to Adrian Perez from comment #6)
> Created attachment 359676 [details]
> Patch v3
> 
> Should fix the build for th GTK+ and WPE bots now.

The build failure for the Cocoa ports is due to the following:

  In file included from /Volumes/Data/EWS/WebKit/WebKitBuild/Debug/DerivedSources/WebKit2/unified-sources/UnifiedSource41.cpp:5:
  /Volumes/Data/EWS/WebKit/Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:49:56:
  error: 'operator new' is a protected member of 'API::ObjectImpl<API::Object::Type::ContentRuleListStore>'
      RefPtr<API::ContentRuleListStore> store = adoptRef(new API::ContentRuleListStore(toWTFString(path), false));
                                                         ^
  In file included from /Volumes/Data/EWS/WebKit/WebKitBuild/Debug/DerivedSources/WebKit2/unified-sources/UnifiedSource41.cpp:1:
  In file included from /Volumes/Data/EWS/WebKit/Source/WebKit/UIProcess/API/C/WKResourceCacheManager.cpp:29:
  In file included from /Volumes/Data/EWS/WebKit/Source/WebKit/Shared/API/APIArray.h:29:
  /Volumes/Data/EWS/WebKit/Source/WebKit/Shared/API/APIObject.h:265:11: note: declared protected here
      void* operator new(size_t size) { return newObject(size, APIType); }
            ^
  1 error generated.

I'll see to it and upload and updated patch.
Comment 8 Adrian Perez 2019-01-21 05:45:53 PST
Created attachment 359685 [details]
Patch v4


This version should solve the build issue for the Cocoa ports.
Comment 9 Adrian Perez 2019-01-21 06:15:31 PST
Created attachment 359687 [details]
Patch v5
Comment 10 Adrian Perez 2019-01-21 06:42:30 PST
Created attachment 359689 [details]
Patch v6

Avoids including WKAPICast.h in TestController.cpp
(which is unneeded anyway).
Comment 11 Build Bot 2019-01-21 07:35:18 PST
Comment on attachment 359689 [details]
Patch v6

Attachment 359689 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/10829510

Number of test failures exceeded the failure limit.
Comment 12 Build Bot 2019-01-21 07:35:20 PST
Created attachment 359690 [details]
Archive of layout-test-results from ews104 for mac-highsierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews104  Port: mac-highsierra-wk2  Platform: Mac OS X 10.13.6
Comment 13 Build Bot 2019-01-21 07:47:12 PST
Comment on attachment 359689 [details]
Patch v6

Attachment 359689 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: https://webkit-queues.webkit.org/results/10829463

Number of test failures exceeded the failure limit.
Comment 14 Build Bot 2019-01-21 07:47:13 PST
Created attachment 359691 [details]
Archive of layout-test-results from ews123 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews123  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.6
Comment 15 Adrian Perez 2019-01-23 09:45:20 PST
Ping reviewers :)
Comment 16 Michael Catanzaro 2019-01-23 10:17:33 PST
(In reply to Build Bot from comment #13)
> Comment on attachment 359689 [details]
> Patch v6
> 
> Attachment 359689 [details] did not pass ios-sim-ews (ios-simulator-wk2):
> Output: https://webkit-queues.webkit.org/results/10829463
> 
> Number of test failures exceeded the failure limit.

I think you broke WebKitTestRunner on the ios-sim and mac-wk2 EWS.
Comment 17 Loïc Yhuel 2019-01-23 15:29:38 PST
Comment on attachment 359689 [details]
Patch v6

View in context: https://bugs.webkit.org/attachment.cgi?id=359689&action=review

> Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp:37
> +#include <gio/gfiledescriptorbased.h>

I didn't try to build this patch on trunk (I'm testing on WPE 2.20), so I may have missed something, but how do you get GIO_UNIX_INCLUDE_DIRS here ?
I only see it in WebCore platform code.

> Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp:133
> +#if USE(GLIB)

Shouldn't this be "#if USE(GLIB) && !PLATFORM(WIN)" to match the definition in Source/WebCore/platform/FileSystem.h ?
I'm not sure this source could be built on Windows, but using soup without USE(GLIB) probably wouldn't work either.

> Source/WebKit/UIProcess/API/glib/APIContentRuleListStoreGLib.cpp:31
> +String ContentRuleListStore::defaultStorePath(bool)

#if ENABLE(CONTENT_EXTENSIONS) is needed around the function definition, since the class isn't defined without the flag.

> Source/cmake/OptionsGTK.cmake:153
> +WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CONTENT_EXTENSIONS PRIVATE ON)

It looks like the options should be in alphabetical order.
Comment 18 Carlos Garcia Campos 2019-01-25 04:49:41 PST
Comment on attachment 359689 [details]
Patch v6

View in context: https://bugs.webkit.org/attachment.cgi?id=359689&action=review

> Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp:139
> +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);
> +}

I find a bit weird that APIContentRuleListStore.cpp from UI process uses NetworekDataCache from the Network process. Would it be possible to use SharedBuffer::createWithContentsOfFile() instead? Otherwise I wonder if it would be better to add FileSystem::fileDescriptor(PlatformFileHandle); with this impl for glib based ports and use it in  APIContentRuleListStore.cpp.

> Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:60
> +    if (error) {

Ww could use an early return here if !error

> Tools/WebKitTestRunner/TestController.cpp:1095
> -        return std::string(buffer.data(), length);
> +        return std::string(buffer.data(), length - 1);

Can length be 0 here?

> Tools/WebKitTestRunner/TestController.cpp:1328
> +    WKRetainPtr<WKUserContentFilterRef> filter { nullptr };

No need to initialize to nullptr here, since that's the default of WKRetainPtr.

> Tools/WebKitTestRunner/TestController.cpp:1341
> +static std::string contentExtensionJsonPath(WKURLRef url)

Json -> JSON?
Comment 19 Carlos Garcia Campos 2019-01-25 05:27:23 PST
Comment on attachment 359689 [details]
Patch v6

View in context: https://bugs.webkit.org/attachment.cgi?id=359689&action=review

> Tools/WebKitTestRunner/TestController.cpp:1414
> +    auto userContentController = adoptWK(WKPageConfigurationGetUserContentController(pageConfiguration.get()));
> +    ASSERT(userContentController);
> +
> +    WKUserContentControllerRemoveAllUserContentFilters(userContentController.get());

I think the problem in cocoa is that userContentController is nullptr here. Note that user content controller is set with WKPageConfigurationSetUserContentController in TestController::generatePageConfiguration(). The generated page configuration is then passed to platformCreateWebView() and the cocoa implementation simply ignores the given WKPageConfigurationRef and used a global WKWebViewConfiguration to create the PlatformWebView.
Comment 20 Adrian Perez 2019-01-28 14:01:47 PST
(In reply to Loïc Yhuel from comment #17)
> Comment on attachment 359689 [details]
> Patch v6
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=359689&action=review
> 
> > Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp:37
> > +#include <gio/gfiledescriptorbased.h>
> 
> I didn't try to build this patch on trunk (I'm testing on WPE 2.20), so I
> may have missed something, but how do you get GIO_UNIX_INCLUDE_DIRS here ?
> I only see it in WebCore platform code.

This is added for WebCore in “Source/WebCore/Platform{GTK,WPE}.cmake”,
and CMake propagates the build flags because the main WebKit library
depends on the WebCore one :)

> > Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp:133
> > +#if USE(GLIB)
> 
> Shouldn't this be "#if USE(GLIB) && !PLATFORM(WIN)" to match the definition
> in Source/WebCore/platform/FileSystem.h ?
> I'm not sure this source could be built on Windows, but using soup without
> USE(GLIB) probably wouldn't work either.

Good point, I will be updating the patch to use this condition for the
guards (also above for the inclusion of “gfiledescriptorbased.h“, which
won't work in Windows either).

> > Source/WebKit/UIProcess/API/glib/APIContentRuleListStoreGLib.cpp:31
> > +String ContentRuleListStore::defaultStorePath(bool)
> 
> #if ENABLE(CONTENT_EXTENSIONS) is needed around the function definition,
> since the class isn't defined without the flag.

Or even better: guard building of the file altogether by using

  #if ENABLE_CONTENT_EXTENSIONS
  UIProcess/API/glib/APIContentRuleListStoreGLib.cpp @no-unify
  #endif

in the “Sources{GTK,WPE}.cmake” files -- one less file to build if the
feature is disabled!

> > Source/cmake/OptionsGTK.cmake:153
> > +WEBKIT_OPTION_DEFAULT_PORT_VALUE(ENABLE_CONTENT_EXTENSIONS PRIVATE ON)
> 
> It looks like the options should be in alphabetical order.

Indeed, I'll reorder those.
Comment 21 Adrian Perez 2019-01-28 14:52:26 PST
(In reply to Carlos Garcia Campos from comment #18)
> Comment on attachment 359689 [details]
> Patch v6
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=359689&action=review
> 
> > Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp:139
> > +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);
> > +}
> 
> I find a bit weird that APIContentRuleListStore.cpp from UI process uses
> NetworekDataCache from the Network process. Would it be possible to use
> SharedBuffer::createWithContentsOfFile() instead? Otherwise I wonder if it
> would be better to add FileSystem::fileDescriptor(PlatformFileHandle); with
> this impl for glib based ports and use it in  APIContentRuleListStore.cpp.

My guess is that NetworkCache::Data was picked here was because of is
utility methods, which are used all over the place. While it looks like
it would be possible to refactor things around, I would rather do it in
a separate bug, and not at this moment where we are close to branching
for 2.24.x -- it seems risky if we want 2.24 to include content extension
support.

> > Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:60
> > +    if (error) {
> 
> Ww could use an early return here if !error

Will do.

> > Tools/WebKitTestRunner/TestController.cpp:1095
> > -        return std::string(buffer.data(), length);
> > +        return std::string(buffer.data(), length - 1);
> 
> Can length be 0 here?

No. Passing just “length” here is wrong, and took me a couple of days
to figure out this was the reason why paths were not being constructed
correctly: the calculated “length” *includes* one byte for the null
terminator ('\0'), so passing “length - 1” ensures that the null
terminator does NOT end up as part of the created std::string.

Let's say we have a WKStringRef which contains “foo”:

 1. The “length” will be 4 (three characters + null terminator).

 2. The created std::string will have contents “foo\0”

 3. When appending to it, for example to add the “.json” suffix, we
    end up with a new std:string with contents “foo\0.json”.

 4. Using printf("%s\n", fooWithSuffix.c_str()), the returned value
    points to a buffer which contains “foo\0.json\0” because the
    std::string::c_str() method adds another null terminator, but
    only “foo” is printed because C string functions will see only
    the data buffer until the first null terminator!

> > Tools/WebKitTestRunner/TestController.cpp:1328
> > +    WKRetainPtr<WKUserContentFilterRef> filter { nullptr };
> 
> No need to initialize to nullptr here, since that's the default of
> WKRetainPtr.

Indeed, thanks.

> > Tools/WebKitTestRunner/TestController.cpp:1341
> > +static std::string contentExtensionJsonPath(WKURLRef url)
> 
> Json -> JSON?

Yes, JSON seems to be more in tune with the style of the rest
of the WebKit code. I'll change this.
Comment 22 Adrian Perez 2019-01-28 15:33:24 PST
(In reply to Carlos Garcia Campos from comment #19)
> Comment on attachment 359689 [details]
> Patch v6
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=359689&action=review
> 
> > Tools/WebKitTestRunner/TestController.cpp:1414
> > +    auto userContentController = adoptWK(WKPageConfigurationGetUserContentController(pageConfiguration.get()));
> > +    ASSERT(userContentController);
> > +
> > +    WKUserContentControllerRemoveAllUserContentFilters(userContentController.get());
> 
> I think the problem in cocoa is that userContentController is nullptr here.
> Note that user content controller is set with
> WKPageConfigurationSetUserContentController in
> TestController::generatePageConfiguration(). The generated page
> configuration is then passed to platformCreateWebView() and the cocoa
> implementation simply ignores the given WKPageConfigurationRef and used a
> global WKWebViewConfiguration to create the PlatformWebView.

Ouch, ouch! It looks like this can be solved by adding a
TestController::userContentController() accessor, which for the
GTK/WPE ports will use the current code (that is: picking it from
the page configuration) and for Cocoa it picks the object from the
global WKWebViewConfiguration somehow.
Comment 23 Adrian Perez 2019-01-28 16:00:27 PST
Created attachment 360393 [details]
Patch v7


The Cocoa port uses a global WKWebViewConfiguration. Add an accesor
TestController::userContentController() which picks the user content
controller from the global for the Cocoa port, and from the current
page configuration for the other ports.

This also addresses the rest of review comments by Carlos García and
Loïc Yhuel (thanks!)
Comment 24 Build Bot 2019-01-28 17:24:36 PST
Comment on attachment 360393 [details]
Patch v7

Attachment 360393 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/10930350

Number of test failures exceeded the failure limit.
Comment 25 Build Bot 2019-01-28 17:24:38 PST
Created attachment 360405 [details]
Archive of layout-test-results from ews106 for mac-highsierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews106  Port: mac-highsierra-wk2  Platform: Mac OS X 10.13.6
Comment 26 Adrian Perez 2019-01-28 17:26:07 PST
(In reply to Adrian Perez from comment #23)
> Created attachment 360393 [details]
> Patch v7
>
> The Cocoa port uses a global WKWebViewConfiguration. Add an accesor
> TestController::userContentController() which picks the user content
> controller from the global for the Cocoa port, and from the current
> page configuration for the other ports.

That didn't cut it either, *sigh* :|

I am getting tempted to revert the changes to TestControllerCocoa.mm,
and leave it to use the previous existing code to configure content
extensions, and have the new bits in TestController.cpp in between
#if !PLATFORM(COCOA) guards; then unify the Cocoa and non-Cocoa setup
for content extensions in a follow-up patch with cleanups. At least
that would get this unblocked... Opinions?
Comment 27 Build Bot 2019-01-29 00:17:47 PST
Comment on attachment 360393 [details]
Patch v7

Attachment 360393 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: https://webkit-queues.webkit.org/results/10935055

Number of test failures exceeded the failure limit.
Comment 28 Build Bot 2019-01-29 00:17:49 PST
Created attachment 360450 [details]
Archive of layout-test-results from ews121 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews121  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.6
Comment 29 Carlos Garcia Campos 2019-01-29 02:19:56 PST
Comment on attachment 359689 [details]
Patch v6

View in context: https://bugs.webkit.org/attachment.cgi?id=359689&action=review

>>> Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp:139
>>> +}
>> 
>> I find a bit weird that APIContentRuleListStore.cpp from UI process uses NetworekDataCache from the Network process. Would it be possible to use SharedBuffer::createWithContentsOfFile() instead? Otherwise I wonder if it would be better to add FileSystem::fileDescriptor(PlatformFileHandle); with this impl for glib based ports and use it in  APIContentRuleListStore.cpp.
> 
> My guess is that NetworkCache::Data was picked here was because of is
> utility methods, which are used all over the place. While it looks like
> it would be possible to refactor things around, I would rather do it in
> a separate bug, and not at this moment where we are close to branching
> for 2.24.x -- it seems risky if we want 2.24 to include content extension
> support.

I agree, but I still think the code to get a fd from a PlatformFileHandle doesn't belong here, but in Filesystem.

>>> Tools/WebKitTestRunner/TestController.cpp:1095
>>> +        return std::string(buffer.data(), length - 1);
>> 
>> Can length be 0 here?
> 
> No. Passing just “length” here is wrong, and took me a couple of days
> to figure out this was the reason why paths were not being constructed
> correctly: the calculated “length” *includes* one byte for the null
> terminator ('\0'), so passing “length - 1” ensures that the null
> terminator does NOT end up as part of the created std::string.
> 
> Let's say we have a WKStringRef which contains “foo”:
> 
>  1. The “length” will be 4 (three characters + null terminator).
> 
>  2. The created std::string will have contents “foo\0”
> 
>  3. When appending to it, for example to add the “.json” suffix, we
>     end up with a new std:string with contents “foo\0.json”.
> 
>  4. Using printf("%s\n", fooWithSuffix.c_str()), the returned value
>     points to a buffer which contains “foo\0.json\0” because the
>     std::string::c_str() method adds another null terminator, but
>     only “foo” is printed because C string functions will see only
>     the data buffer until the first null terminator!

That was not my question. I wonder if length can be 0, because then we will end up passing -1 to std::string().
Comment 30 Carlos Garcia Campos 2019-01-29 02:31:12 PST
(In reply to Adrian Perez from comment #26)
> (In reply to Adrian Perez from comment #23)
> > Created attachment 360393 [details]
> > Patch v7
> >
> > The Cocoa port uses a global WKWebViewConfiguration. Add an accesor
> > TestController::userContentController() which picks the user content
> > controller from the global for the Cocoa port, and from the current
> > page configuration for the other ports.
> 
> That didn't cut it either, *sigh* :|
> 
> I am getting tempted to revert the changes to TestControllerCocoa.mm,
> and leave it to use the previous existing code to configure content
> extensions, and have the new bits in TestController.cpp in between
> #if !PLATFORM(COCOA) guards; then unify the Cocoa and non-Cocoa setup
> for content extensions in a follow-up patch with cleanups. At least
> that would get this unblocked... Opinions?

Sounds good.
Comment 31 Loïc Yhuel 2019-01-29 03:57:33 PST
(In reply to Carlos Garcia Campos from comment #18)
> I find a bit weird that APIContentRuleListStore.cpp from UI process uses
> NetworekDataCache from the Network process. Would it be possible to use
> SharedBuffer::createWithContentsOfFile() instead?
SharedBuffer::createWithContentsOfFile() would reopen the file, perhaps a new SharedBuffer::createFromFile(PlatformFileHandle&&).

(In reply to Adrian Perez from comment #20)
> (In reply to Loïc Yhuel from comment #17)
> > Comment on attachment 359689 [details]
> > Patch v6
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=359689&action=review
> > 
> > > Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp:37
> > > +#include <gio/gfiledescriptorbased.h>
> > 
> > I didn't try to build this patch on trunk (I'm testing on WPE 2.20), so I
> > may have missed something, but how do you get GIO_UNIX_INCLUDE_DIRS here ?
> > I only see it in WebCore platform code.
> 
> This is added for WebCore in “Source/WebCore/Platform{GTK,WPE}.cmake”,
> and CMake propagates the build flags because the main WebKit library
> depends on the WebCore one :)
> 
But GIO_UNIX_INCLUDE_DIRS is in WebCore_SYSTEM_INCLUDE_DIRECTORIES, and the WEBKIT_FRAMEWORK macro declares those as PRIVATE.
Comment 32 Adrian Perez 2019-02-01 07:29:31 PST
(In reply to Loïc Yhuel from comment #31)
> (In reply to Carlos Garcia Campos from comment #18)
> > I find a bit weird that APIContentRuleListStore.cpp from UI process uses
> > NetworekDataCache from the Network process. Would it be possible to use
> > SharedBuffer::createWithContentsOfFile() instead?
> SharedBuffer::createWithContentsOfFile() would reopen the file, perhaps a
> new SharedBuffer::createFromFile(PlatformFileHandle&&).

In my mind the suggestion to add a SharedBuffer::createFromFile()
sounds the better. Would it be okay to over to that later on as a
follow-up patch?

> (In reply to Adrian Perez from comment #20)
> > (In reply to Loïc Yhuel from comment #17)
> > > Comment on attachment 359689 [details]
> > > Patch v6
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=359689&action=review
> > > 
> > > > Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp:37
> > > > +#include <gio/gfiledescriptorbased.h>
> > > 
> > > I didn't try to build this patch on trunk (I'm testing on WPE 2.20), so I
> > > may have missed something, but how do you get GIO_UNIX_INCLUDE_DIRS here ?
> > > I only see it in WebCore platform code.
> > 
> > This is added for WebCore in “Source/WebCore/Platform{GTK,WPE}.cmake”,
> > and CMake propagates the build flags because the main WebKit library
> > depends on the WebCore one :)
> > 
> But GIO_UNIX_INCLUDE_DIRS is in WebCore_SYSTEM_INCLUDE_DIRECTORIES, and the
> WEBKIT_FRAMEWORK macro declares those as PRIVATE.

I'll try to take a look, but definitely the build works fine for both
GTK+ and WPE ports, and the bots seem to agree. ~_~
Comment 33 Adrian Perez 2019-02-01 07:29:54 PST
Created attachment 360861 [details]
Patch v8


Reverted the Cocoa/Mac bits, hopefully this will keep the EWS bots
happy and we can get this landed; then later on do a follow-up patch
to make Cocoa use the C API as well.
Comment 34 Adrian Perez 2019-02-01 07:32:03 PST
(In reply to Carlos Garcia Campos from comment #29)
> Comment on attachment 359689 [details]
> Patch v6
>
> [...]
>
> >>> Tools/WebKitTestRunner/TestController.cpp:1095
> >>> +        return std::string(buffer.data(), length - 1);
> >> 
> >> Can length be 0 here?
> > 
> > No. Passing just “length” here is wrong, and took me a couple of days
> > to figure out this was the reason why paths were not being constructed
> > correctly: the calculated “length” *includes* one byte for the null
> > terminator ('\0'), so passing “length - 1” ensures that the null
> > terminator does NOT end up as part of the created std::string.
> > 
> > Let's say we have a WKStringRef which contains “foo”:
> > 
> >  1. The “length” will be 4 (three characters + null terminator).
> > 
> >  2. The created std::string will have contents “foo\0”
> > 
> >  3. When appending to it, for example to add the “.json” suffix, we
> >     end up with a new std:string with contents “foo\0.json”.
> > 
> >  4. Using printf("%s\n", fooWithSuffix.c_str()), the returned value
> >     points to a buffer which contains “foo\0.json\0” because the
> >     std::string::c_str() method adds another null terminator, but
> >     only “foo” is printed because C string functions will see only
> >     the data buffer until the first null terminator!
> 
> That was not my question. I wonder if length can be 0, because then we will
> end up passing -1 to std::string().

Very good question. I have been assuming that for an empty string
then WKStringGetMaximumUTF8CStringSize() would return “1”, so then
there's at least one byte where to place the null-terminator. I'll
double check before landing.
Comment 35 Adrian Perez 2019-02-01 08:35:59 PST
(In reply to Adrian Perez from comment #34)
> (In reply to Carlos Garcia Campos from comment #29)
> > Comment on attachment 359689 [details]
> > Patch v6
> >
> > [...]
> >
> > >>> Tools/WebKitTestRunner/TestController.cpp:1095
> > >>> +        return std::string(buffer.data(), length - 1);
> > >> 
> > >> Can length be 0 here?
> > > 
> > > No. Passing just “length” here is wrong, and took me a couple of days
> > > to figure out this was the reason why paths were not being constructed
> > > correctly: the calculated “length” *includes* one byte for the null
> > > terminator ('\0'), so passing “length - 1” ensures that the null
> > > terminator does NOT end up as part of the created std::string.
> > > 
> > > Let's say we have a WKStringRef which contains “foo”:
> > > 
> > >  1. The “length” will be 4 (three characters + null terminator).
> > > 
> > >  2. The created std::string will have contents “foo\0”
> > > 
> > >  3. When appending to it, for example to add the “.json” suffix, we
> > >     end up with a new std:string with contents “foo\0.json”.
> > > 
> > >  4. Using printf("%s\n", fooWithSuffix.c_str()), the returned value
> > >     points to a buffer which contains “foo\0.json\0” because the
> > >     std::string::c_str() method adds another null terminator, but
> > >     only “foo” is printed because C string functions will see only
> > >     the data buffer until the first null terminator!
> > 
> > That was not my question. I wonder if length can be 0, because then we will
> > end up passing -1 to std::string().
> 
> Very good question. I have been assuming that for an empty string
> then WKStringGetMaximumUTF8CStringSize() would return “1”, so then
> there's at least one byte where to place the null-terminator. I'll
> double check before landing.

Indeed, the function to get the size of the bufer always adds one extra
for the null terminator:

  size_t WKStringGetMaximumUTF8CStringSize(WKStringRef stringRef)
  {
      return WebKit::toImpl(stringRef)->stringView().length() * 3 + 1;
  }

As for the “length” returned by WKStringGetUTF8CString(), it calls
an internal function which end like this:

  size_t WKStringGetUTF8CStringImpl(...)
  {
      /* ... */

      *p++ = '\0';
      return p - buffer;
  }

The “p” pointer stores has the address of the null terminator *plus one*,
which means that (p - buffer) returns 1 for an empty string. There are two
cases in which it can return zero, though: when the “bufferSize” parameter
passed to WKStringGetUTF8CString() is zero, or when conversion to UTF-8
fails -- and we should not be hitting any of those in WKTR, ever :)

I can add a check for “length > 0” (an assertion, maybe?) if you think
that would make things clearer.
Comment 36 Michael Catanzaro 2019-02-02 14:58:27 PST
Comment on attachment 360861 [details]
Patch v8

View in context: https://bugs.webkit.org/attachment.cgi?id=360861&action=review

This needs owner approval to land, so please find an owner to approve it.

> Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp:241
> -        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 {

You've already captured this. Why are you adding this here? Is it a bug in old GCC?

> Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:49
> +    RefPtr<API::ContentRuleListStore> store(API::ContentRuleListStore::storeWithPath(toWTFString(path), false));

I've never understood the C/C++ APIs... do you really not need to adopt the ref?

> Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.h:48
> +
> +

Is the style really two blank lines?

> Tools/Scripts/webkitperl/FeatureList.pm:65
> +    $contentExtensionsSupport,
>      $cloopSupport,

It belongs under cloop.
Comment 37 Adrian Perez 2019-02-03 05:47:48 PST
(In reply to Michael Catanzaro from comment #36)
> Comment on attachment 360861 [details]
> Patch v8
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=360861&action=review
> 
> This needs owner approval to land, so please find an owner to approve it.

Sure :)

> > Source/WebKit/NetworkProcess/NetworkLoadChecker.cpp:241
> > -        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 {
> 
> You've already captured this. Why are you adding this here? Is it a bug in
> old GCC?

Seems to be a bug in some versions of GCC (for example the version of
GCC6 in some EWS bots, and IIRC the one in the Ubuntu LTS one), which
will complain that the “processContentExtensionRulesForLoad()” method
is not defined in the current scope ¯\_(ツ)_/¯ 

> > Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:49
> > +    RefPtr<API::ContentRuleListStore> store(API::ContentRuleListStore::storeWithPath(toWTFString(path), false));
> 
> I've never understood the C/C++ APIs... do you really not need to adopt the
> ref?

There is no need to adopt. WTF::String itself is always stack-allocated,
so if you ever see a  RefPtr<String>... be suspicious.

(Longer explanation: the WTF::String contains internally a RefPtr<StringImpl>
member, and that is what gets used so multiple WTF::String instances can
share the same underlying contents; destroying and creating WTF::String
instances e.g. when passing copies to functions just changes the refcount
of the internal member.)

> > Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.h:48
> > +
> > +
> 
> Is the style really two blank lines?

Not really, but somehow the style checker didn't complain. I'll make
this just one extra empty line go away. Reading other files in the same
directory I see that usually the “typedef” is above the “enum” so I'll
change that as well.

> > Tools/Scripts/webkitperl/FeatureList.pm:65
> > +    $contentExtensionsSupport,
> >      $cloopSupport,
> 
> It belongs under cloop.

Yup, will change.
Comment 38 Adrian Perez 2019-02-03 06:04:10 PST
(In reply to Adrian Perez from comment #35)
 
> As for the “length” returned by WKStringGetUTF8CString() [...]
> 
> I can add a check for “length > 0” (an assertion, maybe?) if you think
> that would make things clearer.

The next version of the patch will have an assertion here to make
it explicit that the expectation is that the length is non-zero.
Comment 39 Adrian Perez 2019-02-03 06:31:15 PST
Created attachment 361013 [details]
Patch v9


This just contains a few minor edits: an assertion added in TestController.cpp
and a couple of for style issues not caught by the style checker.
Comment 40 Adrian Perez 2019-02-03 06:46:39 PST
(In reply to Michael Catanzaro from comment #36)

> Comment on attachment 360861 [details]
> Patch v8
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=360861&action=review
> 
> This needs owner approval to land, so please find an owner to approve it.

I had already Alex Christensen in CC, plus now added Chris Dumez
and Darin Adler who have been also making fixes and code reviews
for content extensions.
Comment 41 Michael Catanzaro 2019-02-03 11:59:36 PST
(In reply to Adrian Perez from comment #37)
> > > Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:49
> > > +    RefPtr<API::ContentRuleListStore> store(API::ContentRuleListStore::storeWithPath(toWTFString(path), false));
> > 
> > I've never understood the C/C++ APIs... do you really not need to adopt the
> > ref?
> 
> There is no need to adopt. WTF::String itself is always stack-allocated,
> so if you ever see a  RefPtr<String>... be suspicious.

I meant: doesn't the result of API::ContentRuleListStore::storeWithPath already have a ref? Then the RefPtr takes a second ref, right? Then when you leakRef it on the next line, there are two outstanding? Instead of the one you expect?
Comment 42 Michael Catanzaro 2019-02-03 13:58:33 PST
Have you investigated why so many of the tests are crashing?
Comment 43 Adrian Perez 2019-02-03 15:03:04 PST
(In reply to Michael Catanzaro from comment #41)
> (In reply to Adrian Perez from comment #37)
> > > > Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:49
> > > > +    RefPtr<API::ContentRuleListStore> store(API::ContentRuleListStore::storeWithPath(toWTFString(path), false));
> > > 
> > > I've never understood the C/C++ APIs... do you really not need to adopt the
> > > ref?
> > 
> > There is no need to adopt. WTF::String itself is always stack-allocated,
> > so if you ever see a  RefPtr<String>... be suspicious.
> 
> I meant: doesn't the result of API::ContentRuleListStore::storeWithPath
> already have a ref? Then the RefPtr takes a second ref, right? Then when you
> leakRef it on the next line, there are two outstanding? Instead of the one
> you expect?

Ahh, I get it know. You are absolute right, this has to be changed.
Looking around the other source files in the directory, it seems that
the usual is directly returning without even keeping a RefPtr<> around
for one-liner constructors. Therefore I am going to change this into:

   return toAPI(API::ContentRuleListStore::storeWithPath(toWTFString(path), false);
Comment 44 Adrian Perez 2019-02-03 15:11:25 PST
(In reply to Adrian Perez from comment #43)
> (In reply to Michael Catanzaro from comment #41)
>
>> [...]
> 
> Ahh, I get it know. You are absolute right, this has to be changed.
> Looking around the other source files in the directory, it seems that
> the usual is directly returning without even keeping a RefPtr<> around
> for one-liner constructors. Therefore I am going to change this into:
> 
>    return toAPI(API::ContentRuleListStore::storeWithPath(toWTFString(path),
> false);

Correction:

  return toAPI(&API::ContentRuleListStore::storeWithPath(toWTFString(path), false).leakRef());

(:
Comment 45 Adrian Perez 2019-02-04 02:37:21 PST
Created attachment 361047 [details]
Patch v10


Fixes the WKUserContentExtensionStoreCreate() function to return new
objects with only one ref in them.
Comment 46 Loïc Yhuel 2019-02-04 04:38:00 PST
(In reply to Adrian Perez from comment #32)
> (In reply to Loïc Yhuel from comment #31)
> > (In reply to Adrian Perez from comment #20)
> > > (In reply to Loïc Yhuel from comment #17)
> > > > Comment on attachment 359689 [details]
> > > > Patch v6
> > > > 
> > > > View in context:
> > > > https://bugs.webkit.org/attachment.cgi?id=359689&action=review
> > > > 
> > > > > Source/WebKit/NetworkProcess/cache/NetworkCacheDataSoup.cpp:37
> > > > > +#include <gio/gfiledescriptorbased.h>
> > > > 
> > > > I didn't try to build this patch on trunk (I'm testing on WPE 2.20), so I
> > > > may have missed something, but how do you get GIO_UNIX_INCLUDE_DIRS here ?
> > > > I only see it in WebCore platform code.
> > > 
> > > This is added for WebCore in “Source/WebCore/Platform{GTK,WPE}.cmake”,
> > > and CMake propagates the build flags because the main WebKit library
> > > depends on the WebCore one :)
> > > 
> > But GIO_UNIX_INCLUDE_DIRS is in WebCore_SYSTEM_INCLUDE_DIRECTORIES, and the
> > WEBKIT_FRAMEWORK macro declares those as PRIVATE.
> 
> I'll try to take a look, but definitely the build works fine for both
> GTK+ and WPE ports, and the bots seem to agree. ~_~

In fact :
 - for GTK, it's already indirectly in GTK_INCLUDE_DIRS and GTK_INCLUDE_DIRS
 - for WPE, it only relies on WebCore_SYSTEM_INCLUDE_DIRECTORIES being in WebCoreHeaderInterface, we is IHMO a little overkill (but since there are already quite a lot of include paths, it probably doesn't really matter)
Comment 47 Michael Catanzaro 2019-02-04 07:11:56 PST
Comment on attachment 361047 [details]
Patch v10

r=me is conditional on getting owner approval.

I do wish we knew why there is a huge amount of broken tests, but this commit just makes it possible to test, so no reason to delay on that.
Comment 48 youenn fablet 2019-02-04 09:00:15 PST
Comment on attachment 361047 [details]
Patch v10

View in context: https://bugs.webkit.org/attachment.cgi?id=361047&action=review

> Tools/WebKitTestRunner/TestController.cpp:835
> +    m_serverTrustEvaluationCallbackCallsCount = 0;

Is this line needed?

> Tools/WebKitTestRunner/TestController.cpp:836
> +    resetContentExtensions();

Cocoa WTR currently reset these in platformResetStateToConsistentValues.
I guess we should try to align both approaches.
For instance, resetContentExtensions() could be called from resetStateToConsistentValues and cocoa would move its code to resetContentExtensions(), in this patch or as a follow-up.

> LayoutTests/platform/wpe/TestExpectations:1267
> +http/tests/contentextensions/async-xhr-onerror.html [ Crash ]

What is causing all these tests to crash?
Comment 49 Alex Christensen 2019-02-04 10:25:54 PST
Comment on attachment 361047 [details]
Patch v10

View in context: https://bugs.webkit.org/attachment.cgi?id=361047&action=review

> Source/WebKit/SourcesGTK.txt:127
> +#if ENABLE_CONTENT_EXTENSIONS
> +UIProcess/API/glib/APIContentRuleListStoreGLib.cpp @no-unify

Just unconditionally include the file.  Preprocessor-like things seem out of place in this file.

> Source/WebKit/SourcesWPE.txt:112
> +#if ENABLE_CONTENT_EXTENSIONS

ditto

> Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:33
> +#include "WKRetainPtr.h"
> +#include <wtf/Function.h>

These don't seem used.

> LayoutTests/platform/gtk/TestExpectations:126
> +# Content extensions, the failures need up-to-date expectations. The crashing tests do so in a flaky way.

You should probably fix these "flaky crashes" before landing it.  Check that your memory mapped file is not being unmapped somehow.
Comment 50 Loïc Yhuel 2019-02-04 11:05:19 PST
(In reply to Alex Christensen from comment #49)
> Comment on attachment 361047 [details]
> Patch v10
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=361047&action=review
> 
> > Source/WebKit/SourcesGTK.txt:127
> > +#if ENABLE_CONTENT_EXTENSIONS
> > +UIProcess/API/glib/APIContentRuleListStoreGLib.cpp @no-unify
> 
> Just unconditionally include the file.  Preprocessor-like things seem out of
> place in this file.
So you prefer an "#if ENABLE(CONTENT_EXTENSIONS)" in the source ?
Comment 51 Michael Catanzaro 2019-02-04 12:58:20 PST
I suppose. We don't really have a rule, but I agree the build system is easier to maintain if we build most files unconditionally and just have appropriate include guards in the source.
Comment 52 Adrian Perez 2019-02-07 11:40:51 PST
(In reply to Michael Catanzaro from comment #51)
> I suppose. We don't really have a rule, but I agree the build system is
> easier to maintain if we build most files unconditionally and just have
> appropriate include guards in the source.

The reasons why I thought that it would be better to have the conditionals
inside Sources{GTK,WPE}.txt is that, when the feature is disabled, there
will be one less compiler job to launch: multiple fork+exec saved, which
means there is no need to the read source file and its chain of #includes
and expensive template parsing, and no need to generate a .o file.

That being said, I am fine putting back the ENABLE() guards in the .cpp
file -- I don't have a strong preference.
Comment 53 Adrian Perez 2019-02-07 11:49:53 PST
(In reply to youenn fablet from comment #48)
> Comment on attachment 361047 [details]
> Patch v10
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=361047&action=review
> 
> > Tools/WebKitTestRunner/TestController.cpp:835
> > +    m_serverTrustEvaluationCallbackCallsCount = 0;
> 
> Is this line needed?

Definitely not needed. This slipped when making the rebase, I'll
remove it.

> > Tools/WebKitTestRunner/TestController.cpp:836
> > +    resetContentExtensions();
> 
> Cocoa WTR currently reset these in platformResetStateToConsistentValues.
> I guess we should try to align both approaches.
> For instance, resetContentExtensions() could be called from
> resetStateToConsistentValues and cocoa would move its code to
> resetContentExtensions(), in this patch or as a follow-up.

Sounds like a good idea. I'll give it a try to the part of moving
the Cocoa part to resetContentExtensions() in ./cocoa/TestController.cpp,
inside PLATFORM(COCOA) guards, and keep the shared WPE/GTK+ version
in ./TestController.cpp

The part of making the Cocoa implementation use the C API to make
the three ports share the same resetContentExtensions() is something
that I would still rather do in a follow-up.

> > LayoutTests/platform/wpe/TestExpectations:1267
> > +http/tests/contentextensions/async-xhr-onerror.html [ Crash ]
> 
> What is causing all these tests to crash?

I'll try and have another look at it.
Comment 54 Adrian Perez 2019-02-07 13:34:45 PST
(In reply to Alex Christensen from comment #49)
> Comment on attachment 361047 [details]
> Patch v10
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=361047&action=review
> 
> > Source/WebKit/SourcesGTK.txt:127
> > +#if ENABLE_CONTENT_EXTENSIONS
> > +UIProcess/API/glib/APIContentRuleListStoreGLib.cpp @no-unify
> 
> Just unconditionally include the file.  Preprocessor-like things seem out of
> place in this file.

Okay :)

> > Source/WebKit/SourcesWPE.txt:112
> > +#if ENABLE_CONTENT_EXTENSIONS
> 
> ditto
> 
> > Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:33
> > +#include "WKRetainPtr.h"
> > +#include <wtf/Function.h>
> 
> These don't seem used.

Indeed. These are leftovers from from a previous iteration of the
patch, I'll remove them.

> > LayoutTests/platform/gtk/TestExpectations:126
> > +# Content extensions, the failures need up-to-date expectations. The crashing tests do so in a flaky way.
> 
> You should probably fix these "flaky crashes" before landing it.  Check that
> your memory mapped file is not being unmapped somehow.
Comment 55 Adrian Perez 2019-02-07 14:16:34 PST
Created attachment 361443 [details]
Patch v11


This version of the patch addresses all the reviews by owners.

I am still taking a look to see if I can figure out the crashes
from the layout tests.
Comment 56 Adrian Perez 2019-02-07 14:39:41 PST
Created attachment 361449 [details]
Patch v12


Attempt to fix the Cocoa build.
Comment 57 Adrian Perez 2019-02-07 14:59:02 PST
Created attachment 361454 [details]
Patch v13
Comment 58 Michael Catanzaro 2019-02-08 08:23:28 PST
EWS is red.
Comment 59 Adrian Perez 2019-02-09 15:19:18 PST
Created attachment 361612 [details]
Patch v14


Should fix the linker errors for the Cocoa and WinCairo EWS bots.
Comment 60 Adrian Perez 2019-02-10 04:44:16 PST
Created attachment 361626 [details]
Patch v15


Should fix the type conversion error for GTK EWS bot. It turns out
that including <wtf/Function.h> was needed after all for some older
GCC versions.
Comment 61 Michael Catanzaro 2019-02-10 13:03:46 PST
../../Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:79:6: error: no matching function for call to ‘API::ContentRuleListStore::compileContentRuleList(WTF::String, WTF::String, WKUserContentExtensionStoreCompile(WKUserContentExtensionStoreRef, WKStringRef, WKStringRef, void*, WKUserContentExtensionStoreFunction)::<lambda(WTF::RefPtr<API::ContentRuleList>, std::error_code)>)’
     });
      ^
Comment 62 Adrian Perez 2019-02-10 14:20:16 PST
(In reply to Michael Catanzaro from comment #61)
> ../../Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:79:6:
> error: no matching function for call to
> ‘API::ContentRuleListStore::compileContentRuleList(WTF::String, WTF::String,
> WKUserContentExtensionStoreCompile(WKUserContentExtensionStoreRef,
> WKStringRef, WKStringRef, void*,
> WKUserContentExtensionStoreFunction)::<lambda(WTF::RefPtr<API::
> ContentRuleList>, std::error_code)>)’
>      });
>       ^

I saw... This used to build fine with previous versions of the patch, and
definitely builds fine for me here. My suspicion is that it is yet another
Heisenbug “thanks to” the unified sources -- which I am slowly getting to
hate, one build failure at a time ¯\_(ツ)_/¯
Comment 63 Adrian Perez 2019-02-10 14:22:13 PST
(In reply to Adrian Perez from comment #62)
> (In reply to Michael Catanzaro from comment #61)
> > ../../Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:79:6:
> > error: no matching function for call to
> > ‘API::ContentRuleListStore::compileContentRuleList(WTF::String, WTF::String,
> > WKUserContentExtensionStoreCompile(WKUserContentExtensionStoreRef,
> > WKStringRef, WKStringRef, void*,
> > WKUserContentExtensionStoreFunction)::<lambda(WTF::RefPtr<API::
> > ContentRuleList>, std::error_code)>)’
> >      });
> >       ^
> 
> I saw... This used to build fine with previous versions of the patch, and
> definitely builds fine for me here. My suspicion is that it is yet another
> Heisenbug “thanks to” the unified sources -- which I am slowly getting to
> hate, one build failure at a time ¯\_(ツ)_/¯

Bingo! Adding “@no-unify” for this source file makes the compiler complain
locally as well, so at least I can try and figure out the reason easily
now :)
Comment 64 Adrian Perez 2019-02-10 14:44:05 PST
(In reply to Adrian Perez from comment #63)
> (In reply to Adrian Perez from comment #62)
> > (In reply to Michael Catanzaro from comment #61)
> > > ../../Source/WebKit/UIProcess/API/C/WKUserContentExtensionStoreRef.cpp:79:6:
> > > error: no matching function for call to
> > > ‘API::ContentRuleListStore::compileContentRuleList(WTF::String, WTF::String,
> > > WKUserContentExtensionStoreCompile(WKUserContentExtensionStoreRef,
> > > WKStringRef, WKStringRef, void*,
> > > WKUserContentExtensionStoreFunction)::<lambda(WTF::RefPtr<API::
> > > ContentRuleList>, std::error_code)>)’
> > >      });
> > >       ^
> > 
> > I saw... This used to build fine with previous versions of the patch, and
> > definitely builds fine for me here. My suspicion is that it is yet another
> > Heisenbug “thanks to” the unified sources -- which I am slowly getting to
> > hate, one build failure at a time ¯\_(ツ)_/¯
> 
> Bingo! Adding “@no-unify” for this source file makes the compiler complain
> locally as well, so at least I can try and figure out the reason easily
> now :)

The missing include turned out to be <wtf/CompletionHandler.h>, I am
posting a new version of the patch momentarily :)
Comment 65 Adrian Perez 2019-02-10 14:48:00 PST
Created attachment 361643 [details]
Patch v16


Adds missing <wtf/CompletionHandler.h> inclusion.
Comment 66 Michael Catanzaro 2019-02-10 15:17:51 PST
(In reply to Alex Christensen from comment #49)
> You should probably fix these "flaky crashes" before landing it.  Check that
> your memory mapped file is not being unmapped somehow.

Adrian, do you at least have a backtrace to show why the tests are crashing? I'm OK with landing WKTR support before the crashes are fixed, but we should at least have a bug report.
Comment 67 Michael Catanzaro 2019-02-10 15:21:09 PST
Comment on attachment 361643 [details]
Patch v16

View in context: https://bugs.webkit.org/attachment.cgi?id=361643&action=review

Thu number of crashing tests is really huge, so while I'm OK with landing WKTR support for content extensions now, we should look very closely at these failures before deciding to expose the public API for 2.24.

> Tools/WebKitTestRunner/TestController.cpp:1376
> +#if !PLATFORM(COCOA)

Should also have a bug report to make the cross-platform implementation work for Cocoa.
Comment 68 Adrian Perez 2019-02-10 15:40:41 PST
(In reply to Michael Catanzaro from comment #66)
> (In reply to Alex Christensen from comment #49)
> > You should probably fix these "flaky crashes" before landing it.  Check that
> > your memory mapped file is not being unmapped somehow.
> 
> Adrian, do you at least have a backtrace to show why the tests are crashing?
> I'm OK with landing WKTR support before the crashes are fixed, but we should
> at least have a bug report.

I'm making a debug build to go over the crashes tomorrow, let's try and
figure them out before landing :)
Comment 69 Adrian Perez 2019-02-10 15:44:08 PST
(In reply to Adrian Perez from comment #68)
> (In reply to Michael Catanzaro from comment #66)
> > (In reply to Alex Christensen from comment #49)
> > > You should probably fix these "flaky crashes" before landing it.  Check that
> > > your memory mapped file is not being unmapped somehow.
> > 
> > Adrian, do you at least have a backtrace to show why the tests are crashing?
> > I'm OK with landing WKTR support before the crashes are fixed, but we should
> > at least have a bug report.
> 
> I'm making a debug build to go over the crashes tomorrow, let's try and
> figure them out before landing :)

As a side note: They really ought to be something related to WKTR, because
I have been using builds of Epiphany and WebKit with patches applied locally
for over a week and there are no crashes there. So at least we have that
going for us, which is nice =)
Comment 70 Adrian Perez 2019-02-11 14:21:42 PST
(In reply to Michael Catanzaro from comment #67)
> Comment on attachment 361643 [details]
> Patch v16
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=361643&action=review
> 
> Thu number of crashing tests is really huge, so while I'm OK with landing
> WKTR support for content extensions now, we should look very closely at
> these failures before deciding to expose the public API for 2.24.

I have figured out those: it turned to be a refcounting issue inside
WKTR which made caused an use-after-free of WKUserContentControllerRef
inside TestController::resetContentExtensions(). Momentarily I will
upload the patch for landing, which fixes this issue.

With this fixed, now more than half of the layout tests automatically
pass (some still need platform specific expectations, which I will do
later as gardening patches), and there are no more crashes.

> > Tools/WebKitTestRunner/TestController.cpp:1376
> > +#if !PLATFORM(COCOA)
> 
> Should also have a bug report to make the cross-platform implementation work
> for Cocoa.

Filed as bug #194515 :)
Comment 71 Adrian Perez 2019-02-11 14:23:16 PST
Created attachment 361712 [details]
Patch v17


This fixes crashes in WKTR. Should be good for landing.
Comment 72 WebKit Commit Bot 2019-02-11 16:07:27 PST
Comment on attachment 361712 [details]
Patch v17

Clearing flags on attachment: 361712

Committed r241283: <https://trac.webkit.org/changeset/241283>
Comment 73 WebKit Commit Bot 2019-02-11 16:07:30 PST
All reviewed patches have been landed.  Closing bug.
Comment 74 Radar WebKit Bug Importer 2019-02-11 16:08:38 PST
<rdar://problem/47982850>
Comment 75 Michael Catanzaro 2019-02-12 13:36:05 PST
Committed r241316: <https://trac.webkit.org/changeset/241316>