Bug 228803 - [macOS] Clean up Feature Flags related code
Summary: [macOS] Clean up Feature Flags related code
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Peng Liu
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-08-04 15:29 PDT by Peng Liu
Modified: 2021-08-09 15:05 PDT (History)
12 users (show)

See Also:


Attachments
Patch (17.23 KB, patch)
2021-08-04 15:39 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
Revise the patch based on Simon's comments (16.94 KB, patch)
2021-08-04 16:06 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
Update change logs (16.90 KB, patch)
2021-08-04 16:12 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
Update change logs (17.67 KB, patch)
2021-08-04 22:47 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
Fix a layout test failure (19.38 KB, patch)
2021-08-05 10:07 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
Revise the patch based on Kate's comment (19.55 KB, patch)
2021-08-05 11:04 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
Update a layout test expectation (20.81 KB, patch)
2021-08-05 14:08 PDT, Peng Liu
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Revise the patch based on Tim's comments (24.76 KB, patch)
2021-08-05 16:51 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
Update changelogs (24.98 KB, patch)
2021-08-05 17:00 PDT, Peng Liu
no flags Details | Formatted Diff | Diff
Rebase a test expectation for BigSur (25.13 KB, patch)
2021-08-05 21:43 PDT, Peng Liu
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Peng Liu 2021-08-04 15:29:55 PDT
[macOS] Clean up Feature Flags related code
Comment 1 Peng Liu 2021-08-04 15:37:38 PDT
<rdar://81142982>
Comment 2 Peng Liu 2021-08-04 15:39:05 PDT
Created attachment 434944 [details]
Patch
Comment 3 Peng Liu 2021-08-04 15:42:57 PDT
Comment on attachment 434944 [details]
Patch

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

> Source/WebKit/ChangeLog:8
> +        For system WebKit and staged framework, we use the Feature Flags SPI to

The comment is not accurate. For staged framework, webkit parses the plist file instead of using the SPI.
Comment 4 Simon Fraser (smfr) 2021-08-04 15:49:29 PDT
Comment on attachment 434944 [details]
Patch

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

> Source/WebKit/Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm:50
> +    const static NSBundle *bundle = [NSBundle bundleForClass:NSClassFromString(@"WKWebView")];
> +
> +    static bool isSystemWebKit = [] {
> +        return [bundle.bundlePath hasPrefix:@"/System/"];
> +    }();

Use AuxiliaryProcess::isSystemWebKit() which also had some logic for readonly system volumes?

> Source/WebKit/Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm:60
>      if (!isWebKitBundleFromStagedFramework)
> -        return _os_feature_enabled_impl("WebKit", (const char*)featureName.utf8().data());
> +        return defaultValue;

I would prefer you write this as:

if (isWebKitBundleFromStagedFramework) {
   ... read from /Library/Apple/System/Library/FeatureFlags/Domain/WebKit.plist
    return;
}

> Source/WebKit/Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm:65
>          return _os_feature_enabled_impl("WebKit", (const char*)featureName.characters8());

I think it would make more sense here to return defaultValue?

> Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm:48
> +bool isFeatureFlagEnabled(const String& featureName, bool defaultValue)

I wish we could share this code. But make it identical.
Comment 5 Peng Liu 2021-08-04 15:55:21 PDT
Comment on attachment 434944 [details]
Patch

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

>> Source/WebKit/Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm:50
>> +    }();
> 
> Use AuxiliaryProcess::isSystemWebKit() which also had some logic for readonly system volumes?

Yes. But it will return true for staged framework.

>> Source/WebKit/Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm:60
>> +        return defaultValue;
> 
> I would prefer you write this as:
> 
> if (isWebKitBundleFromStagedFramework) {
>    ... read from /Library/Apple/System/Library/FeatureFlags/Domain/WebKit.plist
>     return;
> }

Sounds a good idea considering the next comment.

>> Source/WebKit/Shared/Cocoa/WebPreferencesDefaultValuesCocoa.mm:65
>>          return _os_feature_enabled_impl("WebKit", (const char*)featureName.characters8());
> 
> I think it would make more sense here to return defaultValue?

Yeah, that seems better.

>> Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm:48
>> +bool isFeatureFlagEnabled(const String& featureName, bool defaultValue)
> 
> I wish we could share this code. But make it identical.

Agree.
Comment 6 Peng Liu 2021-08-04 16:06:00 PDT
Created attachment 434948 [details]
Revise the patch based on Simon's comments
Comment 7 Peng Liu 2021-08-04 16:12:41 PDT
Created attachment 434951 [details]
Update change logs
Comment 8 Tim Horton 2021-08-04 17:23:47 PDT
Comment on attachment 434951 [details]
Update change logs

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

> Source/WebKit/ChangeLog:10
> +        For other cases, let's use hardcoded values.

This could use more words, we have a /strong/ motivation.

> Source/WebKit/Shared/WebPreferencesDefaultValues.cpp:258
> +    // TODO: double check

This looks fine to me (since it's inside HAVE(INCREMENTAL_PDF_APIS); if you've got them, we want to use them.)

> Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm:81
> +    // TODO: double check

Yeah, we don't have support in WebKitLegacy so this is right.

> Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm:92
> +    // TODO: double check
> +    return isFeatureFlagEnabled("WebXR", false);

This is right
Comment 9 Peng Liu 2021-08-04 22:47:28 PDT
Created attachment 434964 [details]
Update change logs
Comment 10 Peng Liu 2021-08-05 10:07:02 PDT
Created attachment 434999 [details]
Fix a layout test failure
Comment 11 Kate Cheney 2021-08-05 10:52:49 PDT
Comment on attachment 434999 [details]
Fix a layout test failure

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

> Source/WebKit/Shared/WebPreferencesDefaultValues.cpp:245
>  bool defaultInAppBrowserPrivacy()

It doesn't seem like this function is used anywhere. I think we can remove it.
Comment 12 Peng Liu 2021-08-05 11:04:41 PDT
Created attachment 435010 [details]
Revise the patch based on Kate's comment
Comment 13 Peng Liu 2021-08-05 11:06:01 PDT
Comment on attachment 434999 [details]
Fix a layout test failure

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

>> Source/WebKit/Shared/WebPreferencesDefaultValues.cpp:245
>>  bool defaultInAppBrowserPrivacy()
> 
> It doesn't seem like this function is used anywhere. I think we can remove it.

Yes! Removed.
I will remove the corresponding item in WebKit.plist in a follow-up patch.
Comment 14 Peng Liu 2021-08-05 14:08:06 PDT
Created attachment 435023 [details]
Update a layout test expectation
Comment 15 Tim Horton 2021-08-05 14:25:23 PDT
Comment on attachment 435023 [details]
Update a layout test expectation

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

I really hope we can get rid of this ASAP

> Source/WebKit/Shared/WebPreferencesDefaultValues.cpp:122
>  #if PLATFORM(MAC)
> -    return true;
> +    bool defaultValue = true;
> +#else
> +    bool defaultValue = false;
>  #endif

This is wrong, async_frame_and_overflow_scrolling should be on everywhere (confirm with smfr, but the plists agree)

> Source/WebKit/Shared/WebPreferencesDefaultValues.cpp:313
> +    return isFeatureFlagEnabled("webm_webaudio", false);

Why is this `false` here if it's `true` in the plist? That means that a local build will have it off on Monterey even though it's on in the system WebKit, and seems wrong.

> Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm:54
> +        NSBundle *bundle = [NSBundle bundleForClass:NSClassFromString(@"WKWebView")];

It seems exceedingly bizarre that WebKitLegacy looks up WKWebView; maybe you should use WebView here? (what does other code do?)

> Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm:290
> +    return isFeatureFlagEnabled("webm_webaudio", false);

Why is this `false` here if it's `true` in the plist? That means that a local build will have it off on Monterey even though it's on in the system WebKit, and seems wrong.

> Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm:299
> -#if HAVE(SYSTEM_FEATURE_FLAGS)
> -    return isFeatureFlagEnabled("vp8_decoder");
> -#endif
> -
> -    return false;
> +    return isFeatureFlagEnabled("vp8_decoder", false);

This key does not exist in any of the feature flags plists, so this should not use isFeatureFlagEnabled, should just return false (at which point you should get rid of the function and just put the `false` in WebPreferences.yaml directly).
Comment 16 Tim Horton 2021-08-05 14:35:59 PDT
Comment on attachment 435023 [details]
Update a layout test expectation

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

>> Source/WebKit/Shared/WebPreferencesDefaultValues.cpp:122
>>  #endif
> 
> This is wrong, async_frame_and_overflow_scrolling should be on everywhere (confirm with smfr, but the plists agree)

Ah, simon points out the #ifdef above covers iOS
Comment 17 Peng Liu 2021-08-05 16:41:07 PDT
Comment on attachment 435023 [details]
Update a layout test expectation

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

>> Source/WebKit/Shared/WebPreferencesDefaultValues.cpp:313
>> +    return isFeatureFlagEnabled("webm_webaudio", false);
> 
> Why is this `false` here if it's `true` in the plist? That means that a local build will have it off on Monterey even though it's on in the system WebKit, and seems wrong.

It was a mistake to enable `webm_webaudio` through the plist file. I will remove it from the WebKit.plist for appletvOS, watchOS, and tvOS, and change its value to false in WebKit-macOS.plist.

>> Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm:54
>> +        NSBundle *bundle = [NSBundle bundleForClass:NSClassFromString(@"WKWebView")];
> 
> It seems exceedingly bizarre that WebKitLegacy looks up WKWebView; maybe you should use WebView here? (what does other code do?)

Good catch. Will fix it. Thanks!

>> Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm:290
>> +    return isFeatureFlagEnabled("webm_webaudio", false);
> 
> Why is this `false` here if it's `true` in the plist? That means that a local build will have it off on Monterey even though it's on in the system WebKit, and seems wrong.

Will fix. Actually this feature should be disabled.

>> Source/WebKitLegacy/mac/WebView/WebPreferencesDefaultValues.mm:299
>> +    return isFeatureFlagEnabled("vp8_decoder", false);
> 
> This key does not exist in any of the feature flags plists, so this should not use isFeatureFlagEnabled, should just return false (at which point you should get rid of the function and just put the `false` in WebPreferences.yaml directly).

Will add an item to the plist files to enable it.
Comment 18 Peng Liu 2021-08-05 16:51:35 PDT
Created attachment 435039 [details]
Revise the patch based on Tim's comments
Comment 19 Peng Liu 2021-08-05 17:00:14 PDT
Created attachment 435040 [details]
Update changelogs
Comment 20 Peng Liu 2021-08-05 21:43:12 PDT
Created attachment 435055 [details]
Rebase a test expectation for BigSur
Comment 21 Peng Liu 2021-08-06 09:32:01 PDT
The test failure (fast/speechrecognition/start-recognition-twice-exception.html) is not relevant to this patch.
Comment 22 EWS 2021-08-06 09:38:35 PDT
Committed r280726 (240316@main): <https://commits.webkit.org/240316@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 435055 [details].
Comment 23 Truitt Savell 2021-08-09 15:05:50 PDT
Looks like the changes here broke 25 imported/w3c/web-platform-tests/fetch/ tests, tracking in https://bugs.webkit.org/show_bug.cgi?id=228926