Bug 228803

Summary: [macOS] Clean up Feature Flags related code
Product: WebKit Reporter: Peng Liu <peng.liu6>
Component: New BugsAssignee: Peng Liu <peng.liu6>
Status: RESOLVED FIXED    
Severity: Normal CC: beidson, eric.carlson, ews-watchlist, glenn, jer.noble, katherine_cheney, philipj, sergio, simon.fraser, thorton, tsavell, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=228926
Attachments:
Description Flags
Patch
none
Revise the patch based on Simon's comments
none
Update change logs
none
Update change logs
none
Fix a layout test failure
none
Revise the patch based on Kate's comment
none
Update a layout test expectation
ews-feeder: commit-queue-
Revise the patch based on Tim's comments
none
Update changelogs
none
Rebase a test expectation for BigSur none

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